1 | <?php |
---|
2 | /** |
---|
3 | * Misc WordPress Administration API. |
---|
4 | * |
---|
5 | * @package WordPress |
---|
6 | * @subpackage Administration |
---|
7 | */ |
---|
8 | |
---|
9 | /** |
---|
10 | * {@internal Missing Short Description}} |
---|
11 | * |
---|
12 | * @since unknown |
---|
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 | * |
---|
24 | * @since unknown |
---|
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 | * |
---|
60 | * @since unknown |
---|
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 | * |
---|
120 | * @since unknown |
---|
121 | */ |
---|
122 | function save_mod_rewrite_rules() { |
---|
123 | if ( is_multisite() ) |
---|
124 | return; |
---|
125 | |
---|
126 | global $wp_rewrite; |
---|
127 | |
---|
128 | $home_path = get_home_path(); |
---|
129 | $htaccess_file = $home_path.'.htaccess'; |
---|
130 | |
---|
131 | // If the file doesn't already exist check for write access to the directory and whether we have some rules. |
---|
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(){ |
---|
152 | global $wp_rewrite; |
---|
153 | |
---|
154 | $home_path = get_home_path(); |
---|
155 | $web_config_file = $home_path . 'web.config'; |
---|
156 | |
---|
157 | // Using win_is_writable() instead of is_writable() because of a bug in Windows PHP |
---|
158 | if ( ( ! file_exists($web_config_file) && win_is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks() ) || win_is_writable($web_config_file) ) { |
---|
159 | if ( iis7_supports_permalinks() ) { |
---|
160 | $rule = $wp_rewrite->iis7_url_rewrite_rules(false, '', ''); |
---|
161 | if ( ! empty($rule) ) { |
---|
162 | return iis7_add_rewrite_rule($web_config_file, $rule); |
---|
163 | } else { |
---|
164 | return iis7_delete_rewrite_rule($web_config_file); |
---|
165 | } |
---|
166 | } |
---|
167 | } |
---|
168 | return false; |
---|
169 | } |
---|
170 | |
---|
171 | /** |
---|
172 | * {@internal Missing Short Description}} |
---|
173 | * |
---|
174 | * @since unknown |
---|
175 | * |
---|
176 | * @param unknown_type $file |
---|
177 | */ |
---|
178 | function update_recently_edited( $file ) { |
---|
179 | $oldfiles = (array ) get_option( 'recently_edited' ); |
---|
180 | if ( $oldfiles ) { |
---|
181 | $oldfiles = array_reverse( $oldfiles ); |
---|
182 | $oldfiles[] = $file; |
---|
183 | $oldfiles = array_reverse( $oldfiles ); |
---|
184 | $oldfiles = array_unique( $oldfiles ); |
---|
185 | if ( 5 < count( $oldfiles )) |
---|
186 | array_pop( $oldfiles ); |
---|
187 | } else { |
---|
188 | $oldfiles[] = $file; |
---|
189 | } |
---|
190 | update_option( 'recently_edited', $oldfiles ); |
---|
191 | } |
---|
192 | |
---|
193 | /** |
---|
194 | * If siteurl or home changed, flush rewrite rules. |
---|
195 | * |
---|
196 | * @since unknown |
---|
197 | * |
---|
198 | * @param unknown_type $old_value |
---|
199 | * @param unknown_type $value |
---|
200 | */ |
---|
201 | function update_home_siteurl( $old_value, $value ) { |
---|
202 | global $wp_rewrite; |
---|
203 | |
---|
204 | if ( defined( "WP_INSTALLING" ) ) |
---|
205 | return; |
---|
206 | |
---|
207 | // If home changed, write rewrite rules to new location. |
---|
208 | $wp_rewrite->flush_rules(); |
---|
209 | } |
---|
210 | |
---|
211 | add_action( 'update_option_home', 'update_home_siteurl', 10, 2 ); |
---|
212 | add_action( 'update_option_siteurl', 'update_home_siteurl', 10, 2 ); |
---|
213 | |
---|
214 | /** |
---|
215 | * Shorten an URL, to be used as link text |
---|
216 | * |
---|
217 | * @since 1.2.1 |
---|
218 | * |
---|
219 | * @param string $url |
---|
220 | * @return string |
---|
221 | */ |
---|
222 | function url_shorten( $url ) { |
---|
223 | $short_url = str_replace( 'http://', '', stripslashes( $url )); |
---|
224 | $short_url = str_replace( 'www.', '', $short_url ); |
---|
225 | if ('/' == substr( $short_url, -1 )) |
---|
226 | $short_url = substr( $short_url, 0, -1 ); |
---|
227 | if ( strlen( $short_url ) > 35 ) |
---|
228 | $short_url = substr( $short_url, 0, 32 ).'...'; |
---|
229 | return $short_url; |
---|
230 | } |
---|
231 | |
---|
232 | /** |
---|
233 | * Resets global variables based on $_GET and $_POST |
---|
234 | * |
---|
235 | * This function resets global variables based on the names passed |
---|
236 | * in the $vars array to the value of $_POST[$var] or $_GET[$var] or '' |
---|
237 | * if neither is defined. |
---|
238 | * |
---|
239 | * @since unknown |
---|
240 | * |
---|
241 | * @param array $vars An array of globals to reset. |
---|
242 | */ |
---|
243 | function wp_reset_vars( $vars ) { |
---|
244 | for ( $i=0; $i<count( $vars ); $i += 1 ) { |
---|
245 | $var = $vars[$i]; |
---|
246 | global $$var; |
---|
247 | |
---|
248 | if ( empty( $_POST[$var] ) ) { |
---|
249 | if ( empty( $_GET[$var] ) ) |
---|
250 | $$var = ''; |
---|
251 | else |
---|
252 | $$var = $_GET[$var]; |
---|
253 | } else { |
---|
254 | $$var = $_POST[$var]; |
---|
255 | } |
---|
256 | } |
---|
257 | } |
---|
258 | |
---|
259 | /** |
---|
260 | * {@internal Missing Short Description}} |
---|
261 | * |
---|
262 | * @since unknown |
---|
263 | * |
---|
264 | * @param unknown_type $message |
---|
265 | */ |
---|
266 | function show_message($message) { |
---|
267 | if ( is_wp_error($message) ){ |
---|
268 | if ( $message->get_error_data() ) |
---|
269 | $message = $message->get_error_message() . ': ' . $message->get_error_data(); |
---|
270 | else |
---|
271 | $message = $message->get_error_message(); |
---|
272 | } |
---|
273 | echo "<p>$message</p>\n"; |
---|
274 | wp_ob_end_flush_all(); |
---|
275 | flush(); |
---|
276 | } |
---|
277 | |
---|
278 | function wp_doc_link_parse( $content ) { |
---|
279 | if ( !is_string( $content ) || empty( $content ) ) |
---|
280 | return array(); |
---|
281 | |
---|
282 | if ( !function_exists('token_get_all') ) |
---|
283 | return array(); |
---|
284 | |
---|
285 | $tokens = token_get_all( $content ); |
---|
286 | $functions = array(); |
---|
287 | $ignore_functions = array(); |
---|
288 | for ( $t = 0, $count = count( $tokens ); $t < $count; $t++ ) { |
---|
289 | if ( !is_array( $tokens[$t] ) ) continue; |
---|
290 | if ( T_STRING == $tokens[$t][0] && ( '(' == $tokens[ $t + 1 ] || '(' == $tokens[ $t + 2 ] ) ) { |
---|
291 | // If it's a function or class defined locally, there's not going to be any docs available |
---|
292 | 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] ) ) { |
---|
293 | $ignore_functions[] = $tokens[$t][1]; |
---|
294 | } |
---|
295 | // Add this to our stack of unique references |
---|
296 | $functions[] = $tokens[$t][1]; |
---|
297 | } |
---|
298 | } |
---|
299 | |
---|
300 | $functions = array_unique( $functions ); |
---|
301 | sort( $functions ); |
---|
302 | $ignore_functions = apply_filters( 'documentation_ignore_functions', $ignore_functions ); |
---|
303 | $ignore_functions = array_unique( $ignore_functions ); |
---|
304 | |
---|
305 | $out = array(); |
---|
306 | foreach ( $functions as $function ) { |
---|
307 | if ( in_array( $function, $ignore_functions ) ) |
---|
308 | continue; |
---|
309 | $out[] = $function; |
---|
310 | } |
---|
311 | |
---|
312 | return $out; |
---|
313 | } |
---|
314 | |
---|
315 | /** |
---|
316 | * Saves option for number of rows when listing posts, pages, comments, etc. |
---|
317 | * |
---|
318 | * @since 2.8 |
---|
319 | **/ |
---|
320 | function set_screen_options() { |
---|
321 | |
---|
322 | if ( isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options']) ) { |
---|
323 | check_admin_referer( 'screen-options-nonce', 'screenoptionnonce' ); |
---|
324 | |
---|
325 | if ( !$user = wp_get_current_user() ) |
---|
326 | return; |
---|
327 | $option = $_POST['wp_screen_options']['option']; |
---|
328 | $value = $_POST['wp_screen_options']['value']; |
---|
329 | |
---|
330 | if ( !preg_match( '/^[a-z_-]+$/', $option ) ) |
---|
331 | return; |
---|
332 | |
---|
333 | $option = str_replace('-', '_', $option); |
---|
334 | |
---|
335 | $map_option = $option; |
---|
336 | $type = str_replace('edit_', '', $map_option); |
---|
337 | $type = str_replace('_per_page', '', $type); |
---|
338 | if ( in_array($type, get_post_types()) ) |
---|
339 | $map_option = 'edit_per_page'; |
---|
340 | if ( in_array( $type, get_taxonomies()) ) |
---|
341 | $map_option = 'edit_tags_per_page'; |
---|
342 | |
---|
343 | |
---|
344 | switch ( $map_option ) { |
---|
345 | case 'edit_per_page': |
---|
346 | case 'users_per_page': |
---|
347 | case 'edit_comments_per_page': |
---|
348 | case 'upload_per_page': |
---|
349 | case 'edit_tags_per_page': |
---|
350 | case 'plugins_per_page': |
---|
351 | // Network admin |
---|
352 | case 'sites_network_per_page': |
---|
353 | case 'users_network_per_page': |
---|
354 | case 'site_users_network_per_page': |
---|
355 | case 'plugins_network_per_page': |
---|
356 | case 'themes_network_per_page': |
---|
357 | case 'site_themes_network_per_page': |
---|
358 | $value = (int) $value; |
---|
359 | if ( $value < 1 || $value > 999 ) |
---|
360 | return; |
---|
361 | break; |
---|
362 | default: |
---|
363 | $value = apply_filters('set-screen-option', false, $option, $value); |
---|
364 | if ( false === $value ) |
---|
365 | return; |
---|
366 | break; |
---|
367 | } |
---|
368 | |
---|
369 | update_user_meta($user->ID, $option, $value); |
---|
370 | wp_redirect( remove_query_arg( array('pagenum', 'apage', 'paged'), wp_get_referer() ) ); |
---|
371 | exit; |
---|
372 | } |
---|
373 | } |
---|
374 | |
---|
375 | function wp_menu_unfold() { |
---|
376 | if ( isset($_GET['unfoldmenu']) ) { |
---|
377 | delete_user_setting('mfold'); |
---|
378 | wp_redirect( remove_query_arg( 'unfoldmenu', stripslashes($_SERVER['REQUEST_URI']) ) ); |
---|
379 | exit; |
---|
380 | } |
---|
381 | } |
---|
382 | |
---|
383 | /** |
---|
384 | * Check if IIS 7 supports pretty permalinks |
---|
385 | * |
---|
386 | * @since 2.8.0 |
---|
387 | * |
---|
388 | * @return bool |
---|
389 | */ |
---|
390 | function iis7_supports_permalinks() { |
---|
391 | global $is_iis7; |
---|
392 | |
---|
393 | $supports_permalinks = false; |
---|
394 | if ( $is_iis7 ) { |
---|
395 | /* First we check if the DOMDocument class exists. If it does not exist, |
---|
396 | * which is the case for PHP 4.X, then we cannot easily update the xml configuration file, |
---|
397 | * hence we just bail out and tell user that pretty permalinks cannot be used. |
---|
398 | * This is not a big issue because PHP 4.X is going to be depricated and for IIS it |
---|
399 | * is recommended to use PHP 5.X NTS. |
---|
400 | * Next we check if the URL Rewrite Module 1.1 is loaded and enabled for the web site. When |
---|
401 | * URL Rewrite 1.1 is loaded it always sets a server variable called 'IIS_UrlRewriteModule'. |
---|
402 | * Lastly we make sure that PHP is running via FastCGI. This is important because if it runs |
---|
403 | * via ISAPI then pretty permalinks will not work. |
---|
404 | */ |
---|
405 | $supports_permalinks = class_exists('DOMDocument') && isset($_SERVER['IIS_UrlRewriteModule']) && ( php_sapi_name() == 'cgi-fcgi' ); |
---|
406 | } |
---|
407 | |
---|
408 | return apply_filters('iis7_supports_permalinks', $supports_permalinks); |
---|
409 | } |
---|
410 | |
---|
411 | /** |
---|
412 | * Check if rewrite rule for WordPress already exists in the IIS 7 configuration file |
---|
413 | * |
---|
414 | * @since 2.8.0 |
---|
415 | * |
---|
416 | * @return bool |
---|
417 | * @param string $filename The file path to the configuration file |
---|
418 | */ |
---|
419 | function iis7_rewrite_rule_exists($filename) { |
---|
420 | if ( ! file_exists($filename) ) |
---|
421 | return false; |
---|
422 | if ( ! class_exists('DOMDocument') ) |
---|
423 | return false; |
---|
424 | |
---|
425 | $doc = new DOMDocument(); |
---|
426 | if ( $doc->load($filename) === false ) |
---|
427 | return false; |
---|
428 | $xpath = new DOMXPath($doc); |
---|
429 | $rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')]'); |
---|
430 | if ( $rules->length == 0 ) |
---|
431 | return false; |
---|
432 | else |
---|
433 | return true; |
---|
434 | } |
---|
435 | |
---|
436 | /** |
---|
437 | * Delete WordPress rewrite rule from web.config file if it exists there |
---|
438 | * |
---|
439 | * @since 2.8.0 |
---|
440 | * |
---|
441 | * @param string $filename Name of the configuration file |
---|
442 | * @return bool |
---|
443 | */ |
---|
444 | function iis7_delete_rewrite_rule($filename) { |
---|
445 | // If configuration file does not exist then rules also do not exist so there is nothing to delete |
---|
446 | if ( ! file_exists($filename) ) |
---|
447 | return true; |
---|
448 | |
---|
449 | if ( ! class_exists('DOMDocument') ) |
---|
450 | return false; |
---|
451 | |
---|
452 | $doc = new DOMDocument(); |
---|
453 | $doc->preserveWhiteSpace = false; |
---|
454 | |
---|
455 | if ( $doc -> load($filename) === false ) |
---|
456 | return false; |
---|
457 | $xpath = new DOMXPath($doc); |
---|
458 | $rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')]'); |
---|
459 | if ( $rules->length > 0 ) { |
---|
460 | $child = $rules->item(0); |
---|
461 | $parent = $child->parentNode; |
---|
462 | $parent->removeChild($child); |
---|
463 | $doc->formatOutput = true; |
---|
464 | saveDomDocument($doc, $filename); |
---|
465 | } |
---|
466 | return true; |
---|
467 | } |
---|
468 | |
---|
469 | /** |
---|
470 | * Add WordPress rewrite rule to the IIS 7 configuration file. |
---|
471 | * |
---|
472 | * @since 2.8.0 |
---|
473 | * |
---|
474 | * @param string $filename The file path to the configuration file |
---|
475 | * @param string $rewrite_rule The XML fragment with URL Rewrite rule |
---|
476 | * @return bool |
---|
477 | */ |
---|
478 | function iis7_add_rewrite_rule($filename, $rewrite_rule) { |
---|
479 | if ( ! class_exists('DOMDocument') ) |
---|
480 | return false; |
---|
481 | |
---|
482 | // If configuration file does not exist then we create one. |
---|
483 | if ( ! file_exists($filename) ) { |
---|
484 | $fp = fopen( $filename, 'w'); |
---|
485 | fwrite($fp, '<configuration/>'); |
---|
486 | fclose($fp); |
---|
487 | } |
---|
488 | |
---|
489 | $doc = new DOMDocument(); |
---|
490 | $doc->preserveWhiteSpace = false; |
---|
491 | |
---|
492 | if ( $doc->load($filename) === false ) |
---|
493 | return false; |
---|
494 | |
---|
495 | $xpath = new DOMXPath($doc); |
---|
496 | |
---|
497 | // First check if the rule already exists as in that case there is no need to re-add it |
---|
498 | $wordpress_rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')]'); |
---|
499 | if ( $wordpress_rules->length > 0 ) |
---|
500 | return true; |
---|
501 | |
---|
502 | // Check the XPath to the rewrite rule and create XML nodes if they do not exist |
---|
503 | $xmlnodes = $xpath->query('/configuration/system.webServer/rewrite/rules'); |
---|
504 | if ( $xmlnodes->length > 0 ) { |
---|
505 | $rules_node = $xmlnodes->item(0); |
---|
506 | } else { |
---|
507 | $rules_node = $doc->createElement('rules'); |
---|
508 | |
---|
509 | $xmlnodes = $xpath->query('/configuration/system.webServer/rewrite'); |
---|
510 | if ( $xmlnodes->length > 0 ) { |
---|
511 | $rewrite_node = $xmlnodes->item(0); |
---|
512 | $rewrite_node->appendChild($rules_node); |
---|
513 | } else { |
---|
514 | $rewrite_node = $doc->createElement('rewrite'); |
---|
515 | $rewrite_node->appendChild($rules_node); |
---|
516 | |
---|
517 | $xmlnodes = $xpath->query('/configuration/system.webServer'); |
---|
518 | if ( $xmlnodes->length > 0 ) { |
---|
519 | $system_webServer_node = $xmlnodes->item(0); |
---|
520 | $system_webServer_node->appendChild($rewrite_node); |
---|
521 | } else { |
---|
522 | $system_webServer_node = $doc->createElement('system.webServer'); |
---|
523 | $system_webServer_node->appendChild($rewrite_node); |
---|
524 | |
---|
525 | $xmlnodes = $xpath->query('/configuration'); |
---|
526 | if ( $xmlnodes->length > 0 ) { |
---|
527 | $config_node = $xmlnodes->item(0); |
---|
528 | $config_node->appendChild($system_webServer_node); |
---|
529 | } else { |
---|
530 | $config_node = $doc->createElement('configuration'); |
---|
531 | $doc->appendChild($config_node); |
---|
532 | $config_node->appendChild($system_webServer_node); |
---|
533 | } |
---|
534 | } |
---|
535 | } |
---|
536 | } |
---|
537 | |
---|
538 | $rule_fragment = $doc->createDocumentFragment(); |
---|
539 | $rule_fragment->appendXML($rewrite_rule); |
---|
540 | $rules_node->appendChild($rule_fragment); |
---|
541 | |
---|
542 | $doc->encoding = "UTF-8"; |
---|
543 | $doc->formatOutput = true; |
---|
544 | saveDomDocument($doc, $filename); |
---|
545 | |
---|
546 | return true; |
---|
547 | } |
---|
548 | |
---|
549 | /** |
---|
550 | * Saves the XML document into a file |
---|
551 | * |
---|
552 | * @since 2.8.0 |
---|
553 | * |
---|
554 | * @param DOMDocument $doc |
---|
555 | * @param string $filename |
---|
556 | */ |
---|
557 | function saveDomDocument($doc, $filename) { |
---|
558 | $config = $doc->saveXML(); |
---|
559 | $config = preg_replace("/([^\r])\n/", "$1\r\n", $config); |
---|
560 | $fp = fopen($filename, 'w'); |
---|
561 | fwrite($fp, $config); |
---|
562 | fclose($fp); |
---|
563 | } |
---|
564 | |
---|
565 | /** |
---|
566 | * Workaround for Windows bug in is_writable() function |
---|
567 | * |
---|
568 | * @since 2.8.0 |
---|
569 | * |
---|
570 | * @param object $path |
---|
571 | * @return bool |
---|
572 | */ |
---|
573 | function win_is_writable($path) { |
---|
574 | /* will work in despite of Windows ACLs bug |
---|
575 | * NOTE: use a trailing slash for folders!!! |
---|
576 | * see http://bugs.php.net/bug.php?id=27609 |
---|
577 | * see http://bugs.php.net/bug.php?id=30931 |
---|
578 | */ |
---|
579 | |
---|
580 | if ( $path[strlen($path)-1] == '/' ) // recursively return a temporary file path |
---|
581 | return win_is_writable($path . uniqid(mt_rand()) . '.tmp'); |
---|
582 | else if ( is_dir($path) ) |
---|
583 | return win_is_writable($path . '/' . uniqid(mt_rand()) . '.tmp'); |
---|
584 | // check tmp file for read/write capabilities |
---|
585 | $rm = file_exists($path); |
---|
586 | $f = @fopen($path, 'a'); |
---|
587 | if ($f===false) |
---|
588 | return false; |
---|
589 | fclose($f); |
---|
590 | if ( ! $rm ) |
---|
591 | unlink($path); |
---|
592 | return true; |
---|
593 | } |
---|
594 | |
---|
595 | /** |
---|
596 | * Display the default admin color scheme picker (Used in user-edit.php) |
---|
597 | * |
---|
598 | * @since 3.0.0 |
---|
599 | */ |
---|
600 | function admin_color_scheme_picker() { |
---|
601 | global $_wp_admin_css_colors, $user_id; ?> |
---|
602 | <fieldset><legend class="screen-reader-text"><span><?php _e('Admin Color Scheme')?></span></legend> |
---|
603 | <?php |
---|
604 | $current_color = get_user_option('admin_color', $user_id); |
---|
605 | if ( empty($current_color) ) |
---|
606 | $current_color = 'fresh'; |
---|
607 | foreach ( $_wp_admin_css_colors as $color => $color_info ): ?> |
---|
608 | <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); ?> /> |
---|
609 | <table class="color-palette"> |
---|
610 | <tr> |
---|
611 | <?php foreach ( $color_info->colors as $html_color ): ?> |
---|
612 | <td style="background-color: <?php echo $html_color ?>" title="<?php echo $color ?>"> </td> |
---|
613 | <?php endforeach; ?> |
---|
614 | </tr> |
---|
615 | </table> |
---|
616 | |
---|
617 | <label for="admin_color_<?php echo $color; ?>"><?php echo $color_info->name ?></label> |
---|
618 | </div> |
---|
619 | <?php endforeach; ?> |
---|
620 | </fieldset> |
---|
621 | <?php |
---|
622 | } |
---|
623 | ?> |
---|