/**
  * pre-dispatching logic for admin page controllers
  */
 public function __adminInit()
 {
     // create history folder
     $uploads = wp_upload_dir();
     $wpallimportDirs = array(WP_ALL_EXPORT_UPLOADS_BASE_DIRECTORY, self::TEMP_DIRECTORY, self::UPLOADS_DIRECTORY, self::CRON_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');
         }
     }
     if (!is_dir($uploads['basedir'] . DIRECTORY_SEPARATOR . WP_ALL_EXPORT_UPLOADS_BASE_DIRECTORY) or !is_writable($uploads['basedir'] . DIRECTORY_SEPARATOR . WP_ALL_EXPORT_UPLOADS_BASE_DIRECTORY)) {
         die(sprintf(__('Uploads folder %s must be writable', 'wp_all_export_plugin'), $uploads['basedir'] . DIRECTORY_SEPARATOR . WP_ALL_EXPORT_UPLOADS_BASE_DIRECTORY));
     }
     if (!is_dir($uploads['basedir'] . DIRECTORY_SEPARATOR . self::UPLOADS_DIRECTORY) or !is_writable($uploads['basedir'] . DIRECTORY_SEPARATOR . self::UPLOADS_DIRECTORY)) {
         die(sprintf(__('Uploads folder %s must be writable', 'wp_all_export_plugin'), $uploads['basedir'] . DIRECTORY_SEPARATOR . self::UPLOADS_DIRECTORY));
     }
     self::$session = new PMXE_Handler();
     $input = new PMXE_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)) {
             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 "' . 'wpallexport-plugin";'));
                 $controller = new $controllerName();
                 if (!$controller instanceof PMXE_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('wpallexport_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;
         }
     }
 }