function gltw_plugin_activation() { global $gltw_errors; require_once GLTW_INC . '/functions.php'; if (!function_exists('gltw_api_config')) { extract(gltw_api_config()); } if (empty($consumer_key) || empty($consumer_secret) || empty($access_key) || empty($access_secret)) { printf('<%1$s class="%2$s">%3$s</%1$s>', 'div', 'error', sprintf('<%1$s>%2$s</%1$s>', 'p', sprintf('<%1$s>%2$s<a href="%3$s">%4$s</a>.</%1$s>', 'strong', __('Please set the ', GLTW_DOMAIN), admin_url('admin.php?page=genesis-latest-tweets'), __('Genesis Latest Tweets Settings', GLTW_DOMAIN)))); } }
/** * Render full admin page */ function twitter_api_admin_render_page() { if (!current_user_can('manage_options')) { twitter_api_admin_render_header(__("You don't have permission to manage Twitter API settings", GLTW_DOMAIN), 'error'); twitter_api_admin_render_footer(); return; } try { // update applicaion settings if posted if (isset($_POST['saf_twitter']) && is_array($update = $_POST['saf_twitter'])) { $conf = gltw_api_config($update); } else { $conf = gltw_api_config(); } // check whether we have any OAuth params extract($conf); if (!$consumer_key || !$consumer_secret) { global $gltw_errors; $gltw_errors .= wpautop(__('Twitter application not fully configured', GLTW_DOMAIN)); //throw new Exception( __('Twitter application not fully configured', GLTW_DOMAIN ) ); } // else exchange access token if callback // request secret saved as option if (isset($_GET['oauth_token']) && isset($_GET['oauth_verifier'])) { $Token = twitter_api_oauth_access_token($consumer_key, $consumer_secret, $_GET['oauth_token'], $request_secret, $_GET['oauth_verifier']); // have access token, update config and destroy request secret $conf = gltw_api_config(array('request_secret' => '', 'access_key' => $Token->key, 'access_secret' => $Token->secret)); extract($conf); // fall through to verification of credentials } // else administrator needs to connect / authenticate with Twitter. if (!$access_key || !$access_secret) { twitter_api_admin_render_header(__('Plugin not yet authenticated with Twitter', GLTW_DOMAIN), 'error'); twitter_api_admin_render_login($consumer_key, $consumer_secret); } else { $me = twitter_api_get('account/verify_credentials'); twitter_api_admin_render_header(sprintf(__('Authenticated as @%s', GLTW_DOMAIN), $me['screen_name']), 'updated'); } } catch (TwitterApiException $Ex) { twitter_api_admin_render_header($Ex->getStatus() . ': Error ' . $Ex->getCode() . ', ' . $Ex->getMessage(), 'error'); if (401 === $Ex->getStatus()) { twitter_api_admin_render_login($consumer_key, $consumer_secret); } } catch (Exception $Ex) { twitter_api_admin_render_header($Ex->getMessage(), 'error'); } // end admin page with options form and close wrapper twitter_api_admin_render_form(); twitter_api_admin_render_footer(); }
/** * Echo the settings update form. * * @since 0.1.8 * * @param array $instance Current settings */ function form($instance) { extract(gltw_api_config()); if (empty($consumer_key) && empty($consumer_secret) && empty($access_key) && empty($access_secret)) { printf('<%1$s>%2$s<a href="%3$s">%4$s</a>.</%1$s>', 'p', __('Please set the ', GLTW_DOMAIN), admin_url('admin.php?page=genesis-twitter-widget-settings'), __('Genesis Twitter Widget Settings', GLTW_DOMAIN)); return; } /** Merge with defaults */ $instance = wp_parse_args((array) $instance, $this->defaults); ?> <p> <label for="<?php echo $this->get_field_id('title'); ?> "><?php _e('Title', GLTW_DOMAIN); ?> :</label> <input type="text" id="<?php echo $this->get_field_id('title'); ?> " name="<?php echo $this->get_field_name('title'); ?> " value="<?php echo esc_attr($instance['title']); ?> " class="widefat" /> </p> <p> <label for="<?php echo $this->get_field_id('twitter_id'); ?> "><?php _e('Twitter Username', GLTW_DOMAIN); ?> :</label> <input type="text" id="<?php echo $this->get_field_id('twitter_id'); ?> " name="<?php echo $this->get_field_name('twitter_id'); ?> " value="<?php echo esc_attr($instance['twitter_id']); ?> " class="widefat" /> </p> <p> <label for="<?php echo $this->get_field_id('twitter_num'); ?> "><?php _e('Number of Tweets to Show', GLTW_DOMAIN); ?> :</label> <input type="text" id="<?php echo $this->get_field_id('twitter_num'); ?> " name="<?php echo $this->get_field_name('twitter_num'); ?> " value="<?php echo esc_attr($instance['twitter_num']); ?> " size="3" /> </p> <p> <input id="<?php echo $this->get_field_id('twitter_hide_replies'); ?> " type="checkbox" name="<?php echo $this->get_field_name('twitter_hide_replies'); ?> " value="1" <?php checked($instance['twitter_hide_replies']); ?> /> <label for="<?php echo $this->get_field_id('twitter_hide_replies'); ?> "><?php _e('Hide @ Replies', GLTW_DOMAIN); ?> </label> </p> <p> <label for="<?php echo $this->get_field_id('twitter_duration'); ?> "><?php _e('Load new Tweets every', GLTW_DOMAIN); ?> </label> <select name="<?php echo $this->get_field_name('twitter_duration'); ?> " id="<?php echo $this->get_field_id('twitter_duration'); ?> "> <option value="5" <?php selected(5, $instance['twitter_duration']); ?> ><?php _e('5 Min.', GLTW_DOMAIN); ?> </option> <option value="15" <?php selected(15, $instance['twitter_duration']); ?> ><?php _e('15 Minutes', GLTW_DOMAIN); ?> </option> <option value="30" <?php selected(30, $instance['twitter_duration']); ?> ><?php _e('30 Minutes', GLTW_DOMAIN); ?> </option> <option value="60" <?php selected(60, $instance['twitter_duration']); ?> ><?php _e('1 Hour', GLTW_DOMAIN); ?> </option> <option value="120" <?php selected(120, $instance['twitter_duration']); ?> ><?php _e('2 Hours', GLTW_DOMAIN); ?> </option> <option value="240" <?php selected(240, $instance['twitter_duration']); ?> ><?php _e('4 Hours', GLTW_DOMAIN); ?> </option> <option value="720" <?php selected(720, $instance['twitter_duration']); ?> ><?php _e('12 Hours', GLTW_DOMAIN); ?> </option> <option value="1440" <?php selected(1440, $instance['twitter_duration']); ?> ><?php _e('24 Hours', GLTW_DOMAIN); ?> </option> </select> </p> <p> <input id="<?php echo $this->get_field_id('follow_link_show'); ?> " type="checkbox" name="<?php echo $this->get_field_name('follow_link_show'); ?> " value="1" <?php checked($instance['follow_link_show']); ?> /> <label for="<?php echo $this->get_field_id('follow_link_show'); ?> "><?php _e('Include link to twitter page?', GLTW_DOMAIN); ?> </label> </p> <p> <label for="<?php echo $this->get_field_id('follow_link_text'); ?> "><?php _e('Link Text (required)', GLTW_DOMAIN); ?> :</label> <input type="text" id="<?php echo $this->get_field_id('follow_link_text'); ?> " name="<?php echo $this->get_field_name('follow_link_text'); ?> " value="<?php echo esc_attr($instance['follow_link_text']); ?> " class="widefat" /> </p> <?php }
/** * Render "Connect" button for authenticating at twitter.com * @param string OAuth application Consumer Key * @param string OAuth application Consumer Secret */ function render_login($consumer_key, $consumer_secret) { try { $callback = $this->base_uri(); $Token = $this->oauth_request_token($consumer_key, $consumer_secret, $callback); } catch (Exception $Ex) { echo '<div class="error"><p><strong>Error:</strong> ', esc_html($Ex->getMessage()), '</p></div>'; return; } // Remember request token and render link to authorize // we're storing permanently - not using session here, because WP provides no session API. gltw_api_config(array('request_secret' => $Token->secret)); $href = $Token->get_authorization_url(); echo '<p><a class="button-primary" href="', esc_html($href), '">' . esc_html__('Connect to Twitter') . '</a></p>'; echo '<p> </p>'; }
/** * Get client instance authenticated with 'system' credentials * @param bool whether we're getting the system default client which is expected to be authed * @return TwitterApiClient */ public static function create_instance($default = true) { $Client = new TwitterApiClient(); extract(gltw_api_config()); if ($default) { if (!$consumer_key || !$consumer_secret || !$access_key || !$access_secret) { trigger_error(__('Twitter application is not fully configured')); } $Client->set_oauth($consumer_key, $consumer_secret, $access_key, $access_secret); } else { if ($consumer_key && $consumer_secret) { $Client->set_oauth($consumer_key, $consumer_secret); } } return $Client; }