[ Index ]

PHP Cross Reference of WordPress Trunk (Latest)

title

Body

[close]

/wp-includes/ -> functions-formatting.php (source)

   1  <?php
   2  
   3  function wptexturize($text) {
   4      $output = '';
   5      // Capture tags and everything inside them
   6      $textarr = preg_split("/(<.*>)/Us", $text, -1, PREG_SPLIT_DELIM_CAPTURE);
   7      $stop = count($textarr); $next = true; // loop stuff
   8      for ($i = 0; $i < $stop; $i++) {
   9          $curl = $textarr[$i];
  10  
  11          if (isset($curl{0}) && '<' != $curl{0} && $next) { // If it's not a tag
  12              $curl = str_replace('---', '&#8212;', $curl);
  13              $curl = str_replace(' -- ', ' &#8212; ', $curl);
  14              $curl = str_replace('--', '&#8211;', $curl);
  15              $curl = str_replace('xn&#8211;', 'xn--', $curl);
  16              $curl = str_replace('...', '&#8230;', $curl);
  17              $curl = str_replace('``', '&#8220;', $curl);
  18  
  19              // This is a hack, look at this more later. It works pretty well though.
  20              $cockney = array("'tain't","'twere","'twas","'tis","'twill","'til","'bout","'nuff","'round","'cause");
  21              $cockneyreplace = array("&#8217;tain&#8217;t","&#8217;twere","&#8217;twas","&#8217;tis","&#8217;twill","&#8217;til","&#8217;bout","&#8217;nuff","&#8217;round","&#8217;cause");
  22              $curl = str_replace($cockney, $cockneyreplace, $curl);
  23  
  24              $curl = preg_replace("/'s/", '&#8217;s', $curl);
  25              $curl = preg_replace("/'(\d\d(?:&#8217;|')?s)/", "&#8217;$1", $curl);
  26              $curl = preg_replace('/(\s|\A|")\'/', '$1&#8216;', $curl);
  27              $curl = preg_replace('/(\d+)"/', '$1&#8243;', $curl);
  28              $curl = preg_replace("/(\d+)'/", '$1&#8242;', $curl);
  29              $curl = preg_replace("/(\S)'([^'\s])/", "$1&#8217;$2", $curl);
  30              $curl = preg_replace('/(\s|\A)"(?!\s)/', '$1&#8220;$2', $curl);
  31              $curl = preg_replace('/"(\s|\S|\Z)/', '&#8221;$1', $curl);
  32              $curl = preg_replace("/'([\s.]|\Z)/", '&#8217;$1', $curl);
  33              $curl = preg_replace("/ \(tm\)/i", ' &#8482;', $curl);
  34              $curl = str_replace("''", '&#8221;', $curl);
  35  
  36              $curl = preg_replace('/(\d+)x(\d+)/', "$1&#215;$2", $curl);
  37  
  38          } elseif (strstr($curl, '<code') || strstr($curl, '<pre') || strstr($curl, '<kbd' || strstr($curl, '<style') || strstr($curl, '<script'))) {
  39              // strstr is fast
  40              $next = false;
  41          } else {
  42              $next = true;
  43          }
  44          $curl = preg_replace('/&([^#])(?![a-zA-Z1-4]{1,8};)/', '&#038;$1', $curl);
  45          $output .= $curl;
  46      }
  47      return $output;
  48  }
  49  
  50  function clean_pre($text) {
  51      $text = str_replace('<br />', '', $text);
  52      $text = str_replace('<p>', "\n", $text);
  53      $text = str_replace('</p>', '', $text);
  54      return $text;
  55  }
  56  
  57  function wpautop($pee, $br = 1) {
  58      $pee = $pee . "\n"; // just to make things a little easier, pad the end
  59      $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
  60      // Space things out a little
  61      $pee = preg_replace('!(<(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6])[^>]*>)!', "\n$1", $pee); 
  62      $pee = preg_replace('!(</(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6])>)!', "$1\n\n", $pee);
  63      $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines 
  64      $pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates
  65      $pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "<p>$1</p>\n", $pee); // make paragraphs, including one at the end 
  66      $pee = preg_replace('|<p>\s*?</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace 
  67      $pee = preg_replace('!<p>\s*(</?(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|hr|pre|select|form|blockquote|address|math|p|h[1-6])[^>]*>)\s*</p>!', "$1", $pee); // don't pee all over a tag
  68      $pee = preg_replace("|<p>(<li.+?)</p>|", "$1", $pee); // problem with nested lists
  69      $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee);
  70      $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
  71      $pee = preg_replace('!<p>\s*(</?(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|hr|pre|select|form|blockquote|address|math|p|h[1-6])[^>]*>)!', "$1", $pee);
  72      $pee = preg_replace('!(</?(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6])[^>]*>)\s*</p>!', "$1", $pee); 
  73      if ($br) $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks
  74      $pee = preg_replace('!(</?(?:table|thead|tfoot|caption|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6])[^>]*>)\s*<br />!', "$1", $pee);
  75      $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)!', '$1', $pee);
  76      $pee = preg_replace('!(<pre.*?>)(.*?)</pre>!ise', " stripslashes('$1') .  stripslashes(clean_pre('$2'))  . '</pre>' ", $pee);
  77  
  78      return $pee; 
  79  }
  80  
  81  
  82  function seems_utf8($Str) { # by bmorel at ssi dot fr
  83      for ($i=0; $i<strlen($Str); $i++) {
  84          if (ord($Str[$i]) < 0x80) continue; # 0bbbbbbb
  85          elseif ((ord($Str[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb
  86          elseif ((ord($Str[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb
  87          elseif ((ord($Str[$i]) & 0xF8) == 0xF0) $n=3; # 11110bbb
  88          elseif ((ord($Str[$i]) & 0xFC) == 0xF8) $n=4; # 111110bb
  89          elseif ((ord($Str[$i]) & 0xFE) == 0xFC) $n=5; # 1111110b
  90          else return false; # Does not match any model
  91          for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ?
  92              if ((++$i == strlen($Str)) || ((ord($Str[$i]) & 0xC0) != 0x80))
  93              return false;
  94          }
  95      }
  96      return true;
  97  }
  98  
  99  function wp_specialchars( $text, $quotes = 0 ) {
 100      // Like htmlspecialchars except don't double-encode HTML entities
 101      $text = preg_replace('/&([^#])(?![a-z1-4]{1,8};)/', '&#038;$1', $text);
 102      $text = str_replace('<', '&lt;', $text);
 103      $text = str_replace('>', '&gt;', $text);
 104      if ( 'double' === $quotes ) {
 105          $text = str_replace('"', '&quot;', $text);
 106      } elseif ( 'single' === $quotes ) {
 107          $text = str_replace("'", '&#039;', $text);
 108      } elseif ( $quotes ) {
 109          $text = str_replace('"', '&quot;', $text);
 110          $text = str_replace("'", '&#039;', $text);
 111      }
 112      return $text;
 113  }
 114  
 115  function utf8_uri_encode( $utf8_string ) {
 116    $unicode = '';        
 117    $values = array();
 118    $num_octets = 1;
 119          
 120    for ($i = 0; $i < strlen( $utf8_string ); $i++ ) {
 121  
 122      $value = ord( $utf8_string[ $i ] );
 123              
 124      if ( $value < 128 ) {
 125        $unicode .= chr($value);
 126      } else {
 127        if ( count( $values ) == 0 ) $num_octets = ( $value < 224 ) ? 2 : 3;
 128                  
 129        $values[] = $value;
 130        
 131        if ( count( $values ) == $num_octets ) {
 132      if ($num_octets == 3) {
 133        $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]);
 134      } else {
 135        $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]);
 136      }
 137  
 138      $values = array();
 139      $num_octets = 1;
 140        }
 141      }
 142    }
 143  
 144    return $unicode;    
 145  }
 146  
 147  function remove_accents($string) {
 148      if (seems_utf8($string)) {
 149          $chars = array(
 150          // Decompositions for Latin-1 Supplement
 151          chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
 152          chr(195).chr(130) => 'A', chr(195).chr(131) => 'A',
 153          chr(195).chr(132) => 'A', chr(195).chr(133) => 'A',
 154          chr(195).chr(135) => 'C', chr(195).chr(136) => 'E',
 155          chr(195).chr(137) => 'E', chr(195).chr(138) => 'E',
 156          chr(195).chr(139) => 'E', chr(195).chr(140) => 'I',
 157          chr(195).chr(141) => 'I', chr(195).chr(142) => 'I',
 158          chr(195).chr(143) => 'I', chr(195).chr(145) => 'N',
 159          chr(195).chr(146) => 'O', chr(195).chr(147) => 'O',
 160          chr(195).chr(148) => 'O', chr(195).chr(149) => 'O',
 161          chr(195).chr(150) => 'O', chr(195).chr(153) => 'U',
 162          chr(195).chr(154) => 'U', chr(195).chr(155) => 'U',
 163          chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y',
 164          chr(195).chr(159) => 's', chr(195).chr(160) => 'a',
 165          chr(195).chr(161) => 'a', chr(195).chr(162) => 'a',
 166          chr(195).chr(163) => 'a', chr(195).chr(164) => 'a',
 167          chr(195).chr(165) => 'a', chr(195).chr(167) => 'c',
 168          chr(195).chr(168) => 'e', chr(195).chr(169) => 'e',
 169          chr(195).chr(170) => 'e', chr(195).chr(171) => 'e',
 170          chr(195).chr(172) => 'i', chr(195).chr(173) => 'i',
 171          chr(195).chr(174) => 'i', chr(195).chr(175) => 'i',
 172          chr(195).chr(177) => 'n', chr(195).chr(178) => 'o',
 173          chr(195).chr(179) => 'o', chr(195).chr(180) => 'o',
 174          chr(195).chr(181) => 'o', chr(195).chr(182) => 'o',
 175          chr(195).chr(182) => 'o', chr(195).chr(185) => 'u',
 176          chr(195).chr(186) => 'u', chr(195).chr(187) => 'u',
 177          chr(195).chr(188) => 'u', chr(195).chr(189) => 'y',
 178          chr(195).chr(191) => 'y',
 179          // Decompositions for Latin Extended-A
 180          chr(196).chr(128) => 'A', chr(196).chr(129) => 'a',
 181          chr(196).chr(130) => 'A', chr(196).chr(131) => 'a',
 182          chr(196).chr(132) => 'A', chr(196).chr(133) => 'a',
 183          chr(196).chr(134) => 'C', chr(196).chr(135) => 'c',
 184          chr(196).chr(136) => 'C', chr(196).chr(137) => 'c',
 185          chr(196).chr(138) => 'C', chr(196).chr(139) => 'c',
 186          chr(196).chr(140) => 'C', chr(196).chr(141) => 'c',
 187          chr(196).chr(142) => 'D', chr(196).chr(143) => 'd',
 188          chr(196).chr(144) => 'D', chr(196).chr(145) => 'd',
 189          chr(196).chr(146) => 'E', chr(196).chr(147) => 'e',
 190          chr(196).chr(148) => 'E', chr(196).chr(149) => 'e',
 191          chr(196).chr(150) => 'E', chr(196).chr(151) => 'e',
 192          chr(196).chr(152) => 'E', chr(196).chr(153) => 'e',
 193          chr(196).chr(154) => 'E', chr(196).chr(155) => 'e',
 194          chr(196).chr(156) => 'G', chr(196).chr(157) => 'g',
 195          chr(196).chr(158) => 'G', chr(196).chr(159) => 'g',
 196          chr(196).chr(160) => 'G', chr(196).chr(161) => 'g',
 197          chr(196).chr(162) => 'G', chr(196).chr(163) => 'g',
 198          chr(196).chr(164) => 'H', chr(196).chr(165) => 'h',
 199          chr(196).chr(166) => 'H', chr(196).chr(167) => 'h',
 200          chr(196).chr(168) => 'I', chr(196).chr(169) => 'i',
 201          chr(196).chr(170) => 'I', chr(196).chr(171) => 'i',
 202          chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
 203          chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
 204          chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
 205          chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
 206          chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
 207          chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
 208          chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
 209          chr(196).chr(186) => 'l', chr(196).chr(187) => 'L',
 210          chr(196).chr(188) => 'l', chr(196).chr(189) => 'L',
 211          chr(196).chr(190) => 'l', chr(196).chr(191) => 'L',
 212          chr(197).chr(128) => 'l', chr(197).chr(129) => 'L',
 213          chr(197).chr(130) => 'l', chr(197).chr(131) => 'N',
 214          chr(197).chr(132) => 'n', chr(197).chr(133) => 'N',
 215          chr(197).chr(134) => 'n', chr(197).chr(135) => 'N',
 216          chr(197).chr(136) => 'n', chr(197).chr(137) => 'N',
 217          chr(197).chr(138) => 'n', chr(197).chr(139) => 'N',
 218          chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
 219          chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
 220          chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
 221          chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
 222          chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
 223          chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
 224          chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
 225          chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
 226          chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
 227          chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
 228          chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
 229          chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
 230          chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
 231          chr(197).chr(166) => 'T', chr(197).chr(167) => 't',
 232          chr(197).chr(168) => 'U', chr(197).chr(169) => 'u',
 233          chr(197).chr(170) => 'U', chr(197).chr(171) => 'u',
 234          chr(197).chr(172) => 'U', chr(197).chr(173) => 'u',
 235          chr(197).chr(174) => 'U', chr(197).chr(175) => 'u',
 236          chr(197).chr(176) => 'U', chr(197).chr(177) => 'u',
 237          chr(197).chr(178) => 'U', chr(197).chr(179) => 'u',
 238          chr(197).chr(180) => 'W', chr(197).chr(181) => 'w',
 239          chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y',
 240          chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z',
 241          chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z',
 242          chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z',
 243          chr(197).chr(190) => 'z', chr(197).chr(191) => 's',
 244          // Euro Sign
 245          chr(226).chr(130).chr(172) => 'E');
 246  
 247          $string = strtr($string, $chars);
 248      } else {
 249          // Assume ISO-8859-1 if not UTF-8
 250          $chars['in'] = chr(128).chr(131).chr(138).chr(142).chr(154).chr(158)
 251              .chr(159).chr(162).chr(165).chr(181).chr(192).chr(193).chr(194)
 252              .chr(195).chr(196).chr(197).chr(199).chr(200).chr(201).chr(202)
 253              .chr(203).chr(204).chr(205).chr(206).chr(207).chr(209).chr(210)
 254              .chr(211).chr(212).chr(213).chr(214).chr(216).chr(217).chr(218)
 255              .chr(219).chr(220).chr(221).chr(224).chr(225).chr(226).chr(227)
 256              .chr(228).chr(229).chr(231).chr(232).chr(233).chr(234).chr(235)
 257              .chr(236).chr(237).chr(238).chr(239).chr(241).chr(242).chr(243)
 258              .chr(244).chr(245).chr(246).chr(248).chr(249).chr(250).chr(251)
 259              .chr(252).chr(253).chr(255);
 260  
 261          $chars['out'] = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy";
 262  
 263          $string = strtr($string, $chars['in'], $chars['out']);
 264          $double_chars['in'] = array(chr(140), chr(156), chr(198), chr(208), chr(222), chr(223), chr(230), chr(240), chr(254));
 265          $double_chars['out'] = array('OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th');
 266          $string = str_replace($double_chars['in'], $double_chars['out'], $string);
 267      }
 268  
 269      return $string;
 270  }
 271  
 272  function sanitize_user( $username, $strict = false ) {
 273      $raw_username = $username;
 274      $username = strip_tags($username);
 275      // Kill octets
 276      $username = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '', $username);
 277      $username = preg_replace('/&.+?;/', '', $username); // Kill entities
 278  
 279      // If strict, reduce to ASCII for max portability.
 280      if ( $strict )
 281          $username = preg_replace('|[^a-z0-9 _.\-@]|i', '', $username);
 282  
 283      return apply_filters('sanitize_user', $username, $raw_username, $strict);
 284  }
 285  
 286  function sanitize_title($title, $fallback_title = '') {
 287      $title = strip_tags($title);
 288      $title = apply_filters('sanitize_title', $title);
 289  
 290      if (empty($title)) {
 291          $title = $fallback_title;
 292      }
 293  
 294      return $title;
 295  }
 296  
 297  function sanitize_title_with_dashes($title) {
 298      $title = strip_tags($title);
 299      // Preserve escaped octets.
 300      $title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title);
 301      // Remove percent signs that are not part of an octet.
 302      $title = str_replace('%', '', $title);
 303      // Restore octets.
 304      $title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title);
 305  
 306      $title = remove_accents($title);
 307      if (seems_utf8($title)) {
 308          if (function_exists('mb_strtolower')) {
 309              $title = mb_strtolower($title, 'UTF-8');
 310          }
 311          $title = utf8_uri_encode($title);
 312      }
 313  
 314      $title = strtolower($title);
 315      $title = preg_replace('/&.+?;/', '', $title); // kill entities
 316      $title = preg_replace('/[^%a-z0-9 _-]/', '', $title);
 317      $title = preg_replace('/\s+/', '-', $title);
 318      $title = preg_replace('|-+|', '-', $title);
 319      $title = trim($title, '-');
 320  
 321      return $title;
 322  }
 323  
 324  function convert_chars($content, $flag = 'obsolete') { 
 325      // Translation of invalid Unicode references range to valid range
 326      $wp_htmltranswinuni = array(
 327      '&#128;' => '&#8364;', // the Euro sign
 328      '&#129;' => '',
 329      '&#130;' => '&#8218;', // these are Windows CP1252 specific characters
 330      '&#131;' => '&#402;',  // they would look weird on non-Windows browsers
 331      '&#132;' => '&#8222;',
 332      '&#133;' => '&#8230;',
 333      '&#134;' => '&#8224;',
 334      '&#135;' => '&#8225;',
 335      '&#136;' => '&#710;',
 336      '&#137;' => '&#8240;',
 337      '&#138;' => '&#352;',
 338      '&#139;' => '&#8249;',
 339      '&#140;' => '&#338;',
 340      '&#141;' => '',
 341      '&#142;' => '&#382;',
 342      '&#143;' => '',
 343      '&#144;' => '',
 344      '&#145;' => '&#8216;',
 345      '&#146;' => '&#8217;',
 346      '&#147;' => '&#8220;',
 347      '&#148;' => '&#8221;',
 348      '&#149;' => '&#8226;',
 349      '&#150;' => '&#8211;',
 350      '&#151;' => '&#8212;',
 351      '&#152;' => '&#732;',
 352      '&#153;' => '&#8482;',
 353      '&#154;' => '&#353;',
 354      '&#155;' => '&#8250;',
 355      '&#156;' => '&#339;',
 356      '&#157;' => '',
 357      '&#158;' => '',
 358      '&#159;' => '&#376;'
 359      );
 360  
 361      // Remove metadata tags
 362      $content = preg_replace('/<title>(.+?)<\/title>/','',$content);
 363      $content = preg_replace('/<category>(.+?)<\/category>/','',$content);
 364  
 365      // Converts lone & characters into &#38; (a.k.a. &amp;)
 366      $content = preg_replace('/&([^#])(?![a-z1-4]{1,8};)/i', '&#038;$1', $content);
 367  
 368      // Fix Word pasting
 369      $content = strtr($content, $wp_htmltranswinuni);
 370  
 371      // Just a little XHTML help
 372      $content = str_replace('<br>', '<br />', $content);
 373      $content = str_replace('<hr>', '<hr />', $content);
 374  
 375      return $content;
 376  }
 377  
 378  function funky_javascript_fix($text) {
 379      // Fixes for browsers' javascript bugs
 380      global $is_macIE, $is_winIE;
 381  
 382      if ( $is_winIE || $is_macIE )
 383          $text =  preg_replace("/\%u([0-9A-F]{4,4})/e",  "'&#'.base_convert('\\1',16,10).';'", $text);
 384  
 385      return $text;
 386  }
 387  
 388  /*
 389   balanceTags
 390   
 391   Balances Tags of string using a modified stack.
 392   
 393   @param text      Text to be balanced
 394   @return          Returns balanced text
 395   @author          Leonard Lin (leonard@acm.org)
 396   @version         v1.1
 397   @date            November 4, 2001
 398   @license         GPL v2.0
 399   @notes           
 400   @changelog       
 401   ---  Modified by Scott Reilly (coffee2code) 02 Aug 2004
 402               1.2  ***TODO*** Make better - change loop condition to $text
 403               1.1  Fixed handling of append/stack pop order of end text
 404                    Added Cleaning Hooks
 405               1.0  First Version
 406  */
 407  function balanceTags($text, $is_comment = 0, $force = false) {
 408  
 409      if ( !$force && get_option('use_balanceTags') == 0 )
 410          return $text;
 411  
 412      $tagstack = array(); $stacksize = 0; $tagqueue = ''; $newtext = '';
 413  
 414      # WP bug fix for comments - in case you REALLY meant to type '< !--'
 415      $text = str_replace('< !--', '<    !--', $text);
 416      # WP bug fix for LOVE <3 (and other situations with '<' before a number)
 417      $text = preg_replace('#<([0-9]{1})#', '&lt;$1', $text);
 418  
 419      while (preg_match("/<(\/?\w*)\s*([^>]*)>/",$text,$regex)) {
 420          $newtext .= $tagqueue;
 421  
 422          $i = strpos($text,$regex[0]);
 423          $l = strlen($regex[0]);
 424  
 425          // clear the shifter
 426          $tagqueue = '';
 427          // Pop or Push
 428          if ($regex[1][0] == "/") { // End Tag
 429              $tag = strtolower(substr($regex[1],1));
 430              // if too many closing tags
 431              if($stacksize <= 0) { 
 432                  $tag = '';
 433                  //or close to be safe $tag = '/' . $tag;
 434              }
 435              // if stacktop value = tag close value then pop
 436              else if ($tagstack[$stacksize - 1] == $tag) { // found closing tag
 437                  $tag = '</' . $tag . '>'; // Close Tag
 438                  // Pop
 439                  array_pop ($tagstack);
 440                  $stacksize--;
 441              } else { // closing tag not at top, search for it
 442                  for ($j=$stacksize-1;$j>=0;$j--) {
 443                      if ($tagstack[$j] == $tag) {
 444                      // add tag to tagqueue
 445                          for ($k=$stacksize-1;$k>=$j;$k--){
 446                              $tagqueue .= '</' . array_pop ($tagstack) . '>';
 447                              $stacksize--;
 448                          }
 449                          break;
 450                      }
 451                  }
 452                  $tag = '';
 453              }
 454          } else { // Begin Tag
 455              $tag = strtolower($regex[1]);
 456  
 457              // Tag Cleaning
 458  
 459              // If self-closing or '', don't do anything.
 460              if((substr($regex[2],-1) == '/') || ($tag == '')) {
 461              }
 462              // ElseIf it's a known single-entity tag but it doesn't close itself, do so
 463              elseif ($tag == 'br' || $tag == 'img' || $tag == 'hr' || $tag == 'input') {
 464                  $regex[2] .= '/';
 465              } else {    // Push the tag onto the stack
 466                  // If the top of the stack is the same as the tag we want to push, close previous tag
 467                  if (($stacksize > 0) && ($tag != 'div') && ($tagstack[$stacksize - 1] == $tag)) {
 468                      $tagqueue = '</' . array_pop ($tagstack) . '>';
 469                      $stacksize--;
 470                  }
 471                  $stacksize = array_push ($tagstack, $tag);
 472              }
 473  
 474              // Attributes
 475              $attributes = $regex[2];
 476              if($attributes) {
 477                  $attributes = ' '.$attributes;
 478              }
 479              $tag = '<'.$tag.$attributes.'>';
 480              //If already queuing a close tag, then put this tag on, too
 481              if ($tagqueue) {
 482                  $tagqueue .= $tag;
 483                  $tag = '';
 484              }
 485          }
 486          $newtext .= substr($text,0,$i) . $tag;
 487          $text = substr($text,$i+$l);
 488      }  
 489  
 490      // Clear Tag Queue
 491      $newtext .= $tagqueue;
 492  
 493      // Add Remaining text
 494      $newtext .= $text;
 495  
 496      // Empty Stack
 497      while($x = array_pop($tagstack)) {
 498          $newtext .= '</' . $x . '>'; // Add remaining tags to close
 499      }
 500  
 501      // WP fix for the bug with HTML comments
 502      $newtext = str_replace("< !--","<!--",$newtext);
 503      $newtext = str_replace("<    !--","< !--",$newtext);
 504  
 505      return $newtext;
 506  }
 507  
 508  
 509  function format_to_edit($content, $richedit = false) {
 510      $content = apply_filters('format_to_edit', $content);
 511      if (! $richedit )
 512          $content = htmlspecialchars($content);
 513      return $content;
 514  }
 515  
 516  function format_to_post($content) {
 517      global $wpdb;
 518      $content = apply_filters('format_to_post', $content);
 519      return $content;
 520  }
 521  
 522  function zeroise($number,$threshold) { // function to add leading zeros when necessary
 523      return sprintf('%0'.$threshold.'s', $number);
 524  }
 525  
 526  
 527  function backslashit($string) {
 528      $string = preg_replace('/^([0-9])/', '\\\\\\\\\1', $string);
 529      $string = preg_replace('/([a-z])/i', '\\\\\1', $string);
 530      return $string;
 531  }
 532  
 533  function trailingslashit($string) {
 534      if ( '/' != substr($string, -1)) {
 535          $string .= '/';
 536      }
 537      return $string;
 538  }
 539  
 540  function addslashes_gpc($gpc) {
 541      global $wpdb;
 542  
 543      if (get_magic_quotes_gpc()) {
 544          $gpc = stripslashes($gpc);
 545      }
 546  
 547      return $wpdb->escape($gpc);
 548  }
 549  
 550  
 551  function stripslashes_deep($value)
 552  {
 553     $value = is_array($value) ?
 554                 array_map('stripslashes_deep', $value) :
 555                 stripslashes($value);
 556  
 557     return $value;
 558  }
 559  
 560  function antispambot($emailaddy, $mailto=0) {
 561      $emailNOSPAMaddy = '';
 562      srand ((float) microtime() * 1000000);
 563      for ($i = 0; $i < strlen($emailaddy); $i = $i + 1) {
 564          $j = floor(rand(0, 1+$mailto));
 565          if ($j==0) {
 566              $emailNOSPAMaddy .= '&#'.ord(substr($emailaddy,$i,1)).';';
 567          } elseif ($j==1) {
 568              $emailNOSPAMaddy .= substr($emailaddy,$i,1);
 569          } elseif ($j==2) {
 570              $emailNOSPAMaddy .= '%'.zeroise(dechex(ord(substr($emailaddy, $i, 1))), 2);
 571          }
 572      }
 573      $emailNOSPAMaddy = str_replace('@','&#64;',$emailNOSPAMaddy);
 574      return $emailNOSPAMaddy;
 575  }
 576  
 577  function make_clickable($ret) {
 578      $ret = ' ' . $ret . ' ';
 579      $ret = preg_replace("#([\s>])(https?)://([^\s<>{}()]+[^\s.,<>{}()])#i", "$1<a href='$2://$3' rel='nofollow'>$2://$3</a>", $ret);
 580      $ret = preg_replace("#(\s)www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[^ <>{}()\n\r]*[^., <>{}()\n\r]?)?)#i", "$1<a href='http://www.$2.$3$4' rel='nofollow'>www.$2.$3$4</a>", $ret);
 581      $ret = preg_replace("#(\s)([a-z0-9\-_.]+)@([a-z0-9\-_.]+)\.([^,< \n\r]+)#i", "$1<a href=\"mailto:$2@$3.$4\">$2@$3.$4</a>", $ret);
 582      $ret = trim($ret);
 583      return $ret;
 584  }
 585  
 586  function wp_rel_nofollow( $text ) {
 587      global $wpdb;
 588      // This is a pre save filter, so text is already escaped.
 589      $text = stripslashes($text);
 590      $text = preg_replace('|<a (.+?)>|i', '<a $1 rel="nofollow">', $text);
 591      $text = $wpdb->escape($text);
 592      return $text;
 593  }
 594  
 595  function convert_smilies($text) {
 596      global $wp_smiliessearch, $wp_smiliesreplace;
 597      $output = '';
 598      if (get_settings('use_smilies')) {
 599          // HTML loop taken from texturize function, could possible be consolidated
 600          $textarr = preg_split("/(<.*>)/U", $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between
 601          $stop = count($textarr);// loop stuff
 602          for ($i = 0; $i < $stop; $i++) {
 603              $content = $textarr[$i];
 604              if ((strlen($content) > 0) && ('<' != $content{0})) { // If it's not a tag
 605                  $content = str_replace($wp_smiliessearch, $wp_smiliesreplace, $content);
 606              }
 607              $output .= $content;
 608          }
 609      } else {
 610          // return default text.
 611          $output = $text;
 612      }
 613      return $output;
 614  }
 615  
 616  
 617  function is_email($user_email) {
 618      $chars = "/^([a-z0-9+_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,6}\$/i";
 619      if(strstr($user_email, '@') && strstr($user_email, '.')) {
 620          if (preg_match($chars, $user_email)) {
 621              return true;
 622          } else {
 623              return false;
 624          }
 625      } else {
 626          return false;
 627      }
 628  }
 629  
 630  // used by wp-mail to handle charsets in email subjects
 631  function wp_iso_descrambler($string) {
 632    /* this may only work with iso-8859-1, I'm afraid */
 633    if (!preg_match('#\=\?(.+)\?Q\?(.+)\?\=#i', $string, $matches)) {
 634      return $string;
 635    } else {
 636      $subject = str_replace('_', ' ', $matches[2]);
 637      $subject = preg_replace('#\=([0-9a-f]{2})#ei', "chr(hexdec(strtolower('$1')))", $subject);
 638      return $subject;
 639    }
 640  }
 641  
 642  
 643  // give it a date, it will give you the same date as GMT
 644  function get_gmt_from_date($string) {
 645    // note: this only substracts $time_difference from the given date
 646    preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches);
 647    $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
 648    $string_gmt = gmdate('Y-m-d H:i:s', $string_time - get_settings('gmt_offset') * 3600);
 649    return $string_gmt;
 650  }
 651  
 652  // give it a GMT date, it will give you the same date with $time_difference added
 653  function get_date_from_gmt($string) {
 654    // note: this only adds $time_difference to the given date
 655    preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches);
 656    $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
 657    $string_localtime = gmdate('Y-m-d H:i:s', $string_time + get_settings('gmt_offset')*3600);
 658    return $string_localtime;
 659  }
 660  
 661  // computes an offset in seconds from an iso8601 timezone
 662  function iso8601_timezone_to_offset($timezone) {
 663    // $timezone is either 'Z' or '[+|-]hhmm'
 664    if ($timezone == 'Z') {
 665      $offset = 0;
 666    } else {
 667      $sign    = (substr($timezone, 0, 1) == '+') ? 1 : -1;
 668      $hours   = intval(substr($timezone, 1, 2));
 669      $minutes = intval(substr($timezone, 3, 4)) / 60;
 670      $offset  = $sign * 3600 * ($hours + $minutes);
 671    }
 672    return $offset;
 673  }
 674  
 675  // converts an iso8601 date to MySQL DateTime format used by post_date[_gmt]
 676  function iso8601_to_datetime($date_string, $timezone = USER) {
 677    if ($timezone == GMT) {
 678      preg_match('#([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(Z|[\+|\-][0-9]{2,4}){0,1}#', $date_string, $date_bits);
 679      if (!empty($date_bits[7])) { // we have a timezone, so let's compute an offset
 680        $offset = iso8601_timezone_to_offset($date_bits[7]);
 681      } else { // we don't have a timezone, so we assume user local timezone (not server's!)
 682        $offset = 3600 * get_settings('gmt_offset');
 683      }
 684      $timestamp = gmmktime($date_bits[4], $date_bits[5], $date_bits[6], $date_bits[2], $date_bits[3], $date_bits[1]);
 685      $timestamp -= $offset;
 686      return gmdate('Y-m-d H:i:s', $timestamp);
 687    } elseif ($timezone == USER) {
 688      return preg_replace('#([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(Z|[\+|\-][0-9]{2,4}){0,1}#', '$1-$2-$3 $4:$5:$6', $date_string);
 689    }
 690  }
 691  
 692  function popuplinks($text) {
 693      // Comment text in popup windows should be filtered through this.
 694      // Right now it's a moderately dumb function, ideally it would detect whether
 695      // a target or rel attribute was already there and adjust its actions accordingly.
 696      $text = preg_replace('/<a (.+?)>/i', "<a $1 target='_blank' rel='external'>", $text);
 697      return $text;
 698  }
 699  
 700  function sanitize_email($email) {
 701      return preg_replace('/[^a-z0-9+_.@-]/i', '', $email);
 702  }
 703  
 704  function human_time_diff( $from, $to = '' ) {     
 705      if ( empty($to) )
 706          $to = time();
 707      $diff = (int) abs($to - $from);
 708      if ($diff <= 3600) {
 709          $mins = round($diff / 60);
 710          if ($mins <= 1)
 711              $since = __('1 min');
 712          else
 713              $since = sprintf( __('%s mins'), $mins);
 714      } else if (($diff <= 86400) && ($diff > 3600)) {
 715          $hours = round($diff / 3600);
 716          if ($hours <= 1)
 717              $since = __('1 hour');
 718          else 
 719              $since = sprintf( __('%s hours'), $hours );
 720      } elseif ($diff >= 86400) {
 721          $days = round($diff / 86400);
 722          if ($days <= 1)
 723              $since = __('1 day');
 724          else
 725              $since = sprintf( __('%s days'), $days );
 726      }
 727      return $since;
 728  }
 729  
 730  function wp_trim_excerpt($text) { // Fakes an excerpt if needed
 731      global $post;
 732      if ( '' == $text ) {
 733          $text = $post->post_content;
 734          $text = apply_filters('the_content', $text);
 735          $text = str_replace(']]>', ']]&gt;', $text);
 736          $text = strip_tags($text);
 737          $excerpt_length = 55;
 738          $words = explode(' ', $text, $excerpt_length + 1);
 739          if (count($words) > $excerpt_length) {
 740              array_pop($words);
 741              array_push($words, '[...]');
 742              $text = implode(' ', $words);
 743          }
 744      }
 745      return $text;
 746  }
 747  
 748  function ent2ncr($text) {
 749      $to_ncr = array(
 750          '&quot;' => '&#34;',
 751          '&amp;' => '&#38;',
 752          '&frasl;' => '&#47;',
 753          '&lt;' => '&#60;',
 754          '&gt;' => '&#62;',
 755          '|' => '&#124;',
 756          '&nbsp;' => '&#160;',
 757          '&iexcl;' => '&#161;',
 758          '&cent;' => '&#162;',
 759          '&pound;' => '&#163;',
 760          '&curren;' => '&#164;',
 761          '&yen;' => '&#165;',
 762          '&brvbar;' => '&#166;',
 763          '&brkbar;' => '&#166;',
 764          '&sect;' => '&#167;',
 765          '&uml;' => '&#168;',
 766          '&die;' => '&#168;',
 767          '&copy;' => '&#169;',
 768          '&ordf;' => '&#170;',
 769          '&laquo;' => '&#171;',
 770          '&not;' => '&#172;',
 771          '&shy;' => '&#173;',
 772          '&reg;' => '&#174;',
 773          '&macr;' => '&#175;',
 774          '&hibar;' => '&#175;',
 775          '&deg;' => '&#176;',
 776          '&plusmn;' => '&#177;',
 777          '&sup2;' => '&#178;',
 778          '&sup3;' => '&#179;',
 779          '&acute;' => '&#180;',
 780          '&micro;' => '&#181;',
 781          '&para;' => '&#182;',
 782          '&middot;' => '&#183;',
 783          '&cedil;' => '&#184;',
 784          '&sup1;' => '&#185;',
 785          '&ordm;' => '&#186;',
 786          '&raquo;' => '&#187;',
 787          '&frac14;' => '&#188;',
 788          '&frac12;' => '&#189;',
 789          '&frac34;' => '&#190;',
 790          '&iquest;' => '&#191;',
 791          '&Agrave;' => '&#192;',
 792          '&Aacute;' => '&#193;',
 793          '&Acirc;' => '&#194;',
 794          '&Atilde;' => '&#195;',
 795          '&Auml;' => '&#196;',
 796          '&Aring;' => '&#197;',
 797          '&AElig;' => '&#198;',
 798          '&Ccedil;' => '&#199;',
 799          '&Egrave;' => '&#200;',
 800          '&Eacute;' => '&#201;',
 801          '&Ecirc;' => '&#202;',
 802          '&Euml;' => '&#203;',
 803          '&Igrave;' => '&#204;',
 804          '&Iacute;' => '&#205;',
 805          '&Icirc;' => '&#206;',
 806          '&Iuml;' => '&#207;',
 807          '&ETH;' => '&#208;',
 808          '&Ntilde;' => '&#209;',
 809          '&Ograve;' => '&#210;',
 810          '&Oacute;' => '&#211;',
 811          '&Ocirc;' => '&#212;',
 812          '&Otilde;' => '&#213;',
 813          '&Ouml;' => '&#214;',
 814          '&times;' => '&#215;',
 815          '&Oslash;' => '&#216;',
 816          '&Ugrave;' => '&#217;',
 817          '&Uacute;' => '&#218;',
 818          '&Ucirc;' => '&#219;',
 819          '&Uuml;' => '&#220;',
 820          '&Yacute;' => '&#221;',
 821          '&THORN;' => '&#222;',
 822          '&szlig;' => '&#223;',
 823          '&agrave;' => '&#224;',
 824          '&aacute;' => '&#225;',
 825          '&acirc;' => '&#226;',
 826          '&atilde;' => '&#227;',
 827          '&auml;' => '&#228;',
 828          '&aring;' => '&#229;',
 829          '&aelig;' => '&#230;',
 830          '&ccedil;' => '&#231;',
 831          '&egrave;' => '&#232;',
 832          '&eacute;' => '&#233;',
 833          '&ecirc;' => '&#234;',
 834          '&euml;' => '&#235;',
 835          '&igrave;' => '&#236;',
 836          '&iacute;' => '&#237;',
 837          '&icirc;' => '&#238;',
 838          '&iuml;' => '&#239;',
 839          '&eth;' => '&#240;',
 840          '&ntilde;' => '&#241;',
 841          '&ograve;' => '&#242;',
 842          '&oacute;' => '&#243;',
 843          '&ocirc;' => '&#244;',
 844          '&otilde;' => '&#245;',
 845          '&ouml;' => '&#246;',
 846          '&divide;' => '&#247;',
 847          '&oslash;' => '&#248;',
 848          '&ugrave;' => '&#249;',
 849          '&uacute;' => '&#250;',
 850          '&ucirc;' => '&#251;',
 851          '&uuml;' => '&#252;',
 852          '&yacute;' => '&#253;',
 853          '&thorn;' => '&#254;',
 854          '&yuml;' => '&#255;',
 855          '&OElig;' => '&#338;',
 856          '&oelig;' => '&#339;',
 857          '&Scaron;' => '&#352;',
 858          '&scaron;' => '&#353;',
 859          '&Yuml;' => '&#376;',
 860          '&fnof;' => '&#402;',
 861          '&circ;' => '&#710;',
 862          '&tilde;' => '&#732;',
 863          '&Alpha;' => '&#913;',
 864          '&Beta;' => '&#914;',
 865          '&Gamma;' => '&#915;',
 866          '&Delta;' => '&#916;',
 867          '&Epsilon;' => '&#917;',
 868          '&Zeta;' => '&#918;',
 869          '&Eta;' => '&#919;',
 870          '&Theta;' => '&#920;',
 871          '&Iota;' => '&#921;',
 872          '&Kappa;' => '&#922;',
 873          '&Lambda;' => '&#923;',
 874          '&Mu;' => '&#924;',
 875          '&Nu;' => '&#925;',
 876          '&Xi;' => '&#926;',
 877          '&Omicron;' => '&#927;',
 878          '&Pi;' => '&#928;',
 879          '&Rho;' => '&#929;',
 880          '&Sigma;' => '&#931;',
 881          '&Tau;' => '&#932;',
 882          '&Upsilon;' => '&#933;',
 883          '&Phi;' => '&#934;',
 884          '&Chi;' => '&#935;',
 885          '&Psi;' => '&#936;',
 886          '&Omega;' => '&#937;',
 887          '&alpha;' => '&#945;',
 888          '&beta;' => '&#946;',
 889          '&gamma;' => '&#947;',
 890          '&delta;' => '&#948;',
 891          '&epsilon;' => '&#949;',
 892          '&zeta;' => '&#950;',
 893          '&eta;' => '&#951;',
 894          '&theta;' => '&#952;',
 895          '&iota;' => '&#953;',
 896          '&kappa;' => '&#954;',
 897          '&lambda;' => '&#955;',
 898          '&mu;' => '&#956;',
 899          '&nu;' => '&#957;',
 900          '&xi;' => '&#958;',
 901          '&omicron;' => '&#959;',
 902          '&pi;' => '&#960;',
 903          '&rho;' => '&#961;',
 904          '&sigmaf;' => '&#962;',
 905          '&sigma;' => '&#963;',
 906          '&tau;' => '&#964;',
 907          '&upsilon;' => '&#965;',
 908          '&phi;' => '&#966;',
 909          '&chi;' => '&#967;',
 910          '&psi;' => '&#968;',
 911          '&omega;' => '&#969;',
 912          '&thetasym;' => '&#977;',
 913          '&upsih;' => '&#978;',
 914          '&piv;' => '&#982;',
 915          '&ensp;' => '&#8194;',
 916          '&emsp;' => '&#8195;',
 917          '&thinsp;' => '&#8201;',
 918          '&zwnj;' => '&#8204;',
 919          '&zwj;' => '&#8205;',
 920          '&lrm;' => '&#8206;',
 921          '&rlm;' => '&#8207;',
 922          '&ndash;' => '&#8211;',
 923          '&mdash;' => '&#8212;',
 924          '&lsquo;' => '&#8216;',
 925          '&rsquo;' => '&#8217;',
 926          '&sbquo;' => '&#8218;',
 927          '&ldquo;' => '&#8220;',
 928          '&rdquo;' => '&#8221;',
 929          '&bdquo;' => '&#8222;',
 930          '&dagger;' => '&#8224;',
 931          '&Dagger;' => '&#8225;',
 932          '&bull;' => '&#8226;',
 933          '&hellip;' => '&#8230;',
 934          '&permil;' => '&#8240;',
 935          '&prime;' => '&#8242;',
 936          '&Prime;' => '&#8243;',
 937          '&lsaquo;' => '&#8249;',
 938          '&rsaquo;' => '&#8250;',
 939          '&oline;' => '&#8254;',
 940          '&frasl;' => '&#8260;',
 941          '&euro;' => '&#8364;',
 942          '&image;' => '&#8465;',
 943          '&weierp;' => '&#8472;',
 944          '&real;' => '&#8476;',
 945          '&trade;' => '&#8482;',
 946          '&alefsym;' => '&#8501;',
 947          '&crarr;' => '&#8629;',
 948          '&lArr;' => '&#8656;',
 949          '&uArr;' => '&#8657;',
 950          '&rArr;' => '&#8658;',
 951          '&dArr;' => '&#8659;',
 952          '&hArr;' => '&#8660;',
 953          '&forall;' => '&#8704;',
 954          '&part;' => '&#8706;',
 955          '&exist;' => '&#8707;',
 956          '&empty;' => '&#8709;',
 957          '&nabla;' => '&#8711;',
 958          '&isin;' => '&#8712;',
 959          '&notin;' => '&#8713;',
 960          '&ni;' => '&#8715;',
 961          '&prod;' => '&#8719;',
 962          '&sum;' => '&#8721;',
 963          '&minus;' => '&#8722;',
 964          '&lowast;' => '&#8727;',
 965          '&radic;' => '&#8730;',
 966          '&prop;' => '&#8733;',
 967          '&infin;' => '&#8734;',
 968          '&ang;' => '&#8736;',
 969          '&and;' => '&#8743;',
 970          '&or;' => '&#8744;',
 971          '&cap;' => '&#8745;',
 972          '&cup;' => '&#8746;',
 973          '&int;' => '&#8747;',
 974          '&there4;' => '&#8756;',
 975          '&sim;' => '&#8764;',
 976          '&cong;' => '&#8773;',
 977          '&asymp;' => '&#8776;',
 978          '&ne;' => '&#8800;',
 979          '&equiv;' => '&#8801;',
 980          '&le;' => '&#8804;',
 981          '&ge;' => '&#8805;',
 982          '&sub;' => '&#8834;',
 983          '&sup;' => '&#8835;',
 984          '&nsub;' => '&#8836;',
 985          '&sube;' => '&#8838;',
 986          '&supe;' => '&#8839;',
 987          '&oplus;' => '&#8853;',
 988          '&otimes;' => '&#8855;',
 989          '&perp;' => '&#8869;',
 990          '&sdot;' => '&#8901;',
 991          '&lceil;' => '&#8968;',
 992          '&rceil;' => '&#8969;',
 993          '&lfloor;' => '&#8970;',
 994          '&rfloor;' => '&#8971;',
 995          '&lang;' => '&#9001;',
 996          '&rang;' => '&#9002;',
 997          '&larr;' => '&#8592;',
 998          '&uarr;' => '&#8593;',
 999          '&rarr;' => '&#8594;',
1000          '&darr;' => '&#8595;',
1001          '&harr;' => '&#8596;',
1002          '&loz;' => '&#9674;',
1003          '&spades;' => '&#9824;',
1004          '&clubs;' => '&#9827;',
1005          '&hearts;' => '&#9829;',
1006          '&diams;' => '&#9830;'
1007      );
1008  
1009      return str_replace( array_keys($to_ncr), array_values($to_ncr), $text );
1010  }
1011  
1012  function wp_richedit_pre($text) {
1013      // Filtering a blank results in an annoying <br />\n
1014      if ( empty($text) ) return apply_filters('richedit_pre', '');
1015  
1016      $output = $text;
1017      $output = convert_chars($output);
1018      $output = wpautop($output);
1019  
1020      // These must be double-escaped or planets will collide.
1021      $output = str_replace('&lt;', '&amp;lt;', $output);
1022      $output = str_replace('&gt;', '&amp;gt;', $output);
1023  
1024      return apply_filters('richedit_pre', $output);
1025  }
1026  
1027  function clean_url( $url ) {
1028      if ('' == $url) return $url;
1029      $url = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $url);
1030      $url = str_replace(';//', '://', $url);
1031      $url = (!strstr($url, '://')) ? 'http://'.$url : $url;
1032      $url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&#038;$1', $url);
1033      return $url;
1034  }
1035  
1036  // Borrowed from the PHP Manual user notes. Convert entities, while
1037  // preserving already-encoded entities:
1038  function htmlentities2($myHTML) {
1039      $translation_table=get_html_translation_table (HTML_ENTITIES,ENT_QUOTES);
1040      $translation_table[chr(38)] = '&';
1041      return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/","&amp;" , strtr($myHTML, $translation_table));
1042  }
1043  
1044  // Escape single quotes, specialchar double quotes, and fix line endings.
1045  function js_escape($text) {
1046      $text = wp_specialchars($text, 'double');
1047      return preg_replace("/\r?\n/", "\\n", addslashes($text));    
1048  }
1049  ?>

Your comment here...

Name: Location:
Comments:


List: Classes | Functions | Variables | Constants | Tables

Generated: Sun Jun 11 00:10:35 2006 Courtesy of Taragana