/**
  * Render the options page.
  *
  * @return void
  */
 public function display_options_page()
 {
     if (isset($_POST['save'])) {
         $this->save_options();
         $message = __('Settings saved.', self::SLUG);
         $this->view->add_flash('updated', $message);
     }
     $this->view->set_layout('admin')->set_template('options')->assign('slug', self::SLUG)->assign('origin_scheme', sist_get_origin_scheme())->assign('origin_host', sist_get_origin_host())->assign('destination_scheme', $this->options->get('destination_scheme'))->assign('destination_host', $this->options->get('destination_host'))->assign('temp_files_dir', $this->options->get('temp_files_dir'))->assign('additional_urls', $this->options->get('additional_urls'))->assign('delivery_method', $this->options->get('delivery_method'))->assign('local_dir', $this->options->get('local_dir'))->assign('delete_temp_files', $this->options->get('delete_temp_files'))->assign('aws_s3_bucket', $this->options->get('aws_s3_bucket'))->assign('aws_access_key_id', $this->options->get('aws_access_key_id'))->assign('aws_secret_access_key', $this->options->get('aws_secret_access_key'))->render();
 }
 /**
  * Create a static version of the site
  *
  * @return void
  */
 public function create_archive()
 {
     global $blog_id;
     // TODO: Do ajax calls instead of just running forever and ever
     set_time_limit(0);
     // Create archive directory
     $current_user = wp_get_current_user();
     $archive_name = join('-', array($this->slug, $blog_id, time(), $current_user->user_login));
     $this->archive_dir = trailingslashit($this->temp_files_dir . $archive_name);
     if (!file_exists($this->archive_dir)) {
         wp_mkdir_p($this->archive_dir);
     }
     // Add URLs to queue
     $origin_url = home_url();
     $destination_url = $this->destination_scheme . '://' . $this->destination_host;
     $urls_queue = array_unique(array_merge(array(trailingslashit($origin_url)), preg_split("/\r\n|\n|\r/", $this->additional_urls)));
     while (count($urls_queue)) {
         $current_url = array_shift($urls_queue);
         $response = Simply_Static_Url_Fetcher::fetch($current_url);
         // If we get a WP_Error then somehow our request failed (e.g. space in URL)
         // TODO: Keep a queue of failed urls too
         if (is_wp_error($response)) {
             continue;
         }
         $url_parts = parse_url($response->url);
         $path = $url_parts['path'];
         $is_html = $response->is_html();
         // If we get a 30x redirect...
         if (in_array($response->code, array(301, 302, 303, 307))) {
             $redirect_url = $response->get_redirect_url();
             // WP likes to 301 redirect `/path` to `/path/` -- we want to
             // check for this and just add the trailing slashed version
             if ($redirect_url === trailingslashit($current_url)) {
                 $urls_queue = $this->add_url_to_queue($urls_queue, $redirect_url);
             } else {
                 /// convert our potentially relative URL to an absolute URL
                 $redirect_url = sist_relative_to_absolute_url($redirect_url, $current_url);
                 if ($redirect_url) {
                     // check if this is a local URL
                     if (sist_is_local_url($redirect_url)) {
                         // add the redirected page to the queue
                         $urls_queue = $this->add_url_to_queue($urls_queue, $redirect_url);
                         // and update the URL
                         $redirect_url = str_replace($origin_url, $destination_url, $redirect_url);
                     }
                     $view = new Simply_Static_View();
                     $content = $view->set_template('redirect')->assign('redirect_url', $redirect_url)->render_to_string();
                     $this->save_url_to_file($path, $content, $is_html);
                     $this->export_log[] = $current_url;
                 }
             }
             continue;
         }
         // Not a 200 for the response code? Move on.
         // TODO: Keep a queue of failed urls too
         if ($response->code != 200) {
             continue;
         }
         $this->export_log[] = $current_url;
         // Fetch all URLs from the page and add them to the queue...
         $urls = $response->extract_urls();
         foreach ($urls as $url) {
             $urls_queue = $this->add_url_to_queue($urls_queue, $url);
         }
         // Replace the origin URL with the destination URL
         $response->replace_url($origin_url, $destination_url);
         // Save the page to our archive
         $content = $response->body;
         $this->save_url_to_file($path, $content, $is_html);
     }
 }