/** * Gets an OAuth request token using the API Key and API Secret provided in the plugin's back-end options. * Once a token has been successfully got, the user is sent to an Authorization page where he can allow access for your site. * * @param null $oauth_callback * @return null */ function get_request_token($oauth_callback = null) { if (!empty($oauth_callback)) { $callback = $oauth_callback; } else { $callback = Photonic::get_callback_url(); } if ($this->provider == 'flickr') { $method = 'GET'; } else { $method = 'POST'; } $signature = $this->generate_signature($this->request_token_URL(), array('oauth_callback' => $callback), $method); $parameters = array('oauth_version' => $this->oauth_version, 'oauth_nonce' => $this->nonce, 'oauth_timestamp' => $this->oauth_timestamp, 'oauth_callback' => $callback, 'oauth_consumer_key' => $this->api_key, 'oauth_signature_method' => $this->oauth_signature_method(), 'oauth_signature' => $signature); if ($this->provider == 'smug') { $parameters['method'] = $this->request_token_URL(); } $end_point = $this->provider == 'smug' ? $this->end_point() : $this->request_token_URL(); if ($method == 'GET') { $end_point .= '?' . Photonic_Processor::build_query($parameters); $parameters = null; } $response = Photonic::http($end_point, $method, $parameters); $token = $this->parse_token($response); $secret = 'photonic_' . $this->provider . '_api_secret'; global ${$secret}; // We will hash the secret to store the cookie. Otherwise the cookie for the visitor will have the secret for the app for the plugin user. $secret = md5(${$secret}, false); if (isset($token['oauth_token']) && isset($token['oauth_token_secret'])) { setcookie('photonic-' . $secret . '-oauth-token', $token['oauth_token'], time() + 365 * 60 * 60 * 24, COOKIEPATH); setcookie('photonic-' . $secret . '-oauth-token-secret', $token['oauth_token_secret'], time() + 365 * 60 * 60 * 24, COOKIEPATH); setcookie('photonic-' . $secret . '-oauth-token-type', 'request', time() + 365 * 60 * 60 * 24, COOKIEPATH); } return $token; }