Ticket #17997: misc.diff
| File misc.diff, 18.4 KB (added by Latz, 23 months ago) |
|---|
-
\misc.php
old new 14 14 * @return unknown 15 15 */ 16 16 function got_mod_rewrite() { 17 $got_rewrite = apache_mod_loaded( 'mod_rewrite', true);18 return apply_filters( 'got_rewrite', $got_rewrite);17 $got_rewrite = apache_mod_loaded( 'mod_rewrite', true ); 18 return apply_filters( 'got_rewrite', $got_rewrite ); 19 19 } 20 20 21 21 /** … … 34 34 return $result; 35 35 } 36 36 37 if ( $markerdata = explode( "\n", implode( '', file( $filename ) ) ) );37 if ( $markerdata = explode( "\n", implode( '', file( $filename ) ) ) ); 38 38 { 39 39 $state = false; 40 40 foreach ( $markerdata as $markerline ) { 41 if ( strpos($markerline, '# END ' . $marker) !== false)41 if ( strpos( $markerline, '# END ' . $marker ) !== false ) 42 42 $state = false; 43 43 if ( $state ) 44 44 $result[] = $markerline; 45 if ( strpos($markerline, '# BEGIN ' . $marker) !== false)45 if ( strpos( $markerline, '# BEGIN ' . $marker ) !== false ) 46 46 $state = true; 47 47 } 48 48 } … … 79 79 if ( $markerdata ) { 80 80 $state = true; 81 81 foreach ( $markerdata as $n => $markerline ) { 82 if ( strpos($markerline, '# BEGIN ' . $marker) !== false)82 if ( strpos( $markerline, '# BEGIN ' . $marker ) !== false ) 83 83 $state = false; 84 84 if ( $state ) { 85 85 if ( $n + 1 < count( $markerdata ) ) … … 87 87 else 88 88 fwrite( $f, "{$markerline}" ); 89 89 } 90 if ( strpos($markerline, '# END ' . $marker) !== false) {90 if ( strpos( $markerline, '# END ' . $marker ) !== false ) { 91 91 fwrite( $f, "# BEGIN {$marker}\n" ); 92 if ( is_array( $insertion ) )92 if ( is_array( $insertion ) ) 93 93 foreach ( $insertion as $insertline ) 94 94 fwrite( $f, "{$insertline}\n" ); 95 95 fwrite( $f, "# END {$marker}\n" ); … … 98 98 } 99 99 } 100 100 } 101 if ( !$foundit) {101 if ( !$foundit ) { 102 102 fwrite( $f, "\n# BEGIN {$marker}\n" ); 103 103 foreach ( $insertion as $insertline ) 104 104 fwrite( $f, "{$insertline}\n" ); … … 126 126 global $wp_rewrite; 127 127 128 128 $home_path = get_home_path(); 129 $htaccess_file = $home_path .'.htaccess';129 $htaccess_file = $home_path . '.htaccess'; 130 130 131 131 // If the file doesn't already exist check for write access to the directory and whether we have some rules. 132 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)) {133 if ( ( !file_exists( $htaccess_file ) && is_writable( $home_path ) && $wp_rewrite->using_mod_rewrite_permalinks() ) || is_writable( $htaccess_file ) ) { 134 134 if ( got_mod_rewrite() ) { 135 135 $rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() ); 136 136 return insert_with_markers( $htaccess_file, 'WordPress', $rules ); … … 158 158 $web_config_file = $home_path . 'web.config'; 159 159 160 160 // Using win_is_writable() instead of is_writable() because of a bug in Windows PHP 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) ) ) {162 $rule = $wp_rewrite->iis7_url_rewrite_rules( false, '', '');163 if ( ! empty( $rule) ) {164 return iis7_add_rewrite_rule( $web_config_file, $rule);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 ) ) ) { 162 $rule = $wp_rewrite->iis7_url_rewrite_rules( false, '', '' ); 163 if ( ! empty( $rule ) ) { 164 return iis7_add_rewrite_rule( $web_config_file, $rule ); 165 165 } else { 166 return iis7_delete_rewrite_rule( $web_config_file);166 return iis7_delete_rewrite_rule( $web_config_file ); 167 167 } 168 168 } 169 169 return false; … … 177 177 * @param unknown_type $file 178 178 */ 179 179 function update_recently_edited( $file ) { 180 $oldfiles = ( array ) get_option( 'recently_edited' );180 $oldfiles = ( array ) get_option( 'recently_edited' ); 181 181 if ( $oldfiles ) { 182 182 $oldfiles = array_reverse( $oldfiles ); 183 183 $oldfiles[] = $file; … … 202 202 function update_home_siteurl( $old_value, $value ) { 203 203 global $wp_rewrite; 204 204 205 if ( defined( "WP_INSTALLING") )205 if ( defined( 'WP_INSTALLING' ) ) 206 206 return; 207 207 208 208 // If home changed, write rewrite rules to new location. … … 221 221 * @return string 222 222 */ 223 223 function url_shorten( $url ) { 224 $short_url = str_replace( 'http://', '', stripslashes( $url ) );224 $short_url = str_replace( 'http://', '', stripslashes( $url ) ); 225 225 $short_url = str_replace( 'www.', '', $short_url ); 226 if ('/' == substr( $short_url, -1 ) )226 if ('/' == substr( $short_url, -1 ) ) 227 227 $short_url = substr( $short_url, 0, -1 ); 228 228 if ( strlen( $short_url ) > 35 ) 229 $short_url = substr( $short_url, 0, 32 ) .'...';229 $short_url = substr( $short_url, 0, 32 ) . '...'; 230 230 return $short_url; 231 231 } 232 232 … … 242 242 * @param array $vars An array of globals to reset. 243 243 */ 244 244 function wp_reset_vars( $vars ) { 245 for ( $i =0; $i<count( $vars ); $i += 1 ) {245 for ( $i = 0; $i < count( $vars ); $i += 1 ) { 246 246 $var = $vars[$i]; 247 247 global $$var; 248 248 249 if ( empty( $_POST[ $var] ) ) {250 if ( empty( $_GET[ $var] ) )249 if ( empty( $_POST[ $var ] ) ) { 250 if ( empty( $_GET[ $var ] ) ) 251 251 $$var = ''; 252 252 else 253 $$var = $_GET[ $var];253 $$var = $_GET[ $var ]; 254 254 } else { 255 $$var = $_POST[ $var];255 $$var = $_POST[ $var ]; 256 256 } 257 257 } 258 258 } … … 264 264 * 265 265 * @param unknown_type $message 266 266 */ 267 function show_message( $message) {268 if ( is_wp_error( $message) ){267 function show_message( $message ) { 268 if ( is_wp_error( $message) ){ 269 269 if ( $message->get_error_data() ) 270 270 $message = $message->get_error_message() . ': ' . $message->get_error_data(); 271 271 else … … 284 284 * @param unknown_type $message 285 285 */ 286 286 function wp_doc_link_parse( $content ) { 287 if ( ! is_string( $content ) || empty( $content ) )287 if ( ! is_string( $content ) || empty( $content ) ) 288 288 return array(); 289 289 290 if ( ! function_exists('token_get_all') )290 if ( ! function_exists( 'token_get_all' ) ) 291 291 return array(); 292 292 293 293 $tokens = token_get_all( $content ); 294 294 $functions = array(); 295 295 $ignore_functions = array(); 296 296 for ( $t = 0, $count = count( $tokens ); $t < $count; $t++ ) { 297 if ( ! is_array( $tokens[$t] ) ) continue;298 if ( T_STRING == $tokens[ $t][0] && ( '(' == $tokens[ $t + 1 ] || '(' == $tokens[ $t + 2 ] ) ) {297 if ( ! is_array( $tokens[ $t ] ) ) continue; 298 if ( T_STRING == $tokens[ $t ][ 0 ] && ( '(' == $tokens[ $t + 1 ] || '(' == $tokens[ $t + 2 ] ) ) { 299 299 // If it's a function or class defined locally, there's not going to be any docs available 300 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] ) ) {301 $ignore_functions[] = $tokens[$t][ 1];300 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 ] ) ) { 301 $ignore_functions[] = $tokens[$t][ 1 ]; 302 302 } 303 303 // Add this to our stack of unique references 304 $functions[] = $tokens[ $t][1];304 $functions[] = $tokens[ $t ][ 1 ]; 305 305 } 306 306 } 307 307 … … 327 327 **/ 328 328 function set_screen_options() { 329 329 330 if ( isset( $_POST['wp_screen_options']) && is_array($_POST['wp_screen_options']) ) {330 if ( isset( $_POST[ 'wp_screen_options' ] ) && is_array( $_POST[ 'wp_screen_options' ] ) ) { 331 331 check_admin_referer( 'screen-options-nonce', 'screenoptionnonce' ); 332 332 333 333 if ( !$user = wp_get_current_user() ) 334 334 return; 335 $option = $_POST[ 'wp_screen_options']['option'];336 $value = $_POST[ 'wp_screen_options']['value'];337 338 if ( ! preg_match( '/^[a-z_-]+$/', $option ) )335 $option = $_POST[ 'wp_screen_options' ][ 'option' ]; 336 $value = $_POST[ 'wp_screen_options' ][ 'value' ]; 337 338 if ( ! preg_match( '/^[a-z_-]+$/', $option ) ) 339 339 return; 340 340 341 $option = str_replace( '-', '_', $option);341 $option = str_replace( '-', '_', $option ); 342 342 343 343 $map_option = $option; 344 $type = str_replace( 'edit_', '', $map_option);345 $type = str_replace( '_per_page', '', $type);346 if ( in_array( $type, get_post_types()) )344 $type = str_replace( 'edit_', '', $map_option ); 345 $type = str_replace( '_per_page', '', $type ); 346 if ( in_array( $type, get_post_types() ) ) 347 347 $map_option = 'edit_per_page'; 348 if ( in_array( $type, get_taxonomies() ) )348 if ( in_array( $type, get_taxonomies() ) ) 349 349 $map_option = 'edit_tags_per_page'; 350 350 351 351 … … 363 363 case 'plugins_network_per_page': 364 364 case 'themes_network_per_page': 365 365 case 'site_themes_network_per_page': 366 $value = ( int) $value;366 $value = ( int ) $value; 367 367 if ( $value < 1 || $value > 999 ) 368 368 return; 369 369 break; 370 370 default: 371 $value = apply_filters( 'set-screen-option', false, $option, $value);371 $value = apply_filters( 'set-screen-option', false, $option, $value ); 372 372 if ( false === $value ) 373 373 return; 374 374 break; 375 375 } 376 376 377 update_user_meta( $user->ID, $option, $value);378 wp_redirect( remove_query_arg( array( 'pagenum', 'apage', 'paged'), wp_get_referer() ) );377 update_user_meta( $user->ID, $option, $value ); 378 wp_redirect( remove_query_arg( array( 'pagenum', 'apage', 'paged' ), wp_get_referer() ) ); 379 379 exit; 380 380 } 381 381 } … … 388 388 * @param unknown_type $message 389 389 */ 390 390 function wp_menu_unfold() { 391 if ( isset( $_GET['unfoldmenu']) ) {391 if ( isset( $_GET[ 'unfoldmenu' ] ) ) { 392 392 delete_user_setting('mfold'); 393 wp_redirect( remove_query_arg( 'unfoldmenu', stripslashes( $_SERVER['REQUEST_URI']) ) );393 wp_redirect( remove_query_arg( 'unfoldmenu', stripslashes( $_SERVER[ 'REQUEST_URI' ] ) ) ); 394 394 exit; 395 395 } 396 396 } … … 403 403 * @return bool 404 404 * @param string $filename The file path to the configuration file 405 405 */ 406 function iis7_rewrite_rule_exists( $filename) {407 if ( ! file_exists( $filename) )408 return false; 409 if ( ! class_exists( 'DOMDocument') )406 function iis7_rewrite_rule_exists( $filename ) { 407 if ( ! file_exists( $filename ) ) 408 return false; 409 if ( ! class_exists( 'DOMDocument' ) ) 410 410 return false; 411 411 412 412 $doc = new DOMDocument(); 413 if ( $doc->load( $filename) === false )414 return false; 415 $xpath = new DOMXPath( $doc);416 $rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')]');413 if ( $doc->load( $filename ) === false ) 414 return false; 415 $xpath = new DOMXPath( $doc ); 416 $rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')]' ); 417 417 if ( $rules->length == 0 ) 418 418 return false; 419 419 else … … 428 428 * @param string $filename Name of the configuration file 429 429 * @return bool 430 430 */ 431 function iis7_delete_rewrite_rule( $filename) {431 function iis7_delete_rewrite_rule( $filename ) { 432 432 // If configuration file does not exist then rules also do not exist so there is nothing to delete 433 if ( ! file_exists( $filename) )433 if ( ! file_exists( $filename ) ) 434 434 return true; 435 435 436 if ( ! class_exists( 'DOMDocument') )436 if ( ! class_exists( 'DOMDocument' ) ) 437 437 return false; 438 438 439 439 $doc = new DOMDocument(); 440 440 $doc->preserveWhiteSpace = false; 441 441 442 if ( $doc -> load( $filename) === false )443 return false; 444 $xpath = new DOMXPath( $doc);445 $rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')]');442 if ( $doc -> load( $filename ) === false ) 443 return false; 444 $xpath = new DOMXPath( $doc ); 445 $rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')]' ); 446 446 if ( $rules->length > 0 ) { 447 447 $child = $rules->item(0); 448 448 $parent = $child->parentNode; 449 $parent->removeChild( $child);449 $parent->removeChild( $child ); 450 450 $doc->formatOutput = true; 451 saveDomDocument( $doc, $filename);451 saveDomDocument( $doc, $filename ); 452 452 } 453 453 return true; 454 454 } … … 463 463 * @return bool 464 464 */ 465 465 function iis7_add_rewrite_rule($filename, $rewrite_rule) { 466 if ( ! class_exists( 'DOMDocument') )466 if ( ! class_exists( 'DOMDocument' ) ) 467 467 return false; 468 468 469 469 // If configuration file does not exist then we create one. 470 470 if ( ! file_exists($filename) ) { 471 $fp = fopen( $filename, 'w' );472 fwrite( $fp, '<configuration/>');473 fclose( $fp);471 $fp = fopen( $filename, 'w' ); 472 fwrite( $fp, '<configuration/>' ); 473 fclose( $fp ); 474 474 } 475 475 476 476 $doc = new DOMDocument(); 477 477 $doc->preserveWhiteSpace = false; 478 478 479 if ( $doc->load( $filename) === false )480 return false; 481 482 $xpath = new DOMXPath( $doc);479 if ( $doc->load( $filename ) === false ) 480 return false; 481 482 $xpath = new DOMXPath( $doc ); 483 483 484 484 // First check if the rule already exists as in that case there is no need to re-add it 485 $wordpress_rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')]');485 $wordpress_rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')]' ); 486 486 if ( $wordpress_rules->length > 0 ) 487 487 return true; 488 488 489 489 // Check the XPath to the rewrite rule and create XML nodes if they do not exist 490 $xmlnodes = $xpath->query( '/configuration/system.webServer/rewrite/rules');490 $xmlnodes = $xpath->query( '/configuration/system.webServer/rewrite/rules' ); 491 491 if ( $xmlnodes->length > 0 ) { 492 492 $rules_node = $xmlnodes->item(0); 493 493 } else { 494 $rules_node = $doc->createElement( 'rules');495 496 $xmlnodes = $xpath->query( '/configuration/system.webServer/rewrite');494 $rules_node = $doc->createElement( 'rules' ); 495 496 $xmlnodes = $xpath->query( '/configuration/system.webServer/rewrite' ); 497 497 if ( $xmlnodes->length > 0 ) { 498 $rewrite_node = $xmlnodes->item( 0);499 $rewrite_node->appendChild( $rules_node);498 $rewrite_node = $xmlnodes->item( 0 ); 499 $rewrite_node->appendChild( $rules_node ); 500 500 } else { 501 $rewrite_node = $doc->createElement( 'rewrite');502 $rewrite_node->appendChild( $rules_node);503 504 $xmlnodes = $xpath->query( '/configuration/system.webServer');501 $rewrite_node = $doc->createElement( 'rewrite' ); 502 $rewrite_node->appendChild( $rules_node ); 503 504 $xmlnodes = $xpath->query( '/configuration/system.webServer' ); 505 505 if ( $xmlnodes->length > 0 ) { 506 $system_webServer_node = $xmlnodes->item( 0);507 $system_webServer_node->appendChild( $rewrite_node);506 $system_webServer_node = $xmlnodes->item( 0 ); 507 $system_webServer_node->appendChild( $rewrite_node ); 508 508 } else { 509 $system_webServer_node = $doc->createElement( 'system.webServer');510 $system_webServer_node->appendChild( $rewrite_node);511 512 $xmlnodes = $xpath->query( '/configuration');509 $system_webServer_node = $doc->createElement( 'system.webServer' ); 510 $system_webServer_node->appendChild( $rewrite_node ); 511 512 $xmlnodes = $xpath->query( '/configuration' ); 513 513 if ( $xmlnodes->length > 0 ) { 514 $config_node = $xmlnodes->item( 0);515 $config_node->appendChild( $system_webServer_node);514 $config_node = $xmlnodes->item( 0 ); 515 $config_node->appendChild( $system_webServer_node ); 516 516 } else { 517 $config_node = $doc->createElement( 'configuration');518 $doc->appendChild( $config_node);519 $config_node->appendChild( $system_webServer_node);517 $config_node = $doc->createElement( 'configuration' ); 518 $doc->appendChild( $config_node ); 519 $config_node->appendChild( $system_webServer_node ); 520 520 } 521 521 } 522 522 } 523 523 } 524 524 525 525 $rule_fragment = $doc->createDocumentFragment(); 526 $rule_fragment->appendXML( $rewrite_rule);527 $rules_node->appendChild( $rule_fragment);528 529 $doc->encoding = "UTF-8";526 $rule_fragment->appendXML( $rewrite_rule ); 527 $rules_node->appendChild( $rule_fragment ); 528 529 $doc->encoding = 'UTF-8'; 530 530 $doc->formatOutput = true; 531 saveDomDocument( $doc, $filename);531 saveDomDocument( $doc, $filename ); 532 532 533 533 return true; 534 534 } … … 541 541 * @param DOMDocument $doc 542 542 * @param string $filename 543 543 */ 544 function saveDomDocument( $doc, $filename) {544 function saveDomDocument( $doc, $filename ) { 545 545 $config = $doc->saveXML(); 546 546 $config = preg_replace("/([^\r])\n/", "$1\r\n", $config); 547 $fp = fopen( $filename, 'w');548 fwrite( $fp, $config);549 fclose( $fp);547 $fp = fopen( $filename, 'w' ); 548 fwrite( $fp, $config ); 549 fclose( $fp ); 550 550 } 551 551 552 552 /** … … 564 564 * see http://bugs.php.net/bug.php?id=30931 565 565 */ 566 566 567 if ( $path[ strlen( $path ) - 1] == '/' ) // recursively return a temporary file path568 return win_is_writable( $path . uniqid( mt_rand() ) . '.tmp' );567 if ( $path[ strlen( $path ) - 1 ] == '/' ) // recursively return a temporary file path 568 return win_is_writable( $path . uniqid( mt_rand() ) . '.tmp' ); 569 569 else if ( is_dir( $path ) ) 570 570 return win_is_writable( $path . '/' . uniqid( mt_rand() ) . '.tmp' ); 571 571 // check tmp file for read/write capabilities 572 $should_delete_tmp_file = ! file_exists( $path );572 $should_delete_tmp_file = ! file_exists( $path ); 573 573 $f = @fopen( $path, 'a' ); 574 574 if ( $f === false ) 575 575 return false; … … 588 588 global $_wp_admin_css_colors, $user_id; ?> 589 589 <fieldset><legend class="screen-reader-text"><span><?php _e('Admin Color Scheme')?></span></legend> 590 590 <?php 591 $current_color = get_user_option( 'admin_color', $user_id);592 if ( empty( $current_color) )591 $current_color = get_user_option( 'admin_color', $user_id ); 592 if ( empty( $current_color ) ) 593 593 $current_color = 'fresh'; 594 594 foreach ( $_wp_admin_css_colors as $color => $color_info ): ?> 595 <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); ?> />595 <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 ); ?> /> 596 596 <table class="color-palette"> 597 597 <tr> 598 598 <?php foreach ( $color_info->colors as $html_color ): ?> 599 <td style="background-color: <?php echo $html_color ?>" title="<?php echo $color ?>"> </td>599 <td style="background-color: <?php echo $html_color; ?>" title="<?php echo $color ?>"> </td> 600 600 <?php endforeach; ?> 601 601 </tr> 602 602 </table> 603 603 604 <label for="admin_color_<?php echo $color; ?>"><?php echo $color_info->name ?></label>604 <label for="admin_color_<?php echo $color; ?>"><?php echo $color_info->name; ?></label> 605 605 </div> 606 606 <?php endforeach; ?> 607 607 </fieldset>
