コード例 #1
0
 function __construct()
 {
     parent::__construct();
     global $photonic_picasa_client_id, $photonic_picasa_client_secret, $photonic_picasa_disable_title_link;
     $this->client_id = $photonic_picasa_client_id;
     $this->client_secret = $photonic_picasa_client_secret;
     $this->provider = 'picasa';
     $this->oauth_version = '2.0';
     $this->response_type = 'code';
     $this->scope = 'https://picasaweb.google.com/data/';
     $this->link_lightbox_title = empty($photonic_picasa_disable_title_link);
     $cookie = Photonic::parse_cookie();
     global $photonic_picasa_allow_oauth;
     $this->oauth_done = false;
     if ($photonic_picasa_allow_oauth && isset($cookie['picasa']) && isset($cookie['picasa']['oauth_token']) && isset($cookie['picasa']['oauth_refresh_token'])) {
         // OAuth2, so no Access token secret
         if ($this->is_token_expired($cookie['picasa'])) {
             $this->refresh_token($cookie['picasa']['oauth_refresh_token']);
             $cookie = Photonic::parse_cookie();
             // Refresh the cookie object based on the results of the refresh token
             if ($this->is_token_expired($cookie['picasa'])) {
                 // Tried refreshing, but didn't work
                 $this->oauth_done = false;
             } else {
                 $this->oauth_done = true;
             }
         } else {
             $this->oauth_done = true;
         }
     } else {
         if (!isset($cookie['picasa']) || !isset($cookie['picasa']['oauth_token']) || !isset($cookie['picasa']['oauth_refresh_token'])) {
             $this->oauth_done = false;
         }
     }
 }
コード例 #2
0
 protected function make_call($query_url, $display_what, $columns, $thumb_size = 75, $auth_required = false)
 {
     global $photonic_instagram_client_id;
     $ret = '';
     $query = $query_url;
     if (substr($query, -1, 1) != '&' && !stripos($query, '?')) {
         $query .= '?';
     } else {
         if (substr($query, -1, 1) != '&' && stripos($query, '?')) {
             $query .= '&';
         }
     }
     if ($auth_required) {
         $cookie = Photonic::parse_cookie();
         if (isset($cookie['instagram']) && !$this->is_token_expired($cookie['instagram'])) {
             $query .= 'access_token=' . $cookie['instagram']['oauth_token'];
         } else {
             return __("Please login to see this content.", 'photonic');
         }
     } else {
         $query .= 'client_id=' . $photonic_instagram_client_id;
     }
     $response = wp_remote_request($query, array('sslverify' => false));
     $url = '';
     if ($display_what == 'single-media') {
         $base_url = $this->get_normalized_http_url($query);
         $parameters = $this->parse_parameters(substr($query, strlen($base_url) + 1));
         if (isset($parameters['url'])) {
             $url = $parameters['url'];
         }
     }
     if (!is_wp_error($response)) {
         if (isset($response['response']) && isset($response['response']['code'])) {
             if ($response['response']['code'] == 200) {
                 $body = json_decode($response['body']);
                 if (isset($body->data) && $display_what != 'single-media') {
                     $data = $body->data;
                     $this->gallery_index++;
                     switch ($display_what) {
                         case 'users':
                             $ret .= $this->process_users($data, $columns, $thumb_size);
                             break;
                         case 'media':
                         default:
                             $ret .= $this->process_media($data, $columns, $thumb_size);
                             break;
                     }
                 } else {
                     if ($display_what == 'single-media') {
                         $ret .= $this->process_single_media($body, $url);
                     } else {
                         return __('No data returned. Unknown error', 'photonic');
                     }
                 }
             } else {
                 if (isset($response['body'])) {
                     $body = json_decode($response['body']);
                     if (isset($body->meta) && isset($body->meta->error_message)) {
                         return $body->meta->error_message;
                     } else {
                         return __('Unknown error', 'photonic');
                     }
                 } else {
                     if (isset($response['response']['message'])) {
                         return $response['response']['message'];
                     } else {
                         return __('Unknown error', 'photonic');
                     }
                 }
             }
         }
     } else {
         return __('There was a problem connecting. Please try back after some time.', 'photonic');
     }
     return $ret;
 }
