wp/wp-admin/includes/class-wp-importer.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
    10 	public function __construct() {}
    10 	public function __construct() {}
    11 
    11 
    12 	/**
    12 	/**
    13 	 * Returns array with imported permalinks from WordPress database
    13 	 * Returns array with imported permalinks from WordPress database
    14 	 *
    14 	 *
       
    15 	 * @global wpdb $wpdb WordPress database abstraction object.
       
    16 	 *
       
    17 	 * @param string $importer_name
    15 	 * @param string $bid
    18 	 * @param string $bid
    16 	 * @return array
    19 	 * @return array
    17 	 */
    20 	 */
    18 	public function get_imported_posts( $importer_name, $bid ) {
    21 	public function get_imported_posts( $importer_name, $bid ) {
    19 		global $wpdb;
    22 		global $wpdb;
    24 		$offset = 0;
    27 		$offset = 0;
    25 
    28 
    26 		// Grab all posts in chunks
    29 		// Grab all posts in chunks
    27 		do {
    30 		do {
    28 			$meta_key = $importer_name . '_' . $bid . '_permalink';
    31 			$meta_key = $importer_name . '_' . $bid . '_permalink';
    29 			$sql = $wpdb->prepare( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '%s' LIMIT %d,%d", $meta_key, $offset, $limit );
    32 			$sql = $wpdb->prepare( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = %s LIMIT %d,%d", $meta_key, $offset, $limit );
    30 			$results = $wpdb->get_results( $sql );
    33 			$results = $wpdb->get_results( $sql );
    31 
    34 
    32 			// Increment offset
    35 			// Increment offset
    33 			$offset = ( $limit + $offset );
    36 			$offset = ( $limit + $offset );
    34 
    37 
    47 	}
    50 	}
    48 
    51 
    49 	/**
    52 	/**
    50 	 * Return count of imported permalinks from WordPress database
    53 	 * Return count of imported permalinks from WordPress database
    51 	 *
    54 	 *
       
    55 	 * @global wpdb $wpdb WordPress database abstraction object.
       
    56 	 *
       
    57 	 * @param string $importer_name
    52 	 * @param string $bid
    58 	 * @param string $bid
    53 	 * @return int
    59 	 * @return int
    54 	 */
    60 	 */
    55 	public function count_imported_posts( $importer_name, $bid ) {
    61 	public function count_imported_posts( $importer_name, $bid ) {
    56 		global $wpdb;
    62 		global $wpdb;
    72 		return $count;
    78 		return $count;
    73 	}
    79 	}
    74 
    80 
    75 	/**
    81 	/**
    76 	 * Set array with imported comments from WordPress database
    82 	 * Set array with imported comments from WordPress database
       
    83 	 *
       
    84 	 * @global wpdb $wpdb WordPress database abstraction object.
    77 	 *
    85 	 *
    78 	 * @param string $bid
    86 	 * @param string $bid
    79 	 * @return array
    87 	 * @return array
    80 	 */
    88 	 */
    81 	public function get_imported_comments( $bid ) {
    89 	public function get_imported_comments( $bid ) {
   112 		unset( $results, $r );
   120 		unset( $results, $r );
   113 
   121 
   114 		return $hashtable;
   122 		return $hashtable;
   115 	}
   123 	}
   116 
   124 
       
   125 	/**
       
   126 	 *
       
   127 	 * @param int $blog_id
       
   128 	 * @return int|void
       
   129 	 */
   117 	public function set_blog( $blog_id ) {
   130 	public function set_blog( $blog_id ) {
   118 		if ( is_numeric( $blog_id ) ) {
   131 		if ( is_numeric( $blog_id ) ) {
   119 			$blog_id = (int) $blog_id;
   132 			$blog_id = (int) $blog_id;
   120 		} else {
   133 		} else {
   121 			$blog = 'http://' . preg_replace( '#^https?://#', '', $blog_id );
   134 			$blog = 'http://' . preg_replace( '#^https?://#', '', $blog_id );
   122 			if ( ( !$parsed = parse_url( $blog ) ) || empty( $parsed['host'] ) ) {
   135 			if ( ( !$parsed = parse_url( $blog ) ) || empty( $parsed['host'] ) ) {
   123 				fwrite( STDERR, "Error: can not determine blog_id from $blog_id\n" );
   136 				fwrite( STDERR, "Error: can not determine blog_id from $blog_id\n" );
   124 				exit();
   137 				exit();
   125 			}
   138 			}
   126 			if ( empty( $parsed['path'] ) )
   139 			if ( empty( $parsed['path'] ) ) {
   127 				$parsed['path'] = '/';
   140 				$parsed['path'] = '/';
   128 			$blog = get_blog_details( array( 'domain' => $parsed['host'], 'path' => $parsed['path'] ) );
   141 			}
   129 			if ( !$blog ) {
   142 			$blogs = get_sites( array( 'domain' => $parsed['host'], 'number' => 1, 'path' => $parsed['path'] ) );
       
   143 			if ( ! $blogs ) {
   130 				fwrite( STDERR, "Error: Could not find blog\n" );
   144 				fwrite( STDERR, "Error: Could not find blog\n" );
   131 				exit();
   145 				exit();
   132 			}
   146 			}
       
   147 			$blog = array_shift( $blogs );
   133 			$blog_id = (int) $blog->blog_id;
   148 			$blog_id = (int) $blog->blog_id;
   134 		}
   149 		}
   135 
   150 
   136 		if ( function_exists( 'is_multisite' ) ) {
   151 		if ( function_exists( 'is_multisite' ) ) {
   137 			if ( is_multisite() )
   152 			if ( is_multisite() )
   139 		}
   154 		}
   140 
   155 
   141 		return $blog_id;
   156 		return $blog_id;
   142 	}
   157 	}
   143 
   158 
       
   159 	/**
       
   160 	 *
       
   161 	 * @param int $user_id
       
   162 	 * @return int|void
       
   163 	 */
   144 	public function set_user( $user_id ) {
   164 	public function set_user( $user_id ) {
   145 		if ( is_numeric( $user_id ) ) {
   165 		if ( is_numeric( $user_id ) ) {
   146 			$user_id = (int) $user_id;
   166 			$user_id = (int) $user_id;
   147 		} else {
   167 		} else {
   148 			$user_id = (int) username_exists( $user_id );
   168 			$user_id = (int) username_exists( $user_id );
   171 	 * GET URL
   191 	 * GET URL
   172 	 *
   192 	 *
   173 	 * @param string $url
   193 	 * @param string $url
   174 	 * @param string $username
   194 	 * @param string $username
   175 	 * @param string $password
   195 	 * @param string $password
   176 	 * @param bool $head
   196 	 * @param bool   $head
   177 	 * @return array
   197 	 * @return array
   178 	 */
   198 	 */
   179 	public function get_page( $url, $username = '', $password = '', $head = false ) {
   199 	public function get_page( $url, $username = '', $password = '', $head = false ) {
   180 		// Increase the timeout
   200 		// Increase the timeout
   181 		add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
   201 		add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
   208 	 * @return bool
   228 	 * @return bool
   209 	 */
   229 	 */
   210 	public function is_user_over_quota() {
   230 	public function is_user_over_quota() {
   211 		if ( function_exists( 'upload_is_user_over_quota' ) ) {
   231 		if ( function_exists( 'upload_is_user_over_quota' ) ) {
   212 			if ( upload_is_user_over_quota() ) {
   232 			if ( upload_is_user_over_quota() ) {
   213 				echo "Sorry, you have used your upload quota.\n";
       
   214 				return true;
   233 				return true;
   215 			}
   234 			}
   216 		}
   235 		}
   217 
   236 
   218 		return false;
   237 		return false;
   227 	public function min_whitespace( $string ) {
   246 	public function min_whitespace( $string ) {
   228 		return preg_replace( '|[\r\n\t ]+|', ' ', $string );
   247 		return preg_replace( '|[\r\n\t ]+|', ' ', $string );
   229 	}
   248 	}
   230 
   249 
   231 	/**
   250 	/**
   232 	 * Reset global variables that grow out of control during imports
   251 	 * Resets global variables that grow out of control during imports.
   233 	 *
   252 	 *
   234 	 * @return void
   253 	 * @since 3.0.0
       
   254 	 *
       
   255 	 * @global wpdb  $wpdb       WordPress database abstraction object.
       
   256 	 * @global array $wp_actions
   235 	 */
   257 	 */
   236 	public function stop_the_insanity() {
   258 	public function stop_the_insanity() {
   237 		global $wpdb, $wp_actions;
   259 		global $wpdb, $wp_actions;
   238 		// Or define( 'WP_IMPORTING', true );
   260 		// Or define( 'WP_IMPORTING', true );
   239 		$wpdb->queries = array();
   261 		$wpdb->queries = array();
   245 /**
   267 /**
   246  * Returns value of command line params.
   268  * Returns value of command line params.
   247  * Exits when a required param is not set.
   269  * Exits when a required param is not set.
   248  *
   270  *
   249  * @param string $param
   271  * @param string $param
   250  * @param bool $required
   272  * @param bool   $required
   251  * @return mixed
   273  * @return mixed
   252  */
   274  */
   253 function get_cli_args( $param, $required = false ) {
   275 function get_cli_args( $param, $required = false ) {
   254 	$args = $_SERVER['argv'];
   276 	$args = $_SERVER['argv'];
   255 
   277