/**
  * Front-end display of widget.
  *
  * @see WP_Widget::widget()
  *
  * @param array $args     Widget arguments.
  * @param array $instance Saved values from database.
  */
 public function widget($args, $instance)
 {
     $default = array('title' => 'recent tweet', 'number_tweet' => 5, 'user_id' => 'evanto');
     $instance = wp_parse_args($instance, $default);
     extract($instance);
     echo balanceTags($args['before_widget']);
     if (!empty($title)) {
         echo balanceTags($args['before_title'] . $title . $args['after_title']);
     }
     if ($user_id) {
         $credentials = array('consumer_key' => '18ihEuNsfOJokCLb8SAgA', 'consumer_secret' => '7vTYnLYYiP4BhXvkMWtD3bGnysgiGqYlsPFfwXhGk');
         $twitter_api = new Wp_Twitter_Api($credentials);
         $query = 'count=' . $number_tweet . '&include_entities=true&include_rts=true&screen_name=' . $user_id;
         $args = array('type' => 'statuses/user_timeline');
         $twitters = $twitter_api->query($query);
         $output = array();
         $output[] = '<div class="twitter">';
         $output[] = '<ul class="tweet-list list-unstyled">';
         if (!isset($twitters['errors']) && count($twitters) > 0 and is_array($twitters)) {
             foreach ($twitters as $twitter) {
                 $twitter = (array) $twitter;
                 $output[] = '<li class="tweet">';
                 $output[] = "<span class='tweet-text'><a href='http://twitter.com/" . $user_id . "/status/" . $twitter['id'] . "'>" . human_time_diff(strtotime($twitter['created_at'])) . ' ago</a></span>';
                 $output[] = "<span class='tweet-time'>" . $twitter['text'] . "</span>";
                 $output[] = '</li>';
             }
         }
         $output[] = '</ul>';
         $output[] = '</div>';
         echo implode("\n", $output);
     }
 }
function get_twitter_entries($count, $username, $widget_id, $time = 'yes', $avatar = 'yes', $used_for = 'sidebar', $twitter_consumer_key, $twitter_consumer_secret)
{
    $filtered_message = "";
    $output = "";
    $iterations = 0;
    $cache = get_transient(THEMENAME . '_tweetcache_id_' . $username . '_' . $widget_id);
    if ($cache) {
        // $tweets = get_option(THEMENAME.'_tweetcache_'.$username.'_'.$widget_id);
    } else {
        // Include Twitter API Client
        require_once 'class-wp-twitter-api.php';
        // Set your personal data retrieved at https://dev.twitter.com/apps
        $credentials = array('consumer_key' => $twitter_consumer_key, 'consumer_secret' => $twitter_consumer_secret);
        // Let's instantiate Wp_Twitter_Api with your credentials
        $twitter_api = new Wp_Twitter_Api($credentials);
        // Example a - Retrieve last 5 tweets from my timeline (default type statuses/user_timeline)
        $query = 'count=5&include_entities=true&include_rts=true&screen_name=' . $username;
        $response = $twitter_api->query($query);
        if (!is_wp_error($response)) {
            $tweets = array();
            if (!empty($response)) {
                foreach ($response as $tweet) {
                    if ($iterations == $count) {
                        break;
                    }
                    $text = (string) $tweet->text;
                    if ($text[0] != "@") {
                        $iterations++;
                        $tweets[] = array('text' => filter($text), 'created' => strtotime($tweet->created_at), 'user' => array('name' => (string) $tweet->user->name, 'screen_name' => (string) $tweet->user->screen_name, 'image' => (string) $tweet->user->profile_image_url, 'utc_offset' => (int) $tweet->user->utc_offset[0], 'follower' => (int) $tweet->user->followers_count));
                    }
                }
                set_transient(THEMENAME . '_tweetcache_id_' . $username . '_' . $widget_id, 'true', 60 * 30);
                update_option(THEMENAME . '_tweetcache_' . $username . '_' . $widget_id, $tweets);
            }
        }
    }
    if (!isset($tweets[0])) {
        $tweets = get_option(THEMENAME . '_tweetcache_' . $username . '_' . $widget_id);
    }
    if (isset($tweets[0])) {
        $time_format = get_option('date_format') . " - " . get_option('time_format');
        if ($used_for == 'sidebar') {
            foreach ($tweets as $message) {
                $ex_cl = '';
                if ($avatar == 'yes') {
                    $ex_cl = 'with_avatar';
                }
                $output .= '<li><dl class="dl-horizontal ' . $ex_cl . '"><dt>';
                if ($avatar == 'yes') {
                    $output .= '<img src="' . $message['user']['image'] . '" alt="avatar" />';
                } else {
                    $output .= '<i class="moon-twitter"></i>';
                }
                $output .= '</dt><dd>';
                $output .= '<span class="message">' . $message['text'] . '</span>';
                $output .= '<span class="date">' . date_i18n($time_format, $message['created'] + $message['user']['utc_offset']) . '</span>';
                $output .= '</dd></dl></li>';
            }
        } else {
            if ($used_for == 'box_content') {
                foreach ($tweets as $message) {
                    $output .= '<li><dl class="span' . 12 / $count . '">';
                    $output .= '<dd><span class="message">' . $message['text'] . '</span>';
                    $output .= '<span class="date">' . date_i18n($time_format, $message['created'] + $message['user']['utc_offset']) . '</span></dd>';
                    $output .= '</dl></li>';
                }
            }
        }
    }
    if ($output != "") {
        if ($used_for == 'sidebar') {
            $filtered_message = "<ul class='tweet_list'>{$output}</ul>";
        } else {
            $filtered_message = "<ul class='tweet_list row'>{$output}</ul>";
        }
    } else {
        if ($used_for == 'sidebar') {
            $filtered_message = "<ul class='tweet_list'><li>No public Tweets found</li></ul>";
        } else {
            $filtered_message = '<p>No public Tweets found</p>';
        }
    }
    return $filtered_message;
}
Esempio n. 3
0
/**
 * Get request tweets from service api
 * @param $args
 * @return bool|object
 */