コード例 #3
0
 /**
  * Checks if authentication has been enabled and the user has authenticated. If so, it signs the call, then adds the additional parameters to it.
  * This method also attaches the oauth_signature to the parameters.
  *
  * @param $api_method
  * @param $method
  * @param $parameters
  * @return mixed
  */
 public function sign_call($api_method, $method, $parameters)
 {
     $allow_oauth = 'photonic_' . $this->provider . '_allow_oauth';
     global ${$allow_oauth};
     if (${$allow_oauth}) {
         $cookie = Photonic::parse_cookie();
         if (isset($cookie[$this->provider]) && isset($cookie[$this->provider]['oauth_token']) && isset($cookie[$this->provider]['oauth_token_secret']) && isset($cookie[$this->provider]['oauth_token_type']) && $cookie[$this->provider]['oauth_token_type'] == 'access') {
             $token = array('oauth_token' => $cookie[$this->provider]['oauth_token'], 'oauth_token_secret' => $cookie[$this->provider]['oauth_token_secret']);
             $this->nonce = $this->nonce();
             $this->oauth_timestamp = time();
             $signature = $this->generate_signature($api_method, $parameters, $method, $token);
             if (isset($this->signature_parameters) && isset($this->signature_parameters['parameters'])) {
                 $this->signature_parameters['parameters']['oauth_signature'] = $signature;
                 return $this->signature_parameters['parameters'];
             }
         }
     }
     return $parameters;
 }
