WordPress.org

Plugin Directory

Changeset 1666831


Ignore:
Timestamp:
05/30/17 05:13:01 (6 months ago)
Author:
neversettle
Message:

fixed an issue with renewing the authentication with Google

Location:
ns-google-sheets-connector
Files:
153 added
5 edited

Legend:

Unmodified
Added
Removed
  • ns-google-sheets-connector/trunk/lib/google-sheets.php

    r1179539 r1666831  
    11<?php 
    2 require_once plugin_dir_path(__FILE__).'php-google-oauth/Google_Client.php'; 
    3 include_once ( plugin_dir_path(__FILE__) . 'autoload.php' ); 
     2 
     3if (!class_exists('Google_Client')) { 
     4    require_once plugin_dir_path(__FILE__).'php-google-oauth/Google_Client.php'; 
     5}    
     6 
     7include_once ( plugin_dir_path(__FILE__) . 'autoload.php' );     
    48use Google\Spreadsheet\DefaultServiceRequest; 
    59use Google\Spreadsheet\ServiceRequestFactory; 
     
    1317    const clientSecret = 'v7lv1NNg9ctr2HNwLvDAXtvo'; 
    1418    const redirect = 'urn:ietf:wg:oauth:2.0:oob'; 
    15  
     19         
    1620    public function __construct() { 
    1721    } 
    1822 
    1923    //constructed on call 
    20     public static function preauth($access_code){        
     24    public static function preauth($access_code){ 
    2125        $client = new Google_Client(); 
    2226        $client->setClientId(googlesheet::clientId); 
     
    3539        try{ 
    3640            $tokenJson = json_encode($tokenData); 
    37             update_option('ns_google_sheets_connector_token', $tokenJson); 
     41            update_option('ns_google_sheets_connector_pro_token', $tokenJson); 
     42             
    3843        } catch (Exception $e) { 
    39             ns_google_sheets_connector::ns_debug_log("Token write fail! - ".$e->getMessage()); 
     44            ns_google_sheets_connector_pro::ns_debug_log("Token write fail!"); 
    4045        } 
    4146    } 
    4247     
    4348    public function auth(){ 
    44         $tokenData = json_decode(get_option('ns_google_sheets_connector_token'), true); 
     49        // $tokenData = json_decode(file_get_contents(plugin_dir_path(__FILE__) . ".tokendata"), true); 
     50        $tokenData = json_decode( get_option('ns_google_sheets_connector_pro_token', null), true); 
    4551         
    4652        if(time() > $tokenData['expire']){ 
  • ns-google-sheets-connector/trunk/lib/php-google-oauth/Google_Client.php

    r1179246 r1666831  
    4646 
    4747// Include the top level classes, they each include their own dependencies 
    48 require_once 'service/Google_Model.php'; 
    49 require_once 'service/Google_Service.php'; 
    50 require_once 'service/Google_ServiceResource.php'; 
    51 require_once 'auth/Google_AssertionCredentials.php'; 
    52 require_once 'auth/Google_Signer.php'; 
    53 require_once 'auth/Google_P12Signer.php'; 
    54 require_once 'service/Google_BatchRequest.php'; 
    55 require_once 'external/URITemplateParser.php'; 
    56 require_once 'auth/Google_Auth.php'; 
    57 require_once 'cache/Google_Cache.php'; 
    58 require_once 'io/Google_IO.php'; 
    59 require_once('service/Google_MediaFileUpload.php'); 
     48if (!class_exists('Google_Model')) { 
     49  require_once 'service/Google_Model.php'; 
     50} 
     51if (!class_exists('Google_Service')) { 
     52  require_once 'service/Google_Service.php'; 
     53} 
     54if (!class_exists('Google_ServiceResource')) { 
     55  require_once 'service/Google_ServiceResource.php'; 
     56} 
     57if (!class_exists('Google_AssertionCredentials')) { 
     58  require_once 'auth/Google_AssertionCredentials.php'; 
     59} 
     60if (!class_exists('Google_Signer')) { 
     61  require_once 'auth/Google_Signer.php'; 
     62} 
     63if (!class_exists('Google_P12Signer')) { 
     64  require_once 'auth/Google_P12Signer.php'; 
     65} 
     66if (!class_exists('Google_BatchRequest')) { 
     67  require_once 'service/Google_BatchRequest.php'; 
     68} 
     69if (!class_exists('URI_Template_Parser')) { 
     70  require_once 'external/URITemplateParser.php'; 
     71} 
     72if (!class_exists('Google_Auth')) { 
     73  require_once 'auth/Google_Auth.php'; 
     74} 
     75if (!class_exists('Google_Cache')) { 
     76  require_once 'cache/Google_Cache.php'; 
     77} 
     78if (!class_exists('Google_IO')) { 
     79  require_once 'io/Google_IO.php'; 
     80} 
     81if (!class_exists('Google_MediaFileUpload')) { 
     82  require_once('service/Google_MediaFileUpload.php'); 
     83} 
     84 
     85 
    6086 
    6187/** 
  • ns-google-sheets-connector/trunk/lib/php-google-oauth/auth/Google_OAuth2.php

    r1179246 r1666831  
    111111          $response = $decodedResponse['error']; 
    112112        } 
    113         ns_google_sheets_connector::ns_debug_log("Error fetching OAuth2 access token, message: '$response' :: {$request->getResponseHttpCode()}"); 
     113        ns_google_sheets_connector_pro::ns_debug_log("Error fetching OAuth2 access token, message: '$response' :: {$request->getResponseHttpCode()}"); 
    114114         
    115115        throw new Google_AuthException("Error fetching OAuth2 access token, message: '$response'", $request->getResponseHttpCode()); 
     
    118118 
    119119    $authUrl = $this->createAuthUrl($service['scope']); 
    120     header('Location: ' . $authUrl); 
     120    //header('Location: ' . $authUrl); 
    121121    return true; 
    122122  }  
     
    212212      } else { 
    213213        if (! array_key_exists('refresh_token', $this->token)) { 
    214             ns_google_sheets_connector::ns_debug_log("The OAuth 2.0 access token has expired, " 
     214            ns_google_sheets_connector_pro::ns_debug_log("The OAuth 2.0 access token has expired, " 
    215215                . "and a refresh token is not available. Refresh tokens are not " 
    216216                . "returned for responses that were auto-approved."); 
  • ns-google-sheets-connector/trunk/ns-google-sheets-connector.php

    r1596263 r1666831  
    66    Text Domain: ns-google-sheets 
    77    Author: Never Settle 
    8     Version: 1.2.2 
     8    Version: 1.2.4 
    99    Author URI: http://neversettle.it 
    1010    License: GPLv2 or later 
     
    7575        add_action( 'admin_enqueue_scripts', array($this, 'admin_assets') ); 
    7676        add_action( 'wpcf7_mail_sent', array($this, 'wpcf7_send_to_sheets'), 1); 
     77 
     78        //Deactivates current API code 
     79        if(isset($_GET['remove_code'])) { 
     80            update_option( $this->ns_plugin_ref.'_set', ''); 
     81        } 
    7782        // TODO: uncomment this if you want to add custom JS  
    7883        //add_action( 'admin_print_footer_scripts', array($this, 'add_javascript'), 100 ); 
    79          
     84 
    8085        // TODO: uncomment this if you want to add custom actions to run on deactivation 
    8186        //register_deactivation_hook( __FILE__, array($this, 'deactivate_plugin_actions') ); 
     
    139144                'field_name' => $this->ns_plugin_ref.'_code', 
    140145                'is_set' => ( ( get_option($this->ns_plugin_ref.'_code') != '' || (isset( $this->ns_token_data['access_token'] ) && $this->ns_token_data['access_token'] != '') ) ? 1 : 0 ), 
    141                 'warning' => 'Click <a href="https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force&client_id=1058344555307-fcus00minenokgq9vm48toli90q22783.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=https%3A%2F%2Fspreadsheets.google.com%2Ffeeds%2F" target="_blank">here</a> to retrieve your code from Google Drive to allow us to access your spreadsheets.'  
    142146            ) 
    143147        ); 
     
    202206        $type_value = ( isset( $args['type'] ) ? $args['type'] : 'text' ); 
    203207        $val_set = ( isset( $args['is_set'] ) ? $args['is_set'] : 0 ); 
    204          
     208 
    205209        switch($type_value){ 
    206210            case 'link': 
     
    209213            default: 
    210214                // initialize in case there are no existing options 
    211                 if ( empty($saved_value) && $args['field_name'] == "{$this->ns_plugin_ref}_code" && get_option($this->ns_plugin_ref.'_set')) { 
    212                     echo '<input type="' . $type_value . '" name="' . $args['field_name'] . '" value="" placeholder="Currently Activated" /><br/>'; 
    213                 }else if ( empty($saved_value) && !$val_set ) { 
     215                if ( empty($saved_value) && $args['field_name'] == "{$this->ns_plugin_ref}_code" && get_option($this->ns_plugin_ref.'_set')) {?> 
     216                    <p style="margin-top:5px;"><i><?php _e( 'Currently Activated', $this->text_domain);?></i></p> 
     217                    <a class="button" style=" 
     218                        margin-top:5px; 
     219                        background-color:#d54e21; 
     220                        color:#fff; 
     221                        -webkit-box-shadow: 0 1px 0 #9c3817; 
     222                        box-shadow: 0 1px 0 #9c3817; 
     223                        border-color:#9c3817;" 
     224                        href="<?php echo (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";?>&remove_code=yes"><?php _e( 'Deactivate', $this->text_domain );?></a> 
     225                <?php }else if ( empty($saved_value) && !$val_set ) { 
    214226                    echo '<input type="' . $type_value . '" name="' . $args['field_name'] . '" value="" /><br/>'; 
     227                    echo '<i>Click <a href="https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force&client_id=1058344555307-fcus00minenokgq9vm48toli90q22783.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=https%3A%2F%2Fspreadsheets.google.com%2Ffeeds%2F" target="_blank">here</a> to retrieve your code from Google Drive to allow us to access your spreadsheets.</i>'; 
     228 
    215229                } else { 
    216230                    echo "<input type='$type_value' name='{$args['field_name']}' value='$saved_value' /><br/>"; 
     
    300314                    $doc->settitleSpreadsheet(get_option($this->ns_plugin_ref.'_sheet')); 
    301315                    $doc->settitleWorksheet(get_option($this->ns_plugin_ref.'_tab')); 
    302                     $my_data["date"]=date('n/j/Y'); 
     316                    $my_data["date"]=date('n/j/Y h:i A'); 
    303317                    foreach ( $posted_data as $key => $value ) { 
    304318                        // exclude the default wpcf7 fields in object 
  • ns-google-sheets-connector/trunk/readme.txt

    r1596263 r1666831  
    6969== Changelog == 
    7070 
     71= 1.2.4 = 
     72* Fixed issue with updating the Google Authentication 
     73 
    7174= 1.2.2 = 
    7275* Improved conflict checking for other plugins that also use the Google API  
Note: See TracChangeset for help on using the changeset viewer.