コード例 #1
0
ファイル: restorer.php プロジェクト: nikintharan/campaign
 private function unpack_package_archive($package, $delete_package = true, $type = false)
 {
     if (!empty($this->ud_foreign) && !empty($this->ud_foreign_working_dir)) {
         if (is_dir($this->ud_foreign_working_dir)) {
             return $this->ud_foreign_working_dir;
         } else {
             global $updraftplus;
             $updraftplus->log('Previously unpacked directory seems to have disappeared; will unpack again');
         }
     }
     global $wp_filesystem, $updraftplus;
     $packsize = round(filesize($package) / 1048576, 1) . ' Mb';
     $this->skin->feedback($this->strings['unpack_package'] . ' (' . basename($package) . ', ' . $packsize . ')');
     $upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/';
     //Clean up contents of upgrade directory beforehand.
     $upgrade_files = $wp_filesystem->dirlist($upgrade_folder);
     if (!empty($upgrade_files)) {
         foreach ($upgrade_files as $file) {
             $wp_filesystem->delete($upgrade_folder . $file['name'], true);
         }
     }
     //We need a working directory
     #This is the only change from the WP core version - minimise path length
     #$working_dir = $upgrade_folder . basename($package, '.zip');
     $working_dir = $upgrade_folder . substr(md5($package), 0, 8);
     // Clean up working directory
     if ($wp_filesystem->is_dir($working_dir)) {
         $wp_filesystem->delete($working_dir, true);
     }
     // Unzip package to working directory
     if ('.zip' == strtolower(substr($package, -4, 4))) {
         $result = unzip_file($package, $working_dir);
     } elseif ('.tar' == strtolower(substr($package, -4, 4)) || '.tar.gz' == strtolower(substr($package, -7, 7)) || '.tar.bz2' == strtolower(substr($package, -8, 8))) {
         if (!class_exists('UpdraftPlus_Archive_Tar')) {
             if (false === strpos(get_include_path(), UPDRAFTPLUS_DIR . '/includes/PEAR')) {
                 set_include_path(UPDRAFTPLUS_DIR . '/includes/PEAR' . PATH_SEPARATOR . get_include_path());
             }
             require_once UPDRAFTPLUS_DIR . '/includes/PEAR/Archive/Tar.php';
         }
         $p_compress = null;
         if ('.tar.gz' == strtolower(substr($package, -7, 7))) {
             $p_compress = 'gz';
         } elseif ('.tar.bz2' == strtolower(substr($package, -8, 8))) {
             $p_compress = 'bz2';
         }
         # It's not pretty. But it works.
         if (is_a($wp_filesystem, 'WP_Filesystem_Direct')) {
             $extract_dir = $working_dir;
         } else {
             $updraft_dir = $updraftplus->backups_dir_location();
             if (!$updraftplus->really_is_writable($updraft_dir)) {
                 $updraftplus->log_e("Backup directory (%s) is not writable, or does not exist.", $updraft_dir);
                 $result = new WP_Error('unpack_failed', $this->strings['unpack_failed'], $tar->extract);
             } else {
                 $extract_dir = $updraft_dir . '/' . basename($working_dir) . '-old';
                 if (file_exists($extract_dir)) {
                     $updraftplus->remove_local_directory($extract_dir);
                 }
                 $updraftplus->log("Using a temporary folder to extract before moving over WPFS: {$extract_dir}");
             }
         }
         # Slightly hackish - rather than re-write Archive_Tar to use wp_filesystem, we instead unpack into the location that we already require to be directly writable for other reasons, and then move from there.
         if (empty($result)) {
             $this->ud_extract_count = 0;
             $this->ud_working_dir = trailingslashit($working_dir);
             $this->ud_extract_dir = untrailingslashit($extract_dir);
             $this->ud_made_dirs = array();
             add_filter('updraftplus_tar_wrote', array($this, 'tar_wrote'), 10, 2);
             $tar = new UpdraftPlus_Archive_Tar($package, $p_compress);
             $result = $tar->extract($extract_dir, false);
             if (!is_a($wp_filesystem, 'WP_Filesystem_Direct')) {
                 $updraftplus->remove_local_directory($extract_dir);
             }
             if (true != $result) {
                 $result = new WP_Error('unpack_failed', $this->strings['unpack_failed'], $result);
             } else {
                 if (!is_a($wp_filesystem, 'WP_Filesystem_Direct')) {
                     $updraftplus->log('Moved unpacked tarball contents');
                 }
             }
             remove_filter('updraftplus_tar_wrote', array($this, 'tar_wrote'), 10, 2);
         }
     }
     // Once extracted, delete the package if required.
     if ($delete_package) {
         unlink($package);
     }
     if (is_wp_error($result)) {
         $wp_filesystem->delete($working_dir, true);
         if ('incompatible_archive' == $result->get_error_code()) {
             return new WP_Error('incompatible_archive', $this->strings['incompatible_archive'], $result->get_error_data());
         }
         return $result;
     }
     if (!empty($this->ud_foreign)) {
         $this->ud_foreign_working_dir = $working_dir;
         # Zip containing an SQL file. We try a default pattern.
         if ('db' === $type) {
             $basepack = basename($package, '.zip');
             if ($wp_filesystem->exists($working_dir . '/' . $basepack . '.sql')) {
                 $wp_filesystem->move($working_dir . '/' . $basepack . '.sql', $working_dir . "/backup.db", true);
                 $updraftplus->log("Moving database file {$basepack}.sql to backup.db");
             }
         }
     }
     return $working_dir;
 }
