author | Anthony Ly <anthonyly.com@gmail.com> |
Mon, 19 Nov 2012 18:26:13 +0100 | |
changeset 194 | 32102edaa81b |
parent 136 | bde1974c263b |
child 204 | 09a1c134465b |
permissions | -rw-r--r-- |
136 | 1 |
<?php |
2 |
/** |
|
3 |
* Main WordPress API |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
*/ |
|
7 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
8 |
require( ABSPATH . WPINC . '/option.php' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
9 |
|
136 | 10 |
/** |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
11 |
* Converts given date string into a different format. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
12 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
13 |
* $format should be either a PHP date format string, e.g. 'U' for a Unix |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
14 |
* timestamp, or 'G' for a Unix timestamp assuming that $date is GMT. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
15 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
16 |
* If $translate is true then the given date and format string will |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
17 |
* be passed to date_i18n() for translation. |
136 | 18 |
* |
19 |
* @since 0.71 |
|
20 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
21 |
* @param string $format Format of the date to return. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
22 |
* @param string $date Date string to convert. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
23 |
* @param bool $translate Whether the return date should be translated. Default is true. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
24 |
* @return string|int Formatted date string, or Unix timestamp. |
136 | 25 |
*/ |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
26 |
function mysql2date( $format, $date, $translate = true ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
27 |
if ( empty( $date ) ) |
136 | 28 |
return false; |
29 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
30 |
if ( 'G' == $format ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
31 |
return strtotime( $date . ' +0000' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
32 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
33 |
$i = strtotime( $date ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
34 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
35 |
if ( 'U' == $format ) |
136 | 36 |
return $i; |
37 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
38 |
if ( $translate ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
39 |
return date_i18n( $format, $i ); |
136 | 40 |
else |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
41 |
return date( $format, $i ); |
136 | 42 |
} |
43 |
||
44 |
/** |
|
45 |
* Retrieve the current time based on specified type. |
|
46 |
* |
|
47 |
* The 'mysql' type will return the time in the format for MySQL DATETIME field. |
|
48 |
* The 'timestamp' type will return the current timestamp. |
|
49 |
* |
|
50 |
* If $gmt is set to either '1' or 'true', then both types will use GMT time. |
|
51 |
* if $gmt is false, the output is adjusted with the GMT offset in the WordPress option. |
|
52 |
* |
|
53 |
* @since 1.0.0 |
|
54 |
* |
|
55 |
* @param string $type Either 'mysql' or 'timestamp'. |
|
56 |
* @param int|bool $gmt Optional. Whether to use GMT timezone. Default is false. |
|
57 |
* @return int|string String if $type is 'gmt', int if $type is 'timestamp'. |
|
58 |
*/ |
|
59 |
function current_time( $type, $gmt = 0 ) { |
|
60 |
switch ( $type ) { |
|
61 |
case 'mysql': |
|
62 |
return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * 3600 ) ) ); |
|
63 |
break; |
|
64 |
case 'timestamp': |
|
65 |
return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * 3600 ); |
|
66 |
break; |
|
67 |
} |
|
68 |
} |
|
69 |
||
70 |
/** |
|
71 |
* Retrieve the date in localized format, based on timestamp. |
|
72 |
* |
|
73 |
* If the locale specifies the locale month and weekday, then the locale will |
|
74 |
* take over the format for the date. If it isn't, then the date format string |
|
75 |
* will be used instead. |
|
76 |
* |
|
77 |
* @since 0.71 |
|
78 |
* |
|
79 |
* @param string $dateformatstring Format to display the date. |
|
80 |
* @param int $unixtimestamp Optional. Unix timestamp. |
|
81 |
* @param bool $gmt Optional, default is false. Whether to convert to GMT for time. |
|
82 |
* @return string The date, translated if locale specifies it. |
|
83 |
*/ |
|
84 |
function date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false ) { |
|
85 |
global $wp_locale; |
|
86 |
$i = $unixtimestamp; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
87 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
88 |
if ( false === $i ) { |
136 | 89 |
if ( ! $gmt ) |
90 |
$i = current_time( 'timestamp' ); |
|
91 |
else |
|
92 |
$i = time(); |
|
93 |
// we should not let date() interfere with our |
|
94 |
// specially computed timestamp |
|
95 |
$gmt = true; |
|
96 |
} |
|
97 |
||
98 |
// store original value for language with untypical grammars |
|
99 |
// see http://core.trac.wordpress.org/ticket/9396 |
|
100 |
$req_format = $dateformatstring; |
|
101 |
||
102 |
$datefunc = $gmt? 'gmdate' : 'date'; |
|
103 |
||
104 |
if ( ( !empty( $wp_locale->month ) ) && ( !empty( $wp_locale->weekday ) ) ) { |
|
105 |
$datemonth = $wp_locale->get_month( $datefunc( 'm', $i ) ); |
|
106 |
$datemonth_abbrev = $wp_locale->get_month_abbrev( $datemonth ); |
|
107 |
$dateweekday = $wp_locale->get_weekday( $datefunc( 'w', $i ) ); |
|
108 |
$dateweekday_abbrev = $wp_locale->get_weekday_abbrev( $dateweekday ); |
|
109 |
$datemeridiem = $wp_locale->get_meridiem( $datefunc( 'a', $i ) ); |
|
110 |
$datemeridiem_capital = $wp_locale->get_meridiem( $datefunc( 'A', $i ) ); |
|
111 |
$dateformatstring = ' '.$dateformatstring; |
|
112 |
$dateformatstring = preg_replace( "/([^\\\])D/", "\\1" . backslashit( $dateweekday_abbrev ), $dateformatstring ); |
|
113 |
$dateformatstring = preg_replace( "/([^\\\])F/", "\\1" . backslashit( $datemonth ), $dateformatstring ); |
|
114 |
$dateformatstring = preg_replace( "/([^\\\])l/", "\\1" . backslashit( $dateweekday ), $dateformatstring ); |
|
115 |
$dateformatstring = preg_replace( "/([^\\\])M/", "\\1" . backslashit( $datemonth_abbrev ), $dateformatstring ); |
|
116 |
$dateformatstring = preg_replace( "/([^\\\])a/", "\\1" . backslashit( $datemeridiem ), $dateformatstring ); |
|
117 |
$dateformatstring = preg_replace( "/([^\\\])A/", "\\1" . backslashit( $datemeridiem_capital ), $dateformatstring ); |
|
118 |
||
119 |
$dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 ); |
|
120 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
121 |
$timezone_formats = array( 'P', 'I', 'O', 'T', 'Z', 'e' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
122 |
$timezone_formats_re = implode( '|', $timezone_formats ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
123 |
if ( preg_match( "/$timezone_formats_re/", $dateformatstring ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
124 |
$timezone_string = get_option( 'timezone_string' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
125 |
if ( $timezone_string ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
126 |
$timezone_object = timezone_open( $timezone_string ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
127 |
$date_object = date_create( null, $timezone_object ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
128 |
foreach( $timezone_formats as $timezone_format ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
129 |
if ( false !== strpos( $dateformatstring, $timezone_format ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
130 |
$formatted = date_format( $date_object, $timezone_format ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
131 |
$dateformatstring = ' '.$dateformatstring; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
132 |
$dateformatstring = preg_replace( "/([^\\\])$timezone_format/", "\\1" . backslashit( $formatted ), $dateformatstring ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
133 |
$dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
134 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
135 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
136 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
137 |
} |
136 | 138 |
$j = @$datefunc( $dateformatstring, $i ); |
139 |
// allow plugins to redo this entirely for languages with untypical grammars |
|
140 |
$j = apply_filters('date_i18n', $j, $req_format, $i, $gmt); |
|
141 |
return $j; |
|
142 |
} |
|
143 |
||
144 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
145 |
* Convert integer number to format based on the locale. |
136 | 146 |
* |
147 |
* @since 2.3.0 |
|
148 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
149 |
* @param int $number The number to convert based on locale. |
136 | 150 |
* @param int $decimals Precision of the number of decimal places. |
151 |
* @return string Converted number in string format. |
|
152 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
153 |
function number_format_i18n( $number, $decimals = 0 ) { |
136 | 154 |
global $wp_locale; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
155 |
$formatted = number_format( $number, absint( $decimals ), $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep'] ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
156 |
return apply_filters( 'number_format_i18n', $formatted ); |
136 | 157 |
} |
158 |
||
159 |
/** |
|
160 |
* Convert number of bytes largest unit bytes will fit into. |
|
161 |
* |
|
162 |
* It is easier to read 1kB than 1024 bytes and 1MB than 1048576 bytes. Converts |
|
163 |
* number of bytes to human readable number by taking the number of that unit |
|
164 |
* that the bytes will go into it. Supports TB value. |
|
165 |
* |
|
166 |
* Please note that integers in PHP are limited to 32 bits, unless they are on |
|
167 |
* 64 bit architecture, then they have 64 bit size. If you need to place the |
|
168 |
* larger size then what PHP integer type will hold, then use a string. It will |
|
169 |
* be converted to a double, which should always have 64 bit length. |
|
170 |
* |
|
171 |
* Technically the correct unit names for powers of 1024 are KiB, MiB etc. |
|
172 |
* @link http://en.wikipedia.org/wiki/Byte |
|
173 |
* |
|
174 |
* @since 2.3.0 |
|
175 |
* |
|
176 |
* @param int|string $bytes Number of bytes. Note max integer size for integers. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
177 |
* @param int $decimals Precision of number of decimal places. Deprecated. |
136 | 178 |
* @return bool|string False on failure. Number string on success. |
179 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
180 |
function size_format( $bytes, $decimals = 0 ) { |
136 | 181 |
$quant = array( |
182 |
// ========================= Origin ==== |
|
183 |
'TB' => 1099511627776, // pow( 1024, 4) |
|
184 |
'GB' => 1073741824, // pow( 1024, 3) |
|
185 |
'MB' => 1048576, // pow( 1024, 2) |
|
186 |
'kB' => 1024, // pow( 1024, 1) |
|
187 |
'B ' => 1, // pow( 1024, 0) |
|
188 |
); |
|
189 |
foreach ( $quant as $unit => $mag ) |
|
190 |
if ( doubleval($bytes) >= $mag ) |
|
191 |
return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit; |
|
192 |
||
193 |
return false; |
|
194 |
} |
|
195 |
||
196 |
/** |
|
197 |
* Get the week start and end from the datetime or date string from mysql. |
|
198 |
* |
|
199 |
* @since 0.71 |
|
200 |
* |
|
201 |
* @param string $mysqlstring Date or datetime field type from mysql. |
|
202 |
* @param int $start_of_week Optional. Start of the week as an integer. |
|
203 |
* @return array Keys are 'start' and 'end'. |
|
204 |
*/ |
|
205 |
function get_weekstartend( $mysqlstring, $start_of_week = '' ) { |
|
206 |
$my = substr( $mysqlstring, 0, 4 ); // Mysql string Year |
|
207 |
$mm = substr( $mysqlstring, 8, 2 ); // Mysql string Month |
|
208 |
$md = substr( $mysqlstring, 5, 2 ); // Mysql string day |
|
209 |
$day = mktime( 0, 0, 0, $md, $mm, $my ); // The timestamp for mysqlstring day. |
|
210 |
$weekday = date( 'w', $day ); // The day of the week from the timestamp |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
211 |
if ( !is_numeric($start_of_week) ) |
136 | 212 |
$start_of_week = get_option( 'start_of_week' ); |
213 |
||
214 |
if ( $weekday < $start_of_week ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
215 |
$weekday += 7; |
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 |
$start = $day - 86400 * ( $weekday - $start_of_week ); // The most recent week start day on or before $day |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
218 |
$end = $start + 604799; // $start + 7 days - 1 second |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
219 |
return compact( 'start', 'end' ); |
136 | 220 |
} |
221 |
||
222 |
/** |
|
223 |
* Unserialize value only if it was serialized. |
|
224 |
* |
|
225 |
* @since 2.0.0 |
|
226 |
* |
|
227 |
* @param string $original Maybe unserialized original, if is needed. |
|
228 |
* @return mixed Unserialized data can be any type. |
|
229 |
*/ |
|
230 |
function maybe_unserialize( $original ) { |
|
231 |
if ( is_serialized( $original ) ) // don't attempt to unserialize data that wasn't serialized going in |
|
232 |
return @unserialize( $original ); |
|
233 |
return $original; |
|
234 |
} |
|
235 |
||
236 |
/** |
|
237 |
* Check value to find if it was serialized. |
|
238 |
* |
|
239 |
* If $data is not an string, then returned value will always be false. |
|
240 |
* Serialized data is always a string. |
|
241 |
* |
|
242 |
* @since 2.0.5 |
|
243 |
* |
|
244 |
* @param mixed $data Value to check to see if was serialized. |
|
245 |
* @return bool False if not serialized and true if it was. |
|
246 |
*/ |
|
247 |
function is_serialized( $data ) { |
|
248 |
// if it isn't a string, it isn't serialized |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
249 |
if ( ! is_string( $data ) ) |
136 | 250 |
return false; |
251 |
$data = trim( $data ); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
252 |
if ( 'N;' == $data ) |
136 | 253 |
return true; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
254 |
$length = strlen( $data ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
255 |
if ( $length < 4 ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
256 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
257 |
if ( ':' !== $data[1] ) |
136 | 258 |
return false; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
259 |
$lastc = $data[$length-1]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
260 |
if ( ';' !== $lastc && '}' !== $lastc ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
261 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
262 |
$token = $data[0]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
263 |
switch ( $token ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
264 |
case 's' : |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
265 |
if ( '"' !== $data[$length-2] ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
266 |
return false; |
136 | 267 |
case 'a' : |
268 |
case 'O' : |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
269 |
return (bool) preg_match( "/^{$token}:[0-9]+:/s", $data ); |
136 | 270 |
case 'b' : |
271 |
case 'i' : |
|
272 |
case 'd' : |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
273 |
return (bool) preg_match( "/^{$token}:[0-9.E-]+;\$/", $data ); |
136 | 274 |
} |
275 |
return false; |
|
276 |
} |
|
277 |
||
278 |
/** |
|
279 |
* Check whether serialized data is of string type. |
|
280 |
* |
|
281 |
* @since 2.0.5 |
|
282 |
* |
|
283 |
* @param mixed $data Serialized data |
|
284 |
* @return bool False if not a serialized string, true if it is. |
|
285 |
*/ |
|
286 |
function is_serialized_string( $data ) { |
|
287 |
// if it isn't a string, it isn't a serialized string |
|
288 |
if ( !is_string( $data ) ) |
|
289 |
return false; |
|
290 |
$data = trim( $data ); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
291 |
$length = strlen( $data ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
292 |
if ( $length < 4 ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
293 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
294 |
elseif ( ':' !== $data[1] ) |
136 | 295 |
return false; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
296 |
elseif ( ';' !== $data[$length-1] ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
297 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
298 |
elseif ( $data[0] !== 's' ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
299 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
300 |
elseif ( '"' !== $data[$length-2] ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
301 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
302 |
else |
136 | 303 |
return true; |
304 |
} |
|
305 |
||
306 |
/** |
|
307 |
* Serialize data, if needed. |
|
308 |
* |
|
309 |
* @since 2.0.5 |
|
310 |
* |
|
311 |
* @param mixed $data Data that might be serialized. |
|
312 |
* @return mixed A scalar data |
|
313 |
*/ |
|
314 |
function maybe_serialize( $data ) { |
|
315 |
if ( is_array( $data ) || is_object( $data ) ) |
|
316 |
return serialize( $data ); |
|
317 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
318 |
// Double serialization is required for backward compatibility. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
319 |
// See http://core.trac.wordpress.org/ticket/12930 |
136 | 320 |
if ( is_serialized( $data ) ) |
321 |
return serialize( $data ); |
|
322 |
||
323 |
return $data; |
|
324 |
} |
|
325 |
||
326 |
/** |
|
327 |
* Retrieve post title from XMLRPC XML. |
|
328 |
* |
|
329 |
* If the title element is not part of the XML, then the default post title from |
|
330 |
* the $post_default_title will be used instead. |
|
331 |
* |
|
332 |
* @package WordPress |
|
333 |
* @subpackage XMLRPC |
|
334 |
* @since 0.71 |
|
335 |
* |
|
336 |
* @global string $post_default_title Default XMLRPC post title. |
|
337 |
* |
|
338 |
* @param string $content XMLRPC XML Request content |
|
339 |
* @return string Post title |
|
340 |
*/ |
|
341 |
function xmlrpc_getposttitle( $content ) { |
|
342 |
global $post_default_title; |
|
343 |
if ( preg_match( '/<title>(.+?)<\/title>/is', $content, $matchtitle ) ) { |
|
344 |
$post_title = $matchtitle[1]; |
|
345 |
} else { |
|
346 |
$post_title = $post_default_title; |
|
347 |
} |
|
348 |
return $post_title; |
|
349 |
} |
|
350 |
||
351 |
/** |
|
352 |
* Retrieve the post category or categories from XMLRPC XML. |
|
353 |
* |
|
354 |
* If the category element is not found, then the default post category will be |
|
355 |
* used. The return type then would be what $post_default_category. If the |
|
356 |
* category is found, then it will always be an array. |
|
357 |
* |
|
358 |
* @package WordPress |
|
359 |
* @subpackage XMLRPC |
|
360 |
* @since 0.71 |
|
361 |
* |
|
362 |
* @global string $post_default_category Default XMLRPC post category. |
|
363 |
* |
|
364 |
* @param string $content XMLRPC XML Request content |
|
365 |
* @return string|array List of categories or category name. |
|
366 |
*/ |
|
367 |
function xmlrpc_getpostcategory( $content ) { |
|
368 |
global $post_default_category; |
|
369 |
if ( preg_match( '/<category>(.+?)<\/category>/is', $content, $matchcat ) ) { |
|
370 |
$post_category = trim( $matchcat[1], ',' ); |
|
371 |
$post_category = explode( ',', $post_category ); |
|
372 |
} else { |
|
373 |
$post_category = $post_default_category; |
|
374 |
} |
|
375 |
return $post_category; |
|
376 |
} |
|
377 |
||
378 |
/** |
|
379 |
* XMLRPC XML content without title and category elements. |
|
380 |
* |
|
381 |
* @package WordPress |
|
382 |
* @subpackage XMLRPC |
|
383 |
* @since 0.71 |
|
384 |
* |
|
385 |
* @param string $content XMLRPC XML Request content |
|
386 |
* @return string XMLRPC XML Request content without title and category elements. |
|
387 |
*/ |
|
388 |
function xmlrpc_removepostdata( $content ) { |
|
389 |
$content = preg_replace( '/<title>(.+?)<\/title>/si', '', $content ); |
|
390 |
$content = preg_replace( '/<category>(.+?)<\/category>/si', '', $content ); |
|
391 |
$content = trim( $content ); |
|
392 |
return $content; |
|
393 |
} |
|
394 |
||
395 |
/** |
|
396 |
* Check content for video and audio links to add as enclosures. |
|
397 |
* |
|
398 |
* Will not add enclosures that have already been added and will |
|
399 |
* remove enclosures that are no longer in the post. This is called as |
|
400 |
* pingbacks and trackbacks. |
|
401 |
* |
|
402 |
* @package WordPress |
|
403 |
* @since 1.5.0 |
|
404 |
* |
|
405 |
* @uses $wpdb |
|
406 |
* |
|
407 |
* @param string $content Post Content |
|
408 |
* @param int $post_ID Post ID |
|
409 |
*/ |
|
410 |
function do_enclose( $content, $post_ID ) { |
|
411 |
global $wpdb; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
412 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
413 |
//TODO: Tidy this ghetto code up and make the debug code optional |
136 | 414 |
include_once( ABSPATH . WPINC . '/class-IXR.php' ); |
415 |
||
416 |
$post_links = array(); |
|
417 |
||
418 |
$pung = get_enclosed( $post_ID ); |
|
419 |
||
420 |
$ltrs = '\w'; |
|
421 |
$gunk = '/#~:.?+=&%@!\-'; |
|
422 |
$punc = '.:?\-'; |
|
423 |
$any = $ltrs . $gunk . $punc; |
|
424 |
||
425 |
preg_match_all( "{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp ); |
|
426 |
||
427 |
foreach ( $pung as $link_test ) { |
|
428 |
if ( !in_array( $link_test, $post_links_temp[0] ) ) { // link no longer in post |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
429 |
$mids = $wpdb->get_col( $wpdb->prepare("SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, like_escape( $link_test ) . '%') ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
430 |
foreach ( $mids as $mid ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
431 |
delete_metadata_by_mid( 'post', $mid ); |
136 | 432 |
} |
433 |
} |
|
434 |
||
435 |
foreach ( (array) $post_links_temp[0] as $link_test ) { |
|
436 |
if ( !in_array( $link_test, $pung ) ) { // If we haven't pung it already |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
437 |
$test = @parse_url( $link_test ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
438 |
if ( false === $test ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
439 |
continue; |
136 | 440 |
if ( isset( $test['query'] ) ) |
441 |
$post_links[] = $link_test; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
442 |
elseif ( isset($test['path']) && ( $test['path'] != '/' ) && ($test['path'] != '' ) ) |
136 | 443 |
$post_links[] = $link_test; |
444 |
} |
|
445 |
} |
|
446 |
||
447 |
foreach ( (array) $post_links as $url ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
448 |
if ( $url != '' && !$wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, like_escape( $url ) . '%' ) ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
449 |
|
136 | 450 |
if ( $headers = wp_get_http_headers( $url) ) { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
451 |
$len = isset( $headers['content-length'] ) ? (int) $headers['content-length'] : 0; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
452 |
$type = isset( $headers['content-type'] ) ? $headers['content-type'] : ''; |
136 | 453 |
$allowed_types = array( 'video', 'audio' ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
454 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
455 |
// Check to see if we can figure out the mime type from |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
456 |
// the extension |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
457 |
$url_parts = @parse_url( $url ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
458 |
if ( false !== $url_parts ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
459 |
$extension = pathinfo( $url_parts['path'], PATHINFO_EXTENSION ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
460 |
if ( !empty( $extension ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
461 |
foreach ( get_allowed_mime_types( ) as $exts => $mime ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
462 |
if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
463 |
$type = $mime; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
464 |
break; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
465 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
466 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
467 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
468 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
469 |
|
136 | 470 |
if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
471 |
add_post_meta( $post_ID, 'enclosure', "$url\n$len\n$mime\n" ); |
136 | 472 |
} |
473 |
} |
|
474 |
} |
|
475 |
} |
|
476 |
} |
|
477 |
||
478 |
/** |
|
479 |
* Perform a HTTP HEAD or GET request. |
|
480 |
* |
|
481 |
* If $file_path is a writable filename, this will do a GET request and write |
|
482 |
* the file to that path. |
|
483 |
* |
|
484 |
* @since 2.5.0 |
|
485 |
* |
|
486 |
* @param string $url URL to fetch. |
|
487 |
* @param string|bool $file_path Optional. File path to write request to. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
488 |
* @param int $red (private) The number of Redirects followed, Upon 5 being hit, returns false. |
136 | 489 |
* @return bool|string False on failure and string of headers if HEAD request. |
490 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
491 |
function wp_get_http( $url, $file_path = false, $red = 1 ) { |
136 | 492 |
@set_time_limit( 60 ); |
493 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
494 |
if ( $red > 5 ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
495 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
496 |
|
136 | 497 |
$options = array(); |
498 |
$options['redirection'] = 5; |
|
499 |
||
500 |
if ( false == $file_path ) |
|
501 |
$options['method'] = 'HEAD'; |
|
502 |
else |
|
503 |
$options['method'] = 'GET'; |
|
504 |
||
505 |
$response = wp_remote_request($url, $options); |
|
506 |
||
507 |
if ( is_wp_error( $response ) ) |
|
508 |
return false; |
|
509 |
||
510 |
$headers = wp_remote_retrieve_headers( $response ); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
511 |
$headers['response'] = wp_remote_retrieve_response_code( $response ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
512 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
513 |
// WP_HTTP no longer follows redirects for HEAD requests. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
514 |
if ( 'HEAD' == $options['method'] && in_array($headers['response'], array(301, 302)) && isset( $headers['location'] ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
515 |
return wp_get_http( $headers['location'], $file_path, ++$red ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
516 |
} |
136 | 517 |
|
518 |
if ( false == $file_path ) |
|
519 |
return $headers; |
|
520 |
||
521 |
// GET request - write it to the supplied filename |
|
522 |
$out_fp = fopen($file_path, 'w'); |
|
523 |
if ( !$out_fp ) |
|
524 |
return $headers; |
|
525 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
526 |
fwrite( $out_fp, wp_remote_retrieve_body( $response ) ); |
136 | 527 |
fclose($out_fp); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
528 |
clearstatcache(); |
136 | 529 |
|
530 |
return $headers; |
|
531 |
} |
|
532 |
||
533 |
/** |
|
534 |
* Retrieve HTTP Headers from URL. |
|
535 |
* |
|
536 |
* @since 1.5.1 |
|
537 |
* |
|
538 |
* @param string $url |
|
539 |
* @param bool $deprecated Not Used. |
|
540 |
* @return bool|string False on failure, headers on success. |
|
541 |
*/ |
|
542 |
function wp_get_http_headers( $url, $deprecated = false ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
543 |
if ( !empty( $deprecated ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
544 |
_deprecated_argument( __FUNCTION__, '2.7' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
545 |
|
136 | 546 |
$response = wp_remote_head( $url ); |
547 |
||
548 |
if ( is_wp_error( $response ) ) |
|
549 |
return false; |
|
550 |
||
551 |
return wp_remote_retrieve_headers( $response ); |
|
552 |
} |
|
553 |
||
554 |
/** |
|
555 |
* Whether today is a new day. |
|
556 |
* |
|
557 |
* @since 0.71 |
|
558 |
* @uses $day Today |
|
559 |
* @uses $previousday Previous day |
|
560 |
* |
|
561 |
* @return int 1 when new day, 0 if not a new day. |
|
562 |
*/ |
|
563 |
function is_new_day() { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
564 |
global $currentday, $previousday; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
565 |
if ( $currentday != $previousday ) |
136 | 566 |
return 1; |
567 |
else |
|
568 |
return 0; |
|
569 |
} |
|
570 |
||
571 |
/** |
|
572 |
* Build URL query based on an associative and, or indexed array. |
|
573 |
* |
|
574 |
* This is a convenient function for easily building url queries. It sets the |
|
575 |
* separator to '&' and uses _http_build_query() function. |
|
576 |
* |
|
577 |
* @see _http_build_query() Used to build the query |
|
578 |
* @link http://us2.php.net/manual/en/function.http-build-query.php more on what |
|
579 |
* http_build_query() does. |
|
580 |
* |
|
581 |
* @since 2.3.0 |
|
582 |
* |
|
583 |
* @param array $data URL-encode key/value pairs. |
|
584 |
* @return string URL encoded string |
|
585 |
*/ |
|
586 |
function build_query( $data ) { |
|
587 |
return _http_build_query( $data, null, '&', '', false ); |
|
588 |
} |
|
589 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
590 |
// from php.net (modified by Mark Jaquith to behave like the native PHP5 function) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
591 |
function _http_build_query($data, $prefix=null, $sep=null, $key='', $urlencode=true) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
592 |
$ret = array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
593 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
594 |
foreach ( (array) $data as $k => $v ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
595 |
if ( $urlencode) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
596 |
$k = urlencode($k); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
597 |
if ( is_int($k) && $prefix != null ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
598 |
$k = $prefix.$k; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
599 |
if ( !empty($key) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
600 |
$k = $key . '%5B' . $k . '%5D'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
601 |
if ( $v === null ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
602 |
continue; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
603 |
elseif ( $v === FALSE ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
604 |
$v = '0'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
605 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
606 |
if ( is_array($v) || is_object($v) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
607 |
array_push($ret,_http_build_query($v, '', $sep, $k, $urlencode)); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
608 |
elseif ( $urlencode ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
609 |
array_push($ret, $k.'='.urlencode($v)); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
610 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
611 |
array_push($ret, $k.'='.$v); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
612 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
613 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
614 |
if ( null === $sep ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
615 |
$sep = ini_get('arg_separator.output'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
616 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
617 |
return implode($sep, $ret); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
618 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
619 |
|
136 | 620 |
/** |
621 |
* Retrieve a modified URL query string. |
|
622 |
* |
|
623 |
* You can rebuild the URL and append a new query variable to the URL query by |
|
624 |
* using this function. You can also retrieve the full URL with query data. |
|
625 |
* |
|
626 |
* Adding a single key & value or an associative array. Setting a key value to |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
627 |
* an empty string removes the key. Omitting oldquery_or_uri uses the $_SERVER |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
628 |
* value. Additional values provided are expected to be encoded appropriately |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
629 |
* with urlencode() or rawurlencode(). |
136 | 630 |
* |
631 |
* @since 1.5.0 |
|
632 |
* |
|
633 |
* @param mixed $param1 Either newkey or an associative_array |
|
634 |
* @param mixed $param2 Either newvalue or oldquery or uri |
|
635 |
* @param mixed $param3 Optional. Old query or uri |
|
636 |
* @return string New URL query string. |
|
637 |
*/ |
|
638 |
function add_query_arg() { |
|
639 |
$ret = ''; |
|
640 |
if ( is_array( func_get_arg(0) ) ) { |
|
641 |
if ( @func_num_args() < 2 || false === @func_get_arg( 1 ) ) |
|
642 |
$uri = $_SERVER['REQUEST_URI']; |
|
643 |
else |
|
644 |
$uri = @func_get_arg( 1 ); |
|
645 |
} else { |
|
646 |
if ( @func_num_args() < 3 || false === @func_get_arg( 2 ) ) |
|
647 |
$uri = $_SERVER['REQUEST_URI']; |
|
648 |
else |
|
649 |
$uri = @func_get_arg( 2 ); |
|
650 |
} |
|
651 |
||
652 |
if ( $frag = strstr( $uri, '#' ) ) |
|
653 |
$uri = substr( $uri, 0, -strlen( $frag ) ); |
|
654 |
else |
|
655 |
$frag = ''; |
|
656 |
||
657 |
if ( preg_match( '|^https?://|i', $uri, $matches ) ) { |
|
658 |
$protocol = $matches[0]; |
|
659 |
$uri = substr( $uri, strlen( $protocol ) ); |
|
660 |
} else { |
|
661 |
$protocol = ''; |
|
662 |
} |
|
663 |
||
664 |
if ( strpos( $uri, '?' ) !== false ) { |
|
665 |
$parts = explode( '?', $uri, 2 ); |
|
666 |
if ( 1 == count( $parts ) ) { |
|
667 |
$base = '?'; |
|
668 |
$query = $parts[0]; |
|
669 |
} else { |
|
670 |
$base = $parts[0] . '?'; |
|
671 |
$query = $parts[1]; |
|
672 |
} |
|
673 |
} elseif ( !empty( $protocol ) || strpos( $uri, '=' ) === false ) { |
|
674 |
$base = $uri . '?'; |
|
675 |
$query = ''; |
|
676 |
} else { |
|
677 |
$base = ''; |
|
678 |
$query = $uri; |
|
679 |
} |
|
680 |
||
681 |
wp_parse_str( $query, $qs ); |
|
682 |
$qs = urlencode_deep( $qs ); // this re-URL-encodes things that were already in the query string |
|
683 |
if ( is_array( func_get_arg( 0 ) ) ) { |
|
684 |
$kayvees = func_get_arg( 0 ); |
|
685 |
$qs = array_merge( $qs, $kayvees ); |
|
686 |
} else { |
|
687 |
$qs[func_get_arg( 0 )] = func_get_arg( 1 ); |
|
688 |
} |
|
689 |
||
690 |
foreach ( (array) $qs as $k => $v ) { |
|
691 |
if ( $v === false ) |
|
692 |
unset( $qs[$k] ); |
|
693 |
} |
|
694 |
||
695 |
$ret = build_query( $qs ); |
|
696 |
$ret = trim( $ret, '?' ); |
|
697 |
$ret = preg_replace( '#=(&|$)#', '$1', $ret ); |
|
698 |
$ret = $protocol . $base . $ret . $frag; |
|
699 |
$ret = rtrim( $ret, '?' ); |
|
700 |
return $ret; |
|
701 |
} |
|
702 |
||
703 |
/** |
|
704 |
* Removes an item or list from the query string. |
|
705 |
* |
|
706 |
* @since 1.5.0 |
|
707 |
* |
|
708 |
* @param string|array $key Query key or keys to remove. |
|
709 |
* @param bool $query When false uses the $_SERVER value. |
|
710 |
* @return string New URL query string. |
|
711 |
*/ |
|
712 |
function remove_query_arg( $key, $query=false ) { |
|
713 |
if ( is_array( $key ) ) { // removing multiple keys |
|
714 |
foreach ( $key as $k ) |
|
715 |
$query = add_query_arg( $k, false, $query ); |
|
716 |
return $query; |
|
717 |
} |
|
718 |
return add_query_arg( $key, false, $query ); |
|
719 |
} |
|
720 |
||
721 |
/** |
|
722 |
* Walks the array while sanitizing the contents. |
|
723 |
* |
|
724 |
* @since 0.71 |
|
725 |
* |
|
726 |
* @param array $array Array to used to walk while sanitizing contents. |
|
727 |
* @return array Sanitized $array. |
|
728 |
*/ |
|
729 |
function add_magic_quotes( $array ) { |
|
730 |
foreach ( (array) $array as $k => $v ) { |
|
731 |
if ( is_array( $v ) ) { |
|
732 |
$array[$k] = add_magic_quotes( $v ); |
|
733 |
} else { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
734 |
$array[$k] = addslashes( $v ); |
136 | 735 |
} |
736 |
} |
|
737 |
return $array; |
|
738 |
} |
|
739 |
||
740 |
/** |
|
741 |
* HTTP request for URI to retrieve content. |
|
742 |
* |
|
743 |
* @since 1.5.1 |
|
744 |
* @uses wp_remote_get() |
|
745 |
* |
|
746 |
* @param string $uri URI/URL of web page to retrieve. |
|
747 |
* @return bool|string HTTP content. False on failure. |
|
748 |
*/ |
|
749 |
function wp_remote_fopen( $uri ) { |
|
750 |
$parsed_url = @parse_url( $uri ); |
|
751 |
||
752 |
if ( !$parsed_url || !is_array( $parsed_url ) ) |
|
753 |
return false; |
|
754 |
||
755 |
$options = array(); |
|
756 |
$options['timeout'] = 10; |
|
757 |
||
758 |
$response = wp_remote_get( $uri, $options ); |
|
759 |
||
760 |
if ( is_wp_error( $response ) ) |
|
761 |
return false; |
|
762 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
763 |
return wp_remote_retrieve_body( $response ); |
136 | 764 |
} |
765 |
||
766 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
767 |
* Set up the WordPress query. |
136 | 768 |
* |
769 |
* @since 2.0.0 |
|
770 |
* |
|
771 |
* @param string $query_vars Default WP_Query arguments. |
|
772 |
*/ |
|
773 |
function wp( $query_vars = '' ) { |
|
774 |
global $wp, $wp_query, $wp_the_query; |
|
775 |
$wp->main( $query_vars ); |
|
776 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
777 |
if ( !isset($wp_the_query) ) |
136 | 778 |
$wp_the_query = $wp_query; |
779 |
} |
|
780 |
||
781 |
/** |
|
782 |
* Retrieve the description for the HTTP status. |
|
783 |
* |
|
784 |
* @since 2.3.0 |
|
785 |
* |
|
786 |
* @param int $code HTTP status code. |
|
787 |
* @return string Empty string if not found, or description if found. |
|
788 |
*/ |
|
789 |
function get_status_header_desc( $code ) { |
|
790 |
global $wp_header_to_desc; |
|
791 |
||
792 |
$code = absint( $code ); |
|
793 |
||
794 |
if ( !isset( $wp_header_to_desc ) ) { |
|
795 |
$wp_header_to_desc = array( |
|
796 |
100 => 'Continue', |
|
797 |
101 => 'Switching Protocols', |
|
798 |
102 => 'Processing', |
|
799 |
||
800 |
200 => 'OK', |
|
801 |
201 => 'Created', |
|
802 |
202 => 'Accepted', |
|
803 |
203 => 'Non-Authoritative Information', |
|
804 |
204 => 'No Content', |
|
805 |
205 => 'Reset Content', |
|
806 |
206 => 'Partial Content', |
|
807 |
207 => 'Multi-Status', |
|
808 |
226 => 'IM Used', |
|
809 |
||
810 |
300 => 'Multiple Choices', |
|
811 |
301 => 'Moved Permanently', |
|
812 |
302 => 'Found', |
|
813 |
303 => 'See Other', |
|
814 |
304 => 'Not Modified', |
|
815 |
305 => 'Use Proxy', |
|
816 |
306 => 'Reserved', |
|
817 |
307 => 'Temporary Redirect', |
|
818 |
||
819 |
400 => 'Bad Request', |
|
820 |
401 => 'Unauthorized', |
|
821 |
402 => 'Payment Required', |
|
822 |
403 => 'Forbidden', |
|
823 |
404 => 'Not Found', |
|
824 |
405 => 'Method Not Allowed', |
|
825 |
406 => 'Not Acceptable', |
|
826 |
407 => 'Proxy Authentication Required', |
|
827 |
408 => 'Request Timeout', |
|
828 |
409 => 'Conflict', |
|
829 |
410 => 'Gone', |
|
830 |
411 => 'Length Required', |
|
831 |
412 => 'Precondition Failed', |
|
832 |
413 => 'Request Entity Too Large', |
|
833 |
414 => 'Request-URI Too Long', |
|
834 |
415 => 'Unsupported Media Type', |
|
835 |
416 => 'Requested Range Not Satisfiable', |
|
836 |
417 => 'Expectation Failed', |
|
837 |
422 => 'Unprocessable Entity', |
|
838 |
423 => 'Locked', |
|
839 |
424 => 'Failed Dependency', |
|
840 |
426 => 'Upgrade Required', |
|
841 |
||
842 |
500 => 'Internal Server Error', |
|
843 |
501 => 'Not Implemented', |
|
844 |
502 => 'Bad Gateway', |
|
845 |
503 => 'Service Unavailable', |
|
846 |
504 => 'Gateway Timeout', |
|
847 |
505 => 'HTTP Version Not Supported', |
|
848 |
506 => 'Variant Also Negotiates', |
|
849 |
507 => 'Insufficient Storage', |
|
850 |
510 => 'Not Extended' |
|
851 |
); |
|
852 |
} |
|
853 |
||
854 |
if ( isset( $wp_header_to_desc[$code] ) ) |
|
855 |
return $wp_header_to_desc[$code]; |
|
856 |
else |
|
857 |
return ''; |
|
858 |
} |
|
859 |
||
860 |
/** |
|
861 |
* Set HTTP status header. |
|
862 |
* |
|
863 |
* @since 2.0.0 |
|
864 |
* @uses apply_filters() Calls 'status_header' on status header string, HTTP |
|
865 |
* HTTP code, HTTP code description, and protocol string as separate |
|
866 |
* parameters. |
|
867 |
* |
|
868 |
* @param int $header HTTP status code |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
869 |
* @return unknown |
136 | 870 |
*/ |
871 |
function status_header( $header ) { |
|
872 |
$text = get_status_header_desc( $header ); |
|
873 |
||
874 |
if ( empty( $text ) ) |
|
875 |
return false; |
|
876 |
||
877 |
$protocol = $_SERVER["SERVER_PROTOCOL"]; |
|
878 |
if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol ) |
|
879 |
$protocol = 'HTTP/1.0'; |
|
880 |
$status_header = "$protocol $header $text"; |
|
881 |
if ( function_exists( 'apply_filters' ) ) |
|
882 |
$status_header = apply_filters( 'status_header', $status_header, $header, $text, $protocol ); |
|
883 |
||
884 |
return @header( $status_header, true, $header ); |
|
885 |
} |
|
886 |
||
887 |
/** |
|
888 |
* Gets the header information to prevent caching. |
|
889 |
* |
|
890 |
* The several different headers cover the different ways cache prevention is handled |
|
891 |
* by different browsers |
|
892 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
893 |
* @since 2.8.0 |
136 | 894 |
* |
895 |
* @uses apply_filters() |
|
896 |
* @return array The associative array of header names and field values. |
|
897 |
*/ |
|
898 |
function wp_get_nocache_headers() { |
|
899 |
$headers = array( |
|
900 |
'Expires' => 'Wed, 11 Jan 1984 05:00:00 GMT', |
|
901 |
'Last-Modified' => gmdate( 'D, d M Y H:i:s' ) . ' GMT', |
|
902 |
'Cache-Control' => 'no-cache, must-revalidate, max-age=0', |
|
903 |
'Pragma' => 'no-cache', |
|
904 |
); |
|
905 |
||
906 |
if ( function_exists('apply_filters') ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
907 |
$headers = (array) apply_filters('nocache_headers', $headers); |
136 | 908 |
} |
909 |
return $headers; |
|
910 |
} |
|
911 |
||
912 |
/** |
|
913 |
* Sets the headers to prevent caching for the different browsers. |
|
914 |
* |
|
915 |
* Different browsers support different nocache headers, so several headers must |
|
916 |
* be sent so that all of them get the point that no caching should occur. |
|
917 |
* |
|
918 |
* @since 2.0.0 |
|
919 |
* @uses wp_get_nocache_headers() |
|
920 |
*/ |
|
921 |
function nocache_headers() { |
|
922 |
$headers = wp_get_nocache_headers(); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
923 |
foreach( $headers as $name => $field_value ) |
136 | 924 |
@header("{$name}: {$field_value}"); |
925 |
} |
|
926 |
||
927 |
/** |
|
928 |
* Set the headers for caching for 10 days with JavaScript content type. |
|
929 |
* |
|
930 |
* @since 2.1.0 |
|
931 |
*/ |
|
932 |
function cache_javascript_headers() { |
|
933 |
$expiresOffset = 864000; // 10 days |
|
934 |
header( "Content-Type: text/javascript; charset=" . get_bloginfo( 'charset' ) ); |
|
935 |
header( "Vary: Accept-Encoding" ); // Handle proxies |
|
936 |
header( "Expires: " . gmdate( "D, d M Y H:i:s", time() + $expiresOffset ) . " GMT" ); |
|
937 |
} |
|
938 |
||
939 |
/** |
|
940 |
* Retrieve the number of database queries during the WordPress execution. |
|
941 |
* |
|
942 |
* @since 2.0.0 |
|
943 |
* |
|
944 |
* @return int Number of database queries |
|
945 |
*/ |
|
946 |
function get_num_queries() { |
|
947 |
global $wpdb; |
|
948 |
return $wpdb->num_queries; |
|
949 |
} |
|
950 |
||
951 |
/** |
|
952 |
* Whether input is yes or no. Must be 'y' to be true. |
|
953 |
* |
|
954 |
* @since 1.0.0 |
|
955 |
* |
|
956 |
* @param string $yn Character string containing either 'y' or 'n' |
|
957 |
* @return bool True if yes, false on anything else |
|
958 |
*/ |
|
959 |
function bool_from_yn( $yn ) { |
|
960 |
return ( strtolower( $yn ) == 'y' ); |
|
961 |
} |
|
962 |
||
963 |
/** |
|
964 |
* Loads the feed template from the use of an action hook. |
|
965 |
* |
|
966 |
* If the feed action does not have a hook, then the function will die with a |
|
967 |
* message telling the visitor that the feed is not valid. |
|
968 |
* |
|
969 |
* It is better to only have one hook for each feed. |
|
970 |
* |
|
971 |
* @since 2.1.0 |
|
972 |
* @uses $wp_query Used to tell if the use a comment feed. |
|
973 |
* @uses do_action() Calls 'do_feed_$feed' hook, if a hook exists for the feed. |
|
974 |
*/ |
|
975 |
function do_feed() { |
|
976 |
global $wp_query; |
|
977 |
||
978 |
$feed = get_query_var( 'feed' ); |
|
979 |
||
980 |
// Remove the pad, if present. |
|
981 |
$feed = preg_replace( '/^_+/', '', $feed ); |
|
982 |
||
983 |
if ( $feed == '' || $feed == 'feed' ) |
|
984 |
$feed = get_default_feed(); |
|
985 |
||
986 |
$hook = 'do_feed_' . $feed; |
|
987 |
if ( !has_action($hook) ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
988 |
$message = sprintf( __( 'ERROR: %s is not a valid feed template.' ), esc_html($feed)); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
989 |
wp_die( $message, '', array( 'response' => 404 ) ); |
136 | 990 |
} |
991 |
||
992 |
do_action( $hook, $wp_query->is_comment_feed ); |
|
993 |
} |
|
994 |
||
995 |
/** |
|
996 |
* Load the RDF RSS 0.91 Feed template. |
|
997 |
* |
|
998 |
* @since 2.1.0 |
|
999 |
*/ |
|
1000 |
function do_feed_rdf() { |
|
1001 |
load_template( ABSPATH . WPINC . '/feed-rdf.php' ); |
|
1002 |
} |
|
1003 |
||
1004 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1005 |
* Load the RSS 1.0 Feed Template. |
136 | 1006 |
* |
1007 |
* @since 2.1.0 |
|
1008 |
*/ |
|
1009 |
function do_feed_rss() { |
|
1010 |
load_template( ABSPATH . WPINC . '/feed-rss.php' ); |
|
1011 |
} |
|
1012 |
||
1013 |
/** |
|
1014 |
* Load either the RSS2 comment feed or the RSS2 posts feed. |
|
1015 |
* |
|
1016 |
* @since 2.1.0 |
|
1017 |
* |
|
1018 |
* @param bool $for_comments True for the comment feed, false for normal feed. |
|
1019 |
*/ |
|
1020 |
function do_feed_rss2( $for_comments ) { |
|
1021 |
if ( $for_comments ) |
|
1022 |
load_template( ABSPATH . WPINC . '/feed-rss2-comments.php' ); |
|
1023 |
else |
|
1024 |
load_template( ABSPATH . WPINC . '/feed-rss2.php' ); |
|
1025 |
} |
|
1026 |
||
1027 |
/** |
|
1028 |
* Load either Atom comment feed or Atom posts feed. |
|
1029 |
* |
|
1030 |
* @since 2.1.0 |
|
1031 |
* |
|
1032 |
* @param bool $for_comments True for the comment feed, false for normal feed. |
|
1033 |
*/ |
|
1034 |
function do_feed_atom( $for_comments ) { |
|
1035 |
if ($for_comments) |
|
1036 |
load_template( ABSPATH . WPINC . '/feed-atom-comments.php'); |
|
1037 |
else |
|
1038 |
load_template( ABSPATH . WPINC . '/feed-atom.php' ); |
|
1039 |
} |
|
1040 |
||
1041 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1042 |
* Display the robots.txt file content. |
136 | 1043 |
* |
1044 |
* The echo content should be with usage of the permalinks or for creating the |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1045 |
* robots.txt file. |
136 | 1046 |
* |
1047 |
* @since 2.1.0 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1048 |
* @uses do_action() Calls 'do_robotstxt' hook for displaying robots.txt rules. |
136 | 1049 |
*/ |
1050 |
function do_robots() { |
|
1051 |
header( 'Content-Type: text/plain; charset=utf-8' ); |
|
1052 |
||
1053 |
do_action( 'do_robotstxt' ); |
|
1054 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1055 |
$output = "User-agent: *\n"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1056 |
$public = get_option( 'blog_public' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1057 |
if ( '0' == $public ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1058 |
$output .= "Disallow: /\n"; |
136 | 1059 |
} else { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1060 |
$site_url = parse_url( site_url() ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1061 |
$path = ( !empty( $site_url['path'] ) ) ? $site_url['path'] : ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1062 |
$output .= "Disallow: $path/wp-admin/\n"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1063 |
$output .= "Disallow: $path/wp-includes/\n"; |
136 | 1064 |
} |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1065 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1066 |
echo apply_filters('robots_txt', $output, $public); |
136 | 1067 |
} |
1068 |
||
1069 |
/** |
|
1070 |
* Test whether blog is already installed. |
|
1071 |
* |
|
1072 |
* The cache will be checked first. If you have a cache plugin, which saves the |
|
1073 |
* cache values, then this will work. If you use the default WordPress cache, |
|
1074 |
* and the database goes away, then you might have problems. |
|
1075 |
* |
|
1076 |
* Checks for the option siteurl for whether WordPress is installed. |
|
1077 |
* |
|
1078 |
* @since 2.1.0 |
|
1079 |
* @uses $wpdb |
|
1080 |
* |
|
1081 |
* @return bool Whether blog is already installed. |
|
1082 |
*/ |
|
1083 |
function is_blog_installed() { |
|
1084 |
global $wpdb; |
|
1085 |
||
1086 |
// Check cache first. If options table goes away and we have true cached, oh well. |
|
1087 |
if ( wp_cache_get( 'is_blog_installed' ) ) |
|
1088 |
return true; |
|
1089 |
||
1090 |
$suppress = $wpdb->suppress_errors(); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1091 |
if ( ! defined( 'WP_INSTALLING' ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1092 |
$alloptions = wp_load_alloptions(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1093 |
} |
136 | 1094 |
// If siteurl is not set to autoload, check it specifically |
1095 |
if ( !isset( $alloptions['siteurl'] ) ) |
|
1096 |
$installed = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'" ); |
|
1097 |
else |
|
1098 |
$installed = $alloptions['siteurl']; |
|
1099 |
$wpdb->suppress_errors( $suppress ); |
|
1100 |
||
1101 |
$installed = !empty( $installed ); |
|
1102 |
wp_cache_set( 'is_blog_installed', $installed ); |
|
1103 |
||
1104 |
if ( $installed ) |
|
1105 |
return true; |
|
1106 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1107 |
// If visiting repair.php, return true and let it take over. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1108 |
if ( defined( 'WP_REPAIRING' ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1109 |
return true; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1110 |
|
136 | 1111 |
$suppress = $wpdb->suppress_errors(); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1112 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1113 |
// Loop over the WP tables. If none exist, then scratch install is allowed. |
136 | 1114 |
// If one or more exist, suggest table repair since we got here because the options |
1115 |
// table could not be accessed. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1116 |
$wp_tables = $wpdb->tables(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1117 |
foreach ( $wp_tables as $table ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1118 |
// The existence of custom user tables shouldn't suggest an insane state or prevent a clean install. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1119 |
if ( defined( 'CUSTOM_USER_TABLE' ) && CUSTOM_USER_TABLE == $table ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1120 |
continue; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1121 |
if ( defined( 'CUSTOM_USER_META_TABLE' ) && CUSTOM_USER_META_TABLE == $table ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1122 |
continue; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1123 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1124 |
if ( ! $wpdb->get_results( "DESCRIBE $table;" ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1125 |
continue; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1126 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1127 |
// One or more tables exist. We are insane. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1128 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1129 |
wp_load_translations_early(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1130 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1131 |
// Die with a DB error. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1132 |
$wpdb->error = sprintf( __( 'One or more database tables are unavailable. The database may need to be <a href="%s">repaired</a>.' ), 'maint/repair.php?referrer=is_blog_installed' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1133 |
dead_db(); |
136 | 1134 |
} |
1135 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1136 |
$wpdb->suppress_errors( $suppress ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1137 |
|
136 | 1138 |
wp_cache_set( 'is_blog_installed', false ); |
1139 |
||
1140 |
return false; |
|
1141 |
} |
|
1142 |
||
1143 |
/** |
|
1144 |
* Retrieve URL with nonce added to URL query. |
|
1145 |
* |
|
1146 |
* @package WordPress |
|
1147 |
* @subpackage Security |
|
1148 |
* @since 2.0.4 |
|
1149 |
* |
|
1150 |
* @param string $actionurl URL to add nonce action |
|
1151 |
* @param string $action Optional. Nonce action name |
|
1152 |
* @return string URL with nonce action added. |
|
1153 |
*/ |
|
1154 |
function wp_nonce_url( $actionurl, $action = -1 ) { |
|
1155 |
$actionurl = str_replace( '&', '&', $actionurl ); |
|
1156 |
return esc_html( add_query_arg( '_wpnonce', wp_create_nonce( $action ), $actionurl ) ); |
|
1157 |
} |
|
1158 |
||
1159 |
/** |
|
1160 |
* Retrieve or display nonce hidden field for forms. |
|
1161 |
* |
|
1162 |
* The nonce field is used to validate that the contents of the form came from |
|
1163 |
* the location on the current site and not somewhere else. The nonce does not |
|
1164 |
* offer absolute protection, but should protect against most cases. It is very |
|
1165 |
* important to use nonce field in forms. |
|
1166 |
* |
|
1167 |
* The $action and $name are optional, but if you want to have better security, |
|
1168 |
* it is strongly suggested to set those two parameters. It is easier to just |
|
1169 |
* call the function without any parameters, because validation of the nonce |
|
1170 |
* doesn't require any parameters, but since crackers know what the default is |
|
1171 |
* it won't be difficult for them to find a way around your nonce and cause |
|
1172 |
* damage. |
|
1173 |
* |
|
1174 |
* The input name will be whatever $name value you gave. The input value will be |
|
1175 |
* the nonce creation value. |
|
1176 |
* |
|
1177 |
* @package WordPress |
|
1178 |
* @subpackage Security |
|
1179 |
* @since 2.0.4 |
|
1180 |
* |
|
1181 |
* @param string $action Optional. Action name. |
|
1182 |
* @param string $name Optional. Nonce name. |
|
1183 |
* @param bool $referer Optional, default true. Whether to set the referer field for validation. |
|
1184 |
* @param bool $echo Optional, default true. Whether to display or return hidden form field. |
|
1185 |
* @return string Nonce field. |
|
1186 |
*/ |
|
1187 |
function wp_nonce_field( $action = -1, $name = "_wpnonce", $referer = true , $echo = true ) { |
|
1188 |
$name = esc_attr( $name ); |
|
1189 |
$nonce_field = '<input type="hidden" id="' . $name . '" name="' . $name . '" value="' . wp_create_nonce( $action ) . '" />'; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1190 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1191 |
if ( $referer ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1192 |
$nonce_field .= wp_referer_field( false ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1193 |
|
136 | 1194 |
if ( $echo ) |
1195 |
echo $nonce_field; |
|
1196 |
||
1197 |
return $nonce_field; |
|
1198 |
} |
|
1199 |
||
1200 |
/** |
|
1201 |
* Retrieve or display referer hidden field for forms. |
|
1202 |
* |
|
1203 |
* The referer link is the current Request URI from the server super global. The |
|
1204 |
* input name is '_wp_http_referer', in case you wanted to check manually. |
|
1205 |
* |
|
1206 |
* @package WordPress |
|
1207 |
* @subpackage Security |
|
1208 |
* @since 2.0.4 |
|
1209 |
* |
|
1210 |
* @param bool $echo Whether to echo or return the referer field. |
|
1211 |
* @return string Referer field. |
|
1212 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1213 |
function wp_referer_field( $echo = true ) { |
136 | 1214 |
$ref = esc_attr( $_SERVER['REQUEST_URI'] ); |
1215 |
$referer_field = '<input type="hidden" name="_wp_http_referer" value="'. $ref . '" />'; |
|
1216 |
||
1217 |
if ( $echo ) |
|
1218 |
echo $referer_field; |
|
1219 |
return $referer_field; |
|
1220 |
} |
|
1221 |
||
1222 |
/** |
|
1223 |
* Retrieve or display original referer hidden field for forms. |
|
1224 |
* |
|
1225 |
* The input name is '_wp_original_http_referer' and will be either the same |
|
1226 |
* value of {@link wp_referer_field()}, if that was posted already or it will |
|
1227 |
* be the current page, if it doesn't exist. |
|
1228 |
* |
|
1229 |
* @package WordPress |
|
1230 |
* @subpackage Security |
|
1231 |
* @since 2.0.4 |
|
1232 |
* |
|
1233 |
* @param bool $echo Whether to echo the original http referer |
|
1234 |
* @param string $jump_back_to Optional, default is 'current'. Can be 'previous' or page you want to jump back to. |
|
1235 |
* @return string Original referer field. |
|
1236 |
*/ |
|
1237 |
function wp_original_referer_field( $echo = true, $jump_back_to = 'current' ) { |
|
1238 |
$jump_back_to = ( 'previous' == $jump_back_to ) ? wp_get_referer() : $_SERVER['REQUEST_URI']; |
|
1239 |
$ref = ( wp_get_original_referer() ) ? wp_get_original_referer() : $jump_back_to; |
|
1240 |
$orig_referer_field = '<input type="hidden" name="_wp_original_http_referer" value="' . esc_attr( stripslashes( $ref ) ) . '" />'; |
|
1241 |
if ( $echo ) |
|
1242 |
echo $orig_referer_field; |
|
1243 |
return $orig_referer_field; |
|
1244 |
} |
|
1245 |
||
1246 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1247 |
* Retrieve referer from '_wp_http_referer' or HTTP referer. If it's the same |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1248 |
* as the current request URL, will return false. |
136 | 1249 |
* |
1250 |
* @package WordPress |
|
1251 |
* @subpackage Security |
|
1252 |
* @since 2.0.4 |
|
1253 |
* |
|
1254 |
* @return string|bool False on failure. Referer URL on success. |
|
1255 |
*/ |
|
1256 |
function wp_get_referer() { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1257 |
$ref = false; |
136 | 1258 |
if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) |
1259 |
$ref = $_REQUEST['_wp_http_referer']; |
|
1260 |
else if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) |
|
1261 |
$ref = $_SERVER['HTTP_REFERER']; |
|
1262 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1263 |
if ( $ref && $ref !== $_SERVER['REQUEST_URI'] ) |
136 | 1264 |
return $ref; |
1265 |
return false; |
|
1266 |
} |
|
1267 |
||
1268 |
/** |
|
1269 |
* Retrieve original referer that was posted, if it exists. |
|
1270 |
* |
|
1271 |
* @package WordPress |
|
1272 |
* @subpackage Security |
|
1273 |
* @since 2.0.4 |
|
1274 |
* |
|
1275 |
* @return string|bool False if no original referer or original referer if set. |
|
1276 |
*/ |
|
1277 |
function wp_get_original_referer() { |
|
1278 |
if ( !empty( $_REQUEST['_wp_original_http_referer'] ) ) |
|
1279 |
return $_REQUEST['_wp_original_http_referer']; |
|
1280 |
return false; |
|
1281 |
} |
|
1282 |
||
1283 |
/** |
|
1284 |
* Recursive directory creation based on full path. |
|
1285 |
* |
|
1286 |
* Will attempt to set permissions on folders. |
|
1287 |
* |
|
1288 |
* @since 2.0.1 |
|
1289 |
* |
|
1290 |
* @param string $target Full path to attempt to create. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1291 |
* @return bool Whether the path was created. True if path already exists. |
136 | 1292 |
*/ |
1293 |
function wp_mkdir_p( $target ) { |
|
1294 |
// from php.net/mkdir user contributed notes |
|
1295 |
$target = str_replace( '//', '/', $target ); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1296 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1297 |
// safe mode fails with a trailing slash under certain PHP versions. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1298 |
$target = rtrim($target, '/'); // Use rtrim() instead of untrailingslashit to avoid formatting.php dependency. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1299 |
if ( empty($target) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1300 |
$target = '/'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1301 |
|
136 | 1302 |
if ( file_exists( $target ) ) |
1303 |
return @is_dir( $target ); |
|
1304 |
||
1305 |
// Attempting to create the directory may clutter up our display. |
|
1306 |
if ( @mkdir( $target ) ) { |
|
1307 |
$stat = @stat( dirname( $target ) ); |
|
1308 |
$dir_perms = $stat['mode'] & 0007777; // Get the permission bits. |
|
1309 |
@chmod( $target, $dir_perms ); |
|
1310 |
return true; |
|
1311 |
} elseif ( is_dir( dirname( $target ) ) ) { |
|
1312 |
return false; |
|
1313 |
} |
|
1314 |
||
1315 |
// If the above failed, attempt to create the parent node, then try again. |
|
1316 |
if ( ( $target != '/' ) && ( wp_mkdir_p( dirname( $target ) ) ) ) |
|
1317 |
return wp_mkdir_p( $target ); |
|
1318 |
||
1319 |
return false; |
|
1320 |
} |
|
1321 |
||
1322 |
/** |
|
1323 |
* Test if a give filesystem path is absolute ('/foo/bar', 'c:\windows'). |
|
1324 |
* |
|
1325 |
* @since 2.5.0 |
|
1326 |
* |
|
1327 |
* @param string $path File path |
|
1328 |
* @return bool True if path is absolute, false is not absolute. |
|
1329 |
*/ |
|
1330 |
function path_is_absolute( $path ) { |
|
1331 |
// this is definitive if true but fails if $path does not exist or contains a symbolic link |
|
1332 |
if ( realpath($path) == $path ) |
|
1333 |
return true; |
|
1334 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1335 |
if ( strlen($path) == 0 || $path[0] == '.' ) |
136 | 1336 |
return false; |
1337 |
||
1338 |
// windows allows absolute paths like this |
|
1339 |
if ( preg_match('#^[a-zA-Z]:\\\\#', $path) ) |
|
1340 |
return true; |
|
1341 |
||
1342 |
// a path starting with / or \ is absolute; anything else is relative |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1343 |
return ( $path[0] == '/' || $path[0] == '\\' ); |
136 | 1344 |
} |
1345 |
||
1346 |
/** |
|
1347 |
* Join two filesystem paths together (e.g. 'give me $path relative to $base'). |
|
1348 |
* |
|
1349 |
* If the $path is absolute, then it the full path is returned. |
|
1350 |
* |
|
1351 |
* @since 2.5.0 |
|
1352 |
* |
|
1353 |
* @param string $base |
|
1354 |
* @param string $path |
|
1355 |
* @return string The path with the base or absolute path. |
|
1356 |
*/ |
|
1357 |
function path_join( $base, $path ) { |
|
1358 |
if ( path_is_absolute($path) ) |
|
1359 |
return $path; |
|
1360 |
||
1361 |
return rtrim($base, '/') . '/' . ltrim($path, '/'); |
|
1362 |
} |
|
1363 |
||
1364 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1365 |
* Determines a writable directory for temporary files. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1366 |
* Function's preference is to WP_CONTENT_DIR followed by the return value of <code>sys_get_temp_dir()</code>, before finally defaulting to /tmp/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1367 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1368 |
* In the event that this function does not find a writable location, It may be overridden by the <code>WP_TEMP_DIR</code> constant in your <code>wp-config.php</code> file. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1369 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1370 |
* @since 2.5.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1371 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1372 |
* @return string Writable temporary directory |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1373 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1374 |
function get_temp_dir() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1375 |
static $temp; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1376 |
if ( defined('WP_TEMP_DIR') ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1377 |
return trailingslashit(WP_TEMP_DIR); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1378 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1379 |
if ( $temp ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1380 |
return trailingslashit($temp); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1381 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1382 |
$temp = WP_CONTENT_DIR . '/'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1383 |
if ( is_dir($temp) && @is_writable($temp) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1384 |
return $temp; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1385 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1386 |
if ( function_exists('sys_get_temp_dir') ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1387 |
$temp = sys_get_temp_dir(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1388 |
if ( @is_writable($temp) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1389 |
return trailingslashit($temp); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1390 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1391 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1392 |
$temp = ini_get('upload_tmp_dir'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1393 |
if ( is_dir($temp) && @is_writable($temp) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1394 |
return trailingslashit($temp); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1395 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1396 |
$temp = '/tmp/'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1397 |
return $temp; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1398 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1399 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1400 |
/** |
136 | 1401 |
* Get an array containing the current upload directory's path and url. |
1402 |
* |
|
1403 |
* Checks the 'upload_path' option, which should be from the web root folder, |
|
1404 |
* and if it isn't empty it will be used. If it is empty, then the path will be |
|
1405 |
* 'WP_CONTENT_DIR/uploads'. If the 'UPLOADS' constant is defined, then it will |
|
1406 |
* override the 'upload_path' option and 'WP_CONTENT_DIR/uploads' path. |
|
1407 |
* |
|
1408 |
* The upload URL path is set either by the 'upload_url_path' option or by using |
|
1409 |
* the 'WP_CONTENT_URL' constant and appending '/uploads' to the path. |
|
1410 |
* |
|
1411 |
* If the 'uploads_use_yearmonth_folders' is set to true (checkbox if checked in |
|
1412 |
* the administration settings panel), then the time will be used. The format |
|
1413 |
* will be year first and then month. |
|
1414 |
* |
|
1415 |
* If the path couldn't be created, then an error will be returned with the key |
|
1416 |
* 'error' containing the error message. The error suggests that the parent |
|
1417 |
* directory is not writable by the server. |
|
1418 |
* |
|
1419 |
* On success, the returned array will have many indices: |
|
1420 |
* 'path' - base directory and sub directory or full path to upload directory. |
|
1421 |
* 'url' - base url and sub directory or absolute URL to upload directory. |
|
1422 |
* 'subdir' - sub directory if uploads use year/month folders option is on. |
|
1423 |
* 'basedir' - path without subdir. |
|
1424 |
* 'baseurl' - URL path without subdir. |
|
1425 |
* 'error' - set to false. |
|
1426 |
* |
|
1427 |
* @since 2.0.0 |
|
1428 |
* @uses apply_filters() Calls 'upload_dir' on returned array. |
|
1429 |
* |
|
1430 |
* @param string $time Optional. Time formatted in 'yyyy/mm'. |
|
1431 |
* @return array See above for description. |
|
1432 |
*/ |
|
1433 |
function wp_upload_dir( $time = null ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1434 |
global $switched; |
136 | 1435 |
$siteurl = get_option( 'siteurl' ); |
1436 |
$upload_path = get_option( 'upload_path' ); |
|
1437 |
$upload_path = trim($upload_path); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1438 |
$main_override = is_multisite() && defined( 'MULTISITE' ) && is_main_site(); |
136 | 1439 |
if ( empty($upload_path) ) { |
1440 |
$dir = WP_CONTENT_DIR . '/uploads'; |
|
1441 |
} else { |
|
1442 |
$dir = $upload_path; |
|
1443 |
if ( 'wp-content/uploads' == $upload_path ) { |
|
1444 |
$dir = WP_CONTENT_DIR . '/uploads'; |
|
1445 |
} elseif ( 0 !== strpos($dir, ABSPATH) ) { |
|
1446 |
// $dir is absolute, $upload_path is (maybe) relative to ABSPATH |
|
1447 |
$dir = path_join( ABSPATH, $dir ); |
|
1448 |
} |
|
1449 |
} |
|
1450 |
||
1451 |
if ( !$url = get_option( 'upload_url_path' ) ) { |
|
1452 |
if ( empty($upload_path) || ( 'wp-content/uploads' == $upload_path ) || ( $upload_path == $dir ) ) |
|
1453 |
$url = WP_CONTENT_URL . '/uploads'; |
|
1454 |
else |
|
1455 |
$url = trailingslashit( $siteurl ) . $upload_path; |
|
1456 |
} |
|
1457 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1458 |
if ( defined('UPLOADS') && !$main_override && ( !isset( $switched ) || $switched === false ) ) { |
136 | 1459 |
$dir = ABSPATH . UPLOADS; |
1460 |
$url = trailingslashit( $siteurl ) . UPLOADS; |
|
1461 |
} |
|
1462 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1463 |
if ( is_multisite() && !$main_override && ( !isset( $switched ) || $switched === false ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1464 |
if ( defined( 'BLOGUPLOADDIR' ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1465 |
$dir = untrailingslashit(BLOGUPLOADDIR); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1466 |
$url = str_replace( UPLOADS, 'files', $url ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1467 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1468 |
|
136 | 1469 |
$bdir = $dir; |
1470 |
$burl = $url; |
|
1471 |
||
1472 |
$subdir = ''; |
|
1473 |
if ( get_option( 'uploads_use_yearmonth_folders' ) ) { |
|
1474 |
// Generate the yearly and monthly dirs |
|
1475 |
if ( !$time ) |
|
1476 |
$time = current_time( 'mysql' ); |
|
1477 |
$y = substr( $time, 0, 4 ); |
|
1478 |
$m = substr( $time, 5, 2 ); |
|
1479 |
$subdir = "/$y/$m"; |
|
1480 |
} |
|
1481 |
||
1482 |
$dir .= $subdir; |
|
1483 |
$url .= $subdir; |
|
1484 |
||
1485 |
$uploads = apply_filters( 'upload_dir', array( 'path' => $dir, 'url' => $url, 'subdir' => $subdir, 'basedir' => $bdir, 'baseurl' => $burl, 'error' => false ) ); |
|
1486 |
||
1487 |
// Make sure we have an uploads dir |
|
1488 |
if ( ! wp_mkdir_p( $uploads['path'] ) ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1489 |
if ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1490 |
$error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1491 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1492 |
$error_path = basename( $uploads['basedir'] ) . $uploads['subdir']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1493 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1494 |
$message = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), $error_path ); |
136 | 1495 |
return array( 'error' => $message ); |
1496 |
} |
|
1497 |
||
1498 |
return $uploads; |
|
1499 |
} |
|
1500 |
||
1501 |
/** |
|
1502 |
* Get a filename that is sanitized and unique for the given directory. |
|
1503 |
* |
|
1504 |
* If the filename is not unique, then a number will be added to the filename |
|
1505 |
* before the extension, and will continue adding numbers until the filename is |
|
1506 |
* unique. |
|
1507 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1508 |
* The callback is passed three parameters, the first one is the directory, the |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1509 |
* second is the filename, and the third is the extension. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1510 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1511 |
* @since 2.5.0 |
136 | 1512 |
* |
1513 |
* @param string $dir |
|
1514 |
* @param string $filename |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1515 |
* @param mixed $unique_filename_callback Callback. |
136 | 1516 |
* @return string New filename, if given wasn't unique. |
1517 |
*/ |
|
1518 |
function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) { |
|
1519 |
// sanitize the file name before we begin processing |
|
1520 |
$filename = sanitize_file_name($filename); |
|
1521 |
||
1522 |
// separate the filename into a name and extension |
|
1523 |
$info = pathinfo($filename); |
|
1524 |
$ext = !empty($info['extension']) ? '.' . $info['extension'] : ''; |
|
1525 |
$name = basename($filename, $ext); |
|
1526 |
||
1527 |
// edge case: if file is named '.ext', treat as an empty name |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1528 |
if ( $name === $ext ) |
136 | 1529 |
$name = ''; |
1530 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1531 |
// Increment the file number until we have a unique file to save in $dir. Use callback if supplied. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1532 |
if ( $unique_filename_callback && is_callable( $unique_filename_callback ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1533 |
$filename = call_user_func( $unique_filename_callback, $dir, $name, $ext ); |
136 | 1534 |
} else { |
1535 |
$number = ''; |
|
1536 |
||
1537 |
// change '.ext' to lower case |
|
1538 |
if ( $ext && strtolower($ext) != $ext ) { |
|
1539 |
$ext2 = strtolower($ext); |
|
1540 |
$filename2 = preg_replace( '|' . preg_quote($ext) . '$|', $ext2, $filename ); |
|
1541 |
||
1542 |
// check for both lower and upper case extension or image sub-sizes may be overwritten |
|
1543 |
while ( file_exists($dir . "/$filename") || file_exists($dir . "/$filename2") ) { |
|
1544 |
$new_number = $number + 1; |
|
1545 |
$filename = str_replace( "$number$ext", "$new_number$ext", $filename ); |
|
1546 |
$filename2 = str_replace( "$number$ext2", "$new_number$ext2", $filename2 ); |
|
1547 |
$number = $new_number; |
|
1548 |
} |
|
1549 |
return $filename2; |
|
1550 |
} |
|
1551 |
||
1552 |
while ( file_exists( $dir . "/$filename" ) ) { |
|
1553 |
if ( '' == "$number$ext" ) |
|
1554 |
$filename = $filename . ++$number . $ext; |
|
1555 |
else |
|
1556 |
$filename = str_replace( "$number$ext", ++$number . $ext, $filename ); |
|
1557 |
} |
|
1558 |
} |
|
1559 |
||
1560 |
return $filename; |
|
1561 |
} |
|
1562 |
||
1563 |
/** |
|
1564 |
* Create a file in the upload folder with given content. |
|
1565 |
* |
|
1566 |
* If there is an error, then the key 'error' will exist with the error message. |
|
1567 |
* If success, then the key 'file' will have the unique file path, the 'url' key |
|
1568 |
* will have the link to the new file. and the 'error' key will be set to false. |
|
1569 |
* |
|
1570 |
* This function will not move an uploaded file to the upload folder. It will |
|
1571 |
* create a new file with the content in $bits parameter. If you move the upload |
|
1572 |
* file, read the content of the uploaded file, and then you can give the |
|
1573 |
* filename and content to this function, which will add it to the upload |
|
1574 |
* folder. |
|
1575 |
* |
|
1576 |
* The permissions will be set on the new file automatically by this function. |
|
1577 |
* |
|
1578 |
* @since 2.0.0 |
|
1579 |
* |
|
1580 |
* @param string $name |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1581 |
* @param null $deprecated Never used. Set to null. |
136 | 1582 |
* @param mixed $bits File content |
1583 |
* @param string $time Optional. Time formatted in 'yyyy/mm'. |
|
1584 |
* @return array |
|
1585 |
*/ |
|
1586 |
function wp_upload_bits( $name, $deprecated, $bits, $time = null ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1587 |
if ( !empty( $deprecated ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1588 |
_deprecated_argument( __FUNCTION__, '2.0' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1589 |
|
136 | 1590 |
if ( empty( $name ) ) |
1591 |
return array( 'error' => __( 'Empty filename' ) ); |
|
1592 |
||
1593 |
$wp_filetype = wp_check_filetype( $name ); |
|
1594 |
if ( !$wp_filetype['ext'] ) |
|
1595 |
return array( 'error' => __( 'Invalid file type' ) ); |
|
1596 |
||
1597 |
$upload = wp_upload_dir( $time ); |
|
1598 |
||
1599 |
if ( $upload['error'] !== false ) |
|
1600 |
return $upload; |
|
1601 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1602 |
$upload_bits_error = apply_filters( 'wp_upload_bits', array( 'name' => $name, 'bits' => $bits, 'time' => $time ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1603 |
if ( !is_array( $upload_bits_error ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1604 |
$upload[ 'error' ] = $upload_bits_error; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1605 |
return $upload; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1606 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1607 |
|
136 | 1608 |
$filename = wp_unique_filename( $upload['path'], $name ); |
1609 |
||
1610 |
$new_file = $upload['path'] . "/$filename"; |
|
1611 |
if ( ! wp_mkdir_p( dirname( $new_file ) ) ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1612 |
if ( 0 === strpos( $upload['basedir'], ABSPATH ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1613 |
$error_path = str_replace( ABSPATH, '', $upload['basedir'] ) . $upload['subdir']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1614 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1615 |
$error_path = basename( $upload['basedir'] ) . $upload['subdir']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1616 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1617 |
$message = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), $error_path ); |
136 | 1618 |
return array( 'error' => $message ); |
1619 |
} |
|
1620 |
||
1621 |
$ifp = @ fopen( $new_file, 'wb' ); |
|
1622 |
if ( ! $ifp ) |
|
1623 |
return array( 'error' => sprintf( __( 'Could not write file %s' ), $new_file ) ); |
|
1624 |
||
1625 |
@fwrite( $ifp, $bits ); |
|
1626 |
fclose( $ifp ); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1627 |
clearstatcache(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1628 |
|
136 | 1629 |
// Set correct file permissions |
1630 |
$stat = @ stat( dirname( $new_file ) ); |
|
1631 |
$perms = $stat['mode'] & 0007777; |
|
1632 |
$perms = $perms & 0000666; |
|
1633 |
@ chmod( $new_file, $perms ); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1634 |
clearstatcache(); |
136 | 1635 |
|
1636 |
// Compute the URL |
|
1637 |
$url = $upload['url'] . "/$filename"; |
|
1638 |
||
1639 |
return array( 'file' => $new_file, 'url' => $url, 'error' => false ); |
|
1640 |
} |
|
1641 |
||
1642 |
/** |
|
1643 |
* Retrieve the file type based on the extension name. |
|
1644 |
* |
|
1645 |
* @package WordPress |
|
1646 |
* @since 2.5.0 |
|
1647 |
* @uses apply_filters() Calls 'ext2type' hook on default supported types. |
|
1648 |
* |
|
1649 |
* @param string $ext The extension to search. |
|
1650 |
* @return string|null The file type, example: audio, video, document, spreadsheet, etc. Null if not found. |
|
1651 |
*/ |
|
1652 |
function wp_ext2type( $ext ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1653 |
$ext2type = apply_filters( 'ext2type', array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1654 |
'audio' => array( 'aac', 'ac3', 'aif', 'aiff', 'm3a', 'm4a', 'm4b', 'mka', 'mp1', 'mp2', 'mp3', 'ogg', 'oga', 'ram', 'wav', 'wma' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1655 |
'video' => array( 'asf', 'avi', 'divx', 'dv', 'flv', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mpv', 'ogm', 'ogv', 'qt', 'rm', 'vob', 'wmv' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1656 |
'document' => array( 'doc', 'docx', 'docm', 'dotm', 'odt', 'pages', 'pdf', 'rtf', 'wp', 'wpd' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1657 |
'spreadsheet' => array( 'numbers', 'ods', 'xls', 'xlsx', 'xlsb', 'xlsm' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1658 |
'interactive' => array( 'key', 'ppt', 'pptx', 'pptm', 'odp', 'swf' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1659 |
'text' => array( 'asc', 'csv', 'tsv', 'txt' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1660 |
'archive' => array( 'bz2', 'cab', 'dmg', 'gz', 'rar', 'sea', 'sit', 'sqx', 'tar', 'tgz', 'zip', '7z' ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1661 |
'code' => array( 'css', 'htm', 'html', 'php', 'js' ), |
136 | 1662 |
)); |
1663 |
foreach ( $ext2type as $type => $exts ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1664 |
if ( in_array( $ext, $exts ) ) |
136 | 1665 |
return $type; |
1666 |
} |
|
1667 |
||
1668 |
/** |
|
1669 |
* Retrieve the file type from the file name. |
|
1670 |
* |
|
1671 |
* You can optionally define the mime array, if needed. |
|
1672 |
* |
|
1673 |
* @since 2.0.4 |
|
1674 |
* |
|
1675 |
* @param string $filename File name or path. |
|
1676 |
* @param array $mimes Optional. Key is the file extension with value as the mime type. |
|
1677 |
* @return array Values with extension first and mime type. |
|
1678 |
*/ |
|
1679 |
function wp_check_filetype( $filename, $mimes = null ) { |
|
1680 |
if ( empty($mimes) ) |
|
1681 |
$mimes = get_allowed_mime_types(); |
|
1682 |
$type = false; |
|
1683 |
$ext = false; |
|
1684 |
||
1685 |
foreach ( $mimes as $ext_preg => $mime_match ) { |
|
1686 |
$ext_preg = '!\.(' . $ext_preg . ')$!i'; |
|
1687 |
if ( preg_match( $ext_preg, $filename, $ext_matches ) ) { |
|
1688 |
$type = $mime_match; |
|
1689 |
$ext = $ext_matches[1]; |
|
1690 |
break; |
|
1691 |
} |
|
1692 |
} |
|
1693 |
||
1694 |
return compact( 'ext', 'type' ); |
|
1695 |
} |
|
1696 |
||
1697 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1698 |
* Attempt to determine the real file type of a file. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1699 |
* If unable to, the file name extension will be used to determine type. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1700 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1701 |
* If it's determined that the extension does not match the file's real type, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1702 |
* then the "proper_filename" value will be set with a proper filename and extension. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1703 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1704 |
* Currently this function only supports validating images known to getimagesize(). |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1705 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1706 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1707 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1708 |
* @param string $file Full path to the image. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1709 |
* @param string $filename The filename of the image (may differ from $file due to $file being in a tmp directory) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1710 |
* @param array $mimes Optional. Key is the file extension with value as the mime type. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1711 |
* @return array Values for the extension, MIME, and either a corrected filename or false if original $filename is valid |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1712 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1713 |
function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1714 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1715 |
$proper_filename = false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1716 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1717 |
// Do basic extension validation and MIME mapping |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1718 |
$wp_filetype = wp_check_filetype( $filename, $mimes ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1719 |
extract( $wp_filetype ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1720 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1721 |
// We can't do any further validation without a file to work with |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1722 |
if ( ! file_exists( $file ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1723 |
return compact( 'ext', 'type', 'proper_filename' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1724 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1725 |
// We're able to validate images using GD |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1726 |
if ( $type && 0 === strpos( $type, 'image/' ) && function_exists('getimagesize') ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1727 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1728 |
// Attempt to figure out what type of image it actually is |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1729 |
$imgstats = @getimagesize( $file ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1730 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1731 |
// If getimagesize() knows what kind of image it really is and if the real MIME doesn't match the claimed MIME |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1732 |
if ( !empty($imgstats['mime']) && $imgstats['mime'] != $type ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1733 |
// This is a simplified array of MIMEs that getimagesize() can detect and their extensions |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1734 |
// You shouldn't need to use this filter, but it's here just in case |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1735 |
$mime_to_ext = apply_filters( 'getimagesize_mimes_to_exts', array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1736 |
'image/jpeg' => 'jpg', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1737 |
'image/png' => 'png', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1738 |
'image/gif' => 'gif', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1739 |
'image/bmp' => 'bmp', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1740 |
'image/tiff' => 'tif', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1741 |
) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1742 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1743 |
// Replace whatever is after the last period in the filename with the correct extension |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1744 |
if ( ! empty( $mime_to_ext[ $imgstats['mime'] ] ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1745 |
$filename_parts = explode( '.', $filename ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1746 |
array_pop( $filename_parts ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1747 |
$filename_parts[] = $mime_to_ext[ $imgstats['mime'] ]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1748 |
$new_filename = implode( '.', $filename_parts ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1749 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1750 |
if ( $new_filename != $filename ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1751 |
$proper_filename = $new_filename; // Mark that it changed |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1752 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1753 |
// Redefine the extension / MIME |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1754 |
$wp_filetype = wp_check_filetype( $new_filename, $mimes ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1755 |
extract( $wp_filetype ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1756 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1757 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1758 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1759 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1760 |
// Let plugins try and validate other types of files |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1761 |
// Should return an array in the style of array( 'ext' => $ext, 'type' => $type, 'proper_filename' => $proper_filename ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1762 |
return apply_filters( 'wp_check_filetype_and_ext', compact( 'ext', 'type', 'proper_filename' ), $file, $filename, $mimes ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1763 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1764 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1765 |
/** |
136 | 1766 |
* Retrieve list of allowed mime types and file extensions. |
1767 |
* |
|
1768 |
* @since 2.8.6 |
|
1769 |
* |
|
1770 |
* @return array Array of mime types keyed by the file extension regex corresponding to those types. |
|
1771 |
*/ |
|
1772 |
function get_allowed_mime_types() { |
|
1773 |
static $mimes = false; |
|
1774 |
||
1775 |
if ( !$mimes ) { |
|
1776 |
// Accepted MIME types are set here as PCRE unless provided. |
|
1777 |
$mimes = apply_filters( 'upload_mimes', array( |
|
1778 |
'jpg|jpeg|jpe' => 'image/jpeg', |
|
1779 |
'gif' => 'image/gif', |
|
1780 |
'png' => 'image/png', |
|
1781 |
'bmp' => 'image/bmp', |
|
1782 |
'tif|tiff' => 'image/tiff', |
|
1783 |
'ico' => 'image/x-icon', |
|
1784 |
'asf|asx|wax|wmv|wmx' => 'video/asf', |
|
1785 |
'avi' => 'video/avi', |
|
1786 |
'divx' => 'video/divx', |
|
1787 |
'flv' => 'video/x-flv', |
|
1788 |
'mov|qt' => 'video/quicktime', |
|
1789 |
'mpeg|mpg|mpe' => 'video/mpeg', |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1790 |
'txt|asc|c|cc|h' => 'text/plain', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1791 |
'csv' => 'text/csv', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1792 |
'tsv' => 'text/tab-separated-values', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1793 |
'ics' => 'text/calendar', |
136 | 1794 |
'rtx' => 'text/richtext', |
1795 |
'css' => 'text/css', |
|
1796 |
'htm|html' => 'text/html', |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1797 |
'mp3|m4a|m4b' => 'audio/mpeg', |
136 | 1798 |
'mp4|m4v' => 'video/mp4', |
1799 |
'ra|ram' => 'audio/x-realaudio', |
|
1800 |
'wav' => 'audio/wav', |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1801 |
'ogg|oga' => 'audio/ogg', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1802 |
'ogv' => 'video/ogg', |
136 | 1803 |
'mid|midi' => 'audio/midi', |
1804 |
'wma' => 'audio/wma', |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1805 |
'mka' => 'audio/x-matroska', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1806 |
'mkv' => 'video/x-matroska', |
136 | 1807 |
'rtf' => 'application/rtf', |
1808 |
'js' => 'application/javascript', |
|
1809 |
'pdf' => 'application/pdf', |
|
1810 |
'doc|docx' => 'application/msword', |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1811 |
'pot|pps|ppt|pptx|ppam|pptm|sldm|ppsm|potm' => 'application/vnd.ms-powerpoint', |
136 | 1812 |
'wri' => 'application/vnd.ms-write', |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1813 |
'xla|xls|xlsx|xlt|xlw|xlam|xlsb|xlsm|xltm' => 'application/vnd.ms-excel', |
136 | 1814 |
'mdb' => 'application/vnd.ms-access', |
1815 |
'mpp' => 'application/vnd.ms-project', |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1816 |
'docm|dotm' => 'application/vnd.ms-word', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1817 |
'pptx|sldx|ppsx|potx' => 'application/vnd.openxmlformats-officedocument.presentationml', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1818 |
'xlsx|xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1819 |
'docx|dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1820 |
'onetoc|onetoc2|onetmp|onepkg' => 'application/onenote', |
136 | 1821 |
'swf' => 'application/x-shockwave-flash', |
1822 |
'class' => 'application/java', |
|
1823 |
'tar' => 'application/x-tar', |
|
1824 |
'zip' => 'application/zip', |
|
1825 |
'gz|gzip' => 'application/x-gzip', |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1826 |
'rar' => 'application/rar', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1827 |
'7z' => 'application/x-7z-compressed', |
136 | 1828 |
'exe' => 'application/x-msdownload', |
1829 |
// openoffice formats |
|
1830 |
'odt' => 'application/vnd.oasis.opendocument.text', |
|
1831 |
'odp' => 'application/vnd.oasis.opendocument.presentation', |
|
1832 |
'ods' => 'application/vnd.oasis.opendocument.spreadsheet', |
|
1833 |
'odg' => 'application/vnd.oasis.opendocument.graphics', |
|
1834 |
'odc' => 'application/vnd.oasis.opendocument.chart', |
|
1835 |
'odb' => 'application/vnd.oasis.opendocument.database', |
|
1836 |
'odf' => 'application/vnd.oasis.opendocument.formula', |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1837 |
// wordperfect formats |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1838 |
'wp|wpd' => 'application/wordperfect', |
136 | 1839 |
) ); |
1840 |
} |
|
1841 |
||
1842 |
return $mimes; |
|
1843 |
} |
|
1844 |
||
1845 |
/** |
|
1846 |
* Retrieve nonce action "Are you sure" message. |
|
1847 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1848 |
* Deprecated in 3.4.1 and 3.5.0. Backported to 3.3.3. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1849 |
* |
136 | 1850 |
* @since 2.0.4 |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1851 |
* @deprecated 3.4.1 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1852 |
* @deprecated Use wp_nonce_ays() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1853 |
* @see wp_nonce_ays() |
136 | 1854 |
* |
1855 |
* @param string $action Nonce action. |
|
1856 |
* @return string Are you sure message. |
|
1857 |
*/ |
|
1858 |
function wp_explain_nonce( $action ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1859 |
_deprecated_function( __FUNCTION__, '3.4.1', 'wp_nonce_ays()' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1860 |
return __( 'Are you sure you want to do this?' ); |
136 | 1861 |
} |
1862 |
||
1863 |
/** |
|
1864 |
* Display "Are You Sure" message to confirm the action being taken. |
|
1865 |
* |
|
1866 |
* If the action has the nonce explain message, then it will be displayed along |
|
1867 |
* with the "Are you sure?" message. |
|
1868 |
* |
|
1869 |
* @package WordPress |
|
1870 |
* @subpackage Security |
|
1871 |
* @since 2.0.4 |
|
1872 |
* |
|
1873 |
* @param string $action The nonce action. |
|
1874 |
*/ |
|
1875 |
function wp_nonce_ays( $action ) { |
|
1876 |
$title = __( 'WordPress Failure Notice' ); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1877 |
if ( 'log-out' == $action ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1878 |
$html = sprintf( __( 'You are attempting to log out of %s' ), get_bloginfo( 'name' ) ) . '</p><p>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1879 |
$html .= sprintf( __( "Do you really want to <a href='%s'>log out</a>?"), wp_logout_url() ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1880 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1881 |
$html = __( 'Are you sure you want to do this?' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1882 |
if ( wp_get_referer() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1883 |
$html .= "</p><p><a href='" . esc_url( remove_query_arg( 'updated', wp_get_referer() ) ) . "'>" . __( 'Please try again.' ) . "</a>"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1884 |
} |
136 | 1885 |
|
1886 |
wp_die( $html, $title, array('response' => 403) ); |
|
1887 |
} |
|
1888 |
||
1889 |
/** |
|
1890 |
* Kill WordPress execution and display HTML message with error message. |
|
1891 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1892 |
* This function complements the die() PHP function. The difference is that |
136 | 1893 |
* HTML will be displayed to the user. It is recommended to use this function |
1894 |
* only, when the execution should not continue any further. It is not |
|
1895 |
* recommended to call this function very often and try to handle as many errors |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1896 |
* as possible silently. |
136 | 1897 |
* |
1898 |
* @since 2.0.4 |
|
1899 |
* |
|
1900 |
* @param string $message Error message. |
|
1901 |
* @param string $title Error title. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1902 |
* @param string|array $args Optional arguments to control behavior. |
136 | 1903 |
*/ |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1904 |
function wp_die( $message = '', $title = '', $args = array() ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1905 |
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1906 |
$function = apply_filters( 'wp_die_ajax_handler', '_ajax_wp_die_handler' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1907 |
elseif ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1908 |
$function = apply_filters( 'wp_die_xmlrpc_handler', '_xmlrpc_wp_die_handler' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1909 |
elseif ( defined( 'APP_REQUEST' ) && APP_REQUEST ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1910 |
$function = apply_filters( 'wp_die_app_handler', '_scalar_wp_die_handler' ); |
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 |
$function = apply_filters( 'wp_die_handler', '_default_wp_die_handler' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1913 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1914 |
call_user_func( $function, $message, $title, $args ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1915 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1916 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1917 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1918 |
* Kill WordPress execution and display HTML message with error message. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1919 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1920 |
* This is the default handler for wp_die if you want a custom one for your |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1921 |
* site then you can overload using the wp_die_handler filter in wp_die |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1922 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1923 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1924 |
* @access private |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1925 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1926 |
* @param string $message Error message. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1927 |
* @param string $title Error title. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1928 |
* @param string|array $args Optional arguments to control behavior. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1929 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1930 |
function _default_wp_die_handler( $message, $title = '', $args = array() ) { |
136 | 1931 |
$defaults = array( 'response' => 500 ); |
1932 |
$r = wp_parse_args($args, $defaults); |
|
1933 |
||
1934 |
$have_gettext = function_exists('__'); |
|
1935 |
||
1936 |
if ( function_exists( 'is_wp_error' ) && is_wp_error( $message ) ) { |
|
1937 |
if ( empty( $title ) ) { |
|
1938 |
$error_data = $message->get_error_data(); |
|
1939 |
if ( is_array( $error_data ) && isset( $error_data['title'] ) ) |
|
1940 |
$title = $error_data['title']; |
|
1941 |
} |
|
1942 |
$errors = $message->get_error_messages(); |
|
1943 |
switch ( count( $errors ) ) : |
|
1944 |
case 0 : |
|
1945 |
$message = ''; |
|
1946 |
break; |
|
1947 |
case 1 : |
|
1948 |
$message = "<p>{$errors[0]}</p>"; |
|
1949 |
break; |
|
1950 |
default : |
|
1951 |
$message = "<ul>\n\t\t<li>" . join( "</li>\n\t\t<li>", $errors ) . "</li>\n\t</ul>"; |
|
1952 |
break; |
|
1953 |
endswitch; |
|
1954 |
} elseif ( is_string( $message ) ) { |
|
1955 |
$message = "<p>$message</p>"; |
|
1956 |
} |
|
1957 |
||
1958 |
if ( isset( $r['back_link'] ) && $r['back_link'] ) { |
|
1959 |
$back_text = $have_gettext? __('« Back') : '« Back'; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1960 |
$message .= "\n<p><a href='javascript:history.back()'>$back_text</a></p>"; |
136 | 1961 |
} |
1962 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1963 |
if ( ! did_action( 'admin_head' ) ) : |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1964 |
if ( !headers_sent() ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1965 |
status_header( $r['response'] ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1966 |
nocache_headers(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1967 |
header( 'Content-Type: text/html; charset=utf-8' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1968 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1969 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1970 |
if ( empty($title) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1971 |
$title = $have_gettext ? __('WordPress › Error') : 'WordPress › Error'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1972 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1973 |
$text_direction = 'ltr'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1974 |
if ( isset($r['text_direction']) && 'rtl' == $r['text_direction'] ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1975 |
$text_direction = 'rtl'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1976 |
elseif ( function_exists( 'is_rtl' ) && is_rtl() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1977 |
$text_direction = 'rtl'; |
136 | 1978 |
?> |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1979 |
<!DOCTYPE html> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1980 |
<!-- Ticket #11289, IE bug fix: always pad the error page with enough characters such that it is greater than 512 bytes, even after gzip compression abcdefghijklmnopqrstuvwxyz1234567890aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz11223344556677889900abacbcbdcdcededfefegfgfhghgihihjijikjkjlklkmlmlnmnmononpopoqpqprqrqsrsrtstsubcbcdcdedefefgfabcadefbghicjkldmnoepqrfstugvwxhyz1i234j567k890laabmbccnddeoeffpgghqhiirjjksklltmmnunoovppqwqrrxsstytuuzvvw0wxx1yyz2z113223434455666777889890091abc2def3ghi4jkl5mno6pqr7stu8vwx9yz11aab2bcc3dd4ee5ff6gg7hh8ii9j0jk1kl2lmm3nnoo4p5pq6qrr7ss8tt9uuvv0wwx1x2yyzz13aba4cbcb5dcdc6dedfef8egf9gfh0ghg1ihi2hji3jik4jkj5lkl6kml7mln8mnm9ono |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1981 |
--> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1982 |
<html xmlns="http://www.w3.org/1999/xhtml" <?php if ( function_exists( 'language_attributes' ) && function_exists( 'is_rtl' ) ) language_attributes(); else echo "dir='$text_direction'"; ?>> |
136 | 1983 |
<head> |
1984 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
|
1985 |
<title><?php echo $title ?></title> |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1986 |
<style type="text/css"> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1987 |
html { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1988 |
background: #f9f9f9; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1989 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1990 |
body { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1991 |
background: #fff; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1992 |
color: #333; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1993 |
font-family: sans-serif; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1994 |
margin: 2em auto; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1995 |
padding: 1em 2em; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1996 |
-webkit-border-radius: 3px; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1997 |
border-radius: 3px; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1998 |
border: 1px solid #dfdfdf; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1999 |
max-width: 700px; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2000 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2001 |
h1 { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2002 |
border-bottom: 1px solid #dadada; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2003 |
clear: both; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2004 |
color: #666; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2005 |
font: 24px Georgia, "Times New Roman", Times, serif; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2006 |
margin: 30px 0 0 0; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2007 |
padding: 0; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2008 |
padding-bottom: 7px; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2009 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2010 |
#error-page { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2011 |
margin-top: 50px; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2012 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2013 |
#error-page p { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2014 |
font-size: 14px; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2015 |
line-height: 1.5; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2016 |
margin: 25px 0 20px; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2017 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2018 |
#error-page code { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2019 |
font-family: Consolas, Monaco, monospace; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2020 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2021 |
ul li { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2022 |
margin-bottom: 10px; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2023 |
font-size: 14px ; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2024 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2025 |
a { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2026 |
color: #21759B; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2027 |
text-decoration: none; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2028 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2029 |
a:hover { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2030 |
color: #D54E21; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2031 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2032 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2033 |
.button { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2034 |
font-family: sans-serif; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2035 |
text-decoration: none; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2036 |
font-size: 14px !important; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2037 |
line-height: 16px; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2038 |
padding: 6px 12px; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2039 |
cursor: pointer; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2040 |
border: 1px solid #bbb; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2041 |
color: #464646; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2042 |
-webkit-border-radius: 15px; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2043 |
border-radius: 15px; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2044 |
-moz-box-sizing: content-box; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2045 |
-webkit-box-sizing: content-box; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2046 |
box-sizing: content-box; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2047 |
background-color: #f5f5f5; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2048 |
background-image: -ms-linear-gradient(top, #ffffff, #f2f2f2); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2049 |
background-image: -moz-linear-gradient(top, #ffffff, #f2f2f2); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2050 |
background-image: -o-linear-gradient(top, #ffffff, #f2f2f2); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2051 |
background-image: -webkit-gradient(linear, left top, left bottom, from(#ffffff), to(#f2f2f2)); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2052 |
background-image: -webkit-linear-gradient(top, #ffffff, #f2f2f2); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2053 |
background-image: linear-gradient(top, #ffffff, #f2f2f2); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2054 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2055 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2056 |
.button:hover { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2057 |
color: #000; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2058 |
border-color: #666; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2059 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2060 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2061 |
.button:active { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2062 |
background-image: -ms-linear-gradient(top, #f2f2f2, #ffffff); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2063 |
background-image: -moz-linear-gradient(top, #f2f2f2, #ffffff); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2064 |
background-image: -o-linear-gradient(top, #f2f2f2, #ffffff); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2065 |
background-image: -webkit-gradient(linear, left top, left bottom, from(#f2f2f2), to(#ffffff)); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2066 |
background-image: -webkit-linear-gradient(top, #f2f2f2, #ffffff); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2067 |
background-image: linear-gradient(top, #f2f2f2, #ffffff); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2068 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2069 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2070 |
<?php if ( 'rtl' == $text_direction ) : ?> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2071 |
body { font-family: Tahoma, Arial; } |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2072 |
<?php endif; ?> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2073 |
</style> |
136 | 2074 |
</head> |
2075 |
<body id="error-page"> |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2076 |
<?php endif; // ! did_action( 'admin_head' ) ?> |
136 | 2077 |
<?php echo $message; ?> |
2078 |
</body> |
|
2079 |
</html> |
|
2080 |
<?php |
|
2081 |
die(); |
|
2082 |
} |
|
2083 |
||
2084 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2085 |
* Kill WordPress execution and display XML message with error message. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2086 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2087 |
* This is the handler for wp_die when processing XMLRPC requests. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2088 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2089 |
* @since 3.2.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2090 |
* @access private |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2091 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2092 |
* @param string $message Error message. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2093 |
* @param string $title Error title. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2094 |
* @param string|array $args Optional arguments to control behavior. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2095 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2096 |
function _xmlrpc_wp_die_handler( $message, $title = '', $args = array() ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2097 |
global $wp_xmlrpc_server; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2098 |
$defaults = array( 'response' => 500 ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2099 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2100 |
$r = wp_parse_args($args, $defaults); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2101 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2102 |
if ( $wp_xmlrpc_server ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2103 |
$error = new IXR_Error( $r['response'] , $message); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2104 |
$wp_xmlrpc_server->output( $error->getXml() ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2105 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2106 |
die(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2107 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2108 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2109 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2110 |
* Kill WordPress ajax execution. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2111 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2112 |
* This is the handler for wp_die when processing Ajax requests. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2113 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2114 |
* @since 3.4.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2115 |
* @access private |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2116 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2117 |
* @param string $message Optional. Response to print. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2118 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2119 |
function _ajax_wp_die_handler( $message = '' ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2120 |
if ( is_scalar( $message ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2121 |
die( (string) $message ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2122 |
die( '0' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2123 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2124 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2125 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2126 |
* Kill WordPress execution. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2127 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2128 |
* This is the handler for wp_die when processing APP requests. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2129 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2130 |
* @since 3.4.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2131 |
* @access private |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2132 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2133 |
* @param string $message Optional. Response to print. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2134 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2135 |
function _scalar_wp_die_handler( $message = '' ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2136 |
if ( is_scalar( $message ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2137 |
die( (string) $message ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2138 |
die(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2139 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2140 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2141 |
/** |
136 | 2142 |
* Retrieve the WordPress home page URL. |
2143 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2144 |
* If the constant named 'WP_HOME' exists, then it will be used and returned by |
136 | 2145 |
* the function. This can be used to counter the redirection on your local |
2146 |
* development environment. |
|
2147 |
* |
|
2148 |
* @access private |
|
2149 |
* @package WordPress |
|
2150 |
* @since 2.2.0 |
|
2151 |
* |
|
2152 |
* @param string $url URL for the home location |
|
2153 |
* @return string Homepage location. |
|
2154 |
*/ |
|
2155 |
function _config_wp_home( $url = '' ) { |
|
2156 |
if ( defined( 'WP_HOME' ) ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2157 |
return untrailingslashit( WP_HOME ); |
136 | 2158 |
return $url; |
2159 |
} |
|
2160 |
||
2161 |
/** |
|
2162 |
* Retrieve the WordPress site URL. |
|
2163 |
* |
|
2164 |
* If the constant named 'WP_SITEURL' is defined, then the value in that |
|
2165 |
* constant will always be returned. This can be used for debugging a site on |
|
2166 |
* your localhost while not having to change the database to your URL. |
|
2167 |
* |
|
2168 |
* @access private |
|
2169 |
* @package WordPress |
|
2170 |
* @since 2.2.0 |
|
2171 |
* |
|
2172 |
* @param string $url URL to set the WordPress site location. |
|
2173 |
* @return string The WordPress Site URL |
|
2174 |
*/ |
|
2175 |
function _config_wp_siteurl( $url = '' ) { |
|
2176 |
if ( defined( 'WP_SITEURL' ) ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2177 |
return untrailingslashit( WP_SITEURL ); |
136 | 2178 |
return $url; |
2179 |
} |
|
2180 |
||
2181 |
/** |
|
2182 |
* Set the localized direction for MCE plugin. |
|
2183 |
* |
|
2184 |
* Will only set the direction to 'rtl', if the WordPress locale has the text |
|
2185 |
* direction set to 'rtl'. |
|
2186 |
* |
|
2187 |
* Fills in the 'directionality', 'plugins', and 'theme_advanced_button1' array |
|
2188 |
* keys. These keys are then returned in the $input array. |
|
2189 |
* |
|
2190 |
* @access private |
|
2191 |
* @package WordPress |
|
2192 |
* @subpackage MCE |
|
2193 |
* @since 2.1.0 |
|
2194 |
* |
|
2195 |
* @param array $input MCE plugin array. |
|
2196 |
* @return array Direction set for 'rtl', if needed by locale. |
|
2197 |
*/ |
|
2198 |
function _mce_set_direction( $input ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2199 |
if ( is_rtl() ) { |
136 | 2200 |
$input['directionality'] = 'rtl'; |
2201 |
$input['plugins'] .= ',directionality'; |
|
2202 |
$input['theme_advanced_buttons1'] .= ',ltr'; |
|
2203 |
} |
|
2204 |
||
2205 |
return $input; |
|
2206 |
} |
|
2207 |
||
2208 |
/** |
|
2209 |
* Convert smiley code to the icon graphic file equivalent. |
|
2210 |
* |
|
2211 |
* You can turn off smilies, by going to the write setting screen and unchecking |
|
2212 |
* the box, or by setting 'use_smilies' option to false or removing the option. |
|
2213 |
* |
|
2214 |
* Plugins may override the default smiley list by setting the $wpsmiliestrans |
|
2215 |
* to an array, with the key the code the blogger types in and the value the |
|
2216 |
* image file. |
|
2217 |
* |
|
2218 |
* The $wp_smiliessearch global is for the regular expression and is set each |
|
2219 |
* time the function is called. |
|
2220 |
* |
|
2221 |
* The full list of smilies can be found in the function and won't be listed in |
|
2222 |
* the description. Probably should create a Codex page for it, so that it is |
|
2223 |
* available. |
|
2224 |
* |
|
2225 |
* @global array $wpsmiliestrans |
|
2226 |
* @global array $wp_smiliessearch |
|
2227 |
* @since 2.2.0 |
|
2228 |
*/ |
|
2229 |
function smilies_init() { |
|
2230 |
global $wpsmiliestrans, $wp_smiliessearch; |
|
2231 |
||
2232 |
// don't bother setting up smilies if they are disabled |
|
2233 |
if ( !get_option( 'use_smilies' ) ) |
|
2234 |
return; |
|
2235 |
||
2236 |
if ( !isset( $wpsmiliestrans ) ) { |
|
2237 |
$wpsmiliestrans = array( |
|
2238 |
':mrgreen:' => 'icon_mrgreen.gif', |
|
2239 |
':neutral:' => 'icon_neutral.gif', |
|
2240 |
':twisted:' => 'icon_twisted.gif', |
|
2241 |
':arrow:' => 'icon_arrow.gif', |
|
2242 |
':shock:' => 'icon_eek.gif', |
|
2243 |
':smile:' => 'icon_smile.gif', |
|
2244 |
':???:' => 'icon_confused.gif', |
|
2245 |
':cool:' => 'icon_cool.gif', |
|
2246 |
':evil:' => 'icon_evil.gif', |
|
2247 |
':grin:' => 'icon_biggrin.gif', |
|
2248 |
':idea:' => 'icon_idea.gif', |
|
2249 |
':oops:' => 'icon_redface.gif', |
|
2250 |
':razz:' => 'icon_razz.gif', |
|
2251 |
':roll:' => 'icon_rolleyes.gif', |
|
2252 |
':wink:' => 'icon_wink.gif', |
|
2253 |
':cry:' => 'icon_cry.gif', |
|
2254 |
':eek:' => 'icon_surprised.gif', |
|
2255 |
':lol:' => 'icon_lol.gif', |
|
2256 |
':mad:' => 'icon_mad.gif', |
|
2257 |
':sad:' => 'icon_sad.gif', |
|
2258 |
'8-)' => 'icon_cool.gif', |
|
2259 |
'8-O' => 'icon_eek.gif', |
|
2260 |
':-(' => 'icon_sad.gif', |
|
2261 |
':-)' => 'icon_smile.gif', |
|
2262 |
':-?' => 'icon_confused.gif', |
|
2263 |
':-D' => 'icon_biggrin.gif', |
|
2264 |
':-P' => 'icon_razz.gif', |
|
2265 |
':-o' => 'icon_surprised.gif', |
|
2266 |
':-x' => 'icon_mad.gif', |
|
2267 |
':-|' => 'icon_neutral.gif', |
|
2268 |
';-)' => 'icon_wink.gif', |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2269 |
// This one transformation breaks regular text with frequency. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2270 |
// '8)' => 'icon_cool.gif', |
136 | 2271 |
'8O' => 'icon_eek.gif', |
2272 |
':(' => 'icon_sad.gif', |
|
2273 |
':)' => 'icon_smile.gif', |
|
2274 |
':?' => 'icon_confused.gif', |
|
2275 |
':D' => 'icon_biggrin.gif', |
|
2276 |
':P' => 'icon_razz.gif', |
|
2277 |
':o' => 'icon_surprised.gif', |
|
2278 |
':x' => 'icon_mad.gif', |
|
2279 |
':|' => 'icon_neutral.gif', |
|
2280 |
';)' => 'icon_wink.gif', |
|
2281 |
':!:' => 'icon_exclaim.gif', |
|
2282 |
':?:' => 'icon_question.gif', |
|
2283 |
); |
|
2284 |
} |
|
2285 |
||
2286 |
if (count($wpsmiliestrans) == 0) { |
|
2287 |
return; |
|
2288 |
} |
|
2289 |
||
2290 |
/* |
|
2291 |
* NOTE: we sort the smilies in reverse key order. This is to make sure |
|
2292 |
* we match the longest possible smilie (:???: vs :?) as the regular |
|
2293 |
* expression used below is first-match |
|
2294 |
*/ |
|
2295 |
krsort($wpsmiliestrans); |
|
2296 |
||
2297 |
$wp_smiliessearch = '/(?:\s|^)'; |
|
2298 |
||
2299 |
$subchar = ''; |
|
2300 |
foreach ( (array) $wpsmiliestrans as $smiley => $img ) { |
|
2301 |
$firstchar = substr($smiley, 0, 1); |
|
2302 |
$rest = substr($smiley, 1); |
|
2303 |
||
2304 |
// new subpattern? |
|
2305 |
if ($firstchar != $subchar) { |
|
2306 |
if ($subchar != '') { |
|
2307 |
$wp_smiliessearch .= ')|(?:\s|^)'; |
|
2308 |
} |
|
2309 |
$subchar = $firstchar; |
|
2310 |
$wp_smiliessearch .= preg_quote($firstchar, '/') . '(?:'; |
|
2311 |
} else { |
|
2312 |
$wp_smiliessearch .= '|'; |
|
2313 |
} |
|
2314 |
$wp_smiliessearch .= preg_quote($rest, '/'); |
|
2315 |
} |
|
2316 |
||
2317 |
$wp_smiliessearch .= ')(?:\s|$)/m'; |
|
2318 |
} |
|
2319 |
||
2320 |
/** |
|
2321 |
* Merge user defined arguments into defaults array. |
|
2322 |
* |
|
2323 |
* This function is used throughout WordPress to allow for both string or array |
|
2324 |
* to be merged into another array. |
|
2325 |
* |
|
2326 |
* @since 2.2.0 |
|
2327 |
* |
|
2328 |
* @param string|array $args Value to merge with $defaults |
|
2329 |
* @param array $defaults Array that serves as the defaults. |
|
2330 |
* @return array Merged user defined values with defaults. |
|
2331 |
*/ |
|
2332 |
function wp_parse_args( $args, $defaults = '' ) { |
|
2333 |
if ( is_object( $args ) ) |
|
2334 |
$r = get_object_vars( $args ); |
|
2335 |
elseif ( is_array( $args ) ) |
|
2336 |
$r =& $args; |
|
2337 |
else |
|
2338 |
wp_parse_str( $args, $r ); |
|
2339 |
||
2340 |
if ( is_array( $defaults ) ) |
|
2341 |
return array_merge( $defaults, $r ); |
|
2342 |
return $r; |
|
2343 |
} |
|
2344 |
||
2345 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2346 |
* Clean up an array, comma- or space-separated list of IDs. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2347 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2348 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2349 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2350 |
* @param array|string $list |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2351 |
* @return array Sanitized array of IDs |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2352 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2353 |
function wp_parse_id_list( $list ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2354 |
if ( !is_array($list) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2355 |
$list = preg_split('/[\s,]+/', $list); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2356 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2357 |
return array_unique(array_map('absint', $list)); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2358 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2359 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2360 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2361 |
* Extract a slice of an array, given a list of keys. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2362 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2363 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2364 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2365 |
* @param array $array The original array |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2366 |
* @param array $keys The list of keys |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2367 |
* @return array The array slice |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2368 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2369 |
function wp_array_slice_assoc( $array, $keys ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2370 |
$slice = array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2371 |
foreach ( $keys as $key ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2372 |
if ( isset( $array[ $key ] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2373 |
$slice[ $key ] = $array[ $key ]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2374 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2375 |
return $slice; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2376 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2377 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2378 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2379 |
* Filters a list of objects, based on a set of key => value arguments. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2380 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2381 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2382 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2383 |
* @param array $list An array of objects to filter |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2384 |
* @param array $args An array of key => value arguments to match against each object |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2385 |
* @param string $operator The logical operation to perform. 'or' means only one element |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2386 |
* from the array needs to match; 'and' means all elements must match. The default is 'and'. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2387 |
* @param bool|string $field A field from the object to place instead of the entire object |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2388 |
* @return array A list of objects or object fields |
136 | 2389 |
*/ |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2390 |
function wp_filter_object_list( $list, $args = array(), $operator = 'and', $field = false ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2391 |
if ( ! is_array( $list ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2392 |
return array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2393 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2394 |
$list = wp_list_filter( $list, $args, $operator ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2395 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2396 |
if ( $field ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2397 |
$list = wp_list_pluck( $list, $field ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2398 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2399 |
return $list; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2400 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2401 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2402 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2403 |
* Filters a list of objects, based on a set of key => value arguments. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2404 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2405 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2406 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2407 |
* @param array $list An array of objects to filter |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2408 |
* @param array $args An array of key => value arguments to match against each object |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2409 |
* @param string $operator The logical operation to perform: |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2410 |
* 'AND' means all elements from the array must match; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2411 |
* 'OR' means only one element needs to match; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2412 |
* 'NOT' means no elements may match. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2413 |
* The default is 'AND'. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2414 |
* @return array |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2415 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2416 |
function wp_list_filter( $list, $args = array(), $operator = 'AND' ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2417 |
if ( ! is_array( $list ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2418 |
return array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2419 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2420 |
if ( empty( $args ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2421 |
return $list; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2422 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2423 |
$operator = strtoupper( $operator ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2424 |
$count = count( $args ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2425 |
$filtered = array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2426 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2427 |
foreach ( $list as $key => $obj ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2428 |
$to_match = (array) $obj; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2429 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2430 |
$matched = 0; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2431 |
foreach ( $args as $m_key => $m_value ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2432 |
if ( $m_value == $to_match[ $m_key ] ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2433 |
$matched++; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2434 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2435 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2436 |
if ( ( 'AND' == $operator && $matched == $count ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2437 |
|| ( 'OR' == $operator && $matched > 0 ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2438 |
|| ( 'NOT' == $operator && 0 == $matched ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2439 |
$filtered[$key] = $obj; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2440 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2441 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2442 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2443 |
return $filtered; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2444 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2445 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2446 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2447 |
* Pluck a certain field out of each object in a list. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2448 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2449 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2450 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2451 |
* @param array $list A list of objects or arrays |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2452 |
* @param int|string $field A field from the object to place instead of the entire object |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2453 |
* @return array |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2454 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2455 |
function wp_list_pluck( $list, $field ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2456 |
foreach ( $list as $key => $value ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2457 |
if ( is_object( $value ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2458 |
$list[ $key ] = $value->$field; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2459 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2460 |
$list[ $key ] = $value[ $field ]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2461 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2462 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2463 |
return $list; |
136 | 2464 |
} |
2465 |
||
2466 |
/** |
|
2467 |
* Determines if Widgets library should be loaded. |
|
2468 |
* |
|
2469 |
* Checks to make sure that the widgets library hasn't already been loaded. If |
|
2470 |
* it hasn't, then it will load the widgets library and run an action hook. |
|
2471 |
* |
|
2472 |
* @since 2.2.0 |
|
2473 |
* @uses add_action() Calls '_admin_menu' hook with 'wp_widgets_add_menu' value. |
|
2474 |
*/ |
|
2475 |
function wp_maybe_load_widgets() { |
|
2476 |
if ( ! apply_filters('load_default_widgets', true) ) |
|
2477 |
return; |
|
2478 |
require_once( ABSPATH . WPINC . '/default-widgets.php' ); |
|
2479 |
add_action( '_admin_menu', 'wp_widgets_add_menu' ); |
|
2480 |
} |
|
2481 |
||
2482 |
/** |
|
2483 |
* Append the Widgets menu to the themes main menu. |
|
2484 |
* |
|
2485 |
* @since 2.2.0 |
|
2486 |
* @uses $submenu The administration submenu list. |
|
2487 |
*/ |
|
2488 |
function wp_widgets_add_menu() { |
|
2489 |
global $submenu; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2490 |
$submenu['themes.php'][7] = array( __( 'Widgets' ), 'edit_theme_options', 'widgets.php' ); |
136 | 2491 |
ksort( $submenu['themes.php'], SORT_NUMERIC ); |
2492 |
} |
|
2493 |
||
2494 |
/** |
|
2495 |
* Flush all output buffers for PHP 5.2. |
|
2496 |
* |
|
2497 |
* Make sure all output buffers are flushed before our singletons our destroyed. |
|
2498 |
* |
|
2499 |
* @since 2.2.0 |
|
2500 |
*/ |
|
2501 |
function wp_ob_end_flush_all() { |
|
2502 |
$levels = ob_get_level(); |
|
2503 |
for ($i=0; $i<$levels; $i++) |
|
2504 |
ob_end_flush(); |
|
2505 |
} |
|
2506 |
||
2507 |
/** |
|
2508 |
* Load custom DB error or display WordPress DB error. |
|
2509 |
* |
|
2510 |
* If a file exists in the wp-content directory named db-error.php, then it will |
|
2511 |
* be loaded instead of displaying the WordPress DB error. If it is not found, |
|
2512 |
* then the WordPress DB error will be displayed instead. |
|
2513 |
* |
|
2514 |
* The WordPress DB error sets the HTTP status header to 500 to try to prevent |
|
2515 |
* search engines from caching the message. Custom DB messages should do the |
|
2516 |
* same. |
|
2517 |
* |
|
2518 |
* This function was backported to the the WordPress 2.3.2, but originally was |
|
2519 |
* added in WordPress 2.5.0. |
|
2520 |
* |
|
2521 |
* @since 2.3.2 |
|
2522 |
* @uses $wpdb |
|
2523 |
*/ |
|
2524 |
function dead_db() { |
|
2525 |
global $wpdb; |
|
2526 |
||
2527 |
// Load custom DB error template, if present. |
|
2528 |
if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) { |
|
2529 |
require_once( WP_CONTENT_DIR . '/db-error.php' ); |
|
2530 |
die(); |
|
2531 |
} |
|
2532 |
||
2533 |
// If installing or in the admin, provide the verbose message. |
|
2534 |
if ( defined('WP_INSTALLING') || defined('WP_ADMIN') ) |
|
2535 |
wp_die($wpdb->error); |
|
2536 |
||
2537 |
// Otherwise, be terse. |
|
2538 |
status_header( 500 ); |
|
2539 |
nocache_headers(); |
|
2540 |
header( 'Content-Type: text/html; charset=utf-8' ); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2541 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2542 |
wp_load_translations_early(); |
136 | 2543 |
?> |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2544 |
<!DOCTYPE html> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2545 |
<html xmlns="http://www.w3.org/1999/xhtml"<?php if ( is_rtl() ) echo ' dir="rtl"'; ?>> |
136 | 2546 |
<head> |
2547 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2548 |
<title><?php _e( 'Database Error' ); ?></title> |
136 | 2549 |
|
2550 |
</head> |
|
2551 |
<body> |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2552 |
<h1><?php _e( 'Error establishing a database connection' ); ?></h1> |
136 | 2553 |
</body> |
2554 |
</html> |
|
2555 |
<?php |
|
2556 |
die(); |
|
2557 |
} |
|
2558 |
||
2559 |
/** |
|
2560 |
* Converts value to nonnegative integer. |
|
2561 |
* |
|
2562 |
* @since 2.5.0 |
|
2563 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2564 |
* @param mixed $maybeint Data you wish to have converted to a nonnegative integer |
136 | 2565 |
* @return int An nonnegative integer |
2566 |
*/ |
|
2567 |
function absint( $maybeint ) { |
|
2568 |
return abs( intval( $maybeint ) ); |
|
2569 |
} |
|
2570 |
||
2571 |
/** |
|
2572 |
* Determines if the blog can be accessed over SSL. |
|
2573 |
* |
|
2574 |
* Determines if blog can be accessed over SSL by using cURL to access the site |
|
2575 |
* using the https in the siteurl. Requires cURL extension to work correctly. |
|
2576 |
* |
|
2577 |
* @since 2.5.0 |
|
2578 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2579 |
* @param string $url |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2580 |
* @return bool Whether SSL access is available |
136 | 2581 |
*/ |
2582 |
function url_is_accessable_via_ssl($url) |
|
2583 |
{ |
|
2584 |
if (in_array('curl', get_loaded_extensions())) { |
|
2585 |
$ssl = preg_replace( '/^http:\/\//', 'https://', $url ); |
|
2586 |
||
2587 |
$ch = curl_init(); |
|
2588 |
curl_setopt($ch, CURLOPT_URL, $ssl); |
|
2589 |
curl_setopt($ch, CURLOPT_FAILONERROR, true); |
|
2590 |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
2591 |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
|
2592 |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); |
|
2593 |
||
2594 |
curl_exec($ch); |
|
2595 |
||
2596 |
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
2597 |
curl_close ($ch); |
|
2598 |
||
2599 |
if ($status == 200 || $status == 401) { |
|
2600 |
return true; |
|
2601 |
} |
|
2602 |
} |
|
2603 |
return false; |
|
2604 |
} |
|
2605 |
||
2606 |
/** |
|
2607 |
* Marks a function as deprecated and informs when it has been used. |
|
2608 |
* |
|
2609 |
* There is a hook deprecated_function_run that will be called that can be used |
|
2610 |
* to get the backtrace up to what file and function called the deprecated |
|
2611 |
* function. |
|
2612 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2613 |
* The current behavior is to trigger a user error if WP_DEBUG is true. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2614 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2615 |
* This function is to be used in every function that is deprecated. |
136 | 2616 |
* |
2617 |
* @package WordPress |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2618 |
* @subpackage Debug |
136 | 2619 |
* @since 2.5.0 |
2620 |
* @access private |
|
2621 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2622 |
* @uses do_action() Calls 'deprecated_function_run' and passes the function name, what to use instead, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2623 |
* and the version the function was deprecated in. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2624 |
* @uses apply_filters() Calls 'deprecated_function_trigger_error' and expects boolean value of true to do |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2625 |
* trigger or false to not trigger error. |
136 | 2626 |
* |
2627 |
* @param string $function The function that was called |
|
2628 |
* @param string $version The version of WordPress that deprecated the function |
|
2629 |
* @param string $replacement Optional. The function that should have been called |
|
2630 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2631 |
function _deprecated_function( $function, $version, $replacement = null ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2632 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2633 |
do_action( 'deprecated_function_run', $function, $replacement, $version ); |
136 | 2634 |
|
2635 |
// Allow plugin to filter the output error trigger |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2636 |
if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2637 |
if ( ! is_null($replacement) ) |
136 | 2638 |
trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $function, $version, $replacement ) ); |
2639 |
else |
|
2640 |
trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $function, $version ) ); |
|
2641 |
} |
|
2642 |
} |
|
2643 |
||
2644 |
/** |
|
2645 |
* Marks a file as deprecated and informs when it has been used. |
|
2646 |
* |
|
2647 |
* There is a hook deprecated_file_included that will be called that can be used |
|
2648 |
* to get the backtrace up to what file and function included the deprecated |
|
2649 |
* file. |
|
2650 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2651 |
* The current behavior is to trigger a user error if WP_DEBUG is true. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2652 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2653 |
* This function is to be used in every file that is deprecated. |
136 | 2654 |
* |
2655 |
* @package WordPress |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2656 |
* @subpackage Debug |
136 | 2657 |
* @since 2.5.0 |
2658 |
* @access private |
|
2659 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2660 |
* @uses do_action() Calls 'deprecated_file_included' and passes the file name, what to use instead, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2661 |
* the version in which the file was deprecated, and any message regarding the change. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2662 |
* @uses apply_filters() Calls 'deprecated_file_trigger_error' and expects boolean value of true to do |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2663 |
* trigger or false to not trigger error. |
136 | 2664 |
* |
2665 |
* @param string $file The file that was included |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2666 |
* @param string $version The version of WordPress that deprecated the file |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2667 |
* @param string $replacement Optional. The file that should have been included based on ABSPATH |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2668 |
* @param string $message Optional. A message regarding the change |
136 | 2669 |
*/ |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2670 |
function _deprecated_file( $file, $version, $replacement = null, $message = '' ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2671 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2672 |
do_action( 'deprecated_file_included', $file, $replacement, $version, $message ); |
136 | 2673 |
|
2674 |
// Allow plugin to filter the output error trigger |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2675 |
if ( WP_DEBUG && apply_filters( 'deprecated_file_trigger_error', true ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2676 |
$message = empty( $message ) ? '' : ' ' . $message; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2677 |
if ( ! is_null( $replacement ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2678 |
trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $file, $version, $replacement ) . $message ); |
136 | 2679 |
else |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2680 |
trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $file, $version ) . $message ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2681 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2682 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2683 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2684 |
* Marks a function argument as deprecated and informs when it has been used. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2685 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2686 |
* This function is to be used whenever a deprecated function argument is used. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2687 |
* Before this function is called, the argument must be checked for whether it was |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2688 |
* used by comparing it to its default value or evaluating whether it is empty. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2689 |
* For example: |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2690 |
* <code> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2691 |
* if ( !empty($deprecated) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2692 |
* _deprecated_argument( __FUNCTION__, '3.0' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2693 |
* </code> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2694 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2695 |
* There is a hook deprecated_argument_run that will be called that can be used |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2696 |
* to get the backtrace up to what file and function used the deprecated |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2697 |
* argument. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2698 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2699 |
* The current behavior is to trigger a user error if WP_DEBUG is true. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2700 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2701 |
* @package WordPress |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2702 |
* @subpackage Debug |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2703 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2704 |
* @access private |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2705 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2706 |
* @uses do_action() Calls 'deprecated_argument_run' and passes the function name, a message on the change, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2707 |
* and the version in which the argument was deprecated. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2708 |
* @uses apply_filters() Calls 'deprecated_argument_trigger_error' and expects boolean value of true to do |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2709 |
* trigger or false to not trigger error. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2710 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2711 |
* @param string $function The function that was called |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2712 |
* @param string $version The version of WordPress that deprecated the argument used |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2713 |
* @param string $message Optional. A message regarding the change. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2714 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2715 |
function _deprecated_argument( $function, $version, $message = null ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2716 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2717 |
do_action( 'deprecated_argument_run', $function, $message, $version ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2718 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2719 |
// Allow plugin to filter the output error trigger |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2720 |
if ( WP_DEBUG && apply_filters( 'deprecated_argument_trigger_error', true ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2721 |
if ( ! is_null( $message ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2722 |
trigger_error( sprintf( __('%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s'), $function, $version, $message ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2723 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2724 |
trigger_error( sprintf( __('%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.'), $function, $version ) ); |
136 | 2725 |
} |
2726 |
} |
|
2727 |
||
2728 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2729 |
* Marks something as being incorrectly called. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2730 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2731 |
* There is a hook doing_it_wrong_run that will be called that can be used |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2732 |
* to get the backtrace up to what file and function called the deprecated |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2733 |
* function. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2734 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2735 |
* The current behavior is to trigger a user error if WP_DEBUG is true. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2736 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2737 |
* @package WordPress |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2738 |
* @subpackage Debug |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2739 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2740 |
* @access private |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2741 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2742 |
* @uses do_action() Calls 'doing_it_wrong_run' and passes the function arguments. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2743 |
* @uses apply_filters() Calls 'doing_it_wrong_trigger_error' and expects boolean value of true to do |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2744 |
* trigger or false to not trigger error. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2745 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2746 |
* @param string $function The function that was called. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2747 |
* @param string $message A message explaining what has been done incorrectly. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2748 |
* @param string $version The version of WordPress where the message was added. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2749 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2750 |
function _doing_it_wrong( $function, $message, $version ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2751 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2752 |
do_action( 'doing_it_wrong_run', $function, $message, $version ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2753 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2754 |
// Allow plugin to filter the output error trigger |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2755 |
if ( WP_DEBUG && apply_filters( 'doing_it_wrong_trigger_error', true ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2756 |
$version = is_null( $version ) ? '' : sprintf( __( '(This message was added in version %s.)' ), $version ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2757 |
$message .= ' ' . __( 'Please see <a href="http://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information.' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2758 |
trigger_error( sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ), $function, $message, $version ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2759 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2760 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2761 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2762 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2763 |
* Is the server running earlier than 1.5.0 version of lighttpd? |
136 | 2764 |
* |
2765 |
* @since 2.5.0 |
|
2766 |
* |
|
2767 |
* @return bool Whether the server is running lighttpd < 1.5.0 |
|
2768 |
*/ |
|
2769 |
function is_lighttpd_before_150() { |
|
2770 |
$server_parts = explode( '/', isset( $_SERVER['SERVER_SOFTWARE'] )? $_SERVER['SERVER_SOFTWARE'] : '' ); |
|
2771 |
$server_parts[1] = isset( $server_parts[1] )? $server_parts[1] : ''; |
|
2772 |
return 'lighttpd' == $server_parts[0] && -1 == version_compare( $server_parts[1], '1.5.0' ); |
|
2773 |
} |
|
2774 |
||
2775 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2776 |
* Does the specified module exist in the Apache config? |
136 | 2777 |
* |
2778 |
* @since 2.5.0 |
|
2779 |
* |
|
2780 |
* @param string $mod e.g. mod_rewrite |
|
2781 |
* @param bool $default The default return value if the module is not found |
|
2782 |
* @return bool |
|
2783 |
*/ |
|
2784 |
function apache_mod_loaded($mod, $default = false) { |
|
2785 |
global $is_apache; |
|
2786 |
||
2787 |
if ( !$is_apache ) |
|
2788 |
return false; |
|
2789 |
||
2790 |
if ( function_exists('apache_get_modules') ) { |
|
2791 |
$mods = apache_get_modules(); |
|
2792 |
if ( in_array($mod, $mods) ) |
|
2793 |
return true; |
|
2794 |
} elseif ( function_exists('phpinfo') ) { |
|
2795 |
ob_start(); |
|
2796 |
phpinfo(8); |
|
2797 |
$phpinfo = ob_get_clean(); |
|
2798 |
if ( false !== strpos($phpinfo, $mod) ) |
|
2799 |
return true; |
|
2800 |
} |
|
2801 |
return $default; |
|
2802 |
} |
|
2803 |
||
2804 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2805 |
* Check if IIS 7 supports pretty permalinks. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2806 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2807 |
* @since 2.8.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2808 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2809 |
* @return bool |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2810 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2811 |
function iis7_supports_permalinks() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2812 |
global $is_iis7; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2813 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2814 |
$supports_permalinks = false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2815 |
if ( $is_iis7 ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2816 |
/* First we check if the DOMDocument class exists. If it does not exist, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2817 |
* which is the case for PHP 4.X, then we cannot easily update the xml configuration file, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2818 |
* hence we just bail out and tell user that pretty permalinks cannot be used. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2819 |
* This is not a big issue because PHP 4.X is going to be deprecated and for IIS it |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2820 |
* is recommended to use PHP 5.X NTS. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2821 |
* Next we check if the URL Rewrite Module 1.1 is loaded and enabled for the web site. When |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2822 |
* URL Rewrite 1.1 is loaded it always sets a server variable called 'IIS_UrlRewriteModule'. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2823 |
* Lastly we make sure that PHP is running via FastCGI. This is important because if it runs |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2824 |
* via ISAPI then pretty permalinks will not work. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2825 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2826 |
$supports_permalinks = class_exists('DOMDocument') && isset($_SERVER['IIS_UrlRewriteModule']) && ( php_sapi_name() == 'cgi-fcgi' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2827 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2828 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2829 |
return apply_filters('iis7_supports_permalinks', $supports_permalinks); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2830 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2831 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2832 |
/** |
136 | 2833 |
* File validates against allowed set of defined rules. |
2834 |
* |
|
2835 |
* A return value of '1' means that the $file contains either '..' or './'. A |
|
2836 |
* return value of '2' means that the $file contains ':' after the first |
|
2837 |
* character. A return value of '3' means that the file is not in the allowed |
|
2838 |
* files list. |
|
2839 |
* |
|
2840 |
* @since 1.2.0 |
|
2841 |
* |
|
2842 |
* @param string $file File path. |
|
2843 |
* @param array $allowed_files List of allowed files. |
|
2844 |
* @return int 0 means nothing is wrong, greater than 0 means something was wrong. |
|
2845 |
*/ |
|
2846 |
function validate_file( $file, $allowed_files = '' ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2847 |
if ( false !== strpos( $file, '..' ) ) |
136 | 2848 |
return 1; |
2849 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2850 |
if ( false !== strpos( $file, './' ) ) |
136 | 2851 |
return 1; |
2852 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2853 |
if ( ! empty( $allowed_files ) && ! in_array( $file, $allowed_files ) ) |
136 | 2854 |
return 3; |
2855 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2856 |
if (':' == substr( $file, 1, 1 ) ) |
136 | 2857 |
return 2; |
2858 |
||
2859 |
return 0; |
|
2860 |
} |
|
2861 |
||
2862 |
/** |
|
2863 |
* Determine if SSL is used. |
|
2864 |
* |
|
2865 |
* @since 2.6.0 |
|
2866 |
* |
|
2867 |
* @return bool True if SSL, false if not used. |
|
2868 |
*/ |
|
2869 |
function is_ssl() { |
|
2870 |
if ( isset($_SERVER['HTTPS']) ) { |
|
2871 |
if ( 'on' == strtolower($_SERVER['HTTPS']) ) |
|
2872 |
return true; |
|
2873 |
if ( '1' == $_SERVER['HTTPS'] ) |
|
2874 |
return true; |
|
2875 |
} elseif ( isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] ) ) { |
|
2876 |
return true; |
|
2877 |
} |
|
2878 |
return false; |
|
2879 |
} |
|
2880 |
||
2881 |
/** |
|
2882 |
* Whether SSL login should be forced. |
|
2883 |
* |
|
2884 |
* @since 2.6.0 |
|
2885 |
* |
|
2886 |
* @param string|bool $force Optional. |
|
2887 |
* @return bool True if forced, false if not forced. |
|
2888 |
*/ |
|
2889 |
function force_ssl_login( $force = null ) { |
|
2890 |
static $forced = false; |
|
2891 |
||
2892 |
if ( !is_null( $force ) ) { |
|
2893 |
$old_forced = $forced; |
|
2894 |
$forced = $force; |
|
2895 |
return $old_forced; |
|
2896 |
} |
|
2897 |
||
2898 |
return $forced; |
|
2899 |
} |
|
2900 |
||
2901 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2902 |
* Whether to force SSL used for the Administration Screens. |
136 | 2903 |
* |
2904 |
* @since 2.6.0 |
|
2905 |
* |
|
2906 |
* @param string|bool $force |
|
2907 |
* @return bool True if forced, false if not forced. |
|
2908 |
*/ |
|
2909 |
function force_ssl_admin( $force = null ) { |
|
2910 |
static $forced = false; |
|
2911 |
||
2912 |
if ( !is_null( $force ) ) { |
|
2913 |
$old_forced = $forced; |
|
2914 |
$forced = $force; |
|
2915 |
return $old_forced; |
|
2916 |
} |
|
2917 |
||
2918 |
return $forced; |
|
2919 |
} |
|
2920 |
||
2921 |
/** |
|
2922 |
* Guess the URL for the site. |
|
2923 |
* |
|
2924 |
* Will remove wp-admin links to retrieve only return URLs not in the wp-admin |
|
2925 |
* directory. |
|
2926 |
* |
|
2927 |
* @since 2.6.0 |
|
2928 |
* |
|
2929 |
* @return string |
|
2930 |
*/ |
|
2931 |
function wp_guess_url() { |
|
2932 |
if ( defined('WP_SITEURL') && '' != WP_SITEURL ) { |
|
2933 |
$url = WP_SITEURL; |
|
2934 |
} else { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2935 |
$schema = is_ssl() ? 'https://' : 'http://'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2936 |
$url = preg_replace('#/(wp-admin/.*|wp-login.php)#i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); |
136 | 2937 |
} |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2938 |
return rtrim($url, '/'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2939 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2940 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2941 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2942 |
* Temporarily suspend cache additions. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2943 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2944 |
* Stops more data being added to the cache, but still allows cache retrieval. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2945 |
* This is useful for actions, such as imports, when a lot of data would otherwise |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2946 |
* be almost uselessly added to the cache. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2947 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2948 |
* Suspension lasts for a single page load at most. Remember to call this |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2949 |
* function again if you wish to re-enable cache adds earlier. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2950 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2951 |
* @since 3.3.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2952 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2953 |
* @param bool $suspend Optional. Suspends additions if true, re-enables them if false. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2954 |
* @return bool The current suspend setting |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2955 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2956 |
function wp_suspend_cache_addition( $suspend = null ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2957 |
static $_suspend = false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2958 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2959 |
if ( is_bool( $suspend ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2960 |
$_suspend = $suspend; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2961 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2962 |
return $_suspend; |
136 | 2963 |
} |
2964 |
||
2965 |
/** |
|
2966 |
* Suspend cache invalidation. |
|
2967 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2968 |
* Turns cache invalidation on and off. Useful during imports where you don't wont to do invalidations |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2969 |
* every time a post is inserted. Callers must be sure that what they are doing won't lead to an inconsistent |
136 | 2970 |
* cache when invalidation is suspended. |
2971 |
* |
|
2972 |
* @since 2.7.0 |
|
2973 |
* |
|
2974 |
* @param bool $suspend Whether to suspend or enable cache invalidation |
|
2975 |
* @return bool The current suspend setting |
|
2976 |
*/ |
|
2977 |
function wp_suspend_cache_invalidation($suspend = true) { |
|
2978 |
global $_wp_suspend_cache_invalidation; |
|
2979 |
||
2980 |
$current_suspend = $_wp_suspend_cache_invalidation; |
|
2981 |
$_wp_suspend_cache_invalidation = $suspend; |
|
2982 |
return $current_suspend; |
|
2983 |
} |
|
2984 |
||
2985 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2986 |
* Is main site? |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2987 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2988 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2989 |
* @since 3.0.0 |
136 | 2990 |
* @package WordPress |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2991 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2992 |
* @param int $blog_id optional blog id to test (default current blog) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2993 |
* @return bool True if not multisite or $blog_id is main site |
136 | 2994 |
*/ |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2995 |
function is_main_site( $blog_id = '' ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2996 |
global $current_site, $current_blog; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2997 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2998 |
if ( !is_multisite() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2999 |
return true; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3000 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3001 |
if ( !$blog_id ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3002 |
$blog_id = $current_blog->blog_id; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3003 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3004 |
return $blog_id == $current_site->blog_id; |
136 | 3005 |
} |
3006 |
||
3007 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3008 |
* Whether global terms are enabled. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3009 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3010 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3011 |
* @since 3.0.0 |
136 | 3012 |
* @package WordPress |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3013 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3014 |
* @return bool True if multisite and global terms enabled |
136 | 3015 |
*/ |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3016 |
function global_terms_enabled() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3017 |
if ( ! is_multisite() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3018 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3019 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3020 |
static $global_terms = null; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3021 |
if ( is_null( $global_terms ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3022 |
$filter = apply_filters( 'global_terms_enabled', null ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3023 |
if ( ! is_null( $filter ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3024 |
$global_terms = (bool) $filter; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3025 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3026 |
$global_terms = (bool) get_site_option( 'global_terms_enabled', false ); |
136 | 3027 |
} |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3028 |
return $global_terms; |
136 | 3029 |
} |
3030 |
||
3031 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3032 |
* gmt_offset modification for smart timezone handling. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3033 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3034 |
* Overrides the gmt_offset option if we have a timezone_string available. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3035 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3036 |
* @since 2.8.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3037 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3038 |
* @return float|bool |
136 | 3039 |
*/ |
3040 |
function wp_timezone_override_offset() { |
|
3041 |
if ( !$timezone_string = get_option( 'timezone_string' ) ) { |
|
3042 |
return false; |
|
3043 |
} |
|
3044 |
||
3045 |
$timezone_object = timezone_open( $timezone_string ); |
|
3046 |
$datetime_object = date_create(); |
|
3047 |
if ( false === $timezone_object || false === $datetime_object ) { |
|
3048 |
return false; |
|
3049 |
} |
|
3050 |
return round( timezone_offset_get( $timezone_object, $datetime_object ) / 3600, 2 ); |
|
3051 |
} |
|
3052 |
||
3053 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3054 |
* {@internal Missing Short Description}} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3055 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3056 |
* @since 2.9.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3057 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3058 |
* @param unknown_type $a |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3059 |
* @param unknown_type $b |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3060 |
* @return int |
136 | 3061 |
*/ |
3062 |
function _wp_timezone_choice_usort_callback( $a, $b ) { |
|
3063 |
// Don't use translated versions of Etc |
|
3064 |
if ( 'Etc' === $a['continent'] && 'Etc' === $b['continent'] ) { |
|
3065 |
// Make the order of these more like the old dropdown |
|
3066 |
if ( 'GMT+' === substr( $a['city'], 0, 4 ) && 'GMT+' === substr( $b['city'], 0, 4 ) ) { |
|
3067 |
return -1 * ( strnatcasecmp( $a['city'], $b['city'] ) ); |
|
3068 |
} |
|
3069 |
if ( 'UTC' === $a['city'] ) { |
|
3070 |
if ( 'GMT+' === substr( $b['city'], 0, 4 ) ) { |
|
3071 |
return 1; |
|
3072 |
} |
|
3073 |
return -1; |
|
3074 |
} |
|
3075 |
if ( 'UTC' === $b['city'] ) { |
|
3076 |
if ( 'GMT+' === substr( $a['city'], 0, 4 ) ) { |
|
3077 |
return -1; |
|
3078 |
} |
|
3079 |
return 1; |
|
3080 |
} |
|
3081 |
return strnatcasecmp( $a['city'], $b['city'] ); |
|
3082 |
} |
|
3083 |
if ( $a['t_continent'] == $b['t_continent'] ) { |
|
3084 |
if ( $a['t_city'] == $b['t_city'] ) { |
|
3085 |
return strnatcasecmp( $a['t_subcity'], $b['t_subcity'] ); |
|
3086 |
} |
|
3087 |
return strnatcasecmp( $a['t_city'], $b['t_city'] ); |
|
3088 |
} else { |
|
3089 |
// Force Etc to the bottom of the list |
|
3090 |
if ( 'Etc' === $a['continent'] ) { |
|
3091 |
return 1; |
|
3092 |
} |
|
3093 |
if ( 'Etc' === $b['continent'] ) { |
|
3094 |
return -1; |
|
3095 |
} |
|
3096 |
return strnatcasecmp( $a['t_continent'], $b['t_continent'] ); |
|
3097 |
} |
|
3098 |
} |
|
3099 |
||
3100 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3101 |
* Gives a nicely formatted list of timezone strings. // temporary! Not in final |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3102 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3103 |
* @since 2.9.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3104 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3105 |
* @param string $selected_zone Selected Zone |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3106 |
* @return string |
136 | 3107 |
*/ |
3108 |
function wp_timezone_choice( $selected_zone ) { |
|
3109 |
static $mo_loaded = false; |
|
3110 |
||
3111 |
$continents = array( 'Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific'); |
|
3112 |
||
3113 |
// Load translations for continents and cities |
|
3114 |
if ( !$mo_loaded ) { |
|
3115 |
$locale = get_locale(); |
|
3116 |
$mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
3117 |
load_textdomain( 'continents-cities', $mofile ); |
|
3118 |
$mo_loaded = true; |
|
3119 |
} |
|
3120 |
||
3121 |
$zonen = array(); |
|
3122 |
foreach ( timezone_identifiers_list() as $zone ) { |
|
3123 |
$zone = explode( '/', $zone ); |
|
3124 |
if ( !in_array( $zone[0], $continents ) ) { |
|
3125 |
continue; |
|
3126 |
} |
|
3127 |
||
3128 |
// This determines what gets set and translated - we don't translate Etc/* strings here, they are done later |
|
3129 |
$exists = array( |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3130 |
0 => ( isset( $zone[0] ) && $zone[0] ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3131 |
1 => ( isset( $zone[1] ) && $zone[1] ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3132 |
2 => ( isset( $zone[2] ) && $zone[2] ), |
136 | 3133 |
); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3134 |
$exists[3] = ( $exists[0] && 'Etc' !== $zone[0] ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3135 |
$exists[4] = ( $exists[1] && $exists[3] ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3136 |
$exists[5] = ( $exists[2] && $exists[3] ); |
136 | 3137 |
|
3138 |
$zonen[] = array( |
|
3139 |
'continent' => ( $exists[0] ? $zone[0] : '' ), |
|
3140 |
'city' => ( $exists[1] ? $zone[1] : '' ), |
|
3141 |
'subcity' => ( $exists[2] ? $zone[2] : '' ), |
|
3142 |
't_continent' => ( $exists[3] ? translate( str_replace( '_', ' ', $zone[0] ), 'continents-cities' ) : '' ), |
|
3143 |
't_city' => ( $exists[4] ? translate( str_replace( '_', ' ', $zone[1] ), 'continents-cities' ) : '' ), |
|
3144 |
't_subcity' => ( $exists[5] ? translate( str_replace( '_', ' ', $zone[2] ), 'continents-cities' ) : '' ) |
|
3145 |
); |
|
3146 |
} |
|
3147 |
usort( $zonen, '_wp_timezone_choice_usort_callback' ); |
|
3148 |
||
3149 |
$structure = array(); |
|
3150 |
||
3151 |
if ( empty( $selected_zone ) ) { |
|
3152 |
$structure[] = '<option selected="selected" value="">' . __( 'Select a city' ) . '</option>'; |
|
3153 |
} |
|
3154 |
||
3155 |
foreach ( $zonen as $key => $zone ) { |
|
3156 |
// Build value in an array to join later |
|
3157 |
$value = array( $zone['continent'] ); |
|
3158 |
||
3159 |
if ( empty( $zone['city'] ) ) { |
|
3160 |
// It's at the continent level (generally won't happen) |
|
3161 |
$display = $zone['t_continent']; |
|
3162 |
} else { |
|
3163 |
// It's inside a continent group |
|
3164 |
||
3165 |
// Continent optgroup |
|
3166 |
if ( !isset( $zonen[$key - 1] ) || $zonen[$key - 1]['continent'] !== $zone['continent'] ) { |
|
3167 |
$label = $zone['t_continent']; |
|
3168 |
$structure[] = '<optgroup label="'. esc_attr( $label ) .'">'; |
|
3169 |
} |
|
3170 |
||
3171 |
// Add the city to the value |
|
3172 |
$value[] = $zone['city']; |
|
3173 |
||
3174 |
$display = $zone['t_city']; |
|
3175 |
if ( !empty( $zone['subcity'] ) ) { |
|
3176 |
// Add the subcity to the value |
|
3177 |
$value[] = $zone['subcity']; |
|
3178 |
$display .= ' - ' . $zone['t_subcity']; |
|
3179 |
} |
|
3180 |
} |
|
3181 |
||
3182 |
// Build the value |
|
3183 |
$value = join( '/', $value ); |
|
3184 |
$selected = ''; |
|
3185 |
if ( $value === $selected_zone ) { |
|
3186 |
$selected = 'selected="selected" '; |
|
3187 |
} |
|
3188 |
$structure[] = '<option ' . $selected . 'value="' . esc_attr( $value ) . '">' . esc_html( $display ) . "</option>"; |
|
3189 |
||
3190 |
// Close continent optgroup |
|
3191 |
if ( !empty( $zone['city'] ) && ( !isset($zonen[$key + 1]) || (isset( $zonen[$key + 1] ) && $zonen[$key + 1]['continent'] !== $zone['continent']) ) ) { |
|
3192 |
$structure[] = '</optgroup>'; |
|
3193 |
} |
|
3194 |
} |
|
3195 |
||
3196 |
// Do UTC |
|
3197 |
$structure[] = '<optgroup label="'. esc_attr__( 'UTC' ) .'">'; |
|
3198 |
$selected = ''; |
|
3199 |
if ( 'UTC' === $selected_zone ) |
|
3200 |
$selected = 'selected="selected" '; |
|
3201 |
$structure[] = '<option ' . $selected . 'value="' . esc_attr( 'UTC' ) . '">' . __('UTC') . '</option>'; |
|
3202 |
$structure[] = '</optgroup>'; |
|
3203 |
||
3204 |
// Do manual UTC offsets |
|
3205 |
$structure[] = '<optgroup label="'. esc_attr__( 'Manual Offsets' ) .'">'; |
|
3206 |
$offset_range = array (-12, -11.5, -11, -10.5, -10, -9.5, -9, -8.5, -8, -7.5, -7, -6.5, -6, -5.5, -5, -4.5, -4, -3.5, -3, -2.5, -2, -1.5, -1, -0.5, |
|
3207 |
0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 5.75, 6, 6.5, 7, 7.5, 8, 8.5, 8.75, 9, 9.5, 10, 10.5, 11, 11.5, 12, 12.75, 13, 13.75, 14); |
|
3208 |
foreach ( $offset_range as $offset ) { |
|
3209 |
if ( 0 <= $offset ) |
|
3210 |
$offset_name = '+' . $offset; |
|
3211 |
else |
|
3212 |
$offset_name = (string) $offset; |
|
3213 |
||
3214 |
$offset_value = $offset_name; |
|
3215 |
$offset_name = str_replace(array('.25','.5','.75'), array(':15',':30',':45'), $offset_name); |
|
3216 |
$offset_name = 'UTC' . $offset_name; |
|
3217 |
$offset_value = 'UTC' . $offset_value; |
|
3218 |
$selected = ''; |
|
3219 |
if ( $offset_value === $selected_zone ) |
|
3220 |
$selected = 'selected="selected" '; |
|
3221 |
$structure[] = '<option ' . $selected . 'value="' . esc_attr( $offset_value ) . '">' . esc_html( $offset_name ) . "</option>"; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3222 |
|
136 | 3223 |
} |
3224 |
$structure[] = '</optgroup>'; |
|
3225 |
||
3226 |
return join( "\n", $structure ); |
|
3227 |
} |
|
3228 |
||
3229 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3230 |
* Strip close comment and close php tags from file headers used by WP. |
136 | 3231 |
* See http://core.trac.wordpress.org/ticket/8497 |
3232 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3233 |
* @since 2.8.0 |
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 |
* @param string $str |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3236 |
* @return string |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3237 |
*/ |
136 | 3238 |
function _cleanup_header_comment($str) { |
3239 |
return trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $str)); |
|
3240 |
} |
|
3241 |
||
3242 |
/** |
|
3243 |
* Permanently deletes posts, pages, attachments, and comments which have been in the trash for EMPTY_TRASH_DAYS. |
|
3244 |
* |
|
3245 |
* @since 2.9.0 |
|
3246 |
*/ |
|
3247 |
function wp_scheduled_delete() { |
|
3248 |
global $wpdb; |
|
3249 |
||
3250 |
$delete_timestamp = time() - (60*60*24*EMPTY_TRASH_DAYS); |
|
3251 |
||
3252 |
$posts_to_delete = $wpdb->get_results($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_trash_meta_time' AND meta_value < '%d'", $delete_timestamp), ARRAY_A); |
|
3253 |
||
3254 |
foreach ( (array) $posts_to_delete as $post ) { |
|
3255 |
$post_id = (int) $post['post_id']; |
|
3256 |
if ( !$post_id ) |
|
3257 |
continue; |
|
3258 |
||
3259 |
$del_post = get_post($post_id); |
|
3260 |
||
3261 |
if ( !$del_post || 'trash' != $del_post->post_status ) { |
|
3262 |
delete_post_meta($post_id, '_wp_trash_meta_status'); |
|
3263 |
delete_post_meta($post_id, '_wp_trash_meta_time'); |
|
3264 |
} else { |
|
3265 |
wp_delete_post($post_id); |
|
3266 |
} |
|
3267 |
} |
|
3268 |
||
3269 |
$comments_to_delete = $wpdb->get_results($wpdb->prepare("SELECT comment_id FROM $wpdb->commentmeta WHERE meta_key = '_wp_trash_meta_time' AND meta_value < '%d'", $delete_timestamp), ARRAY_A); |
|
3270 |
||
3271 |
foreach ( (array) $comments_to_delete as $comment ) { |
|
3272 |
$comment_id = (int) $comment['comment_id']; |
|
3273 |
if ( !$comment_id ) |
|
3274 |
continue; |
|
3275 |
||
3276 |
$del_comment = get_comment($comment_id); |
|
3277 |
||
3278 |
if ( !$del_comment || 'trash' != $del_comment->comment_approved ) { |
|
3279 |
delete_comment_meta($comment_id, '_wp_trash_meta_time'); |
|
3280 |
delete_comment_meta($comment_id, '_wp_trash_meta_status'); |
|
3281 |
} else { |
|
3282 |
wp_delete_comment($comment_id); |
|
3283 |
} |
|
3284 |
} |
|
3285 |
} |
|
3286 |
||
3287 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3288 |
* Retrieve metadata from a file. |
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 |
* Searches for metadata in the first 8kiB of a file, such as a plugin or theme. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3291 |
* Each piece of metadata must be on its own line. Fields can not span multiple |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3292 |
* lines, the value will get cut at the end of the first line. |
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 |
* If the file data is not within that first 8kiB, then the author should correct |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3295 |
* their plugin file and move the data headers to the top. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3296 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3297 |
* @see http://codex.wordpress.org/File_Header |
136 | 3298 |
* |
3299 |
* @since 2.9.0 |
|
3300 |
* @param string $file Path to the file |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3301 |
* @param array $default_headers List of headers, in the format array('HeaderKey' => 'Header Name') |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3302 |
* @param string $context If specified adds filter hook "extra_{$context}_headers" |
136 | 3303 |
*/ |
3304 |
function get_file_data( $file, $default_headers, $context = '' ) { |
|
3305 |
// We don't need to write to the file, so just open for reading. |
|
3306 |
$fp = fopen( $file, 'r' ); |
|
3307 |
||
3308 |
// Pull only the first 8kiB of the file in. |
|
3309 |
$file_data = fread( $fp, 8192 ); |
|
3310 |
||
3311 |
// PHP will close file handle, but we are good citizens. |
|
3312 |
fclose( $fp ); |
|
3313 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3314 |
// Make sure we catch CR-only line endings. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3315 |
$file_data = str_replace( "\r", "\n", $file_data ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3316 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3317 |
if ( $context && $extra_headers = apply_filters( "extra_{$context}_headers", array() ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3318 |
$extra_headers = array_combine( $extra_headers, $extra_headers ); // keys equal values |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3319 |
$all_headers = array_merge( $extra_headers, (array) $default_headers ); |
136 | 3320 |
} else { |
3321 |
$all_headers = $default_headers; |
|
3322 |
} |
|
3323 |
||
3324 |
foreach ( $all_headers as $field => $regex ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3325 |
if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, $match ) && $match[1] ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3326 |
$all_headers[ $field ] = _cleanup_header_comment( $match[1] ); |
136 | 3327 |
else |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3328 |
$all_headers[ $field ] = ''; |
136 | 3329 |
} |
3330 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3331 |
return $all_headers; |
136 | 3332 |
} |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3333 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3334 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3335 |
* Used internally to tidy up the search terms. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3336 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3337 |
* @access private |
136 | 3338 |
* @since 2.9.0 |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3339 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3340 |
* @param string $t |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3341 |
* @return string |
136 | 3342 |
*/ |
3343 |
function _search_terms_tidy($t) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3344 |
return trim($t, "\"'\n\r "); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3345 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3346 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3347 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3348 |
* Returns true. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3349 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3350 |
* Useful for returning true to filters easily. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3351 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3352 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3353 |
* @see __return_false() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3354 |
* @return bool true |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3355 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3356 |
function __return_true() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3357 |
return true; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3358 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3359 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3360 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3361 |
* Returns false. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3362 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3363 |
* Useful for returning false to filters easily. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3364 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3365 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3366 |
* @see __return_true() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3367 |
* @return bool false |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3368 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3369 |
function __return_false() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3370 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3371 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3372 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3373 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3374 |
* Returns 0. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3375 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3376 |
* Useful for returning 0 to filters easily. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3377 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3378 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3379 |
* @see __return_zero() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3380 |
* @return int 0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3381 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3382 |
function __return_zero() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3383 |
return 0; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3384 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3385 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3386 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3387 |
* Returns an empty array. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3388 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3389 |
* Useful for returning an empty array to filters easily. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3390 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3391 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3392 |
* @see __return_zero() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3393 |
* @return array Empty array |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3394 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3395 |
function __return_empty_array() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3396 |
return array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3397 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3398 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3399 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3400 |
* Returns null. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3401 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3402 |
* Useful for returning null to filters easily. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3403 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3404 |
* @since 3.4.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3405 |
* @return null |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3406 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3407 |
function __return_null() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3408 |
return null; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3409 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3410 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3411 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3412 |
* Send a HTTP header to disable content type sniffing in browsers which support it. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3413 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3414 |
* @link http://blogs.msdn.com/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3415 |
* @link http://src.chromium.org/viewvc/chrome?view=rev&revision=6985 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3416 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3417 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3418 |
* @return none |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3419 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3420 |
function send_nosniff_header() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3421 |
@header( 'X-Content-Type-Options: nosniff' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3422 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3423 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3424 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3425 |
* Returns a MySQL expression for selecting the week number based on the start_of_week option. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3426 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3427 |
* @internal |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3428 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3429 |
* @param string $column |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3430 |
* @return string |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3431 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3432 |
function _wp_mysql_week( $column ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3433 |
switch ( $start_of_week = (int) get_option( 'start_of_week' ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3434 |
default : |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3435 |
case 0 : |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3436 |
return "WEEK( $column, 0 )"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3437 |
case 1 : |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3438 |
return "WEEK( $column, 1 )"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3439 |
case 2 : |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3440 |
case 3 : |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3441 |
case 4 : |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3442 |
case 5 : |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3443 |
case 6 : |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3444 |
return "WEEK( DATE_SUB( $column, INTERVAL $start_of_week DAY ), 0 )"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3445 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3446 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3447 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3448 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3449 |
* Finds hierarchy loops using a callback function that maps object IDs to parent IDs. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3450 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3451 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3452 |
* @access private |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3453 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3454 |
* @param callback $callback function that accepts ( ID, $callback_args ) and outputs parent_ID |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3455 |
* @param int $start The ID to start the loop check at |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3456 |
* @param int $start_parent the parent_ID of $start to use instead of calling $callback( $start ). Use null to always use $callback |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3457 |
* @param array $callback_args optional additional arguments to send to $callback |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3458 |
* @return array IDs of all members of loop |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3459 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3460 |
function wp_find_hierarchy_loop( $callback, $start, $start_parent, $callback_args = array() ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3461 |
$override = is_null( $start_parent ) ? array() : array( $start => $start_parent ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3462 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3463 |
if ( !$arbitrary_loop_member = wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override, $callback_args ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3464 |
return array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3465 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3466 |
return wp_find_hierarchy_loop_tortoise_hare( $callback, $arbitrary_loop_member, $override, $callback_args, true ); |
136 | 3467 |
} |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3468 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3469 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3470 |
* Uses the "The Tortoise and the Hare" algorithm to detect loops. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3471 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3472 |
* For every step of the algorithm, the hare takes two steps and the tortoise one. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3473 |
* If the hare ever laps the tortoise, there must be a loop. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3474 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3475 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3476 |
* @access private |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3477 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3478 |
* @param callback $callback function that accepts ( ID, callback_arg, ... ) and outputs parent_ID |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3479 |
* @param int $start The ID to start the loop check at |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3480 |
* @param array $override an array of ( ID => parent_ID, ... ) to use instead of $callback |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3481 |
* @param array $callback_args optional additional arguments to send to $callback |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3482 |
* @param bool $_return_loop Return loop members or just detect presence of loop? |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3483 |
* Only set to true if you already know the given $start is part of a loop |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3484 |
* (otherwise the returned array might include branches) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3485 |
* @return mixed scalar ID of some arbitrary member of the loop, or array of IDs of all members of loop if $_return_loop |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3486 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3487 |
function wp_find_hierarchy_loop_tortoise_hare( $callback, $start, $override = array(), $callback_args = array(), $_return_loop = false ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3488 |
$tortoise = $hare = $evanescent_hare = $start; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3489 |
$return = array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3490 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3491 |
// Set evanescent_hare to one past hare |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3492 |
// Increment hare two steps |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3493 |
while ( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3494 |
$tortoise |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3495 |
&& |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3496 |
( $evanescent_hare = isset( $override[$hare] ) ? $override[$hare] : call_user_func_array( $callback, array_merge( array( $hare ), $callback_args ) ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3497 |
&& |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3498 |
( $hare = isset( $override[$evanescent_hare] ) ? $override[$evanescent_hare] : call_user_func_array( $callback, array_merge( array( $evanescent_hare ), $callback_args ) ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3499 |
) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3500 |
if ( $_return_loop ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3501 |
$return[$tortoise] = $return[$evanescent_hare] = $return[$hare] = true; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3502 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3503 |
// tortoise got lapped - must be a loop |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3504 |
if ( $tortoise == $evanescent_hare || $tortoise == $hare ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3505 |
return $_return_loop ? $return : $tortoise; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3506 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3507 |
// Increment tortoise by one step |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3508 |
$tortoise = isset( $override[$tortoise] ) ? $override[$tortoise] : call_user_func_array( $callback, array_merge( array( $tortoise ), $callback_args ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3509 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3510 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3511 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3512 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3513 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3514 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3515 |
* Send a HTTP header to limit rendering of pages to same origin iframes. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3516 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3517 |
* @link https://developer.mozilla.org/en/the_x-frame-options_response_header |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3518 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3519 |
* @since 3.1.3 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3520 |
* @return none |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3521 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3522 |
function send_frame_options_header() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3523 |
@header( 'X-Frame-Options: SAMEORIGIN' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3524 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3525 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3526 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3527 |
* Retrieve a list of protocols to allow in HTML attributes. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3528 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3529 |
* @since 3.3.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3530 |
* @see wp_kses() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3531 |
* @see esc_url() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3532 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3533 |
* @return array Array of allowed protocols |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3534 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3535 |
function wp_allowed_protocols() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3536 |
static $protocols; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3537 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3538 |
if ( empty( $protocols ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3539 |
$protocols = array( 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3540 |
$protocols = apply_filters( 'kses_allowed_protocols', $protocols ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3541 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3542 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3543 |
return $protocols; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3544 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3545 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3546 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3547 |
* Return a comma separated string of functions that have been called to get to the current point in code. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3548 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3549 |
* @link http://core.trac.wordpress.org/ticket/19589 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3550 |
* @since 3.4 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3551 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3552 |
* @param string $ignore_class A class to ignore all function calls within - useful when you want to just give info about the callee |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3553 |
* @param int $skip_frames A number of stack frames to skip - useful for unwinding back to the source of the issue |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3554 |
* @param bool $pretty Whether or not you want a comma separated string or raw array returned |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3555 |
* @return string|array Either a string containing a reversed comma separated trace or an array of individual calls. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3556 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3557 |
function wp_debug_backtrace_summary( $ignore_class = null, $skip_frames = 0, $pretty = true ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3558 |
if ( version_compare( PHP_VERSION, '5.2.5', '>=' ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3559 |
$trace = debug_backtrace( false ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3560 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3561 |
$trace = debug_backtrace(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3562 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3563 |
$caller = array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3564 |
$check_class = ! is_null( $ignore_class ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3565 |
$skip_frames++; // skip this function |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3566 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3567 |
foreach ( $trace as $call ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3568 |
if ( $skip_frames > 0 ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3569 |
$skip_frames--; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3570 |
} elseif ( isset( $call['class'] ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3571 |
if ( $check_class && $ignore_class == $call['class'] ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3572 |
continue; // Filter out calls |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3573 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3574 |
$caller[] = "{$call['class']}{$call['type']}{$call['function']}"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3575 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3576 |
if ( in_array( $call['function'], array( 'do_action', 'apply_filters' ) ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3577 |
$caller[] = "{$call['function']}('{$call['args'][0]}')"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3578 |
} elseif ( in_array( $call['function'], array( 'include', 'include_once', 'require', 'require_once' ) ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3579 |
$caller[] = $call['function'] . "('" . str_replace( array( WP_CONTENT_DIR, ABSPATH ) , '', $call['args'][0] ) . "')"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3580 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3581 |
$caller[] = $call['function']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3582 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3583 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3584 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3585 |
if ( $pretty ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3586 |
return join( ', ', array_reverse( $caller ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3587 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3588 |
return $caller; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3589 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3590 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3591 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3592 |
* Retrieve ids that are not already present in the cache |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3593 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3594 |
* @since 3.4.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3595 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3596 |
* @param array $object_ids ID list |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3597 |
* @param string $cache_key The cache bucket to check against |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3598 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3599 |
* @return array |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3600 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3601 |
function _get_non_cached_ids( $object_ids, $cache_key ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3602 |
$clean = array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3603 |
foreach ( $object_ids as $id ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3604 |
$id = (int) $id; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3605 |
if ( !wp_cache_get( $id, $cache_key ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3606 |
$clean[] = $id; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3607 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3608 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3609 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3610 |
return $clean; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3611 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3612 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3613 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3614 |
* Test if the current device has the capability to upload files. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3615 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3616 |
* @since 3.4.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3617 |
* @access private |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3618 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3619 |
* @return bool true|false |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3620 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3621 |
function _device_can_upload() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3622 |
if ( ! wp_is_mobile() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3623 |
return true; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3624 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3625 |
$ua = $_SERVER['HTTP_USER_AGENT']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3626 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3627 |
if ( strpos($ua, 'iPhone') !== false |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3628 |
|| strpos($ua, 'iPad') !== false |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3629 |
|| strpos($ua, 'iPod') !== false ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3630 |
return preg_match( '#OS ([\d_]+) like Mac OS X#', $ua, $version ) && version_compare( $version[1], '6', '>=' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3631 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3632 |
return true; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3633 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3634 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
3635 |