raw
mp-wp_genesis           1 <?php

mp-wp_genesis 2 /**
mp-wp_genesis 3 * Main Wordpress Formatting API.
mp-wp_genesis 4 *
mp-wp_genesis 5 * Handles many functions for formatting output.
mp-wp_genesis 6 *
mp-wp_genesis 7 * @package WordPress
mp-wp_genesis 8 **/
mp-wp_genesis 9
mp-wp_genesis 10 /**
mp-wp_genesis 11 * Replaces common plain text characters into formatted entities
mp-wp_genesis 12 *
mp-wp_genesis 13 * As an example,
mp-wp_genesis 14 * <code>
mp-wp_genesis 15 * 'cause today's effort makes it worth tomorrow's "holiday"...
mp-wp_genesis 16 * </code>
mp-wp_genesis 17 * Becomes:
mp-wp_genesis 18 * <code>
mp-wp_genesis 19 * &#8217;cause today&#8217;s effort makes it worth tomorrow&#8217;s &#8220;holiday&#8221;&#8230;
mp-wp_genesis 20 * </code>
mp-wp_genesis 21 * Code within certain html blocks are skipped.
mp-wp_genesis 22 *
mp-wp_genesis 23 * @since 0.71
mp-wp_genesis 24 * @uses $wp_cockneyreplace Array of formatted entities for certain common phrases
mp-wp_genesis 25 *
mp-wp_genesis 26 * @param string $text The text to be formatted
mp-wp_genesis 27 * @return string The string replaced with html entities
mp-wp_genesis 28 */
mp-wp_genesis 29 function wptexturize($text) {
mp-wp_genesis 30 /* global $wp_cockneyreplace;
mp-wp_genesis 31 $next = true;
mp-wp_genesis 32 $has_pre_parent = false;
mp-wp_genesis 33 $output = '';
mp-wp_genesis 34 $curl = '';
mp-wp_genesis 35 $textarr = preg_split('/(<.*>|\[.*\])/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
mp-wp_genesis 36 $stop = count($textarr);
mp-wp_genesis 37
mp-wp_genesis 38 // if a plugin has provided an autocorrect array, use it
mp-wp_genesis 39 if ( isset($wp_cockneyreplace) ) {
mp-wp_genesis 40 $cockney = array_keys($wp_cockneyreplace);
mp-wp_genesis 41 $cockneyreplace = array_values($wp_cockneyreplace);
mp-wp_genesis 42 } else {
mp-wp_genesis 43 $cockney = array("'tain't","'twere","'twas","'tis","'twill","'til","'bout","'nuff","'round","'cause");
mp-wp_genesis 44 $cockneyreplace = array("&#8217;tain&#8217;t","&#8217;twere","&#8217;twas","&#8217;tis","&#8217;twill","&#8217;til","&#8217;bout","&#8217;nuff","&#8217;round","&#8217;cause");
mp-wp_genesis 45 }
mp-wp_genesis 46
mp-wp_genesis 47 $static_characters = array_merge(array('---', ' -- ', '--', 'xn&#8211;', '...', '``', '\'s', '\'\'', ' (tm)'), $cockney);
mp-wp_genesis 48 $static_replacements = array_merge(array('&#8212;', ' &#8212; ', '&#8211;', 'xn--', '&#8230;', '&#8220;', '&#8217;s', '&#8221;', ' &#8482;'), $cockneyreplace);
mp-wp_genesis 49
mp-wp_genesis 50 $dynamic_characters = array('/\'(\d\d(?:&#8217;|\')?s)/', '/(\s|\A|")\'/', '/(\d+)"/', '/(\d+)\'/', '/(\S)\'([^\'\s])/', '/(\s|\A)"(?!\s)/', '/"(\s|\S|\Z)/', '/\'([\s.]|\Z)/', '/(\d+)x(\d+)/');
mp-wp_genesis 51 $dynamic_replacements = array('&#8217;$1','$1&#8216;', '$1&#8243;', '$1&#8242;', '$1&#8217;$2', '$1&#8220;$2', '&#8221;$1', '&#8217;$1', '$1&#215;$2');
mp-wp_genesis 52
mp-wp_genesis 53 for ( $i = 0; $i < $stop; $i++ ) {
mp-wp_genesis 54 $curl = $textarr[$i];
mp-wp_genesis 55
mp-wp_genesis 56 if ( !empty($curl) && '<' != $curl{0} && '[' != $curl{0} && $next && !$has_pre_parent) { // If it's not a tag
mp-wp_genesis 57 // static strings
mp-wp_genesis 58 $curl = str_replace($static_characters, $static_replacements, $curl);
mp-wp_genesis 59 // regular expressions
mp-wp_genesis 60 $curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl);
mp-wp_genesis 61 } elseif (strpos($curl, '<code') !== false || strpos($curl, '<kbd') !== false || strpos($curl, '<style') !== false || strpos($curl, '<script') !== false) {
mp-wp_genesis 62 $next = false;
mp-wp_genesis 63 } elseif (strpos($curl, '<pre') !== false) {
mp-wp_genesis 64 $has_pre_parent = true;
mp-wp_genesis 65 } elseif (strpos($curl, '</pre>') !== false) {
mp-wp_genesis 66 $has_pre_parent = false;
mp-wp_genesis 67 } else {
mp-wp_genesis 68 $next = true;
mp-wp_genesis 69 }
mp-wp_genesis 70
mp-wp_genesis 71 $curl = preg_replace('/&([^#])(?![a-zA-Z1-4]{1,8};)/', '&#038;$1', $curl);
mp-wp_genesis 72 $output .= $curl;
mp-wp_genesis 73 }
mp-wp_genesis 74
mp-wp_genesis 75 return $output;
mp-wp_genesis 76 */
mp-wp_genesis 77 return $text;
mp-wp_genesis 78 }
mp-wp_genesis 79
mp-wp_genesis 80 /**
mp-wp_genesis 81 * Accepts matches array from preg_replace_callback in wpautop() or a string.
mp-wp_genesis 82 *
mp-wp_genesis 83 * Ensures that the contents of a <<pre>>...<</pre>> HTML block are not
mp-wp_genesis 84 * converted into paragraphs or line-breaks.
mp-wp_genesis 85 *
mp-wp_genesis 86 * @since 1.2.0
mp-wp_genesis 87 *
mp-wp_genesis 88 * @param array|string $matches The array or string
mp-wp_genesis 89 * @return string The pre block without paragraph/line-break conversion.
mp-wp_genesis 90 */
mp-wp_genesis 91 function clean_pre($matches) {
mp-wp_genesis 92 if ( is_array($matches) )
mp-wp_genesis 93 $text = $matches[1] . $matches[2] . "</pre>";
mp-wp_genesis 94 else
mp-wp_genesis 95 $text = $matches;
mp-wp_genesis 96
mp-wp_genesis 97 $text = str_replace('<br />', '', $text);
mp-wp_genesis 98 $text = str_replace('<p>', "\n", $text);
mp-wp_genesis 99 $text = str_replace('</p>', '', $text);
mp-wp_genesis 100
mp-wp_genesis 101 return $text;
mp-wp_genesis 102 }
mp-wp_genesis 103
mp-wp_genesis 104 /**
mp-wp_genesis 105 * Replaces double line-breaks with paragraph elements.
mp-wp_genesis 106 *
mp-wp_genesis 107 * A group of regex replaces used to identify text formatted with newlines and
mp-wp_genesis 108 * replace double line-breaks with HTML paragraph tags. The remaining
mp-wp_genesis 109 * line-breaks after conversion become <<br />> tags, unless $br is set to '0'
mp-wp_genesis 110 * or 'false'.
mp-wp_genesis 111 *
mp-wp_genesis 112 * @since 0.71
mp-wp_genesis 113 *
mp-wp_genesis 114 * @param string $pee The text which has to be formatted.
mp-wp_genesis 115 * @param int|bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true.
mp-wp_genesis 116 * @return string Text which has been converted into correct paragraph tags.
mp-wp_genesis 117 */
mp-wp_genesis 118 function wpautop($pee, $br = 1) {
mp-wp_genesis 119 $pee = $pee . "\n"; // just to make things a little easier, pad the end
mp-wp_genesis 120 $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee);
mp-wp_genesis 121 // Space things out a little
mp-wp_genesis 122 $allblocks = '(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|map|area|blockquote|address|math|style|input|p|h[1-6]|hr)';
mp-wp_genesis 123 $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee);
mp-wp_genesis 124 $pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee);
mp-wp_genesis 125 $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines
mp-wp_genesis 126 if ( strpos($pee, '<object') !== false ) {
mp-wp_genesis 127 $pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param$1>", $pee); // no pee inside object/embed
mp-wp_genesis 128 $pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee);
mp-wp_genesis 129 }
mp-wp_genesis 130 $pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates
mp-wp_genesis 131 // make paragraphs, including one at the end
mp-wp_genesis 132 $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
mp-wp_genesis 133 $pee = '';
mp-wp_genesis 134 foreach ( $pees as $tinkle )
mp-wp_genesis 135 $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
mp-wp_genesis 136 $pee = preg_replace('|<p>\s*?</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace
mp-wp_genesis 137 $pee = preg_replace('!<p>([^<]+)\s*?(</(?:div|address|form)[^>]*>)!', "<p>$1</p>$2", $pee);
mp-wp_genesis 138 $pee = preg_replace( '|<p>|', "$1<p>", $pee );
mp-wp_genesis 139 $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee); // don't pee all over a tag
mp-wp_genesis 140 $pee = preg_replace("|<p>(<li.+?)</p>|", "$1", $pee); // problem with nested lists
mp-wp_genesis 141 $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee);
mp-wp_genesis 142 $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
mp-wp_genesis 143 $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee);
mp-wp_genesis 144 $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee);
mp-wp_genesis 145 if ($br) {
mp-wp_genesis 146 $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', create_function('$matches', 'return str_replace("\n", "<WPPreserveNewline />", $matches[0]);'), $pee);
mp-wp_genesis 147 $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks
mp-wp_genesis 148 $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
mp-wp_genesis 149 }
mp-wp_genesis 150 $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $pee);
mp-wp_genesis 151 $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
mp-wp_genesis 152 if (strpos($pee, '<pre') !== false)
mp-wp_genesis 153 $pee = preg_replace_callback('!(<pre.*?>)(.*?)</pre>!is', 'clean_pre', $pee );
mp-wp_genesis 154 $pee = preg_replace( "|\n</p>$|", '</p>', $pee );
mp-wp_genesis 155 $pee = preg_replace('/<p>\s*?(' . get_shortcode_regex() . ')\s*<\/p>/s', '$1', $pee); // don't auto-p wrap shortcodes that stand alone
mp-wp_genesis 156
mp-wp_genesis 157 return $pee;
mp-wp_genesis 158 }
mp-wp_genesis 159
mp-wp_genesis 160 /**
mp-wp_genesis 161 * Checks to see if a string is utf8 encoded.
mp-wp_genesis 162 *
mp-wp_genesis 163 * @author bmorel at ssi dot fr
mp-wp_genesis 164 *
mp-wp_genesis 165 * @since 1.2.1
mp-wp_genesis 166 *
mp-wp_genesis 167 * @param string $Str The string to be checked
mp-wp_genesis 168 * @return bool True if $Str fits a UTF-8 model, false otherwise.
mp-wp_genesis 169 */
mp-wp_genesis 170 function seems_utf8($Str) { # by bmorel at ssi dot fr
mp-wp_genesis 171 $length = strlen($Str);
mp-wp_genesis 172 for ($i=0; $i < $length; $i++) {
mp-wp_genesis 173 if (ord($Str[$i]) < 0x80) continue; # 0bbbbbbb
mp-wp_genesis 174 elseif ((ord($Str[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb
mp-wp_genesis 175 elseif ((ord($Str[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb
mp-wp_genesis 176 elseif ((ord($Str[$i]) & 0xF8) == 0xF0) $n=3; # 11110bbb
mp-wp_genesis 177 elseif ((ord($Str[$i]) & 0xFC) == 0xF8) $n=4; # 111110bb
mp-wp_genesis 178 elseif ((ord($Str[$i]) & 0xFE) == 0xFC) $n=5; # 1111110b
mp-wp_genesis 179 else return false; # Does not match any model
mp-wp_genesis 180 for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ?
mp-wp_genesis 181 if ((++$i == $length) || ((ord($Str[$i]) & 0xC0) != 0x80))
mp-wp_genesis 182 return false;
mp-wp_genesis 183 }
mp-wp_genesis 184 }
mp-wp_genesis 185 return true;
mp-wp_genesis 186 }
mp-wp_genesis 187
mp-wp_genesis 188 /**
mp-wp_genesis 189 * Converts a number of special characters into their HTML entities.
mp-wp_genesis 190 *
mp-wp_genesis 191 * Differs from htmlspecialchars as existing HTML entities will not be encoded.
mp-wp_genesis 192 * Specifically changes: & to &#038;, < to &lt; and > to &gt;.
mp-wp_genesis 193 *
mp-wp_genesis 194 * $quotes can be set to 'single' to encode ' to &#039;, 'double' to encode " to
mp-wp_genesis 195 * &quot;, or '1' to do both. Default is 0 where no quotes are encoded.
mp-wp_genesis 196 *
mp-wp_genesis 197 * @since 1.2.2
mp-wp_genesis 198 *
mp-wp_genesis 199 * @param string $text The text which is to be encoded.
mp-wp_genesis 200 * @param mixed $quotes Optional. Converts single quotes if set to 'single', double if set to 'double' or both if otherwise set. Default 0.
mp-wp_genesis 201 * @return string The encoded text with HTML entities.
mp-wp_genesis 202 */
mp-wp_genesis 203 function wp_specialchars( $text, $quotes = 0 ) {
mp-wp_genesis 204 // Like htmlspecialchars except don't double-encode HTML entities
mp-wp_genesis 205 $text = str_replace('&&', '&#038;&', $text);
mp-wp_genesis 206 $text = str_replace('&&', '&#038;&', $text);
mp-wp_genesis 207 $text = preg_replace('/&(?:$|([^#])(?![a-z1-4]{1,8};))/', '&#038;$1', $text);
mp-wp_genesis 208 $text = str_replace('<', '&lt;', $text);
mp-wp_genesis 209 $text = str_replace('>', '&gt;', $text);
mp-wp_genesis 210 if ( 'double' === $quotes ) {
mp-wp_genesis 211 $text = str_replace('"', '&quot;', $text);
mp-wp_genesis 212 } elseif ( 'single' === $quotes ) {
mp-wp_genesis 213 $text = str_replace("'", '&#039;', $text);
mp-wp_genesis 214 } elseif ( $quotes ) {
mp-wp_genesis 215 $text = str_replace('"', '&quot;', $text);
mp-wp_genesis 216 $text = str_replace("'", '&#039;', $text);
mp-wp_genesis 217 }
mp-wp_genesis 218 return $text;
mp-wp_genesis 219 }
mp-wp_genesis 220
mp-wp_genesis 221 /**
mp-wp_genesis 222 * Encode the Unicode values to be used in the URI.
mp-wp_genesis 223 *
mp-wp_genesis 224 * @since 1.5.0
mp-wp_genesis 225 *
mp-wp_genesis 226 * @param string $utf8_string
mp-wp_genesis 227 * @param int $length Max length of the string
mp-wp_genesis 228 * @return string String with Unicode encoded for URI.
mp-wp_genesis 229 */
mp-wp_genesis 230 function utf8_uri_encode( $utf8_string, $length = 0 ) {
mp-wp_genesis 231 $unicode = '';
mp-wp_genesis 232 $values = array();
mp-wp_genesis 233 $num_octets = 1;
mp-wp_genesis 234 $unicode_length = 0;
mp-wp_genesis 235
mp-wp_genesis 236 $string_length = strlen( $utf8_string );
mp-wp_genesis 237 for ($i = 0; $i < $string_length; $i++ ) {
mp-wp_genesis 238
mp-wp_genesis 239 $value = ord( $utf8_string[ $i ] );
mp-wp_genesis 240
mp-wp_genesis 241 if ( $value < 128 ) {
mp-wp_genesis 242 if ( $length && ( $unicode_length >= $length ) )
mp-wp_genesis 243 break;
mp-wp_genesis 244 $unicode .= chr($value);
mp-wp_genesis 245 $unicode_length++;
mp-wp_genesis 246 } else {
mp-wp_genesis 247 if ( count( $values ) == 0 ) $num_octets = ( $value < 224 ) ? 2 : 3;
mp-wp_genesis 248
mp-wp_genesis 249 $values[] = $value;
mp-wp_genesis 250
mp-wp_genesis 251 if ( $length && ( $unicode_length + ($num_octets * 3) ) > $length )
mp-wp_genesis 252 break;
mp-wp_genesis 253 if ( count( $values ) == $num_octets ) {
mp-wp_genesis 254 if ($num_octets == 3) {
mp-wp_genesis 255 $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]);
mp-wp_genesis 256 $unicode_length += 9;
mp-wp_genesis 257 } else {
mp-wp_genesis 258 $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]);
mp-wp_genesis 259 $unicode_length += 6;
mp-wp_genesis 260 }
mp-wp_genesis 261
mp-wp_genesis 262 $values = array();
mp-wp_genesis 263 $num_octets = 1;
mp-wp_genesis 264 }
mp-wp_genesis 265 }
mp-wp_genesis 266 }
mp-wp_genesis 267
mp-wp_genesis 268 return $unicode;
mp-wp_genesis 269 }
mp-wp_genesis 270
mp-wp_genesis 271 /**
mp-wp_genesis 272 * Converts all accent characters to ASCII characters.
mp-wp_genesis 273 *
mp-wp_genesis 274 * If there are no accent characters, then the string given is just returned.
mp-wp_genesis 275 *
mp-wp_genesis 276 * @since 1.2.1
mp-wp_genesis 277 *
mp-wp_genesis 278 * @param string $string Text that might have accent characters
mp-wp_genesis 279 * @return string Filtered string with replaced "nice" characters.
mp-wp_genesis 280 */
mp-wp_genesis 281 function remove_accents($string) {
mp-wp_genesis 282 if ( !preg_match('/[\x80-\xff]/', $string) )
mp-wp_genesis 283 return $string;
mp-wp_genesis 284
mp-wp_genesis 285 if (seems_utf8($string)) {
mp-wp_genesis 286 $chars = array(
mp-wp_genesis 287 // Decompositions for Latin-1 Supplement
mp-wp_genesis 288 chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
mp-wp_genesis 289 chr(195).chr(130) => 'A', chr(195).chr(131) => 'A',
mp-wp_genesis 290 chr(195).chr(132) => 'A', chr(195).chr(133) => 'A',
mp-wp_genesis 291 chr(195).chr(135) => 'C', chr(195).chr(136) => 'E',
mp-wp_genesis 292 chr(195).chr(137) => 'E', chr(195).chr(138) => 'E',
mp-wp_genesis 293 chr(195).chr(139) => 'E', chr(195).chr(140) => 'I',
mp-wp_genesis 294 chr(195).chr(141) => 'I', chr(195).chr(142) => 'I',
mp-wp_genesis 295 chr(195).chr(143) => 'I', chr(195).chr(145) => 'N',
mp-wp_genesis 296 chr(195).chr(146) => 'O', chr(195).chr(147) => 'O',
mp-wp_genesis 297 chr(195).chr(148) => 'O', chr(195).chr(149) => 'O',
mp-wp_genesis 298 chr(195).chr(150) => 'O', chr(195).chr(153) => 'U',
mp-wp_genesis 299 chr(195).chr(154) => 'U', chr(195).chr(155) => 'U',
mp-wp_genesis 300 chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y',
mp-wp_genesis 301 chr(195).chr(159) => 's', chr(195).chr(160) => 'a',
mp-wp_genesis 302 chr(195).chr(161) => 'a', chr(195).chr(162) => 'a',
mp-wp_genesis 303 chr(195).chr(163) => 'a', chr(195).chr(164) => 'a',
mp-wp_genesis 304 chr(195).chr(165) => 'a', chr(195).chr(167) => 'c',
mp-wp_genesis 305 chr(195).chr(168) => 'e', chr(195).chr(169) => 'e',
mp-wp_genesis 306 chr(195).chr(170) => 'e', chr(195).chr(171) => 'e',
mp-wp_genesis 307 chr(195).chr(172) => 'i', chr(195).chr(173) => 'i',
mp-wp_genesis 308 chr(195).chr(174) => 'i', chr(195).chr(175) => 'i',
mp-wp_genesis 309 chr(195).chr(177) => 'n', chr(195).chr(178) => 'o',
mp-wp_genesis 310 chr(195).chr(179) => 'o', chr(195).chr(180) => 'o',
mp-wp_genesis 311 chr(195).chr(181) => 'o', chr(195).chr(182) => 'o',
mp-wp_genesis 312 chr(195).chr(182) => 'o', chr(195).chr(185) => 'u',
mp-wp_genesis 313 chr(195).chr(186) => 'u', chr(195).chr(187) => 'u',
mp-wp_genesis 314 chr(195).chr(188) => 'u', chr(195).chr(189) => 'y',
mp-wp_genesis 315 chr(195).chr(191) => 'y',
mp-wp_genesis 316 // Decompositions for Latin Extended-A
mp-wp_genesis 317 chr(196).chr(128) => 'A', chr(196).chr(129) => 'a',
mp-wp_genesis 318 chr(196).chr(130) => 'A', chr(196).chr(131) => 'a',
mp-wp_genesis 319 chr(196).chr(132) => 'A', chr(196).chr(133) => 'a',
mp-wp_genesis 320 chr(196).chr(134) => 'C', chr(196).chr(135) => 'c',
mp-wp_genesis 321 chr(196).chr(136) => 'C', chr(196).chr(137) => 'c',
mp-wp_genesis 322 chr(196).chr(138) => 'C', chr(196).chr(139) => 'c',
mp-wp_genesis 323 chr(196).chr(140) => 'C', chr(196).chr(141) => 'c',
mp-wp_genesis 324 chr(196).chr(142) => 'D', chr(196).chr(143) => 'd',
mp-wp_genesis 325 chr(196).chr(144) => 'D', chr(196).chr(145) => 'd',
mp-wp_genesis 326 chr(196).chr(146) => 'E', chr(196).chr(147) => 'e',
mp-wp_genesis 327 chr(196).chr(148) => 'E', chr(196).chr(149) => 'e',
mp-wp_genesis 328 chr(196).chr(150) => 'E', chr(196).chr(151) => 'e',
mp-wp_genesis 329 chr(196).chr(152) => 'E', chr(196).chr(153) => 'e',
mp-wp_genesis 330 chr(196).chr(154) => 'E', chr(196).chr(155) => 'e',
mp-wp_genesis 331 chr(196).chr(156) => 'G', chr(196).chr(157) => 'g',
mp-wp_genesis 332 chr(196).chr(158) => 'G', chr(196).chr(159) => 'g',
mp-wp_genesis 333 chr(196).chr(160) => 'G', chr(196).chr(161) => 'g',
mp-wp_genesis 334 chr(196).chr(162) => 'G', chr(196).chr(163) => 'g',
mp-wp_genesis 335 chr(196).chr(164) => 'H', chr(196).chr(165) => 'h',
mp-wp_genesis 336 chr(196).chr(166) => 'H', chr(196).chr(167) => 'h',
mp-wp_genesis 337 chr(196).chr(168) => 'I', chr(196).chr(169) => 'i',
mp-wp_genesis 338 chr(196).chr(170) => 'I', chr(196).chr(171) => 'i',
mp-wp_genesis 339 chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
mp-wp_genesis 340 chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
mp-wp_genesis 341 chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
mp-wp_genesis 342 chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
mp-wp_genesis 343 chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
mp-wp_genesis 344 chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
mp-wp_genesis 345 chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
mp-wp_genesis 346 chr(196).chr(186) => 'l', chr(196).chr(187) => 'L',
mp-wp_genesis 347 chr(196).chr(188) => 'l', chr(196).chr(189) => 'L',
mp-wp_genesis 348 chr(196).chr(190) => 'l', chr(196).chr(191) => 'L',
mp-wp_genesis 349 chr(197).chr(128) => 'l', chr(197).chr(129) => 'L',
mp-wp_genesis 350 chr(197).chr(130) => 'l', chr(197).chr(131) => 'N',
mp-wp_genesis 351 chr(197).chr(132) => 'n', chr(197).chr(133) => 'N',
mp-wp_genesis 352 chr(197).chr(134) => 'n', chr(197).chr(135) => 'N',
mp-wp_genesis 353 chr(197).chr(136) => 'n', chr(197).chr(137) => 'N',
mp-wp_genesis 354 chr(197).chr(138) => 'n', chr(197).chr(139) => 'N',
mp-wp_genesis 355 chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
mp-wp_genesis 356 chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
mp-wp_genesis 357 chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
mp-wp_genesis 358 chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
mp-wp_genesis 359 chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
mp-wp_genesis 360 chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
mp-wp_genesis 361 chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
mp-wp_genesis 362 chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
mp-wp_genesis 363 chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
mp-wp_genesis 364 chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
mp-wp_genesis 365 chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
mp-wp_genesis 366 chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
mp-wp_genesis 367 chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
mp-wp_genesis 368 chr(197).chr(166) => 'T', chr(197).chr(167) => 't',
mp-wp_genesis 369 chr(197).chr(168) => 'U', chr(197).chr(169) => 'u',
mp-wp_genesis 370 chr(197).chr(170) => 'U', chr(197).chr(171) => 'u',
mp-wp_genesis 371 chr(197).chr(172) => 'U', chr(197).chr(173) => 'u',
mp-wp_genesis 372 chr(197).chr(174) => 'U', chr(197).chr(175) => 'u',
mp-wp_genesis 373 chr(197).chr(176) => 'U', chr(197).chr(177) => 'u',
mp-wp_genesis 374 chr(197).chr(178) => 'U', chr(197).chr(179) => 'u',
mp-wp_genesis 375 chr(197).chr(180) => 'W', chr(197).chr(181) => 'w',
mp-wp_genesis 376 chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y',
mp-wp_genesis 377 chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z',
mp-wp_genesis 378 chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z',
mp-wp_genesis 379 chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z',
mp-wp_genesis 380 chr(197).chr(190) => 'z', chr(197).chr(191) => 's',
mp-wp_genesis 381 // Euro Sign
mp-wp_genesis 382 chr(226).chr(130).chr(172) => 'E',
mp-wp_genesis 383 // GBP (Pound) Sign
mp-wp_genesis 384 chr(194).chr(163) => '');
mp-wp_genesis 385
mp-wp_genesis 386 $string = strtr($string, $chars);
mp-wp_genesis 387 } else {
mp-wp_genesis 388 // Assume ISO-8859-1 if not UTF-8
mp-wp_genesis 389 $chars['in'] = chr(128).chr(131).chr(138).chr(142).chr(154).chr(158)
mp-wp_genesis 390 .chr(159).chr(162).chr(165).chr(181).chr(192).chr(193).chr(194)
mp-wp_genesis 391 .chr(195).chr(196).chr(197).chr(199).chr(200).chr(201).chr(202)
mp-wp_genesis 392 .chr(203).chr(204).chr(205).chr(206).chr(207).chr(209).chr(210)
mp-wp_genesis 393 .chr(211).chr(212).chr(213).chr(214).chr(216).chr(217).chr(218)
mp-wp_genesis 394 .chr(219).chr(220).chr(221).chr(224).chr(225).chr(226).chr(227)
mp-wp_genesis 395 .chr(228).chr(229).chr(231).chr(232).chr(233).chr(234).chr(235)
mp-wp_genesis 396 .chr(236).chr(237).chr(238).chr(239).chr(241).chr(242).chr(243)
mp-wp_genesis 397 .chr(244).chr(245).chr(246).chr(248).chr(249).chr(250).chr(251)
mp-wp_genesis 398 .chr(252).chr(253).chr(255);
mp-wp_genesis 399
mp-wp_genesis 400 $chars['out'] = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy";
mp-wp_genesis 401
mp-wp_genesis 402 $string = strtr($string, $chars['in'], $chars['out']);
mp-wp_genesis 403 $double_chars['in'] = array(chr(140), chr(156), chr(198), chr(208), chr(222), chr(223), chr(230), chr(240), chr(254));
mp-wp_genesis 404 $double_chars['out'] = array('OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th');
mp-wp_genesis 405 $string = str_replace($double_chars['in'], $double_chars['out'], $string);
mp-wp_genesis 406 }
mp-wp_genesis 407
mp-wp_genesis 408 return $string;
mp-wp_genesis 409 }
mp-wp_genesis 410
mp-wp_genesis 411 /**
mp-wp_genesis 412 * Filters certain characters from the file name.
mp-wp_genesis 413 *
mp-wp_genesis 414 * Turns all strings to lowercase removing most characters except alphanumeric
mp-wp_genesis 415 * with spaces, dashes and periods. All spaces and underscores are converted to
mp-wp_genesis 416 * dashes. Multiple dashes are converted to a single dash. Finally, if the file
mp-wp_genesis 417 * name ends with a dash, it is removed.
mp-wp_genesis 418 *
mp-wp_genesis 419 * @since 2.1.0
mp-wp_genesis 420 *
mp-wp_genesis 421 * @param string $name The file name
mp-wp_genesis 422 * @return string Sanitized file name
mp-wp_genesis 423 */
mp-wp_genesis 424 function sanitize_file_name( $name ) { // Like sanitize_title, but with periods
mp-wp_genesis 425 $name = strtolower( $name );
mp-wp_genesis 426 $name = preg_replace('/&.+?;/', '', $name); // kill entities
mp-wp_genesis 427 $name = str_replace( '_', '-', $name );
mp-wp_genesis 428 $name = preg_replace('/[^a-z0-9\s-.]/', '', $name);
mp-wp_genesis 429 $name = preg_replace('/\s+/', '-', $name);
mp-wp_genesis 430 $name = preg_replace('|-+|', '-', $name);
mp-wp_genesis 431 $name = trim($name, '-');
mp-wp_genesis 432 return $name;
mp-wp_genesis 433 }
mp-wp_genesis 434
mp-wp_genesis 435 /**
mp-wp_genesis 436 * Sanitize username stripping out unsafe characters.
mp-wp_genesis 437 *
mp-wp_genesis 438 * If $strict is true, only alphanumeric characters (as well as _, space, ., -,
mp-wp_genesis 439 * @) are returned.
mp-wp_genesis 440 * Removes tags, octets, entities, and if strict is enabled, will remove all
mp-wp_genesis 441 * non-ASCII characters. After sanitizing, it passes the username, raw username
mp-wp_genesis 442 * (the username in the parameter), and the strict parameter as parameters for
mp-wp_genesis 443 * the filter.
mp-wp_genesis 444 *
mp-wp_genesis 445 * @since 2.0.0
mp-wp_genesis 446 * @uses apply_filters() Calls 'sanitize_user' hook on username, raw username,
mp-wp_genesis 447 * and $strict parameter.
mp-wp_genesis 448 *
mp-wp_genesis 449 * @param string $username The username to be sanitized.
mp-wp_genesis 450 * @param bool $strict If set limits $username to specific characters. Default false.
mp-wp_genesis 451 * @return string The sanitized username, after passing through filters.
mp-wp_genesis 452 */
mp-wp_genesis 453 function sanitize_user( $username, $strict = false ) {
mp-wp_genesis 454 $raw_username = $username;
mp-wp_genesis 455 $username = strip_tags($username);
mp-wp_genesis 456 // Kill octets
mp-wp_genesis 457 $username = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '', $username);
mp-wp_genesis 458 $username = preg_replace('/&.+?;/', '', $username); // Kill entities
mp-wp_genesis 459
mp-wp_genesis 460 // If strict, reduce to ASCII for max portability.
mp-wp_genesis 461 if ( $strict )
mp-wp_genesis 462 $username = preg_replace('|[^a-z0-9 _.\-@]|i', '', $username);
mp-wp_genesis 463
mp-wp_genesis 464 // Consolidate contiguous whitespace
mp-wp_genesis 465 $username = preg_replace('|\s+|', ' ', $username);
mp-wp_genesis 466
mp-wp_genesis 467 return apply_filters('sanitize_user', $username, $raw_username, $strict);
mp-wp_genesis 468 }
mp-wp_genesis 469
mp-wp_genesis 470 /**
mp-wp_genesis 471 * Sanitizes title or use fallback title.
mp-wp_genesis 472 *
mp-wp_genesis 473 * Specifically, HTML and PHP tags are stripped. Further actions can be added
mp-wp_genesis 474 * via the plugin API. If $title is empty and $fallback_title is set, the latter
mp-wp_genesis 475 * will be used.
mp-wp_genesis 476 *
mp-wp_genesis 477 * @since 1.0.0
mp-wp_genesis 478 *
mp-wp_genesis 479 * @param string $title The string to be sanitized.
mp-wp_genesis 480 * @param string $fallback_title Optional. A title to use if $title is empty.
mp-wp_genesis 481 * @return string The sanitized string.
mp-wp_genesis 482 */
mp-wp_genesis 483 function sanitize_title($title, $fallback_title = '') {
mp-wp_genesis 484 $title = strip_tags($title);
mp-wp_genesis 485 $title = apply_filters('sanitize_title', $title);
mp-wp_genesis 486
mp-wp_genesis 487 if ( '' === $title || false === $title )
mp-wp_genesis 488 $title = $fallback_title;
mp-wp_genesis 489
mp-wp_genesis 490 return $title;
mp-wp_genesis 491 }
mp-wp_genesis 492
mp-wp_genesis 493 /**
mp-wp_genesis 494 * Sanitizes title, replacing whitespace with dashes.
mp-wp_genesis 495 *
mp-wp_genesis 496 * Limits the output to alphanumeric characters, underscore (_) and dash (-).
mp-wp_genesis 497 * Whitespace becomes a dash.
mp-wp_genesis 498 *
mp-wp_genesis 499 * @since 1.2.0
mp-wp_genesis 500 *
mp-wp_genesis 501 * @param string $title The title to be sanitized.
mp-wp_genesis 502 * @return string The sanitized title.
mp-wp_genesis 503 */
mp-wp_genesis 504 function sanitize_title_with_dashes($title) {
mp-wp_genesis 505 $title = strip_tags($title);
mp-wp_genesis 506 // Preserve escaped octets.
mp-wp_genesis 507 $title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title);
mp-wp_genesis 508 // Remove percent signs that are not part of an octet.
mp-wp_genesis 509 $title = str_replace('%', '', $title);
mp-wp_genesis 510 // Restore octets.
mp-wp_genesis 511 $title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title);
mp-wp_genesis 512
mp-wp_genesis 513 $title = remove_accents($title);
mp-wp_genesis 514 if (seems_utf8($title)) {
mp-wp_genesis 515 if (function_exists('mb_strtolower')) {
mp-wp_genesis 516 $title = mb_strtolower($title, 'UTF-8');
mp-wp_genesis 517 }
mp-wp_genesis 518 $title = utf8_uri_encode($title, 200);
mp-wp_genesis 519 }
mp-wp_genesis 520
mp-wp_genesis 521 $title = strtolower($title);
mp-wp_genesis 522 $title = preg_replace('/&.+?;/', '', $title); // kill entities
mp-wp_genesis 523 $title = preg_replace('/[^%a-z0-9 _-]/', '', $title);
mp-wp_genesis 524 $title = preg_replace('/\s+/', '-', $title);
mp-wp_genesis 525 $title = preg_replace('|-+|', '-', $title);
mp-wp_genesis 526 $title = trim($title, '-');
mp-wp_genesis 527
mp-wp_genesis 528 return $title;
mp-wp_genesis 529 }
mp-wp_genesis 530
mp-wp_genesis 531 /**
mp-wp_genesis 532 * Ensures a string is a valid SQL order by clause.
mp-wp_genesis 533 *
mp-wp_genesis 534 * Accepts one or more columns, with or without ASC/DESC, and also accepts
mp-wp_genesis 535 * RAND().
mp-wp_genesis 536 *
mp-wp_genesis 537 * @since 2.5.1
mp-wp_genesis 538 *
mp-wp_genesis 539 * @param string $orderby Order by string to be checked.
mp-wp_genesis 540 * @return string|false Returns the order by clause if it is a match, false otherwise.
mp-wp_genesis 541 */
mp-wp_genesis 542 function sanitize_sql_orderby( $orderby ){
mp-wp_genesis 543 preg_match('/^\s*([a-z0-9_]+(\s+(ASC|DESC))?(\s*,\s*|\s*$))+|^\s*RAND\(\s*\)\s*$/i', $orderby, $obmatches);
mp-wp_genesis 544 if ( !$obmatches )
mp-wp_genesis 545 return false;
mp-wp_genesis 546 return $orderby;
mp-wp_genesis 547 }
mp-wp_genesis 548
mp-wp_genesis 549 /**
mp-wp_genesis 550 * Converts a number of characters from a string.
mp-wp_genesis 551 *
mp-wp_genesis 552 * Metadata tags <<title>> and <<category>> are removed, <<br>> and <<hr>> are
mp-wp_genesis 553 * converted into correct XHTML and Unicode characters are converted to the
mp-wp_genesis 554 * valid range.
mp-wp_genesis 555 *
mp-wp_genesis 556 * @since 0.71
mp-wp_genesis 557 *
mp-wp_genesis 558 * @param string $content String of characters to be converted.
mp-wp_genesis 559 * @param string $deprecated Not used.
mp-wp_genesis 560 * @return string Converted string.
mp-wp_genesis 561 */
mp-wp_genesis 562 function convert_chars($content, $deprecated = '') {
mp-wp_genesis 563 // Translation of invalid Unicode references range to valid range
mp-wp_genesis 564 $wp_htmltranswinuni = array(
mp-wp_genesis 565 '&#128;' => '&#8364;', // the Euro sign
mp-wp_genesis 566 '&#129;' => '',
mp-wp_genesis 567 '&#130;' => '&#8218;', // these are Windows CP1252 specific characters
mp-wp_genesis 568 '&#131;' => '&#402;', // they would look weird on non-Windows browsers
mp-wp_genesis 569 '&#132;' => '&#8222;',
mp-wp_genesis 570 '&#133;' => '&#8230;',
mp-wp_genesis 571 '&#134;' => '&#8224;',
mp-wp_genesis 572 '&#135;' => '&#8225;',
mp-wp_genesis 573 '&#136;' => '&#710;',
mp-wp_genesis 574 '&#137;' => '&#8240;',
mp-wp_genesis 575 '&#138;' => '&#352;',
mp-wp_genesis 576 '&#139;' => '&#8249;',
mp-wp_genesis 577 '&#140;' => '&#338;',
mp-wp_genesis 578 '&#141;' => '',
mp-wp_genesis 579 '&#142;' => '&#382;',
mp-wp_genesis 580 '&#143;' => '',
mp-wp_genesis 581 '&#144;' => '',
mp-wp_genesis 582 '&#145;' => '&#8216;',
mp-wp_genesis 583 '&#146;' => '&#8217;',
mp-wp_genesis 584 '&#147;' => '&#8220;',
mp-wp_genesis 585 '&#148;' => '&#8221;',
mp-wp_genesis 586 '&#149;' => '&#8226;',
mp-wp_genesis 587 '&#150;' => '&#8211;',
mp-wp_genesis 588 '&#151;' => '&#8212;',
mp-wp_genesis 589 '&#152;' => '&#732;',
mp-wp_genesis 590 '&#153;' => '&#8482;',
mp-wp_genesis 591 '&#154;' => '&#353;',
mp-wp_genesis 592 '&#155;' => '&#8250;',
mp-wp_genesis 593 '&#156;' => '&#339;',
mp-wp_genesis 594 '&#157;' => '',
mp-wp_genesis 595 '&#158;' => '',
mp-wp_genesis 596 '&#159;' => '&#376;'
mp-wp_genesis 597 );
mp-wp_genesis 598
mp-wp_genesis 599 // Remove metadata tags
mp-wp_genesis 600 $content = preg_replace('/<title>(.+?)<\/title>/','',$content);
mp-wp_genesis 601 $content = preg_replace('/<category>(.+?)<\/category>/','',$content);
mp-wp_genesis 602
mp-wp_genesis 603 // Converts lone & characters into &#38; (a.k.a. &amp;)
mp-wp_genesis 604 $content = preg_replace('/&([^#])(?![a-z1-4]{1,8};)/i', '&#038;$1', $content);
mp-wp_genesis 605
mp-wp_genesis 606 // Fix Word pasting
mp-wp_genesis 607 $content = strtr($content, $wp_htmltranswinuni);
mp-wp_genesis 608
mp-wp_genesis 609 // Just a little XHTML help
mp-wp_genesis 610 $content = str_replace('<br>', '<br />', $content);
mp-wp_genesis 611 $content = str_replace('<hr>', '<hr />', $content);
mp-wp_genesis 612
mp-wp_genesis 613 return $content;
mp-wp_genesis 614 }
mp-wp_genesis 615
mp-wp_genesis 616 /**
mp-wp_genesis 617 * Fixes javascript bugs in browsers.
mp-wp_genesis 618 *
mp-wp_genesis 619 * Converts unicode characters to HTML numbered entities.
mp-wp_genesis 620 *
mp-wp_genesis 621 * @since 1.5.0
mp-wp_genesis 622 * @uses $is_macIE
mp-wp_genesis 623 * @uses $is_winIE
mp-wp_genesis 624 *
mp-wp_genesis 625 * @param string $text Text to be made safe.
mp-wp_genesis 626 * @return string Fixed text.
mp-wp_genesis 627 */
mp-wp_genesis 628 function funky_javascript_fix($text) {
mp-wp_genesis 629 // Fixes for browsers' javascript bugs
mp-wp_genesis 630 global $is_macIE, $is_winIE;
mp-wp_genesis 631
mp-wp_genesis 632 /** @todo use preg_replace_callback() instead */
mp-wp_genesis 633 if ( $is_winIE || $is_macIE )
mp-wp_genesis 634 $text = preg_replace("/\%u([0-9A-F]{4,4})/e", "'&#'.base_convert('\\1',16,10).';'", $text);
mp-wp_genesis 635
mp-wp_genesis 636 return $text;
mp-wp_genesis 637 }
mp-wp_genesis 638
mp-wp_genesis 639 /**
mp-wp_genesis 640 * Will only balance the tags if forced to and the option is set to balance tags.
mp-wp_genesis 641 *
mp-wp_genesis 642 * The option 'use_balanceTags' is used for whether the tags will be balanced.
mp-wp_genesis 643 * Both the $force parameter and 'use_balanceTags' option will have to be true
mp-wp_genesis 644 * before the tags will be balanced.
mp-wp_genesis 645 *
mp-wp_genesis 646 * @since 0.71
mp-wp_genesis 647 *
mp-wp_genesis 648 * @param string $text Text to be balanced
mp-wp_genesis 649 * @param bool $force Forces balancing, ignoring the value of the option. Default false.
mp-wp_genesis 650 * @return string Balanced text
mp-wp_genesis 651 */
mp-wp_genesis 652 function balanceTags( $text, $force = false ) {
mp-wp_genesis 653 if ( !$force && get_option('use_balanceTags') == 0 )
mp-wp_genesis 654 return $text;
mp-wp_genesis 655 return force_balance_tags( $text );
mp-wp_genesis 656 }
mp-wp_genesis 657
mp-wp_genesis 658 /**
mp-wp_genesis 659 * Balances tags of string using a modified stack.
mp-wp_genesis 660 *
mp-wp_genesis 661 * @since 2.0.4
mp-wp_genesis 662 *
mp-wp_genesis 663 * @author Leonard Lin <leonard@acm.org>
mp-wp_genesis 664 * @license GPL v2.0
mp-wp_genesis 665 * @copyright November 4, 2001
mp-wp_genesis 666 * @version 1.1
mp-wp_genesis 667 * @todo Make better - change loop condition to $text in 1.2
mp-wp_genesis 668 * @internal Modified by Scott Reilly (coffee2code) 02 Aug 2004
mp-wp_genesis 669 * 1.1 Fixed handling of append/stack pop order of end text
mp-wp_genesis 670 * Added Cleaning Hooks
mp-wp_genesis 671 * 1.0 First Version
mp-wp_genesis 672 *
mp-wp_genesis 673 * @param string $text Text to be balanced.
mp-wp_genesis 674 * @return string Balanced text.
mp-wp_genesis 675 */
mp-wp_genesis 676 function force_balance_tags( $text ) {
mp-wp_genesis 677 $tagstack = array(); $stacksize = 0; $tagqueue = ''; $newtext = '';
mp-wp_genesis 678 $single_tags = array('br', 'hr', 'img', 'input'); //Known single-entity/self-closing tags
mp-wp_genesis 679 $nestable_tags = array('blockquote', 'div', 'span'); //Tags that can be immediately nested within themselves
mp-wp_genesis 680
mp-wp_genesis 681 # WP bug fix for comments - in case you REALLY meant to type '< !--'
mp-wp_genesis 682 $text = str_replace('< !--', '< !--', $text);
mp-wp_genesis 683 # WP bug fix for LOVE <3 (and other situations with '<' before a number)
mp-wp_genesis 684 $text = preg_replace('#<([0-9]{1})#', '&lt;$1', $text);
mp-wp_genesis 685
mp-wp_genesis 686 while (preg_match("/<(\/?\w*)\s*([^>]*)>/",$text,$regex)) {
mp-wp_genesis 687 $newtext .= $tagqueue;
mp-wp_genesis 688
mp-wp_genesis 689 $i = strpos($text,$regex[0]);
mp-wp_genesis 690 $l = strlen($regex[0]);
mp-wp_genesis 691
mp-wp_genesis 692 // clear the shifter
mp-wp_genesis 693 $tagqueue = '';
mp-wp_genesis 694 // Pop or Push
mp-wp_genesis 695 if ($regex[1][0] == "/") { // End Tag
mp-wp_genesis 696 $tag = strtolower(substr($regex[1],1));
mp-wp_genesis 697 // if too many closing tags
mp-wp_genesis 698 if($stacksize <= 0) {
mp-wp_genesis 699 $tag = '';
mp-wp_genesis 700 //or close to be safe $tag = '/' . $tag;
mp-wp_genesis 701 }
mp-wp_genesis 702 // if stacktop value = tag close value then pop
mp-wp_genesis 703 else if ($tagstack[$stacksize - 1] == $tag) { // found closing tag
mp-wp_genesis 704 $tag = '</' . $tag . '>'; // Close Tag
mp-wp_genesis 705 // Pop
mp-wp_genesis 706 array_pop ($tagstack);
mp-wp_genesis 707 $stacksize--;
mp-wp_genesis 708 } else { // closing tag not at top, search for it
mp-wp_genesis 709 for ($j=$stacksize-1;$j>=0;$j--) {
mp-wp_genesis 710 if ($tagstack[$j] == $tag) {
mp-wp_genesis 711 // add tag to tagqueue
mp-wp_genesis 712 for ($k=$stacksize-1;$k>=$j;$k--){
mp-wp_genesis 713 $tagqueue .= '</' . array_pop ($tagstack) . '>';
mp-wp_genesis 714 $stacksize--;
mp-wp_genesis 715 }
mp-wp_genesis 716 break;
mp-wp_genesis 717 }
mp-wp_genesis 718 }
mp-wp_genesis 719 $tag = '';
mp-wp_genesis 720 }
mp-wp_genesis 721 } else { // Begin Tag
mp-wp_genesis 722 $tag = strtolower($regex[1]);
mp-wp_genesis 723
mp-wp_genesis 724 // Tag Cleaning
mp-wp_genesis 725
mp-wp_genesis 726 // If self-closing or '', don't do anything.
mp-wp_genesis 727 if((substr($regex[2],-1) == '/') || ($tag == '')) {
mp-wp_genesis 728 }
mp-wp_genesis 729 // ElseIf it's a known single-entity tag but it doesn't close itself, do so
mp-wp_genesis 730 elseif ( in_array($tag, $single_tags) ) {
mp-wp_genesis 731 $regex[2] .= '/';
mp-wp_genesis 732 } else { // Push the tag onto the stack
mp-wp_genesis 733 // If the top of the stack is the same as the tag we want to push, close previous tag
mp-wp_genesis 734 if (($stacksize > 0) && !in_array($tag, $nestable_tags) && ($tagstack[$stacksize - 1] == $tag)) {
mp-wp_genesis 735 $tagqueue = '</' . array_pop ($tagstack) . '>';
mp-wp_genesis 736 $stacksize--;
mp-wp_genesis 737 }
mp-wp_genesis 738 $stacksize = array_push ($tagstack, $tag);
mp-wp_genesis 739 }
mp-wp_genesis 740
mp-wp_genesis 741 // Attributes
mp-wp_genesis 742 $attributes = $regex[2];
mp-wp_genesis 743 if($attributes) {
mp-wp_genesis 744 $attributes = ' '.$attributes;
mp-wp_genesis 745 }
mp-wp_genesis 746 $tag = '<'.$tag.$attributes.'>';
mp-wp_genesis 747 //If already queuing a close tag, then put this tag on, too
mp-wp_genesis 748 if ($tagqueue) {
mp-wp_genesis 749 $tagqueue .= $tag;
mp-wp_genesis 750 $tag = '';
mp-wp_genesis 751 }
mp-wp_genesis 752 }
mp-wp_genesis 753 $newtext .= substr($text,0,$i) . $tag;
mp-wp_genesis 754 $text = substr($text,$i+$l);
mp-wp_genesis 755 }
mp-wp_genesis 756
mp-wp_genesis 757 // Clear Tag Queue
mp-wp_genesis 758 $newtext .= $tagqueue;
mp-wp_genesis 759
mp-wp_genesis 760 // Add Remaining text
mp-wp_genesis 761 $newtext .= $text;
mp-wp_genesis 762
mp-wp_genesis 763 // Empty Stack
mp-wp_genesis 764 while($x = array_pop($tagstack)) {
mp-wp_genesis 765 $newtext .= '</' . $x . '>'; // Add remaining tags to close
mp-wp_genesis 766 }
mp-wp_genesis 767
mp-wp_genesis 768 // WP fix for the bug with HTML comments
mp-wp_genesis 769 $newtext = str_replace("< !--","<!--",$newtext);
mp-wp_genesis 770 $newtext = str_replace("< !--","< !--",$newtext);
mp-wp_genesis 771
mp-wp_genesis 772 return $newtext;
mp-wp_genesis 773 }
mp-wp_genesis 774
mp-wp_genesis 775 /**
mp-wp_genesis 776 * Acts on text which is about to be edited.
mp-wp_genesis 777 *
mp-wp_genesis 778 * Unless $richedit is set, it is simply a holder for the 'format_to_edit'
mp-wp_genesis 779 * filter. If $richedit is set true htmlspecialchars() will be run on the
mp-wp_genesis 780 * content, converting special characters to HTMl entities.
mp-wp_genesis 781 *
mp-wp_genesis 782 * @since 0.71
mp-wp_genesis 783 *
mp-wp_genesis 784 * @param string $content The text about to be edited.
mp-wp_genesis 785 * @param bool $richedit Whether or not the $content should pass through htmlspecialchars(). Default false.
mp-wp_genesis 786 * @return string The text after the filter (and possibly htmlspecialchars()) has been run.
mp-wp_genesis 787 */
mp-wp_genesis 788 function format_to_edit($content, $richedit = false) {
mp-wp_genesis 789 $content = apply_filters('format_to_edit', $content);
mp-wp_genesis 790 if (! $richedit )
mp-wp_genesis 791 $content = htmlspecialchars($content);
mp-wp_genesis 792 return $content;
mp-wp_genesis 793 }
mp-wp_genesis 794
mp-wp_genesis 795 /**
mp-wp_genesis 796 * Holder for the 'format_to_post' filter.
mp-wp_genesis 797 *
mp-wp_genesis 798 * @since 0.71
mp-wp_genesis 799 *
mp-wp_genesis 800 * @param string $content The text to pass through the filter.
mp-wp_genesis 801 * @return string Text returned from the 'format_to_post' filter.
mp-wp_genesis 802 */
mp-wp_genesis 803 function format_to_post($content) {
mp-wp_genesis 804 $content = apply_filters('format_to_post', $content);
mp-wp_genesis 805 return $content;
mp-wp_genesis 806 }
mp-wp_genesis 807
mp-wp_genesis 808 /**
mp-wp_genesis 809 * Add leading zeros when necessary.
mp-wp_genesis 810 *
mp-wp_genesis 811 * If you set the threshold to '4' and the number is '10', then you will get
mp-wp_genesis 812 * back '0010'. If you set the number to '4' and the number is '5000', then you
mp-wp_genesis 813 * will get back '5000'.
mp-wp_genesis 814 *
mp-wp_genesis 815 * Uses sprintf to append the amount of zeros based on the $threshold parameter
mp-wp_genesis 816 * and the size of the number. If the number is large enough, then no zeros will
mp-wp_genesis 817 * be appended.
mp-wp_genesis 818 *
mp-wp_genesis 819 * @since 0.71
mp-wp_genesis 820 *
mp-wp_genesis 821 * @param mixed $number Number to append zeros to if not greater than threshold.
mp-wp_genesis 822 * @param int $threshold Digit places number needs to be to not have zeros added.
mp-wp_genesis 823 * @return string Adds leading zeros to number if needed.
mp-wp_genesis 824 */
mp-wp_genesis 825 function zeroise($number, $threshold) {
mp-wp_genesis 826 return sprintf('%0'.$threshold.'s', $number);
mp-wp_genesis 827 }
mp-wp_genesis 828
mp-wp_genesis 829 /**
mp-wp_genesis 830 * Adds backslashes before letters and before a number at the start of a string.
mp-wp_genesis 831 *
mp-wp_genesis 832 * @since 0.71
mp-wp_genesis 833 *
mp-wp_genesis 834 * @param string $string Value to which backslashes will be added.
mp-wp_genesis 835 * @return string String with backslashes inserted.
mp-wp_genesis 836 */
mp-wp_genesis 837 function backslashit($string) {
mp-wp_genesis 838 $string = preg_replace('/^([0-9])/', '\\\\\\\\\1', $string);
mp-wp_genesis 839 $string = preg_replace('/([a-z])/i', '\\\\\1', $string);
mp-wp_genesis 840 return $string;
mp-wp_genesis 841 }
mp-wp_genesis 842
mp-wp_genesis 843 /**
mp-wp_genesis 844 * Appends a trailing slash.
mp-wp_genesis 845 *
mp-wp_genesis 846 * Will remove trailing slash if it exists already before adding a trailing
mp-wp_genesis 847 * slash. This prevents double slashing a string or path.
mp-wp_genesis 848 *
mp-wp_genesis 849 * The primary use of this is for paths and thus should be used for paths. It is
mp-wp_genesis 850 * not restricted to paths and offers no specific path support.
mp-wp_genesis 851 *
mp-wp_genesis 852 * @since 1.2.0
mp-wp_genesis 853 * @uses untrailingslashit() Unslashes string if it was slashed already.
mp-wp_genesis 854 *
mp-wp_genesis 855 * @param string $string What to add the trailing slash to.
mp-wp_genesis 856 * @return string String with trailing slash added.
mp-wp_genesis 857 */
mp-wp_genesis 858 function trailingslashit($string) {
mp-wp_genesis 859 return untrailingslashit($string) . '/';
mp-wp_genesis 860 }
mp-wp_genesis 861
mp-wp_genesis 862 /**
mp-wp_genesis 863 * Removes trailing slash if it exists.
mp-wp_genesis 864 *
mp-wp_genesis 865 * The primary use of this is for paths and thus should be used for paths. It is
mp-wp_genesis 866 * not restricted to paths and offers no specific path support.
mp-wp_genesis 867 *
mp-wp_genesis 868 * @since 2.2.0
mp-wp_genesis 869 *
mp-wp_genesis 870 * @param string $string What to remove the trailing slash from.
mp-wp_genesis 871 * @return string String without the trailing slash.
mp-wp_genesis 872 */
mp-wp_genesis 873 function untrailingslashit($string) {
mp-wp_genesis 874 return rtrim($string, '/');
mp-wp_genesis 875 }
mp-wp_genesis 876
mp-wp_genesis 877 /**
mp-wp_genesis 878 * Adds slashes to escape strings.
mp-wp_genesis 879 *
mp-wp_genesis 880 * Slashes will first be removed if magic_quotes_gpc is set, see {@link
mp-wp_genesis 881 * http://www.php.net/magic_quotes} for more details.
mp-wp_genesis 882 *
mp-wp_genesis 883 * @since 0.71
mp-wp_genesis 884 *
mp-wp_genesis 885 * @param string $gpc The string returned from HTTP request data.
mp-wp_genesis 886 * @return string Returns a string escaped with slashes.
mp-wp_genesis 887 */
mp-wp_genesis 888 function addslashes_gpc($gpc) {
mp-wp_genesis 889 global $wpdb;
mp-wp_genesis 890
mp-wp_genesis 891 if (get_magic_quotes_gpc()) {
mp-wp_genesis 892 $gpc = stripslashes($gpc);
mp-wp_genesis 893 }
mp-wp_genesis 894
mp-wp_genesis 895 return $wpdb->escape($gpc);
mp-wp_genesis 896 }
mp-wp_genesis 897
mp-wp_genesis 898 /**
mp-wp_genesis 899 * Navigates through an array and removes slashes from the values.
mp-wp_genesis 900 *
mp-wp_genesis 901 * If an array is passed, the array_map() function causes a callback to pass the
mp-wp_genesis 902 * value back to the function. The slashes from this value will removed.
mp-wp_genesis 903 *
mp-wp_genesis 904 * @since 2.0.0
mp-wp_genesis 905 *
mp-wp_genesis 906 * @param array|string $value The array or string to be striped.
mp-wp_genesis 907 * @return array|string Stripped array (or string in the callback).
mp-wp_genesis 908 */
mp-wp_genesis 909 function stripslashes_deep($value) {
mp-wp_genesis 910 $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
mp-wp_genesis 911 return $value;
mp-wp_genesis 912 }
mp-wp_genesis 913
mp-wp_genesis 914 /**
mp-wp_genesis 915 * Navigates through an array and encodes the values to be used in a URL.
mp-wp_genesis 916 *
mp-wp_genesis 917 * Uses a callback to pass the value of the array back to the function as a
mp-wp_genesis 918 * string.
mp-wp_genesis 919 *
mp-wp_genesis 920 * @since 2.2.0
mp-wp_genesis 921 *
mp-wp_genesis 922 * @param array|string $value The array or string to be encoded.
mp-wp_genesis 923 * @return array|string $value The encoded array (or string from the callback).
mp-wp_genesis 924 */
mp-wp_genesis 925 function urlencode_deep($value) {
mp-wp_genesis 926 $value = is_array($value) ? array_map('urlencode_deep', $value) : urlencode($value);
mp-wp_genesis 927 return $value;
mp-wp_genesis 928 }
mp-wp_genesis 929
mp-wp_genesis 930 /**
mp-wp_genesis 931 * Converts email addresses characters to HTML entities to block spam bots.
mp-wp_genesis 932 *
mp-wp_genesis 933 * @since 0.71
mp-wp_genesis 934 *
mp-wp_genesis 935 * @param string $emailaddy Email address.
mp-wp_genesis 936 * @param int $mailto Optional. Range from 0 to 1. Used for encoding.
mp-wp_genesis 937 * @return string Converted email address.
mp-wp_genesis 938 */
mp-wp_genesis 939 function antispambot($emailaddy, $mailto=0) {
mp-wp_genesis 940 $emailNOSPAMaddy = '';
mp-wp_genesis 941 srand ((float) microtime() * 1000000);
mp-wp_genesis 942 for ($i = 0; $i < strlen($emailaddy); $i = $i + 1) {
mp-wp_genesis 943 $j = floor(rand(0, 1+$mailto));
mp-wp_genesis 944 if ($j==0) {
mp-wp_genesis 945 $emailNOSPAMaddy .= '&#'.ord(substr($emailaddy,$i,1)).';';
mp-wp_genesis 946 } elseif ($j==1) {
mp-wp_genesis 947 $emailNOSPAMaddy .= substr($emailaddy,$i,1);
mp-wp_genesis 948 } elseif ($j==2) {
mp-wp_genesis 949 $emailNOSPAMaddy .= '%'.zeroise(dechex(ord(substr($emailaddy, $i, 1))), 2);
mp-wp_genesis 950 }
mp-wp_genesis 951 }
mp-wp_genesis 952 $emailNOSPAMaddy = str_replace('@','&#64;',$emailNOSPAMaddy);
mp-wp_genesis 953 return $emailNOSPAMaddy;
mp-wp_genesis 954 }
mp-wp_genesis 955
mp-wp_genesis 956 /**
mp-wp_genesis 957 * Callback to convert URI match to HTML A element.
mp-wp_genesis 958 *
mp-wp_genesis 959 * This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link
mp-wp_genesis 960 * make_clickable()}.
mp-wp_genesis 961 *
mp-wp_genesis 962 * @since 2.3.2
mp-wp_genesis 963 * @access private
mp-wp_genesis 964 *
mp-wp_genesis 965 * @param array $matches Single Regex Match.
mp-wp_genesis 966 * @return string HTML A element with URI address.
mp-wp_genesis 967 */
mp-wp_genesis 968 function _make_url_clickable_cb($matches) {
mp-wp_genesis 969 $ret = '';
mp-wp_genesis 970 $url = $matches[2];
mp-wp_genesis 971 $url = clean_url($url);
mp-wp_genesis 972 if ( empty($url) )
mp-wp_genesis 973 return $matches[0];
mp-wp_genesis 974 // removed trailing [.,;:] from URL
mp-wp_genesis 975 if ( in_array(substr($url, -1), array('.', ',', ';', ':')) === true ) {
mp-wp_genesis 976 $ret = substr($url, -1);
mp-wp_genesis 977 $url = substr($url, 0, strlen($url)-1);
mp-wp_genesis 978 }
mp-wp_genesis 979 return $matches[1] . "<a href=\"$url\" rel=\"nofollow\">$url</a>" . $ret;
mp-wp_genesis 980 }
mp-wp_genesis 981
mp-wp_genesis 982 /**
mp-wp_genesis 983 * Callback to convert URL match to HTML A element.
mp-wp_genesis 984 *
mp-wp_genesis 985 * This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link
mp-wp_genesis 986 * make_clickable()}.
mp-wp_genesis 987 *
mp-wp_genesis 988 * @since 2.3.2
mp-wp_genesis 989 * @access private
mp-wp_genesis 990 *
mp-wp_genesis 991 * @param array $matches Single Regex Match.
mp-wp_genesis 992 * @return string HTML A element with URL address.
mp-wp_genesis 993 */
mp-wp_genesis 994 function _make_web_ftp_clickable_cb($matches) {
mp-wp_genesis 995 $ret = '';
mp-wp_genesis 996 $dest = $matches[2];
mp-wp_genesis 997 $dest = 'http://' . $dest;
mp-wp_genesis 998 $dest = clean_url($dest);
mp-wp_genesis 999 if ( empty($dest) )
mp-wp_genesis 1000 return $matches[0];
mp-wp_genesis 1001 // removed trailing [,;:] from URL
mp-wp_genesis 1002 if ( in_array(substr($dest, -1), array('.', ',', ';', ':')) === true ) {
mp-wp_genesis 1003 $ret = substr($dest, -1);
mp-wp_genesis 1004 $dest = substr($dest, 0, strlen($dest)-1);
mp-wp_genesis 1005 }
mp-wp_genesis 1006 return $matches[1] . "<a href=\"$dest\" rel=\"nofollow\">$dest</a>" . $ret;
mp-wp_genesis 1007 }
mp-wp_genesis 1008
mp-wp_genesis 1009 /**
mp-wp_genesis 1010 * Callback to convert email address match to HTML A element.
mp-wp_genesis 1011 *
mp-wp_genesis 1012 * This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link
mp-wp_genesis 1013 * make_clickable()}.
mp-wp_genesis 1014 *
mp-wp_genesis 1015 * @since 2.3.2
mp-wp_genesis 1016 * @access private
mp-wp_genesis 1017 *
mp-wp_genesis 1018 * @param array $matches Single Regex Match.
mp-wp_genesis 1019 * @return string HTML A element with email address.
mp-wp_genesis 1020 */
mp-wp_genesis 1021 function _make_email_clickable_cb($matches) {
mp-wp_genesis 1022 $email = $matches[2] . '@' . $matches[3];
mp-wp_genesis 1023 return $matches[1] . "<a href=\"mailto:$email\">$email</a>";
mp-wp_genesis 1024 }
mp-wp_genesis 1025
mp-wp_genesis 1026 /**
mp-wp_genesis 1027 * Convert plaintext URI to HTML links.
mp-wp_genesis 1028 *
mp-wp_genesis 1029 * Converts URI, www and ftp, and email addresses. Finishes by fixing links
mp-wp_genesis 1030 * within links.
mp-wp_genesis 1031 *
mp-wp_genesis 1032 * @since 0.71
mp-wp_genesis 1033 *
mp-wp_genesis 1034 * @param string $ret Content to convert URIs.
mp-wp_genesis 1035 * @return string Content with converted URIs.
mp-wp_genesis 1036 */
mp-wp_genesis 1037 function make_clickable($ret) {
mp-wp_genesis 1038 $ret = ' ' . $ret;
mp-wp_genesis 1039 // in testing, using arrays here was found to be faster
mp-wp_genesis 1040 $ret = preg_replace_callback('#([\s>])([\w]+?://[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]*)#is', '_make_url_clickable_cb', $ret);
mp-wp_genesis 1041 $ret = preg_replace_callback('#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]*)#is', '_make_web_ftp_clickable_cb', $ret);
mp-wp_genesis 1042 $ret = preg_replace_callback('#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $ret);
mp-wp_genesis 1043 // this one is not in an array because we need it to run last, for cleanup of accidental links within links
mp-wp_genesis 1044 $ret = preg_replace("#(<a( [^>]+?>|>))<a [^>]+?>([^>]+?)</a></a>#i", "$1$3</a>", $ret);
mp-wp_genesis 1045 $ret = trim($ret);
mp-wp_genesis 1046 return $ret;
mp-wp_genesis 1047 }
mp-wp_genesis 1048
mp-wp_genesis 1049 /**
mp-wp_genesis 1050 * Adds rel nofollow string to all HTML A elements in content.
mp-wp_genesis 1051 *
mp-wp_genesis 1052 * @since 1.5.0
mp-wp_genesis 1053 *
mp-wp_genesis 1054 * @param string $text Content that may contain HTML A elements.
mp-wp_genesis 1055 * @return string Converted content.
mp-wp_genesis 1056 */
mp-wp_genesis 1057 function wp_rel_nofollow( $text ) {
mp-wp_genesis 1058 global $wpdb;
mp-wp_genesis 1059 // This is a pre save filter, so text is already escaped.
mp-wp_genesis 1060 $text = stripslashes($text);
mp-wp_genesis 1061 $text = preg_replace_callback('|<a (.+?)>|i', 'wp_rel_nofollow_callback', $text);
mp-wp_genesis 1062 $text = $wpdb->escape($text);
mp-wp_genesis 1063 return $text;
mp-wp_genesis 1064 }
mp-wp_genesis 1065
mp-wp_genesis 1066 /**
mp-wp_genesis 1067 * Callback to used to add rel=nofollow string to HTML A element.
mp-wp_genesis 1068 *
mp-wp_genesis 1069 * Will remove already existing rel="nofollow" and rel='nofollow' from the
mp-wp_genesis 1070 * string to prevent from invalidating (X)HTML.
mp-wp_genesis 1071 *
mp-wp_genesis 1072 * @since 2.3.0
mp-wp_genesis 1073 *
mp-wp_genesis 1074 * @param array $matches Single Match
mp-wp_genesis 1075 * @return string HTML A Element with rel nofollow.
mp-wp_genesis 1076 */
mp-wp_genesis 1077 function wp_rel_nofollow_callback( $matches ) {
mp-wp_genesis 1078 $text = $matches[1];
mp-wp_genesis 1079 $text = str_replace(array(' rel="nofollow"', " rel='nofollow'"), '', $text);
mp-wp_genesis 1080 return "<a $text rel=\"nofollow\">";
mp-wp_genesis 1081 }
mp-wp_genesis 1082
mp-wp_genesis 1083 /**
mp-wp_genesis 1084 * Convert text equivalent of smilies to images.
mp-wp_genesis 1085 *
mp-wp_genesis 1086 * Will only convert smilies if the option 'use_smilies' is true and the globals
mp-wp_genesis 1087 * used in the function aren't empty.
mp-wp_genesis 1088 *
mp-wp_genesis 1089 * @since 0.71
mp-wp_genesis 1090 * @uses $wp_smiliessearch, $wp_smiliesreplace Smiley replacement arrays.
mp-wp_genesis 1091 *
mp-wp_genesis 1092 * @param string $text Content to convert smilies from text.
mp-wp_genesis 1093 * @return string Converted content with text smilies replaced with images.
mp-wp_genesis 1094 */
mp-wp_genesis 1095 function convert_smilies($text) {
mp-wp_genesis 1096 global $wp_smiliessearch, $wp_smiliesreplace;
mp-wp_genesis 1097 $output = '';
mp-wp_genesis 1098 if ( get_option('use_smilies') && !empty($wp_smiliessearch) && !empty($wp_smiliesreplace) ) {
mp-wp_genesis 1099 // HTML loop taken from texturize function, could possible be consolidated
mp-wp_genesis 1100 $textarr = preg_split("/(<.*>)/U", $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between
mp-wp_genesis 1101 $stop = count($textarr);// loop stuff
mp-wp_genesis 1102 for ($i = 0; $i < $stop; $i++) {
mp-wp_genesis 1103 $content = $textarr[$i];
mp-wp_genesis 1104 if ((strlen($content) > 0) && ('<' != $content{0})) { // If it's not a tag
mp-wp_genesis 1105 $content = preg_replace($wp_smiliessearch, $wp_smiliesreplace, $content);
mp-wp_genesis 1106 }
mp-wp_genesis 1107 $output .= $content;
mp-wp_genesis 1108 }
mp-wp_genesis 1109 } else {
mp-wp_genesis 1110 // return default text.
mp-wp_genesis 1111 $output = $text;
mp-wp_genesis 1112 }
mp-wp_genesis 1113 return $output;
mp-wp_genesis 1114 }
mp-wp_genesis 1115
mp-wp_genesis 1116 /**
mp-wp_genesis 1117 * Checks to see if the text is a valid email address.
mp-wp_genesis 1118 *
mp-wp_genesis 1119 * @since 0.71
mp-wp_genesis 1120 *
mp-wp_genesis 1121 * @param string $user_email The email address to be checked.
mp-wp_genesis 1122 * @return bool Returns true if valid, otherwise false.
mp-wp_genesis 1123 */
mp-wp_genesis 1124 function is_email($user_email) {
mp-wp_genesis 1125 $chars = "/^([a-z0-9+_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,6}\$/i";
mp-wp_genesis 1126 if (strpos($user_email, '@') !== false && strpos($user_email, '.') !== false) {
mp-wp_genesis 1127 if (preg_match($chars, $user_email)) {
mp-wp_genesis 1128 return true;
mp-wp_genesis 1129 } else {
mp-wp_genesis 1130 return false;
mp-wp_genesis 1131 }
mp-wp_genesis 1132 } else {
mp-wp_genesis 1133 return false;
mp-wp_genesis 1134 }
mp-wp_genesis 1135 }
mp-wp_genesis 1136
mp-wp_genesis 1137 /**
mp-wp_genesis 1138 * Convert to ASCII from email subjects.
mp-wp_genesis 1139 *
mp-wp_genesis 1140 * @since 1.2.0
mp-wp_genesis 1141 * @usedby wp_mail() handles charsets in email subjects
mp-wp_genesis 1142 *
mp-wp_genesis 1143 * @param string $string Subject line
mp-wp_genesis 1144 * @return string Converted string to ASCII
mp-wp_genesis 1145 */
mp-wp_genesis 1146 function wp_iso_descrambler($string) {
mp-wp_genesis 1147 /* this may only work with iso-8859-1, I'm afraid */
mp-wp_genesis 1148 if (!preg_match('#\=\?(.+)\?Q\?(.+)\?\=#i', $string, $matches)) {
mp-wp_genesis 1149 return $string;
mp-wp_genesis 1150 } else {
mp-wp_genesis 1151 $subject = str_replace('_', ' ', $matches[2]);
mp-wp_genesis 1152 /** @todo use preg_replace_callback() */
mp-wp_genesis 1153 $subject = preg_replace('#\=([0-9a-f]{2})#ei', "chr(hexdec(strtolower('$1')))", $subject);
mp-wp_genesis 1154 return $subject;
mp-wp_genesis 1155 }
mp-wp_genesis 1156 }
mp-wp_genesis 1157
mp-wp_genesis 1158 /**
mp-wp_genesis 1159 * Returns a date in the GMT equivalent.
mp-wp_genesis 1160 *
mp-wp_genesis 1161 * Requires and returns a date in the Y-m-d H:i:s format. Simply subtracts the
mp-wp_genesis 1162 * value of gmt_offset.
mp-wp_genesis 1163 *
mp-wp_genesis 1164 * @since 1.2.0
mp-wp_genesis 1165 *
mp-wp_genesis 1166 * @param string $string The date to be converted.
mp-wp_genesis 1167 * @return string GMT version of the date provided.
mp-wp_genesis 1168 */
mp-wp_genesis 1169 function get_gmt_from_date($string) {
mp-wp_genesis 1170 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);
mp-wp_genesis 1171 $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
mp-wp_genesis 1172 $string_gmt = gmdate('Y-m-d H:i:s', $string_time - get_option('gmt_offset') * 3600);
mp-wp_genesis 1173 return $string_gmt;
mp-wp_genesis 1174 }
mp-wp_genesis 1175
mp-wp_genesis 1176 /**
mp-wp_genesis 1177 * Converts a GMT date into the correct format for the blog.
mp-wp_genesis 1178 *
mp-wp_genesis 1179 * Requires and returns in the Y-m-d H:i:s format. Simply adds the value of
mp-wp_genesis 1180 * gmt_offset.
mp-wp_genesis 1181 *
mp-wp_genesis 1182 * @since 1.2.0
mp-wp_genesis 1183 *
mp-wp_genesis 1184 * @param string $string The date to be converted.
mp-wp_genesis 1185 * @return string Formatted date relative to the GMT offset.
mp-wp_genesis 1186 */
mp-wp_genesis 1187 function get_date_from_gmt($string) {
mp-wp_genesis 1188 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);
mp-wp_genesis 1189 $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
mp-wp_genesis 1190 $string_localtime = gmdate('Y-m-d H:i:s', $string_time + get_option('gmt_offset')*3600);
mp-wp_genesis 1191 return $string_localtime;
mp-wp_genesis 1192 }
mp-wp_genesis 1193
mp-wp_genesis 1194 /**
mp-wp_genesis 1195 * Computes an offset in seconds from an iso8601 timezone.
mp-wp_genesis 1196 *
mp-wp_genesis 1197 * @since 1.5.0
mp-wp_genesis 1198 *
mp-wp_genesis 1199 * @param string $timezone Either 'Z' for 0 offset or 'hhmm'.
mp-wp_genesis 1200 * @return int|float The offset in seconds.
mp-wp_genesis 1201 */
mp-wp_genesis 1202 function iso8601_timezone_to_offset($timezone) {
mp-wp_genesis 1203 // $timezone is either 'Z' or '[+|-]hhmm'
mp-wp_genesis 1204 if ($timezone == 'Z') {
mp-wp_genesis 1205 $offset = 0;
mp-wp_genesis 1206 } else {
mp-wp_genesis 1207 $sign = (substr($timezone, 0, 1) == '+') ? 1 : -1;
mp-wp_genesis 1208 $hours = intval(substr($timezone, 1, 2));
mp-wp_genesis 1209 $minutes = intval(substr($timezone, 3, 4)) / 60;
mp-wp_genesis 1210 $offset = $sign * 3600 * ($hours + $minutes);
mp-wp_genesis 1211 }
mp-wp_genesis 1212 return $offset;
mp-wp_genesis 1213 }
mp-wp_genesis 1214
mp-wp_genesis 1215 /**
mp-wp_genesis 1216 * Converts an iso8601 date to MySQL DateTime format used by post_date[_gmt].
mp-wp_genesis 1217 *
mp-wp_genesis 1218 * @since 1.5.0
mp-wp_genesis 1219 *
mp-wp_genesis 1220 * @param string $date_string Date and time in ISO 8601 format {@link http://en.wikipedia.org/wiki/ISO_8601}.
mp-wp_genesis 1221 * @param string $timezone Optional. If set to GMT returns the time minus gmt_offset. Default is 'user'.
mp-wp_genesis 1222 * @return string The date and time in MySQL DateTime format - Y-m-d H:i:s.
mp-wp_genesis 1223 */
mp-wp_genesis 1224 function iso8601_to_datetime($date_string, $timezone = 'user') {
mp-wp_genesis 1225 $timezone = strtolower($timezone);
mp-wp_genesis 1226
mp-wp_genesis 1227 if ($timezone == 'gmt') {
mp-wp_genesis 1228
mp-wp_genesis 1229 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);
mp-wp_genesis 1230
mp-wp_genesis 1231 if (!empty($date_bits[7])) { // we have a timezone, so let's compute an offset
mp-wp_genesis 1232 $offset = iso8601_timezone_to_offset($date_bits[7]);
mp-wp_genesis 1233 } else { // we don't have a timezone, so we assume user local timezone (not server's!)
mp-wp_genesis 1234 $offset = 3600 * get_option('gmt_offset');
mp-wp_genesis 1235 }
mp-wp_genesis 1236
mp-wp_genesis 1237 $timestamp = gmmktime($date_bits[4], $date_bits[5], $date_bits[6], $date_bits[2], $date_bits[3], $date_bits[1]);
mp-wp_genesis 1238 $timestamp -= $offset;
mp-wp_genesis 1239
mp-wp_genesis 1240 return gmdate('Y-m-d H:i:s', $timestamp);
mp-wp_genesis 1241
mp-wp_genesis 1242 } else if ($timezone == 'user') {
mp-wp_genesis 1243 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);
mp-wp_genesis 1244 }
mp-wp_genesis 1245 }
mp-wp_genesis 1246
mp-wp_genesis 1247 /**
mp-wp_genesis 1248 * Adds a element attributes to open links in new windows.
mp-wp_genesis 1249 *
mp-wp_genesis 1250 * Comment text in popup windows should be filtered through this. Right now it's
mp-wp_genesis 1251 * a moderately dumb function, ideally it would detect whether a target or rel
mp-wp_genesis 1252 * attribute was already there and adjust its actions accordingly.
mp-wp_genesis 1253 *
mp-wp_genesis 1254 * @since 0.71
mp-wp_genesis 1255 *
mp-wp_genesis 1256 * @param string $text Content to replace links to open in a new window.
mp-wp_genesis 1257 * @return string Content that has filtered links.
mp-wp_genesis 1258 */
mp-wp_genesis 1259 function popuplinks($text) {
mp-wp_genesis 1260 $text = preg_replace('/<a (.+?)>/i', "<a $1 target='_blank' rel='external'>", $text);
mp-wp_genesis 1261 return $text;
mp-wp_genesis 1262 }
mp-wp_genesis 1263
mp-wp_genesis 1264 /**
mp-wp_genesis 1265 * Strips out all characters that are not allowable in an email.
mp-wp_genesis 1266 *
mp-wp_genesis 1267 * @since 1.5.0
mp-wp_genesis 1268 *
mp-wp_genesis 1269 * @param string $email Email address to filter.
mp-wp_genesis 1270 * @return string Filtered email address.
mp-wp_genesis 1271 */
mp-wp_genesis 1272 function sanitize_email($email) {
mp-wp_genesis 1273 return preg_replace('/[^a-z0-9+_.@-]/i', '', $email);
mp-wp_genesis 1274 }
mp-wp_genesis 1275
mp-wp_genesis 1276 /**
mp-wp_genesis 1277 * Determines the difference between two timestamps.
mp-wp_genesis 1278 *
mp-wp_genesis 1279 * The difference is returned in a human readable format such as "1 hour",
mp-wp_genesis 1280 * "5 mins", "2 days".
mp-wp_genesis 1281 *
mp-wp_genesis 1282 * @since 1.5.0
mp-wp_genesis 1283 *
mp-wp_genesis 1284 * @param int $from Unix timestamp from which the difference begins.
mp-wp_genesis 1285 * @param int $to Optional. Unix timestamp to end the time difference. Default becomes time() if not set.
mp-wp_genesis 1286 * @return string Human readable time difference.
mp-wp_genesis 1287 */
mp-wp_genesis 1288 function human_time_diff( $from, $to = '' ) {
mp-wp_genesis 1289 if ( empty($to) )
mp-wp_genesis 1290 $to = time();
mp-wp_genesis 1291 $diff = (int) abs($to - $from);
mp-wp_genesis 1292 if ($diff <= 3600) {
mp-wp_genesis 1293 $mins = round($diff / 60);
mp-wp_genesis 1294 if ($mins <= 1) {
mp-wp_genesis 1295 $mins = 1;
mp-wp_genesis 1296 }
mp-wp_genesis 1297 $since = sprintf(__ngettext('%s min', '%s mins', $mins), $mins);
mp-wp_genesis 1298 } else if (($diff <= 86400) && ($diff > 3600)) {
mp-wp_genesis 1299 $hours = round($diff / 3600);
mp-wp_genesis 1300 if ($hours <= 1) {
mp-wp_genesis 1301 $hours = 1;
mp-wp_genesis 1302 }
mp-wp_genesis 1303 $since = sprintf(__ngettext('%s hour', '%s hours', $hours), $hours);
mp-wp_genesis 1304 } elseif ($diff >= 86400) {
mp-wp_genesis 1305 $days = round($diff / 86400);
mp-wp_genesis 1306 if ($days <= 1) {
mp-wp_genesis 1307 $days = 1;
mp-wp_genesis 1308 }
mp-wp_genesis 1309 $since = sprintf(__ngettext('%s day', '%s days', $days), $days);
mp-wp_genesis 1310 }
mp-wp_genesis 1311 return $since;
mp-wp_genesis 1312 }
mp-wp_genesis 1313
mp-wp_genesis 1314 /**
mp-wp_genesis 1315 * Generates an excerpt from the content, if needed.
mp-wp_genesis 1316 *
mp-wp_genesis 1317 * The excerpt word amount will be 55 words and if the amount is greater than
mp-wp_genesis 1318 * that, then the string '[...]' will be appended to the excerpt. If the string
mp-wp_genesis 1319 * is less than 55 words, then the content will be returned as is.
mp-wp_genesis 1320 *
mp-wp_genesis 1321 * @since 1.5.0
mp-wp_genesis 1322 *
mp-wp_genesis 1323 * @param string $text The exerpt. If set to empty an excerpt is generated.
mp-wp_genesis 1324 * @return string The excerpt.
mp-wp_genesis 1325 */
mp-wp_genesis 1326 function wp_trim_excerpt($text) {
mp-wp_genesis 1327 if ( '' == $text ) {
mp-wp_genesis 1328 $text = get_the_content('');
mp-wp_genesis 1329
mp-wp_genesis 1330 $text = strip_shortcodes( $text );
mp-wp_genesis 1331
mp-wp_genesis 1332 $text = apply_filters('the_content', $text);
mp-wp_genesis 1333 $text = str_replace(']]>', ']]&gt;', $text);
mp-wp_genesis 1334 $text = strip_tags($text);
mp-wp_genesis 1335 $excerpt_length = apply_filters('excerpt_length', 55);
mp-wp_genesis 1336 $words = explode(' ', $text, $excerpt_length + 1);
mp-wp_genesis 1337 if (count($words) > $excerpt_length) {
mp-wp_genesis 1338 array_pop($words);
mp-wp_genesis 1339 array_push($words, '[...]');
mp-wp_genesis 1340 $text = implode(' ', $words);
mp-wp_genesis 1341 }
mp-wp_genesis 1342 }
mp-wp_genesis 1343 return $text;
mp-wp_genesis 1344 }
mp-wp_genesis 1345
mp-wp_genesis 1346 /**
mp-wp_genesis 1347 * Converts named entities into numbered entities.
mp-wp_genesis 1348 *
mp-wp_genesis 1349 * @since 1.5.1
mp-wp_genesis 1350 *
mp-wp_genesis 1351 * @param string $text The text within which entities will be converted.
mp-wp_genesis 1352 * @return string Text with converted entities.
mp-wp_genesis 1353 */
mp-wp_genesis 1354 function ent2ncr($text) {
mp-wp_genesis 1355 $to_ncr = array(
mp-wp_genesis 1356 '&quot;' => '&#34;',
mp-wp_genesis 1357 '&amp;' => '&#38;',
mp-wp_genesis 1358 '&frasl;' => '&#47;',
mp-wp_genesis 1359 '&lt;' => '&#60;',
mp-wp_genesis 1360 '&gt;' => '&#62;',
mp-wp_genesis 1361 '|' => '&#124;',
mp-wp_genesis 1362 '&nbsp;' => '&#160;',
mp-wp_genesis 1363 '&iexcl;' => '&#161;',
mp-wp_genesis 1364 '&cent;' => '&#162;',
mp-wp_genesis 1365 '&pound;' => '&#163;',
mp-wp_genesis 1366 '&curren;' => '&#164;',
mp-wp_genesis 1367 '&yen;' => '&#165;',
mp-wp_genesis 1368 '&brvbar;' => '&#166;',
mp-wp_genesis 1369 '&brkbar;' => '&#166;',
mp-wp_genesis 1370 '&sect;' => '&#167;',
mp-wp_genesis 1371 '&uml;' => '&#168;',
mp-wp_genesis 1372 '&die;' => '&#168;',
mp-wp_genesis 1373 '&copy;' => '&#169;',
mp-wp_genesis 1374 '&ordf;' => '&#170;',
mp-wp_genesis 1375 '&laquo;' => '&#171;',
mp-wp_genesis 1376 '&not;' => '&#172;',
mp-wp_genesis 1377 '&shy;' => '&#173;',
mp-wp_genesis 1378 '&reg;' => '&#174;',
mp-wp_genesis 1379 '&macr;' => '&#175;',
mp-wp_genesis 1380 '&hibar;' => '&#175;',
mp-wp_genesis 1381 '&deg;' => '&#176;',
mp-wp_genesis 1382 '&plusmn;' => '&#177;',
mp-wp_genesis 1383 '&sup2;' => '&#178;',
mp-wp_genesis 1384 '&sup3;' => '&#179;',
mp-wp_genesis 1385 '&acute;' => '&#180;',
mp-wp_genesis 1386 '&micro;' => '&#181;',
mp-wp_genesis 1387 '&para;' => '&#182;',
mp-wp_genesis 1388 '&middot;' => '&#183;',
mp-wp_genesis 1389 '&cedil;' => '&#184;',
mp-wp_genesis 1390 '&sup1;' => '&#185;',
mp-wp_genesis 1391 '&ordm;' => '&#186;',
mp-wp_genesis 1392 '&raquo;' => '&#187;',
mp-wp_genesis 1393 '&frac14;' => '&#188;',
mp-wp_genesis 1394 '&frac12;' => '&#189;',
mp-wp_genesis 1395 '&frac34;' => '&#190;',
mp-wp_genesis 1396 '&iquest;' => '&#191;',
mp-wp_genesis 1397 '&Agrave;' => '&#192;',
mp-wp_genesis 1398 '&Aacute;' => '&#193;',
mp-wp_genesis 1399 '&Acirc;' => '&#194;',
mp-wp_genesis 1400 '&Atilde;' => '&#195;',
mp-wp_genesis 1401 '&Auml;' => '&#196;',
mp-wp_genesis 1402 '&Aring;' => '&#197;',
mp-wp_genesis 1403 '&AElig;' => '&#198;',
mp-wp_genesis 1404 '&Ccedil;' => '&#199;',
mp-wp_genesis 1405 '&Egrave;' => '&#200;',
mp-wp_genesis 1406 '&Eacute;' => '&#201;',
mp-wp_genesis 1407 '&Ecirc;' => '&#202;',
mp-wp_genesis 1408 '&Euml;' => '&#203;',
mp-wp_genesis 1409 '&Igrave;' => '&#204;',
mp-wp_genesis 1410 '&Iacute;' => '&#205;',
mp-wp_genesis 1411 '&Icirc;' => '&#206;',
mp-wp_genesis 1412 '&Iuml;' => '&#207;',
mp-wp_genesis 1413 '&ETH;' => '&#208;',
mp-wp_genesis 1414 '&Ntilde;' => '&#209;',
mp-wp_genesis 1415 '&Ograve;' => '&#210;',
mp-wp_genesis 1416 '&Oacute;' => '&#211;',
mp-wp_genesis 1417 '&Ocirc;' => '&#212;',
mp-wp_genesis 1418 '&Otilde;' => '&#213;',
mp-wp_genesis 1419 '&Ouml;' => '&#214;',
mp-wp_genesis 1420 '&times;' => '&#215;',
mp-wp_genesis 1421 '&Oslash;' => '&#216;',
mp-wp_genesis 1422 '&Ugrave;' => '&#217;',
mp-wp_genesis 1423 '&Uacute;' => '&#218;',
mp-wp_genesis 1424 '&Ucirc;' => '&#219;',
mp-wp_genesis 1425 '&Uuml;' => '&#220;',
mp-wp_genesis 1426 '&Yacute;' => '&#221;',
mp-wp_genesis 1427 '&THORN;' => '&#222;',
mp-wp_genesis 1428 '&szlig;' => '&#223;',
mp-wp_genesis 1429 '&agrave;' => '&#224;',
mp-wp_genesis 1430 '&aacute;' => '&#225;',
mp-wp_genesis 1431 '&acirc;' => '&#226;',
mp-wp_genesis 1432 '&atilde;' => '&#227;',
mp-wp_genesis 1433 '&auml;' => '&#228;',
mp-wp_genesis 1434 '&aring;' => '&#229;',
mp-wp_genesis 1435 '&aelig;' => '&#230;',
mp-wp_genesis 1436 '&ccedil;' => '&#231;',
mp-wp_genesis 1437 '&egrave;' => '&#232;',
mp-wp_genesis 1438 '&eacute;' => '&#233;',
mp-wp_genesis 1439 '&ecirc;' => '&#234;',
mp-wp_genesis 1440 '&euml;' => '&#235;',
mp-wp_genesis 1441 '&igrave;' => '&#236;',
mp-wp_genesis 1442 '&iacute;' => '&#237;',
mp-wp_genesis 1443 '&icirc;' => '&#238;',
mp-wp_genesis 1444 '&iuml;' => '&#239;',
mp-wp_genesis 1445 '&eth;' => '&#240;',
mp-wp_genesis 1446 '&ntilde;' => '&#241;',
mp-wp_genesis 1447 '&ograve;' => '&#242;',
mp-wp_genesis 1448 '&oacute;' => '&#243;',
mp-wp_genesis 1449 '&ocirc;' => '&#244;',
mp-wp_genesis 1450 '&otilde;' => '&#245;',
mp-wp_genesis 1451 '&ouml;' => '&#246;',
mp-wp_genesis 1452 '&divide;' => '&#247;',
mp-wp_genesis 1453 '&oslash;' => '&#248;',
mp-wp_genesis 1454 '&ugrave;' => '&#249;',
mp-wp_genesis 1455 '&uacute;' => '&#250;',
mp-wp_genesis 1456 '&ucirc;' => '&#251;',
mp-wp_genesis 1457 '&uuml;' => '&#252;',
mp-wp_genesis 1458 '&yacute;' => '&#253;',
mp-wp_genesis 1459 '&thorn;' => '&#254;',
mp-wp_genesis 1460 '&yuml;' => '&#255;',
mp-wp_genesis 1461 '&OElig;' => '&#338;',
mp-wp_genesis 1462 '&oelig;' => '&#339;',
mp-wp_genesis 1463 '&Scaron;' => '&#352;',
mp-wp_genesis 1464 '&scaron;' => '&#353;',
mp-wp_genesis 1465 '&Yuml;' => '&#376;',
mp-wp_genesis 1466 '&fnof;' => '&#402;',
mp-wp_genesis 1467 '&circ;' => '&#710;',
mp-wp_genesis 1468 '&tilde;' => '&#732;',
mp-wp_genesis 1469 '&Alpha;' => '&#913;',
mp-wp_genesis 1470 '&Beta;' => '&#914;',
mp-wp_genesis 1471 '&Gamma;' => '&#915;',
mp-wp_genesis 1472 '&Delta;' => '&#916;',
mp-wp_genesis 1473 '&Epsilon;' => '&#917;',
mp-wp_genesis 1474 '&Zeta;' => '&#918;',
mp-wp_genesis 1475 '&Eta;' => '&#919;',
mp-wp_genesis 1476 '&Theta;' => '&#920;',
mp-wp_genesis 1477 '&Iota;' => '&#921;',
mp-wp_genesis 1478 '&Kappa;' => '&#922;',
mp-wp_genesis 1479 '&Lambda;' => '&#923;',
mp-wp_genesis 1480 '&Mu;' => '&#924;',
mp-wp_genesis 1481 '&Nu;' => '&#925;',
mp-wp_genesis 1482 '&Xi;' => '&#926;',
mp-wp_genesis 1483 '&Omicron;' => '&#927;',
mp-wp_genesis 1484 '&Pi;' => '&#928;',
mp-wp_genesis 1485 '&Rho;' => '&#929;',
mp-wp_genesis 1486 '&Sigma;' => '&#931;',
mp-wp_genesis 1487 '&Tau;' => '&#932;',
mp-wp_genesis 1488 '&Upsilon;' => '&#933;',
mp-wp_genesis 1489 '&Phi;' => '&#934;',
mp-wp_genesis 1490 '&Chi;' => '&#935;',
mp-wp_genesis 1491 '&Psi;' => '&#936;',
mp-wp_genesis 1492 '&Omega;' => '&#937;',
mp-wp_genesis 1493 '&alpha;' => '&#945;',
mp-wp_genesis 1494 '&beta;' => '&#946;',
mp-wp_genesis 1495 '&gamma;' => '&#947;',
mp-wp_genesis 1496 '&delta;' => '&#948;',
mp-wp_genesis 1497 '&epsilon;' => '&#949;',
mp-wp_genesis 1498 '&zeta;' => '&#950;',
mp-wp_genesis 1499 '&eta;' => '&#951;',
mp-wp_genesis 1500 '&theta;' => '&#952;',
mp-wp_genesis 1501 '&iota;' => '&#953;',
mp-wp_genesis 1502 '&kappa;' => '&#954;',
mp-wp_genesis 1503 '&lambda;' => '&#955;',
mp-wp_genesis 1504 '&mu;' => '&#956;',
mp-wp_genesis 1505 '&nu;' => '&#957;',
mp-wp_genesis 1506 '&xi;' => '&#958;',
mp-wp_genesis 1507 '&omicron;' => '&#959;',
mp-wp_genesis 1508 '&pi;' => '&#960;',
mp-wp_genesis 1509 '&rho;' => '&#961;',
mp-wp_genesis 1510 '&sigmaf;' => '&#962;',
mp-wp_genesis 1511 '&sigma;' => '&#963;',
mp-wp_genesis 1512 '&tau;' => '&#964;',
mp-wp_genesis 1513 '&upsilon;' => '&#965;',
mp-wp_genesis 1514 '&phi;' => '&#966;',
mp-wp_genesis 1515 '&chi;' => '&#967;',
mp-wp_genesis 1516 '&psi;' => '&#968;',
mp-wp_genesis 1517 '&omega;' => '&#969;',
mp-wp_genesis 1518 '&thetasym;' => '&#977;',
mp-wp_genesis 1519 '&upsih;' => '&#978;',
mp-wp_genesis 1520 '&piv;' => '&#982;',
mp-wp_genesis 1521 '&ensp;' => '&#8194;',
mp-wp_genesis 1522 '&emsp;' => '&#8195;',
mp-wp_genesis 1523 '&thinsp;' => '&#8201;',
mp-wp_genesis 1524 '&zwnj;' => '&#8204;',
mp-wp_genesis 1525 '&zwj;' => '&#8205;',
mp-wp_genesis 1526 '&lrm;' => '&#8206;',
mp-wp_genesis 1527 '&rlm;' => '&#8207;',
mp-wp_genesis 1528 '&ndash;' => '&#8211;',
mp-wp_genesis 1529 '&mdash;' => '&#8212;',
mp-wp_genesis 1530 '&lsquo;' => '&#8216;',
mp-wp_genesis 1531 '&rsquo;' => '&#8217;',
mp-wp_genesis 1532 '&sbquo;' => '&#8218;',
mp-wp_genesis 1533 '&ldquo;' => '&#8220;',
mp-wp_genesis 1534 '&rdquo;' => '&#8221;',
mp-wp_genesis 1535 '&bdquo;' => '&#8222;',
mp-wp_genesis 1536 '&dagger;' => '&#8224;',
mp-wp_genesis 1537 '&Dagger;' => '&#8225;',
mp-wp_genesis 1538 '&bull;' => '&#8226;',
mp-wp_genesis 1539 '&hellip;' => '&#8230;',
mp-wp_genesis 1540 '&permil;' => '&#8240;',
mp-wp_genesis 1541 '&prime;' => '&#8242;',
mp-wp_genesis 1542 '&Prime;' => '&#8243;',
mp-wp_genesis 1543 '&lsaquo;' => '&#8249;',
mp-wp_genesis 1544 '&rsaquo;' => '&#8250;',
mp-wp_genesis 1545 '&oline;' => '&#8254;',
mp-wp_genesis 1546 '&frasl;' => '&#8260;',
mp-wp_genesis 1547 '&euro;' => '&#8364;',
mp-wp_genesis 1548 '&image;' => '&#8465;',
mp-wp_genesis 1549 '&weierp;' => '&#8472;',
mp-wp_genesis 1550 '&real;' => '&#8476;',
mp-wp_genesis 1551 '&trade;' => '&#8482;',
mp-wp_genesis 1552 '&alefsym;' => '&#8501;',
mp-wp_genesis 1553 '&crarr;' => '&#8629;',
mp-wp_genesis 1554 '&lArr;' => '&#8656;',
mp-wp_genesis 1555 '&uArr;' => '&#8657;',
mp-wp_genesis 1556 '&rArr;' => '&#8658;',
mp-wp_genesis 1557 '&dArr;' => '&#8659;',
mp-wp_genesis 1558 '&hArr;' => '&#8660;',
mp-wp_genesis 1559 '&forall;' => '&#8704;',
mp-wp_genesis 1560 '&part;' => '&#8706;',
mp-wp_genesis 1561 '&exist;' => '&#8707;',
mp-wp_genesis 1562 '&empty;' => '&#8709;',
mp-wp_genesis 1563 '&nabla;' => '&#8711;',
mp-wp_genesis 1564 '&isin;' => '&#8712;',
mp-wp_genesis 1565 '&notin;' => '&#8713;',
mp-wp_genesis 1566 '&ni;' => '&#8715;',
mp-wp_genesis 1567 '&prod;' => '&#8719;',
mp-wp_genesis 1568 '&sum;' => '&#8721;',
mp-wp_genesis 1569 '&minus;' => '&#8722;',
mp-wp_genesis 1570 '&lowast;' => '&#8727;',
mp-wp_genesis 1571 '&radic;' => '&#8730;',
mp-wp_genesis 1572 '&prop;' => '&#8733;',
mp-wp_genesis 1573 '&infin;' => '&#8734;',
mp-wp_genesis 1574 '&ang;' => '&#8736;',
mp-wp_genesis 1575 '&and;' => '&#8743;',
mp-wp_genesis 1576 '&or;' => '&#8744;',
mp-wp_genesis 1577 '&cap;' => '&#8745;',
mp-wp_genesis 1578 '&cup;' => '&#8746;',
mp-wp_genesis 1579 '&int;' => '&#8747;',
mp-wp_genesis 1580 '&there4;' => '&#8756;',
mp-wp_genesis 1581 '&sim;' => '&#8764;',
mp-wp_genesis 1582 '&cong;' => '&#8773;',
mp-wp_genesis 1583 '&asymp;' => '&#8776;',
mp-wp_genesis 1584 '&ne;' => '&#8800;',
mp-wp_genesis 1585 '&equiv;' => '&#8801;',
mp-wp_genesis 1586 '&le;' => '&#8804;',
mp-wp_genesis 1587 '&ge;' => '&#8805;',
mp-wp_genesis 1588 '&sub;' => '&#8834;',
mp-wp_genesis 1589 '&sup;' => '&#8835;',
mp-wp_genesis 1590 '&nsub;' => '&#8836;',
mp-wp_genesis 1591 '&sube;' => '&#8838;',
mp-wp_genesis 1592 '&supe;' => '&#8839;',
mp-wp_genesis 1593 '&oplus;' => '&#8853;',
mp-wp_genesis 1594 '&otimes;' => '&#8855;',
mp-wp_genesis 1595 '&perp;' => '&#8869;',
mp-wp_genesis 1596 '&sdot;' => '&#8901;',
mp-wp_genesis 1597 '&lceil;' => '&#8968;',
mp-wp_genesis 1598 '&rceil;' => '&#8969;',
mp-wp_genesis 1599 '&lfloor;' => '&#8970;',
mp-wp_genesis 1600 '&rfloor;' => '&#8971;',
mp-wp_genesis 1601 '&lang;' => '&#9001;',
mp-wp_genesis 1602 '&rang;' => '&#9002;',
mp-wp_genesis 1603 '&larr;' => '&#8592;',
mp-wp_genesis 1604 '&uarr;' => '&#8593;',
mp-wp_genesis 1605 '&rarr;' => '&#8594;',
mp-wp_genesis 1606 '&darr;' => '&#8595;',
mp-wp_genesis 1607 '&harr;' => '&#8596;',
mp-wp_genesis 1608 '&loz;' => '&#9674;',
mp-wp_genesis 1609 '&spades;' => '&#9824;',
mp-wp_genesis 1610 '&clubs;' => '&#9827;',
mp-wp_genesis 1611 '&hearts;' => '&#9829;',
mp-wp_genesis 1612 '&diams;' => '&#9830;'
mp-wp_genesis 1613 );
mp-wp_genesis 1614
mp-wp_genesis 1615 return str_replace( array_keys($to_ncr), array_values($to_ncr), $text );
mp-wp_genesis 1616 }
mp-wp_genesis 1617
mp-wp_genesis 1618 /**
mp-wp_genesis 1619 * Formats text for the rich text editor.
mp-wp_genesis 1620 *
mp-wp_genesis 1621 * The filter 'richedit_pre' is applied here. If $text is empty the filter will
mp-wp_genesis 1622 * be applied to an empty string.
mp-wp_genesis 1623 *
mp-wp_genesis 1624 * @since 2.0.0
mp-wp_genesis 1625 *
mp-wp_genesis 1626 * @param string $text The text to be formatted.
mp-wp_genesis 1627 * @return string The formatted text after filter is applied.
mp-wp_genesis 1628 */
mp-wp_genesis 1629 function wp_richedit_pre($text) {
mp-wp_genesis 1630 // Filtering a blank results in an annoying <br />\n
mp-wp_genesis 1631 if ( empty($text) ) return apply_filters('richedit_pre', '');
mp-wp_genesis 1632
mp-wp_genesis 1633 $output = convert_chars($text);
mp-wp_genesis 1634 $output = wpautop($output);
mp-wp_genesis 1635 $output = htmlspecialchars($output, ENT_NOQUOTES);
mp-wp_genesis 1636
mp-wp_genesis 1637 return apply_filters('richedit_pre', $output);
mp-wp_genesis 1638 }
mp-wp_genesis 1639
mp-wp_genesis 1640 /**
mp-wp_genesis 1641 * Formats text for the HTML editor.
mp-wp_genesis 1642 *
mp-wp_genesis 1643 * Unless $output is empty it will pass through htmlspecialchars before the
mp-wp_genesis 1644 * 'htmledit_pre' filter is applied.
mp-wp_genesis 1645 *
mp-wp_genesis 1646 * @since 2.5.0
mp-wp_genesis 1647 *
mp-wp_genesis 1648 * @param string $output The text to be formatted.
mp-wp_genesis 1649 * @return string Formatted text after filter applied.
mp-wp_genesis 1650 */
mp-wp_genesis 1651 function wp_htmledit_pre($output) {
mp-wp_genesis 1652 if ( !empty($output) )
mp-wp_genesis 1653 $output = htmlspecialchars($output, ENT_NOQUOTES); // convert only < > &
mp-wp_genesis 1654
mp-wp_genesis 1655 return apply_filters('htmledit_pre', $output);
mp-wp_genesis 1656 }
mp-wp_genesis 1657
mp-wp_genesis 1658 /**
mp-wp_genesis 1659 * Checks and cleans a URL.
mp-wp_genesis 1660 *
mp-wp_genesis 1661 * A number of characters are removed from the URL. If the URL is for displaying
mp-wp_genesis 1662 * (the default behaviour) amperstands are also replaced. The 'clean_url' filter
mp-wp_genesis 1663 * is applied to the returned cleaned URL.
mp-wp_genesis 1664 *
mp-wp_genesis 1665 * @since 1.2.0
mp-wp_genesis 1666 * @uses wp_kses_bad_protocol() To only permit protocols in the URL set
mp-wp_genesis 1667 * via $protocols or the common ones set in the function.
mp-wp_genesis 1668 *
mp-wp_genesis 1669 * @param string $url The URL to be cleaned.
mp-wp_genesis 1670 * @param array $protocols Optional. An array of acceptable protocols.
mp-wp_genesis 1671 * Defaults to 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet' if not set.
mp-wp_genesis 1672 * @param string $context Optional. How the URL will be used. Default is 'display'.
mp-wp_genesis 1673 * @return string The cleaned $url after the 'cleaned_url' filter is applied.
mp-wp_genesis 1674 */
mp-wp_genesis 1675 function clean_url( $url, $protocols = null, $context = 'display' ) {
mp-wp_genesis 1676 $original_url = $url;
mp-wp_genesis 1677
mp-wp_genesis 1678 if ('' == $url) return $url;
mp-wp_genesis 1679 $url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$*\'()\\x80-\\xff]|i', '', $url);
mp-wp_genesis 1680 $strip = array('%0d', '%0a');
mp-wp_genesis 1681 $url = str_replace($strip, '', $url);
mp-wp_genesis 1682 $url = str_replace(';//', '://', $url);
mp-wp_genesis 1683 /* If the URL doesn't appear to contain a scheme, we
mp-wp_genesis 1684 * presume it needs http:// appended (unless a relative
mp-wp_genesis 1685 * link starting with / or a php file).
mp-wp_genesis 1686 */
mp-wp_genesis 1687 if ( strpos($url, ':') === false &&
mp-wp_genesis 1688 substr( $url, 0, 1 ) != '/' && !preg_match('/^[a-z0-9-]+?\.php/i', $url) )
mp-wp_genesis 1689 $url = 'http://' . $url;
mp-wp_genesis 1690
mp-wp_genesis 1691 // Replace ampersands and single quotes only when displaying.
mp-wp_genesis 1692 if ( 'display' == $context ) {
mp-wp_genesis 1693 $url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&#038;$1', $url);
mp-wp_genesis 1694 $url = str_replace( "'", '&#039;', $url );
mp-wp_genesis 1695 }
mp-wp_genesis 1696
mp-wp_genesis 1697 if ( !is_array($protocols) )
mp-wp_genesis 1698 $protocols = array('http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet');
mp-wp_genesis 1699 if ( wp_kses_bad_protocol( $url, $protocols ) != $url )
mp-wp_genesis 1700 return '';
mp-wp_genesis 1701
mp-wp_genesis 1702 return apply_filters('clean_url', $url, $original_url, $context);
mp-wp_genesis 1703 }
mp-wp_genesis 1704
mp-wp_genesis 1705 /**
mp-wp_genesis 1706 * Performs clean_url() for database usage.
mp-wp_genesis 1707 *
mp-wp_genesis 1708 * @see clean_url()
mp-wp_genesis 1709 *
mp-wp_genesis 1710 * @since 2.3.1
mp-wp_genesis 1711 *
mp-wp_genesis 1712 * @param string $url The URL to be cleaned.
mp-wp_genesis 1713 * @param array $protocols An array of acceptable protocols.
mp-wp_genesis 1714 * @return string The cleaned URL.
mp-wp_genesis 1715 */
mp-wp_genesis 1716 function sanitize_url( $url, $protocols = null ) {
mp-wp_genesis 1717 return clean_url( $url, $protocols, 'db' );
mp-wp_genesis 1718 }
mp-wp_genesis 1719
mp-wp_genesis 1720 /**
mp-wp_genesis 1721 * Convert entities, while preserving already-encoded entities.
mp-wp_genesis 1722 *
mp-wp_genesis 1723 * @link http://www.php.net/htmlentities Borrowed from the PHP Manual user notes.
mp-wp_genesis 1724 *
mp-wp_genesis 1725 * @since 1.2.2
mp-wp_genesis 1726 *
mp-wp_genesis 1727 * @param string $myHTML The text to be converted.
mp-wp_genesis 1728 * @return string Converted text.
mp-wp_genesis 1729 */
mp-wp_genesis 1730 function htmlentities2($myHTML) {
mp-wp_genesis 1731 $translation_table = get_html_translation_table( HTML_ENTITIES, ENT_QUOTES );
mp-wp_genesis 1732 $translation_table[chr(38)] = '&';
mp-wp_genesis 1733 return preg_replace( "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/", "&amp;", strtr($myHTML, $translation_table) );
mp-wp_genesis 1734 }
mp-wp_genesis 1735
mp-wp_genesis 1736 /**
mp-wp_genesis 1737 * Escape single quotes, specialchar double quotes, and fix line endings.
mp-wp_genesis 1738 *
mp-wp_genesis 1739 * The filter 'js_escape' is also applied here.
mp-wp_genesis 1740 *
mp-wp_genesis 1741 * @since 2.0.4
mp-wp_genesis 1742 *
mp-wp_genesis 1743 * @param string $text The text to be escaped.
mp-wp_genesis 1744 * @return string Escaped text.
mp-wp_genesis 1745 */
mp-wp_genesis 1746 function js_escape($text) {
mp-wp_genesis 1747 $safe_text = wp_specialchars($text, 'double');
mp-wp_genesis 1748 $safe_text = preg_replace('/&#(x)?0*(?(1)27|39);?/i', "'", stripslashes($safe_text));
mp-wp_genesis 1749 $safe_text = preg_replace("/\r?\n/", "\\n", addslashes($safe_text));
mp-wp_genesis 1750 return apply_filters('js_escape', $safe_text, $text);
mp-wp_genesis 1751 }
mp-wp_genesis 1752
mp-wp_genesis 1753 /**
mp-wp_genesis 1754 * Escaping for HTML attributes.
mp-wp_genesis 1755 *
mp-wp_genesis 1756 * @since 2.0.6
mp-wp_genesis 1757 *
mp-wp_genesis 1758 * @param string $text
mp-wp_genesis 1759 * @return string
mp-wp_genesis 1760 */
mp-wp_genesis 1761 function attribute_escape($text) {
mp-wp_genesis 1762 $safe_text = wp_specialchars($text, true);
mp-wp_genesis 1763 return apply_filters('attribute_escape', $safe_text, $text);
mp-wp_genesis 1764 }
mp-wp_genesis 1765
mp-wp_genesis 1766 /**
mp-wp_genesis 1767 * Escape a HTML tag name.
mp-wp_genesis 1768 *
mp-wp_genesis 1769 * @since 2.5.0
mp-wp_genesis 1770 *
mp-wp_genesis 1771 * @param string $tag_name
mp-wp_genesis 1772 * @return string
mp-wp_genesis 1773 */
mp-wp_genesis 1774 function tag_escape($tag_name) {
mp-wp_genesis 1775 $safe_tag = strtolower( preg_replace('[^a-zA-Z_:]', '', $tag_name) );
mp-wp_genesis 1776 return apply_filters('tag_escape', $safe_tag, $tag_name);
mp-wp_genesis 1777 }
mp-wp_genesis 1778
mp-wp_genesis 1779 /**
mp-wp_genesis 1780 * Escapes text for SQL LIKE special characters % and _.
mp-wp_genesis 1781 *
mp-wp_genesis 1782 * @since 2.5.0
mp-wp_genesis 1783 *
mp-wp_genesis 1784 * @param string $text The text to be escaped.
mp-wp_genesis 1785 * @return string text, safe for inclusion in LIKE query.
mp-wp_genesis 1786 */
mp-wp_genesis 1787 function like_escape($text) {
mp-wp_genesis 1788 return str_replace(array("%", "_"), array("\\%", "\\_"), $text);
mp-wp_genesis 1789 }
mp-wp_genesis 1790
mp-wp_genesis 1791 /**
mp-wp_genesis 1792 * Convert full URL paths to absolute paths.
mp-wp_genesis 1793 *
mp-wp_genesis 1794 * Removes the http or https protocols and the domain. Keeps the path '/' at the
mp-wp_genesis 1795 * beginning, so it isn't a true relative link, but from the web root base.
mp-wp_genesis 1796 *
mp-wp_genesis 1797 * @since 2.1.0
mp-wp_genesis 1798 *
mp-wp_genesis 1799 * @param string $link Full URL path.
mp-wp_genesis 1800 * @return string Absolute path.
mp-wp_genesis 1801 */
mp-wp_genesis 1802 function wp_make_link_relative( $link ) {
mp-wp_genesis 1803 return preg_replace( '|https?://[^/]+(/.*)|i', '$1', $link );
mp-wp_genesis 1804 }
mp-wp_genesis 1805
mp-wp_genesis 1806 /**
mp-wp_genesis 1807 * Sanitises various option values based on the nature of the option.
mp-wp_genesis 1808 *
mp-wp_genesis 1809 * This is basically a switch statement which will pass $value through a number
mp-wp_genesis 1810 * of functions depending on the $option.
mp-wp_genesis 1811 *
mp-wp_genesis 1812 * @since 2.0.5
mp-wp_genesis 1813 *
mp-wp_genesis 1814 * @param string $option The name of the option.
mp-wp_genesis 1815 * @param string $value The unsanitised value.
mp-wp_genesis 1816 * @return string Sanitized value.
mp-wp_genesis 1817 */
mp-wp_genesis 1818 function sanitize_option($option, $value) {
mp-wp_genesis 1819
mp-wp_genesis 1820 switch ($option) {
mp-wp_genesis 1821 case 'admin_email':
mp-wp_genesis 1822 $value = sanitize_email($value);
mp-wp_genesis 1823 break;
mp-wp_genesis 1824
mp-wp_genesis 1825 case 'thumbnail_size_w':
mp-wp_genesis 1826 case 'thumbnail_size_h':
mp-wp_genesis 1827 case 'medium_size_w':
mp-wp_genesis 1828 case 'medium_size_h':
mp-wp_genesis 1829 case 'large_size_w':
mp-wp_genesis 1830 case 'large_size_h':
mp-wp_genesis 1831 case 'default_post_edit_rows':
mp-wp_genesis 1832 case 'mailserver_port':
mp-wp_genesis 1833 case 'comment_max_links':
mp-wp_genesis 1834 case 'page_on_front':
mp-wp_genesis 1835 case 'rss_excerpt_length':
mp-wp_genesis 1836 case 'default_category':
mp-wp_genesis 1837 case 'default_email_category':
mp-wp_genesis 1838 case 'default_link_category':
mp-wp_genesis 1839 case 'close_comments_days_old':
mp-wp_genesis 1840 case 'comments_per_page':
mp-wp_genesis 1841 case 'thread_comments_depth':
mp-wp_genesis 1842 $value = abs((int) $value);
mp-wp_genesis 1843 break;
mp-wp_genesis 1844
mp-wp_genesis 1845 case 'posts_per_page':
mp-wp_genesis 1846 case 'posts_per_rss':
mp-wp_genesis 1847 $value = (int) $value;
mp-wp_genesis 1848 if ( empty($value) ) $value = 1;
mp-wp_genesis 1849 if ( $value < -1 ) $value = abs($value);
mp-wp_genesis 1850 break;
mp-wp_genesis 1851
mp-wp_genesis 1852 case 'default_ping_status':
mp-wp_genesis 1853 case 'default_comment_status':
mp-wp_genesis 1854 // Options that if not there have 0 value but need to be something like "closed"
mp-wp_genesis 1855 if ( $value == '0' || $value == '')
mp-wp_genesis 1856 $value = 'closed';
mp-wp_genesis 1857 break;
mp-wp_genesis 1858
mp-wp_genesis 1859 case 'blogdescription':
mp-wp_genesis 1860 case 'blogname':
mp-wp_genesis 1861 $value = addslashes($value);
mp-wp_genesis 1862 $value = wp_filter_post_kses( $value ); // calls stripslashes then addslashes
mp-wp_genesis 1863 $value = stripslashes($value);
mp-wp_genesis 1864 $value = wp_specialchars( $value );
mp-wp_genesis 1865 break;
mp-wp_genesis 1866
mp-wp_genesis 1867 case 'blog_charset':
mp-wp_genesis 1868 $value = preg_replace('/[^a-zA-Z0-9_-]/', '', $value); // strips slashes
mp-wp_genesis 1869 break;
mp-wp_genesis 1870
mp-wp_genesis 1871 case 'date_format':
mp-wp_genesis 1872 case 'time_format':
mp-wp_genesis 1873 case 'mailserver_url':
mp-wp_genesis 1874 case 'mailserver_login':
mp-wp_genesis 1875 case 'mailserver_pass':
mp-wp_genesis 1876 case 'ping_sites':
mp-wp_genesis 1877 case 'upload_path':
mp-wp_genesis 1878 $value = strip_tags($value);
mp-wp_genesis 1879 $value = addslashes($value);
mp-wp_genesis 1880 $value = wp_filter_kses($value); // calls stripslashes then addslashes
mp-wp_genesis 1881 $value = stripslashes($value);
mp-wp_genesis 1882 break;
mp-wp_genesis 1883
mp-wp_genesis 1884 case 'gmt_offset':
mp-wp_genesis 1885 $value = preg_replace('/[^0-9:.-]/', '', $value); // strips slashes
mp-wp_genesis 1886 break;
mp-wp_genesis 1887
mp-wp_genesis 1888 case 'siteurl':
mp-wp_genesis 1889 case 'home':
mp-wp_genesis 1890 $value = stripslashes($value);
mp-wp_genesis 1891 $value = clean_url($value);
mp-wp_genesis 1892 break;
mp-wp_genesis 1893 default :
mp-wp_genesis 1894 $value = apply_filters("sanitize_option_{$option}", $value, $option);
mp-wp_genesis 1895 break;
mp-wp_genesis 1896 }
mp-wp_genesis 1897
mp-wp_genesis 1898 return $value;
mp-wp_genesis 1899 }
mp-wp_genesis 1900
mp-wp_genesis 1901 /**
mp-wp_genesis 1902 * Parses a string into variables to be stored in an array.
mp-wp_genesis 1903 *
mp-wp_genesis 1904 * Uses {@link http://www.php.net/parse_str parse_str()} and stripslashes if
mp-wp_genesis 1905 * {@link http://www.php.net/magic_quotes magic_quotes_gpc} is on.
mp-wp_genesis 1906 *
mp-wp_genesis 1907 * @since 2.2.1
mp-wp_genesis 1908 * @uses apply_filters() for the 'wp_parse_str' filter.
mp-wp_genesis 1909 *
mp-wp_genesis 1910 * @param string $string The string to be parsed.
mp-wp_genesis 1911 * @param array $array Variables will be stored in this array.
mp-wp_genesis 1912 */
mp-wp_genesis 1913 function wp_parse_str( $string, &$array ) {
mp-wp_genesis 1914 parse_str( $string, $array );
mp-wp_genesis 1915 if ( get_magic_quotes_gpc() )
mp-wp_genesis 1916 $array = stripslashes_deep( $array );
mp-wp_genesis 1917 $array = apply_filters( 'wp_parse_str', $array );
mp-wp_genesis 1918 }
mp-wp_genesis 1919
mp-wp_genesis 1920 /**
mp-wp_genesis 1921 * Convert lone less than signs.
mp-wp_genesis 1922 *
mp-wp_genesis 1923 * KSES already converts lone greater than signs.
mp-wp_genesis 1924 *
mp-wp_genesis 1925 * @uses wp_pre_kses_less_than_callback in the callback function.
mp-wp_genesis 1926 * @since 2.3.0
mp-wp_genesis 1927 *
mp-wp_genesis 1928 * @param string $text Text to be converted.
mp-wp_genesis 1929 * @return string Converted text.
mp-wp_genesis 1930 */
mp-wp_genesis 1931 function wp_pre_kses_less_than( $text ) {
mp-wp_genesis 1932 return preg_replace_callback('%<[^>]*?((?=<)|>|$)%', 'wp_pre_kses_less_than_callback', $text);
mp-wp_genesis 1933 }
mp-wp_genesis 1934
mp-wp_genesis 1935 /**
mp-wp_genesis 1936 * Callback function used by preg_replace.
mp-wp_genesis 1937 *
mp-wp_genesis 1938 * @uses wp_specialchars to format the $matches text.
mp-wp_genesis 1939 * @since 2.3.0
mp-wp_genesis 1940 *
mp-wp_genesis 1941 * @param array $matches Populated by matches to preg_replace.
mp-wp_genesis 1942 * @return string The text returned after wp_specialchars if needed.
mp-wp_genesis 1943 */
mp-wp_genesis 1944 function wp_pre_kses_less_than_callback( $matches ) {
mp-wp_genesis 1945 if ( false === strpos($matches[0], '>') )
mp-wp_genesis 1946 return wp_specialchars($matches[0]);
mp-wp_genesis 1947 return $matches[0];
mp-wp_genesis 1948 }
mp-wp_genesis 1949
mp-wp_genesis 1950 /**
mp-wp_genesis 1951 * WordPress implementation of PHP sprintf() with filters.
mp-wp_genesis 1952 *
mp-wp_genesis 1953 * @since 2.5.0
mp-wp_genesis 1954 * @link http://www.php.net/sprintf
mp-wp_genesis 1955 *
mp-wp_genesis 1956 * @param string $pattern The string which formatted args are inserted.
mp-wp_genesis 1957 * @param mixed $args,... Arguments to be formatted into the $pattern string.
mp-wp_genesis 1958 * @return string The formatted string.
mp-wp_genesis 1959 */
mp-wp_genesis 1960 function wp_sprintf( $pattern ) {
mp-wp_genesis 1961 $args = func_get_args( );
mp-wp_genesis 1962 $len = strlen($pattern);
mp-wp_genesis 1963 $start = 0;
mp-wp_genesis 1964 $result = '';
mp-wp_genesis 1965 $arg_index = 0;
mp-wp_genesis 1966 while ( $len > $start ) {
mp-wp_genesis 1967 // Last character: append and break
mp-wp_genesis 1968 if ( strlen($pattern) - 1 == $start ) {
mp-wp_genesis 1969 $result .= substr($pattern, -1);
mp-wp_genesis 1970 break;
mp-wp_genesis 1971 }
mp-wp_genesis 1972
mp-wp_genesis 1973 // Literal %: append and continue
mp-wp_genesis 1974 if ( substr($pattern, $start, 2) == '%%' ) {
mp-wp_genesis 1975 $start += 2;
mp-wp_genesis 1976 $result .= '%';
mp-wp_genesis 1977 continue;
mp-wp_genesis 1978 }
mp-wp_genesis 1979
mp-wp_genesis 1980 // Get fragment before next %
mp-wp_genesis 1981 $end = strpos($pattern, '%', $start + 1);
mp-wp_genesis 1982 if ( false === $end )
mp-wp_genesis 1983 $end = $len;
mp-wp_genesis 1984 $fragment = substr($pattern, $start, $end - $start);
mp-wp_genesis 1985
mp-wp_genesis 1986 // Fragment has a specifier
mp-wp_genesis 1987 if ( $pattern{$start} == '%' ) {
mp-wp_genesis 1988 // Find numbered arguments or take the next one in order
mp-wp_genesis 1989 if ( preg_match('/^%(\d+)\$/', $fragment, $matches) ) {
mp-wp_genesis 1990 $arg = isset($args[$matches[1]]) ? $args[$matches[1]] : '';
mp-wp_genesis 1991 $fragment = str_replace("%{$matches[1]}$", '%', $fragment);
mp-wp_genesis 1992 } else {
mp-wp_genesis 1993 ++$arg_index;
mp-wp_genesis 1994 $arg = isset($args[$arg_index]) ? $args[$arg_index] : '';
mp-wp_genesis 1995 }
mp-wp_genesis 1996
mp-wp_genesis 1997 // Apply filters OR sprintf
mp-wp_genesis 1998 $_fragment = apply_filters( 'wp_sprintf', $fragment, $arg );
mp-wp_genesis 1999 if ( $_fragment != $fragment )
mp-wp_genesis 2000 $fragment = $_fragment;
mp-wp_genesis 2001 else
mp-wp_genesis 2002 $fragment = sprintf($fragment, strval($arg) );
mp-wp_genesis 2003 }
mp-wp_genesis 2004
mp-wp_genesis 2005 // Append to result and move to next fragment
mp-wp_genesis 2006 $result .= $fragment;
mp-wp_genesis 2007 $start = $end;
mp-wp_genesis 2008 }
mp-wp_genesis 2009 return $result;
mp-wp_genesis 2010 }
mp-wp_genesis 2011
mp-wp_genesis 2012 /**
mp-wp_genesis 2013 * Localize list items before the rest of the content.
mp-wp_genesis 2014 *
mp-wp_genesis 2015 * The '%l' must be at the first characters can then contain the rest of the
mp-wp_genesis 2016 * content. The list items will have ', ', ', and', and ' and ' added depending
mp-wp_genesis 2017 * on the amount of list items in the $args parameter.
mp-wp_genesis 2018 *
mp-wp_genesis 2019 * @since 2.5.0
mp-wp_genesis 2020 *
mp-wp_genesis 2021 * @param string $pattern Content containing '%l' at the beginning.
mp-wp_genesis 2022 * @param array $args List items to prepend to the content and replace '%l'.
mp-wp_genesis 2023 * @return string Localized list items and rest of the content.
mp-wp_genesis 2024 */
mp-wp_genesis 2025 function wp_sprintf_l($pattern, $args) {
mp-wp_genesis 2026 // Not a match
mp-wp_genesis 2027 if ( substr($pattern, 0, 2) != '%l' )
mp-wp_genesis 2028 return $pattern;
mp-wp_genesis 2029
mp-wp_genesis 2030 // Nothing to work with
mp-wp_genesis 2031 if ( empty($args) )
mp-wp_genesis 2032 return '';
mp-wp_genesis 2033
mp-wp_genesis 2034 // Translate and filter the delimiter set (avoid ampersands and entities here)
mp-wp_genesis 2035 $l = apply_filters('wp_sprintf_l', array(
mp-wp_genesis 2036 'between' => _c(', |between list items'),
mp-wp_genesis 2037 'between_last_two' => _c(', and |between last two list items'),
mp-wp_genesis 2038 'between_only_two' => _c(' and |between only two list items'),
mp-wp_genesis 2039 ));
mp-wp_genesis 2040
mp-wp_genesis 2041 $args = (array) $args;
mp-wp_genesis 2042 $result = array_shift($args);
mp-wp_genesis 2043 if ( count($args) == 1 )
mp-wp_genesis 2044 $result .= $l['between_only_two'] . array_shift($args);
mp-wp_genesis 2045 // Loop when more than two args
mp-wp_genesis 2046 $i = count($args);
mp-wp_genesis 2047 while ( $i ) {
mp-wp_genesis 2048 $arg = array_shift($args);
mp-wp_genesis 2049 $i--;
mp-wp_genesis 2050 if ( $i == 1 )
mp-wp_genesis 2051 $result .= $l['between_last_two'] . $arg;
mp-wp_genesis 2052 else
mp-wp_genesis 2053 $result .= $l['between'] . $arg;
mp-wp_genesis 2054 }
mp-wp_genesis 2055 return $result . substr($pattern, 2);
mp-wp_genesis 2056 }
mp-wp_genesis 2057
mp-wp_genesis 2058 /**
mp-wp_genesis 2059 * Safely extracts not more than the first $count characters from html string.
mp-wp_genesis 2060 *
mp-wp_genesis 2061 * UTF-8, tags and entities safe prefix extraction. Entities inside will *NOT*
mp-wp_genesis 2062 * be counted as one character. For example &amp; will be counted as 4, &lt; as
mp-wp_genesis 2063 * 3, etc.
mp-wp_genesis 2064 *
mp-wp_genesis 2065 * @since 2.5.0
mp-wp_genesis 2066 *
mp-wp_genesis 2067 * @param integer $str String to get the excerpt from.
mp-wp_genesis 2068 * @param integer $count Maximum number of characters to take.
mp-wp_genesis 2069 * @return string The excerpt.
mp-wp_genesis 2070 */
mp-wp_genesis 2071 function wp_html_excerpt( $str, $count ) {
mp-wp_genesis 2072 $str = strip_tags( $str );
mp-wp_genesis 2073 $str = mb_strcut( $str, 0, $count );
mp-wp_genesis 2074 // remove part of an entity at the end
mp-wp_genesis 2075 $str = preg_replace( '/&[^;\s]{0,6}$/', '', $str );
mp-wp_genesis 2076 return $str;
mp-wp_genesis 2077 }
mp-wp_genesis 2078
mp-wp_genesis 2079 /**
mp-wp_genesis 2080 * Add a Base url to relative links in passed content.
mp-wp_genesis 2081 *
mp-wp_genesis 2082 * By default it supports the 'src' and 'href' attributes. However this can be
mp-wp_genesis 2083 * changed via the 3rd param.
mp-wp_genesis 2084 *
mp-wp_genesis 2085 * @since 2.7.0
mp-wp_genesis 2086 *
mp-wp_genesis 2087 * @param string $content String to search for links in.
mp-wp_genesis 2088 * @param string $base The base URL to prefix to links.
mp-wp_genesis 2089 * @param array $attrs The attributes which should be processed.
mp-wp_genesis 2090 * @return string The processed content.
mp-wp_genesis 2091 */
mp-wp_genesis 2092 function links_add_base_url( $content, $base, $attrs = array('src', 'href') ) {
mp-wp_genesis 2093 $attrs = implode('|', (array)$attrs);
mp-wp_genesis 2094 return preg_replace_callback("!($attrs)=(['\"])(.+?)\\2!i",
mp-wp_genesis 2095 create_function('$m', 'return _links_add_base($m, "' . $base . '");'),
mp-wp_genesis 2096 $content);
mp-wp_genesis 2097 }
mp-wp_genesis 2098
mp-wp_genesis 2099 /**
mp-wp_genesis 2100 * Callback to add a base url to relative links in passed content.
mp-wp_genesis 2101 *
mp-wp_genesis 2102 * @since 2.7.0
mp-wp_genesis 2103 * @access private
mp-wp_genesis 2104 *
mp-wp_genesis 2105 * @param string $m The matched link.
mp-wp_genesis 2106 * @param string $base The base URL to prefix to links.
mp-wp_genesis 2107 * @return string The processed link.
mp-wp_genesis 2108 */
mp-wp_genesis 2109 function _links_add_base($m, $base) {
mp-wp_genesis 2110 //1 = attribute name 2 = quotation mark 3 = URL
mp-wp_genesis 2111 return $m[1] . '=' . $m[2] .
mp-wp_genesis 2112 (strpos($m[3], 'http://') === false ?
mp-wp_genesis 2113 path_join($base, $m[3]) :
mp-wp_genesis 2114 $m[3])
mp-wp_genesis 2115 . $m[2];
mp-wp_genesis 2116 }
mp-wp_genesis 2117
mp-wp_genesis 2118 /**
mp-wp_genesis 2119 * Adds a Target attribute to all links in passed content.
mp-wp_genesis 2120 *
mp-wp_genesis 2121 * This function by default only applies to <a> tags, however this can be
mp-wp_genesis 2122 * modified by the 3rd param.
mp-wp_genesis 2123 *
mp-wp_genesis 2124 * <b>NOTE:</b> Any current target attributed will be striped and replaced.
mp-wp_genesis 2125 *
mp-wp_genesis 2126 * @since 2.7.0
mp-wp_genesis 2127 *
mp-wp_genesis 2128 * @param string $content String to search for links in.
mp-wp_genesis 2129 * @param string $target The Target to add to the links.
mp-wp_genesis 2130 * @param array $tags An array of tags to apply to.
mp-wp_genesis 2131 * @return string The processed content.
mp-wp_genesis 2132 */
mp-wp_genesis 2133 function links_add_target( $content, $target = '_blank', $tags = array('a') ) {
mp-wp_genesis 2134 $tags = implode('|', (array)$tags);
mp-wp_genesis 2135 return preg_replace_callback("!<($tags)(.+?)>!i",
mp-wp_genesis 2136 create_function('$m', 'return _links_add_target($m, "' . $target . '");'),
mp-wp_genesis 2137 $content);
mp-wp_genesis 2138 }
mp-wp_genesis 2139 /**
mp-wp_genesis 2140 * Callback to add a target attribute to all links in passed content.
mp-wp_genesis 2141 *
mp-wp_genesis 2142 * @since 2.7.0
mp-wp_genesis 2143 * @access private
mp-wp_genesis 2144 *
mp-wp_genesis 2145 * @param string $m The matched link.
mp-wp_genesis 2146 * @param string $target The Target to add to the links.
mp-wp_genesis 2147 * @return string The processed link.
mp-wp_genesis 2148 */
mp-wp_genesis 2149 function _links_add_target( $m, $target ) {
mp-wp_genesis 2150 $tag = $m[1];
mp-wp_genesis 2151 $link = preg_replace('|(target=[\'"](.*?)[\'"])|i', '', $m[2]);
mp-wp_genesis 2152 return '<' . $tag . $link . ' target="' . $target . '">';
mp-wp_genesis 2153 }
mp-wp_genesis 2154
mp-wp_genesis 2155 // normalize EOL characters and strip duplicate whitespace
mp-wp_genesis 2156 function normalize_whitespace( $str ) {
mp-wp_genesis 2157 $str = trim($str);
mp-wp_genesis 2158 $str = str_replace("\r", "\n", $str);
mp-wp_genesis 2159 $str = preg_replace( array( '/\n+/', '/[ \t]+/' ), array( "\n", ' ' ), $str );
mp-wp_genesis 2160 return $str;
mp-wp_genesis 2161 }
mp-wp_genesis 2162
mp-wp_genesis 2163 ?>