]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/includes/class-wp-importer.php
WordPress 4.7.1-scripts
[autoinstalls/wordpress.git] / wp-admin / includes / class-wp-importer.php
index 0268e7e6ee39835349edcf2a21d768a3091818ba..794fa5cf0d07c3ed6c198b48bbb9365ed74062be 100644 (file)
@@ -6,17 +6,19 @@ class WP_Importer {
        /**
         * Class Constructor
         *
-        * @return void
         */
-       function __construct() {}
+       public function __construct() {}
 
        /**
         * Returns array with imported permalinks from WordPress database
         *
+        * @global wpdb $wpdb WordPress database abstraction object.
+        *
+        * @param string $importer_name
         * @param string $bid
         * @return array
         */
-       function get_imported_posts( $importer_name, $bid ) {
+       public function get_imported_posts( $importer_name, $bid ) {
                global $wpdb;
 
                $hashtable = array();
@@ -41,7 +43,7 @@ class WP_Importer {
                        }
                } while ( count( $results ) == $limit );
 
-               // unset to save memory
+               // Unset to save memory.
                unset( $results, $r );
 
                return $hashtable;
@@ -50,10 +52,13 @@ class WP_Importer {
        /**
         * Return count of imported permalinks from WordPress database
         *
+        * @global wpdb $wpdb WordPress database abstraction object.
+        *
+        * @param string $importer_name
         * @param string $bid
         * @return int
         */
-       function count_imported_posts( $importer_name, $bid ) {
+       public function count_imported_posts( $importer_name, $bid ) {
                global $wpdb;
 
                $count = 0;
@@ -67,7 +72,7 @@ class WP_Importer {
                if ( !empty( $result ) )
                        $count = intval( $result[0]->cnt );
 
-               // unset to save memory
+               // Unset to save memory.
                unset( $results );
 
                return $count;
@@ -76,10 +81,12 @@ class WP_Importer {
        /**
         * Set array with imported comments from WordPress database
         *
+        * @global wpdb $wpdb WordPress database abstraction object.
+        *
         * @param string $bid
         * @return array
         */
-       function get_imported_comments( $bid ) {
+       public function get_imported_comments( $bid ) {
                global $wpdb;
 
                $hashtable = array();
@@ -109,13 +116,18 @@ class WP_Importer {
                        }
                } while ( count( $results ) == $limit );
 
-               // unset to save memory
+               // Unset to save memory.
                unset( $results, $r );
 
                return $hashtable;
        }
 
-       function set_blog( $blog_id ) {
+       /**
+        *
+        * @param int $blog_id
+        * @return int|void
+        */
+       public function set_blog( $blog_id ) {
                if ( is_numeric( $blog_id ) ) {
                        $blog_id = (int) $blog_id;
                } else {
@@ -124,13 +136,15 @@ class WP_Importer {
                                fwrite( STDERR, "Error: can not determine blog_id from $blog_id\n" );
                                exit();
                        }
-                       if ( empty( $parsed['path'] ) )
+                       if ( empty( $parsed['path'] ) ) {
                                $parsed['path'] = '/';
-                       $blog = get_blog_details( array( 'domain' => $parsed['host'], 'path' => $parsed['path'] ) );
-                       if ( !$blog ) {
+                       }
+                       $blogs = get_sites( array( 'domain' => $parsed['host'], 'number' => 1, 'path' => $parsed['path'] ) );
+                       if ( ! $blogs ) {
                                fwrite( STDERR, "Error: Could not find blog\n" );
                                exit();
                        }
+                       $blog = array_shift( $blogs );
                        $blog_id = (int) $blog->blog_id;
                }
 
@@ -142,7 +156,12 @@ class WP_Importer {
                return $blog_id;
        }
 
-       function set_user( $user_id ) {
+       /**
+        *
+        * @param int $user_id
+        * @return int|void
+        */
+       public function set_user( $user_id ) {
                if ( is_numeric( $user_id ) ) {
                        $user_id = (int) $user_id;
                } else {
@@ -164,7 +183,7 @@ class WP_Importer {
         * @param string $b
         * @return int
         */
-       function cmpr_strlen( $a, $b ) {
+       public function cmpr_strlen( $a, $b ) {
                return strlen( $b ) - strlen( $a );
        }
 
@@ -174,16 +193,15 @@ class WP_Importer {
         * @param string $url
         * @param string $username
         * @param string $password
-        * @param bool $head
+        * @param bool   $head
         * @return array
         */
-       function get_page( $url, $username = '', $password = '', $head = false ) {
+       public function get_page( $url, $username = '', $password = '', $head = false ) {
                // Increase the timeout
-               add_filter( 'http_request_timeout', array( &$this, 'bump_request_timeout' ) );
+               add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
 
                $headers = array();
                $args = array();
-               $args['reject_unsafe_urls'] = true;
                if ( true === $head )
                        $args['method'] = 'HEAD';
                if ( !empty( $username ) && !empty( $password ) )
@@ -191,7 +209,7 @@ class WP_Importer {
 
                $args['headers'] = $headers;
 
-               return wp_remote_request( $url, $args );
+               return wp_safe_remote_request( $url, $args );
        }
 
        /**
@@ -200,7 +218,7 @@ class WP_Importer {
         * @param int $val
         * @return int
         */
-       function bump_request_timeout( $val ) {
+       public function bump_request_timeout( $val ) {
                return 60;
        }
 
@@ -209,10 +227,9 @@ class WP_Importer {
         *
         * @return bool
         */
-       function is_user_over_quota() {
+       public function is_user_over_quota() {
                if ( function_exists( 'upload_is_user_over_quota' ) ) {
-                       if ( upload_is_user_over_quota( 1 ) ) {
-                               echo "Sorry, you have used your upload quota.\n";
+                       if ( upload_is_user_over_quota() ) {
                                return true;
                        }
                }
@@ -226,16 +243,17 @@ class WP_Importer {
         * @param string $string
         * @return string
         */
-       function min_whitespace( $string ) {
+       public function min_whitespace( $string ) {
                return preg_replace( '|[\r\n\t ]+|', ' ', $string );
        }
 
        /**
         * Reset global variables that grow out of control during imports
         *
-        * @return void
+        * @global wpdb  $wpdb
+        * @global array $wp_actions
         */
-       function stop_the_insanity() {
+       public function stop_the_insanity() {
                global $wpdb, $wp_actions;
                // Or define( 'WP_IMPORTING', true );
                $wpdb->queries = array();
@@ -249,7 +267,7 @@ class WP_Importer {
  * Exits when a required param is not set.
  *
  * @param string $param
- * @param bool $required
+ * @param bool   $required
  * @return mixed
  */
 function get_cli_args( $param, $required = false ) {
@@ -274,14 +292,14 @@ function get_cli_args( $param, $required = false ) {
                        }
 
                        $last_arg = $key;
-               } else if ( (bool) preg_match( "/^-([a-zA-Z0-9]+)/", $args[$i], $match ) ) {
+               } elseif ( (bool) preg_match( "/^-([a-zA-Z0-9]+)/", $args[$i], $match ) ) {
                        for ( $j = 0, $jl = strlen( $match[1] ); $j < $jl; $j++ ) {
                                $key = $match[1]{$j};
                                $out[$key] = true;
                        }
 
                        $last_arg = $key;
-               } else if ( $last_arg !== null ) {
+               } elseif ( $last_arg !== null ) {
                        $out[$last_arg] = $args[$i];
                }
        }