wp/wp-admin/includes/class-wp-importer.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     1 <?php
     1 <?php
     2 /**
     2 /**
     3  * WP_Importer base class
     3  * WP_Importer base class
     4  */
     4  */
       
     5 #[AllowDynamicProperties]
     5 class WP_Importer {
     6 class WP_Importer {
     6 	/**
     7 	/**
     7 	 * Class Constructor
     8 	 * Class Constructor
     8 	 */
     9 	 */
     9 	public function __construct() {}
    10 	public function __construct() {}
    10 
    11 
    11 	/**
    12 	/**
    12 	 * Returns array with imported permalinks from WordPress database
    13 	 * Returns array with imported permalinks from WordPress database.
    13 	 *
    14 	 *
    14 	 * @global wpdb $wpdb WordPress database abstraction object.
    15 	 * @global wpdb $wpdb WordPress database abstraction object.
    15 	 *
    16 	 *
    16 	 * @param string $importer_name
    17 	 * @param string $importer_name
    17 	 * @param string $blog_id
    18 	 * @param string $blog_id
    38 				foreach ( $results as $r ) {
    39 				foreach ( $results as $r ) {
    39 					// Set permalinks into array.
    40 					// Set permalinks into array.
    40 					$hashtable[ $r->meta_value ] = (int) $r->post_id;
    41 					$hashtable[ $r->meta_value ] = (int) $r->post_id;
    41 				}
    42 				}
    42 			}
    43 			}
    43 		} while ( count( $results ) == $limit );
    44 		} while ( count( $results ) === $limit );
    44 
    45 
    45 		return $hashtable;
    46 		return $hashtable;
    46 	}
    47 	}
    47 
    48 
    48 	/**
    49 	/**
    49 	 * Return count of imported permalinks from WordPress database
    50 	 * Returns count of imported permalinks from WordPress database.
    50 	 *
    51 	 *
    51 	 * @global wpdb $wpdb WordPress database abstraction object.
    52 	 * @global wpdb $wpdb WordPress database abstraction object.
    52 	 *
    53 	 *
    53 	 * @param string $importer_name
    54 	 * @param string $importer_name
    54 	 * @param string $blog_id
    55 	 * @param string $blog_id
    71 
    72 
    72 		return $count;
    73 		return $count;
    73 	}
    74 	}
    74 
    75 
    75 	/**
    76 	/**
    76 	 * Set array with imported comments from WordPress database
    77 	 * Sets array with imported comments from WordPress database.
    77 	 *
    78 	 *
    78 	 * @global wpdb $wpdb WordPress database abstraction object.
    79 	 * @global wpdb $wpdb WordPress database abstraction object.
    79 	 *
    80 	 *
    80 	 * @param string $blog_id
    81 	 * @param string $blog_id
    81 	 * @return array
    82 	 * @return array
   102 					list ( $comment_agent_blog_id, $source_comment_id ) = explode( '-', $r->comment_agent );
   103 					list ( $comment_agent_blog_id, $source_comment_id ) = explode( '-', $r->comment_agent );
   103 
   104 
   104 					$source_comment_id = (int) $source_comment_id;
   105 					$source_comment_id = (int) $source_comment_id;
   105 
   106 
   106 					// Check if this comment came from this blog.
   107 					// Check if this comment came from this blog.
   107 					if ( $blog_id == $comment_agent_blog_id ) {
   108 					if ( (int) $blog_id === (int) $comment_agent_blog_id ) {
   108 						$hashtable[ $source_comment_id ] = (int) $r->comment_ID;
   109 						$hashtable[ $source_comment_id ] = (int) $r->comment_ID;
   109 					}
   110 					}
   110 				}
   111 				}
   111 			}
   112 			}
   112 		} while ( count( $results ) == $limit );
   113 		} while ( count( $results ) === $limit );
   113 
   114 
   114 		return $hashtable;
   115 		return $hashtable;
   115 	}
   116 	}
   116 
   117 
   117 	/**
   118 	/**
   173 
   174 
   174 		return $user_id;
   175 		return $user_id;
   175 	}
   176 	}
   176 
   177 
   177 	/**
   178 	/**
   178 	 * Sort by strlen, longest string first
   179 	 * Sorts by strlen, longest string first.
   179 	 *
   180 	 *
   180 	 * @param string $a
   181 	 * @param string $a
   181 	 * @param string $b
   182 	 * @param string $b
   182 	 * @return int
   183 	 * @return int
   183 	 */
   184 	 */
   184 	public function cmpr_strlen( $a, $b ) {
   185 	public function cmpr_strlen( $a, $b ) {
   185 		return strlen( $b ) - strlen( $a );
   186 		return strlen( $b ) - strlen( $a );
   186 	}
   187 	}
   187 
   188 
   188 	/**
   189 	/**
   189 	 * GET URL
   190 	 * Gets URL.
   190 	 *
   191 	 *
   191 	 * @param string $url
   192 	 * @param string $url
   192 	 * @param string $username
   193 	 * @param string $username
   193 	 * @param string $password
   194 	 * @param string $password
   194 	 * @param bool   $head
   195 	 * @param bool   $head
   211 
   212 
   212 		return wp_safe_remote_request( $url, $args );
   213 		return wp_safe_remote_request( $url, $args );
   213 	}
   214 	}
   214 
   215 
   215 	/**
   216 	/**
   216 	 * Bump up the request timeout for http requests
   217 	 * Bumps up the request timeout for http requests.
   217 	 *
   218 	 *
   218 	 * @param int $val
   219 	 * @param int $val
   219 	 * @return int
   220 	 * @return int
   220 	 */
   221 	 */
   221 	public function bump_request_timeout( $val ) {
   222 	public function bump_request_timeout( $val ) {
   222 		return 60;
   223 		return 60;
   223 	}
   224 	}
   224 
   225 
   225 	/**
   226 	/**
   226 	 * Check if user has exceeded disk quota
   227 	 * Checks if user has exceeded disk quota.
   227 	 *
   228 	 *
   228 	 * @return bool
   229 	 * @return bool
   229 	 */
   230 	 */
   230 	public function is_user_over_quota() {
   231 	public function is_user_over_quota() {
   231 		if ( function_exists( 'upload_is_user_over_quota' ) ) {
   232 		if ( function_exists( 'upload_is_user_over_quota' ) ) {
   236 
   237 
   237 		return false;
   238 		return false;
   238 	}
   239 	}
   239 
   240 
   240 	/**
   241 	/**
   241 	 * Replace newlines, tabs, and multiple spaces with a single space.
   242 	 * Replaces newlines, tabs, and multiple spaces with a single space.
   242 	 *
   243 	 *
   243 	 * @param string $text
   244 	 * @param string $text
   244 	 * @return string
   245 	 * @return string
   245 	 */
   246 	 */
   246 	public function min_whitespace( $text ) {
   247 	public function min_whitespace( $text ) {