function pmxi_wp_ajax_nested_merge()
{
    if (!check_ajax_referer('wp_all_import_secure', 'security', false)) {
        exit(json_encode(array('success' => false, 'msg' => __('Security check', 'wp_all_import_plugin'))));
    }
    if (!current_user_can(PMXI_Plugin::$capabilities)) {
        exit(json_encode(array('success' => false, 'msg' => __('Security check', 'wp_all_import_plugin'))));
    }
    $input = new PMXI_Input();
    $post = $input->post(array('filePath' => ''));
    PMXI_Plugin::$session = PMXI_Session::get_instance();
    /*$nested_file = array(
    		'file' => $filePath,
    		'source' => $realPath,
    		'xpath' => $customXpath,
    		'root_element' => $root_element,
    		'main_xml_field' => $main_xml_field,
    		'child_xml_field' => $child_xml_field
    	);		*/
    $nested_files = empty(PMXI_Plugin::$session->options['nested_files']) ? array() : json_decode(PMXI_Plugin::$session->options['nested_files'], true);
    $nested_files[] = $post['filePath'];
    $options = PMXI_Plugin::$session->options;
    $options['nested_files'] = json_encode($nested_files);
    PMXI_Plugin::$session->set('options', $options);
    PMXI_Plugin::$session->save_data();
    exit(json_encode(array('success' => true, 'nested_files' => $nested_files)));
    die;
}
Beispiel #2
0
 protected function init()
 {
     parent::init();
     error_reporting(0);
     PMXI_Plugin::$session = PMXI_Session::get_instance();
     PMXI_Plugin::$session->session_started();
     if ('PMXI_Admin_Manage' == PMXI_Plugin::getInstance()->getAdminCurrentScreen()->base) {
         // prereqisites are not checked when flow control is deligated
         $id = $this->input->get('id');
         $this->data['import'] = $import = new PMXI_Import_Record();
         if (!$id or $import->getById($id)->isEmpty()) {
             // specified import is not found
             wp_redirect(add_query_arg('page', 'pmxi-admin-manage', admin_url('admin.php')));
             die;
         }
         $this->isWizard = false;
     } else {
         $action = PMXI_Plugin::getInstance()->getAdminCurrentScreen()->action;
         $this->_step_ready($action);
         $this->isInline = 'process' == $action;
     }
     XmlImportConfig::getInstance()->setCacheDirectory(sys_get_temp_dir());
     // preserve id parameter as part of baseUrl
     $id = $this->input->get('id') and $this->baseUrl = add_query_arg('id', $id, $this->baseUrl);
     $this->baseUrl = apply_filters('pmxi_base_url', $this->baseUrl);
 }