function themify_request_tweets($args)
{
    $data = themify_get_data();
    $prefix = 'setting-twitter_settings_';
    $screen_name = urlencode(strip_tags(sanitize_user(str_replace('@', '', $args['username']))));
    if ($args['limit'] != '') {
        $count = intval($args['limit']);
    }
    if ($args['include_retweets'] == 'true') {
        $include_rts = '1';
    } else {
        $include_rts = '0';
    }
    $exclude_replies = $args['exclude_replies'];
    $consumer_key = isset($data[$prefix . 'consumer_key']) ? $data[$prefix . 'consumer_key'] : '';
    $consumer_secret = isset($data[$prefix . 'consumer_secret']) ? $data[$prefix . 'consumer_secret'] : '';
    if (!class_exists('Wp_Twitter_Api')) {
        // Require twitter oauth class
        require 'twitteroauth/class-wp-twitter-api.php';
    }
    $credentials = apply_filters('themify_twitter_credentials', array('consumer_key' => $consumer_key, 'consumer_secret' => $consumer_secret));
    $query = 'screen_name=' . $screen_name . '&count=' . $count . '&include_rts=' . $include_rts . '&exclude_replies=' . $exclude_replies . '&include_entities=true';
    $twitterConnection = new Wp_Twitter_Api($credentials);
    $tweets = $twitterConnection->query($query);
    return $tweets;
}
Esempio n. 4
0
/**
 * get_twitter_entries()
 * 
 * @param mixed $count
 * @param mixed $username
 * @param mixed $widget_id
 * @param string $time
 * @param string $avatar
 * @param string $used_for
 * @return
 */
function get_twitter_top_footer($count, $username, $widget_id = 9999, $time = 'no', $avatar = 'no')
{
    $filtered_message = "";
    $output = "";
    $iterations = 0;
    $cache = get_transient(THEMENAME . '_tweetcache_id_' . $username . '_' . $widget_id);
    if ($cache) {
        $tweets = get_option(THEMENAME . '_tweetcache_' . $username . '_' . $widget_id);
    } else {
        // Include Twitter API Client
        require_once 'class-wp-twitter-api.php';
        $twitter_consumer_key = themeple_get_option('twitter_consumer_key');
        $twitter_consumer_secret = themeple_get_option('twitter_consumer_secret');
        // Set your personal data retrieved at https://dev.twitter.com/apps
        $credentials = array('consumer_key' => $twitter_consumer_key, 'consumer_secret' => $twitter_consumer_secret);
        // Let's instantiate Wp_Twitter_Api with your credentials
        $twitter_api = new Wp_Twitter_Api($credentials);
        // Example a - Retrieve last 5 tweets from my timeline (default type statuses/user_timeline)
        $query = 'count=5&include_entities=true&include_rts=true&screen_name=' . $username;
        $response = $twitter_api->query($query);
        if (!is_wp_error($response)) {
            $tweets = array();
            if (!empty($response)) {
                foreach ($response as $tweet) {
                    if ($iterations == $count) {
                        break;
                    }
                    $text = (string) $tweet->text;
                    if ($text[0] != "@") {
                        $iterations++;
                        $tweets[] = array('text' => filter($text), 'created' => strtotime($tweet->created_at), 'user' => array('name' => (string) $tweet->user->name, 'screen_name' => (string) $tweet->user->screen_name, 'image' => (string) $tweet->user->profile_image_url, 'utc_offset' => (int) $tweet->user->utc_offset[0], 'follower' => (int) $tweet->user->followers_count));
                    }
                }
                set_transient(THEMENAME . '_tweetcache_id_' . $username . '_' . $widget_id, 'true', 60 * 30);
                update_option(THEMENAME . '_tweetcache_' . $username . '_' . $widget_id, $tweets);
            }
        }
    }
    if (!isset($tweets[0])) {
        $tweets = get_option(THEMENAME . '_tweetcache_' . $username . '_' . $widget_id);
    }
    if (isset($tweets[0])) {
        $time_format = get_option('date_format') . " - " . get_option('time_format');
        foreach ($tweets as $message) {
            $output .= '<li class="tweet">';
            $output .= '<h5><img src="' . $message['user']['image'] . '"> ' . $message['user']['name'] . ' @ ' . $message['text'] . '</h5>';
            $output .= '</li>';
        }
    }
    if ($output != "") {
        $filtered_message = "<ul class='tweet_list' id='tweet_footer'>" . $output . "</ul>";
    } else {
        $filtered_message = "<ul class='tweet_list' id='tweet_footer'><li> No public Tweets found</li></ul>";
    }
    return $filtered_message;
}
Esempio n. 5
0
 function be_get_tweets($query)
 {
     require_once BE_PB_ROOT_PATH . 'functions/twitter/class-wp-twitter-api.php';
     $credentials = array('consumer_key' => 'NzICpLcZh35wmxHbdxIPjA', 'consumer_secret' => 'ragtPbz0eC2FpzBJL3CGy5sxgdNGhJ7f9nWw1nnkboo');
     $twitter_api = new Wp_Twitter_Api($credentials);
     return $twitter_api->query($query);
 }
