Exemplo n.º 1
0
 /**
  * Step #1: Choose CPT
  */
 public function index()
 {
     PMXE_Plugin::$session->clean_session();
     $wp_uploads = wp_upload_dir();
     $this->data['post'] = $post = $this->input->post(array('cpt' => '', 'export_to' => 'xml', 'export_type' => 'specific', 'wp_query' => '', 'filter_rules_hierarhy' => '', 'product_matching_mode' => 'strict', 'wp_query_selector' => 'wp_query'));
     // Delete history
     $history_files = PMXE_Helper::safe_glob(PMXE_ROOT_DIR . '/history/*', PMXE_Helper::GLOB_RECURSE | PMXE_Helper::GLOB_PATH);
     if (!empty($history_files)) {
         foreach ($history_files as $filePath) {
             @file_exists($filePath) and @unlink($filePath);
         }
     }
     if ($this->input->post('is_submitted')) {
         PMXE_Plugin::$session->set('export_type', $post['export_type']);
         PMXE_Plugin::$session->set('filter_rules_hierarhy', $post['filter_rules_hierarhy']);
         PMXE_Plugin::$session->set('product_matching_mode', $post['product_matching_mode']);
         PMXE_Plugin::$session->set('wp_query_selector', $post['wp_query_selector']);
         $engine = new XmlExportEngine($post, $this->errors);
         $engine->init_additional_data();
     }
     if ($this->input->post('is_submitted') and !$this->errors->get_error_codes()) {
         check_admin_referer('choose-cpt', '_wpnonce_choose-cpt');
         PMXE_Plugin::$session->save_data();
         wp_redirect(add_query_arg('action', 'template', $this->baseUrl));
         die;
     }
     $this->render();
 }
Exemplo n.º 2
0
 /**
  * Step #1: Choose CPT
  */
 public function index()
 {
     PMXE_Plugin::$session->clean_session();
     $wp_uploads = wp_upload_dir();
     $this->data['post'] = $post = $this->input->post(array('cpt' => '', 'export_to' => 'xml', 'export_type' => 'specific', 'wp_query' => '', 'filter_rules_hierarhy' => '', 'product_matching_mode' => 'strict', 'wp_query_selector' => 'wp_query', 'auto_generate' => 0));
     // Delete history
     $history_files = PMXE_Helper::safe_glob(PMXE_ROOT_DIR . '/history/*', PMXE_Helper::GLOB_RECURSE | PMXE_Helper::GLOB_PATH);
     if (!empty($history_files)) {
         foreach ($history_files as $filePath) {
             @file_exists($filePath) and @unlink($filePath);
         }
     }
     if ($this->input->post('is_submitted')) {
         PMXE_Plugin::$session->set('export_type', $post['export_type']);
         PMXE_Plugin::$session->set('filter_rules_hierarhy', $post['filter_rules_hierarhy']);
         PMXE_Plugin::$session->set('product_matching_mode', $post['product_matching_mode']);
         PMXE_Plugin::$session->set('wp_query_selector', $post['wp_query_selector']);
         $engine = new XmlExportEngine($post, $this->errors);
         $engine->init_additional_data();
         if (!empty($post['auto_generate'])) {
             $auto_generate = array('ids' => array(), 'cc_label' => array(), 'cc_php' => array(), 'cc_code' => array(), 'cc_sql' => array(), 'cc_type' => array(), 'cc_options' => array(), 'cc_value' => array(), 'cc_name' => array());
             $available_data = $engine->init_available_data();
             $available_sections = apply_filters("wp_all_export_available_sections", $engine->get('available_sections'));
             foreach ($available_sections as $slug => $section) {
                 foreach ($available_data[$section['content']] as $field) {
                     if (is_array($field) and isset($field['auto'])) {
                         $auto_generate['ids'][] = 1;
                         $auto_generate['cc_label'][] = $field['label'];
                         $auto_generate['cc_php'][] = 0;
                         $auto_generate['cc_code'][] = '';
                         $auto_generate['cc_sql'][] = '';
                         $auto_generate['cc_type'][] = $field['type'];
                         $auto_generate['cc_options'][] = '';
                         $auto_generate['cc_value'][] = $field['label'];
                         $auto_generate['cc_name'][] = $field['name'];
                     }
                 }
             }
             foreach ($auto_generate as $key => $value) {
                 PMXE_Plugin::$session->set($key, $value);
             }
             PMXE_Plugin::$session->save_data();
         }
     }
     if ($this->input->post('is_submitted') and !$this->errors->get_error_codes()) {
         check_admin_referer('choose-cpt', '_wpnonce_choose-cpt');
         PMXE_Plugin::$session->save_data();
         if (!empty($post['auto_generate'])) {
             wp_redirect(add_query_arg('action', 'options', $this->baseUrl));
             die;
         } else {
             wp_redirect(add_query_arg('action', 'template', $this->baseUrl));
             die;
         }
     }
     $this->render();
 }
