function refresh_token($refresh_token) { $response = Photonic::http($this->access_token_url(), 'POST', array('client_id' => $this->client_id, 'client_secret' => $this->client_secret, 'refresh_token' => $refresh_token, 'grant_type' => 'refresh_token')); if (!is_wp_error($response)) { $secret = md5($this->client_secret, false); $body = $response['body']; $body = json_decode($body); if (isset($_COOKIE['photonic-' . $secret . '-oauth-token'])) { unset($_COOKIE['photonic-' . $secret . '-oauth-token']); } if (isset($_COOKIE['photonic-' . $secret . '-oauth-token-type'])) { unset($_COOKIE['photonic-' . $secret . '-oauth-token-type']); } if (isset($_COOKIE['photonic-' . $secret . '-oauth-token-created'])) { unset($_COOKIE['photonic-' . $secret . '-oauth-token-created']); } if (isset($_COOKIE['photonic-' . $secret . '-oauth-token-expires'])) { unset($_COOKIE['photonic-' . $secret . '-oauth-token-expires']); } $cookie_expiration = 365 * 24 * 60 * 60; setcookie('photonic-' . $secret . '-oauth-token', $body->access_token, time() + $cookie_expiration, COOKIEPATH); if (isset($body->refresh_token)) { setcookie('photonic-' . $secret . '-oauth-refresh-token', $body->refresh_token, time() + $cookie_expiration, COOKIEPATH); } setcookie('photonic-' . $secret . '-oauth-token-type', $body->token_type, time() + $cookie_expiration, COOKIEPATH); setcookie('photonic-' . $secret . '-oauth-token-created', time(), time() + $cookie_expiration, COOKIEPATH); setcookie('photonic-' . $secret . '-oauth-token-expires', $body->expires_in, time() + $cookie_expiration, COOKIEPATH); } }
/** * Tests to see if the OAuth Access Token that is cached is still valid. This is important because a user might have manually revoked * access for your app through the provider's control panel. * * @param $request_token * @return array|WP_Error */ function check_access_token($request_token) { if ($this->provider == 'flickr') { $method = 'GET'; } else { $method = 'POST'; } $signature = $this->generate_signature($this->check_access_token_method(), array('method' => $this->check_access_token_method()), $method, $request_token); $parameters = array('oauth_consumer_key' => $this->api_key, 'oauth_nonce' => $this->nonce, 'oauth_signature' => $signature, 'oauth_signature_method' => $this->oauth_signature_method(), 'oauth_timestamp' => $this->oauth_timestamp, 'oauth_token' => $request_token['oauth_token'], 'oauth_version' => $this->oauth_version, 'method' => $this->check_access_token_method()); $end_point = $this->end_point(); if ($method == 'GET') { $end_point .= '?' . Photonic_Processor::build_query($parameters); $parameters = null; } $response = Photonic::http($end_point, $method, $parameters); return $response; }
/** * Method to validate that the stored token is indeed authenticated. * * @param $request_token * @return array|WP_Error */ function check_access_token($request_token) { $signed_parameters = $this->sign_call('https://api.500px.com/v1/users', 'GET', array()); // $end_point = $this->end_point(); $end_point = 'https://api.500px.com/v1/users?' . Photonic_Processor::build_query($signed_parameters); $response = Photonic::http($end_point, 'GET', null); return $response; }
/** * Runs a sequence of web-service calls to get information. Most often a single web-service call with the "Extras" parameter suffices for SmugMug. * But there are some scenarios, e.g. clicking on an album to get a popup of all images in that album, where you need to chain the calls for the header. * * @param $chained_calls * @param $smug_args * @param $shortcode_attr * @return string */ function make_chained_calls($chained_calls, $smug_args, $shortcode_attr) { if (is_array($chained_calls) && count($chained_calls) > 0) { $this->gallery_index++; extract($shortcode_attr); $ret = ''; global $photonic_smug_oauth_done; $passworded = false; foreach ($chained_calls as $call) { $smug_args['method'] = $call; if ($photonic_smug_oauth_done) { $signed_args = $this->sign_call('https://secure.smugmug.com/services/api/json/1.3.0/', 'POST', $smug_args); $response = Photonic::http('https://secure.smugmug.com/services/api/json/1.3.0/', 'POST', $signed_args); } else { $response = Photonic::http('https://secure.smugmug.com/services/api/json/1.3.0/', 'POST', $smug_args); } if ($call == 'smugmug.albums.get') { $body = $response['body']; $body = json_decode($body); if ($body->stat == 'ok') { $albums = $body->Albums; if (is_array($albums) && count($albums) > 0) { $album_text = $this->process_albums($albums, $columns); if (!empty($album_text)) { $ret .= "<div class='photonic-smug-stream photonic-stream' id='photonic-smug-stream-{$this->gallery_index}'>"; $ret .= $album_text; $ret .= "</div>"; } } } } else { if ($call == 'smugmug.albums.getInfo') { $body = $response['body']; $body = json_decode($body); if ($body->stat == 'ok') { $album = $body->Album; if (isset($album->Passworded) && $album->Passworded && !isset($album->Password) && !isset($signed_args['Password'])) { $passworded = true; } $header_object = array(); $highlight = $album->Highlight; $rand = rand(1000, 9999); $header_object['thumb_url'] = "https://secure.smugmug.com/photos/random.mg?AlbumID={$album->id}&AlbumKey={$album->Key}&Size=75x75&rand={$rand}"; $header_object['title'] = $album->Title; $header_object['link_url'] = $album->URL; global $photonic_smug_disable_title_link, $photonic_smug_hide_album_thumbnail, $photonic_smug_hide_album_title, $photonic_smug_hide_album_photo_count; $hidden = array('thumbnail' => !empty($photonic_smug_hide_album_thumbnail), 'title' => !empty($photonic_smug_hide_album_title), 'counter' => !empty($photonic_smug_hide_album_photo_count)); $counters = array('photos' => $album->ImageCount); if (empty($display)) { $display = 'in-page'; } $insert = $this->process_object_header($header_object, 'album', $hidden, $counters, empty($photonic_smug_disable_title_link), $display); if (isset($shortcode_attr['display']) && $shortcode_attr['display'] == 'popup') { // Do nothing. We will insert this into the popup. } else { $ret .= $insert; } } else { if ($body->stat == 'fail' && $body->code == 31) { $passworded = false; } } } else { if ($call == 'smugmug.images.get') { if (!$passworded) { if (isset($insert)) { $ret .= $this->process_images($response, $columns, $shortcode_attr, $insert); } else { $ret .= $this->process_images($response, $columns, $shortcode_attr); } } } else { if ($call == 'smugmug.users.getTree') { $body = $response['body']; $body = json_decode($body); if ($body->stat == 'ok') { $categories = $body->Categories; if (is_array($categories) && count($categories) > 0) { $ret .= "<ul class='photonic-tree'>"; foreach ($categories as $category) { if (isset($category->Albums)) { $albums = $category->Albums; $album_text = $this->process_albums($albums, $columns); if (!empty($album_text)) { $ret .= "<li>"; $ret .= "<div class='photonic-smug-category'><span class='photonic-header-title photonic-category-title'>{$category->Name}</span></div>"; $ret .= $album_text; $ret .= "</li>"; } } if (isset($category->SubCategories)) { $sub_categories = $category->SubCategories; $ret .= "<li>"; if (is_array($sub_categories) && count($sub_categories) > 0) { $ret .= "<ul class='photonic-sub-tree'>"; foreach ($sub_categories as $sub_category) { $albums = $sub_category->Albums; $ret .= "<li>"; $ret .= "<div class='photonic-smug-sub-category'><span class='photonic-header-title photonic-sub-category-title'>{$sub_category->Name}</span></div>"; $ret .= $this->process_albums($albums, $columns); $ret .= "</li>"; } $ret .= "</ul>"; } $ret .= "</li>"; } } $ret .= "</ul>"; } } } } } } } return $ret; } return ''; }
/** * Method to validate that the stored token is indeed authenticated. * * @param $request_token * @return array|WP_Error */ function check_access_token($request_token) { $parameters = array('method' => $this->check_access_token_method(), 'format' => 'json', 'nojsoncallback' => 1); $signed_parameters = $this->sign_call($this->end_point(), 'GET', $parameters); $end_point = $this->end_point(); $end_point .= '?' . Photonic_Processor::build_query($signed_parameters); $parameters = null; $response = Photonic::http($end_point, 'GET', $parameters); return $response; }