author | Anthony Ly <anthonyly.com@gmail.com> |
Tue, 12 Mar 2013 18:21:39 +0100 | |
changeset 206 | 919b4ddb13fa |
parent 204 | 09a1c134465b |
permissions | -rw-r--r-- |
136 | 1 |
<?php |
2 |
/** |
|
3 |
* Main WordPress Formatting API. |
|
4 |
* |
|
5 |
* Handles many functions for formatting output. |
|
6 |
* |
|
7 |
* @package WordPress |
|
8 |
**/ |
|
9 |
||
10 |
/** |
|
11 |
* Replaces common plain text characters into formatted entities |
|
12 |
* |
|
13 |
* As an example, |
|
14 |
* <code> |
|
15 |
* 'cause today's effort makes it worth tomorrow's "holiday"... |
|
16 |
* </code> |
|
17 |
* Becomes: |
|
18 |
* <code> |
|
19 |
* ’cause today’s effort makes it worth tomorrow’s “holiday”… |
|
20 |
* </code> |
|
21 |
* Code within certain html blocks are skipped. |
|
22 |
* |
|
23 |
* @since 0.71 |
|
24 |
* @uses $wp_cockneyreplace Array of formatted entities for certain common phrases |
|
25 |
* |
|
26 |
* @param string $text The text to be formatted |
|
27 |
* @return string The string replaced with html entities |
|
28 |
*/ |
|
29 |
function wptexturize($text) { |
|
30 |
global $wp_cockneyreplace; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
31 |
static $static_characters, $static_replacements, $dynamic_characters, $dynamic_replacements, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
32 |
$default_no_texturize_tags, $default_no_texturize_shortcodes; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
33 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
34 |
// No need to set up these static variables more than once |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
35 |
if ( ! isset( $static_characters ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
36 |
/* translators: opening curly double quote */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
37 |
$opening_quote = _x( '“', 'opening curly double quote' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
38 |
/* translators: closing curly double quote */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
39 |
$closing_quote = _x( '”', 'closing curly double quote' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
40 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
41 |
/* translators: apostrophe, for example in 'cause or can't */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
42 |
$apos = _x( '’', 'apostrophe' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
43 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
44 |
/* translators: prime, for example in 9' (nine feet) */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
45 |
$prime = _x( '′', 'prime' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
46 |
/* translators: double prime, for example in 9" (nine inches) */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
47 |
$double_prime = _x( '″', 'double prime' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
48 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
49 |
/* translators: opening curly single quote */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
50 |
$opening_single_quote = _x( '‘', 'opening curly single quote' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
51 |
/* translators: closing curly single quote */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
52 |
$closing_single_quote = _x( '’', 'closing curly single quote' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
53 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
54 |
/* translators: en dash */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
55 |
$en_dash = _x( '–', 'en dash' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
56 |
/* translators: em dash */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
57 |
$em_dash = _x( '—', 'em dash' ); |
136 | 58 |
|
59 |
$default_no_texturize_tags = array('pre', 'code', 'kbd', 'style', 'script', 'tt'); |
|
60 |
$default_no_texturize_shortcodes = array('code'); |
|
61 |
||
62 |
// if a plugin has provided an autocorrect array, use it |
|
63 |
if ( isset($wp_cockneyreplace) ) { |
|
64 |
$cockney = array_keys($wp_cockneyreplace); |
|
65 |
$cockneyreplace = array_values($wp_cockneyreplace); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
66 |
} elseif ( "'" != $apos ) { // Only bother if we're doing a replacement. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
67 |
$cockney = array( "'tain't", "'twere", "'twas", "'tis", "'twill", "'til", "'bout", "'nuff", "'round", "'cause" ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
68 |
$cockneyreplace = array( $apos . "tain" . $apos . "t", $apos . "twere", $apos . "twas", $apos . "tis", $apos . "twill", $apos . "til", $apos . "bout", $apos . "nuff", $apos . "round", $apos . "cause" ); |
136 | 69 |
} else { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
70 |
$cockney = $cockneyreplace = array(); |
136 | 71 |
} |
72 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
73 |
$static_characters = array_merge( array( '---', ' -- ', '--', ' - ', 'xn–', '...', '``', '\'\'', ' (tm)' ), $cockney ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
74 |
$static_replacements = array_merge( array( $em_dash, ' ' . $em_dash . ' ', $en_dash, ' ' . $en_dash . ' ', 'xn--', '…', $opening_quote, $closing_quote, ' ™' ), $cockneyreplace ); |
136 | 75 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
76 |
$dynamic = array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
77 |
if ( "'" != $apos ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
78 |
$dynamic[ '/\'(\d\d(?:’|\')?s)/' ] = $apos . '$1'; // '99's |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
79 |
$dynamic[ '/\'(\d)/' ] = $apos . '$1'; // '99 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
80 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
81 |
if ( "'" != $opening_single_quote ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
82 |
$dynamic[ '/(\s|\A|[([{<]|")\'/' ] = '$1' . $opening_single_quote; // opening single quote, even after (, {, <, [ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
83 |
if ( '"' != $double_prime ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
84 |
$dynamic[ '/(\d)"/' ] = '$1' . $double_prime; // 9" (double prime) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
85 |
if ( "'" != $prime ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
86 |
$dynamic[ '/(\d)\'/' ] = '$1' . $prime; // 9' (prime) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
87 |
if ( "'" != $apos ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
88 |
$dynamic[ '/(\S)\'([^\'\s])/' ] = '$1' . $apos . '$2'; // apostrophe in a word |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
89 |
if ( '"' != $opening_quote ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
90 |
$dynamic[ '/(\s|\A|[([{<])"(?!\s)/' ] = '$1' . $opening_quote . '$2'; // opening double quote, even after (, {, <, [ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
91 |
if ( '"' != $closing_quote ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
92 |
$dynamic[ '/"(\s|\S|\Z)/' ] = $closing_quote . '$1'; // closing double quote |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
93 |
if ( "'" != $closing_single_quote ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
94 |
$dynamic[ '/\'([\s.]|\Z)/' ] = $closing_single_quote . '$1'; // closing single quote |
136 | 95 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
96 |
$dynamic[ '/\b(\d+)x(\d+)\b/' ] = '$1×$2'; // 9x9 (times) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
97 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
98 |
$dynamic_characters = array_keys( $dynamic ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
99 |
$dynamic_replacements = array_values( $dynamic ); |
136 | 100 |
} |
101 |
||
102 |
// Transform into regexp sub-expression used in _wptexturize_pushpop_element |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
103 |
// Must do this every time in case plugins use these filters in a context sensitive manner |
136 | 104 |
$no_texturize_tags = '(' . implode('|', apply_filters('no_texturize_tags', $default_no_texturize_tags) ) . ')'; |
105 |
$no_texturize_shortcodes = '(' . implode('|', apply_filters('no_texturize_shortcodes', $default_no_texturize_shortcodes) ) . ')'; |
|
106 |
||
107 |
$no_texturize_tags_stack = array(); |
|
108 |
$no_texturize_shortcodes_stack = array(); |
|
109 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
110 |
$textarr = preg_split('/(<.*>|\[.*\])/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
111 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
112 |
foreach ( $textarr as &$curl ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
113 |
if ( empty( $curl ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
114 |
continue; |
136 | 115 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
116 |
// Only call _wptexturize_pushpop_element if first char is correct tag opening |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
117 |
$first = $curl[0]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
118 |
if ( '<' === $first ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
119 |
_wptexturize_pushpop_element($curl, $no_texturize_tags_stack, $no_texturize_tags, '<', '>'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
120 |
} elseif ( '[' === $first ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
121 |
_wptexturize_pushpop_element($curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes, '[', ']'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
122 |
} elseif ( empty($no_texturize_shortcodes_stack) && empty($no_texturize_tags_stack) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
123 |
// This is not a tag, nor is the texturization disabled static strings |
136 | 124 |
$curl = str_replace($static_characters, $static_replacements, $curl); |
125 |
// regular expressions |
|
126 |
$curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl); |
|
127 |
} |
|
128 |
$curl = preg_replace('/&([^#])(?![a-zA-Z1-4]{1,8};)/', '&$1', $curl); |
|
129 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
130 |
return implode( '', $textarr ); |
136 | 131 |
} |
132 |
||
133 |
/** |
|
134 |
* Search for disabled element tags. Push element to stack on tag open and pop |
|
135 |
* on tag close. Assumes first character of $text is tag opening. |
|
136 |
* |
|
137 |
* @access private |
|
138 |
* @since 2.9.0 |
|
139 |
* |
|
140 |
* @param string $text Text to check. First character is assumed to be $opening |
|
141 |
* @param array $stack Array used as stack of opened tag elements |
|
142 |
* @param string $disabled_elements Tags to match against formatted as regexp sub-expression |
|
143 |
* @param string $opening Tag opening character, assumed to be 1 character long |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
144 |
* @param string $closing Tag closing character |
136 | 145 |
*/ |
146 |
function _wptexturize_pushpop_element($text, &$stack, $disabled_elements, $opening = '<', $closing = '>') { |
|
147 |
// Check if it is a closing tag -- otherwise assume opening tag |
|
148 |
if (strncmp($opening . '/', $text, 2)) { |
|
149 |
// Opening? Check $text+1 against disabled elements |
|
150 |
if (preg_match('/^' . $disabled_elements . '\b/', substr($text, 1), $matches)) { |
|
151 |
/* |
|
152 |
* This disables texturize until we find a closing tag of our type |
|
153 |
* (e.g. <pre>) even if there was invalid nesting before that |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
154 |
* |
136 | 155 |
* Example: in the case <pre>sadsadasd</code>"baba"</pre> |
156 |
* "baba" won't be texturize |
|
157 |
*/ |
|
158 |
||
159 |
array_push($stack, $matches[1]); |
|
160 |
} |
|
161 |
} else { |
|
162 |
// Closing? Check $text+2 against disabled elements |
|
163 |
$c = preg_quote($closing, '/'); |
|
164 |
if (preg_match('/^' . $disabled_elements . $c . '/', substr($text, 2), $matches)) { |
|
165 |
$last = array_pop($stack); |
|
166 |
||
167 |
// Make sure it matches the opening tag |
|
168 |
if ($last != $matches[1]) |
|
169 |
array_push($stack, $last); |
|
170 |
} |
|
171 |
} |
|
172 |
} |
|
173 |
||
174 |
/** |
|
175 |
* Replaces double line-breaks with paragraph elements. |
|
176 |
* |
|
177 |
* A group of regex replaces used to identify text formatted with newlines and |
|
178 |
* replace double line-breaks with HTML paragraph tags. The remaining |
|
179 |
* line-breaks after conversion become <<br />> tags, unless $br is set to '0' |
|
180 |
* or 'false'. |
|
181 |
* |
|
182 |
* @since 0.71 |
|
183 |
* |
|
184 |
* @param string $pee The text which has to be formatted. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
185 |
* @param bool $br Optional. If set, this will convert all remaining line-breaks after paragraphing. Default true. |
136 | 186 |
* @return string Text which has been converted into correct paragraph tags. |
187 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
188 |
function wpautop($pee, $br = true) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
189 |
$pre_tags = array(); |
136 | 190 |
|
191 |
if ( trim($pee) === '' ) |
|
192 |
return ''; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
193 |
|
136 | 194 |
$pee = $pee . "\n"; // just to make things a little easier, pad the end |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
195 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
196 |
if ( strpos($pee, '<pre') !== false ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
197 |
$pee_parts = explode( '</pre>', $pee ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
198 |
$last_pee = array_pop($pee_parts); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
199 |
$pee = ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
200 |
$i = 0; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
201 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
202 |
foreach ( $pee_parts as $pee_part ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
203 |
$start = strpos($pee_part, '<pre'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
204 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
205 |
// Malformed html? |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
206 |
if ( $start === false ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
207 |
$pee .= $pee_part; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
208 |
continue; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
209 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
210 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
211 |
$name = "<pre wp-pre-tag-$i></pre>"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
212 |
$pre_tags[$name] = substr( $pee_part, $start ) . '</pre>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
213 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
214 |
$pee .= substr( $pee_part, 0, $start ) . $name; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
215 |
$i++; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
216 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
217 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
218 |
$pee .= $last_pee; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
219 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
220 |
|
136 | 221 |
$pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee); |
222 |
// Space things out a little |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
223 |
$allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|samp|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)'; |
136 | 224 |
$pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee); |
225 |
$pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee); |
|
226 |
$pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines |
|
227 |
if ( strpos($pee, '<object') !== false ) { |
|
228 |
$pee = preg_replace('|\s*<param([^>]*)>\s*|', "<param$1>", $pee); // no pee inside object/embed |
|
229 |
$pee = preg_replace('|\s*</embed>\s*|', '</embed>', $pee); |
|
230 |
} |
|
231 |
$pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates |
|
232 |
// make paragraphs, including one at the end |
|
233 |
$pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY); |
|
234 |
$pee = ''; |
|
235 |
foreach ( $pees as $tinkle ) |
|
236 |
$pee .= '<p>' . trim($tinkle, "\n") . "</p>\n"; |
|
237 |
$pee = preg_replace('|<p>\s*</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace |
|
238 |
$pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>$1</p></$2>", $pee); |
|
239 |
$pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee); // don't pee all over a tag |
|
240 |
$pee = preg_replace("|<p>(<li.+?)</p>|", "$1", $pee); // problem with nested lists |
|
241 |
$pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee); |
|
242 |
$pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee); |
|
243 |
$pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee); |
|
244 |
$pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
245 |
if ( $br ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
246 |
$pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee); |
136 | 247 |
$pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks |
248 |
$pee = str_replace('<WPPreserveNewline />', "\n", $pee); |
|
249 |
} |
|
250 |
$pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $pee); |
|
251 |
$pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee); |
|
252 |
$pee = preg_replace( "|\n</p>$|", '</p>', $pee ); |
|
253 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
254 |
if ( !empty($pre_tags) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
255 |
$pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
256 |
|
136 | 257 |
return $pee; |
258 |
} |
|
259 |
||
260 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
261 |
* Newline preservation help function for wpautop |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
262 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
263 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
264 |
* @access private |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
265 |
* @param array $matches preg_replace_callback matches array |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
266 |
* @return string |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
267 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
268 |
function _autop_newline_preservation_helper( $matches ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
269 |
return str_replace("\n", "<WPPreserveNewline />", $matches[0]); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
270 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
271 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
272 |
/** |
136 | 273 |
* Don't auto-p wrap shortcodes that stand alone |
274 |
* |
|
275 |
* Ensures that shortcodes are not wrapped in <<p>>...<</p>>. |
|
276 |
* |
|
277 |
* @since 2.9.0 |
|
278 |
* |
|
279 |
* @param string $pee The content. |
|
280 |
* @return string The filtered content. |
|
281 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
282 |
function shortcode_unautop( $pee ) { |
136 | 283 |
global $shortcode_tags; |
284 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
285 |
if ( empty( $shortcode_tags ) || !is_array( $shortcode_tags ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
286 |
return $pee; |
136 | 287 |
} |
288 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
289 |
$tagregexp = join( '|', array_map( 'preg_quote', array_keys( $shortcode_tags ) ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
290 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
291 |
$pattern = |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
292 |
'/' |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
293 |
. '<p>' // Opening paragraph |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
294 |
. '\\s*+' // Optional leading whitespace |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
295 |
. '(' // 1: The shortcode |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
296 |
. '\\[' // Opening bracket |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
297 |
. "($tagregexp)" // 2: Shortcode name |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
298 |
. '(?![\\w-])' // Not followed by word character or hyphen |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
299 |
// Unroll the loop: Inside the opening shortcode tag |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
300 |
. '[^\\]\\/]*' // Not a closing bracket or forward slash |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
301 |
. '(?:' |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
302 |
. '\\/(?!\\])' // A forward slash not followed by a closing bracket |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
303 |
. '[^\\]\\/]*' // Not a closing bracket or forward slash |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
304 |
. ')*?' |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
305 |
. '(?:' |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
306 |
. '\\/\\]' // Self closing tag and closing bracket |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
307 |
. '|' |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
308 |
. '\\]' // Closing bracket |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
309 |
. '(?:' // Unroll the loop: Optionally, anything between the opening and closing shortcode tags |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
310 |
. '[^\\[]*+' // Not an opening bracket |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
311 |
. '(?:' |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
312 |
. '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
313 |
. '[^\\[]*+' // Not an opening bracket |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
314 |
. ')*+' |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
315 |
. '\\[\\/\\2\\]' // Closing shortcode tag |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
316 |
. ')?' |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
317 |
. ')' |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
318 |
. ')' |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
319 |
. '\\s*+' // optional trailing whitespace |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
320 |
. '<\\/p>' // closing paragraph |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
321 |
. '/s'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
322 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
323 |
return preg_replace( $pattern, '$1', $pee ); |
136 | 324 |
} |
325 |
||
326 |
/** |
|
327 |
* Checks to see if a string is utf8 encoded. |
|
328 |
* |
|
329 |
* NOTE: This function checks for 5-Byte sequences, UTF8 |
|
330 |
* has Bytes Sequences with a maximum length of 4. |
|
331 |
* |
|
332 |
* @author bmorel at ssi dot fr (modified) |
|
333 |
* @since 1.2.1 |
|
334 |
* |
|
335 |
* @param string $str The string to be checked |
|
336 |
* @return bool True if $str fits a UTF-8 model, false otherwise. |
|
337 |
*/ |
|
338 |
function seems_utf8($str) { |
|
339 |
$length = strlen($str); |
|
340 |
for ($i=0; $i < $length; $i++) { |
|
341 |
$c = ord($str[$i]); |
|
342 |
if ($c < 0x80) $n = 0; # 0bbbbbbb |
|
343 |
elseif (($c & 0xE0) == 0xC0) $n=1; # 110bbbbb |
|
344 |
elseif (($c & 0xF0) == 0xE0) $n=2; # 1110bbbb |
|
345 |
elseif (($c & 0xF8) == 0xF0) $n=3; # 11110bbb |
|
346 |
elseif (($c & 0xFC) == 0xF8) $n=4; # 111110bb |
|
347 |
elseif (($c & 0xFE) == 0xFC) $n=5; # 1111110b |
|
348 |
else return false; # Does not match any model |
|
349 |
for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ? |
|
350 |
if ((++$i == $length) || ((ord($str[$i]) & 0xC0) != 0x80)) |
|
351 |
return false; |
|
352 |
} |
|
353 |
} |
|
354 |
return true; |
|
355 |
} |
|
356 |
||
357 |
/** |
|
358 |
* Converts a number of special characters into their HTML entities. |
|
359 |
* |
|
360 |
* Specifically deals with: &, <, >, ", and '. |
|
361 |
* |
|
362 |
* $quote_style can be set to ENT_COMPAT to encode " to |
|
363 |
* ", or ENT_QUOTES to do both. Default is ENT_NOQUOTES where no quotes are encoded. |
|
364 |
* |
|
365 |
* @since 1.2.2 |
|
366 |
* |
|
367 |
* @param string $string The text which is to be encoded. |
|
368 |
* @param mixed $quote_style Optional. Converts double quotes if set to ENT_COMPAT, both single and double if set to ENT_QUOTES or none if set to ENT_NOQUOTES. Also compatible with old values; converting single quotes if set to 'single', double if set to 'double' or both if otherwise set. Default is ENT_NOQUOTES. |
|
369 |
* @param string $charset Optional. The character encoding of the string. Default is false. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
370 |
* @param boolean $double_encode Optional. Whether to encode existing html entities. Default is false. |
136 | 371 |
* @return string The encoded text with HTML entities. |
372 |
*/ |
|
373 |
function _wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false ) { |
|
374 |
$string = (string) $string; |
|
375 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
376 |
if ( 0 === strlen( $string ) ) |
136 | 377 |
return ''; |
378 |
||
379 |
// Don't bother if there are no specialchars - saves some processing |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
380 |
if ( ! preg_match( '/[&<>"\']/', $string ) ) |
136 | 381 |
return $string; |
382 |
||
383 |
// Account for the previous behaviour of the function when the $quote_style is not an accepted value |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
384 |
if ( empty( $quote_style ) ) |
136 | 385 |
$quote_style = ENT_NOQUOTES; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
386 |
elseif ( ! in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) |
136 | 387 |
$quote_style = ENT_QUOTES; |
388 |
||
389 |
// Store the site charset as a static to avoid multiple calls to wp_load_alloptions() |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
390 |
if ( ! $charset ) { |
136 | 391 |
static $_charset; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
392 |
if ( ! isset( $_charset ) ) { |
136 | 393 |
$alloptions = wp_load_alloptions(); |
394 |
$_charset = isset( $alloptions['blog_charset'] ) ? $alloptions['blog_charset'] : ''; |
|
395 |
} |
|
396 |
$charset = $_charset; |
|
397 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
398 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
399 |
if ( in_array( $charset, array( 'utf8', 'utf-8', 'UTF8' ) ) ) |
136 | 400 |
$charset = 'UTF-8'; |
401 |
||
402 |
$_quote_style = $quote_style; |
|
403 |
||
404 |
if ( $quote_style === 'double' ) { |
|
405 |
$quote_style = ENT_COMPAT; |
|
406 |
$_quote_style = ENT_COMPAT; |
|
407 |
} elseif ( $quote_style === 'single' ) { |
|
408 |
$quote_style = ENT_NOQUOTES; |
|
409 |
} |
|
410 |
||
411 |
// Handle double encoding ourselves |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
412 |
if ( $double_encode ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
413 |
$string = @htmlspecialchars( $string, $quote_style, $charset ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
414 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
415 |
// Decode & into & |
136 | 416 |
$string = wp_specialchars_decode( $string, $_quote_style ); |
417 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
418 |
// Guarantee every &entity; is valid or re-encode the & |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
419 |
$string = wp_kses_normalize_entities( $string ); |
136 | 420 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
421 |
// Now re-encode everything except &entity; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
422 |
$string = preg_split( '/(&#?x?[0-9a-z]+;)/i', $string, -1, PREG_SPLIT_DELIM_CAPTURE ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
423 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
424 |
for ( $i = 0; $i < count( $string ); $i += 2 ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
425 |
$string[$i] = @htmlspecialchars( $string[$i], $quote_style, $charset ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
426 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
427 |
$string = implode( '', $string ); |
136 | 428 |
} |
429 |
||
430 |
// Backwards compatibility |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
431 |
if ( 'single' === $_quote_style ) |
136 | 432 |
$string = str_replace( "'", ''', $string ); |
433 |
||
434 |
return $string; |
|
435 |
} |
|
436 |
||
437 |
/** |
|
438 |
* Converts a number of HTML entities into their special characters. |
|
439 |
* |
|
440 |
* Specifically deals with: &, <, >, ", and '. |
|
441 |
* |
|
442 |
* $quote_style can be set to ENT_COMPAT to decode " entities, |
|
443 |
* or ENT_QUOTES to do both " and '. Default is ENT_NOQUOTES where no quotes are decoded. |
|
444 |
* |
|
445 |
* @since 2.8 |
|
446 |
* |
|
447 |
* @param string $string The text which is to be decoded. |
|
448 |
* @param mixed $quote_style Optional. Converts double quotes if set to ENT_COMPAT, both single and double if set to ENT_QUOTES or none if set to ENT_NOQUOTES. Also compatible with old _wp_specialchars() values; converting single quotes if set to 'single', double if set to 'double' or both if otherwise set. Default is ENT_NOQUOTES. |
|
449 |
* @return string The decoded text without HTML entities. |
|
450 |
*/ |
|
451 |
function wp_specialchars_decode( $string, $quote_style = ENT_NOQUOTES ) { |
|
452 |
$string = (string) $string; |
|
453 |
||
454 |
if ( 0 === strlen( $string ) ) { |
|
455 |
return ''; |
|
456 |
} |
|
457 |
||
458 |
// Don't bother if there are no entities - saves a lot of processing |
|
459 |
if ( strpos( $string, '&' ) === false ) { |
|
460 |
return $string; |
|
461 |
} |
|
462 |
||
463 |
// Match the previous behaviour of _wp_specialchars() when the $quote_style is not an accepted value |
|
464 |
if ( empty( $quote_style ) ) { |
|
465 |
$quote_style = ENT_NOQUOTES; |
|
466 |
} elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) { |
|
467 |
$quote_style = ENT_QUOTES; |
|
468 |
} |
|
469 |
||
470 |
// More complete than get_html_translation_table( HTML_SPECIALCHARS ) |
|
471 |
$single = array( ''' => '\'', ''' => '\'' ); |
|
472 |
$single_preg = array( '/�*39;/' => ''', '/�*27;/i' => ''' ); |
|
473 |
$double = array( '"' => '"', '"' => '"', '"' => '"' ); |
|
474 |
$double_preg = array( '/�*34;/' => '"', '/�*22;/i' => '"' ); |
|
475 |
$others = array( '<' => '<', '<' => '<', '>' => '>', '>' => '>', '&' => '&', '&' => '&', '&' => '&' ); |
|
476 |
$others_preg = array( '/�*60;/' => '<', '/�*62;/' => '>', '/�*38;/' => '&', '/�*26;/i' => '&' ); |
|
477 |
||
478 |
if ( $quote_style === ENT_QUOTES ) { |
|
479 |
$translation = array_merge( $single, $double, $others ); |
|
480 |
$translation_preg = array_merge( $single_preg, $double_preg, $others_preg ); |
|
481 |
} elseif ( $quote_style === ENT_COMPAT || $quote_style === 'double' ) { |
|
482 |
$translation = array_merge( $double, $others ); |
|
483 |
$translation_preg = array_merge( $double_preg, $others_preg ); |
|
484 |
} elseif ( $quote_style === 'single' ) { |
|
485 |
$translation = array_merge( $single, $others ); |
|
486 |
$translation_preg = array_merge( $single_preg, $others_preg ); |
|
487 |
} elseif ( $quote_style === ENT_NOQUOTES ) { |
|
488 |
$translation = $others; |
|
489 |
$translation_preg = $others_preg; |
|
490 |
} |
|
491 |
||
492 |
// Remove zero padding on numeric entities |
|
493 |
$string = preg_replace( array_keys( $translation_preg ), array_values( $translation_preg ), $string ); |
|
494 |
||
495 |
// Replace characters according to translation table |
|
496 |
return strtr( $string, $translation ); |
|
497 |
} |
|
498 |
||
499 |
/** |
|
500 |
* Checks for invalid UTF8 in a string. |
|
501 |
* |
|
502 |
* @since 2.8 |
|
503 |
* |
|
504 |
* @param string $string The text which is to be checked. |
|
505 |
* @param boolean $strip Optional. Whether to attempt to strip out invalid UTF8. Default is false. |
|
506 |
* @return string The checked text. |
|
507 |
*/ |
|
508 |
function wp_check_invalid_utf8( $string, $strip = false ) { |
|
509 |
$string = (string) $string; |
|
510 |
||
511 |
if ( 0 === strlen( $string ) ) { |
|
512 |
return ''; |
|
513 |
} |
|
514 |
||
515 |
// Store the site charset as a static to avoid multiple calls to get_option() |
|
516 |
static $is_utf8; |
|
517 |
if ( !isset( $is_utf8 ) ) { |
|
518 |
$is_utf8 = in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ); |
|
519 |
} |
|
520 |
if ( !$is_utf8 ) { |
|
521 |
return $string; |
|
522 |
} |
|
523 |
||
524 |
// Check for support for utf8 in the installed PCRE library once and store the result in a static |
|
525 |
static $utf8_pcre; |
|
526 |
if ( !isset( $utf8_pcre ) ) { |
|
527 |
$utf8_pcre = @preg_match( '/^./u', 'a' ); |
|
528 |
} |
|
529 |
// We can't demand utf8 in the PCRE installation, so just return the string in those cases |
|
530 |
if ( !$utf8_pcre ) { |
|
531 |
return $string; |
|
532 |
} |
|
533 |
||
534 |
// preg_match fails when it encounters invalid UTF8 in $string |
|
535 |
if ( 1 === @preg_match( '/^./us', $string ) ) { |
|
536 |
return $string; |
|
537 |
} |
|
538 |
||
539 |
// Attempt to strip the bad chars if requested (not recommended) |
|
540 |
if ( $strip && function_exists( 'iconv' ) ) { |
|
541 |
return iconv( 'utf-8', 'utf-8', $string ); |
|
542 |
} |
|
543 |
||
544 |
return ''; |
|
545 |
} |
|
546 |
||
547 |
/** |
|
548 |
* Encode the Unicode values to be used in the URI. |
|
549 |
* |
|
550 |
* @since 1.5.0 |
|
551 |
* |
|
552 |
* @param string $utf8_string |
|
553 |
* @param int $length Max length of the string |
|
554 |
* @return string String with Unicode encoded for URI. |
|
555 |
*/ |
|
556 |
function utf8_uri_encode( $utf8_string, $length = 0 ) { |
|
557 |
$unicode = ''; |
|
558 |
$values = array(); |
|
559 |
$num_octets = 1; |
|
560 |
$unicode_length = 0; |
|
561 |
||
562 |
$string_length = strlen( $utf8_string ); |
|
563 |
for ($i = 0; $i < $string_length; $i++ ) { |
|
564 |
||
565 |
$value = ord( $utf8_string[ $i ] ); |
|
566 |
||
567 |
if ( $value < 128 ) { |
|
568 |
if ( $length && ( $unicode_length >= $length ) ) |
|
569 |
break; |
|
570 |
$unicode .= chr($value); |
|
571 |
$unicode_length++; |
|
572 |
} else { |
|
573 |
if ( count( $values ) == 0 ) $num_octets = ( $value < 224 ) ? 2 : 3; |
|
574 |
||
575 |
$values[] = $value; |
|
576 |
||
577 |
if ( $length && ( $unicode_length + ($num_octets * 3) ) > $length ) |
|
578 |
break; |
|
579 |
if ( count( $values ) == $num_octets ) { |
|
580 |
if ($num_octets == 3) { |
|
581 |
$unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]); |
|
582 |
$unicode_length += 9; |
|
583 |
} else { |
|
584 |
$unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]); |
|
585 |
$unicode_length += 6; |
|
586 |
} |
|
587 |
||
588 |
$values = array(); |
|
589 |
$num_octets = 1; |
|
590 |
} |
|
591 |
} |
|
592 |
} |
|
593 |
||
594 |
return $unicode; |
|
595 |
} |
|
596 |
||
597 |
/** |
|
598 |
* Converts all accent characters to ASCII characters. |
|
599 |
* |
|
600 |
* If there are no accent characters, then the string given is just returned. |
|
601 |
* |
|
602 |
* @since 1.2.1 |
|
603 |
* |
|
604 |
* @param string $string Text that might have accent characters |
|
605 |
* @return string Filtered string with replaced "nice" characters. |
|
606 |
*/ |
|
607 |
function remove_accents($string) { |
|
608 |
if ( !preg_match('/[\x80-\xff]/', $string) ) |
|
609 |
return $string; |
|
610 |
||
611 |
if (seems_utf8($string)) { |
|
612 |
$chars = array( |
|
613 |
// Decompositions for Latin-1 Supplement |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
614 |
chr(194).chr(170) => 'a', chr(194).chr(186) => 'o', |
136 | 615 |
chr(195).chr(128) => 'A', chr(195).chr(129) => 'A', |
616 |
chr(195).chr(130) => 'A', chr(195).chr(131) => 'A', |
|
617 |
chr(195).chr(132) => 'A', chr(195).chr(133) => 'A', |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
618 |
chr(195).chr(134) => 'AE',chr(195).chr(135) => 'C', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
619 |
chr(195).chr(136) => 'E', chr(195).chr(137) => 'E', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
620 |
chr(195).chr(138) => 'E', chr(195).chr(139) => 'E', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
621 |
chr(195).chr(140) => 'I', chr(195).chr(141) => 'I', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
622 |
chr(195).chr(142) => 'I', chr(195).chr(143) => 'I', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
623 |
chr(195).chr(144) => 'D', chr(195).chr(145) => 'N', |
136 | 624 |
chr(195).chr(146) => 'O', chr(195).chr(147) => 'O', |
625 |
chr(195).chr(148) => 'O', chr(195).chr(149) => 'O', |
|
626 |
chr(195).chr(150) => 'O', chr(195).chr(153) => 'U', |
|
627 |
chr(195).chr(154) => 'U', chr(195).chr(155) => 'U', |
|
628 |
chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y', |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
629 |
chr(195).chr(158) => 'TH',chr(195).chr(159) => 's', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
630 |
chr(195).chr(160) => 'a', chr(195).chr(161) => 'a', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
631 |
chr(195).chr(162) => 'a', chr(195).chr(163) => 'a', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
632 |
chr(195).chr(164) => 'a', chr(195).chr(165) => 'a', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
633 |
chr(195).chr(166) => 'ae',chr(195).chr(167) => 'c', |
136 | 634 |
chr(195).chr(168) => 'e', chr(195).chr(169) => 'e', |
635 |
chr(195).chr(170) => 'e', chr(195).chr(171) => 'e', |
|
636 |
chr(195).chr(172) => 'i', chr(195).chr(173) => 'i', |
|
637 |
chr(195).chr(174) => 'i', chr(195).chr(175) => 'i', |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
638 |
chr(195).chr(176) => 'd', chr(195).chr(177) => 'n', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
639 |
chr(195).chr(178) => 'o', chr(195).chr(179) => 'o', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
640 |
chr(195).chr(180) => 'o', chr(195).chr(181) => 'o', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
641 |
chr(195).chr(182) => 'o', chr(195).chr(184) => 'o', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
642 |
chr(195).chr(185) => 'u', chr(195).chr(186) => 'u', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
643 |
chr(195).chr(187) => 'u', chr(195).chr(188) => 'u', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
644 |
chr(195).chr(189) => 'y', chr(195).chr(190) => 'th', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
645 |
chr(195).chr(191) => 'y', chr(195).chr(152) => 'O', |
136 | 646 |
// Decompositions for Latin Extended-A |
647 |
chr(196).chr(128) => 'A', chr(196).chr(129) => 'a', |
|
648 |
chr(196).chr(130) => 'A', chr(196).chr(131) => 'a', |
|
649 |
chr(196).chr(132) => 'A', chr(196).chr(133) => 'a', |
|
650 |
chr(196).chr(134) => 'C', chr(196).chr(135) => 'c', |
|
651 |
chr(196).chr(136) => 'C', chr(196).chr(137) => 'c', |
|
652 |
chr(196).chr(138) => 'C', chr(196).chr(139) => 'c', |
|
653 |
chr(196).chr(140) => 'C', chr(196).chr(141) => 'c', |
|
654 |
chr(196).chr(142) => 'D', chr(196).chr(143) => 'd', |
|
655 |
chr(196).chr(144) => 'D', chr(196).chr(145) => 'd', |
|
656 |
chr(196).chr(146) => 'E', chr(196).chr(147) => 'e', |
|
657 |
chr(196).chr(148) => 'E', chr(196).chr(149) => 'e', |
|
658 |
chr(196).chr(150) => 'E', chr(196).chr(151) => 'e', |
|
659 |
chr(196).chr(152) => 'E', chr(196).chr(153) => 'e', |
|
660 |
chr(196).chr(154) => 'E', chr(196).chr(155) => 'e', |
|
661 |
chr(196).chr(156) => 'G', chr(196).chr(157) => 'g', |
|
662 |
chr(196).chr(158) => 'G', chr(196).chr(159) => 'g', |
|
663 |
chr(196).chr(160) => 'G', chr(196).chr(161) => 'g', |
|
664 |
chr(196).chr(162) => 'G', chr(196).chr(163) => 'g', |
|
665 |
chr(196).chr(164) => 'H', chr(196).chr(165) => 'h', |
|
666 |
chr(196).chr(166) => 'H', chr(196).chr(167) => 'h', |
|
667 |
chr(196).chr(168) => 'I', chr(196).chr(169) => 'i', |
|
668 |
chr(196).chr(170) => 'I', chr(196).chr(171) => 'i', |
|
669 |
chr(196).chr(172) => 'I', chr(196).chr(173) => 'i', |
|
670 |
chr(196).chr(174) => 'I', chr(196).chr(175) => 'i', |
|
671 |
chr(196).chr(176) => 'I', chr(196).chr(177) => 'i', |
|
672 |
chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij', |
|
673 |
chr(196).chr(180) => 'J', chr(196).chr(181) => 'j', |
|
674 |
chr(196).chr(182) => 'K', chr(196).chr(183) => 'k', |
|
675 |
chr(196).chr(184) => 'k', chr(196).chr(185) => 'L', |
|
676 |
chr(196).chr(186) => 'l', chr(196).chr(187) => 'L', |
|
677 |
chr(196).chr(188) => 'l', chr(196).chr(189) => 'L', |
|
678 |
chr(196).chr(190) => 'l', chr(196).chr(191) => 'L', |
|
679 |
chr(197).chr(128) => 'l', chr(197).chr(129) => 'L', |
|
680 |
chr(197).chr(130) => 'l', chr(197).chr(131) => 'N', |
|
681 |
chr(197).chr(132) => 'n', chr(197).chr(133) => 'N', |
|
682 |
chr(197).chr(134) => 'n', chr(197).chr(135) => 'N', |
|
683 |
chr(197).chr(136) => 'n', chr(197).chr(137) => 'N', |
|
684 |
chr(197).chr(138) => 'n', chr(197).chr(139) => 'N', |
|
685 |
chr(197).chr(140) => 'O', chr(197).chr(141) => 'o', |
|
686 |
chr(197).chr(142) => 'O', chr(197).chr(143) => 'o', |
|
687 |
chr(197).chr(144) => 'O', chr(197).chr(145) => 'o', |
|
688 |
chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe', |
|
689 |
chr(197).chr(148) => 'R',chr(197).chr(149) => 'r', |
|
690 |
chr(197).chr(150) => 'R',chr(197).chr(151) => 'r', |
|
691 |
chr(197).chr(152) => 'R',chr(197).chr(153) => 'r', |
|
692 |
chr(197).chr(154) => 'S',chr(197).chr(155) => 's', |
|
693 |
chr(197).chr(156) => 'S',chr(197).chr(157) => 's', |
|
694 |
chr(197).chr(158) => 'S',chr(197).chr(159) => 's', |
|
695 |
chr(197).chr(160) => 'S', chr(197).chr(161) => 's', |
|
696 |
chr(197).chr(162) => 'T', chr(197).chr(163) => 't', |
|
697 |
chr(197).chr(164) => 'T', chr(197).chr(165) => 't', |
|
698 |
chr(197).chr(166) => 'T', chr(197).chr(167) => 't', |
|
699 |
chr(197).chr(168) => 'U', chr(197).chr(169) => 'u', |
|
700 |
chr(197).chr(170) => 'U', chr(197).chr(171) => 'u', |
|
701 |
chr(197).chr(172) => 'U', chr(197).chr(173) => 'u', |
|
702 |
chr(197).chr(174) => 'U', chr(197).chr(175) => 'u', |
|
703 |
chr(197).chr(176) => 'U', chr(197).chr(177) => 'u', |
|
704 |
chr(197).chr(178) => 'U', chr(197).chr(179) => 'u', |
|
705 |
chr(197).chr(180) => 'W', chr(197).chr(181) => 'w', |
|
706 |
chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y', |
|
707 |
chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z', |
|
708 |
chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z', |
|
709 |
chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z', |
|
710 |
chr(197).chr(190) => 'z', chr(197).chr(191) => 's', |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
711 |
// Decompositions for Latin Extended-B |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
712 |
chr(200).chr(152) => 'S', chr(200).chr(153) => 's', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
713 |
chr(200).chr(154) => 'T', chr(200).chr(155) => 't', |
136 | 714 |
// Euro Sign |
715 |
chr(226).chr(130).chr(172) => 'E', |
|
716 |
// GBP (Pound) Sign |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
717 |
chr(194).chr(163) => '', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
718 |
// Vowels with diacritic (Vietnamese) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
719 |
// unmarked |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
720 |
chr(198).chr(160) => 'O', chr(198).chr(161) => 'o', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
721 |
chr(198).chr(175) => 'U', chr(198).chr(176) => 'u', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
722 |
// grave accent |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
723 |
chr(225).chr(186).chr(166) => 'A', chr(225).chr(186).chr(167) => 'a', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
724 |
chr(225).chr(186).chr(176) => 'A', chr(225).chr(186).chr(177) => 'a', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
725 |
chr(225).chr(187).chr(128) => 'E', chr(225).chr(187).chr(129) => 'e', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
726 |
chr(225).chr(187).chr(146) => 'O', chr(225).chr(187).chr(147) => 'o', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
727 |
chr(225).chr(187).chr(156) => 'O', chr(225).chr(187).chr(157) => 'o', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
728 |
chr(225).chr(187).chr(170) => 'U', chr(225).chr(187).chr(171) => 'u', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
729 |
chr(225).chr(187).chr(178) => 'Y', chr(225).chr(187).chr(179) => 'y', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
730 |
// hook |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
731 |
chr(225).chr(186).chr(162) => 'A', chr(225).chr(186).chr(163) => 'a', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
732 |
chr(225).chr(186).chr(168) => 'A', chr(225).chr(186).chr(169) => 'a', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
733 |
chr(225).chr(186).chr(178) => 'A', chr(225).chr(186).chr(179) => 'a', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
734 |
chr(225).chr(186).chr(186) => 'E', chr(225).chr(186).chr(187) => 'e', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
735 |
chr(225).chr(187).chr(130) => 'E', chr(225).chr(187).chr(131) => 'e', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
736 |
chr(225).chr(187).chr(136) => 'I', chr(225).chr(187).chr(137) => 'i', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
737 |
chr(225).chr(187).chr(142) => 'O', chr(225).chr(187).chr(143) => 'o', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
738 |
chr(225).chr(187).chr(148) => 'O', chr(225).chr(187).chr(149) => 'o', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
739 |
chr(225).chr(187).chr(158) => 'O', chr(225).chr(187).chr(159) => 'o', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
740 |
chr(225).chr(187).chr(166) => 'U', chr(225).chr(187).chr(167) => 'u', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
741 |
chr(225).chr(187).chr(172) => 'U', chr(225).chr(187).chr(173) => 'u', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
742 |
chr(225).chr(187).chr(182) => 'Y', chr(225).chr(187).chr(183) => 'y', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
743 |
// tilde |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
744 |
chr(225).chr(186).chr(170) => 'A', chr(225).chr(186).chr(171) => 'a', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
745 |
chr(225).chr(186).chr(180) => 'A', chr(225).chr(186).chr(181) => 'a', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
746 |
chr(225).chr(186).chr(188) => 'E', chr(225).chr(186).chr(189) => 'e', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
747 |
chr(225).chr(187).chr(132) => 'E', chr(225).chr(187).chr(133) => 'e', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
748 |
chr(225).chr(187).chr(150) => 'O', chr(225).chr(187).chr(151) => 'o', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
749 |
chr(225).chr(187).chr(160) => 'O', chr(225).chr(187).chr(161) => 'o', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
750 |
chr(225).chr(187).chr(174) => 'U', chr(225).chr(187).chr(175) => 'u', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
751 |
chr(225).chr(187).chr(184) => 'Y', chr(225).chr(187).chr(185) => 'y', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
752 |
// acute accent |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
753 |
chr(225).chr(186).chr(164) => 'A', chr(225).chr(186).chr(165) => 'a', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
754 |
chr(225).chr(186).chr(174) => 'A', chr(225).chr(186).chr(175) => 'a', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
755 |
chr(225).chr(186).chr(190) => 'E', chr(225).chr(186).chr(191) => 'e', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
756 |
chr(225).chr(187).chr(144) => 'O', chr(225).chr(187).chr(145) => 'o', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
757 |
chr(225).chr(187).chr(154) => 'O', chr(225).chr(187).chr(155) => 'o', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
758 |
chr(225).chr(187).chr(168) => 'U', chr(225).chr(187).chr(169) => 'u', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
759 |
// dot below |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
760 |
chr(225).chr(186).chr(160) => 'A', chr(225).chr(186).chr(161) => 'a', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
761 |
chr(225).chr(186).chr(172) => 'A', chr(225).chr(186).chr(173) => 'a', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
762 |
chr(225).chr(186).chr(182) => 'A', chr(225).chr(186).chr(183) => 'a', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
763 |
chr(225).chr(186).chr(184) => 'E', chr(225).chr(186).chr(185) => 'e', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
764 |
chr(225).chr(187).chr(134) => 'E', chr(225).chr(187).chr(135) => 'e', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
765 |
chr(225).chr(187).chr(138) => 'I', chr(225).chr(187).chr(139) => 'i', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
766 |
chr(225).chr(187).chr(140) => 'O', chr(225).chr(187).chr(141) => 'o', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
767 |
chr(225).chr(187).chr(152) => 'O', chr(225).chr(187).chr(153) => 'o', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
768 |
chr(225).chr(187).chr(162) => 'O', chr(225).chr(187).chr(163) => 'o', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
769 |
chr(225).chr(187).chr(164) => 'U', chr(225).chr(187).chr(165) => 'u', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
770 |
chr(225).chr(187).chr(176) => 'U', chr(225).chr(187).chr(177) => 'u', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
771 |
chr(225).chr(187).chr(180) => 'Y', chr(225).chr(187).chr(181) => 'y', |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
772 |
// Vowels with diacritic (Chinese, Hanyu Pinyin) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
773 |
chr(201).chr(145) => 'a', |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
774 |
// macron |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
775 |
chr(199).chr(149) => 'U', chr(199).chr(150) => 'u', |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
776 |
// acute accent |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
777 |
chr(199).chr(151) => 'U', chr(199).chr(152) => 'u', |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
778 |
// caron |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
779 |
chr(199).chr(141) => 'A', chr(199).chr(142) => 'a', |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
780 |
chr(199).chr(143) => 'I', chr(199).chr(144) => 'i', |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
781 |
chr(199).chr(145) => 'O', chr(199).chr(146) => 'o', |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
782 |
chr(199).chr(147) => 'U', chr(199).chr(148) => 'u', |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
783 |
chr(199).chr(153) => 'U', chr(199).chr(154) => 'u', |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
784 |
// grave accent |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
785 |
chr(199).chr(155) => 'U', chr(199).chr(156) => 'u', |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
786 |
); |
136 | 787 |
|
788 |
$string = strtr($string, $chars); |
|
789 |
} else { |
|
790 |
// Assume ISO-8859-1 if not UTF-8 |
|
791 |
$chars['in'] = chr(128).chr(131).chr(138).chr(142).chr(154).chr(158) |
|
792 |
.chr(159).chr(162).chr(165).chr(181).chr(192).chr(193).chr(194) |
|
793 |
.chr(195).chr(196).chr(197).chr(199).chr(200).chr(201).chr(202) |
|
794 |
.chr(203).chr(204).chr(205).chr(206).chr(207).chr(209).chr(210) |
|
795 |
.chr(211).chr(212).chr(213).chr(214).chr(216).chr(217).chr(218) |
|
796 |
.chr(219).chr(220).chr(221).chr(224).chr(225).chr(226).chr(227) |
|
797 |
.chr(228).chr(229).chr(231).chr(232).chr(233).chr(234).chr(235) |
|
798 |
.chr(236).chr(237).chr(238).chr(239).chr(241).chr(242).chr(243) |
|
799 |
.chr(244).chr(245).chr(246).chr(248).chr(249).chr(250).chr(251) |
|
800 |
.chr(252).chr(253).chr(255); |
|
801 |
||
802 |
$chars['out'] = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy"; |
|
803 |
||
804 |
$string = strtr($string, $chars['in'], $chars['out']); |
|
805 |
$double_chars['in'] = array(chr(140), chr(156), chr(198), chr(208), chr(222), chr(223), chr(230), chr(240), chr(254)); |
|
806 |
$double_chars['out'] = array('OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th'); |
|
807 |
$string = str_replace($double_chars['in'], $double_chars['out'], $string); |
|
808 |
} |
|
809 |
||
810 |
return $string; |
|
811 |
} |
|
812 |
||
813 |
/** |
|
814 |
* Sanitizes a filename replacing whitespace with dashes |
|
815 |
* |
|
816 |
* Removes special characters that are illegal in filenames on certain |
|
817 |
* operating systems and special characters requiring special escaping |
|
818 |
* to manipulate at the command line. Replaces spaces and consecutive |
|
819 |
* dashes with a single dash. Trim period, dash and underscore from beginning |
|
820 |
* and end of filename. |
|
821 |
* |
|
822 |
* @since 2.1.0 |
|
823 |
* |
|
824 |
* @param string $filename The filename to be sanitized |
|
825 |
* @return string The sanitized filename |
|
826 |
*/ |
|
827 |
function sanitize_file_name( $filename ) { |
|
828 |
$filename_raw = $filename; |
|
829 |
$special_chars = array("?", "[", "]", "/", "\\", "=", "<", ">", ":", ";", ",", "'", "\"", "&", "$", "#", "*", "(", ")", "|", "~", "`", "!", "{", "}", chr(0)); |
|
830 |
$special_chars = apply_filters('sanitize_file_name_chars', $special_chars, $filename_raw); |
|
831 |
$filename = str_replace($special_chars, '', $filename); |
|
832 |
$filename = preg_replace('/[\s-]+/', '-', $filename); |
|
833 |
$filename = trim($filename, '.-_'); |
|
834 |
||
835 |
// Split the filename into a base and extension[s] |
|
836 |
$parts = explode('.', $filename); |
|
837 |
||
838 |
// Return if only one extension |
|
839 |
if ( count($parts) <= 2 ) |
|
840 |
return apply_filters('sanitize_file_name', $filename, $filename_raw); |
|
841 |
||
842 |
// Process multiple extensions |
|
843 |
$filename = array_shift($parts); |
|
844 |
$extension = array_pop($parts); |
|
845 |
$mimes = get_allowed_mime_types(); |
|
846 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
847 |
// Loop over any intermediate extensions. Munge them with a trailing underscore if they are a 2 - 5 character |
136 | 848 |
// long alpha string not in the extension whitelist. |
849 |
foreach ( (array) $parts as $part) { |
|
850 |
$filename .= '.' . $part; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
851 |
|
136 | 852 |
if ( preg_match("/^[a-zA-Z]{2,5}\d?$/", $part) ) { |
853 |
$allowed = false; |
|
854 |
foreach ( $mimes as $ext_preg => $mime_match ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
855 |
$ext_preg = '!^(' . $ext_preg . ')$!i'; |
136 | 856 |
if ( preg_match( $ext_preg, $part ) ) { |
857 |
$allowed = true; |
|
858 |
break; |
|
859 |
} |
|
860 |
} |
|
861 |
if ( !$allowed ) |
|
862 |
$filename .= '_'; |
|
863 |
} |
|
864 |
} |
|
865 |
$filename .= '.' . $extension; |
|
866 |
||
867 |
return apply_filters('sanitize_file_name', $filename, $filename_raw); |
|
868 |
} |
|
869 |
||
870 |
/** |
|
871 |
* Sanitize username stripping out unsafe characters. |
|
872 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
873 |
* Removes tags, octets, entities, and if strict is enabled, will only keep |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
874 |
* alphanumeric, _, space, ., -, @. After sanitizing, it passes the username, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
875 |
* raw username (the username in the parameter), and the value of $strict as |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
876 |
* parameters for the 'sanitize_user' filter. |
136 | 877 |
* |
878 |
* @since 2.0.0 |
|
879 |
* @uses apply_filters() Calls 'sanitize_user' hook on username, raw username, |
|
880 |
* and $strict parameter. |
|
881 |
* |
|
882 |
* @param string $username The username to be sanitized. |
|
883 |
* @param bool $strict If set limits $username to specific characters. Default false. |
|
884 |
* @return string The sanitized username, after passing through filters. |
|
885 |
*/ |
|
886 |
function sanitize_user( $username, $strict = false ) { |
|
887 |
$raw_username = $username; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
888 |
$username = wp_strip_all_tags( $username ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
889 |
$username = remove_accents( $username ); |
136 | 890 |
// Kill octets |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
891 |
$username = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '', $username ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
892 |
$username = preg_replace( '/&.+?;/', '', $username ); // Kill entities |
136 | 893 |
|
894 |
// If strict, reduce to ASCII for max portability. |
|
895 |
if ( $strict ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
896 |
$username = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $username ); |
136 | 897 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
898 |
$username = trim( $username ); |
136 | 899 |
// Consolidate contiguous whitespace |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
900 |
$username = preg_replace( '|\s+|', ' ', $username ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
901 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
902 |
return apply_filters( 'sanitize_user', $username, $raw_username, $strict ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
903 |
} |
136 | 904 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
905 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
906 |
* Sanitize a string key. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
907 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
908 |
* Keys are used as internal identifiers. Lowercase alphanumeric characters, dashes and underscores are allowed. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
909 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
910 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
911 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
912 |
* @param string $key String key |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
913 |
* @return string Sanitized key |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
914 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
915 |
function sanitize_key( $key ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
916 |
$raw_key = $key; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
917 |
$key = strtolower( $key ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
918 |
$key = preg_replace( '/[^a-z0-9_\-]/', '', $key ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
919 |
return apply_filters( 'sanitize_key', $key, $raw_key ); |
136 | 920 |
} |
921 |
||
922 |
/** |
|
923 |
* Sanitizes title or use fallback title. |
|
924 |
* |
|
925 |
* Specifically, HTML and PHP tags are stripped. Further actions can be added |
|
926 |
* via the plugin API. If $title is empty and $fallback_title is set, the latter |
|
927 |
* will be used. |
|
928 |
* |
|
929 |
* @since 1.0.0 |
|
930 |
* |
|
931 |
* @param string $title The string to be sanitized. |
|
932 |
* @param string $fallback_title Optional. A title to use if $title is empty. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
933 |
* @param string $context Optional. The operation for which the string is sanitized |
136 | 934 |
* @return string The sanitized string. |
935 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
936 |
function sanitize_title($title, $fallback_title = '', $context = 'save') { |
136 | 937 |
$raw_title = $title; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
938 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
939 |
if ( 'save' == $context ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
940 |
$title = remove_accents($title); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
941 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
942 |
$title = apply_filters('sanitize_title', $title, $raw_title, $context); |
136 | 943 |
|
944 |
if ( '' === $title || false === $title ) |
|
945 |
$title = $fallback_title; |
|
946 |
||
947 |
return $title; |
|
948 |
} |
|
949 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
950 |
function sanitize_title_for_query($title) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
951 |
return sanitize_title($title, '', 'query'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
952 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
953 |
|
136 | 954 |
/** |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
955 |
* Sanitizes title, replacing whitespace and a few other characters with dashes. |
136 | 956 |
* |
957 |
* Limits the output to alphanumeric characters, underscore (_) and dash (-). |
|
958 |
* Whitespace becomes a dash. |
|
959 |
* |
|
960 |
* @since 1.2.0 |
|
961 |
* |
|
962 |
* @param string $title The title to be sanitized. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
963 |
* @param string $raw_title Optional. Not used. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
964 |
* @param string $context Optional. The operation for which the string is sanitized. |
136 | 965 |
* @return string The sanitized title. |
966 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
967 |
function sanitize_title_with_dashes($title, $raw_title = '', $context = 'display') { |
136 | 968 |
$title = strip_tags($title); |
969 |
// Preserve escaped octets. |
|
970 |
$title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title); |
|
971 |
// Remove percent signs that are not part of an octet. |
|
972 |
$title = str_replace('%', '', $title); |
|
973 |
// Restore octets. |
|
974 |
$title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title); |
|
975 |
||
976 |
if (seems_utf8($title)) { |
|
977 |
if (function_exists('mb_strtolower')) { |
|
978 |
$title = mb_strtolower($title, 'UTF-8'); |
|
979 |
} |
|
980 |
$title = utf8_uri_encode($title, 200); |
|
981 |
} |
|
982 |
||
983 |
$title = strtolower($title); |
|
984 |
$title = preg_replace('/&.+?;/', '', $title); // kill entities |
|
985 |
$title = str_replace('.', '-', $title); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
986 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
987 |
if ( 'save' == $context ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
988 |
// Convert nbsp, ndash and mdash to hyphens |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
989 |
$title = str_replace( array( '%c2%a0', '%e2%80%93', '%e2%80%94' ), '-', $title ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
990 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
991 |
// Strip these characters entirely |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
992 |
$title = str_replace( array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
993 |
// iexcl and iquest |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
994 |
'%c2%a1', '%c2%bf', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
995 |
// angle quotes |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
996 |
'%c2%ab', '%c2%bb', '%e2%80%b9', '%e2%80%ba', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
997 |
// curly quotes |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
998 |
'%e2%80%98', '%e2%80%99', '%e2%80%9c', '%e2%80%9d', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
999 |
'%e2%80%9a', '%e2%80%9b', '%e2%80%9e', '%e2%80%9f', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1000 |
// copy, reg, deg, hellip and trade |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1001 |
'%c2%a9', '%c2%ae', '%c2%b0', '%e2%80%a6', '%e2%84%a2', |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1002 |
// grave accent, acute accent, macron, caron |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1003 |
'%cc%80', '%cc%81', '%cc%84', '%cc%8c', |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1004 |
), '', $title ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1005 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1006 |
// Convert times to x |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1007 |
$title = str_replace( '%c3%97', 'x', $title ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1008 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1009 |
|
136 | 1010 |
$title = preg_replace('/[^%a-z0-9 _-]/', '', $title); |
1011 |
$title = preg_replace('/\s+/', '-', $title); |
|
1012 |
$title = preg_replace('|-+|', '-', $title); |
|
1013 |
$title = trim($title, '-'); |
|
1014 |
||
1015 |
return $title; |
|
1016 |
} |
|
1017 |
||
1018 |
/** |
|
1019 |
* Ensures a string is a valid SQL order by clause. |
|
1020 |
* |
|
1021 |
* Accepts one or more columns, with or without ASC/DESC, and also accepts |
|
1022 |
* RAND(). |
|
1023 |
* |
|
1024 |
* @since 2.5.1 |
|
1025 |
* |
|
1026 |
* @param string $orderby Order by string to be checked. |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1027 |
* @return string|bool Returns the order by clause if it is a match, false otherwise. |
136 | 1028 |
*/ |
1029 |
function sanitize_sql_orderby( $orderby ){ |
|
1030 |
preg_match('/^\s*([a-z0-9_]+(\s+(ASC|DESC))?(\s*,\s*|\s*$))+|^\s*RAND\(\s*\)\s*$/i', $orderby, $obmatches); |
|
1031 |
if ( !$obmatches ) |
|
1032 |
return false; |
|
1033 |
return $orderby; |
|
1034 |
} |
|
1035 |
||
1036 |
/** |
|
1037 |
* Santizes a html classname to ensure it only contains valid characters |
|
1038 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1039 |
* Strips the string down to A-Z,a-z,0-9,_,-. If this results in an empty |
136 | 1040 |
* string then it will return the alternative value supplied. |
1041 |
* |
|
1042 |
* @todo Expand to support the full range of CDATA that a class attribute can contain. |
|
1043 |
* |
|
1044 |
* @since 2.8.0 |
|
1045 |
* |
|
1046 |
* @param string $class The classname to be sanitized |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1047 |
* @param string $fallback Optional. The value to return if the sanitization end's up as an empty string. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1048 |
* Defaults to an empty string. |
136 | 1049 |
* @return string The sanitized value |
1050 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1051 |
function sanitize_html_class( $class, $fallback = '' ) { |
136 | 1052 |
//Strip out any % encoded octets |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1053 |
$sanitized = preg_replace( '|%[a-fA-F0-9][a-fA-F0-9]|', '', $class ); |
136 | 1054 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1055 |
//Limit to A-Z,a-z,0-9,_,- |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1056 |
$sanitized = preg_replace( '/[^A-Za-z0-9_-]/', '', $sanitized ); |
136 | 1057 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1058 |
if ( '' == $sanitized ) |
136 | 1059 |
$sanitized = $fallback; |
1060 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1061 |
return apply_filters( 'sanitize_html_class', $sanitized, $class, $fallback ); |
136 | 1062 |
} |
1063 |
||
1064 |
/** |
|
1065 |
* Converts a number of characters from a string. |
|
1066 |
* |
|
1067 |
* Metadata tags <<title>> and <<category>> are removed, <<br>> and <<hr>> are |
|
1068 |
* converted into correct XHTML and Unicode characters are converted to the |
|
1069 |
* valid range. |
|
1070 |
* |
|
1071 |
* @since 0.71 |
|
1072 |
* |
|
1073 |
* @param string $content String of characters to be converted. |
|
1074 |
* @param string $deprecated Not used. |
|
1075 |
* @return string Converted string. |
|
1076 |
*/ |
|
1077 |
function convert_chars($content, $deprecated = '') { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1078 |
if ( !empty( $deprecated ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1079 |
_deprecated_argument( __FUNCTION__, '0.71' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1080 |
|
136 | 1081 |
// Translation of invalid Unicode references range to valid range |
1082 |
$wp_htmltranswinuni = array( |
|
1083 |
'€' => '€', // the Euro sign |
|
1084 |
'' => '', |
|
1085 |
'‚' => '‚', // these are Windows CP1252 specific characters |
|
1086 |
'ƒ' => 'ƒ', // they would look weird on non-Windows browsers |
|
1087 |
'„' => '„', |
|
1088 |
'…' => '…', |
|
1089 |
'†' => '†', |
|
1090 |
'‡' => '‡', |
|
1091 |
'ˆ' => 'ˆ', |
|
1092 |
'‰' => '‰', |
|
1093 |
'Š' => 'Š', |
|
1094 |
'‹' => '‹', |
|
1095 |
'Œ' => 'Œ', |
|
1096 |
'' => '', |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1097 |
'Ž' => 'Ž', |
136 | 1098 |
'' => '', |
1099 |
'' => '', |
|
1100 |
'‘' => '‘', |
|
1101 |
'’' => '’', |
|
1102 |
'“' => '“', |
|
1103 |
'”' => '”', |
|
1104 |
'•' => '•', |
|
1105 |
'–' => '–', |
|
1106 |
'—' => '—', |
|
1107 |
'˜' => '˜', |
|
1108 |
'™' => '™', |
|
1109 |
'š' => 'š', |
|
1110 |
'›' => '›', |
|
1111 |
'œ' => 'œ', |
|
1112 |
'' => '', |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1113 |
'ž' => 'ž', |
136 | 1114 |
'Ÿ' => 'Ÿ' |
1115 |
); |
|
1116 |
||
1117 |
// Remove metadata tags |
|
1118 |
$content = preg_replace('/<title>(.+?)<\/title>/','',$content); |
|
1119 |
$content = preg_replace('/<category>(.+?)<\/category>/','',$content); |
|
1120 |
||
1121 |
// Converts lone & characters into & (a.k.a. &) |
|
1122 |
$content = preg_replace('/&([^#])(?![a-z1-4]{1,8};)/i', '&$1', $content); |
|
1123 |
||
1124 |
// Fix Word pasting |
|
1125 |
$content = strtr($content, $wp_htmltranswinuni); |
|
1126 |
||
1127 |
// Just a little XHTML help |
|
1128 |
$content = str_replace('<br>', '<br />', $content); |
|
1129 |
$content = str_replace('<hr>', '<hr />', $content); |
|
1130 |
||
1131 |
return $content; |
|
1132 |
} |
|
1133 |
||
1134 |
/** |
|
1135 |
* Will only balance the tags if forced to and the option is set to balance tags. |
|
1136 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1137 |
* The option 'use_balanceTags' is used to determine whether the tags will be balanced. |
136 | 1138 |
* |
1139 |
* @since 0.71 |
|
1140 |
* |
|
1141 |
* @param string $text Text to be balanced |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1142 |
* @param bool $force If true, forces balancing, ignoring the value of the option. Default false. |
136 | 1143 |
* @return string Balanced text |
1144 |
*/ |
|
1145 |
function balanceTags( $text, $force = false ) { |
|
1146 |
if ( !$force && get_option('use_balanceTags') == 0 ) |
|
1147 |
return $text; |
|
1148 |
return force_balance_tags( $text ); |
|
1149 |
} |
|
1150 |
||
1151 |
/** |
|
1152 |
* Balances tags of string using a modified stack. |
|
1153 |
* |
|
1154 |
* @since 2.0.4 |
|
1155 |
* |
|
1156 |
* @author Leonard Lin <leonard@acm.org> |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1157 |
* @license GPL |
136 | 1158 |
* @copyright November 4, 2001 |
1159 |
* @version 1.1 |
|
1160 |
* @todo Make better - change loop condition to $text in 1.2 |
|
1161 |
* @internal Modified by Scott Reilly (coffee2code) 02 Aug 2004 |
|
1162 |
* 1.1 Fixed handling of append/stack pop order of end text |
|
1163 |
* Added Cleaning Hooks |
|
1164 |
* 1.0 First Version |
|
1165 |
* |
|
1166 |
* @param string $text Text to be balanced. |
|
1167 |
* @return string Balanced text. |
|
1168 |
*/ |
|
1169 |
function force_balance_tags( $text ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1170 |
$tagstack = array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1171 |
$stacksize = 0; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1172 |
$tagqueue = ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1173 |
$newtext = ''; |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1174 |
// Known single-entity/self-closing tags |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1175 |
$single_tags = array( 'area', 'base', 'basefont', 'br', 'col', 'command', 'embed', 'frame', 'hr', 'img', 'input', 'isindex', 'link', 'meta', 'param', 'source' ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1176 |
// Tags that can be immediately nested within themselves |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1177 |
$nestable_tags = array( 'blockquote', 'div', 'object', 'q', 'span' ); |
136 | 1178 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1179 |
// WP bug fix for comments - in case you REALLY meant to type '< !--' |
136 | 1180 |
$text = str_replace('< !--', '< !--', $text); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1181 |
// WP bug fix for LOVE <3 (and other situations with '<' before a number) |
136 | 1182 |
$text = preg_replace('#<([0-9]{1})#', '<$1', $text); |
1183 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1184 |
while ( preg_match("/<(\/?[\w:]*)\s*([^>]*)>/", $text, $regex) ) { |
136 | 1185 |
$newtext .= $tagqueue; |
1186 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1187 |
$i = strpos($text, $regex[0]); |
136 | 1188 |
$l = strlen($regex[0]); |
1189 |
||
1190 |
// clear the shifter |
|
1191 |
$tagqueue = ''; |
|
1192 |
// Pop or Push |
|
1193 |
if ( isset($regex[1][0]) && '/' == $regex[1][0] ) { // End Tag |
|
1194 |
$tag = strtolower(substr($regex[1],1)); |
|
1195 |
// if too many closing tags |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1196 |
if( $stacksize <= 0 ) { |
136 | 1197 |
$tag = ''; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1198 |
// or close to be safe $tag = '/' . $tag; |
136 | 1199 |
} |
1200 |
// if stacktop value = tag close value then pop |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1201 |
else if ( $tagstack[$stacksize - 1] == $tag ) { // found closing tag |
136 | 1202 |
$tag = '</' . $tag . '>'; // Close Tag |
1203 |
// Pop |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1204 |
array_pop( $tagstack ); |
136 | 1205 |
$stacksize--; |
1206 |
} else { // closing tag not at top, search for it |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1207 |
for ( $j = $stacksize-1; $j >= 0; $j-- ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1208 |
if ( $tagstack[$j] == $tag ) { |
136 | 1209 |
// add tag to tagqueue |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1210 |
for ( $k = $stacksize-1; $k >= $j; $k--) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1211 |
$tagqueue .= '</' . array_pop( $tagstack ) . '>'; |
136 | 1212 |
$stacksize--; |
1213 |
} |
|
1214 |
break; |
|
1215 |
} |
|
1216 |
} |
|
1217 |
$tag = ''; |
|
1218 |
} |
|
1219 |
} else { // Begin Tag |
|
1220 |
$tag = strtolower($regex[1]); |
|
1221 |
||
1222 |
// Tag Cleaning |
|
1223 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1224 |
// If it's an empty tag "< >", do nothing |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1225 |
if ( '' == $tag ) { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1226 |
// do nothing |
136 | 1227 |
} |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1228 |
// ElseIf it presents itself as a self-closing tag... |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1229 |
elseif ( substr( $regex[2], -1 ) == '/' ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1230 |
// ...but it isn't a known single-entity self-closing tag, then don't let it be treated as such and |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1231 |
// immediately close it with a closing tag (the tag will encapsulate no text as a result) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1232 |
if ( ! in_array( $tag, $single_tags ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1233 |
$regex[2] = trim( substr( $regex[2], 0, -1 ) ) . "></$tag"; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1234 |
} |
136 | 1235 |
// ElseIf it's a known single-entity tag but it doesn't close itself, do so |
1236 |
elseif ( in_array($tag, $single_tags) ) { |
|
1237 |
$regex[2] .= '/'; |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1238 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1239 |
// Else it's not a single-entity tag |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1240 |
else { |
136 | 1241 |
// If the top of the stack is the same as the tag we want to push, close previous tag |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1242 |
if ( $stacksize > 0 && !in_array($tag, $nestable_tags) && $tagstack[$stacksize - 1] == $tag ) { |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1243 |
$tagqueue = '</' . array_pop( $tagstack ) . '>'; |
136 | 1244 |
$stacksize--; |
1245 |
} |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1246 |
$stacksize = array_push( $tagstack, $tag ); |
136 | 1247 |
} |
1248 |
||
1249 |
// Attributes |
|
1250 |
$attributes = $regex[2]; |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1251 |
if( ! empty( $attributes ) && $attributes[0] != '>' ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1252 |
$attributes = ' ' . $attributes; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1253 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1254 |
$tag = '<' . $tag . $attributes . '>'; |
136 | 1255 |
//If already queuing a close tag, then put this tag on, too |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1256 |
if ( !empty($tagqueue) ) { |
136 | 1257 |
$tagqueue .= $tag; |
1258 |
$tag = ''; |
|
1259 |
} |
|
1260 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1261 |
$newtext .= substr($text, 0, $i) . $tag; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1262 |
$text = substr($text, $i + $l); |
136 | 1263 |
} |
1264 |
||
1265 |
// Clear Tag Queue |
|
1266 |
$newtext .= $tagqueue; |
|
1267 |
||
1268 |
// Add Remaining text |
|
1269 |
$newtext .= $text; |
|
1270 |
||
1271 |
// Empty Stack |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1272 |
while( $x = array_pop($tagstack) ) |
136 | 1273 |
$newtext .= '</' . $x . '>'; // Add remaining tags to close |
1274 |
||
1275 |
// WP fix for the bug with HTML comments |
|
1276 |
$newtext = str_replace("< !--","<!--",$newtext); |
|
1277 |
$newtext = str_replace("< !--","< !--",$newtext); |
|
1278 |
||
1279 |
return $newtext; |
|
1280 |
} |
|
1281 |
||
1282 |
/** |
|
1283 |
* Acts on text which is about to be edited. |
|
1284 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1285 |
* The $content is run through esc_textarea(), which uses htmlspecialchars() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1286 |
* to convert special characters to HTML entities. If $richedit is set to true, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1287 |
* it is simply a holder for the 'format_to_edit' filter. |
136 | 1288 |
* |
1289 |
* @since 0.71 |
|
1290 |
* |
|
1291 |
* @param string $content The text about to be edited. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1292 |
* @param bool $richedit Whether the $content should not pass through htmlspecialchars(). Default false (meaning it will be passed). |
136 | 1293 |
* @return string The text after the filter (and possibly htmlspecialchars()) has been run. |
1294 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1295 |
function format_to_edit( $content, $richedit = false ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1296 |
$content = apply_filters( 'format_to_edit', $content ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1297 |
if ( ! $richedit ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1298 |
$content = esc_textarea( $content ); |
136 | 1299 |
return $content; |
1300 |
} |
|
1301 |
||
1302 |
/** |
|
1303 |
* Holder for the 'format_to_post' filter. |
|
1304 |
* |
|
1305 |
* @since 0.71 |
|
1306 |
* |
|
1307 |
* @param string $content The text to pass through the filter. |
|
1308 |
* @return string Text returned from the 'format_to_post' filter. |
|
1309 |
*/ |
|
1310 |
function format_to_post($content) { |
|
1311 |
$content = apply_filters('format_to_post', $content); |
|
1312 |
return $content; |
|
1313 |
} |
|
1314 |
||
1315 |
/** |
|
1316 |
* Add leading zeros when necessary. |
|
1317 |
* |
|
1318 |
* If you set the threshold to '4' and the number is '10', then you will get |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1319 |
* back '0010'. If you set the threshold to '4' and the number is '5000', then you |
136 | 1320 |
* will get back '5000'. |
1321 |
* |
|
1322 |
* Uses sprintf to append the amount of zeros based on the $threshold parameter |
|
1323 |
* and the size of the number. If the number is large enough, then no zeros will |
|
1324 |
* be appended. |
|
1325 |
* |
|
1326 |
* @since 0.71 |
|
1327 |
* |
|
1328 |
* @param mixed $number Number to append zeros to if not greater than threshold. |
|
1329 |
* @param int $threshold Digit places number needs to be to not have zeros added. |
|
1330 |
* @return string Adds leading zeros to number if needed. |
|
1331 |
*/ |
|
1332 |
function zeroise($number, $threshold) { |
|
1333 |
return sprintf('%0'.$threshold.'s', $number); |
|
1334 |
} |
|
1335 |
||
1336 |
/** |
|
1337 |
* Adds backslashes before letters and before a number at the start of a string. |
|
1338 |
* |
|
1339 |
* @since 0.71 |
|
1340 |
* |
|
1341 |
* @param string $string Value to which backslashes will be added. |
|
1342 |
* @return string String with backslashes inserted. |
|
1343 |
*/ |
|
1344 |
function backslashit($string) { |
|
1345 |
$string = preg_replace('/^([0-9])/', '\\\\\\\\\1', $string); |
|
1346 |
$string = preg_replace('/([a-z])/i', '\\\\\1', $string); |
|
1347 |
return $string; |
|
1348 |
} |
|
1349 |
||
1350 |
/** |
|
1351 |
* Appends a trailing slash. |
|
1352 |
* |
|
1353 |
* Will remove trailing slash if it exists already before adding a trailing |
|
1354 |
* slash. This prevents double slashing a string or path. |
|
1355 |
* |
|
1356 |
* The primary use of this is for paths and thus should be used for paths. It is |
|
1357 |
* not restricted to paths and offers no specific path support. |
|
1358 |
* |
|
1359 |
* @since 1.2.0 |
|
1360 |
* @uses untrailingslashit() Unslashes string if it was slashed already. |
|
1361 |
* |
|
1362 |
* @param string $string What to add the trailing slash to. |
|
1363 |
* @return string String with trailing slash added. |
|
1364 |
*/ |
|
1365 |
function trailingslashit($string) { |
|
1366 |
return untrailingslashit($string) . '/'; |
|
1367 |
} |
|
1368 |
||
1369 |
/** |
|
1370 |
* Removes trailing slash if it exists. |
|
1371 |
* |
|
1372 |
* The primary use of this is for paths and thus should be used for paths. It is |
|
1373 |
* not restricted to paths and offers no specific path support. |
|
1374 |
* |
|
1375 |
* @since 2.2.0 |
|
1376 |
* |
|
1377 |
* @param string $string What to remove the trailing slash from. |
|
1378 |
* @return string String without the trailing slash. |
|
1379 |
*/ |
|
1380 |
function untrailingslashit($string) { |
|
1381 |
return rtrim($string, '/'); |
|
1382 |
} |
|
1383 |
||
1384 |
/** |
|
1385 |
* Adds slashes to escape strings. |
|
1386 |
* |
|
1387 |
* Slashes will first be removed if magic_quotes_gpc is set, see {@link |
|
1388 |
* http://www.php.net/magic_quotes} for more details. |
|
1389 |
* |
|
1390 |
* @since 0.71 |
|
1391 |
* |
|
1392 |
* @param string $gpc The string returned from HTTP request data. |
|
1393 |
* @return string Returns a string escaped with slashes. |
|
1394 |
*/ |
|
1395 |
function addslashes_gpc($gpc) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1396 |
if ( get_magic_quotes_gpc() ) |
136 | 1397 |
$gpc = stripslashes($gpc); |
1398 |
||
1399 |
return esc_sql($gpc); |
|
1400 |
} |
|
1401 |
||
1402 |
/** |
|
1403 |
* Navigates through an array and removes slashes from the values. |
|
1404 |
* |
|
1405 |
* If an array is passed, the array_map() function causes a callback to pass the |
|
1406 |
* value back to the function. The slashes from this value will removed. |
|
1407 |
* |
|
1408 |
* @since 2.0.0 |
|
1409 |
* |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1410 |
* @param mixed $value The value to be stripped. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1411 |
* @return mixed Stripped value. |
136 | 1412 |
*/ |
1413 |
function stripslashes_deep($value) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1414 |
if ( is_array($value) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1415 |
$value = array_map('stripslashes_deep', $value); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1416 |
} elseif ( is_object($value) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1417 |
$vars = get_object_vars( $value ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1418 |
foreach ($vars as $key=>$data) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1419 |
$value->{$key} = stripslashes_deep( $data ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1420 |
} |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1421 |
} elseif ( is_string( $value ) ) { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1422 |
$value = stripslashes($value); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1423 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1424 |
|
136 | 1425 |
return $value; |
1426 |
} |
|
1427 |
||
1428 |
/** |
|
1429 |
* Navigates through an array and encodes the values to be used in a URL. |
|
1430 |
* |
|
1431 |
* |
|
1432 |
* @since 2.2.0 |
|
1433 |
* |
|
1434 |
* @param array|string $value The array or string to be encoded. |
|
1435 |
* @return array|string $value The encoded array (or string from the callback). |
|
1436 |
*/ |
|
1437 |
function urlencode_deep($value) { |
|
1438 |
$value = is_array($value) ? array_map('urlencode_deep', $value) : urlencode($value); |
|
1439 |
return $value; |
|
1440 |
} |
|
1441 |
||
1442 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1443 |
* Navigates through an array and raw encodes the values to be used in a URL. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1444 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1445 |
* @since 3.4.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1446 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1447 |
* @param array|string $value The array or string to be encoded. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1448 |
* @return array|string $value The encoded array (or string from the callback). |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1449 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1450 |
function rawurlencode_deep( $value ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1451 |
return is_array( $value ) ? array_map( 'rawurlencode_deep', $value ) : rawurlencode( $value ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1452 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1453 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1454 |
/** |
136 | 1455 |
* Converts email addresses characters to HTML entities to block spam bots. |
1456 |
* |
|
1457 |
* @since 0.71 |
|
1458 |
* |
|
1459 |
* @param string $emailaddy Email address. |
|
1460 |
* @param int $mailto Optional. Range from 0 to 1. Used for encoding. |
|
1461 |
* @return string Converted email address. |
|
1462 |
*/ |
|
1463 |
function antispambot($emailaddy, $mailto=0) { |
|
1464 |
$emailNOSPAMaddy = ''; |
|
1465 |
srand ((float) microtime() * 1000000); |
|
1466 |
for ($i = 0; $i < strlen($emailaddy); $i = $i + 1) { |
|
1467 |
$j = floor(rand(0, 1+$mailto)); |
|
1468 |
if ($j==0) { |
|
1469 |
$emailNOSPAMaddy .= '&#'.ord(substr($emailaddy,$i,1)).';'; |
|
1470 |
} elseif ($j==1) { |
|
1471 |
$emailNOSPAMaddy .= substr($emailaddy,$i,1); |
|
1472 |
} elseif ($j==2) { |
|
1473 |
$emailNOSPAMaddy .= '%'.zeroise(dechex(ord(substr($emailaddy, $i, 1))), 2); |
|
1474 |
} |
|
1475 |
} |
|
1476 |
$emailNOSPAMaddy = str_replace('@','@',$emailNOSPAMaddy); |
|
1477 |
return $emailNOSPAMaddy; |
|
1478 |
} |
|
1479 |
||
1480 |
/** |
|
1481 |
* Callback to convert URI match to HTML A element. |
|
1482 |
* |
|
1483 |
* This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link |
|
1484 |
* make_clickable()}. |
|
1485 |
* |
|
1486 |
* @since 2.3.2 |
|
1487 |
* @access private |
|
1488 |
* |
|
1489 |
* @param array $matches Single Regex Match. |
|
1490 |
* @return string HTML A element with URI address. |
|
1491 |
*/ |
|
1492 |
function _make_url_clickable_cb($matches) { |
|
1493 |
$url = $matches[2]; |
|
1494 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1495 |
if ( ')' == $matches[3] && strpos( $url, '(' ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1496 |
// If the trailing character is a closing parethesis, and the URL has an opening parenthesis in it, add the closing parenthesis to the URL. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1497 |
// Then we can let the parenthesis balancer do its thing below. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1498 |
$url .= $matches[3]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1499 |
$suffix = ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1500 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1501 |
$suffix = $matches[3]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1502 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1503 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1504 |
// Include parentheses in the URL only if paired |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1505 |
while ( substr_count( $url, '(' ) < substr_count( $url, ')' ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1506 |
$suffix = strrchr( $url, ')' ) . $suffix; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1507 |
$url = substr( $url, 0, strrpos( $url, ')' ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1508 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1509 |
|
136 | 1510 |
$url = esc_url($url); |
1511 |
if ( empty($url) ) |
|
1512 |
return $matches[0]; |
|
1513 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1514 |
return $matches[1] . "<a href=\"$url\" rel=\"nofollow\">$url</a>" . $suffix; |
136 | 1515 |
} |
1516 |
||
1517 |
/** |
|
1518 |
* Callback to convert URL match to HTML A element. |
|
1519 |
* |
|
1520 |
* This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link |
|
1521 |
* make_clickable()}. |
|
1522 |
* |
|
1523 |
* @since 2.3.2 |
|
1524 |
* @access private |
|
1525 |
* |
|
1526 |
* @param array $matches Single Regex Match. |
|
1527 |
* @return string HTML A element with URL address. |
|
1528 |
*/ |
|
1529 |
function _make_web_ftp_clickable_cb($matches) { |
|
1530 |
$ret = ''; |
|
1531 |
$dest = $matches[2]; |
|
1532 |
$dest = 'http://' . $dest; |
|
1533 |
$dest = esc_url($dest); |
|
1534 |
if ( empty($dest) ) |
|
1535 |
return $matches[0]; |
|
1536 |
||
1537 |
// removed trailing [.,;:)] from URL |
|
1538 |
if ( in_array( substr($dest, -1), array('.', ',', ';', ':', ')') ) === true ) { |
|
1539 |
$ret = substr($dest, -1); |
|
1540 |
$dest = substr($dest, 0, strlen($dest)-1); |
|
1541 |
} |
|
1542 |
return $matches[1] . "<a href=\"$dest\" rel=\"nofollow\">$dest</a>$ret"; |
|
1543 |
} |
|
1544 |
||
1545 |
/** |
|
1546 |
* Callback to convert email address match to HTML A element. |
|
1547 |
* |
|
1548 |
* This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link |
|
1549 |
* make_clickable()}. |
|
1550 |
* |
|
1551 |
* @since 2.3.2 |
|
1552 |
* @access private |
|
1553 |
* |
|
1554 |
* @param array $matches Single Regex Match. |
|
1555 |
* @return string HTML A element with email address. |
|
1556 |
*/ |
|
1557 |
function _make_email_clickable_cb($matches) { |
|
1558 |
$email = $matches[2] . '@' . $matches[3]; |
|
1559 |
return $matches[1] . "<a href=\"mailto:$email\">$email</a>"; |
|
1560 |
} |
|
1561 |
||
1562 |
/** |
|
1563 |
* Convert plaintext URI to HTML links. |
|
1564 |
* |
|
1565 |
* Converts URI, www and ftp, and email addresses. Finishes by fixing links |
|
1566 |
* within links. |
|
1567 |
* |
|
1568 |
* @since 0.71 |
|
1569 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1570 |
* @param string $text Content to convert URIs. |
136 | 1571 |
* @return string Content with converted URIs. |
1572 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1573 |
function make_clickable( $text ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1574 |
$r = ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1575 |
$textarr = preg_split( '/(<[^<>]+>)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // split out HTML tags |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1576 |
foreach ( $textarr as $piece ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1577 |
if ( empty( $piece ) || ( $piece[0] == '<' && ! preg_match('|^<\s*[\w]{1,20}+://|', $piece) ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1578 |
$r .= $piece; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1579 |
continue; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1580 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1581 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1582 |
// Long strings might contain expensive edge cases ... |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1583 |
if ( 10000 < strlen( $piece ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1584 |
// ... break it up |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1585 |
foreach ( _split_str_by_whitespace( $piece, 2100 ) as $chunk ) { // 2100: Extra room for scheme and leading and trailing paretheses |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1586 |
if ( 2101 < strlen( $chunk ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1587 |
$r .= $chunk; // Too big, no whitespace: bail. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1588 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1589 |
$r .= make_clickable( $chunk ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1590 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1591 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1592 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1593 |
$ret = " $piece "; // Pad with whitespace to simplify the regexes |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1594 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1595 |
$url_clickable = '~ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1596 |
([\\s(<.,;:!?]) # 1: Leading whitespace, or punctuation |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1597 |
( # 2: URL |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1598 |
[\\w]{1,20}+:// # Scheme and hier-part prefix |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1599 |
(?=\S{1,2000}\s) # Limit to URLs less than about 2000 characters long |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1600 |
[\\w\\x80-\\xff#%\\~/@\\[\\]*(+=&$-]*+ # Non-punctuation URL character |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1601 |
(?: # Unroll the Loop: Only allow puctuation URL character if followed by a non-punctuation URL character |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1602 |
[\'.,;:!?)] # Punctuation URL character |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1603 |
[\\w\\x80-\\xff#%\\~/@\\[\\]*(+=&$-]++ # Non-punctuation URL character |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1604 |
)* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1605 |
) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1606 |
(\)?) # 3: Trailing closing parenthesis (for parethesis balancing post processing) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1607 |
~xS'; // The regex is a non-anchored pattern and does not have a single fixed starting character. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1608 |
// Tell PCRE to spend more time optimizing since, when used on a page load, it will probably be used several times. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1609 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1610 |
$ret = preg_replace_callback( $url_clickable, '_make_url_clickable_cb', $ret ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1611 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1612 |
$ret = preg_replace_callback( '#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]+)#is', '_make_web_ftp_clickable_cb', $ret ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1613 |
$ret = preg_replace_callback( '#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $ret ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1614 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1615 |
$ret = substr( $ret, 1, -1 ); // Remove our whitespace padding. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1616 |
$r .= $ret; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1617 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1618 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1619 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1620 |
// Cleanup of accidental links within links |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1621 |
$r = preg_replace( '#(<a( [^>]+?>|>))<a [^>]+?>([^>]+?)</a></a>#i', "$1$3</a>", $r ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1622 |
return $r; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1623 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1624 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1625 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1626 |
* Breaks a string into chunks by splitting at whitespace characters. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1627 |
* The length of each returned chunk is as close to the specified length goal as possible, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1628 |
* with the caveat that each chunk includes its trailing delimiter. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1629 |
* Chunks longer than the goal are guaranteed to not have any inner whitespace. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1630 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1631 |
* Joining the returned chunks with empty delimiters reconstructs the input string losslessly. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1632 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1633 |
* Input string must have no null characters (or eventual transformations on output chunks must not care about null characters) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1634 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1635 |
* <code> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1636 |
* _split_str_by_whitespace( "1234 67890 1234 67890a cd 1234 890 123456789 1234567890a 45678 1 3 5 7 90 ", 10 ) == |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1637 |
* array ( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1638 |
* 0 => '1234 67890 ', // 11 characters: Perfect split |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1639 |
* 1 => '1234 ', // 5 characters: '1234 67890a' was too long |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1640 |
* 2 => '67890a cd ', // 10 characters: '67890a cd 1234' was too long |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1641 |
* 3 => '1234 890 ', // 11 characters: Perfect split |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1642 |
* 4 => '123456789 ', // 10 characters: '123456789 1234567890a' was too long |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1643 |
* 5 => '1234567890a ', // 12 characters: Too long, but no inner whitespace on which to split |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1644 |
* 6 => ' 45678 ', // 11 characters: Perfect split |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1645 |
* 7 => '1 3 5 7 9', // 9 characters: End of $string |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1646 |
* ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1647 |
* </code> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1648 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1649 |
* @since 3.4.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1650 |
* @access private |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1651 |
* |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1652 |
* @param string $string The string to split. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1653 |
* @param int $goal The desired chunk length. |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1654 |
* @return array Numeric array of chunks. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1655 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1656 |
function _split_str_by_whitespace( $string, $goal ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1657 |
$chunks = array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1658 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1659 |
$string_nullspace = strtr( $string, "\r\n\t\v\f ", "\000\000\000\000\000\000" ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1660 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1661 |
while ( $goal < strlen( $string_nullspace ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1662 |
$pos = strrpos( substr( $string_nullspace, 0, $goal + 1 ), "\000" ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1663 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1664 |
if ( false === $pos ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1665 |
$pos = strpos( $string_nullspace, "\000", $goal + 1 ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1666 |
if ( false === $pos ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1667 |
break; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1668 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1669 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1670 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1671 |
$chunks[] = substr( $string, 0, $pos + 1 ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1672 |
$string = substr( $string, $pos + 1 ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1673 |
$string_nullspace = substr( $string_nullspace, $pos + 1 ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1674 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1675 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1676 |
if ( $string ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1677 |
$chunks[] = $string; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1678 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1679 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1680 |
return $chunks; |
136 | 1681 |
} |
1682 |
||
1683 |
/** |
|
1684 |
* Adds rel nofollow string to all HTML A elements in content. |
|
1685 |
* |
|
1686 |
* @since 1.5.0 |
|
1687 |
* |
|
1688 |
* @param string $text Content that may contain HTML A elements. |
|
1689 |
* @return string Converted content. |
|
1690 |
*/ |
|
1691 |
function wp_rel_nofollow( $text ) { |
|
1692 |
// This is a pre save filter, so text is already escaped. |
|
1693 |
$text = stripslashes($text); |
|
1694 |
$text = preg_replace_callback('|<a (.+?)>|i', 'wp_rel_nofollow_callback', $text); |
|
1695 |
$text = esc_sql($text); |
|
1696 |
return $text; |
|
1697 |
} |
|
1698 |
||
1699 |
/** |
|
1700 |
* Callback to used to add rel=nofollow string to HTML A element. |
|
1701 |
* |
|
1702 |
* Will remove already existing rel="nofollow" and rel='nofollow' from the |
|
1703 |
* string to prevent from invalidating (X)HTML. |
|
1704 |
* |
|
1705 |
* @since 2.3.0 |
|
1706 |
* |
|
1707 |
* @param array $matches Single Match |
|
1708 |
* @return string HTML A Element with rel nofollow. |
|
1709 |
*/ |
|
1710 |
function wp_rel_nofollow_callback( $matches ) { |
|
1711 |
$text = $matches[1]; |
|
1712 |
$text = str_replace(array(' rel="nofollow"', " rel='nofollow'"), '', $text); |
|
1713 |
return "<a $text rel=\"nofollow\">"; |
|
1714 |
} |
|
1715 |
||
1716 |
/** |
|
1717 |
* Convert one smiley code to the icon graphic file equivalent. |
|
1718 |
* |
|
1719 |
* Looks up one smiley code in the $wpsmiliestrans global array and returns an |
|
1720 |
* <img> string for that smiley. |
|
1721 |
* |
|
1722 |
* @global array $wpsmiliestrans |
|
1723 |
* @since 2.8.0 |
|
1724 |
* |
|
1725 |
* @param string $smiley Smiley code to convert to image. |
|
1726 |
* @return string Image string for smiley. |
|
1727 |
*/ |
|
1728 |
function translate_smiley($smiley) { |
|
1729 |
global $wpsmiliestrans; |
|
1730 |
||
1731 |
if (count($smiley) == 0) { |
|
1732 |
return ''; |
|
1733 |
} |
|
1734 |
||
1735 |
$smiley = trim(reset($smiley)); |
|
1736 |
$img = $wpsmiliestrans[$smiley]; |
|
1737 |
$smiley_masked = esc_attr($smiley); |
|
1738 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1739 |
$srcurl = apply_filters('smilies_src', includes_url("images/smilies/$img"), $img, site_url()); |
136 | 1740 |
|
1741 |
return " <img src='$srcurl' alt='$smiley_masked' class='wp-smiley' /> "; |
|
1742 |
} |
|
1743 |
||
1744 |
/** |
|
1745 |
* Convert text equivalent of smilies to images. |
|
1746 |
* |
|
1747 |
* Will only convert smilies if the option 'use_smilies' is true and the global |
|
1748 |
* used in the function isn't empty. |
|
1749 |
* |
|
1750 |
* @since 0.71 |
|
1751 |
* @uses $wp_smiliessearch |
|
1752 |
* |
|
1753 |
* @param string $text Content to convert smilies from text. |
|
1754 |
* @return string Converted content with text smilies replaced with images. |
|
1755 |
*/ |
|
1756 |
function convert_smilies($text) { |
|
1757 |
global $wp_smiliessearch; |
|
1758 |
$output = ''; |
|
1759 |
if ( get_option('use_smilies') && !empty($wp_smiliessearch) ) { |
|
1760 |
// HTML loop taken from texturize function, could possible be consolidated |
|
1761 |
$textarr = preg_split("/(<.*>)/U", $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between |
|
1762 |
$stop = count($textarr);// loop stuff |
|
1763 |
for ($i = 0; $i < $stop; $i++) { |
|
1764 |
$content = $textarr[$i]; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1765 |
if ((strlen($content) > 0) && ('<' != $content[0])) { // If it's not a tag |
136 | 1766 |
$content = preg_replace_callback($wp_smiliessearch, 'translate_smiley', $content); |
1767 |
} |
|
1768 |
$output .= $content; |
|
1769 |
} |
|
1770 |
} else { |
|
1771 |
// return default text. |
|
1772 |
$output = $text; |
|
1773 |
} |
|
1774 |
return $output; |
|
1775 |
} |
|
1776 |
||
1777 |
/** |
|
1778 |
* Verifies that an email is valid. |
|
1779 |
* |
|
1780 |
* Does not grok i18n domains. Not RFC compliant. |
|
1781 |
* |
|
1782 |
* @since 0.71 |
|
1783 |
* |
|
1784 |
* @param string $email Email address to verify. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1785 |
* @param boolean $deprecated Deprecated. |
136 | 1786 |
* @return string|bool Either false or the valid email address. |
1787 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1788 |
function is_email( $email, $deprecated = false ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1789 |
if ( ! empty( $deprecated ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1790 |
_deprecated_argument( __FUNCTION__, '3.0' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1791 |
|
136 | 1792 |
// Test for the minimum length the email can be |
1793 |
if ( strlen( $email ) < 3 ) { |
|
1794 |
return apply_filters( 'is_email', false, $email, 'email_too_short' ); |
|
1795 |
} |
|
1796 |
||
1797 |
// Test for an @ character after the first position |
|
1798 |
if ( strpos( $email, '@', 1 ) === false ) { |
|
1799 |
return apply_filters( 'is_email', false, $email, 'email_no_at' ); |
|
1800 |
} |
|
1801 |
||
1802 |
// Split out the local and domain parts |
|
1803 |
list( $local, $domain ) = explode( '@', $email, 2 ); |
|
1804 |
||
1805 |
// LOCAL PART |
|
1806 |
// Test for invalid characters |
|
1807 |
if ( !preg_match( '/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]+$/', $local ) ) { |
|
1808 |
return apply_filters( 'is_email', false, $email, 'local_invalid_chars' ); |
|
1809 |
} |
|
1810 |
||
1811 |
// DOMAIN PART |
|
1812 |
// Test for sequences of periods |
|
1813 |
if ( preg_match( '/\.{2,}/', $domain ) ) { |
|
1814 |
return apply_filters( 'is_email', false, $email, 'domain_period_sequence' ); |
|
1815 |
} |
|
1816 |
||
1817 |
// Test for leading and trailing periods and whitespace |
|
1818 |
if ( trim( $domain, " \t\n\r\0\x0B." ) !== $domain ) { |
|
1819 |
return apply_filters( 'is_email', false, $email, 'domain_period_limits' ); |
|
1820 |
} |
|
1821 |
||
1822 |
// Split the domain into subs |
|
1823 |
$subs = explode( '.', $domain ); |
|
1824 |
||
1825 |
// Assume the domain will have at least two subs |
|
1826 |
if ( 2 > count( $subs ) ) { |
|
1827 |
return apply_filters( 'is_email', false, $email, 'domain_no_periods' ); |
|
1828 |
} |
|
1829 |
||
1830 |
// Loop through each sub |
|
1831 |
foreach ( $subs as $sub ) { |
|
1832 |
// Test for leading and trailing hyphens and whitespace |
|
1833 |
if ( trim( $sub, " \t\n\r\0\x0B-" ) !== $sub ) { |
|
1834 |
return apply_filters( 'is_email', false, $email, 'sub_hyphen_limits' ); |
|
1835 |
} |
|
1836 |
||
1837 |
// Test for invalid characters |
|
1838 |
if ( !preg_match('/^[a-z0-9-]+$/i', $sub ) ) { |
|
1839 |
return apply_filters( 'is_email', false, $email, 'sub_invalid_chars' ); |
|
1840 |
} |
|
1841 |
} |
|
1842 |
||
1843 |
// Congratulations your email made it! |
|
1844 |
return apply_filters( 'is_email', $email, $email, null ); |
|
1845 |
} |
|
1846 |
||
1847 |
/** |
|
1848 |
* Convert to ASCII from email subjects. |
|
1849 |
* |
|
1850 |
* @since 1.2.0 |
|
1851 |
* |
|
1852 |
* @param string $string Subject line |
|
1853 |
* @return string Converted string to ASCII |
|
1854 |
*/ |
|
1855 |
function wp_iso_descrambler($string) { |
|
1856 |
/* this may only work with iso-8859-1, I'm afraid */ |
|
1857 |
if (!preg_match('#\=\?(.+)\?Q\?(.+)\?\=#i', $string, $matches)) { |
|
1858 |
return $string; |
|
1859 |
} else { |
|
1860 |
$subject = str_replace('_', ' ', $matches[2]); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1861 |
$subject = preg_replace_callback('#\=([0-9a-f]{2})#i', '_wp_iso_convert', $subject); |
136 | 1862 |
return $subject; |
1863 |
} |
|
1864 |
} |
|
1865 |
||
1866 |
/** |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1867 |
* Helper function to convert hex encoded chars to ASCII |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1868 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1869 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1870 |
* @access private |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1871 |
* @param array $match The preg_replace_callback matches array |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1872 |
* @return array Converted chars |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1873 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1874 |
function _wp_iso_convert( $match ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1875 |
return chr( hexdec( strtolower( $match[1] ) ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1876 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1877 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1878 |
/** |
136 | 1879 |
* Returns a date in the GMT equivalent. |
1880 |
* |
|
1881 |
* Requires and returns a date in the Y-m-d H:i:s format. Simply subtracts the |
|
1882 |
* value of the 'gmt_offset' option. Return format can be overridden using the |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1883 |
* $format parameter. The DateTime and DateTimeZone classes are used to respect |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1884 |
* time zone differences in DST. |
136 | 1885 |
* |
1886 |
* @since 1.2.0 |
|
1887 |
* |
|
1888 |
* @uses get_option() to retrieve the the value of 'gmt_offset'. |
|
1889 |
* @param string $string The date to be converted. |
|
1890 |
* @param string $format The format string for the returned date (default is Y-m-d H:i:s) |
|
1891 |
* @return string GMT version of the date provided. |
|
1892 |
*/ |
|
1893 |
function get_gmt_from_date($string, $format = 'Y-m-d H:i:s') { |
|
1894 |
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); |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1895 |
if ( ! $matches ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1896 |
return date( $format, 0 ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1897 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1898 |
$tz = get_option('timezone_string'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1899 |
if ( $tz ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1900 |
date_default_timezone_set( $tz ); |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1901 |
$datetime = date_create( $string ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1902 |
if ( ! $datetime ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1903 |
return date( $format, 0 ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1904 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1905 |
$datetime->setTimezone( new DateTimeZone('UTC') ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1906 |
$offset = $datetime->getOffset(); |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1907 |
$datetime->modify( '+' . $offset / HOUR_IN_SECONDS . ' hours'); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1908 |
$string_gmt = gmdate($format, $datetime->format('U')); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1909 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1910 |
date_default_timezone_set('UTC'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1911 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1912 |
$string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]); |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1913 |
$string_gmt = gmdate($format, $string_time - get_option('gmt_offset') * HOUR_IN_SECONDS); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1914 |
} |
136 | 1915 |
return $string_gmt; |
1916 |
} |
|
1917 |
||
1918 |
/** |
|
1919 |
* Converts a GMT date into the correct format for the blog. |
|
1920 |
* |
|
1921 |
* Requires and returns in the Y-m-d H:i:s format. Simply adds the value of |
|
1922 |
* gmt_offset.Return format can be overridden using the $format parameter |
|
1923 |
* |
|
1924 |
* @since 1.2.0 |
|
1925 |
* |
|
1926 |
* @param string $string The date to be converted. |
|
1927 |
* @param string $format The format string for the returned date (default is Y-m-d H:i:s) |
|
1928 |
* @return string Formatted date relative to the GMT offset. |
|
1929 |
*/ |
|
1930 |
function get_date_from_gmt($string, $format = 'Y-m-d H:i:s') { |
|
1931 |
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); |
|
1932 |
$string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]); |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1933 |
$string_localtime = gmdate($format, $string_time + get_option('gmt_offset') * HOUR_IN_SECONDS); |
136 | 1934 |
return $string_localtime; |
1935 |
} |
|
1936 |
||
1937 |
/** |
|
1938 |
* Computes an offset in seconds from an iso8601 timezone. |
|
1939 |
* |
|
1940 |
* @since 1.5.0 |
|
1941 |
* |
|
1942 |
* @param string $timezone Either 'Z' for 0 offset or '±hhmm'. |
|
1943 |
* @return int|float The offset in seconds. |
|
1944 |
*/ |
|
1945 |
function iso8601_timezone_to_offset($timezone) { |
|
1946 |
// $timezone is either 'Z' or '[+|-]hhmm' |
|
1947 |
if ($timezone == 'Z') { |
|
1948 |
$offset = 0; |
|
1949 |
} else { |
|
1950 |
$sign = (substr($timezone, 0, 1) == '+') ? 1 : -1; |
|
1951 |
$hours = intval(substr($timezone, 1, 2)); |
|
1952 |
$minutes = intval(substr($timezone, 3, 4)) / 60; |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1953 |
$offset = $sign * HOUR_IN_SECONDS * ($hours + $minutes); |
136 | 1954 |
} |
1955 |
return $offset; |
|
1956 |
} |
|
1957 |
||
1958 |
/** |
|
1959 |
* Converts an iso8601 date to MySQL DateTime format used by post_date[_gmt]. |
|
1960 |
* |
|
1961 |
* @since 1.5.0 |
|
1962 |
* |
|
1963 |
* @param string $date_string Date and time in ISO 8601 format {@link http://en.wikipedia.org/wiki/ISO_8601}. |
|
1964 |
* @param string $timezone Optional. If set to GMT returns the time minus gmt_offset. Default is 'user'. |
|
1965 |
* @return string The date and time in MySQL DateTime format - Y-m-d H:i:s. |
|
1966 |
*/ |
|
1967 |
function iso8601_to_datetime($date_string, $timezone = 'user') { |
|
1968 |
$timezone = strtolower($timezone); |
|
1969 |
||
1970 |
if ($timezone == 'gmt') { |
|
1971 |
||
1972 |
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); |
|
1973 |
||
1974 |
if (!empty($date_bits[7])) { // we have a timezone, so let's compute an offset |
|
1975 |
$offset = iso8601_timezone_to_offset($date_bits[7]); |
|
1976 |
} else { // we don't have a timezone, so we assume user local timezone (not server's!) |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1977 |
$offset = HOUR_IN_SECONDS * get_option('gmt_offset'); |
136 | 1978 |
} |
1979 |
||
1980 |
$timestamp = gmmktime($date_bits[4], $date_bits[5], $date_bits[6], $date_bits[2], $date_bits[3], $date_bits[1]); |
|
1981 |
$timestamp -= $offset; |
|
1982 |
||
1983 |
return gmdate('Y-m-d H:i:s', $timestamp); |
|
1984 |
||
1985 |
} else if ($timezone == 'user') { |
|
1986 |
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); |
|
1987 |
} |
|
1988 |
} |
|
1989 |
||
1990 |
/** |
|
1991 |
* Adds a element attributes to open links in new windows. |
|
1992 |
* |
|
1993 |
* Comment text in popup windows should be filtered through this. Right now it's |
|
1994 |
* a moderately dumb function, ideally it would detect whether a target or rel |
|
1995 |
* attribute was already there and adjust its actions accordingly. |
|
1996 |
* |
|
1997 |
* @since 0.71 |
|
1998 |
* |
|
1999 |
* @param string $text Content to replace links to open in a new window. |
|
2000 |
* @return string Content that has filtered links. |
|
2001 |
*/ |
|
2002 |
function popuplinks($text) { |
|
2003 |
$text = preg_replace('/<a (.+?)>/i', "<a $1 target='_blank' rel='external'>", $text); |
|
2004 |
return $text; |
|
2005 |
} |
|
2006 |
||
2007 |
/** |
|
2008 |
* Strips out all characters that are not allowable in an email. |
|
2009 |
* |
|
2010 |
* @since 1.5.0 |
|
2011 |
* |
|
2012 |
* @param string $email Email address to filter. |
|
2013 |
* @return string Filtered email address. |
|
2014 |
*/ |
|
2015 |
function sanitize_email( $email ) { |
|
2016 |
// Test for the minimum length the email can be |
|
2017 |
if ( strlen( $email ) < 3 ) { |
|
2018 |
return apply_filters( 'sanitize_email', '', $email, 'email_too_short' ); |
|
2019 |
} |
|
2020 |
||
2021 |
// Test for an @ character after the first position |
|
2022 |
if ( strpos( $email, '@', 1 ) === false ) { |
|
2023 |
return apply_filters( 'sanitize_email', '', $email, 'email_no_at' ); |
|
2024 |
} |
|
2025 |
||
2026 |
// Split out the local and domain parts |
|
2027 |
list( $local, $domain ) = explode( '@', $email, 2 ); |
|
2028 |
||
2029 |
// LOCAL PART |
|
2030 |
// Test for invalid characters |
|
2031 |
$local = preg_replace( '/[^a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]/', '', $local ); |
|
2032 |
if ( '' === $local ) { |
|
2033 |
return apply_filters( 'sanitize_email', '', $email, 'local_invalid_chars' ); |
|
2034 |
} |
|
2035 |
||
2036 |
// DOMAIN PART |
|
2037 |
// Test for sequences of periods |
|
2038 |
$domain = preg_replace( '/\.{2,}/', '', $domain ); |
|
2039 |
if ( '' === $domain ) { |
|
2040 |
return apply_filters( 'sanitize_email', '', $email, 'domain_period_sequence' ); |
|
2041 |
} |
|
2042 |
||
2043 |
// Test for leading and trailing periods and whitespace |
|
2044 |
$domain = trim( $domain, " \t\n\r\0\x0B." ); |
|
2045 |
if ( '' === $domain ) { |
|
2046 |
return apply_filters( 'sanitize_email', '', $email, 'domain_period_limits' ); |
|
2047 |
} |
|
2048 |
||
2049 |
// Split the domain into subs |
|
2050 |
$subs = explode( '.', $domain ); |
|
2051 |
||
2052 |
// Assume the domain will have at least two subs |
|
2053 |
if ( 2 > count( $subs ) ) { |
|
2054 |
return apply_filters( 'sanitize_email', '', $email, 'domain_no_periods' ); |
|
2055 |
} |
|
2056 |
||
2057 |
// Create an array that will contain valid subs |
|
2058 |
$new_subs = array(); |
|
2059 |
||
2060 |
// Loop through each sub |
|
2061 |
foreach ( $subs as $sub ) { |
|
2062 |
// Test for leading and trailing hyphens |
|
2063 |
$sub = trim( $sub, " \t\n\r\0\x0B-" ); |
|
2064 |
||
2065 |
// Test for invalid characters |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2066 |
$sub = preg_replace( '/[^a-z0-9-]+/i', '', $sub ); |
136 | 2067 |
|
2068 |
// If there's anything left, add it to the valid subs |
|
2069 |
if ( '' !== $sub ) { |
|
2070 |
$new_subs[] = $sub; |
|
2071 |
} |
|
2072 |
} |
|
2073 |
||
2074 |
// If there aren't 2 or more valid subs |
|
2075 |
if ( 2 > count( $new_subs ) ) { |
|
2076 |
return apply_filters( 'sanitize_email', '', $email, 'domain_no_valid_subs' ); |
|
2077 |
} |
|
2078 |
||
2079 |
// Join valid subs into the new domain |
|
2080 |
$domain = join( '.', $new_subs ); |
|
2081 |
||
2082 |
// Put the email back together |
|
2083 |
$email = $local . '@' . $domain; |
|
2084 |
||
2085 |
// Congratulations your email made it! |
|
2086 |
return apply_filters( 'sanitize_email', $email, $email, null ); |
|
2087 |
} |
|
2088 |
||
2089 |
/** |
|
2090 |
* Determines the difference between two timestamps. |
|
2091 |
* |
|
2092 |
* The difference is returned in a human readable format such as "1 hour", |
|
2093 |
* "5 mins", "2 days". |
|
2094 |
* |
|
2095 |
* @since 1.5.0 |
|
2096 |
* |
|
2097 |
* @param int $from Unix timestamp from which the difference begins. |
|
2098 |
* @param int $to Optional. Unix timestamp to end the time difference. Default becomes time() if not set. |
|
2099 |
* @return string Human readable time difference. |
|
2100 |
*/ |
|
2101 |
function human_time_diff( $from, $to = '' ) { |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2102 |
if ( empty( $to ) ) |
136 | 2103 |
$to = time(); |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2104 |
$diff = (int) abs( $to - $from ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2105 |
if ( $diff <= HOUR_IN_SECONDS ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2106 |
$mins = round( $diff / MINUTE_IN_SECONDS ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2107 |
if ( $mins <= 1 ) { |
136 | 2108 |
$mins = 1; |
2109 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2110 |
/* translators: min=minute */ |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2111 |
$since = sprintf( _n( '%s min', '%s mins', $mins ), $mins ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2112 |
} elseif ( ( $diff <= DAY_IN_SECONDS ) && ( $diff > HOUR_IN_SECONDS ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2113 |
$hours = round( $diff / HOUR_IN_SECONDS ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2114 |
if ( $hours <= 1 ) { |
136 | 2115 |
$hours = 1; |
2116 |
} |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2117 |
$since = sprintf( _n( '%s hour', '%s hours', $hours ), $hours ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2118 |
} elseif ( $diff >= DAY_IN_SECONDS ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2119 |
$days = round( $diff / DAY_IN_SECONDS ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2120 |
if ( $days <= 1 ) { |
136 | 2121 |
$days = 1; |
2122 |
} |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2123 |
$since = sprintf( _n( '%s day', '%s days', $days ), $days ); |
136 | 2124 |
} |
2125 |
return $since; |
|
2126 |
} |
|
2127 |
||
2128 |
/** |
|
2129 |
* Generates an excerpt from the content, if needed. |
|
2130 |
* |
|
2131 |
* The excerpt word amount will be 55 words and if the amount is greater than |
|
2132 |
* that, then the string ' [...]' will be appended to the excerpt. If the string |
|
2133 |
* is less than 55 words, then the content will be returned as is. |
|
2134 |
* |
|
2135 |
* The 55 word limit can be modified by plugins/themes using the excerpt_length filter |
|
2136 |
* The ' [...]' string can be modified by plugins/themes using the excerpt_more filter |
|
2137 |
* |
|
2138 |
* @since 1.5.0 |
|
2139 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2140 |
* @param string $text Optional. The excerpt. If set to empty, an excerpt is generated. |
136 | 2141 |
* @return string The excerpt. |
2142 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2143 |
function wp_trim_excerpt($text = '') { |
136 | 2144 |
$raw_excerpt = $text; |
2145 |
if ( '' == $text ) { |
|
2146 |
$text = get_the_content(''); |
|
2147 |
||
2148 |
$text = strip_shortcodes( $text ); |
|
2149 |
||
2150 |
$text = apply_filters('the_content', $text); |
|
2151 |
$text = str_replace(']]>', ']]>', $text); |
|
2152 |
$excerpt_length = apply_filters('excerpt_length', 55); |
|
2153 |
$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]'); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2154 |
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more ); |
136 | 2155 |
} |
2156 |
return apply_filters('wp_trim_excerpt', $text, $raw_excerpt); |
|
2157 |
} |
|
2158 |
||
2159 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2160 |
* Trims text to a certain number of words. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2161 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2162 |
* This function is localized. For languages that count 'words' by the individual |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2163 |
* character (such as East Asian languages), the $num_words argument will apply |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2164 |
* to the number of individual characters. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2165 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2166 |
* @since 3.3.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2167 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2168 |
* @param string $text Text to trim. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2169 |
* @param int $num_words Number of words. Default 55. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2170 |
* @param string $more What to append if $text needs to be trimmed. Default '…'. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2171 |
* @return string Trimmed text. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2172 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2173 |
function wp_trim_words( $text, $num_words = 55, $more = null ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2174 |
if ( null === $more ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2175 |
$more = __( '…' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2176 |
$original_text = $text; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2177 |
$text = wp_strip_all_tags( $text ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2178 |
/* translators: If your word count is based on single characters (East Asian characters), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2179 |
enter 'characters'. Otherwise, enter 'words'. Do not translate into your own language. */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2180 |
if ( 'characters' == _x( 'words', 'word count: words or characters?' ) && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2181 |
$text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2182 |
preg_match_all( '/./u', $text, $words_array ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2183 |
$words_array = array_slice( $words_array[0], 0, $num_words + 1 ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2184 |
$sep = ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2185 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2186 |
$words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2187 |
$sep = ' '; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2188 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2189 |
if ( count( $words_array ) > $num_words ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2190 |
array_pop( $words_array ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2191 |
$text = implode( $sep, $words_array ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2192 |
$text = $text . $more; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2193 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2194 |
$text = implode( $sep, $words_array ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2195 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2196 |
return apply_filters( 'wp_trim_words', $text, $num_words, $more, $original_text ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2197 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2198 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2199 |
/** |
136 | 2200 |
* Converts named entities into numbered entities. |
2201 |
* |
|
2202 |
* @since 1.5.1 |
|
2203 |
* |
|
2204 |
* @param string $text The text within which entities will be converted. |
|
2205 |
* @return string Text with converted entities. |
|
2206 |
*/ |
|
2207 |
function ent2ncr($text) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2208 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2209 |
// Allow a plugin to short-circuit and override the mappings. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2210 |
$filtered = apply_filters( 'pre_ent2ncr', null, $text ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2211 |
if( null !== $filtered ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2212 |
return $filtered; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2213 |
|
136 | 2214 |
$to_ncr = array( |
2215 |
'"' => '"', |
|
2216 |
'&' => '&', |
|
2217 |
'⁄' => '/', |
|
2218 |
'<' => '<', |
|
2219 |
'>' => '>', |
|
2220 |
'|' => '|', |
|
2221 |
' ' => ' ', |
|
2222 |
'¡' => '¡', |
|
2223 |
'¢' => '¢', |
|
2224 |
'£' => '£', |
|
2225 |
'¤' => '¤', |
|
2226 |
'¥' => '¥', |
|
2227 |
'¦' => '¦', |
|
2228 |
'&brkbar;' => '¦', |
|
2229 |
'§' => '§', |
|
2230 |
'¨' => '¨', |
|
2231 |
'¨' => '¨', |
|
2232 |
'©' => '©', |
|
2233 |
'ª' => 'ª', |
|
2234 |
'«' => '«', |
|
2235 |
'¬' => '¬', |
|
2236 |
'­' => '­', |
|
2237 |
'®' => '®', |
|
2238 |
'¯' => '¯', |
|
2239 |
'&hibar;' => '¯', |
|
2240 |
'°' => '°', |
|
2241 |
'±' => '±', |
|
2242 |
'²' => '²', |
|
2243 |
'³' => '³', |
|
2244 |
'´' => '´', |
|
2245 |
'µ' => 'µ', |
|
2246 |
'¶' => '¶', |
|
2247 |
'·' => '·', |
|
2248 |
'¸' => '¸', |
|
2249 |
'¹' => '¹', |
|
2250 |
'º' => 'º', |
|
2251 |
'»' => '»', |
|
2252 |
'¼' => '¼', |
|
2253 |
'½' => '½', |
|
2254 |
'¾' => '¾', |
|
2255 |
'¿' => '¿', |
|
2256 |
'À' => 'À', |
|
2257 |
'Á' => 'Á', |
|
2258 |
'Â' => 'Â', |
|
2259 |
'Ã' => 'Ã', |
|
2260 |
'Ä' => 'Ä', |
|
2261 |
'Å' => 'Å', |
|
2262 |
'Æ' => 'Æ', |
|
2263 |
'Ç' => 'Ç', |
|
2264 |
'È' => 'È', |
|
2265 |
'É' => 'É', |
|
2266 |
'Ê' => 'Ê', |
|
2267 |
'Ë' => 'Ë', |
|
2268 |
'Ì' => 'Ì', |
|
2269 |
'Í' => 'Í', |
|
2270 |
'Î' => 'Î', |
|
2271 |
'Ï' => 'Ï', |
|
2272 |
'Ð' => 'Ð', |
|
2273 |
'Ñ' => 'Ñ', |
|
2274 |
'Ò' => 'Ò', |
|
2275 |
'Ó' => 'Ó', |
|
2276 |
'Ô' => 'Ô', |
|
2277 |
'Õ' => 'Õ', |
|
2278 |
'Ö' => 'Ö', |
|
2279 |
'×' => '×', |
|
2280 |
'Ø' => 'Ø', |
|
2281 |
'Ù' => 'Ù', |
|
2282 |
'Ú' => 'Ú', |
|
2283 |
'Û' => 'Û', |
|
2284 |
'Ü' => 'Ü', |
|
2285 |
'Ý' => 'Ý', |
|
2286 |
'Þ' => 'Þ', |
|
2287 |
'ß' => 'ß', |
|
2288 |
'à' => 'à', |
|
2289 |
'á' => 'á', |
|
2290 |
'â' => 'â', |
|
2291 |
'ã' => 'ã', |
|
2292 |
'ä' => 'ä', |
|
2293 |
'å' => 'å', |
|
2294 |
'æ' => 'æ', |
|
2295 |
'ç' => 'ç', |
|
2296 |
'è' => 'è', |
|
2297 |
'é' => 'é', |
|
2298 |
'ê' => 'ê', |
|
2299 |
'ë' => 'ë', |
|
2300 |
'ì' => 'ì', |
|
2301 |
'í' => 'í', |
|
2302 |
'î' => 'î', |
|
2303 |
'ï' => 'ï', |
|
2304 |
'ð' => 'ð', |
|
2305 |
'ñ' => 'ñ', |
|
2306 |
'ò' => 'ò', |
|
2307 |
'ó' => 'ó', |
|
2308 |
'ô' => 'ô', |
|
2309 |
'õ' => 'õ', |
|
2310 |
'ö' => 'ö', |
|
2311 |
'÷' => '÷', |
|
2312 |
'ø' => 'ø', |
|
2313 |
'ù' => 'ù', |
|
2314 |
'ú' => 'ú', |
|
2315 |
'û' => 'û', |
|
2316 |
'ü' => 'ü', |
|
2317 |
'ý' => 'ý', |
|
2318 |
'þ' => 'þ', |
|
2319 |
'ÿ' => 'ÿ', |
|
2320 |
'Œ' => 'Œ', |
|
2321 |
'œ' => 'œ', |
|
2322 |
'Š' => 'Š', |
|
2323 |
'š' => 'š', |
|
2324 |
'Ÿ' => 'Ÿ', |
|
2325 |
'ƒ' => 'ƒ', |
|
2326 |
'ˆ' => 'ˆ', |
|
2327 |
'˜' => '˜', |
|
2328 |
'Α' => 'Α', |
|
2329 |
'Β' => 'Β', |
|
2330 |
'Γ' => 'Γ', |
|
2331 |
'Δ' => 'Δ', |
|
2332 |
'Ε' => 'Ε', |
|
2333 |
'Ζ' => 'Ζ', |
|
2334 |
'Η' => 'Η', |
|
2335 |
'Θ' => 'Θ', |
|
2336 |
'Ι' => 'Ι', |
|
2337 |
'Κ' => 'Κ', |
|
2338 |
'Λ' => 'Λ', |
|
2339 |
'Μ' => 'Μ', |
|
2340 |
'Ν' => 'Ν', |
|
2341 |
'Ξ' => 'Ξ', |
|
2342 |
'Ο' => 'Ο', |
|
2343 |
'Π' => 'Π', |
|
2344 |
'Ρ' => 'Ρ', |
|
2345 |
'Σ' => 'Σ', |
|
2346 |
'Τ' => 'Τ', |
|
2347 |
'Υ' => 'Υ', |
|
2348 |
'Φ' => 'Φ', |
|
2349 |
'Χ' => 'Χ', |
|
2350 |
'Ψ' => 'Ψ', |
|
2351 |
'Ω' => 'Ω', |
|
2352 |
'α' => 'α', |
|
2353 |
'β' => 'β', |
|
2354 |
'γ' => 'γ', |
|
2355 |
'δ' => 'δ', |
|
2356 |
'ε' => 'ε', |
|
2357 |
'ζ' => 'ζ', |
|
2358 |
'η' => 'η', |
|
2359 |
'θ' => 'θ', |
|
2360 |
'ι' => 'ι', |
|
2361 |
'κ' => 'κ', |
|
2362 |
'λ' => 'λ', |
|
2363 |
'μ' => 'μ', |
|
2364 |
'ν' => 'ν', |
|
2365 |
'ξ' => 'ξ', |
|
2366 |
'ο' => 'ο', |
|
2367 |
'π' => 'π', |
|
2368 |
'ρ' => 'ρ', |
|
2369 |
'ς' => 'ς', |
|
2370 |
'σ' => 'σ', |
|
2371 |
'τ' => 'τ', |
|
2372 |
'υ' => 'υ', |
|
2373 |
'φ' => 'φ', |
|
2374 |
'χ' => 'χ', |
|
2375 |
'ψ' => 'ψ', |
|
2376 |
'ω' => 'ω', |
|
2377 |
'ϑ' => 'ϑ', |
|
2378 |
'ϒ' => 'ϒ', |
|
2379 |
'ϖ' => 'ϖ', |
|
2380 |
' ' => ' ', |
|
2381 |
' ' => ' ', |
|
2382 |
' ' => ' ', |
|
2383 |
'‌' => '‌', |
|
2384 |
'‍' => '‍', |
|
2385 |
'‎' => '‎', |
|
2386 |
'‏' => '‏', |
|
2387 |
'–' => '–', |
|
2388 |
'—' => '—', |
|
2389 |
'‘' => '‘', |
|
2390 |
'’' => '’', |
|
2391 |
'‚' => '‚', |
|
2392 |
'“' => '“', |
|
2393 |
'”' => '”', |
|
2394 |
'„' => '„', |
|
2395 |
'†' => '†', |
|
2396 |
'‡' => '‡', |
|
2397 |
'•' => '•', |
|
2398 |
'…' => '…', |
|
2399 |
'‰' => '‰', |
|
2400 |
'′' => '′', |
|
2401 |
'″' => '″', |
|
2402 |
'‹' => '‹', |
|
2403 |
'›' => '›', |
|
2404 |
'‾' => '‾', |
|
2405 |
'⁄' => '⁄', |
|
2406 |
'€' => '€', |
|
2407 |
'ℑ' => 'ℑ', |
|
2408 |
'℘' => '℘', |
|
2409 |
'ℜ' => 'ℜ', |
|
2410 |
'™' => '™', |
|
2411 |
'ℵ' => 'ℵ', |
|
2412 |
'↵' => '↵', |
|
2413 |
'⇐' => '⇐', |
|
2414 |
'⇑' => '⇑', |
|
2415 |
'⇒' => '⇒', |
|
2416 |
'⇓' => '⇓', |
|
2417 |
'⇔' => '⇔', |
|
2418 |
'∀' => '∀', |
|
2419 |
'∂' => '∂', |
|
2420 |
'∃' => '∃', |
|
2421 |
'∅' => '∅', |
|
2422 |
'∇' => '∇', |
|
2423 |
'∈' => '∈', |
|
2424 |
'∉' => '∉', |
|
2425 |
'∋' => '∋', |
|
2426 |
'∏' => '∏', |
|
2427 |
'∑' => '∑', |
|
2428 |
'−' => '−', |
|
2429 |
'∗' => '∗', |
|
2430 |
'√' => '√', |
|
2431 |
'∝' => '∝', |
|
2432 |
'∞' => '∞', |
|
2433 |
'∠' => '∠', |
|
2434 |
'∧' => '∧', |
|
2435 |
'∨' => '∨', |
|
2436 |
'∩' => '∩', |
|
2437 |
'∪' => '∪', |
|
2438 |
'∫' => '∫', |
|
2439 |
'∴' => '∴', |
|
2440 |
'∼' => '∼', |
|
2441 |
'≅' => '≅', |
|
2442 |
'≈' => '≈', |
|
2443 |
'≠' => '≠', |
|
2444 |
'≡' => '≡', |
|
2445 |
'≤' => '≤', |
|
2446 |
'≥' => '≥', |
|
2447 |
'⊂' => '⊂', |
|
2448 |
'⊃' => '⊃', |
|
2449 |
'⊄' => '⊄', |
|
2450 |
'⊆' => '⊆', |
|
2451 |
'⊇' => '⊇', |
|
2452 |
'⊕' => '⊕', |
|
2453 |
'⊗' => '⊗', |
|
2454 |
'⊥' => '⊥', |
|
2455 |
'⋅' => '⋅', |
|
2456 |
'⌈' => '⌈', |
|
2457 |
'⌉' => '⌉', |
|
2458 |
'⌊' => '⌊', |
|
2459 |
'⌋' => '⌋', |
|
2460 |
'⟨' => '〈', |
|
2461 |
'⟩' => '〉', |
|
2462 |
'←' => '←', |
|
2463 |
'↑' => '↑', |
|
2464 |
'→' => '→', |
|
2465 |
'↓' => '↓', |
|
2466 |
'↔' => '↔', |
|
2467 |
'◊' => '◊', |
|
2468 |
'♠' => '♠', |
|
2469 |
'♣' => '♣', |
|
2470 |
'♥' => '♥', |
|
2471 |
'♦' => '♦' |
|
2472 |
); |
|
2473 |
||
2474 |
return str_replace( array_keys($to_ncr), array_values($to_ncr), $text ); |
|
2475 |
} |
|
2476 |
||
2477 |
/** |
|
2478 |
* Formats text for the rich text editor. |
|
2479 |
* |
|
2480 |
* The filter 'richedit_pre' is applied here. If $text is empty the filter will |
|
2481 |
* be applied to an empty string. |
|
2482 |
* |
|
2483 |
* @since 2.0.0 |
|
2484 |
* |
|
2485 |
* @param string $text The text to be formatted. |
|
2486 |
* @return string The formatted text after filter is applied. |
|
2487 |
*/ |
|
2488 |
function wp_richedit_pre($text) { |
|
2489 |
// Filtering a blank results in an annoying <br />\n |
|
2490 |
if ( empty($text) ) return apply_filters('richedit_pre', ''); |
|
2491 |
||
2492 |
$output = convert_chars($text); |
|
2493 |
$output = wpautop($output); |
|
2494 |
$output = htmlspecialchars($output, ENT_NOQUOTES); |
|
2495 |
||
2496 |
return apply_filters('richedit_pre', $output); |
|
2497 |
} |
|
2498 |
||
2499 |
/** |
|
2500 |
* Formats text for the HTML editor. |
|
2501 |
* |
|
2502 |
* Unless $output is empty it will pass through htmlspecialchars before the |
|
2503 |
* 'htmledit_pre' filter is applied. |
|
2504 |
* |
|
2505 |
* @since 2.5.0 |
|
2506 |
* |
|
2507 |
* @param string $output The text to be formatted. |
|
2508 |
* @return string Formatted text after filter applied. |
|
2509 |
*/ |
|
2510 |
function wp_htmledit_pre($output) { |
|
2511 |
if ( !empty($output) ) |
|
2512 |
$output = htmlspecialchars($output, ENT_NOQUOTES); // convert only < > & |
|
2513 |
||
2514 |
return apply_filters('htmledit_pre', $output); |
|
2515 |
} |
|
2516 |
||
2517 |
/** |
|
2518 |
* Perform a deep string replace operation to ensure the values in $search are no longer present |
|
2519 |
* |
|
2520 |
* Repeats the replacement operation until it no longer replaces anything so as to remove "nested" values |
|
2521 |
* e.g. $subject = '%0%0%0DDD', $search ='%0D', $result ='' rather than the '%0%0DD' that |
|
2522 |
* str_replace would return |
|
2523 |
* |
|
2524 |
* @since 2.8.1 |
|
2525 |
* @access private |
|
2526 |
* |
|
2527 |
* @param string|array $search |
|
2528 |
* @param string $subject |
|
2529 |
* @return string The processed string |
|
2530 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2531 |
function _deep_replace( $search, $subject ) { |
136 | 2532 |
$found = true; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2533 |
$subject = (string) $subject; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2534 |
while ( $found ) { |
136 | 2535 |
$found = false; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2536 |
foreach ( (array) $search as $val ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2537 |
while ( strpos( $subject, $val ) !== false ) { |
136 | 2538 |
$found = true; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2539 |
$subject = str_replace( $val, '', $subject ); |
136 | 2540 |
} |
2541 |
} |
|
2542 |
} |
|
2543 |
||
2544 |
return $subject; |
|
2545 |
} |
|
2546 |
||
2547 |
/** |
|
2548 |
* Escapes data for use in a MySQL query |
|
2549 |
* |
|
2550 |
* This is just a handy shortcut for $wpdb->escape(), for completeness' sake |
|
2551 |
* |
|
2552 |
* @since 2.8.0 |
|
2553 |
* @param string $sql Unescaped SQL data |
|
2554 |
* @return string The cleaned $sql |
|
2555 |
*/ |
|
2556 |
function esc_sql( $sql ) { |
|
2557 |
global $wpdb; |
|
2558 |
return $wpdb->escape( $sql ); |
|
2559 |
} |
|
2560 |
||
2561 |
/** |
|
2562 |
* Checks and cleans a URL. |
|
2563 |
* |
|
2564 |
* A number of characters are removed from the URL. If the URL is for displaying |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2565 |
* (the default behaviour) ampersands are also replaced. The 'clean_url' filter |
136 | 2566 |
* is applied to the returned cleaned URL. |
2567 |
* |
|
2568 |
* @since 2.8.0 |
|
2569 |
* @uses wp_kses_bad_protocol() To only permit protocols in the URL set |
|
2570 |
* via $protocols or the common ones set in the function. |
|
2571 |
* |
|
2572 |
* @param string $url The URL to be cleaned. |
|
2573 |
* @param array $protocols Optional. An array of acceptable protocols. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2574 |
* Defaults to 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn' if not set. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2575 |
* @param string $_context Private. Use esc_url_raw() for database usage. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2576 |
* @return string The cleaned $url after the 'clean_url' filter is applied. |
136 | 2577 |
*/ |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2578 |
function esc_url( $url, $protocols = null, $_context = 'display' ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2579 |
$original_url = $url; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2580 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2581 |
if ( '' == $url ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2582 |
return $url; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2583 |
$url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\\x80-\\xff]|i', '', $url); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2584 |
$strip = array('%0d', '%0a', '%0D', '%0A'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2585 |
$url = _deep_replace($strip, $url); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2586 |
$url = str_replace(';//', '://', $url); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2587 |
/* If the URL doesn't appear to contain a scheme, we |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2588 |
* presume it needs http:// appended (unless a relative |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2589 |
* link starting with /, # or ? or a php file). |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2590 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2591 |
if ( strpos($url, ':') === false && ! in_array( $url[0], array( '/', '#', '?' ) ) && |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2592 |
! preg_match('/^[a-z0-9-]+?\.php/i', $url) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2593 |
$url = 'http://' . $url; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2594 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2595 |
// Replace ampersands and single quotes only when displaying. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2596 |
if ( 'display' == $_context ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2597 |
$url = wp_kses_normalize_entities( $url ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2598 |
$url = str_replace( '&', '&', $url ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2599 |
$url = str_replace( "'", ''', $url ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2600 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2601 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2602 |
if ( ! is_array( $protocols ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2603 |
$protocols = wp_allowed_protocols(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2604 |
if ( wp_kses_bad_protocol( $url, $protocols ) != $url ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2605 |
return ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2606 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2607 |
return apply_filters('clean_url', $url, $original_url, $_context); |
136 | 2608 |
} |
2609 |
||
2610 |
/** |
|
2611 |
* Performs esc_url() for database usage. |
|
2612 |
* |
|
2613 |
* @since 2.8.0 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2614 |
* @uses esc_url() |
136 | 2615 |
* |
2616 |
* @param string $url The URL to be cleaned. |
|
2617 |
* @param array $protocols An array of acceptable protocols. |
|
2618 |
* @return string The cleaned URL. |
|
2619 |
*/ |
|
2620 |
function esc_url_raw( $url, $protocols = null ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2621 |
return esc_url( $url, $protocols, 'db' ); |
136 | 2622 |
} |
2623 |
||
2624 |
/** |
|
2625 |
* Convert entities, while preserving already-encoded entities. |
|
2626 |
* |
|
2627 |
* @link http://www.php.net/htmlentities Borrowed from the PHP Manual user notes. |
|
2628 |
* |
|
2629 |
* @since 1.2.2 |
|
2630 |
* |
|
2631 |
* @param string $myHTML The text to be converted. |
|
2632 |
* @return string Converted text. |
|
2633 |
*/ |
|
2634 |
function htmlentities2($myHTML) { |
|
2635 |
$translation_table = get_html_translation_table( HTML_ENTITIES, ENT_QUOTES ); |
|
2636 |
$translation_table[chr(38)] = '&'; |
|
2637 |
return preg_replace( "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/", "&", strtr($myHTML, $translation_table) ); |
|
2638 |
} |
|
2639 |
||
2640 |
/** |
|
2641 |
* Escape single quotes, htmlspecialchar " < > &, and fix line endings. |
|
2642 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2643 |
* Escapes text strings for echoing in JS. It is intended to be used for inline JS |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2644 |
* (in a tag attribute, for example onclick="..."). Note that the strings have to |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2645 |
* be in single quotes. The filter 'js_escape' is also applied here. |
136 | 2646 |
* |
2647 |
* @since 2.8.0 |
|
2648 |
* |
|
2649 |
* @param string $text The text to be escaped. |
|
2650 |
* @return string Escaped text. |
|
2651 |
*/ |
|
2652 |
function esc_js( $text ) { |
|
2653 |
$safe_text = wp_check_invalid_utf8( $text ); |
|
2654 |
$safe_text = _wp_specialchars( $safe_text, ENT_COMPAT ); |
|
2655 |
$safe_text = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", stripslashes( $safe_text ) ); |
|
2656 |
$safe_text = str_replace( "\r", '', $safe_text ); |
|
2657 |
$safe_text = str_replace( "\n", '\\n', addslashes( $safe_text ) ); |
|
2658 |
return apply_filters( 'js_escape', $safe_text, $text ); |
|
2659 |
} |
|
2660 |
||
2661 |
/** |
|
2662 |
* Escaping for HTML blocks. |
|
2663 |
* |
|
2664 |
* @since 2.8.0 |
|
2665 |
* |
|
2666 |
* @param string $text |
|
2667 |
* @return string |
|
2668 |
*/ |
|
2669 |
function esc_html( $text ) { |
|
2670 |
$safe_text = wp_check_invalid_utf8( $text ); |
|
2671 |
$safe_text = _wp_specialchars( $safe_text, ENT_QUOTES ); |
|
2672 |
return apply_filters( 'esc_html', $safe_text, $text ); |
|
2673 |
} |
|
2674 |
||
2675 |
/** |
|
2676 |
* Escaping for HTML attributes. |
|
2677 |
* |
|
2678 |
* @since 2.8.0 |
|
2679 |
* |
|
2680 |
* @param string $text |
|
2681 |
* @return string |
|
2682 |
*/ |
|
2683 |
function esc_attr( $text ) { |
|
2684 |
$safe_text = wp_check_invalid_utf8( $text ); |
|
2685 |
$safe_text = _wp_specialchars( $safe_text, ENT_QUOTES ); |
|
2686 |
return apply_filters( 'attribute_escape', $safe_text, $text ); |
|
2687 |
} |
|
2688 |
||
2689 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2690 |
* Escaping for textarea values. |
136 | 2691 |
* |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2692 |
* @since 3.1 |
136 | 2693 |
* |
2694 |
* @param string $text |
|
2695 |
* @return string |
|
2696 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2697 |
function esc_textarea( $text ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2698 |
$safe_text = htmlspecialchars( $text, ENT_QUOTES ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2699 |
return apply_filters( 'esc_textarea', $safe_text, $text ); |
136 | 2700 |
} |
2701 |
||
2702 |
/** |
|
2703 |
* Escape a HTML tag name. |
|
2704 |
* |
|
2705 |
* @since 2.5.0 |
|
2706 |
* |
|
2707 |
* @param string $tag_name |
|
2708 |
* @return string |
|
2709 |
*/ |
|
2710 |
function tag_escape($tag_name) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2711 |
$safe_tag = strtolower( preg_replace('/[^a-zA-Z0-9_:]/', '', $tag_name) ); |
136 | 2712 |
return apply_filters('tag_escape', $safe_tag, $tag_name); |
2713 |
} |
|
2714 |
||
2715 |
/** |
|
2716 |
* Escapes text for SQL LIKE special characters % and _. |
|
2717 |
* |
|
2718 |
* @since 2.5.0 |
|
2719 |
* |
|
2720 |
* @param string $text The text to be escaped. |
|
2721 |
* @return string text, safe for inclusion in LIKE query. |
|
2722 |
*/ |
|
2723 |
function like_escape($text) { |
|
2724 |
return str_replace(array("%", "_"), array("\\%", "\\_"), $text); |
|
2725 |
} |
|
2726 |
||
2727 |
/** |
|
2728 |
* Convert full URL paths to absolute paths. |
|
2729 |
* |
|
2730 |
* Removes the http or https protocols and the domain. Keeps the path '/' at the |
|
2731 |
* beginning, so it isn't a true relative link, but from the web root base. |
|
2732 |
* |
|
2733 |
* @since 2.1.0 |
|
2734 |
* |
|
2735 |
* @param string $link Full URL path. |
|
2736 |
* @return string Absolute path. |
|
2737 |
*/ |
|
2738 |
function wp_make_link_relative( $link ) { |
|
2739 |
return preg_replace( '|https?://[^/]+(/.*)|i', '$1', $link ); |
|
2740 |
} |
|
2741 |
||
2742 |
/** |
|
2743 |
* Sanitises various option values based on the nature of the option. |
|
2744 |
* |
|
2745 |
* This is basically a switch statement which will pass $value through a number |
|
2746 |
* of functions depending on the $option. |
|
2747 |
* |
|
2748 |
* @since 2.0.5 |
|
2749 |
* |
|
2750 |
* @param string $option The name of the option. |
|
2751 |
* @param string $value The unsanitised value. |
|
2752 |
* @return string Sanitized value. |
|
2753 |
*/ |
|
2754 |
function sanitize_option($option, $value) { |
|
2755 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2756 |
switch ( $option ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2757 |
case 'admin_email' : |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2758 |
case 'new_admin_email' : |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2759 |
$value = sanitize_email( $value ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2760 |
if ( ! is_email( $value ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2761 |
$value = get_option( $option ); // Resets option to stored value in the case of failed sanitization |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2762 |
if ( function_exists( 'add_settings_error' ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2763 |
add_settings_error( $option, 'invalid_admin_email', __( 'The email address entered did not appear to be a valid email address. Please enter a valid email address.' ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2764 |
} |
136 | 2765 |
break; |
2766 |
||
2767 |
case 'thumbnail_size_w': |
|
2768 |
case 'thumbnail_size_h': |
|
2769 |
case 'medium_size_w': |
|
2770 |
case 'medium_size_h': |
|
2771 |
case 'large_size_w': |
|
2772 |
case 'large_size_h': |
|
2773 |
case 'mailserver_port': |
|
2774 |
case 'comment_max_links': |
|
2775 |
case 'page_on_front': |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2776 |
case 'page_for_posts': |
136 | 2777 |
case 'rss_excerpt_length': |
2778 |
case 'default_category': |
|
2779 |
case 'default_email_category': |
|
2780 |
case 'default_link_category': |
|
2781 |
case 'close_comments_days_old': |
|
2782 |
case 'comments_per_page': |
|
2783 |
case 'thread_comments_depth': |
|
2784 |
case 'users_can_register': |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2785 |
case 'start_of_week': |
136 | 2786 |
$value = absint( $value ); |
2787 |
break; |
|
2788 |
||
2789 |
case 'posts_per_page': |
|
2790 |
case 'posts_per_rss': |
|
2791 |
$value = (int) $value; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2792 |
if ( empty($value) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2793 |
$value = 1; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2794 |
if ( $value < -1 ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2795 |
$value = abs($value); |
136 | 2796 |
break; |
2797 |
||
2798 |
case 'default_ping_status': |
|
2799 |
case 'default_comment_status': |
|
2800 |
// Options that if not there have 0 value but need to be something like "closed" |
|
2801 |
if ( $value == '0' || $value == '') |
|
2802 |
$value = 'closed'; |
|
2803 |
break; |
|
2804 |
||
2805 |
case 'blogdescription': |
|
2806 |
case 'blogname': |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2807 |
$value = wp_kses_post( $value ); |
136 | 2808 |
$value = esc_html( $value ); |
2809 |
break; |
|
2810 |
||
2811 |
case 'blog_charset': |
|
2812 |
$value = preg_replace('/[^a-zA-Z0-9_-]/', '', $value); // strips slashes |
|
2813 |
break; |
|
2814 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2815 |
case 'blog_public': |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2816 |
// This is the value if the settings checkbox is not checked on POST. Don't rely on this. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2817 |
if ( null === $value ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2818 |
$value = 1; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2819 |
else |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2820 |
$value = intval( $value ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2821 |
break; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2822 |
|
136 | 2823 |
case 'date_format': |
2824 |
case 'time_format': |
|
2825 |
case 'mailserver_url': |
|
2826 |
case 'mailserver_login': |
|
2827 |
case 'mailserver_pass': |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2828 |
case 'upload_path': |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2829 |
$value = strip_tags( $value ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2830 |
$value = wp_kses_data( $value ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2831 |
break; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2832 |
|
136 | 2833 |
case 'ping_sites': |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2834 |
$value = explode( "\n", $value ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2835 |
$value = array_filter( array_map( 'trim', $value ) ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2836 |
$value = array_filter( array_map( 'esc_url_raw', $value ) ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2837 |
$value = implode( "\n", $value ); |
136 | 2838 |
break; |
2839 |
||
2840 |
case 'gmt_offset': |
|
2841 |
$value = preg_replace('/[^0-9:.-]/', '', $value); // strips slashes |
|
2842 |
break; |
|
2843 |
||
2844 |
case 'siteurl': |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2845 |
if ( (bool)preg_match( '#http(s?)://(.+)#i', $value) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2846 |
$value = esc_url_raw($value); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2847 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2848 |
$value = get_option( $option ); // Resets option to stored value in the case of failed sanitization |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2849 |
if ( function_exists('add_settings_error') ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2850 |
add_settings_error('siteurl', 'invalid_siteurl', __('The WordPress address you entered did not appear to be a valid URL. Please enter a valid URL.')); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2851 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2852 |
break; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2853 |
|
136 | 2854 |
case 'home': |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2855 |
if ( (bool)preg_match( '#http(s?)://(.+)#i', $value) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2856 |
$value = esc_url_raw($value); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2857 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2858 |
$value = get_option( $option ); // Resets option to stored value in the case of failed sanitization |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2859 |
if ( function_exists('add_settings_error') ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2860 |
add_settings_error('home', 'invalid_home', __('The Site address you entered did not appear to be a valid URL. Please enter a valid URL.')); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2861 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2862 |
break; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2863 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2864 |
case 'WPLANG': |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2865 |
$allowed = get_available_languages(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2866 |
if ( ! in_array( $value, $allowed ) && ! empty( $value ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2867 |
$value = get_option( $option ); |
136 | 2868 |
break; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2869 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2870 |
case 'illegal_names': |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2871 |
if ( ! is_array( $value ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2872 |
$value = explode( "\n", $value ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2873 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2874 |
$value = array_values( array_filter( array_map( 'trim', $value ) ) ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2875 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2876 |
if ( ! $value ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2877 |
$value = ''; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2878 |
break; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2879 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2880 |
case 'limited_email_domains': |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2881 |
case 'banned_email_domains': |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2882 |
if ( ! is_array( $value ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2883 |
$value = explode( "\n", $value ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2884 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2885 |
$domains = array_values( array_filter( array_map( 'trim', $value ) ) ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2886 |
$value = array(); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2887 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2888 |
foreach ( $domains as $domain ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2889 |
if ( ! preg_match( '/(--|\.\.)/', $domain ) && preg_match( '|^([a-zA-Z0-9-\.])+$|', $domain ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2890 |
$value[] = $domain; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2891 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2892 |
if ( ! $value ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2893 |
$value = ''; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2894 |
break; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
2895 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2896 |
case 'timezone_string': |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2897 |
$allowed_zones = timezone_identifiers_list(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2898 |
if ( ! in_array( $value, $allowed_zones ) && ! empty( $value ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2899 |
$value = get_option( $option ); // Resets option to stored value in the case of failed sanitization |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2900 |
if ( function_exists('add_settings_error') ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2901 |
add_settings_error('timezone_string', 'invalid_timezone_string', __('The timezone you have entered is not valid. Please select a valid timezone.') ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2902 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2903 |
break; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2904 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2905 |
case 'permalink_structure': |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2906 |
case 'category_base': |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2907 |
case 'tag_base': |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2908 |
$value = esc_url_raw( $value ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2909 |
$value = str_replace( 'http://', '', $value ); |
136 | 2910 |
break; |
2911 |
} |
|
2912 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2913 |
$value = apply_filters("sanitize_option_{$option}", $value, $option); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2914 |
|
136 | 2915 |
return $value; |
2916 |
} |
|
2917 |
||
2918 |
/** |
|
2919 |
* Parses a string into variables to be stored in an array. |
|
2920 |
* |
|
2921 |
* Uses {@link http://www.php.net/parse_str parse_str()} and stripslashes if |
|
2922 |
* {@link http://www.php.net/magic_quotes magic_quotes_gpc} is on. |
|
2923 |
* |
|
2924 |
* @since 2.2.1 |
|
2925 |
* @uses apply_filters() for the 'wp_parse_str' filter. |
|
2926 |
* |
|
2927 |
* @param string $string The string to be parsed. |
|
2928 |
* @param array $array Variables will be stored in this array. |
|
2929 |
*/ |
|
2930 |
function wp_parse_str( $string, &$array ) { |
|
2931 |
parse_str( $string, $array ); |
|
2932 |
if ( get_magic_quotes_gpc() ) |
|
2933 |
$array = stripslashes_deep( $array ); |
|
2934 |
$array = apply_filters( 'wp_parse_str', $array ); |
|
2935 |
} |
|
2936 |
||
2937 |
/** |
|
2938 |
* Convert lone less than signs. |
|
2939 |
* |
|
2940 |
* KSES already converts lone greater than signs. |
|
2941 |
* |
|
2942 |
* @uses wp_pre_kses_less_than_callback in the callback function. |
|
2943 |
* @since 2.3.0 |
|
2944 |
* |
|
2945 |
* @param string $text Text to be converted. |
|
2946 |
* @return string Converted text. |
|
2947 |
*/ |
|
2948 |
function wp_pre_kses_less_than( $text ) { |
|
2949 |
return preg_replace_callback('%<[^>]*?((?=<)|>|$)%', 'wp_pre_kses_less_than_callback', $text); |
|
2950 |
} |
|
2951 |
||
2952 |
/** |
|
2953 |
* Callback function used by preg_replace. |
|
2954 |
* |
|
2955 |
* @uses esc_html to format the $matches text. |
|
2956 |
* @since 2.3.0 |
|
2957 |
* |
|
2958 |
* @param array $matches Populated by matches to preg_replace. |
|
2959 |
* @return string The text returned after esc_html if needed. |
|
2960 |
*/ |
|
2961 |
function wp_pre_kses_less_than_callback( $matches ) { |
|
2962 |
if ( false === strpos($matches[0], '>') ) |
|
2963 |
return esc_html($matches[0]); |
|
2964 |
return $matches[0]; |
|
2965 |
} |
|
2966 |
||
2967 |
/** |
|
2968 |
* WordPress implementation of PHP sprintf() with filters. |
|
2969 |
* |
|
2970 |
* @since 2.5.0 |
|
2971 |
* @link http://www.php.net/sprintf |
|
2972 |
* |
|
2973 |
* @param string $pattern The string which formatted args are inserted. |
|
2974 |
* @param mixed $args,... Arguments to be formatted into the $pattern string. |
|
2975 |
* @return string The formatted string. |
|
2976 |
*/ |
|
2977 |
function wp_sprintf( $pattern ) { |
|
2978 |
$args = func_get_args( ); |
|
2979 |
$len = strlen($pattern); |
|
2980 |
$start = 0; |
|
2981 |
$result = ''; |
|
2982 |
$arg_index = 0; |
|
2983 |
while ( $len > $start ) { |
|
2984 |
// Last character: append and break |
|
2985 |
if ( strlen($pattern) - 1 == $start ) { |
|
2986 |
$result .= substr($pattern, -1); |
|
2987 |
break; |
|
2988 |
} |
|
2989 |
||
2990 |
// Literal %: append and continue |
|
2991 |
if ( substr($pattern, $start, 2) == '%%' ) { |
|
2992 |
$start += 2; |
|
2993 |
$result .= '%'; |
|
2994 |
continue; |
|
2995 |
} |
|
2996 |
||
2997 |
// Get fragment before next % |
|
2998 |
$end = strpos($pattern, '%', $start + 1); |
|
2999 |
if ( false === $end ) |
|
3000 |
$end = $len; |
|
3001 |
$fragment = substr($pattern, $start, $end - $start); |
|
3002 |
||
3003 |
// Fragment has a specifier |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3004 |
if ( $pattern[$start] == '%' ) { |
136 | 3005 |
// Find numbered arguments or take the next one in order |
3006 |
if ( preg_match('/^%(\d+)\$/', $fragment, $matches) ) { |
|
3007 |
$arg = isset($args[$matches[1]]) ? $args[$matches[1]] : ''; |
|
3008 |
$fragment = str_replace("%{$matches[1]}$", '%', $fragment); |
|
3009 |
} else { |
|
3010 |
++$arg_index; |
|
3011 |
$arg = isset($args[$arg_index]) ? $args[$arg_index] : ''; |
|
3012 |
} |
|
3013 |
||
3014 |
// Apply filters OR sprintf |
|
3015 |
$_fragment = apply_filters( 'wp_sprintf', $fragment, $arg ); |
|
3016 |
if ( $_fragment != $fragment ) |
|
3017 |
$fragment = $_fragment; |
|
3018 |
else |
|
3019 |
$fragment = sprintf($fragment, strval($arg) ); |
|
3020 |
} |
|
3021 |
||
3022 |
// Append to result and move to next fragment |
|
3023 |
$result .= $fragment; |
|
3024 |
$start = $end; |
|
3025 |
} |
|
3026 |
return $result; |
|
3027 |
} |
|
3028 |
||
3029 |
/** |
|
3030 |
* Localize list items before the rest of the content. |
|
3031 |
* |
|
3032 |
* The '%l' must be at the first characters can then contain the rest of the |
|
3033 |
* content. The list items will have ', ', ', and', and ' and ' added depending |
|
3034 |
* on the amount of list items in the $args parameter. |
|
3035 |
* |
|
3036 |
* @since 2.5.0 |
|
3037 |
* |
|
3038 |
* @param string $pattern Content containing '%l' at the beginning. |
|
3039 |
* @param array $args List items to prepend to the content and replace '%l'. |
|
3040 |
* @return string Localized list items and rest of the content. |
|
3041 |
*/ |
|
3042 |
function wp_sprintf_l($pattern, $args) { |
|
3043 |
// Not a match |
|
3044 |
if ( substr($pattern, 0, 2) != '%l' ) |
|
3045 |
return $pattern; |
|
3046 |
||
3047 |
// Nothing to work with |
|
3048 |
if ( empty($args) ) |
|
3049 |
return ''; |
|
3050 |
||
3051 |
// Translate and filter the delimiter set (avoid ampersands and entities here) |
|
3052 |
$l = apply_filters('wp_sprintf_l', array( |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3053 |
/* translators: used between list items, there is a space after the comma */ |
136 | 3054 |
'between' => __(', '), |
3055 |
/* translators: used between list items, there is a space after the and */ |
|
3056 |
'between_last_two' => __(', and '), |
|
3057 |
/* translators: used between only two list items, there is a space after the and */ |
|
3058 |
'between_only_two' => __(' and '), |
|
3059 |
)); |
|
3060 |
||
3061 |
$args = (array) $args; |
|
3062 |
$result = array_shift($args); |
|
3063 |
if ( count($args) == 1 ) |
|
3064 |
$result .= $l['between_only_two'] . array_shift($args); |
|
3065 |
// Loop when more than two args |
|
3066 |
$i = count($args); |
|
3067 |
while ( $i ) { |
|
3068 |
$arg = array_shift($args); |
|
3069 |
$i--; |
|
3070 |
if ( 0 == $i ) |
|
3071 |
$result .= $l['between_last_two'] . $arg; |
|
3072 |
else |
|
3073 |
$result .= $l['between'] . $arg; |
|
3074 |
} |
|
3075 |
return $result . substr($pattern, 2); |
|
3076 |
} |
|
3077 |
||
3078 |
/** |
|
3079 |
* Safely extracts not more than the first $count characters from html string. |
|
3080 |
* |
|
3081 |
* UTF-8, tags and entities safe prefix extraction. Entities inside will *NOT* |
|
3082 |
* be counted as one character. For example & will be counted as 4, < as |
|
3083 |
* 3, etc. |
|
3084 |
* |
|
3085 |
* @since 2.5.0 |
|
3086 |
* |
|
3087 |
* @param integer $str String to get the excerpt from. |
|
3088 |
* @param integer $count Maximum number of characters to take. |
|
3089 |
* @return string The excerpt. |
|
3090 |
*/ |
|
3091 |
function wp_html_excerpt( $str, $count ) { |
|
3092 |
$str = wp_strip_all_tags( $str, true ); |
|
3093 |
$str = mb_substr( $str, 0, $count ); |
|
3094 |
// remove part of an entity at the end |
|
3095 |
$str = preg_replace( '/&[^;\s]{0,6}$/', '', $str ); |
|
3096 |
return $str; |
|
3097 |
} |
|
3098 |
||
3099 |
/** |
|
3100 |
* Add a Base url to relative links in passed content. |
|
3101 |
* |
|
3102 |
* By default it supports the 'src' and 'href' attributes. However this can be |
|
3103 |
* changed via the 3rd param. |
|
3104 |
* |
|
3105 |
* @since 2.7.0 |
|
3106 |
* |
|
3107 |
* @param string $content String to search for links in. |
|
3108 |
* @param string $base The base URL to prefix to links. |
|
3109 |
* @param array $attrs The attributes which should be processed. |
|
3110 |
* @return string The processed content. |
|
3111 |
*/ |
|
3112 |
function links_add_base_url( $content, $base, $attrs = array('src', 'href') ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3113 |
global $_links_add_base; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3114 |
$_links_add_base = $base; |
136 | 3115 |
$attrs = implode('|', (array)$attrs); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3116 |
return preg_replace_callback( "!($attrs)=(['\"])(.+?)\\2!i", '_links_add_base', $content ); |
136 | 3117 |
} |
3118 |
||
3119 |
/** |
|
3120 |
* Callback to add a base url to relative links in passed content. |
|
3121 |
* |
|
3122 |
* @since 2.7.0 |
|
3123 |
* @access private |
|
3124 |
* |
|
3125 |
* @param string $m The matched link. |
|
3126 |
* @return string The processed link. |
|
3127 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3128 |
function _links_add_base($m) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3129 |
global $_links_add_base; |
136 | 3130 |
//1 = attribute name 2 = quotation mark 3 = URL |
3131 |
return $m[1] . '=' . $m[2] . |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3132 |
( preg_match( '#^(\w{1,20}):#', $m[3], $protocol ) && in_array( $protocol[1], wp_allowed_protocols() ) ? |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3133 |
$m[3] : |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3134 |
path_join( $_links_add_base, $m[3] ) ) |
136 | 3135 |
. $m[2]; |
3136 |
} |
|
3137 |
||
3138 |
/** |
|
3139 |
* Adds a Target attribute to all links in passed content. |
|
3140 |
* |
|
3141 |
* This function by default only applies to <a> tags, however this can be |
|
3142 |
* modified by the 3rd param. |
|
3143 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3144 |
* <b>NOTE:</b> Any current target attributed will be stripped and replaced. |
136 | 3145 |
* |
3146 |
* @since 2.7.0 |
|
3147 |
* |
|
3148 |
* @param string $content String to search for links in. |
|
3149 |
* @param string $target The Target to add to the links. |
|
3150 |
* @param array $tags An array of tags to apply to. |
|
3151 |
* @return string The processed content. |
|
3152 |
*/ |
|
3153 |
function links_add_target( $content, $target = '_blank', $tags = array('a') ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3154 |
global $_links_add_target; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3155 |
$_links_add_target = $target; |
136 | 3156 |
$tags = implode('|', (array)$tags); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3157 |
return preg_replace_callback( "!<($tags)(.+?)>!i", '_links_add_target', $content ); |
136 | 3158 |
} |
3159 |
||
3160 |
/** |
|
3161 |
* Callback to add a target attribute to all links in passed content. |
|
3162 |
* |
|
3163 |
* @since 2.7.0 |
|
3164 |
* @access private |
|
3165 |
* |
|
3166 |
* @param string $m The matched link. |
|
3167 |
* @return string The processed link. |
|
3168 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3169 |
function _links_add_target( $m ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3170 |
global $_links_add_target; |
136 | 3171 |
$tag = $m[1]; |
3172 |
$link = preg_replace('|(target=[\'"](.*?)[\'"])|i', '', $m[2]); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3173 |
return '<' . $tag . $link . ' target="' . esc_attr( $_links_add_target ) . '">'; |
136 | 3174 |
} |
3175 |
||
3176 |
// normalize EOL characters and strip duplicate whitespace |
|
3177 |
function normalize_whitespace( $str ) { |
|
3178 |
$str = trim($str); |
|
3179 |
$str = str_replace("\r", "\n", $str); |
|
3180 |
$str = preg_replace( array( '/\n+/', '/[ \t]+/' ), array( "\n", ' ' ), $str ); |
|
3181 |
return $str; |
|
3182 |
} |
|
3183 |
||
3184 |
/** |
|
3185 |
* Properly strip all HTML tags including script and style |
|
3186 |
* |
|
3187 |
* @since 2.9.0 |
|
3188 |
* |
|
3189 |
* @param string $string String containing HTML tags |
|
3190 |
* @param bool $remove_breaks optional Whether to remove left over line breaks and white space chars |
|
3191 |
* @return string The processed string. |
|
3192 |
*/ |
|
3193 |
function wp_strip_all_tags($string, $remove_breaks = false) { |
|
3194 |
$string = preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $string ); |
|
3195 |
$string = strip_tags($string); |
|
3196 |
||
3197 |
if ( $remove_breaks ) |
|
3198 |
$string = preg_replace('/[\r\n\t ]+/', ' ', $string); |
|
3199 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3200 |
return trim( $string ); |
136 | 3201 |
} |
3202 |
||
3203 |
/** |
|
3204 |
* Sanitize a string from user input or from the db |
|
3205 |
* |
|
3206 |
* check for invalid UTF-8, |
|
3207 |
* Convert single < characters to entity, |
|
3208 |
* strip all tags, |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3209 |
* remove line breaks, tabs and extra white space, |
136 | 3210 |
* strip octets. |
3211 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3212 |
* @since 2.9.0 |
136 | 3213 |
* |
3214 |
* @param string $str |
|
3215 |
* @return string |
|
3216 |
*/ |
|
3217 |
function sanitize_text_field($str) { |
|
3218 |
$filtered = wp_check_invalid_utf8( $str ); |
|
3219 |
||
3220 |
if ( strpos($filtered, '<') !== false ) { |
|
3221 |
$filtered = wp_pre_kses_less_than( $filtered ); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3222 |
// This will strip extra whitespace for us. |
136 | 3223 |
$filtered = wp_strip_all_tags( $filtered, true ); |
3224 |
} else { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3225 |
$filtered = trim( preg_replace('/[\r\n\t ]+/', ' ', $filtered) ); |
136 | 3226 |
} |
3227 |
||
3228 |
$match = array(); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3229 |
$found = false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3230 |
while ( preg_match('/%[a-f0-9]{2}/i', $filtered, $match) ) { |
136 | 3231 |
$filtered = str_replace($match[0], '', $filtered); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3232 |
$found = true; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3233 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3234 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3235 |
if ( $found ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3236 |
// Strip out the whitespace that may now exist after removing the octets. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3237 |
$filtered = trim( preg_replace('/ +/', ' ', $filtered) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3238 |
} |
136 | 3239 |
|
3240 |
return apply_filters('sanitize_text_field', $filtered, $str); |
|
3241 |
} |
|
3242 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3243 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3244 |
* i18n friendly version of basename() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3245 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3246 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3247 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3248 |
* @param string $path A path. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3249 |
* @param string $suffix If the filename ends in suffix this will also be cut off. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3250 |
* @return string |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3251 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3252 |
function wp_basename( $path, $suffix = '' ) { |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3253 |
return urldecode( basename( str_replace( array( '%2F', '%5C' ), '/', urlencode( $path ) ), $suffix ) ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3254 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3255 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3256 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3257 |
* Forever eliminate "Wordpress" from the planet (or at least the little bit we can influence). |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3258 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3259 |
* Violating our coding standards for a good function name. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3260 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3261 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3262 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3263 |
function capital_P_dangit( $text ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3264 |
// Simple replacement for titles |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3265 |
if ( 'the_title' === current_filter() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3266 |
return str_replace( 'Wordpress', 'WordPress', $text ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3267 |
// Still here? Use the more judicious replacement |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3268 |
static $dblq = false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3269 |
if ( false === $dblq ) |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
3270 |
$dblq = _x( '“', 'opening curly double quote' ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3271 |
return str_replace( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3272 |
array( ' Wordpress', '‘Wordpress', $dblq . 'Wordpress', '>Wordpress', '(Wordpress' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3273 |
array( ' WordPress', '‘WordPress', $dblq . 'WordPress', '>WordPress', '(WordPress' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3274 |
$text ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3275 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3276 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3277 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3278 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3279 |
* Sanitize a mime type |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3280 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3281 |
* @since 3.1.3 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3282 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3283 |
* @param string $mime_type Mime type |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3284 |
* @return string Sanitized mime type |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3285 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3286 |
function sanitize_mime_type( $mime_type ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3287 |
$sani_mime_type = preg_replace( '/[^-+*.a-zA-Z0-9\/]/', '', $mime_type ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3288 |
return apply_filters( 'sanitize_mime_type', $sani_mime_type, $mime_type ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3289 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3290 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3291 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3292 |
* Sanitize space or carriage return separated URLs that are used to send trackbacks. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3293 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3294 |
* @since 3.4.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3295 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3296 |
* @param string $to_ping Space or carriage return separated URLs |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3297 |
* @return string URLs starting with the http or https protocol, separated by a carriage return. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3298 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3299 |
function sanitize_trackback_urls( $to_ping ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3300 |
$urls_to_ping = preg_split( '/[\r\n\t ]/', trim( $to_ping ), -1, PREG_SPLIT_NO_EMPTY ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3301 |
foreach ( $urls_to_ping as $k => $url ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3302 |
if ( !preg_match( '#^https?://.#i', $url ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3303 |
unset( $urls_to_ping[$k] ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3304 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3305 |
$urls_to_ping = array_map( 'esc_url_raw', $urls_to_ping ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3306 |
$urls_to_ping = implode( "\n", $urls_to_ping ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3307 |
return apply_filters( 'sanitize_trackback_urls', $urls_to_ping, $to_ping ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3308 |
} |