コード例 #1
0
 /**
  * Save the crawl issues
  *
  * @param WPSEO_GWT_Google_Client $gwt
  */
 private function save_crawl_issues(WPSEO_GWT_Google_Client $gwt)
 {
     global $wpdb;
     // Create a the service object
     $service = new WPSEO_GWT_Service($gwt);
     // Get crawl issues
     $crawl_issues = $service->get_crawl_issues();
     // Store the urls of crawl issues
     $crawl_issue_urls = array();
     // Mutate and save the crawl issues
     if (count($crawl_issues) > 0) {
         foreach ($crawl_issues as $crawl_issue) {
             /**
              * @var WPSEO_Crawl_Issue $crawl_issue
              */
             $ci_post_id = post_exists($crawl_issue->get_url());
             // Check if the post exists
             if (0 == $ci_post_id) {
                 // Create the post
                 $ci_post_id = wp_insert_post(array('post_type' => self::PT_CRAWL_ISSUE, 'post_title' => $crawl_issue->get_url(), 'post_status' => 'publish'));
             }
             // Update all the meta data
             update_post_meta($ci_post_id, self::PM_CI_CRAWL_TYPE, $crawl_issue->get_crawl_type());
             update_post_meta($ci_post_id, self::PM_CI_ISSUE_TYPE, $crawl_issue->get_issue_type());
             update_post_meta($ci_post_id, self::PM_CI_DATE_DETECTED, (string) strftime('%x', strtotime($crawl_issue->get_date_detected()->format('Y-m-d H:i:s'))));
             update_post_meta($ci_post_id, self::PM_CI_DETAIL, $crawl_issue->get_detail());
             update_post_meta($ci_post_id, self::PM_CI_LINKED_FROM, $crawl_issue->get_linked_from());
             // Store the url in $crawl_issue_urls
             if (false == in_array($crawl_issue->get_url(), $crawl_issue_urls)) {
                 $crawl_issue_urls[] = $crawl_issue->get_url();
             }
         }
     }
     // Remove local crawl issues that are not in the Google response
     $sql_raw = "DELETE FROM `{$wpdb->posts}` WHERE `post_type` = '" . self::PT_CRAWL_ISSUE . "'";
     $crawl_issue_count = count($crawl_issue_urls);
     if ($crawl_issue_count > 0) {
         $sql_raw .= " AND `post_title` NOT IN (" . implode(', ', array_fill(0, count($crawl_issue_urls), '%s')) . ")";
         // Format the SQL
         $sql = call_user_func_array(array($wpdb, 'prepare'), array_merge(array($sql_raw), $crawl_issue_urls));
     } else {
         $sql = $sql_raw;
     }
     // Run the delete SQL
     $wpdb->query($sql);
     // Save the last checked
     $this->save_last_checked();
 }
コード例 #2
0
    /**
     * Function that outputs the redirect page
     */
    public function display()
    {
        global $wpseo_admin_pages;
        // Admin header
        $wpseo_admin_pages->admin_header(false, 'yoast_wpseo_redirects_options', 'wpseo_redirects');
        ?>
		<h2 class="nav-tab-wrapper" id="wpseo-tabs">
			<form action="" method="post">
				<input type="submit" name="reload-crawl-issues" id="reload-crawl-issue" class="button-primary" style="float: right;" value="<?php 
        _e('Reload crawl issues', 'wordpress-seo');
        ?>
">
			</form>
			<a class="nav-tab" id="crawl-issues-tab" href="#top#redirects"><?php 
        _e('Crawl Issues', 'wordpress-seo');
        ?>
</a>
			<a class="nav-tab" id="settings-tab" href="#top#settings"><?php 
        _e('Settings', 'wordpress-seo');
        ?>
</a>

		</h2>

		<div class="tabwrapper>">
			<div id="crawl-issues" class="wpseotab">
				<?php 
        // Create a new WPSEO GWT Google Client
        $gwt_client = new WPSEO_GWT_Google_Client();
        // Check if there is an access token
        if (null != $gwt_client->getAccessToken()) {
            //echo "<h2>Google Webmaster Tools Errors</h2>\n";
            // Open <form>
            echo "<form id='wpseo-crawl-issues-table-form' action='" . admin_url('admin.php') . '?page=' . $_GET['page'] . "' method='post'>\n";
            // AJAX nonce
            echo "<input type='hidden' class='wpseo_redirects_ajax_nonce' value='" . wp_create_nonce('wpseo-redirects-ajax-security') . "' />\n";
            // The list table
            $list_table = new WPSEO_Crawl_Issue_Table($gwt_client);
            $list_table->prepare_items();
            $list_table->search_box(__('Search', 'wordpress-seo'), 'wpseo-crawl-issues-search');
            $list_table->display();
            // Close <form>
            echo "</form>\n";
        } else {
            // Get the oauth URL
            $oath_url = $gwt_client->createAuthUrl();
            // Print auth screen
            echo "<p>" . __('To allow WordPress SEO Premium to fetch your Google Webmaster Tools information, please enter your Google Authorization Code.', 'wordpress-seo') . "</p>\n";
            echo "<a href='javascript:wpseo_gwt_open_authorize_code_window(\"{$oath_url}\");'>" . __('Click here to get a Google Authorization Code', 'wordpress-seo') . "</a>\n";
            echo "<p>" . __('Please enter the Authorization Code in the field below and press the Authenticate button.', 'wordpress-seo') . "</p>\n";
            echo "<form action='' method='post'>\n";
            echo "<input type='text' name='gwt[authorization_code]' value='' />";
            echo "<input type='submit' name='gwt[Submit]' value='" . __('Authenticate', 'wordpress-seo') . "' class='button-primary' />";
            echo "</form>\n";
        }
        ?>
			</div>
			<div id="settings" class="wpseotab">
				<h2>Google Webmaster Tools Settings</h2>

				<form action="<?php 
        echo admin_url('options.php');
        ?>
" method="post">
					<?php 
        settings_fields('yoast_wpseo_gwt_options');
        $wpseo_admin_pages->currentoption = 'wpseo-premium-gwt';
        // Get the sites
        $service = new WPSEO_GWT_Service($gwt_client);
        $sites = $service->get_sites();
        echo $wpseo_admin_pages->select('profile', __('Profile', 'wordpress-seo'), $sites);
        ?>

					<p class="submit">
						<input type="submit" name="submit" id="submit" class="button button-primary" value="<?php 
        _e('Save Changes', 'wordpress-seo');
        ?>
">
					</p>
				</form>

			</div>
		</div>
		<br class="clear">
		<?php 
        // Admin footer
        $wpseo_admin_pages->admin_footer(false);
    }