public function widget($args, $instance) { extract($args, EXTR_SKIP); echo $before_widget; $title = apply_filters('widget_title', $instance['title']); if ($title) { echo $before_title . '<i class="fa fa-twitter"></i>' . $title . $after_title; } $result = $this->getTweets($instance['username'], $instance['count']); echo '<ul class="tweets">'; if ($result && is_array($result)) { foreach ($result as $tweet) { $text = $this->link_replace($tweet['text']); $text = preg_replace('/RT/', '<span>RT</span>', $text, 1); echo '<li>'; echo $text; echo ' '; echo '<a href="http://twitter.com/' . $instance['username'] . '/status/' . $tweet['id'] . '">' . twitter_time(strtotime($tweet['timestamp'])) . '</a>'; echo '</li>'; } } else { echo '<li>' . __('There was an error grabbing the Twitter feed', 'ta-music') . '</li>'; } echo '</ul>'; if (!empty($instance['tweettext'])) { echo '<a class="pull-right" href="http://twitter.com/' . $instance['username'] . '">' . $instance['tweettext'] . '</a>'; } echo $after_widget; }
function twitter_script($unique_id, $limit) { require_once dirname(__FILE__) . '/script/twitter/TwitterAPIExchange.php'; /*GET TWITTER KEYS FROM ADMINISTRATION*/ $twitter_consumer_key = get_theme_option(tk_theme_name . '_social_twitter_consumer_key'); $twitter_consumer_secret = get_theme_option(tk_theme_name . '_social_twitter_consumer_secret'); $twitter_access_token = get_theme_option(tk_theme_name . '_social_twitter_access_token'); $twitter_token_secret = get_theme_option(tk_theme_name . '_social_twitter_token_secret'); $twitter_username = get_theme_option(tk_theme_name . '_social_twitter'); /** Set access tokens here - see: https://dev.twitter.com/apps/ **/ $settings = array('oauth_access_token' => $twitter_access_token, 'oauth_access_token_secret' => $twitter_token_secret, 'consumer_key' => $twitter_consumer_key, 'consumer_secret' => $twitter_consumer_secret); /** URL for REST request, see: https://dev.twitter.com/docs/api/1.1/ **/ $url = 'https://api.twitter.com/1.1/statuses/user_timeline.json'; $getfield = '?screen_name=' . $twitter_username; if (!empty($unique_id)) { $getfield .= "&count=" . $limit; } else { $getfield .= "&count=1"; } $requestMethod = 'GET'; /** Perform the request and echo the response **/ $twitter = new TwitterAPIExchange($settings); $twitter_results = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest(); if ($unique_id !== 'home') { ?> <ul class="twitter_ul"> <?php } foreach ($twitter_results as $single_tweet) { if (!empty($single_tweet->text)) { //gets twitter content, time and name $twitter_status = $single_tweet->text; $twitter_time = $single_tweet->created_at; $twitter_name = $single_tweet->user->screen_name; $twitter_status = preg_replace("#(^|[\n ])([\\w]+?://[\\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\">\\2</a>", $twitter_status); $twitter_status = preg_replace("#(^|[\n ])((www|ftp)\\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\">\\2</a>", $twitter_status); $twitter_status = preg_replace("/@(\\w+)/", "<a href=\"http://twitter.com/\\1\">@\\1</a>", $twitter_status); $twitter_status = preg_replace("/#(\\w+)/", "<a href=\"http://search.twitter.com/search?q=\\1\">#\\1</a>", $twitter_status); //checks if it's single tweet on home or twitter widget if ($unique_id == 'home') { ?> <div class="home-twitter left"> <div class="home-twitter-content"> <img src="<?php echo get_template_directory_uri(); ?> /style/img/twitter-home.png" alt="img" title="img" /> <div class="home-twitter-text right"> <span><?php echo $twitter_status; ?> </span> <p><?php echo '@' . $twitter_name; ?> </p> </div><!--/home-twitter-text--> </div><!--/home-twitter-content--> </div><!--/home-twitter--> <?php //use this if it's twitter widget } else { ?> <li><div class="bg-widget-center left"><span class="twitt"></span><span><?php echo $twitter_status; ?> </span></div><p class="twitter-links"><?php echo twitter_time($twitter_time); ?> </p></li> <?php } //$unique_id == 'home' ?> <?php } //single_tweet->text } //uniquer_id if ($unique_id !== 'home') { ?> </ul> <?php } }
if (isset($_GET['last'])) { $query .= 'WHERE tweet_id < "' . $_GET['last'] . '" '; } $query .= 'ORDER BY tweet_id DESC LIMIT ' . TWEET_DISPLAY_COUNT; $result = $oDB->select($query); // Use the text file tweet_template.txt to construct each tweet in the list $tweet_template = file_get_contents('tweet_template.txt', FILE_USE_INCLUDE_PATH); $tweet_list = ''; $tweets_found = 0; while (($row = mysqli_fetch_assoc($result)) && $tweets_found < TWEET_DISPLAY_COUNT) { ++$tweets_found; // create a fresh copy of the empty template $current_tweet = $tweet_template; // Fill in the template with the current tweet $current_tweet = str_replace('[profile_image_url]', $row['profile_image_url'], $current_tweet); $current_tweet = str_replace('[created_at]', twitter_time($row['created_at']), $current_tweet); $current_tweet = str_replace('[screen_name]', $row['screen_name'], $current_tweet); $current_tweet = str_replace('[name]', $row['name'], $current_tweet); $current_tweet = str_replace('[user_mention_title]', USER_MENTION_TITLE . ' ' . $row['screen_name'] . ' (' . $row['name'] . ')', $current_tweet); $current_tweet = str_replace('[tweet_display_title]', TWEET_DISPLAY_TITLE, $current_tweet); $current_tweet = str_replace('[tweet_text]', linkify($row['tweet_text']), $current_tweet); // Include each tweet's id so site.js can request older or newer tweets $current_tweet = str_replace('[tweet_id]', $row['tweet_id'], $current_tweet); // Add this tweet to the list $tweet_list .= $current_tweet; } if (!$tweets_found) { if (isset($_GET['last'])) { $tweet_list = '<strong>No more tweets found</strong><br />'; } else { $tweet_list = '<strong>No tweets found</strong><br />';
?> " target="_blank"><?php echo $tweet->user->name; ?> </a></span> <?php $date = DateTime::createFromFormat('M j H:i:s P Y', $tweet->created_at); ?> <span class="username"><a href="https://twitter.com/<?php echo $tweet->user->screen_name; ?> " target="_blank">@<?php echo $tweet->user->screen_name; ?> </a> - <?php echo twitter_time($tweet->created_at); ?> </span> </div> <div class="text"> <?php // make a URL in text link if (substr($tweet->text, 0, 2) === "RT") { $text = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=\"\\0\">\\0</a>", $tweet->text); $text = preg_replace('/(@(\\w+))/', '<a href="http://twitter.com/\\2">\\1</a>', $text); } else { $text = $tweet->text; } ?> <p><?php echo $text;
// Create a stream of formatted tweets as HTML $tweet_stream = ''; foreach ($tweet_data as $tweet) { // Ignore any retweets if (isset($tweet['retweeted_status'])) { continue; } // Get a fresh copy of the tweet template $tweet_html = $tweet_template; // Insert this tweet into the html $tweet_html = str_replace('[screen_name]', $tweet['user']['screen_name'], $tweet_html); $tweet_html = str_replace('[name]', $tweet['user']['name'], $tweet_html); $tweet_html = str_replace('[profile_image_url]', $tweet['user']['profile_image_url'], $tweet_html); $tweet_html = str_replace('[tweet_id]', $tweet['id'], $tweet_html); $tweet_html = str_replace('[tweet_text]', linkify($tweet['text']), $tweet_html); $tweet_html = str_replace('[created_at]', twitter_time($tweet['created_at']), $tweet_html); $tweet_html = str_replace('[retweet_count]', $tweet['retweet_count'], $tweet_html); // Add the HTML for this tweet to the stream $tweet_stream .= $tweet_html; } // Pass the tweets HTML back to the Ajax request print $tweet_stream; // Handle errors from API request } else { if ($http_code == 429) { print 'Error: Twitter API rate limit reached'; } else { print 'Error: Twitter was not able to process that search'; } } } else {
function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', $instance['title']); $notweets = $instance['notweets']; echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } ?> <!-- Tweets List --> <?php $tweets = getTweets($notweets); //change number up to 20 for number of tweets if (!isset($tweets['error'])) { if (is_array($tweets)) { // to use with intents echo '<script type="text/javascript" src="//platform.twitter.com/widgets.js"></script>'; echo '<ul class="twitter_update_list">'; foreach ($tweets as $tweet) { echo '<li>'; if ($tweet['text']) { $the_tweet = $tweet['text']; /* Twitter Developer Display Requirements https://dev.twitter.com/terms/display-requirements 2.b. Tweet Entities within the Tweet text must be properly linked to their appropriate home on Twitter. For example: i. User_mentions must link to the mentioned user's profile. ii. Hashtags must link to a twitter.com search with the hashtag as the query. iii. Links in Tweet text must be displayed using the display_url field in the URL entities API response, and link to the original t.co url field. */ // i. User_mentions must link to the mentioned user's profile. if (is_array($tweet['entities']['user_mentions'])) { foreach ($tweet['entities']['user_mentions'] as $key => $user_mention) { $the_tweet = preg_replace('/@' . $user_mention['screen_name'] . '/i', '<a href="http://www.twitter.com/' . $user_mention['screen_name'] . '" target="_blank">@' . $user_mention['screen_name'] . '</a>', $the_tweet); } } // ii. Hashtags must link to a twitter.com search with the hashtag as the query. if (is_array($tweet['entities']['hashtags'])) { foreach ($tweet['entities']['hashtags'] as $key => $hashtag) { $the_tweet = preg_replace('/#' . $hashtag['text'] . '/i', '<a href="https://twitter.com/search?q=%23' . $hashtag['text'] . '&src=hash" target="_blank">#' . $hashtag['text'] . '</a>', $the_tweet); } } // iii. Links in Tweet text must be displayed using the display_url // field in the URL entities API response, and link to the original t.co url field. if (is_array($tweet['entities']['urls'])) { foreach ($tweet['entities']['urls'] as $key => $link) { $the_tweet = preg_replace('`' . $link['url'] . '`', '<a href="' . $link['url'] . '" target="_blank">' . $link['url'] . '</a>', $the_tweet); } } echo '<div class="twitter-text">'; echo $the_tweet; echo '</div>'; // 3. Tweet Actions // Reply, Retweet, and Favorite action icons must always be visible for the user to interact with the Tweet. These actions must be implemented using Web Intents or with the authenticated Twitter API. // No other social or 3rd party actions similar to Follow, Reply, Retweet and Favorite may be attached to a Tweet. // get the sprite or images from twitter's developers resource and update your stylesheet // echo ' // <div class="twitter_intents"> // <a class="reply" href="https://twitter.com/intent/tweet?in_reply_to='.$tweet['id_str'].'">Reply</a> // <a class="retweet" href="https://twitter.com/intent/retweet?tweet_id='.$tweet['id_str'].'">Retweet</a> // <a class="favorite" href="https://twitter.com/intent/favorite?tweet_id='.$tweet['id_str'].'">Favorite</a> // </div>'; // 4. Tweet Timestamp // The Tweet timestamp must always be visible and include the time and date. e.g., “3:00 PM - 31 May 12”. // 5. Tweet Permalink // The Tweet timestamp must always be linked to the Tweet permalink. echo ' <a class="timesince" href="https://twitter.com/' . $tweet['user']['screen_name'] . '/status/' . $tweet['id_str'] . '" target="_blank"> ' . twitter_time(date('h:i A M d', strtotime($tweet['created_at'] . '- 8 hours'))) . ' </a>'; // -8 GMT for Pacific Standard Time } else { echo ' <br /> <a href="http://twitter.com/' . $tweet['user']['screen_name'] . '" target="_blank">Click here to read ' . $tweet['user']['screen_name'] . '\'s Twitter feed</a>'; } echo '</li>'; } echo '</ul>'; } } ?> <!-- //Tweets List --> <?php echo $after_widget; }
<?php // if (sizeof($dms)) { require_once '../display_lib.php'; $dm_html = '<link rel="stylesheet" type="text/css" media="all" href="dm.css" />'; $template_html = file_get_contents('dm_template.html'); foreach ($dms as $dm) { $dm_html .= $template_html; $dm_html = str_replace('[sender_user_id]', $dm['sender_user_id'], $dm_html); $dm_html = str_replace('[sender_screen_name]', $dm['sender_screen_name'], $dm_html); $dm_html = str_replace('[sender_name]', $dm['sender_name'], $dm_html); $dm_html = str_replace('[sender_profile_image_url]', $dm['sender_profile_image_url'], $dm_html); $dm_html = str_replace('[recipient_user_id]', $dm['recipient_user_id'], $dm_html); $dm_html = str_replace('[recipient_screen_name]', $dm['recipient_screen_name'], $dm_html); $dm_html = str_replace('[recipient_name]', $dm['recipient_name'], $dm_html); $dm_html = str_replace('[recipient_profile_image_url]', $dm['recipient_profile_image_url'], $dm_html); $dm_html = str_replace('[dm_text]', linkify($dm['dm_text']), $dm_html); $dm_html = str_replace('[created_at]', twitter_time($dm['created_at']), $dm_html); } print $dm_html; } else { print "No dms found"; }
function twitter_script($unique_id, $limit) { require_once dirname(__FILE__) . '/script/twitter/TwitterAPIExchange.php'; /*GET TWITTER KEYS FROM ADMINISTRATION*/ $twitter_consumer_key = get_theme_option(tk_theme_name . '_social_twitter_consumer_key'); $twitter_consumer_secret = get_theme_option(tk_theme_name . '_social_twitter_consumer_secret'); $twitter_access_token = get_theme_option(tk_theme_name . '_social_twitter_access_token'); $twitter_token_secret = get_theme_option(tk_theme_name . '_social_twitter_token_secret'); $twitter_username = get_theme_option(tk_theme_name . '_social_twitter'); /** Set access tokens here - see: https://dev.twitter.com/apps/ **/ $settings = array('oauth_access_token' => $twitter_access_token, 'oauth_access_token_secret' => $twitter_token_secret, 'consumer_key' => $twitter_consumer_key, 'consumer_secret' => $twitter_consumer_secret); /** URL for REST request, see: https://dev.twitter.com/docs/api/1.1/ **/ $url = 'https://api.twitter.com/1.1/statuses/user_timeline.json'; $getfield = '?screen_name=' . $twitter_username; if (!empty($unique_id)) { $getfield .= "&count=" . $limit; } else { $getfield .= "&count=1"; } $requestMethod = 'GET'; /** Perform the request and echo the response **/ $twitter = new TwitterAPIExchange($settings); $twitter_results = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest(); if ($unique_id !== 'home') { ?> <ul class="twitter_ul"> <?php } foreach ($twitter_results as $single_tweet) { if (!empty($single_tweet->text)) { //gets twitter content, time and name $twitter_status = $single_tweet->text; $twitter_time = $single_tweet->created_at; $twitter_name = $single_tweet->user->screen_name; $twitter_status = preg_replace("#(^|[\n ])([\\w]+?://[\\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\">\\2</a>", $twitter_status); $twitter_status = preg_replace("#(^|[\n ])((www|ftp)\\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\">\\2</a>", $twitter_status); $twitter_status = preg_replace("/@(\\w+)/", "<a href=\"http://twitter.com/\\1\">@\\1</a>", $twitter_status); $twitter_status = preg_replace("/#(\\w+)/", "<a href=\"http://search.twitter.com/search?q=\\1\">#\\1</a>", $twitter_status); //checks if it's single tweet on home or twitter widget if ($unique_id == 'home') { ?> <div class="twitter-holder"> <div class="footer_twitter"> <div class="twitter-dialog"> <table class="twitter_table"> <thead> <tr><th colspan="2"><div class="twitter-dialog-top"> </div></th></tr> </thead> <tbody> <tr><td style="width:10px;vertical-align:top;"> <a href="http://twitter.com/<?php echo $twitter_name; ?> " class="twitter-link" title="Follow me on Twitter"><span class="bird"></span></a></td> <td class="twitter-dialog-td-p"> <?php echo $twitter_status; ?> </td> </tr> <tr><td colspan="2"> <div class="twitter-dialog-down"> </div> </td></tr> </tbody> </table> </div> </div> </div><!--twitter holder--> <?php //use this if it's twitter widget } else { ?> <li> <span> <div class="twitter-box-holder"> <div class="twitter-box-top"></div> <div class="twitter-box-center"> <?php echo $twitter_status; ?> </div> <div class="twitter-box-bottom"></div> </div> </span> <a class="twitter-time" style="font-size:85%" href="http://twitter.com/<?php echo $twitter_name; ?> "><?php echo twitter_time($twitter_time); ?> </a> </li> <?php } //$unique_id == 'home' ?> <?php } //single_tweet->text } //uniquer_id if ($unique_id !== 'home') { ?> </ul> <?php } }