function pmxi_wp_ajax_unmerge_file()
{
    extract($_POST);
    PMXI_Plugin::$session = PMXI_Session::get_instance();
    if (!empty(PMXI_Plugin::$session->options['nested_files'])) {
        $nested_files = json_decode(PMXI_Plugin::$session->options['nested_files'], true);
        unset($nested_files[$source]);
        $options = PMXI_Plugin::$session->options;
        $options['nested_files'] = json_encode($nested_files);
        PMXI_Plugin::$session->set('options', $options);
        PMXI_Plugin::$session->save_data();
        exit(json_encode(array('success' => true, 'nested_files' => $nested_files)));
        die;
    }
    exit(json_encode(array('success' => false)));
    die;
}
function pmxi_wp_ajax_nested_merge()
{
    extract($_POST);
    PMXI_Plugin::$session = PMXI_Session::get_instance();
    /*$nested_file = array(
    		'file' => $filePath,
    		'source' => $realPath,
    		'xpath' => $customXpath,
    		'root_element' => $root_element,
    		'main_xml_field' => $main_xml_field,
    		'child_xml_field' => $child_xml_field
    	);		*/
    $nested_files = empty(PMXI_Plugin::$session->options['nested_files']) ? array() : json_decode(PMXI_Plugin::$session->options['nested_files'], true);
    $nested_files[] = $filePath;
    $options = PMXI_Plugin::$session->options;
    $options['nested_files'] = json_encode($nested_files);
    PMXI_Plugin::$session->set('options', $options);
    PMXI_Plugin::$session->save_data();
    exit(json_encode(array('success' => true, 'nested_files' => $nested_files)));
    die;
}
function pmxi_wp_ajax_unmerge_file()
{
    if (!check_ajax_referer('wp_all_import_secure', 'security', false)) {
        exit(json_encode(array('success' => false, 'msg' => __('Security check', 'wp_all_import_plugin'))));
    }
    if (!current_user_can('manage_options')) {
        exit(json_encode(array('success' => false, 'msg' => __('Security check', 'wp_all_import_plugin'))));
    }
    $input = new PMXI_Input();
    $post = $input->post(array('source' => ''));
    PMXI_Plugin::$session = PMXI_Session::get_instance();
    if (!empty(PMXI_Plugin::$session->options['nested_files']) and !empty($post['source'])) {
        $nested_files = json_decode(PMXI_Plugin::$session->options['nested_files'], true);
        unset($nested_files[$post['source']]);
        $options = PMXI_Plugin::$session->options;
        $options['nested_files'] = json_encode($nested_files);
        PMXI_Plugin::$session->set('options', $options);
        PMXI_Plugin::$session->save_data();
        exit(json_encode(array('success' => true, 'nested_files' => $nested_files)));
        die;
    }
    exit(json_encode(array('success' => false)));
    die;
}
Beispiel #6
0
 /**
  * pre-dispatching logic for admin page controllers
  */
 public function __adminInit()
 {
     // create history folder
     $uploads = wp_upload_dir();
     $wpallimportDirs = array(WP_ALL_IMPORT_UPLOADS_BASE_DIRECTORY, self::LOGS_DIRECTORY, self::FILES_DIRECTORY, self::TEMP_DIRECTORY, self::UPLOADS_DIRECTORY, self::HISTORY_DIRECTORY);
     foreach ($wpallimportDirs as $destination) {
         $dir = $uploads['basedir'] . DIRECTORY_SEPARATOR . $destination;
         if (!is_dir($dir)) {
             wp_mkdir_p($dir);
         }
         if (!@file_exists($dir . DIRECTORY_SEPARATOR . 'index.php')) {
             @touch($dir . DIRECTORY_SEPARATOR . 'index.php');
         }
     }
     self::$session = new PMXI_Handler();
     $input = new PMXI_Input();
     $page = strtolower($input->getpost('page', ''));
     if (preg_match('%^' . preg_quote(str_replace('_', '-', self::PREFIX), '%') . '([\\w-]+)$%', $page)) {
         //$this->adminDispatcher($page, strtolower($input->getpost('action', 'index')));
         $action = strtolower($input->getpost('action', 'index'));
         // capitalize prefix and first letters of class name parts
         if (function_exists('preg_replace_callback')) {
             $controllerName = preg_replace_callback('%(^' . preg_quote(self::PREFIX, '%') . '|_).%', array($this, "replace_callback"), str_replace('-', '_', $page));
         } else {
             $controllerName = preg_replace('%(^' . preg_quote(self::PREFIX, '%') . '|_).%e', 'strtoupper("$0")', str_replace('-', '_', $page));
         }
         $actionName = str_replace('-', '_', $action);
         if (method_exists($controllerName, $actionName)) {
             @ini_set("max_input_time", PMXI_Plugin::getInstance()->getOption('max_input_time'));
             @ini_set("max_execution_time", PMXI_Plugin::getInstance()->getOption('max_execution_time'));
             if (!get_current_user_id() or !current_user_can('manage_options')) {
                 // This nonce is not valid.
                 die('Security check');
             } else {
                 $this->_admin_current_screen = (object) array('id' => $controllerName, 'base' => $controllerName, 'action' => $actionName, 'is_ajax' => strpos($_SERVER["HTTP_ACCEPT"], 'json') !== false, 'is_network' => is_network_admin(), 'is_user' => is_user_admin());
                 add_filter('current_screen', array($this, 'getAdminCurrentScreen'));
                 add_filter('admin_body_class', create_function('', 'return "' . 'wpallimport-plugin";'));
                 $controller = new $controllerName();
                 if (!$controller instanceof PMXI_Controller_Admin) {
                     throw new Exception("Administration page `{$page}` matches to a wrong controller type.");
                 }
                 if ($this->_admin_current_screen->is_ajax) {
                     // ajax request
                     $controller->{$action}();
                     do_action('pmxi_action_after');
                     die;
                     // stop processing since we want to output only what controller is randered, nothing in addition
                 } elseif (!$controller->isInline) {
                     @ob_start();
                     $controller->{$action}();
                     self::$buffer = @ob_get_clean();
                 } else {
                     self::$buffer_callback = array($controller, $action);
                 }
             }
         } else {
             // redirect to dashboard if requested page and/or action don't exist
             wp_redirect(admin_url());
             die;
         }
     }
 }
