/**
  * Do authentication with Google servers and store refresh_token
  *
  * @param $authorization_code
  *
  * @return bool
  */
 public function authenticate($authorization_code)
 {
     // Create a client object
     $client = new WPSEO_GWT_Google_Client();
     // Authenticate client
     try {
         $client->authenticate($authorization_code);
         // Get access response
         $response = $client->getAccessToken();
         // Check if there is a response body
         if ('' != $response) {
             $response = json_decode($response);
             if (is_object($response)) {
                 // Save the refresh token
                 $client->save_refresh_token($response->refresh_token);
                 return true;
             }
         }
     } catch (Google_AuthException $exception) {
     }
     return false;
 }
Esempio n. 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);
    }