[ Index ]

WordPress Source Cross Reference

title

Body

[close]

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

Your comment here...

Name: Location:
Comments:


List: Classes | Functions | Variables | Constants | Tables

Generated: Sat Jul 15 11:57:04 2006 Courtesy of Taragana