public static function upload_file()
 {
     global $wp_rewrite;
     // Set default handlers
     set_error_handler(array('Ai1wm_Error', 'error_handler'));
     set_exception_handler(array('Ai1wm_Error', 'exception_handler'));
     $result = array();
     // Get options
     if (isset($_FILES['input_file']) && ($input_file = $_FILES['input_file'])) {
         $options = array('chunk' => 0, 'chunks' => 0, 'name' => null);
         // Ordinal number of the current chunk in the set (starts with zero)
         if (isset($_REQUEST['chunk'])) {
             $options['chunk'] = intval($_REQUEST['chunk']);
         }
         // Total number of chunks in the file
         if (isset($_REQUEST['chunks'])) {
             $options['chunks'] = intval($_REQUEST['chunks']);
         }
         // Name of partial file
         if (isset($_REQUEST['name'])) {
             $options['name'] = $_REQUEST['name'];
         }
         $model = new Ai1wm_Import();
         $result = $model->import($input_file, $options);
         // Regenerate permalinks
         $wp_rewrite->flush_rules(true);
     }
     echo json_encode($result);
     exit;
 }
 public static function import()
 {
     global $wp_rewrite;
     // Set default handlers
     set_error_handler(array('Ai1wm_Error', 'error_handler'));
     set_exception_handler(array('Ai1wm_Error', 'exception_handler'));
     // Verify capabilities
     if (!current_user_can('import')) {
         wp_die('Unable to process the request.');
     }
     $messages = array();
     if (isset($_FILES['upload-file']) || isset($_REQUEST['force'])) {
         $options = array('chunk' => 0, 'chunks' => 1, 'import' => array('file' => null, 'force' => null));
         // Ordinal number of the current chunk in the set (starts with zero)
         if (isset($_REQUEST['chunk'])) {
             $options['chunk'] = intval($_REQUEST['chunk']);
         }
         // Total number of chunks in the file
         if (isset($_REQUEST['chunks'])) {
             $options['chunks'] = intval($_REQUEST['chunks']);
         }
         // Import file
         if (isset($_REQUEST['name'])) {
             $options['import']['file'] = $_REQUEST['name'];
         }
         // Force file
         if (isset($_REQUEST['force'])) {
             $options['import']['force'] = $_REQUEST['force'];
         }
         try {
             // Upload file
             if (self::upload($options)) {
                 // Import site
                 $model = new Ai1wm_Import($options);
                 if ($model->import()) {
                     $messages[] = array('type' => 'success', 'text' => sprintf(_('Your data has been imported successfuly!<br />' . 'You need to perform two more steps:<br />' . '<strong>1. You must save your permalinks structure twice. <a class="ai1wm-no-underline" href="%s#submit" target="_blank">Permalinks Settings</a></strong> (opens a new window)<br />' . '<strong>2. <a class="ai1wm-no-underline" href="https://wordpress.org/support/view/plugin-reviews/all-in-one-wp-migration?rate=5#postform" target="_blank">Review the plugin</a>.</strong> (opens a new window)'), admin_url('options-permalink.php')));
                     // Flush storage
                     StorageArea::getInstance()->flush();
                 }
             }
         } catch (Exception $e) {
             $messages[] = array('type' => 'error', 'text' => $e->getMessage());
         }
     }
     // Regenerate permalinks
     $wp_rewrite->flush_rules(true);
     // Display messages
     echo json_encode($messages);
     exit;
 }