コード例 #2
0
ファイル: morefiles.php プロジェクト: jimrucinski/Vine
 public function checkzip_wpcore($zipfile, &$mess, &$warn, &$err)
 {
     if (!empty($this->wpcore_foundyet) && 3 == $this->wpcore_foundyet) {
         return;
     }
     if (!is_readable($zipfile)) {
         $warn[] = sprintf(__('Unable to read zip file (%s) - could not pre-scan it to check its integrity.', 'updraftplus'), basename($zipfile));
         return;
     }
     if ('.zip' == strtolower(substr($zipfile, -4, 4))) {
         if (!class_exists('UpdraftPlus_PclZip')) {
             require UPDRAFTPLUS_DIR . '/class-zip.php';
         }
         $zip = new UpdraftPlus_PclZip();
         if (!$zip->open($zipfile)) {
             $warn[] = sprintf(__('Unable to open zip file (%s) - could not pre-scan it to check its integrity.', 'updraftplus'), basename($zipfile));
             return;
         }
         # Don't put this in the for loop, or the magic __get() method gets called and opens the zip file every time the loop goes round
         $numfiles = $zip->numFiles;
         for ($i = 0; $i < $numfiles; $i++) {
             $si = $zip->statIndex($i);
             if ($si['name'] == 'wp-admin/index.php') {
                 $this->wpcore_foundyet = $this->wpcore_foundyet | 1;
                 if (3 == $this->wpcore_foundyet) {
                     return;
                 }
             }
             if ($si['name'] == 'xmlrpc.php' || $si['name'] == 'xmlrpc.php/xmlrpc.php') {
                 $this->wpcore_foundyet = $this->wpcore_foundyet | 2;
                 if (3 == $this->wpcore_foundyet) {
                     return;
                 }
             }
         }
         @$zip->close();
     } elseif (preg_match('/\\.tar(\\.(gz|bz2))$/i', $zipfile)) {
         if (!class_exists('UpdraftPlus_Archive_Tar')) {
             if (false === strpos(get_include_path(), UPDRAFTPLUS_DIR . '/includes/PEAR')) {
                 set_include_path(UPDRAFTPLUS_DIR . '/includes/PEAR' . PATH_SEPARATOR . get_include_path());
             }
             require_once UPDRAFTPLUS_DIR . '/includes/PEAR/Archive/Tar.php';
         }
         $p_compress = null;
         if ('.tar.gz' == strtolower(substr($zipfile, -7, 7))) {
             $p_compress = 'gz';
         } elseif ('.tar.bz2' == strtolower(substr($zipfile, -8, 8))) {
             $p_compress = 'bz2';
         }
         $tar = new UpdraftPlus_Archive_Tar($zipfile, $p_compress);
         $list = $tar->listContent();
         foreach ($list as $file) {
             if (is_array($file) && isset($file['filename'])) {
                 if ('wp-admin/index.php' == $file['filename']) {
                     $this->wpcore_foundyet = $this->wpcore_foundyet | 1;
                     if (3 == $this->wpcore_foundyet) {
                         return;
                     }
                 } elseif ('xmlrpc.php' == $file['filename']) {
                     $this->wpcore_foundyet = $this->wpcore_foundyet | 2;
                     if (3 == $this->wpcore_foundyet) {
                         return;
                     }
                 }
             }
         }
     }
 }