コード例 #4
0
ファイル: photonic.php プロジェクト: n3ssi3/tauch-terminal
 /**
  * Checks if a user has authenticated a particular provider's services. When this is invoked we don't know if the page has
  * a Flickr / 500px / SmugMug gallery, so we just invoke it and set some global variables.
  *
  * @return mixed
  */
 function check_authentication()
 {
     if (is_admin()) {
         return;
     }
     global $photonic_flickr_allow_oauth, $photonic_500px_allow_oauth, $photonic_smug_allow_oauth, $photonic_picasa_allow_oauth;
     if (!$photonic_flickr_allow_oauth && !$photonic_500px_allow_oauth && !$photonic_smug_allow_oauth && !$photonic_picasa_allow_oauth) {
         return;
     }
     global $photonic_flickr_oauth_done, $photonic_500px_oauth_done, $photonic_smug_oauth_done;
     $photonic_flickr_oauth_done = $photonic_500px_oauth_done = $photonic_smug_oauth_done = false;
     $cookie = Photonic::parse_cookie();
     if ($photonic_flickr_allow_oauth && isset($cookie['flickr']) && isset($cookie['flickr']['oauth_token']) && isset($cookie['flickr']['oauth_token_secret'])) {
         global $photonic_flickr_gallery;
         if (!isset($photonic_flickr_gallery)) {
             $photonic_flickr_gallery = new Photonic_Flickr_Processor();
         }
         $current_token = array('oauth_token' => $cookie['flickr']['oauth_token'], 'oauth_token_secret' => $cookie['flickr']['oauth_token_secret']);
         if (isset($_REQUEST['oauth_verifier']) && isset($_REQUEST['oauth_token'])) {
             $current_token['oauth_token'] = $_REQUEST['oauth_token'];
             $current_token['oauth_verifier'] = $_REQUEST['oauth_verifier'];
             $new_token = $photonic_flickr_gallery->get_access_token($current_token);
             if (isset($new_token['oauth_token']) && isset($new_token['oauth_token_secret'])) {
                 $photonic_flickr_oauth_done = true;
                 $redirect = remove_query_arg(array('oauth_token', 'oauth_verifier'));
                 wp_redirect($redirect);
                 exit;
             }
         } else {
             if (isset($cookie['flickr']['oauth_token_type']) && $cookie['flickr']['oauth_token_type'] == 'access') {
                 $access_token_response = $photonic_flickr_gallery->check_access_token($current_token);
                 if (is_wp_error($access_token_response)) {
                     $photonic_flickr_gallery->is_server_down = true;
                 }
                 $photonic_flickr_oauth_done = $photonic_flickr_gallery->is_access_token_valid($access_token_response);
             }
         }
     }
     if ($photonic_500px_allow_oauth && isset($cookie['500px']) && isset($cookie['500px']['oauth_token']) && isset($cookie['500px']['oauth_token_secret'])) {
         global $photonic_500px_gallery;
         if (!isset($photonic_500px_gallery)) {
             $photonic_500px_gallery = new Photonic_500px_Processor();
         }
         $current_token = array('oauth_token' => $cookie['500px']['oauth_token'], 'oauth_token_secret' => $cookie['500px']['oauth_token_secret']);
         if (isset($_REQUEST['oauth_verifier']) && isset($_REQUEST['oauth_token'])) {
             $current_token['oauth_token'] = $_REQUEST['oauth_token'];
             $current_token['oauth_verifier'] = $_REQUEST['oauth_verifier'];
             $new_token = $photonic_500px_gallery->get_access_token($current_token);
             if (isset($new_token['oauth_token']) && isset($new_token['oauth_token_secret'])) {
                 // Strip out the token and the verifier from the callback URL and send the user to the callback URL.
                 $photonic_500px_oauth_done = true;
                 $redirect = remove_query_arg(array('oauth_token', 'oauth_verifier'));
                 wp_redirect($redirect);
                 exit;
             }
         } else {
             if (isset($cookie['500px']['oauth_token_type']) && $cookie['500px']['oauth_token_type'] == 'access') {
                 $access_token_response = $photonic_500px_gallery->check_access_token($current_token);
                 if (is_wp_error($access_token_response)) {
                     $photonic_500px_gallery->is_server_down = true;
                 }
                 $photonic_500px_oauth_done = $photonic_500px_gallery->is_access_token_valid($access_token_response);
             }
         }
     }
     if ($photonic_smug_allow_oauth && isset($cookie['smug']) && isset($cookie['smug']['oauth_token']) && isset($cookie['smug']['oauth_token_secret'])) {
         global $photonic_smugmug_gallery;
         if (!isset($photonic_smugmug_gallery)) {
             $photonic_smugmug_gallery = new Photonic_SmugMug_Processor();
         }
         $current_token = array('oauth_token' => $cookie['smug']['oauth_token'], 'oauth_token_secret' => $cookie['smug']['oauth_token_secret']);
         if (!$photonic_smug_oauth_done && (isset($cookie['smug']['oauth_token_type']) && $cookie['smug']['oauth_token_type'] == 'request' || !isset($cookie['smug']['oauth_token_type']))) {
             $new_token = $photonic_smugmug_gallery->get_access_token($current_token);
             if (isset($new_token['oauth_token']) && isset($new_token['oauth_token_secret'])) {
                 $access_token_response = $photonic_smugmug_gallery->check_access_token($new_token);
                 if (is_wp_error($access_token_response)) {
                     $photonic_smugmug_gallery->is_server_down = true;
                 }
                 $photonic_smug_oauth_done = $photonic_smugmug_gallery->is_access_token_valid($access_token_response);
             }
         } else {
             if (isset($cookie['smug']['oauth_token_type']) && $cookie['smug']['oauth_token_type'] == 'access') {
                 $access_token_response = $photonic_smugmug_gallery->check_access_token($current_token);
                 if (is_wp_error($access_token_response)) {
                     $photonic_smugmug_gallery->is_server_down = true;
                 }
                 $photonic_smug_oauth_done = $photonic_smugmug_gallery->is_access_token_valid($access_token_response);
             }
         }
     }
     if (isset($photonic_picasa_allow_oauth)) {
         global $photonic_picasa_gallery;
         if (!isset($photonic_picasa_gallery)) {
             $photonic_picasa_gallery = new Photonic_Picasa_Processor();
         }
     }
     if (isset($photonic_instagram_allow_oauth)) {
         global $photonic_instagram_gallery;
         if (!isset($photonic_instagram_gallery)) {
             $photonic_instagram_gallery = new Photonic_Instagram_Processor();
         }
     }
 }