示例#1
0
 public function generate_bundle($debug = false)
 {
     // do not generate export bundle if not supported
     if (!self::is_bundle_supported($this->options)) {
         return;
     }
     $uploads = wp_upload_dir();
     //generate temporary folder
     $export_dir = wp_all_export_secure_file($uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::UPLOADS_DIRECTORY, $this->id) . DIRECTORY_SEPARATOR;
     $bundle_dir = $export_dir . 'bundle' . DIRECTORY_SEPARATOR;
     // clear tmp dir
     wp_all_export_rrmdir($bundle_dir);
     @mkdir($bundle_dir);
     $friendly_name = sanitize_file_name($this->friendly_name);
     $template = "WP All Import Template - " . $friendly_name . ".txt";
     $templates = array();
     $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
     if (!$is_secure_import) {
         $filepath = get_attached_file($this->attch_id);
     } else {
         $filepath = wp_all_export_get_absolute_path($this->options['filepath']);
     }
     @copy($filepath, $bundle_dir . basename($filepath));
     if (!empty($this->options['tpl_data'])) {
         $template_data = array($this->options['tpl_data']);
         $template_data[0]['source_file_name'] = basename($filepath);
         $template_options = maybe_unserialize($template_data[0]['options']);
         $templates[$template_options['custom_type']] = $template_data;
         $readme = __("The other two files in this zip are the export file containing all of your data and the import template for WP All Import. \n\nTo import this data, create a new import with WP All Import and upload this zip file.", "wp_all_export_plugin");
         file_put_contents($bundle_dir . 'readme.txt', $readme);
     }
     file_put_contents($bundle_dir . $template, json_encode($templates));
     if ($this->options['creata_a_new_export_file'] && !empty($this->options['cpt']) and class_exists('WooCommerce') and in_array('shop_order', $this->options['cpt']) and empty($this->parent_id)) {
         $bundle_path = $export_dir . $friendly_name . '-' . ($this->iteration + 1) . '.zip';
     } else {
         $bundle_path = $export_dir . $friendly_name . '.zip';
     }
     if (@file_exists($bundle_path)) {
         @unlink($bundle_path);
     }
     PMXE_Zip::zipDir($bundle_dir, $bundle_path);
     // clear tmp dir
     wp_all_export_rrmdir($bundle_dir);
     $exportOptions = $this->options;
     $exportOptions['bundlepath'] = wp_all_export_get_relative_path($bundle_path);
     $this->set(array('options' => $exportOptions))->save();
     return $bundle_path;
 }
示例#2
0
 function wp_all_export_rrmdir($dir)
 {
     if (is_dir($dir)) {
         $objects = scandir($dir);
         foreach ($objects as $object) {
             if ($object != "." && $object != "..") {
                 if (filetype($dir . "/" . $object) == "dir") {
                     wp_all_export_rrmdir($dir . "/" . $object);
                 } else {
                     unlink($dir . "/" . $object);
                 }
             }
         }
         reset($objects);
         rmdir($dir);
     }
 }
示例#3
0
 public function split_bundle()
 {
     $nonce = !empty($_REQUEST['_wpnonce']) ? $_REQUEST['_wpnonce'] : '';
     if (!wp_verify_nonce($nonce, '_wpnonce-download_split_bundle')) {
         die(__('Security check', 'wp_all_export_plugin'));
     } else {
         $uploads = wp_upload_dir();
         $id = PMXE_Plugin::$session->update_previous;
         if (empty($id)) {
             $id = $this->input->get('id');
         }
         $export = new PMXE_Export_Record();
         if (!$export->getById($id)->isEmpty()) {
             if (!empty($export->options['split_files_list'])) {
                 $tmp_dir = $uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::TEMP_DIRECTORY . DIRECTORY_SEPARATOR . md5($export->id) . DIRECTORY_SEPARATOR;
                 $bundle_dir = $tmp_dir . 'split_files' . DIRECTORY_SEPARATOR;
                 wp_all_export_rrmdir($tmp_dir);
                 @mkdir($tmp_dir);
                 @mkdir($bundle_dir);
                 foreach ($export->options['split_files_list'] as $file) {
                     @copy($file, $bundle_dir . basename($file));
                 }
                 $friendly_name = sanitize_file_name($export->friendly_name);
                 $bundle_path = $tmp_dir . $friendly_name . '-split-files.zip';
                 PMXE_Zip::zipDir($bundle_dir, $bundle_path);
                 if (file_exists($bundle_path)) {
                     $bundle_url = $uploads['baseurl'] . str_replace($uploads['basedir'], '', $bundle_path);
                     PMXE_download::zip($bundle_path);
                 }
             }
         }
     }
 }