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); }
/** * * 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 }