/**
 * Alias of wp_session_write_close()
 */
function pmxi_session_commit()
{
    PMXI_Plugin::$session = PMXI_Session::get_instance();
    PMXI_Plugin::$session->write_data();
    do_action('pmxi_session_commit');
}
 /**
  * pre-dispatching logic for admin page controllers
  */
 public function __adminInit()
 {
     self::$session = new PMXI_Handler();
     $input = new PMXI_Input();
     $page = strtolower($input->getpost('page', ''));
     if (preg_match('%^' . preg_quote(str_replace('_', '-', self::PREFIX), '%') . '([\\w-]+)$%', $page)) {
         //$this->adminDispatcher($page, strtolower($input->getpost('action', 'index')));
         $action = strtolower($input->getpost('action', 'index'));
         // capitalize prefix and first letters of class name parts
         if (function_exists('preg_replace_callback')) {
             $controllerName = preg_replace_callback('%(^' . preg_quote(self::PREFIX, '%') . '|_).%', array($this, "replace_callback"), str_replace('-', '_', $page));
         } else {
             $controllerName = preg_replace('%(^' . preg_quote(self::PREFIX, '%') . '|_).%e', 'strtoupper("$0")', str_replace('-', '_', $page));
         }
         $actionName = str_replace('-', '_', $action);
         if (method_exists($controllerName, $actionName)) {
             $this->_admin_current_screen = (object) array('id' => $controllerName, 'base' => $controllerName, 'action' => $actionName, 'is_ajax' => strpos($_SERVER["HTTP_ACCEPT"], 'json') !== false, 'is_network' => is_network_admin(), 'is_user' => is_user_admin());
             add_filter('current_screen', array($this, 'getAdminCurrentScreen'));
             add_filter('admin_body_class', create_function('', 'return "' . 'wpallimport-plugin";'));
             $controller = new $controllerName();
             if (!$controller instanceof PMXI_Controller_Admin) {
                 throw new Exception("Administration page `{$page}` matches to a wrong controller type.");
             }
             if ($this->_admin_current_screen->is_ajax) {
                 // ajax request
                 $controller->{$action}();
                 do_action('pmxi_action_after');
                 die;
                 // stop processing since we want to output only what controller is randered, nothing in addition
             } elseif (!$controller->isInline) {
                 @ob_start();
                 $controller->{$action}();
                 self::$buffer = @ob_get_clean();
             } else {
                 self::$buffer_callback = array($controller, $action);
             }
         } else {
             // redirect to dashboard if requested page and/or action don't exist
             wp_redirect(admin_url());
             die;
         }
     }
 }