Exemplo n.º 3
0
 /**
  * Class constructor containing dispatching logic
  * @param string $rootDir Plugin root dir
  * @param string $pluginFilePath Plugin main file
  */
 protected function __construct()
 {
     // regirster autoloading method
     if (function_exists('__autoload') and !in_array('__autoload', spl_autoload_functions())) {
         // make sure old way of autoloading classes is not broken
         spl_autoload_register('__autoload');
     }
     spl_autoload_register(array($this, '__autoload'));
     // register helpers
     if (is_dir(self::ROOT_DIR . '/helpers')) {
         foreach (PMXE_Helper::safe_glob(self::ROOT_DIR . '/helpers/*.php', PMXE_Helper::GLOB_RECURSE | PMXE_Helper::GLOB_PATH) as $filePath) {
             require_once $filePath;
         }
     }
     // init plugin options
     $option_name = get_class($this) . '_Options';
     $options_default = PMXE_Config::createFromFile(self::ROOT_DIR . '/config/options.php')->toArray();
     $this->options = array_intersect_key(get_option($option_name, array()), $options_default) + $options_default;
     $this->options = array_intersect_key($options_default, array_flip(array('info_api_url'))) + $this->options;
     // make sure hidden options apply upon plugin reactivation
     if ('' == $this->options['cron_job_key']) {
         $this->options['cron_job_key'] = wp_all_export_url_title(wp_all_export_rand_char(12));
     }
     update_option($option_name, $this->options);
     $this->options = get_option(get_class($this) . '_Options');
     register_activation_hook(self::FILE, array($this, '__activation'));
     // register action handlers
     if (is_dir(self::ROOT_DIR . '/actions')) {
         if (is_dir(self::ROOT_DIR . '/actions')) {
             foreach (PMXE_Helper::safe_glob(self::ROOT_DIR . '/actions/*.php', PMXE_Helper::GLOB_RECURSE | PMXE_Helper::GLOB_PATH) as $filePath) {
                 require_once $filePath;
                 $function = $actionName = basename($filePath, '.php');
                 if (preg_match('%^(.+?)[_-](\\d+)$%', $actionName, $m)) {
                     $actionName = $m[1];
                     $priority = intval($m[2]);
                 } else {
                     $priority = 10;
                 }
                 add_action($actionName, self::PREFIX . str_replace('-', '_', $function), $priority, 99);
                 // since we don't know at this point how many parameters each plugin expects, we make sure they will be provided with all of them (it's unlikely any developer will specify more than 99 parameters in a function)
             }
         }
     }
     // register filter handlers
     if (is_dir(self::ROOT_DIR . '/filters')) {
         foreach (PMXE_Helper::safe_glob(self::ROOT_DIR . '/filters/*.php', PMXE_Helper::GLOB_RECURSE | PMXE_Helper::GLOB_PATH) as $filePath) {
             require_once $filePath;
             $function = $actionName = basename($filePath, '.php');
             if (preg_match('%^(.+?)[_-](\\d+)$%', $actionName, $m)) {
                 $actionName = $m[1];
                 $priority = intval($m[2]);
             } else {
                 $priority = 10;
             }
             add_filter($actionName, self::PREFIX . str_replace('-', '_', $function), $priority, 99);
             // since we don't know at this point how many parameters each plugin expects, we make sure they will be provided with all of them (it's unlikely any developer will specify more than 99 parameters in a function)
         }
     }
     // register shortcodes handlers
     if (is_dir(self::ROOT_DIR . '/shortcodes')) {
         foreach (PMXE_Helper::safe_glob(self::ROOT_DIR . '/shortcodes/*.php', PMXE_Helper::GLOB_RECURSE | PMXE_Helper::GLOB_PATH) as $filePath) {
             $tag = strtolower(str_replace('/', '_', preg_replace('%^' . preg_quote(self::ROOT_DIR . '/shortcodes/', '%') . '|\\.php$%', '', $filePath)));
             add_shortcode($tag, array($this, 'shortcodeDispatcher'));
         }
     }
     // register admin page pre-dispatcher
     add_action('admin_init', array($this, '__adminInit'));
     add_action('admin_init', array($this, '__fix_db_schema'));
     add_action('init', array($this, 'init'));
 }
