Make WordPress Core

Changeset 9


Ignore:
Timestamp:
04/23/2003 01:21:54 AM (21 years ago)
Author:
saxmatt
Message:

Added wptexturize.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/b2-include/b2functions.php

    r8 r9  
    4949
    5050/***** Formatting functions *****/
     51function wptexturize($text) {
     52    $textarr = preg_split("/(<.*>)/U", $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between
     53    $stop = count($textarr); $next = true; // loop stuff
     54    for ($i = 0; $i < $stop; $i++) {
     55        $curl = $textarr[$i];
     56        if (!strstr($_SERVER['HTTP_USER_AGENT'], 'Gecko')) {
     57            $curl = str_replace('<q>', '&#8220;', $curl);
     58            $curl = str_replace('</q>', '&#8221;', $curl);
     59        }
     60        if ('<' != $curl{0} && $next) { // If it's not a tag
     61            $curl = str_replace('---', '&#8212;', $curl);
     62            $curl = str_replace('--', '&#8211;', $curl);
     63            $curl = str_replace("...", '&#8230;', $curl);
     64            $curl = str_replace('``', '&#8220;', $curl);
     65
     66            // This is a hack, look at this more later. It works pretty well though.
     67            $cockney = array("'tain't","'twere","'twas","'tis","'twill","'til","'bout","'nuff","'round");
     68            $cockneyreplace = array("&#8217;tain&#8217;t","&#8217;twere","&#8217;twas","&#8217;tis","&#8217;twill","&#8217;til","&#8217;bout","&#8217;nuff","&#8217;round");
     69            $curl = str_replace($cockney, $cockneyreplace, $curl);
     70
     71       
     72            $curl = preg_replace("/'s/", "&#8217;s", $curl);
     73            $curl = preg_replace("/'(\d\d(?:&#8217;|')?s)/", "&#8217;$1", $curl);
     74            $curl = preg_replace('/(\s|\A|")\'/', '$1&#8216;', $curl);
     75            $curl = preg_replace("/(\d+)\"/", "$1&Prime;", $curl);
     76            $curl = preg_replace("/(\d+)'/", "$1&prime;", $curl);
     77            $curl = preg_replace("/(\S)'([^'\s])/", "$1&#8217;$2", $curl);
     78            $curl = preg_replace('/"([\s.]|\Z)/', '&#8221;$1', $curl);
     79            $curl = preg_replace('/(\s|\A)"/', '$1&#8220;', $curl);
     80            $curl = preg_replace("/'([\s.]|\Z)/", '&#8217;$1', $curl);
     81            $curl = preg_replace("/\(tm\)/i", '&#8482;', $curl);
     82            $curl = preg_replace("/\(c\)/i", '&#169;', $curl);
     83            $curl = preg_replace("/\(r\)/i", '&#174;', $curl);
     84
     85            $curl = str_replace("''", '&#8221;', $curl);
     86            $curl = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&#038;$1', $curl);
     87           
     88            $curl = preg_replace('/(d+)x(\d+)/', "$1&#215;$2", $curl);
     89
     90        } elseif (strstr($curl, '<code') || strstr($curl, '<pre') || strstr($curl, '<kbd' || strstr($curl, '<style') || strstr($curl, '<script'))) {
     91            // strstr is fast
     92            $next = false;
     93        } else {
     94            $next = true;
     95        }
     96        $output .= $curl;
     97    }
     98    return $output;
     99    }
    51100
    52101function autobrize($content) {
Note: See TracChangeset for help on using the changeset viewer.