Esempio n. 6
0
/**
 * Construct Twitter tab
 *
 * @since 1.0
 */
function ts_fab_show_twitter($context = '', $authorid = '')
{
    // Grab settings
    $ts_fab_settings = ts_fab_get_tabs_settings();
    if ($authorid == '') {
        global $authordata;
        $author = $authordata;
    } else {
        $author = get_userdata($authorid);
    }
    // Check if author has entered twitter username into WordPress profile
    if (get_user_meta($author->ID, 'ts_fab_twitter', true)) {
        $screen_name = get_user_meta($author->ID, 'ts_fab_twitter', true);
        if (isset($ts_fab_settings['twitter_consumer_key']) && isset($ts_fab_settings['twitter_consumer_secret'])) {
            // Include Twitter API 1.1 Client for WordPress
            require_once dirname(__FILE__) . '/class-wp-twitter-api.php';
            // Set your personal data retrieved at https://dev.twitter.com/apps
            $credentials = array('consumer_key' => $ts_fab_settings['twitter_consumer_key'], 'consumer_secret' => $ts_fab_settings['twitter_consumer_secret']);
            // Let's instantiate our class with our credentials
            $twitter_api = new Wp_Twitter_Api($credentials);
            // Example b - Retrieve my follower with a cache of 24 hour (default 30 minutes)
            $query = 'count=1&include_entities=true&screen_name=' . $screen_name;
            $args = array('type' => 'statuses/user_timeline', 'cache' => $ts_fab_settings['twitter_cache_interval'] * 60);
            $result = $twitter_api->query($query, $args);
        }
        // Store information we plan to use as variables
        if (isset($result[0]->text) && '' != $result[0]->text) {
            $status = $result[0]->text;
            $tweet_time = $result[0]->created_at;
            if (isset($result[0]->user->description)) {
                $description = $result[0]->user->description;
            }
        } else {
            $status = __('<!-- Couldn\'t fetch latest tweet -->', 'ts-fab');
        }
        // Create Fanciest Author Box output
        $ts_fab_twitter = '
		<div class="ts-fab-tab" id="ts-fab-twitter-' . $context . '">
			<div class="ts-fab-avatar">' . ts_fab_get_author_image($author) . '</div>
			<div class="ts-fab-text">
				<div class="ts-fab-header">
					<h4><a href="http://twitter.com/' . $screen_name . '">@' . $screen_name . '</a></h4>';
        if ($ts_fab_settings['twitter_bio'] == 1 && isset($description)) {
            $ts_fab_twitter .= '<div class="ts-fab-description">' . ts_fab_link_twitter($description) . '</div>';
        }
        $ts_fab_twitter .= '</div><!-- /.ts-fab-header -->';
        if ($ts_fab_settings['twitter_tweet'] == 1) {
            $ts_fab_twitter .= '<div class="ts-fab-content">';
            $ts_fab_twitter .= ts_fab_link_twitter($status);
            if (isset($tweet_time)) {
                $ts_fab_twitter .= '<span class="ts-fab-twitter-time"> - ' . human_time_diff(strtotime($tweet_time), time('U')) . ' ago</span>';
            }
            $ts_fab_twitter .= '</div>';
        }
        $show_count = $ts_fab_settings['twitter_count'] == 1 ? ' data-show-count="true" ' : ' data-show-count="false" ';
        $ts_fab_twitter .= '<div class="ts-fab-follow"><a href="https://twitter.com/' . $screen_name . '" class="twitter-follow-button"' . $show_count . 'data-lang="' . get_locale() . '">Follow @' . $screen_name . '</a></div>
				<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
			</div>
		</div>';
        return $ts_fab_twitter;
    }
}