コード例 #1
0
 function wp_all_import_clear_directory($path)
 {
     if (($dir = @opendir($path . '/')) !== false or ($dir = @opendir($path)) !== false) {
         while (($file = @readdir($dir)) !== false) {
             $filePath = $path . '/' . $file;
             if (is_dir($filePath) && !in_array($file, array('.', '..'))) {
                 wp_all_import_rmdir($filePath);
             } elseif (is_file($filePath)) {
                 @unlink($filePath);
             }
         }
     }
 }
コード例 #2
0
function wp_all_import_rmdir($dir)
{
    $scanned_files = @scandir($dir);
    if (!empty($scanned_files) and is_array($scanned_files)) {
        $files = array_diff($scanned_files, array('.', '..'));
        if (!empty($files)) {
            foreach ($files as $file) {
                is_dir("{$dir}/{$file}") ? wp_all_import_rmdir("{$dir}/{$file}") : @unlink("{$dir}/{$file}");
            }
        }
        return @rmdir($dir);
    }
}
コード例 #3
0
 function wp_all_import_remove_source($file, $remove_dir = true)
 {
     @unlink($file);
     $path_parts = pathinfo($file);
     if (!empty($path_parts['dirname'])) {
         $path_all_parts = explode('/', $path_parts['dirname']);
         $dirname = array_pop($path_all_parts);
         if (wp_all_import_isValidMd5($dirname)) {
             if ($remove_dir) {
                 @unlink($path_parts['dirname'] . DIRECTORY_SEPARATOR . 'index.php');
             }
             if ($remove_dir or count(@scandir($path_parts['dirname'])) == 2) {
                 wp_all_import_rmdir($path_parts['dirname']);
             }
         }
     }
 }
