author | Anthony Ly <anthonyly.com@gmail.com> |
Tue, 11 Dec 2012 12:47:47 -0800 | |
changeset 198 | dcf82fd50cc6 |
parent 194 | 32102edaa81b |
child 204 | 09a1c134465b |
permissions | -rw-r--r-- |
136 | 1 |
<?php |
2 |
/** |
|
3 |
* Misc WordPress Administration API. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Administration |
|
7 |
*/ |
|
8 |
||
9 |
/** |
|
10 |
* {@internal Missing Short Description}} |
|
11 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
12 |
* @since 2.0.0 |
136 | 13 |
* |
14 |
* @return unknown |
|
15 |
*/ |
|
16 |
function got_mod_rewrite() { |
|
17 |
$got_rewrite = apache_mod_loaded('mod_rewrite', true); |
|
18 |
return apply_filters('got_rewrite', $got_rewrite); |
|
19 |
} |
|
20 |
||
21 |
/** |
|
22 |
* {@internal Missing Short Description}} |
|
23 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
24 |
* @since 1.5.0 |
136 | 25 |
* |
26 |
* @param unknown_type $filename |
|
27 |
* @param unknown_type $marker |
|
28 |
* @return array An array of strings from a file (.htaccess ) from between BEGIN and END markers. |
|
29 |
*/ |
|
30 |
function extract_from_markers( $filename, $marker ) { |
|
31 |
$result = array (); |
|
32 |
||
33 |
if (!file_exists( $filename ) ) { |
|
34 |
return $result; |
|
35 |
} |
|
36 |
||
37 |
if ( $markerdata = explode( "\n", implode( '', file( $filename ) ) )); |
|
38 |
{ |
|
39 |
$state = false; |
|
40 |
foreach ( $markerdata as $markerline ) { |
|
41 |
if (strpos($markerline, '# END ' . $marker) !== false) |
|
42 |
$state = false; |
|
43 |
if ( $state ) |
|
44 |
$result[] = $markerline; |
|
45 |
if (strpos($markerline, '# BEGIN ' . $marker) !== false) |
|
46 |
$state = true; |
|
47 |
} |
|
48 |
} |
|
49 |
||
50 |
return $result; |
|
51 |
} |
|
52 |
||
53 |
/** |
|
54 |
* {@internal Missing Short Description}} |
|
55 |
* |
|
56 |
* Inserts an array of strings into a file (.htaccess ), placing it between |
|
57 |
* BEGIN and END markers. Replaces existing marked info. Retains surrounding |
|
58 |
* data. Creates file if none exists. |
|
59 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
60 |
* @since 1.5.0 |
136 | 61 |
* |
62 |
* @param unknown_type $filename |
|
63 |
* @param unknown_type $marker |
|
64 |
* @param unknown_type $insertion |
|
65 |
* @return bool True on write success, false on failure. |
|
66 |
*/ |
|
67 |
function insert_with_markers( $filename, $marker, $insertion ) { |
|
68 |
if (!file_exists( $filename ) || is_writeable( $filename ) ) { |
|
69 |
if (!file_exists( $filename ) ) { |
|
70 |
$markerdata = ''; |
|
71 |
} else { |
|
72 |
$markerdata = explode( "\n", implode( '', file( $filename ) ) ); |
|
73 |
} |
|
74 |
||
75 |
if ( !$f = @fopen( $filename, 'w' ) ) |
|
76 |
return false; |
|
77 |
||
78 |
$foundit = false; |
|
79 |
if ( $markerdata ) { |
|
80 |
$state = true; |
|
81 |
foreach ( $markerdata as $n => $markerline ) { |
|
82 |
if (strpos($markerline, '# BEGIN ' . $marker) !== false) |
|
83 |
$state = false; |
|
84 |
if ( $state ) { |
|
85 |
if ( $n + 1 < count( $markerdata ) ) |
|
86 |
fwrite( $f, "{$markerline}\n" ); |
|
87 |
else |
|
88 |
fwrite( $f, "{$markerline}" ); |
|
89 |
} |
|
90 |
if (strpos($markerline, '# END ' . $marker) !== false) { |
|
91 |
fwrite( $f, "# BEGIN {$marker}\n" ); |
|
92 |
if ( is_array( $insertion )) |
|
93 |
foreach ( $insertion as $insertline ) |
|
94 |
fwrite( $f, "{$insertline}\n" ); |
|
95 |
fwrite( $f, "# END {$marker}\n" ); |
|
96 |
$state = true; |
|
97 |
$foundit = true; |
|
98 |
} |
|
99 |
} |
|
100 |
} |
|
101 |
if (!$foundit) { |
|
102 |
fwrite( $f, "\n# BEGIN {$marker}\n" ); |
|
103 |
foreach ( $insertion as $insertline ) |
|
104 |
fwrite( $f, "{$insertline}\n" ); |
|
105 |
fwrite( $f, "# END {$marker}\n" ); |
|
106 |
} |
|
107 |
fclose( $f ); |
|
108 |
return true; |
|
109 |
} else { |
|
110 |
return false; |
|
111 |
} |
|
112 |
} |
|
113 |
||
114 |
/** |
|
115 |
* Updates the htaccess file with the current rules if it is writable. |
|
116 |
* |
|
117 |
* Always writes to the file if it exists and is writable to ensure that we |
|
118 |
* blank out old rules. |
|
119 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
120 |
* @since 1.5.0 |
136 | 121 |
*/ |
122 |
function save_mod_rewrite_rules() { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
123 |
if ( is_multisite() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
124 |
return; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
125 |
|
136 | 126 |
global $wp_rewrite; |
127 |
||
128 |
$home_path = get_home_path(); |
|
129 |
$htaccess_file = $home_path.'.htaccess'; |
|
130 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
131 |
// If the file doesn't already exist check for write access to the directory and whether we have some rules. |
136 | 132 |
// else check for write access to the file. |
133 |
if ((!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks()) || is_writable($htaccess_file)) { |
|
134 |
if ( got_mod_rewrite() ) { |
|
135 |
$rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() ); |
|
136 |
return insert_with_markers( $htaccess_file, 'WordPress', $rules ); |
|
137 |
} |
|
138 |
} |
|
139 |
||
140 |
return false; |
|
141 |
} |
|
142 |
||
143 |
/** |
|
144 |
* Updates the IIS web.config file with the current rules if it is writable. |
|
145 |
* If the permalinks do not require rewrite rules then the rules are deleted from the web.config file. |
|
146 |
* |
|
147 |
* @since 2.8.0 |
|
148 |
* |
|
149 |
* @return bool True if web.config was updated successfully |
|
150 |
*/ |
|
151 |
function iis7_save_url_rewrite_rules(){ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
152 |
if ( is_multisite() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
153 |
return; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
154 |
|
136 | 155 |
global $wp_rewrite; |
156 |
||
157 |
$home_path = get_home_path(); |
|
158 |
$web_config_file = $home_path . 'web.config'; |
|
159 |
||
160 |
// Using win_is_writable() instead of is_writable() because of a bug in Windows PHP |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
161 |
if ( iis7_supports_permalinks() && ( ( ! file_exists($web_config_file) && win_is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks() ) || win_is_writable($web_config_file) ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
162 |
$rule = $wp_rewrite->iis7_url_rewrite_rules(false, '', ''); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
163 |
if ( ! empty($rule) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
164 |
return iis7_add_rewrite_rule($web_config_file, $rule); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
165 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
166 |
return iis7_delete_rewrite_rule($web_config_file); |
136 | 167 |
} |
168 |
} |
|
169 |
return false; |
|
170 |
} |
|
171 |
||
172 |
/** |
|
173 |
* {@internal Missing Short Description}} |
|
174 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
175 |
* @since 1.5.0 |
136 | 176 |
* |
177 |
* @param unknown_type $file |
|
178 |
*/ |
|
179 |
function update_recently_edited( $file ) { |
|
180 |
$oldfiles = (array ) get_option( 'recently_edited' ); |
|
181 |
if ( $oldfiles ) { |
|
182 |
$oldfiles = array_reverse( $oldfiles ); |
|
183 |
$oldfiles[] = $file; |
|
184 |
$oldfiles = array_reverse( $oldfiles ); |
|
185 |
$oldfiles = array_unique( $oldfiles ); |
|
186 |
if ( 5 < count( $oldfiles )) |
|
187 |
array_pop( $oldfiles ); |
|
188 |
} else { |
|
189 |
$oldfiles[] = $file; |
|
190 |
} |
|
191 |
update_option( 'recently_edited', $oldfiles ); |
|
192 |
} |
|
193 |
||
194 |
/** |
|
195 |
* If siteurl or home changed, flush rewrite rules. |
|
196 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
197 |
* @since 2.1.0 |
136 | 198 |
* |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
199 |
* @param string $old_value |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
200 |
* @param string $value |
136 | 201 |
*/ |
202 |
function update_home_siteurl( $old_value, $value ) { |
|
203 |
if ( defined( "WP_INSTALLING" ) ) |
|
204 |
return; |
|
205 |
||
206 |
// If home changed, write rewrite rules to new location. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
207 |
flush_rewrite_rules(); |
136 | 208 |
} |
209 |
||
210 |
add_action( 'update_option_home', 'update_home_siteurl', 10, 2 ); |
|
211 |
add_action( 'update_option_siteurl', 'update_home_siteurl', 10, 2 ); |
|
212 |
||
213 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
214 |
* Shorten an URL, to be used as link text |
136 | 215 |
* |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
216 |
* @since 1.2.1 |
136 | 217 |
* |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
218 |
* @param string $url |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
219 |
* @return string |
136 | 220 |
*/ |
221 |
function url_shorten( $url ) { |
|
222 |
$short_url = str_replace( 'http://', '', stripslashes( $url )); |
|
223 |
$short_url = str_replace( 'www.', '', $short_url ); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
224 |
$short_url = untrailingslashit( $short_url ); |
136 | 225 |
if ( strlen( $short_url ) > 35 ) |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
226 |
$short_url = substr( $short_url, 0, 32 ) . '...'; |
136 | 227 |
return $short_url; |
228 |
} |
|
229 |
||
230 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
231 |
* Resets global variables based on $_GET and $_POST |
136 | 232 |
* |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
233 |
* This function resets global variables based on the names passed |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
234 |
* in the $vars array to the value of $_POST[$var] or $_GET[$var] or '' |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
235 |
* if neither is defined. |
136 | 236 |
* |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
237 |
* @since 2.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
238 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
239 |
* @param array $vars An array of globals to reset. |
136 | 240 |
*/ |
241 |
function wp_reset_vars( $vars ) { |
|
242 |
for ( $i=0; $i<count( $vars ); $i += 1 ) { |
|
243 |
$var = $vars[$i]; |
|
244 |
global $$var; |
|
245 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
246 |
if ( empty( $_POST[$var] ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
247 |
if ( empty( $_GET[$var] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
248 |
$$var = ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
249 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
250 |
$$var = $_GET[$var]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
251 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
252 |
$$var = $_POST[$var]; |
136 | 253 |
} |
254 |
} |
|
255 |
} |
|
256 |
||
257 |
/** |
|
258 |
* {@internal Missing Short Description}} |
|
259 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
260 |
* @since 2.1.0 |
136 | 261 |
* |
262 |
* @param unknown_type $message |
|
263 |
*/ |
|
264 |
function show_message($message) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
265 |
if ( is_wp_error($message) ){ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
266 |
if ( $message->get_error_data() ) |
136 | 267 |
$message = $message->get_error_message() . ': ' . $message->get_error_data(); |
268 |
else |
|
269 |
$message = $message->get_error_message(); |
|
270 |
} |
|
271 |
echo "<p>$message</p>\n"; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
272 |
wp_ob_end_flush_all(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
273 |
flush(); |
136 | 274 |
} |
275 |
||
276 |
function wp_doc_link_parse( $content ) { |
|
277 |
if ( !is_string( $content ) || empty( $content ) ) |
|
278 |
return array(); |
|
279 |
||
280 |
if ( !function_exists('token_get_all') ) |
|
281 |
return array(); |
|
282 |
||
283 |
$tokens = token_get_all( $content ); |
|
284 |
$functions = array(); |
|
285 |
$ignore_functions = array(); |
|
286 |
for ( $t = 0, $count = count( $tokens ); $t < $count; $t++ ) { |
|
287 |
if ( !is_array( $tokens[$t] ) ) continue; |
|
288 |
if ( T_STRING == $tokens[$t][0] && ( '(' == $tokens[ $t + 1 ] || '(' == $tokens[ $t + 2 ] ) ) { |
|
289 |
// If it's a function or class defined locally, there's not going to be any docs available |
|
290 |
if ( ( isset( $tokens[ $t - 2 ][1] ) && in_array( $tokens[ $t - 2 ][1], array( 'function', 'class' ) ) ) || ( isset( $tokens[ $t - 2 ][0] ) && T_OBJECT_OPERATOR == $tokens[ $t - 1 ][0] ) ) { |
|
291 |
$ignore_functions[] = $tokens[$t][1]; |
|
292 |
} |
|
293 |
// Add this to our stack of unique references |
|
294 |
$functions[] = $tokens[$t][1]; |
|
295 |
} |
|
296 |
} |
|
297 |
||
298 |
$functions = array_unique( $functions ); |
|
299 |
sort( $functions ); |
|
300 |
$ignore_functions = apply_filters( 'documentation_ignore_functions', $ignore_functions ); |
|
301 |
$ignore_functions = array_unique( $ignore_functions ); |
|
302 |
||
303 |
$out = array(); |
|
304 |
foreach ( $functions as $function ) { |
|
305 |
if ( in_array( $function, $ignore_functions ) ) |
|
306 |
continue; |
|
307 |
$out[] = $function; |
|
308 |
} |
|
309 |
||
310 |
return $out; |
|
311 |
} |
|
312 |
||
313 |
/** |
|
314 |
* Saves option for number of rows when listing posts, pages, comments, etc. |
|
315 |
* |
|
316 |
* @since 2.8 |
|
317 |
**/ |
|
318 |
function set_screen_options() { |
|
319 |
||
320 |
if ( isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options']) ) { |
|
321 |
check_admin_referer( 'screen-options-nonce', 'screenoptionnonce' ); |
|
322 |
||
323 |
if ( !$user = wp_get_current_user() ) |
|
324 |
return; |
|
325 |
$option = $_POST['wp_screen_options']['option']; |
|
326 |
$value = $_POST['wp_screen_options']['value']; |
|
327 |
||
328 |
if ( !preg_match( '/^[a-z_-]+$/', $option ) ) |
|
329 |
return; |
|
330 |
||
331 |
$option = str_replace('-', '_', $option); |
|
332 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
333 |
$map_option = $option; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
334 |
$type = str_replace('edit_', '', $map_option); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
335 |
$type = str_replace('_per_page', '', $type); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
336 |
if ( in_array($type, get_post_types()) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
337 |
$map_option = 'edit_per_page'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
338 |
if ( in_array( $type, get_taxonomies()) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
339 |
$map_option = 'edit_tags_per_page'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
340 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
341 |
switch ( $map_option ) { |
136 | 342 |
case 'edit_per_page': |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
343 |
case 'users_per_page': |
136 | 344 |
case 'edit_comments_per_page': |
345 |
case 'upload_per_page': |
|
346 |
case 'edit_tags_per_page': |
|
347 |
case 'plugins_per_page': |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
348 |
// Network admin |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
349 |
case 'sites_network_per_page': |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
350 |
case 'users_network_per_page': |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
351 |
case 'site_users_network_per_page': |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
352 |
case 'plugins_network_per_page': |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
353 |
case 'themes_network_per_page': |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
354 |
case 'site_themes_network_per_page': |
136 | 355 |
$value = (int) $value; |
356 |
if ( $value < 1 || $value > 999 ) |
|
357 |
return; |
|
358 |
break; |
|
359 |
default: |
|
360 |
$value = apply_filters('set-screen-option', false, $option, $value); |
|
361 |
if ( false === $value ) |
|
362 |
return; |
|
363 |
break; |
|
364 |
} |
|
365 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
366 |
update_user_meta($user->ID, $option, $value); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
367 |
wp_safe_redirect( remove_query_arg( array('pagenum', 'apage', 'paged'), wp_get_referer() ) ); |
136 | 368 |
exit; |
369 |
} |
|
370 |
} |
|
371 |
||
372 |
/** |
|
373 |
* Check if rewrite rule for WordPress already exists in the IIS 7 configuration file |
|
374 |
* |
|
375 |
* @since 2.8.0 |
|
376 |
* |
|
377 |
* @return bool |
|
378 |
* @param string $filename The file path to the configuration file |
|
379 |
*/ |
|
380 |
function iis7_rewrite_rule_exists($filename) { |
|
381 |
if ( ! file_exists($filename) ) |
|
382 |
return false; |
|
383 |
if ( ! class_exists('DOMDocument') ) |
|
384 |
return false; |
|
385 |
||
386 |
$doc = new DOMDocument(); |
|
387 |
if ( $doc->load($filename) === false ) |
|
388 |
return false; |
|
389 |
$xpath = new DOMXPath($doc); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
390 |
$rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')]'); |
136 | 391 |
if ( $rules->length == 0 ) |
392 |
return false; |
|
393 |
else |
|
394 |
return true; |
|
395 |
} |
|
396 |
||
397 |
/** |
|
398 |
* Delete WordPress rewrite rule from web.config file if it exists there |
|
399 |
* |
|
400 |
* @since 2.8.0 |
|
401 |
* |
|
402 |
* @param string $filename Name of the configuration file |
|
403 |
* @return bool |
|
404 |
*/ |
|
405 |
function iis7_delete_rewrite_rule($filename) { |
|
406 |
// If configuration file does not exist then rules also do not exist so there is nothing to delete |
|
407 |
if ( ! file_exists($filename) ) |
|
408 |
return true; |
|
409 |
||
410 |
if ( ! class_exists('DOMDocument') ) |
|
411 |
return false; |
|
412 |
||
413 |
$doc = new DOMDocument(); |
|
414 |
$doc->preserveWhiteSpace = false; |
|
415 |
||
416 |
if ( $doc -> load($filename) === false ) |
|
417 |
return false; |
|
418 |
$xpath = new DOMXPath($doc); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
419 |
$rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')]'); |
136 | 420 |
if ( $rules->length > 0 ) { |
421 |
$child = $rules->item(0); |
|
422 |
$parent = $child->parentNode; |
|
423 |
$parent->removeChild($child); |
|
424 |
$doc->formatOutput = true; |
|
425 |
saveDomDocument($doc, $filename); |
|
426 |
} |
|
427 |
return true; |
|
428 |
} |
|
429 |
||
430 |
/** |
|
431 |
* Add WordPress rewrite rule to the IIS 7 configuration file. |
|
432 |
* |
|
433 |
* @since 2.8.0 |
|
434 |
* |
|
435 |
* @param string $filename The file path to the configuration file |
|
436 |
* @param string $rewrite_rule The XML fragment with URL Rewrite rule |
|
437 |
* @return bool |
|
438 |
*/ |
|
439 |
function iis7_add_rewrite_rule($filename, $rewrite_rule) { |
|
440 |
if ( ! class_exists('DOMDocument') ) |
|
441 |
return false; |
|
442 |
||
443 |
// If configuration file does not exist then we create one. |
|
444 |
if ( ! file_exists($filename) ) { |
|
445 |
$fp = fopen( $filename, 'w'); |
|
446 |
fwrite($fp, '<configuration/>'); |
|
447 |
fclose($fp); |
|
448 |
} |
|
449 |
||
450 |
$doc = new DOMDocument(); |
|
451 |
$doc->preserveWhiteSpace = false; |
|
452 |
||
453 |
if ( $doc->load($filename) === false ) |
|
454 |
return false; |
|
455 |
||
456 |
$xpath = new DOMXPath($doc); |
|
457 |
||
458 |
// First check if the rule already exists as in that case there is no need to re-add it |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
459 |
$wordpress_rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')]'); |
136 | 460 |
if ( $wordpress_rules->length > 0 ) |
461 |
return true; |
|
462 |
||
463 |
// Check the XPath to the rewrite rule and create XML nodes if they do not exist |
|
464 |
$xmlnodes = $xpath->query('/configuration/system.webServer/rewrite/rules'); |
|
465 |
if ( $xmlnodes->length > 0 ) { |
|
466 |
$rules_node = $xmlnodes->item(0); |
|
467 |
} else { |
|
468 |
$rules_node = $doc->createElement('rules'); |
|
469 |
||
470 |
$xmlnodes = $xpath->query('/configuration/system.webServer/rewrite'); |
|
471 |
if ( $xmlnodes->length > 0 ) { |
|
472 |
$rewrite_node = $xmlnodes->item(0); |
|
473 |
$rewrite_node->appendChild($rules_node); |
|
474 |
} else { |
|
475 |
$rewrite_node = $doc->createElement('rewrite'); |
|
476 |
$rewrite_node->appendChild($rules_node); |
|
477 |
||
478 |
$xmlnodes = $xpath->query('/configuration/system.webServer'); |
|
479 |
if ( $xmlnodes->length > 0 ) { |
|
480 |
$system_webServer_node = $xmlnodes->item(0); |
|
481 |
$system_webServer_node->appendChild($rewrite_node); |
|
482 |
} else { |
|
483 |
$system_webServer_node = $doc->createElement('system.webServer'); |
|
484 |
$system_webServer_node->appendChild($rewrite_node); |
|
485 |
||
486 |
$xmlnodes = $xpath->query('/configuration'); |
|
487 |
if ( $xmlnodes->length > 0 ) { |
|
488 |
$config_node = $xmlnodes->item(0); |
|
489 |
$config_node->appendChild($system_webServer_node); |
|
490 |
} else { |
|
491 |
$config_node = $doc->createElement('configuration'); |
|
492 |
$doc->appendChild($config_node); |
|
493 |
$config_node->appendChild($system_webServer_node); |
|
494 |
} |
|
495 |
} |
|
496 |
} |
|
497 |
} |
|
498 |
||
499 |
$rule_fragment = $doc->createDocumentFragment(); |
|
500 |
$rule_fragment->appendXML($rewrite_rule); |
|
501 |
$rules_node->appendChild($rule_fragment); |
|
502 |
||
503 |
$doc->encoding = "UTF-8"; |
|
504 |
$doc->formatOutput = true; |
|
505 |
saveDomDocument($doc, $filename); |
|
506 |
||
507 |
return true; |
|
508 |
} |
|
509 |
||
510 |
/** |
|
511 |
* Saves the XML document into a file |
|
512 |
* |
|
513 |
* @since 2.8.0 |
|
514 |
* |
|
515 |
* @param DOMDocument $doc |
|
516 |
* @param string $filename |
|
517 |
*/ |
|
518 |
function saveDomDocument($doc, $filename) { |
|
519 |
$config = $doc->saveXML(); |
|
520 |
$config = preg_replace("/([^\r])\n/", "$1\r\n", $config); |
|
521 |
$fp = fopen($filename, 'w'); |
|
522 |
fwrite($fp, $config); |
|
523 |
fclose($fp); |
|
524 |
} |
|
525 |
||
526 |
/** |
|
527 |
* Workaround for Windows bug in is_writable() function |
|
528 |
* |
|
529 |
* @since 2.8.0 |
|
530 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
531 |
* @param string $path |
136 | 532 |
* @return bool |
533 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
534 |
function win_is_writable( $path ) { |
136 | 535 |
/* will work in despite of Windows ACLs bug |
536 |
* NOTE: use a trailing slash for folders!!! |
|
537 |
* see http://bugs.php.net/bug.php?id=27609 |
|
538 |
* see http://bugs.php.net/bug.php?id=30931 |
|
539 |
*/ |
|
540 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
541 |
if ( $path[strlen( $path ) - 1] == '/' ) // recursively return a temporary file path |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
542 |
return win_is_writable( $path . uniqid( mt_rand() ) . '.tmp'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
543 |
else if ( is_dir( $path ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
544 |
return win_is_writable( $path . '/' . uniqid( mt_rand() ) . '.tmp' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
545 |
// check tmp file for read/write capabilities |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
546 |
$should_delete_tmp_file = !file_exists( $path ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
547 |
$f = @fopen( $path, 'a' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
548 |
if ( $f === false ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
549 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
550 |
fclose( $f ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
551 |
if ( $should_delete_tmp_file ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
552 |
unlink( $path ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
553 |
return true; |
136 | 554 |
} |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
555 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
556 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
557 |
* Display the default admin color scheme picker (Used in user-edit.php) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
558 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
559 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
560 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
561 |
function admin_color_scheme_picker() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
562 |
global $_wp_admin_css_colors, $user_id; ?> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
563 |
<fieldset><legend class="screen-reader-text"><span><?php _e('Admin Color Scheme')?></span></legend> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
564 |
<?php |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
565 |
$current_color = get_user_option('admin_color', $user_id); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
566 |
if ( empty($current_color) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
567 |
$current_color = 'fresh'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
568 |
foreach ( $_wp_admin_css_colors as $color => $color_info ): ?> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
569 |
<div class="color-option"><input name="admin_color" id="admin_color_<?php echo $color; ?>" type="radio" value="<?php echo esc_attr($color) ?>" class="tog" <?php checked($color, $current_color); ?> /> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
570 |
<table class="color-palette"> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
571 |
<tr> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
572 |
<?php foreach ( $color_info->colors as $html_color ): ?> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
573 |
<td style="background-color: <?php echo $html_color ?>" title="<?php echo $color ?>"> </td> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
574 |
<?php endforeach; ?> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
575 |
</tr> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
576 |
</table> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
577 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
578 |
<label for="admin_color_<?php echo $color; ?>"><?php echo $color_info->name ?></label> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
579 |
</div> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
580 |
<?php endforeach; ?> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
581 |
</fieldset> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
582 |
<?php |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
583 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
584 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
585 |
function _ipad_meta() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
586 |
if ( wp_is_mobile() ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
587 |
?> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
588 |
<meta name="viewport" id="viewport-meta" content="width=device-width, initial-scale=1"> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
589 |
<?php |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
590 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
591 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
592 |
add_action('admin_head', '_ipad_meta'); |