Exemplo n.º 4
0
 /**
  * Step #1: Choose CPT
  */
 public function index()
 {
     $action = $this->input->get('action');
     $DefaultOptions = array('cpt' => '', 'export_to' => 'xml', 'export_type' => 'specific', 'wp_query' => '', 'filter_rules_hierarhy' => '', 'product_matching_mode' => 'strict', 'wp_query_selector' => 'wp_query', 'auto_generate' => 0);
     if (!in_array($action, array('index'))) {
         PMXE_Plugin::$session->clean_session();
         $this->data['preload'] = false;
     } else {
         $DefaultOptions = (PMXE_Plugin::$session->has_session() ? PMXE_Plugin::$session->get_clear_session_data() : array()) + $DefaultOptions;
         $this->data['preload'] = true;
     }
     $wp_uploads = wp_upload_dir();
     $this->data['post'] = $post = $this->input->post($DefaultOptions);
     if (is_array($this->data['post']['cpt'])) {
         $this->data['post']['cpt'] = $this->data['post']['cpt'][0];
     }
     // Delete history
     $history_files = PMXE_Helper::safe_glob(PMXE_ROOT_DIR . '/history/*', PMXE_Helper::GLOB_RECURSE | PMXE_Helper::GLOB_PATH);
     if (!empty($history_files)) {
         foreach ($history_files as $filePath) {
             @file_exists($filePath) and @unlink($filePath);
         }
     }
     if (!class_exists('ZipArchive')) {
         $this->errors->add('form-validation', __('ZipArchive class is missing on your server.<br/>Please contact your web hosting provider and ask them to install and activate ZipArchive.', 'wp_all_export_plugin'));
     }
     if (!class_exists('XMLReader') or !class_exists('XMLWriter')) {
         $this->errors->add('form-validation', __('Required PHP components are missing.<br/><br/>WP All Export requires XMLReader, and XMLWriter PHP modules to be installed.<br/>These are standard features of PHP, and are necessary for WP All Export to write the files you are trying to export.<br/>Please contact your web hosting provider and ask them to install and activate the DOMDocument, XMLReader, and XMLWriter PHP modules.', 'wp_all_export_plugin'));
     }
     if ($this->input->post('is_submitted')) {
         PMXE_Plugin::$session->set('export_type', $post['export_type']);
         PMXE_Plugin::$session->set('filter_rules_hierarhy', $post['filter_rules_hierarhy']);
         PMXE_Plugin::$session->set('product_matching_mode', $post['product_matching_mode']);
         PMXE_Plugin::$session->set('wp_query_selector', $post['wp_query_selector']);
         if (!empty($post['auto_generate'])) {
             $auto_generate = XmlCsvExport::auto_genetate_export_fields($post, $this->errors);
             foreach ($auto_generate as $key => $value) {
                 PMXE_Plugin::$session->set($key, $value);
             }
             PMXE_Plugin::$session->save_data();
         } else {
             $engine = new XmlExportEngine($post, $this->errors);
             $engine->init_additional_data();
         }
     }
     if ($this->input->post('is_submitted') and !$this->errors->get_error_codes()) {
         check_admin_referer('choose-cpt', '_wpnonce_choose-cpt');
         PMXE_Plugin::$session->save_data();
         if (!empty($post['auto_generate'])) {
             wp_redirect(add_query_arg('action', 'options', $this->baseUrl));
             die;
         } else {
             wp_redirect(add_query_arg('action', 'template', $this->baseUrl));
             die;
         }
     }
     $this->render();
 }