コード例 #4
0
ファイル: manage.php プロジェクト: TakenCdosG/chefs
 protected function create_bundle($id, $nonce)
 {
     $uploads = wp_upload_dir();
     //generate temporary folder
     $tmp_dir = $uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::TEMP_DIRECTORY . DIRECTORY_SEPARATOR . md5($nonce) . DIRECTORY_SEPARATOR;
     $bundle_dir = $tmp_dir . 'bundle' . DIRECTORY_SEPARATOR;
     // clear tmp dir
     wp_all_import_rmdir($tmp_dir);
     @mkdir($tmp_dir);
     $import = new PMXI_Import_Record();
     if (!$import->getById($id)->isEmpty()) {
         $friendly_name = sanitize_file_name($import->friendly_name);
         @mkdir($bundle_dir);
         $tpl_name = empty($import->friendly_name) ? $import->name : $import->friendly_name;
         if (empty($tpl_name)) {
             $tpl_name = 'Import_' . $import->id;
         }
         $tpl_data = array('name' => $tpl_name, 'is_keep_linebreaks' => 0, 'is_leave_html' => 0, 'fix_characters' => 0, 'options' => $import->options);
         $template_data = array($tpl_data);
         $template = "WP All Import Template - " . $tpl_name . ".txt";
         $filepath = '';
         if (in_array($import->type, array('url'))) {
             $template_data[0]['_import_type'] = 'url';
             $template_data[0]['_import_url'] = $import->path;
             // $history = new PMXI_File_List();
             // $history->setColumns('id', 'name', 'registered_on', 'path')->getBy(array('import_id' => $import->id), 'id DESC');
             // if ($history->count()){
             // 	foreach ($history as $file){
             // 		$filepath = wp_all_import_get_absolute_path($file['path']);
             // 		if (@file_exists($filepath)) break;
             // 	}
             // }
         } else {
             $filepath = wp_all_import_get_absolute_path($import->path);
         }
         file_put_contents($bundle_dir . $template, json_encode($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);
         @copy($filepath, $bundle_dir . basename($filepath));
         $bundle_path = $tmp_dir . $tpl_name . '.zip';
         PMXI_Zip::zipDir($bundle_dir, $bundle_path);
         return $bundle_path;
     }
 }
コード例 #5
0
ファイル: plugin.php プロジェクト: GolgoSoft/KeenerWP
 /**
  * convert imports options
  * compatibility with version 3.2.3
  */
 public function _fix_options()
 {
     global $wpdb;
     $imports = new PMXI_Import_List();
     $post = new PMXI_Post_Record();
     $templates = new PMXI_Template_List();
     $template = new PMXI_Template_Record();
     $is_migrated = get_option('pmxi_is_migrated');
     $uploads = wp_upload_dir();
     if (empty($is_migrated) or version_compare($is_migrated, PMXI_VERSION) < 0) {
         //PMXI_VERSION
         $commit_migration = true;
         if (empty($is_migrated)) {
             // plugin version less than 4.0.0
             wp_all_import_rmdir($uploads['basedir'] . '/wpallimport_history');
             wp_all_import_rmdir($uploads['basedir'] . '/wpallimport_logs');
             foreach ($imports->setColumns($imports->getTable() . '.*')->getBy(array('id !=' => ''))->convertRecords() as $imp) {
                 $imp->getById($imp->id);
                 if (!$imp->isEmpty() and !empty($imp->template)) {
                     $options = array_merge($imp->options, $imp->template);
                     $this->__ver_4_transition_fix($options);
                     $imp->set(array('options' => $options))->update();
                     if ($imp->type == 'file') {
                         $imp->set(array('path' => $uploads['basedir'] . DIRECTORY_SEPARATOR . self::FILES_DIRECTORY . DIRECTORY_SEPARATOR . basename($imp->path)))->update();
                     }
                 }
             }
             foreach ($templates->setColumns($templates->getTable() . '.*')->getBy(array('id !=' => ''))->convertRecords() as $tpl) {
                 $tpl->getById($tpl->id);
                 if (!$tpl->isEmpty() and !empty($tpl->title)) {
                     $opt = empty($tpl->options) ? array() : $tpl->options;
                     $options = array_merge($opt, array('title' => $tpl->title, 'content' => $tpl->content, 'is_keep_linebreaks' => $tpl->is_keep_linebreaks, 'is_leave_html' => $tpl->is_leave_html, 'fix_characters' => $tpl->fix_characters));
                     $this->__ver_4_transition_fix($options);
                     $tpl->set(array('options' => $options))->update();
                 }
             }
             $commit_migration = $this->__fix_db_schema();
             // feature to version 4.0.0
         } else {
             // migration fixes for vesions
             switch ($is_migrated) {
                 case '4.0.0-beta1':
                 case '4.0.0-beta2':
                 case '4.0.0 RC1':
                 case '4.0.0':
                 case '4.0.1':
                     $commit_migration = $this->__fix_db_schema();
                     // feature to version 4.0.0
                     break;
                 case '4.0.2':
                 case '4.0.3':
                 case '4.0.4':
                     break;
                 default:
                     # code...
                     break;
             }
             foreach ($imports->setColumns($imports->getTable() . '.*')->getBy(array('id !=' => ''))->convertRecords() as $imp) {
                 $imp->getById($imp->id);
                 if (!$imp->isEmpty()) {
                     $options = $imp->options;
                     $this->__ver_4x_transition_fix($options, $is_migrated);
                     $imp->set(array('options' => $options))->update();
                 }
             }
             foreach ($templates->setColumns($templates->getTable() . '.*')->getBy(array('id !=' => ''))->convertRecords() as $tpl) {
                 $tpl->getById($tpl->id);
                 if (!$tpl->isEmpty()) {
                     $options = empty($tpl->options) ? array() : $tpl->options;
                     $this->__ver_4x_transition_fix($options, $is_migrated);
                     $tpl->set(array('options' => $options))->update();
                 }
             }
         }
         if ($commit_migration) {
             update_option('pmxi_is_migrated', PMXI_VERSION);
         }
     }
 }
コード例 #6
0
function pmxi_wp_ajax_get_bundle_post_type()
{
    if (!check_ajax_referer('wp_all_import_secure', 'security', false)) {
        exit(json_encode(array('success' => false, 'errors' => '<div class="error inline"><p>' . __('Security check', 'wp_all_import_plugin') . '</p></div>')));
    }
    if (!current_user_can(PMXI_Plugin::$capabilities)) {
        exit(json_encode(array('success' => false, 'errors' => '<div class="error inline"><p>' . __('Security check', 'wp_all_import_plugin') . '</p></div>')));
    }
    $input = new PMXI_Input();
    $post = $input->post(array('file' => ''));
    $response = array('post_type' => false, 'notice' => false);
    if (preg_match('%\\W(zip)$%i', trim($post['file']))) {
        if (!class_exists('PclZip')) {
            include_once PMXI_Plugin::ROOT_DIR . '/libraries/pclzip.lib.php';
        }
        $uploads = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::FILES_DIRECTORY . DIRECTORY_SEPARATOR;
        $archive = new PclZip($uploads . $post['file']);
        $tmp_dir = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::TEMP_DIRECTORY . DIRECTORY_SEPARATOR . md5(time());
        @wp_mkdir_p($tmp_dir);
        $v_result_list = $archive->extract(PCLZIP_OPT_PATH, $tmp_dir, PCLZIP_OPT_REPLACE_NEWER);
        if ($v_result_list) {
            foreach ($v_result_list as $unzipped_file) {
                if ($unzipped_file['status'] == 'ok' and preg_match('%\\W(xml|csv|txt|dat|psv|json|xls|xlsx)$%i', trim($unzipped_file['stored_filename'])) and strpos($unzipped_file['stored_filename'], 'readme.txt') === false) {
                    if (strpos(basename($unzipped_file['stored_filename']), 'WP All Import Template') === 0 || strpos(basename($unzipped_file['stored_filename']), 'templates_') === 0) {
                        $templates = file_get_contents($unzipped_file['filename']);
                        $decodedTemplates = json_decode($templates, true);
                        $templateOptions = empty($decodedTemplates[0]) ? current($decodedTemplates) : $decodedTemplates;
                        $options = empty($templateOptions[0]['options']) ? false : maybe_unserialize($templateOptions[0]['options']);
                        $response['post_type'] = !empty($options) ? $options['custom_type'] : false;
                    }
                }
            }
        }
        wp_all_import_rmdir($tmp_dir);
        if (!empty($response['post_type'])) {
            switch ($response['post_type']) {
                case 'product':
                case 'shop_order':
                    if (!class_exists('WooCommerce')) {
                        $response['notice'] = __('<p class="wpallimport-bundle-notice">The import bundle you are using requires WooCommerce.</p><a class="upgrade_link" href="https://wordpress.org/plugins/woocommerce/" target="_blank">Get WooCommerce</a>.', 'wp_all_import_plugin');
                    } else {
                        if (!defined('PMWI_EDITION')) {
                            $response['notice'] = __('<p class="wpallimport-bundle-notice">The import bundle you are using requires the Pro version of the WooCommerce Add-On.</p><a href="http://www.wpallimport.com/checkout/?edd_action=add_to_cart&download_id=1529&edd_options%5Bprice_id%5D=1" class="upgrade_link" target="_blank">Purchase the WooCommerce Add-On</a>.', 'wp_all_import_plugin');
                        } elseif (PMWI_EDITION != 'paid') {
                            $response['notice'] = __('<p class="wpallimport-bundle-notice">The import bundle you are using requires the Pro version of the WooCommerce Add-On, but you have the free version installed.</p><a href="http://www.wpallimport.com/checkout/?edd_action=add_to_cart&download_id=1529&edd_options%5Bprice_id%5D=1" target="_blank" class="upgrade_link">Purchase the WooCommerce Add-On</a>.', 'wp_all_import_plugin');
                        }
                    }
                    break;
                case 'import_users':
                    if (!class_exists('PMUI_Plugin')) {
                        $response['notice'] = __('<p class="wpallimport-bundle-notice">The import bundle you are using requires the User Import Add-On.</p><a href="http://www.wpallimport.com/checkout/?edd_action=add_to_cart&download_id=1921&edd_options%5Bprice_id%5D=1" target="_blank" class="upgrade_link">Purchase the User Import Add-On</a>.', 'wp_all_import_plugin');
                    }
                    break;
                default:
                    # code...
                    break;
            }
        }
    }
    exit(json_encode($response));
}
コード例 #7
0
ファイル: settings.php プロジェクト: lizbur10/js_finalproject
 public function cleanup()
 {
     $removedFiles = 0;
     $wp_uploads = wp_upload_dir();
     $dir = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::TEMP_DIRECTORY;
     $cacheDir = PMXI_Plugin::ROOT_DIR . '/libraries/cache';
     $files = array_diff(@scandir($dir), array('.', '..'));
     $cacheFiles = @array_diff(@scandir($cacheDir), array('.', '..'));
     $msg = __('Files not found', 'wp_all_import_plugin');
     if (count($files) or count($cacheFiles)) {
         wp_all_import_clear_directory($dir);
         wp_all_import_clear_directory($cacheDir);
         $msg = __('Clean Up has been successfully completed.', 'wp_all_import_plugin');
     }
     // clean logs files
     $table = PMXI_Plugin::getInstance()->getTablePrefix() . 'history';
     global $wpdb;
     $histories = $wpdb->get_results("SELECT * FROM {$table}", ARRAY_A);
     if (!empty($histories)) {
         $importRecord = new PMXI_Import_Record();
         $importRecord->clear();
         foreach ($histories as $history) {
             $importRecord->getById($history['import_id']);
             if ($importRecord->isEmpty()) {
                 $historyRecord = new PMXI_History_Record();
                 $historyRecord->getById($history['id']);
                 if (!$historyRecord->isEmpty()) {
                     $historyRecord->delete();
                 }
             }
             $importRecord->clear();
         }
     }
     // clean uploads folder
     $table = PMXI_Plugin::getInstance()->getTablePrefix() . 'files';
     $files = $wpdb->get_results("SELECT * FROM {$table}", ARRAY_A);
     $required_dirs = array();
     if (!empty($files)) {
         $importRecord = new PMXI_Import_Record();
         $importRecord->clear();
         foreach ($files as $file) {
             $importRecord->getById($file['import_id']);
             if ($importRecord->isEmpty()) {
                 $fileRecord = new PMXI_File_Record();
                 $fileRecord->getById($file['id']);
                 if (!$fileRecord->isEmpty()) {
                     $fileRecord->delete();
                 }
             } else {
                 $path_parts = pathinfo(wp_all_import_get_absolute_path($file['path']));
                 if (!empty($path_parts['dirname'])) {
                     $path_all_parts = explode('/', $path_parts['dirname']);
                     $dirname = array_pop($path_all_parts);
                     if (wp_all_import_isValidMd5($dirname)) {
                         $required_dirs[] = $path_parts['dirname'];
                     }
                 }
             }
             $importRecord->clear();
         }
     }
     $uploads_dir = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::UPLOADS_DIRECTORY;
     if (($dir = @opendir($uploads_dir . DIRECTORY_SEPARATOR)) !== false or ($dir = @opendir($uploads_dir)) !== false) {
         while (($file = @readdir($dir)) !== false) {
             $filePath = $uploads_dir . DIRECTORY_SEPARATOR . $file;
             if (is_dir($filePath) and !in_array($filePath, $required_dirs) and !in_array($file, array('.', '..'))) {
                 wp_all_import_rmdir($filePath);
             }
         }
     }
     wp_redirect(add_query_arg('pmxi_nt', urlencode($msg), $this->baseUrl));
     die;
 }