Changeset 42343 for trunk/src/wp-admin/includes/class-wp-importer.php
- Timestamp:
- 11/30/2017 11:09:33 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-wp-importer.php
r41628 r42343 6 6 /** 7 7 * Class Constructor 8 *9 8 */ 10 9 public function __construct() {} … … 24 23 $hashtable = array(); 25 24 26 $limit = 100;25 $limit = 100; 27 26 $offset = 0; 28 27 … … 30 29 do { 31 30 $meta_key = $importer_name . '_' . $bid . '_permalink'; 32 $sql = $wpdb->prepare( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = %s LIMIT %d,%d", $meta_key, $offset, $limit );33 $results = $wpdb->get_results( $sql );31 $sql = $wpdb->prepare( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = %s LIMIT %d,%d", $meta_key, $offset, $limit ); 32 $results = $wpdb->get_results( $sql ); 34 33 35 34 // Increment offset 36 35 $offset = ( $limit + $offset ); 37 36 38 if ( ! empty( $results ) ) {37 if ( ! empty( $results ) ) { 39 38 foreach ( $results as $r ) { 40 39 // Set permalinks into array 41 $hashtable[ $r->meta_value] = intval( $r->post_id );40 $hashtable[ $r->meta_value ] = intval( $r->post_id ); 42 41 } 43 42 } … … 66 65 // Get count of permalinks 67 66 $meta_key = $importer_name . '_' . $bid . '_permalink'; 68 $sql = $wpdb->prepare( "SELECT COUNT( post_id ) AS cnt FROM $wpdb->postmeta WHERE meta_key = '%s'", $meta_key );67 $sql = $wpdb->prepare( "SELECT COUNT( post_id ) AS cnt FROM $wpdb->postmeta WHERE meta_key = '%s'", $meta_key ); 69 68 70 69 $result = $wpdb->get_results( $sql ); 71 70 72 if ( ! empty( $result ) )71 if ( ! empty( $result ) ) { 73 72 $count = intval( $result[0]->cnt ); 73 } 74 74 75 75 // Unset to save memory. … … 92 92 $hashtable = array(); 93 93 94 $limit = 100;94 $limit = 100; 95 95 $offset = 0; 96 96 97 97 // Grab all comments in chunks 98 98 do { 99 $sql = $wpdb->prepare( "SELECT comment_ID, comment_agent FROM $wpdb->comments LIMIT %d,%d", $offset, $limit );99 $sql = $wpdb->prepare( "SELECT comment_ID, comment_agent FROM $wpdb->comments LIMIT %d,%d", $offset, $limit ); 100 100 $results = $wpdb->get_results( $sql ); 101 101 … … 103 103 $offset = ( $limit + $offset ); 104 104 105 if ( ! empty( $results ) ) {105 if ( ! empty( $results ) ) { 106 106 foreach ( $results as $r ) { 107 107 // Explode comment_agent key 108 108 list ( $ca_bid, $source_comment_id ) = explode( '-', $r->comment_agent ); 109 $source_comment_id = intval( $source_comment_id );109 $source_comment_id = intval( $source_comment_id ); 110 110 111 111 // Check if this comment came from this blog 112 112 if ( $bid == $ca_bid ) { 113 $hashtable[ $source_comment_id] = intval( $r->comment_ID );113 $hashtable[ $source_comment_id ] = intval( $r->comment_ID ); 114 114 } 115 115 } … … 124 124 125 125 /** 126 *127 126 * @param int $blog_id 128 127 * @return int|void … … 133 132 } else { 134 133 $blog = 'http://' . preg_replace( '#^https?://#', '', $blog_id ); 135 if ( ( ! $parsed = parse_url( $blog ) ) || empty( $parsed['host'] ) ) {134 if ( ( ! $parsed = parse_url( $blog ) ) || empty( $parsed['host'] ) ) { 136 135 fwrite( STDERR, "Error: can not determine blog_id from $blog_id\n" ); 137 136 exit(); … … 140 139 $parsed['path'] = '/'; 141 140 } 142 $blogs = get_sites( array( 'domain' => $parsed['host'], 'number' => 1, 'path' => $parsed['path'] ) ); 141 $blogs = get_sites( 142 array( 143 'domain' => $parsed['host'], 144 'number' => 1, 145 'path' => $parsed['path'], 146 ) 147 ); 143 148 if ( ! $blogs ) { 144 149 fwrite( STDERR, "Error: Could not find blog\n" ); 145 150 exit(); 146 151 } 147 $blog = array_shift( $blogs );152 $blog = array_shift( $blogs ); 148 153 $blog_id = (int) $blog->blog_id; 149 154 } 150 155 151 156 if ( function_exists( 'is_multisite' ) ) { 152 if ( is_multisite() ) 157 if ( is_multisite() ) { 153 158 switch_to_blog( $blog_id ); 159 } 154 160 } 155 161 … … 158 164 159 165 /** 160 *161 166 * @param int $user_id 162 167 * @return int|void … … 169 174 } 170 175 171 if ( ! $user_id || !wp_set_current_user( $user_id ) ) {176 if ( ! $user_id || ! wp_set_current_user( $user_id ) ) { 172 177 fwrite( STDERR, "Error: can not find user\n" ); 173 178 exit(); … … 202 207 203 208 $headers = array(); 204 $args = array();205 if ( true === $head ) 209 $args = array(); 210 if ( true === $head ) { 206 211 $args['method'] = 'HEAD'; 207 if ( !empty( $username ) && !empty( $password ) ) 212 } 213 if ( ! empty( $username ) && ! empty( $password ) ) { 208 214 $headers['Authorization'] = 'Basic ' . base64_encode( "$username:$password" ); 215 } 209 216 210 217 $args['headers'] = $headers; … … 279 286 280 287 $last_arg = null; 281 $return = null;288 $return = null; 282 289 283 290 $il = sizeof( $args ); 284 291 285 292 for ( $i = 1, $il; $i < $il; $i++ ) { 286 if ( (bool) preg_match( "/^--(.+)/", $args[$i], $match ) ) {287 $parts = explode( "=", $match[1] );288 $key = preg_replace( "/[^a-z0-9]+/", "", $parts[0] );293 if ( (bool) preg_match( '/^--(.+)/', $args[ $i ], $match ) ) { 294 $parts = explode( '=', $match[1] ); 295 $key = preg_replace( '/[^a-z0-9]+/', '', $parts[0] ); 289 296 290 297 if ( isset( $parts[1] ) ) { 291 $out[ $key] = $parts[1];298 $out[ $key ] = $parts[1]; 292 299 } else { 293 $out[ $key] = true;300 $out[ $key ] = true; 294 301 } 295 302 296 303 $last_arg = $key; 297 } elseif ( (bool) preg_match( "/^-([a-zA-Z0-9]+)/", $args[$i], $match ) ) {304 } elseif ( (bool) preg_match( '/^-([a-zA-Z0-9]+)/', $args[ $i ], $match ) ) { 298 305 for ( $j = 0, $jl = strlen( $match[1] ); $j < $jl; $j++ ) { 299 $key = $match[1]{$j};300 $out[ $key] = true;306 $key = $match[1]{$j}; 307 $out[ $key ] = true; 301 308 } 302 309 303 310 $last_arg = $key; 304 311 } elseif ( $last_arg !== null ) { 305 $out[ $last_arg] = $args[$i];312 $out[ $last_arg ] = $args[ $i ]; 306 313 } 307 314 } 308 315 309 316 // Check array for specified param 310 if ( isset( $out[ $param] ) ) {317 if ( isset( $out[ $param ] ) ) { 311 318 // Set return value 312 $return = $out[ $param];319 $return = $out[ $param ]; 313 320 } 314 321 315 322 // Check for missing required param 316 if ( ! isset( $out[$param] ) && $required ) {323 if ( ! isset( $out[ $param ] ) && $required ) { 317 324 // Display message and exit 318 325 echo "\"$param\" parameter is required but was not specified\n";
Note: See TracChangeset
for help on using the changeset viewer.