/**
  * Catch the reload-crawl-issues POST
  */
 private function catch_reload_crawl_issues()
 {
     if (isset($_POST['reload-crawl-issues'])) {
         $crawl_issue_manager = new WPSEO_Crawl_Issue_Manager();
         $crawl_issue_manager->remove_last_checked();
     }
 }
 /**
  * Get crawl issues
  *
  * @param $site_url
  *
  * @return array
  */
 public function get_crawl_issues()
 {
     // Setup crawl error list
     $crawl_issues = array();
     // Issues per page
     $per_page = 100;
     $cur_page = 0;
     // We always have issues on first request
     $has_more_issues = true;
     $crawl_issue_manager = new WPSEO_Crawl_Issue_Manager();
     $profile_url = $crawl_issue_manager->get_profile();
     // Do multiple request
     while (true === $has_more_issues) {
         // Set issues to false
         $has_more_issues = false;
         // Do request
         $url = $profile_url . "/crawlissues/?start-index=" . ($per_page * $cur_page + 1) . "&max-results=" . $per_page;
         $request = new Google_HttpRequest($url);
         // Get list sites response
         $response = $this->client->getIo()->authenticatedRequest($request);
         // Check response code
         if ('200' == $response->getResponseHttpCode()) {
             // Create XML object from reponse body
             $response_xml = simplexml_load_string($response->getResponseBody());
             // Check if we got entries
             if (count($response_xml->entry) > 0) {
                 // Count, future use itemsperpage in Google reponse
                 if (100 == count($response_xml->entry)) {
                     // We have issues
                     $has_more_issues = true;
                 }
                 // Loop
                 foreach ($response_xml->entry as $entry) {
                     $wt = $entry->children('wt', true);
                     $crawl_issues[] = new WPSEO_Crawl_Issue(WPSEO_Redirect_Manager::format_url((string) $wt->url), (string) $wt->{'crawl-type'}, (string) $wt->{'issue-type'}, new DateTime((string) $wt->{'date-detected'}), (string) $wt->{'detail'}, (array) $wt->{'linked-from'}, false);
                 }
             }
         }
         // Up page nr
         $cur_page++;
     }
     return $crawl_issues;
 }
 /**
  * Remove the last check timestamp if the profile is switched
  *
  * @param $setting
  *
  * @return mixed
  */
 public function gwt_sanatize_callback($setting)
 {
     $crawl_issue_manager = new WPSEO_Crawl_Issue_Manager();
     // Remove last check if new profile is selected
     if ($crawl_issue_manager->get_profile() != $setting['profile']) {
         $crawl_issue_manager->remove_last_checked();
     }
     return $setting;
 }
 /**
  * Setup the table variables, fetch the items from the database, search, sort and format the items.
  * Set the items as the WPSEO_Redirect_Table items variable.
  */
 public function prepare_items()
 {
     // Setup the columns
     $columns = $this->get_columns();
     $hidden = array();
     $sortable = $this->get_sortable_columns();
     $this->_column_headers = array($columns, $hidden, $sortable);
     // Vies
     $this->views();
     // Get current view
     $current_view = $this->get_current_view();
     // Build crawl issues args
     $ci_args = array();
     // Set the post status
     $ci_args['post_status'] = 'publish';
     // Set the orderby
     $orderby = !empty($_GET['orderby']) ? $_GET['orderby'] : 'title';
     $ci_args['orderby'] = $orderby;
     // Set the order
     $order = !empty($_GET['order']) ? $_GET['order'] : 'asc';
     $ci_args['order'] = $order;
     // Prepares the issue filter
     $this->prepare_issue_filter();
     // Set the issue filter
     if ($issue_filter = get_transient('gwt-issue_filter')) {
         $filter_posts = $this->issue_filter($issue_filter);
         if (is_array($filter_posts) && !empty($filter_posts)) {
             $ci_args['post__in'] = $filter_posts;
         }
     }
     // Get variables needed for pagination
     $per_page = $this->get_items_per_page('errors_per_page', 25);
     $current_page = intval(isset($_GET['paged']) ? $_GET['paged'] : 1);
     // Set query pagination
     $ci_args['posts_per_page'] = $per_page;
     $ci_args['offset'] = ($current_page - 1) * $per_page;
     // Check current view
     if ('ignored' == $current_view) {
         $ci_args['post_status'] = 'trash';
     }
     // Filter crawl errors
     if ('not-redirected' == $current_view) {
         $url_redirect_manager = new WPSEO_URL_Redirect_Manager();
         $redirects = $url_redirect_manager->get_redirects();
         $wpseo_urls = array();
         if (count($redirects) > 0) {
             foreach ($redirects as $old_url => $new_url) {
                 $wpseo_urls[] = $old_url;
             }
         }
         $ci_args['wpseo_urls'] = $wpseo_urls;
     }
     // Get the crawl issues
     $crawl_issue_manager = new WPSEO_Crawl_Issue_Manager();
     $crawl_issues = $crawl_issue_manager->get_crawl_issues($this->gwt, $ci_args);
     // Get the total items
     $total_items = $crawl_issue_manager->get_latest_query()->found_posts;
     // Set table pagination
     $this->set_pagination_args(array('total_items' => $total_items, 'total_pages' => ceil($total_items / $per_page), 'per_page' => $per_page));
     // Set items
     $items_array = array();
     if (is_array($crawl_issues) && count($crawl_issues) > 0) {
         foreach ($crawl_issues as $crawl_issue) {
             $items_array[] = $crawl_issue->to_array();
         }
     }
     $this->items = $items_array;
 }