-
+ 942F981387EDC8404D66D96649B268C9AF338B94993B7F32CD635922A3B0941AC737450AC389E5D053F1B5289A43B1EFA2C25FBDA9FC801EED9C154A0275F56D
mp-wp/wp-admin/includes/misc.php
(0 . 0)(1 . 241)
36591 <?php
36592 /**
36593 * Misc WordPress Administration API.
36594 *
36595 * @package WordPress
36596 * @subpackage Administration
36597 */
36598
36599 /**
36600 * {@internal Missing Short Description}}
36601 *
36602 * @since unknown
36603 *
36604 * @return unknown
36605 */
36606 function got_mod_rewrite() {
36607 $got_rewrite = apache_mod_loaded('mod_rewrite', true);
36608 return apply_filters('got_rewrite', $got_rewrite);
36609 }
36610
36611 /**
36612 * {@internal Missing Short Description}}
36613 *
36614 * @since unknown
36615 *
36616 * @param unknown_type $filename
36617 * @param unknown_type $marker
36618 * @return array An array of strings from a file (.htaccess ) from between BEGIN and END markers.
36619 */
36620 function extract_from_markers( $filename, $marker ) {
36621 $result = array ();
36622
36623 if (!file_exists( $filename ) ) {
36624 return $result;
36625 }
36626
36627 if ( $markerdata = explode( "\n", implode( '', file( $filename ) ) ));
36628 {
36629 $state = false;
36630 foreach ( $markerdata as $markerline ) {
36631 if (strpos($markerline, '# END ' . $marker) !== false)
36632 $state = false;
36633 if ( $state )
36634 $result[] = $markerline;
36635 if (strpos($markerline, '# BEGIN ' . $marker) !== false)
36636 $state = true;
36637 }
36638 }
36639
36640 return $result;
36641 }
36642
36643 /**
36644 * {@internal Missing Short Description}}
36645 *
36646 * Inserts an array of strings into a file (.htaccess ), placing it between
36647 * BEGIN and END markers. Replaces existing marked info. Retains surrounding
36648 * data. Creates file if none exists.
36649 *
36650 * @since unknown
36651 *
36652 * @param unknown_type $filename
36653 * @param unknown_type $marker
36654 * @param unknown_type $insertion
36655 * @return bool True on write success, false on failure.
36656 */
36657 function insert_with_markers( $filename, $marker, $insertion ) {
36658 if (!file_exists( $filename ) || is_writeable( $filename ) ) {
36659 if (!file_exists( $filename ) ) {
36660 $markerdata = '';
36661 } else {
36662 $markerdata = explode( "\n", implode( '', file( $filename ) ) );
36663 }
36664
36665 $f = fopen( $filename, 'w' );
36666 $foundit = false;
36667 if ( $markerdata ) {
36668 $state = true;
36669 foreach ( $markerdata as $n => $markerline ) {
36670 if (strpos($markerline, '# BEGIN ' . $marker) !== false)
36671 $state = false;
36672 if ( $state ) {
36673 if ( $n + 1 < count( $markerdata ) )
36674 fwrite( $f, "{$markerline}\n" );
36675 else
36676 fwrite( $f, "{$markerline}" );
36677 }
36678 if (strpos($markerline, '# END ' . $marker) !== false) {
36679 fwrite( $f, "# BEGIN {$marker}\n" );
36680 if ( is_array( $insertion ))
36681 foreach ( $insertion as $insertline )
36682 fwrite( $f, "{$insertline}\n" );
36683 fwrite( $f, "# END {$marker}\n" );
36684 $state = true;
36685 $foundit = true;
36686 }
36687 }
36688 }
36689 if (!$foundit) {
36690 fwrite( $f, "\n# BEGIN {$marker}\n" );
36691 foreach ( $insertion as $insertline )
36692 fwrite( $f, "{$insertline}\n" );
36693 fwrite( $f, "# END {$marker}\n" );
36694 }
36695 fclose( $f );
36696 return true;
36697 } else {
36698 return false;
36699 }
36700 }
36701
36702 /**
36703 * Updates the htaccess file with the current rules if it is writable.
36704 *
36705 * Always writes to the file if it exists and is writable to ensure that we
36706 * blank out old rules.
36707 *
36708 * @since unknown
36709 */
36710 function save_mod_rewrite_rules() {
36711 global $wp_rewrite;
36712
36713 $home_path = get_home_path();
36714 $htaccess_file = $home_path.'.htaccess';
36715
36716 // If the file doesn't already exists check for write access to the directory and whether of not we have some rules.
36717 // else check for write access to the file.
36718 if ((!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks()) || is_writable($htaccess_file)) {
36719 if ( got_mod_rewrite() ) {
36720 $rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() );
36721 return insert_with_markers( $htaccess_file, 'WordPress', $rules );
36722 }
36723 }
36724
36725 return false;
36726 }
36727
36728 /**
36729 * {@internal Missing Short Description}}
36730 *
36731 * @since unknown
36732 *
36733 * @param unknown_type $file
36734 */
36735 function update_recently_edited( $file ) {
36736 $oldfiles = (array ) get_option( 'recently_edited' );
36737 if ( $oldfiles ) {
36738 $oldfiles = array_reverse( $oldfiles );
36739 $oldfiles[] = $file;
36740 $oldfiles = array_reverse( $oldfiles );
36741 $oldfiles = array_unique( $oldfiles );
36742 if ( 5 < count( $oldfiles ))
36743 array_pop( $oldfiles );
36744 } else {
36745 $oldfiles[] = $file;
36746 }
36747 update_option( 'recently_edited', $oldfiles );
36748 }
36749
36750 /**
36751 * If siteurl or home changed, flush rewrite rules.
36752 *
36753 * @since unknown
36754 *
36755 * @param unknown_type $old_value
36756 * @param unknown_type $value
36757 */
36758 function update_home_siteurl( $old_value, $value ) {
36759 global $wp_rewrite;
36760
36761 if ( defined( "WP_INSTALLING" ) )
36762 return;
36763
36764 // If home changed, write rewrite rules to new location.
36765 $wp_rewrite->flush_rules();
36766 }
36767
36768 add_action( 'update_option_home', 'update_home_siteurl', 10, 2 );
36769 add_action( 'update_option_siteurl', 'update_home_siteurl', 10, 2 );
36770
36771 /**
36772 * {@internal Missing Short Description}}
36773 *
36774 * @since unknown
36775 *
36776 * @param unknown_type $url
36777 * @return unknown
36778 */
36779 function url_shorten( $url ) {
36780 $short_url = str_replace( 'http://', '', stripslashes( $url ));
36781 $short_url = str_replace( 'www.', '', $short_url );
36782 if ('/' == substr( $short_url, -1 ))
36783 $short_url = substr( $short_url, 0, -1 );
36784 if ( strlen( $short_url ) > 35 )
36785 $short_url = substr( $short_url, 0, 32 ).'...';
36786 return $short_url;
36787 }
36788
36789 /**
36790 * {@internal Missing Short Description}}
36791 *
36792 * @since unknown
36793 *
36794 * @param unknown_type $vars
36795 */
36796 function wp_reset_vars( $vars ) {
36797 for ( $i=0; $i<count( $vars ); $i += 1 ) {
36798 $var = $vars[$i];
36799 global $$var;
36800
36801 if (!isset( $$var ) ) {
36802 if ( empty( $_POST["$var"] ) ) {
36803 if ( empty( $_GET["$var"] ) )
36804 $$var = '';
36805 else
36806 $$var = $_GET["$var"];
36807 } else {
36808 $$var = $_POST["$var"];
36809 }
36810 }
36811 }
36812 }
36813
36814 /**
36815 * {@internal Missing Short Description}}
36816 *
36817 * @since unknown
36818 *
36819 * @param unknown_type $message
36820 */
36821 function show_message($message) {
36822 if( is_wp_error($message) ){
36823 if( $message->get_error_data() )
36824 $message = $message->get_error_message() . ': ' . $message->get_error_data();
36825 else
36826 $message = $message->get_error_message();
36827 }
36828 echo "<p>$message</p>\n";
36829 }
36830
36831 ?>