function __construct($preflight_check) { if ($this->debug) { error_log('Inside: CWS_GPPAdmin::__construct()'); } include_once 'Zend/Loader.php'; Zend_Loader::loadClass('Zend_Gdata_HttpClient'); Zend_Loader::loadClass('Zend_Gdata_Photos'); Zend_Loader::loadClass('Zend_Oauth_Consumer'); Zend_Loader::loadClass('Zend_Http_Client'); Zend_Loader::loadClass('Zend_Gdata_Gbase'); // Get tokens from db $this->request_token = get_option('CWS_FLICKR_REQUEST_TOKEN'); $this->access_token = get_option('CWS-FLICKR-ACCESS_TOKEN'); $this->consumer_key = '1ba95822668e1181e229796002c5b2b5'; $this->consumer_secret = 'ee228c3ab73762a9'; $this->return_to = CWS_WPFlickr::cws_get_admin_url('/options-general.php') . '?page=cws_flickr&cws_oauth_return=true'; $this->perms = array('read'); /* 'read', 'write', 'delete', etc... */ // Prepare array for OAuth request try { $this->oauth_options = array('callbackUrl' => $this->return_to, 'siteUrl' => 'http://www.flickr.com/services/oauth', 'consumerKey' => $this->consumer_key, 'consumerSecret' => $this->consumer_secret, 'requestTokenUrl' => 'http://www.flickr.com/services/oauth/request_token', 'accessTokenUrl' => 'http://www.flickr.com/services/oauth/access_token', 'authorizeUrl' => 'http://www.flickr.com/services/oauth/authorize', 'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER, 'version' => '1.0', 'signatureMethod' => 'HMAC-SHA1'); } catch (Zend_Gdata_App_Exception $ex) { $this->errors[] = $ex->getMessage(); error_log('Error: ' . $ex); return; } try { $this->consumer = new Zend_Oauth_Consumer($this->oauth_options); } catch (Zend_Gdata_App_Exception $ex) { $this->errors[] = $ex->getMessage(); error_log('Error: ' . $ex); } }
function __construct() { if ($this->debug) { error_log('Inside: CWS_FlickrApi::__construct()'); } Zend_Loader::loadClass('Zend_Gdata_HttpClient'); Zend_Loader::loadClass('Zend_Oauth_Consumer'); Zend_Loader::loadClass('Zend_Http_Client'); Zend_Loader::loadClass('Zend_Cache'); Zend_Loader::loadClass('Zend_Config_Xml'); // Get options from database $this->request_token = get_option('CWS_FLICKR_REQUEST_TOKEN'); $this->access_token = get_option('CWS-FLICKR-ACCESS_TOKEN'); $this->options = get_option('cws_flickr_options'); $this->consumer_key = $this->options['consumer_key']; $this->consumer_secret = $this->options['consumer_secret']; $this->perms = $this->options['perms']; $this->return_to = CWS_WPFlickr::cws_get_admin_url('/options-general.php') . '?page=cws_flickr&cws_oauth_return=true'; // Prepare options array $this->oauth_options = array('callbackUrl' => $this->return_to, 'siteUrl' => 'http://www.flickr.com/services/oauth', 'consumerKey' => $this->consumer_key, 'consumerSecret' => $this->consumer_secret, 'requestTokenUrl' => 'http://www.flickr.com/services/oauth/request_token', 'accessTokenUrl' => 'http://www.flickr.com/services/oauth/access_token', 'authorizeUrl' => 'http://www.flickr.com/services/oauth/authorize', 'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER, 'version' => '1.0', 'signatureMethod' => 'HMAC-SHA1'); $this->consumer = new Zend_Oauth_Consumer($this->oauth_options); }
/** * * Get photo set * * @param string $photoset_id The photoset ID to chose random photo from. * @param string $per_page The number of photos to display per page * * @return object */ public function fetchPhotoset($id, $per_page = null) { static $method = 'flickr.photosets.getPhotos'; if (empty($id)) { // @see Zend_Service_Exception require_once 'Zend/Service/Exception.php'; throw new Zend_Service_Exception('You must supply a photo set ID'); } // Get page number from the url - if there isn't one - we're on page 1 $cws_page = isset($_GET['cws_page']) ? $_GET['cws_page'] : 1; $options = array('api_key' => $this->consumer_key, 'method' => $method, 'photoset_id' => $id, 'extras' => 'license, date_upload, date_taken, owner_name, icon_server, original_format, last_update, geo, tags, machine_tags, o_dims, views, media, path_alias, url_sq, url_t, url_s, url_m, url_o', 'per_page' => "{$per_page}", 'page' => $cws_page); // Add some caching... try { // Setup Zend Cache for 24hrs... // TODO: make cache duration user configurable... $frontendOptions = array('lifetime' => 86400, 'automatic_serialization' => true); $backendOptions = array('cache_dir' => WPFLICKR_PLUGIN_PATH . 'cache/'); $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions); // If we don't have cached version, grab em from Flickr if (($response = $cache->load('photo_set_' . $id . '_' . $options['page'] . '_' . $options['per_page'])) === false) { if ($this->debug) { error_log('Inside: CWS_FlickrApi::get_photo_set() - This one is from Flickr servers.'); } // if( $this->is_pro ) { if (CWS_WPFlickr::is_pro_check()) { $options['privacy_filter'] = ''; // empty this to return public and private $consumer = new Zend_Oauth_Consumer($this->oauth_options); $this->access_token = get_option('CWS-FLICKR-ACCESS_TOKEN'); $my_access_token = unserialize($this->access_token); $consumer = unserialize($this->access_token); $client = $consumer->getHttpClient($this->oauth_options); $client->setUri("http://api.flickr.com/services/rest/"); $client->setMethod(Zend_Http_Client::GET); $client->setConfig(array('timeout' => 30)); // TODO: check this stopped the time out issue $client->setParameterGet($options); $response = $client->request(); // Uses Zend_Config_Xml to parse xml to array require_once 'Zend/Config/Xml.php'; $photoset = new Zend_Config_Xml($response->getBody()); $cache->save($photoset, 'photo_set_' . $id . '_' . $options['page'] . '_' . $options['per_page']); return $photoset; } else { $options['privacy_filter'] = '1'; // Now search for photos $consumer = new Zend_Oauth_Consumer(); $client = $consumer->getHttpClient(); $client->setUri("http://api.flickr.com/services/rest/"); $client->setMethod(Zend_Http_Client::GET); $client->setConfig(array('timeout' => 30)); // TODO: check this stopped the time out issue $client->setParameterGet($options); $response = $client->request(); // Uses Zend_Config_Xml to parse xml to array require_once 'Zend/Config/Xml.php'; $photoset = new Zend_Config_Xml($response->getBody()); $cache->save($photoset, 'photo_set_' . $id . '_' . $options['page'] . '_' . $options['per_page']); return $photoset; } if ($response->isError()) { // @see Zend_Service_Exception require_once 'Zend/Service/Exception.php'; throw new Zend_Service_Exception('An error occurred sending request. Status code: ' . $response > getStatus()); } } else { if ($this->debug) { error_log('Inside: CWS_FlickrApi::get_photo_set() - This one is from cache.'); } $cache->save($response, 'photo_set_' . $id . '_' . $options['page']); return $response; } } catch (Zend_Gdata_App_Exception $ex) { $this->errors[] = $ex->getMessage(); $this->get_errors($this->errors); } }
/** * * Draw the options page * */ function cws_flickr_options_page() { // global $get_page; $hook = 'cws_flickr'; if (!current_user_can('manage_options')) { wp_die(__('You do not have sufficient permissions to access this page.')); } ?> <div class="wrap"> <?php screen_icon(); ?> <h2>Flickr Settings Page</h2> <?php $options = get_option('cws_flickr_options'); $WPFlickr = new CWS_WPFlickr(); // Check if we need to authenticate before displaying options form... $cws_FlickrAdmin = new CWS_FlickrAdmin($WPFlickr->preflight_errors); if (!$WPFlickr->preflight_errors) { if (isset($_REQUEST['cws_oauth_return'])) { if ($cws_FlickrAdmin->debug) { error_log('Returned from callback'); } if (!isset($_REQUEST['page']) || $_REQUEST['page'] != $hook) { return; } // Make sure we play nicely with other OAUth peeps // Save access token and run $cws_FlickrAdmin->is_authenticated() again... try { if ($cws_FlickrAdmin->debug) { error_log('Storing Access Token'); } $access_token = serialize($cws_FlickrAdmin->consumer->getAccessToken($_GET, unserialize($cws_FlickrAdmin->request_token))); add_option('CWS-FLICKR-ACCESS_TOKEN', $access_token); delete_option('CWS_FLICKR_REQUEST_TOKEN'); // no longer need this token so delete it. header("Location: " . CWS_WPFlickr::cws_get_admin_url('/options-general.php') . "?page=cws_flickr"); } catch (Zend_Oauth_Exception $ex) { // Nuke request token... delete_option('CWS_FLICKR_REQUEST_TOKEN'); error_log('ERROR: ' . $ex); header("Location: " . CWS_WPFlickr::cws_get_admin_url('/options-general.php') . "?page=cws_flickr"); die; } } else { // If user is authenticated display options form if ($cws_FlickrAdmin->is_authenticated()) { ?> <form method="post" action="options.php"> <?php if (function_exists('settings_fields')) { settings_fields('cws_flickr_options'); } // if (function_exists('do_settings_sections')) { do_settings_sections('cws_flickr'); } cws_flickr_setting_input(); // Grab the form cws_flickr_meta_box_feedback(); // Grab the meta boxes // cws_flickr_meta_box_links(); // Grab the links meta boxes ?> </form> <?php } else { ?> <p> <?php _e('This is the preferred method of authenticating your Flickr account.', 'cws_flickr'); ?> <br/> <?php _e("All authentication is taken place on FLickr's secure servers.", 'cws_flickr'); ?> <br/> </p> <p> <?php _e('Clicking the "Start the Login Process" link will redirect you to a login page at Flickr.com.', 'cws_flickr'); ?> <br/> <?php _e('After accepting the login there you will be returned here.', 'cws_flickr'); ?> </p> <?php echo $cws_FlickrAdmin->get_grant_link(); } } } else { $WPFlickr->showAdminMessages($WPFlickr->preflight_errors); } ?> </div> <?php }