public function show_profile($instance = array())
 {
     $defaults = array('convert_emoji' => 'hide', 'hide_replies' => false, 'include_retweets' => false, 'mandatory_hash' => '', 'max_tweets' => 3, 'html_after' => '', 'preamble' => '');
     $instance = wp_parse_args($instance, $defaults);
     extract($instance);
     // Allow the local custom field to overwrite the widget's query, but
     // only on single post (of any type)
     if (is_singular() && ($post_id = get_queried_object_id())) {
         if ($local_username = trim(get_post_meta($post_id, '_tt_username', true))) {
             $username = $local_username;
         }
     }
     // Let the user know if there's no search query
     $username = trim($username);
     if (empty($username)) {
         $vars = array('msg' => __('For this Twitter Tracker profile widget to work you need to set at least a Twitter screenname (username) in the widget settings.', 'twitter-tracker'), 'additional_error_class' => '', 'strong' => true);
         $this->render('widget-error', $vars);
         return;
     }
     // Let the user know if there's no auth
     if (!TT_Twitter_Authentication::init()->is_authenticated()) {
         $vars = array('msg' => __('For this Twitter Tracker profile widget to work you need to authorise with Twitter in "Dashboard" -> "Settings" -> "Twitter Tracker Auth".', 'twitter-tracker'), 'additional_error_class' => '', 'strong' => true);
         $this->render('widget-error', $vars);
         return;
     }
     require_once 'class.oauth.php';
     require_once 'class.wp-twitter-oauth.php';
     require_once 'class.response.php';
     require_once 'class.twitter-service.php';
     $args = array('count' => max($max_tweets * 4, 200));
     $transient_key = 'tt_search-' . md5(serialize($instance) . $username . serialize($args));
     if ($output = get_transient($transient_key)) {
         echo $output;
         return;
     }
     $service = new TT_Service();
     $response = $service->request_user_timeline($username, $args);
     if (is_wp_error($response)) {
         error_log("Twitter Tracker response error: " . print_r($response, true));
         return;
     }
     if ($hide_replies) {
         $response->remove_replies();
     }
     if (!$include_retweets) {
         $response->remove_retweets();
     }
     $response->convert_emoji();
     $mandatory_hash = strtolower(trim(ltrim($mandatory_hash, '#')));
     if ($mandatory_hash) {
         $response->remove_without_hash($mandatory_hash);
     }
     // @TODO Setup a method for the default vars needed
     $vars = array('tweets' => array_slice($response->items, 0, $max_tweets), 'preamble' => $preamble, 'html_after' => $html_after);
     $vars['datef'] = _x('M j, Y @ G:i', 'Publish box date format', 'twitter-tracker');
     $output = $this->capture('widget-contents', $vars);
     echo PHP_EOL . "<!-- Regenerating cache {$transient_key} at " . current_time('mysql') . " -->" . PHP_EOL;
     echo $output;
     $output = PHP_EOL . "<!-- Retrieved from {$transient_key}, cached at " . current_time('mysql') . " -->" . PHP_EOL . $output;
     set_transient($transient_key, $output, apply_filters('tt_cache_expiry', 300, $transient_key, $username, $args));
 }
    {
        $creds_defaults = array('consumer_key' => 'XV7HZZKjYpPtGwhsTZY6A', 'consumer_secret' => 'etSpBLB6951otLgmAsKP67oV7ALKe8ipAaKe5OIyU', 'oauth_token' => null, 'oauth_token_secret' => null, 'authenticated' => false, 'user_id' => null, 'screen_name' => null);
        $creds_option = get_option('tt_twitter_creds', array());
        $this->creds = wp_parse_args($creds_option, $creds_defaults);
    }
    public function set_creds($new_creds)
    {
        $current_creds = get_option('tt_twitter_creds', array());
        unset($current_creds['consumer_key']);
        unset($current_creds['consumer_secret']);
        update_option('tt_twitter_creds', wp_parse_args($new_creds, $current_creds));
        $this->load_creds();
    }
    public function unset_creds($names)
    {
        $creds = get_option('tt_twitter_creds', array());
        unset($creds['consumer_key']);
        unset($creds['consumer_secret']);
        foreach ($names as $name) {
            unset($creds[$name]);
        }
        update_option('tt_twitter_creds', $creds);
        $this->load_creds();
    }
    public function is_authentication_response()
    {
        return isset($_GET['oauth_token']);
    }
}
TT_Twitter_Authentication::init();