function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', $instance['title']); $twitter_username = $instance['twitter_username']; $show_num = $instance['show_num']; $consumer_key = $instance['consumer_key']; $consumer_secret = $instance['consumer_secret']; $access_token = $instance['access_token']; $access_token_secret = $instance['access_token_secret']; $cache_time = $instance['cache_time']; // Opening of widget echo $before_widget; // Open of title tag if ($title) { echo $before_title . $title . $after_title; } $last_cache_time = get_option('gdl_twitter_widget_last_cache_time', 0); $diff = time() - $last_cache_time; $crt = $cache_time * 3600; if (empty($last_cache_time) || $diff >= $crt) { $connection = getConnectionWithAccessToken($consumer_key, $consumer_secret, $access_token, $access_token_secret); $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $twitter_username . "&count=" . $show_num) or die('Couldn\'t retrieve tweets! Wrong username?'); if (!empty($tweets->errors)) { if ($tweets->errors[0]->message == 'Invalid or expired token') { echo '<strong>' . $tweets->errors[0]->message . '!</strong><br />You\'ll need to regenerate it <a href="https://dev.twitter.com/apps" target="_blank">here</a>!' . $after_widget; } else { echo '<strong>' . $tweets->errors[0]->message . '</strong>' . $after_widget; } return; } $tweets_data = array(); for ($i = 0; $i <= count($tweets); $i++) { if (!empty($tweets[$i])) { $tweets_data[$i]['created_at'] = $tweets[$i]->created_at; $tweets_data[$i]['text'] = $tweets[$i]->text; $tweets_data[$i]['status_id'] = $tweets[$i]->id_str; } } update_option('gdl_twitter_widget_tweets', serialize($tweets_data)); update_option('gdl_twitter_widget_last_cache_time', time()); } else { $tweets_data = maybe_unserialize(get_option('gdl_twitter_widget_tweets')); } echo '<div class="twitter-whole">'; echo '<ul id="twitter_update_list">'; foreach ($tweets_data as $each_tweet) { echo '<li>'; echo '<span>' . convert_links($each_tweet['text']) . '</span>'; echo '<a target="_blank" href="http://twitter.com/' . $twitter_username . '/statuses/' . $each_tweet['status_id'] . '">' . relative_time($each_tweet['created_at']) . '</a>'; echo '</li>'; } echo '</ul>'; echo '</div>'; // Closing of widget echo $after_widget; }
function widget($args, $instance) { if (!isset($args['widget_id'])) { $args['widget_id'] = null; } extract($args, EXTR_SKIP); echo $before_widget; $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); if ($title) { echo $before_title . $title . $after_title; } if (empty($instance['consumerkey']) || empty($instance['consumersecret']) || empty($instance['accesstoken']) || empty($instance['accesstokensecret']) || empty($instance['userID'])) { echo 'Please fill all widget settings!' . $after_widget; return; } $connection = new TwitterOAuth($instance['consumerkey'], $instance['consumersecret'], $instance['accesstoken'], $instance['accesstokensecret']); $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $instance['userID'] . "&count=" . $instance['count']) or die('Couldn\'t retrieve tweets! Wrong username?'); if (!empty($tweets->errors)) { if ($tweets->errors[0]->message == 'Invalid or expired token') { echo '<strong>' . $tweets->errors[0]->message . '!</strong><br />You\'ll need to regenerate it <a href="https://dev.twitter.com/apps" target="_blank">here</a>!' . $after_widget; } else { echo '<strong>' . $tweets->errors[0]->message . '</strong>' . $after_widget; } return; } function convert_links($status, $targetBlank = true, $linkMaxLen = 250) { $target = $targetBlank ? " target=\"_blank\" " : ""; $status = preg_replace("/((http:\\/\\/|https:\\/\\/)[^ )\n]+)/e", "'<a href=\"\$1\" title=\"\$1\" {$target} >'. ((strlen('\$1')>={$linkMaxLen} ? substr('\$1',0,{$linkMaxLen}).'...':'\$1')).'</a>'", $status); $status = preg_replace("/(@([_a-z0-9\\-]+))/i", "<a href=\"http://twitter.com/\$2\" title=\"Follow \$2\" {$target} >\$1</a>", $status); $status = preg_replace("/(#([_a-z0-9\\-]+))/i", "<a href=\"https://twitter.com/search?q=\$2\" title=\"Search \$1\" {$target} >\$1</a>", $status); return $status; } if (is_array($tweets)) { echo '<div class="Twitter">'; echo '<ul>'; foreach ($tweets as $tweet) { echo '<li><span>' . convert_links($tweet->text) . '</span><a class="twitter_time" target="_blank" href="http://twitter.com/' . $instance['userID'] . '/statuses/' . $tweet->id_str . '"><i class="icon-calendar"></i> ' . date('F j, Y G:i:s', strtotime($tweet->created_at)) . '</a></li>'; } echo '</ul>'; echo '</div>'; } echo $after_widget; }
} ?> <div class="footer-twitter-wrapper boxed-style"> <div class="container twitter-container"> <i class="gdl-twitter-icon icon-twitter"></i> <div class="gdl-twitter-wrapper"> <div class="gdl-twitter-navigation"> <a class="prev icon-angle-left"></a> <a class="next icon-angle-right"></a> </div> <ul id="gdl-twitter" > <?php foreach ($tweets_data as $each_tweet) { echo '<li>'; echo '<span>' . convert_links($each_tweet['text']) . '</span>'; echo '<a class="date" target="_blank" href="http://twitter.com/' . $twitter_id . '/statuses/' . $each_tweet['status_id'] . '">' . relative_time($each_tweet['created_at']) . '</a>'; echo '</li>'; } ?> </ul> <script type="text/javascript"> jQuery(document).ready(function(){ var twitter_wrapper = jQuery('ul#gdl-twitter'); twitter_wrapper.each(function(){ var fetch_num = jQuery(this).children().length; var twitter_nav = jQuery(this).siblings('div.gdl-twitter-navigation'); if( fetch_num > 0 ){
function widget($args, $instance) { extract($args); if (!empty($instance['title'])) { $title = apply_filters('widget_title', $instance['title']); } echo $before_widget; if (!empty($title)) { echo $before_title . $title . $after_title; } //check settings and die if not set if (empty($instance['username'])) { echo '<strong>Please fill all widget settings!</strong>' . $after_widget; return; } if (function_exists('ot_get_option')) { $consumerkey = ''; if (ot_get_option('meganews_twitter_consumer_key')) { $consumerkey = ot_get_option('meganews_twitter_consumer_key'); } $consumersecret = ''; if (ot_get_option('meganews_twitter_consumer_secret')) { $consumersecret = ot_get_option('meganews_twitter_consumer_secret'); } $accesstoken = ''; if (ot_get_option('meganews_twitter_access_token')) { $accesstoken = ot_get_option('meganews_twitter_access_token'); } $accesstokensecret = ''; if (ot_get_option('meganews_twitter_access_secret_token')) { $accesstokensecret = ot_get_option('meganews_twitter_access_secret_token'); } $connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret); $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $instance['username'] . "&count=10") or die('Couldn\'t retrieve tweets! Wrong username?'); } if (!empty($tweets->errors)) { if ($tweets->errors[0]->message == 'Invalid or expired token') { echo '<strong>' . $tweets->errors[0]->message . '!</strong><br />You\'ll need to regenerate it <a href="https://dev.twitter.com/apps" target="_blank">here</a>!' . $after_widget; } else { echo '<strong>' . $tweets->errors[0]->message . '</strong>' . $after_widget; } return; } for ($i = 0; $i <= count($tweets); $i++) { if (!empty($tweets[$i])) { $tweets_array[$i]['created_at'] = $tweets[$i]->created_at; $tweets_array[$i]['text'] = $tweets[$i]->text; $tweets_array[$i]['status_id'] = $tweets[$i]->id_str; } } //save tweets to wp option update_option('tp_twitter_plugin_tweets', serialize($tweets_array)); update_option('tp_twitter_plugin_last_cache_time', time()); echo '<!-- twitter cache has been updated! -->'; $tp_twitter_plugin_tweets = maybe_unserialize(get_option('tp_twitter_plugin_tweets')); if (!empty($tp_twitter_plugin_tweets)) { print ' <div class="twitter_updates"> <ul class="tweet_list">'; $fctr = '1'; foreach ($tp_twitter_plugin_tweets as $tweet) { print '<li>' . convert_links($tweet['text']) . '<br /><span class="tweet_time"><a target="_blank" href="http://twitter.com/' . $instance['username'] . '/statuses/' . $tweet['status_id'] . '">' . relative_time($tweet['created_at']) . '</a></span></li>'; if ($fctr == $instance['tweetstoshow']) { break; } $fctr++; } print ' </ul> </div>'; } echo $after_widget; }
public function widget($args, $instance) { extract($args); if (!empty($instance['title'])) { $title = apply_filters('widget_title', $instance['title']); } echo $before_widget; if (!empty($title)) { echo $before_title . $title . $after_title; } if (empty($instance['consumerkey']) || empty($instance['consumersecret']) || empty($instance['accesstoken']) || empty($instance['accesstokensecret']) || empty($instance['cachetime']) || empty($instance['username'])) { echo '<strong>Please fill all widget settings!</strong>' . $after_widget; return; } // Check cache time $tc_recent_tweets_cache_time = get_option('tc_recent_tweets_cache_time'); $diff = time() - $tc_recent_tweets_cache_time; $crt = $instance['cachetime'] * 3600; //require_once('twitteroauth.php'); if ($diff >= $crt || empty($tc_recent_tweets_cache_time)) { if (!(require_once 'twitteroauth.php')) { echo '<strong>Couldn\'t find twitteroauth.php!</strong>' . $after_widget; return; } function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) { $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret); return $connection; } $connection = getConnectionWithAccessToken($instance['consumerkey'], $instance['consumersecret'], $instance['accesstoken'], $instance['accesstokensecret']); $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $instance['username'] . "&count=10") or die('Couldn\'t retrieve tweets! Wrong username?'); if (!empty($tweets->errors)) { if ($tweets->errors[0]->message == 'Invalid or expired token') { echo '<strong>' . $tweets->errors[0]->message . '!</strong><br />You\'ll need to regenerate it <a href="https://dev.twitter.com/apps" target="_blank">here</a>!' . $after_widget; } else { echo '<strong>' . $tweets->errors[0]->message . '</strong>' . $after_widget; } return; } for ($i = 0; $i <= count($tweets); $i++) { if (!empty($tweets[$i])) { $tweets_array[$i]['created_at'] = $tweets[$i]->created_at; $tweets_array[$i]['text'] = $tweets[$i]->text; $tweets_array[$i]['status_id'] = $tweets[$i]->id_str; } } //save tweets to wp option update_option('mts_twitter_plugin_tweets', serialize($tweets_array)); update_option('tc_recent_tweets_cache_time', time()); echo '<!-- twitter cache has been updated! -->'; } //convert links to clickable format function convert_links($status, $targetBlank = true, $linkMaxLen = 250) { $target = $targetBlank ? " target=\"_blank\" " : ""; // the target $status = preg_replace("/((http:\\/\\/|https:\\/\\/)[^ )]+)/e", "'<a href=\"\$1\" title=\"\$1\" {$target} >'. ((strlen('\$1')>={$linkMaxLen} ? substr('\$1',0,{$linkMaxLen}).'...':'\$1')).'</a>'", $status); // convert link to url $status = preg_replace("/(@([_a-z0-9\\-]+))/i", "<a href=\"http://twitter.com/\$2\" title=\"Follow \$2\" {$target} >\$1</a>", $status); // convert @ to follow $status = preg_replace("/(#([_a-z0-9\\-]+))/i", "<a href=\"https://twitter.com/search?q=\$2\" title=\"Search \$1\" {$target} >\$1</a>", $status); // convert # to search return $status; // return the status } //convert dates to readable format function relative_time($a) { $b = strtotime("now"); //get current timestampt $c = strtotime($a); //get timestamp when tweet created $d = $b - $c; //get difference $minute = 60; //calculate different time values $hour = $minute * 60; $day = $hour * 24; $week = $day * 7; if (is_numeric($d) && $d > 0) { if ($d < 3) { return "right now"; } //if less then 3 seconds if ($d < $minute) { return floor($d) . " seconds ago"; } //if less then minute if ($d < $minute * 2) { return "about 1 minute ago"; } //if less then 2 minutes if ($d < $hour) { return floor($d / $minute) . " minutes ago"; } //if less then hour if ($d < $hour * 2) { return "about 1 hour ago"; } //if less then 2 hours if ($d < $day) { return floor($d / $hour) . " hours ago"; } //if less then day if ($d > $day && $d < $day * 2) { return "yesterday"; } //if more then day, but less then 2 days if ($d < $day * 365) { return floor($d / $day) . " days ago"; } //if less then year return "over a year ago"; //else return more than a year } } $mts_twitter_plugin_tweets = maybe_unserialize(get_option('mts_twitter_plugin_tweets')); if (!empty($mts_twitter_plugin_tweets)) { print '<div class="tc-recent-tweets tweets"><ul>'; $fctr = '1'; foreach ($mts_twitter_plugin_tweets as $tweet) { print '<li><span>' . convert_links($tweet['text']) . '</span><br /><a class="twitter-time" target="_blank" href="http://twitter.com/' . $instance['username'] . '/statuses/' . $tweet['status_id'] . '">' . relative_time($tweet['created_at']) . '</a></li>'; if ($fctr == $instance['tweetstoshow']) { break; } $fctr++; } print '</ul></div>'; } echo $after_widget; }
//if less then year if ($d < $day * 365) { return floor($d / $day) . " days ago"; } //else return more than a year return "over a year ago"; } } foreach ($tweets_array as $tweet) { ?> <ul class="tweet_list"> <li class="tweet_first tweet_odd"> <div class="the-tweet"> <span class="tweet_text"><?php echo convert_links($tweet['text']); ?> </span> <span class="tweet_time"><a class="twitter_time" target="_blank" href="http://twitter.com/<?php echo $b_data['TW_USERNAME']; ?> /statuses/<?php echo $tweet['status_id']; ?> "><?php echo relative_time($tweet['created_at']); ?> </a></span> </div> </li> </ul>
} } function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) { $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret); return $connection; } $connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret); $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $username . "&count=" . $count) or die('Couldn\'t retrieve tweets! Wrong username?'); if (!empty($tweets->errors)) { if ($tweets->errors[0]->message == 'Invalid or expired token') { echo '<strong>' . $tweets->errors[0]->message . '!</strong><br />You\'ll need to regenerate it <a href="https://dev.twitter.com/apps" target="_blank">here</a>!' . $after_widget; } else { echo '<strong>' . $tweets->errors[0]->message . '</strong>' . $after_widget; } return; } for ($i = 0; $i <= count($tweets); $i++) { if (!empty($tweets[$i])) { $tweets_array[$i]['created_at'] = $tweets[$i]->created_at; $tweets_array[$i]['text'] = $tweets[$i]->text; $tweets_array[$i]['status_id'] = $tweets[$i]->id_str; } } foreach ($tweets_array as $tweet) { $timeline .= '<li>'; $timeline .= '<span class="tweet_text">' . convert_links($tweet['text']) . '</span> '; $timeline .= '<a class="twitter_time" target="_blank" href="http://twitter.com/' . $username . '/statuses/' . $tweet['status_id'] . '">' . relative_time($tweet['created_at']) . '</a>'; $timeline .= '</li>'; } echo $timeline;
echo $title; ?> </h3> <div id="updates"> <?php $total_rows = mysql_num_rows($result); if ($total_rows > 0) { while ($row = mysql_fetch_array($result)) { ?> <div class="msg_body" id="message<?php echo $row['id']; ?> "> <div class="msg_img"> <img src="http://0.gravatar.com/avatar/82620dd66b22b34a915303b93b92929b" /></div> <div class="msg_text"> <?php echo convert_links($row['message']); ?> <div class="time"><?php echo $row['time']; ?> </div> </div> </div> <?php } } ?> </div> </div> </body> </html>
function shortcode_jw_twitter($atts, $content) { $jw_twitter_tweets = twitter_build($atts); if (is_array($jw_twitter_tweets)) { $output = '<div class="jw-twitter">'; $output .= '<ul class="jtwt">'; $fctr = '1'; foreach ($jw_twitter_tweets as $tweet) { $output .= '<li class="clearfix"><div class="category-icon-box"><i class="fa fa-twitter"></i></div><span>' . convert_links($tweet['text']) . '</span><br /><a class="twitter_time" target="_blank" href="http://twitter.com/' . $atts['username'] . '/statuses/' . $tweet['status_id'] . '">' . relative_time($tweet['created_at']) . '</a></li>'; if ($fctr == $atts['tweetstoshow']) { break; } $fctr++; } $output .= '</ul>'; //$output.='<div class="twitter-follow">' . (jw_option('jw_car_follow') ? jw_option('jw_car_follow') : __('Follow Us', 'designinvento')) . ' - <a target="_blank" href="http://twitter.com/' . $atts['username'] . '">@' . $atts['username'] . '</a></div>'; $output .= '</div>'; return $output; } else { return $jw_twitter_tweets; } }
function get_theme_tweets($username, $consumerkey, $consumerkeysecret, $accesstoken, $accesstokensecret, $notweets) { //check settings and die if not set if (empty($username) || empty($consumerkey) || empty($consumerkeysecret) || empty($accesstoken) || empty($accesstokensecret)) { echo '<strong>Please fill all Twitter settings!</strong>'; return; } // yes, it needs update function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) { $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret); return $connection; } $cacheContent = file_get_contents(__DIR__ . '/cache.txt'); if (!empty($cacheContent)) { $cacheContent = json_decode($cacheContent, true); } if (empty($cacheContent) || time() - $cacheContent['time'] > 60) { $connection = getConnectionWithAccessToken($consumerkey, $consumerkeysecret, $accesstoken, $accesstokensecret); $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $username . "&count=10") or die('Couldn\'t retrieve tweets! Wrong username?'); if (!empty($tweets->errors)) { if ($tweets->errors[0]->message == 'Invalid or expired token') { echo '<strong>' . $tweets->errors[0]->message . '!</strong><br />You will need to regenerate it <a href="https://dev.twitter.com/apps" target="_blank">here</a>!' . $after_widget; } else { echo '<strong>' . $tweets->errors[0]->message . '</strong>' . $after_widget; } return; } for ($i = 0; $i <= count($tweets); $i++) { if (!empty($tweets[$i])) { $tweets_array[$i]['created_at'] = $tweets[$i]->created_at; $tweets_array[$i]['text'] = $tweets[$i]->text; $tweets_array[$i]['status_id'] = $tweets[$i]->id_str; } } $cacheContent = array('time' => time(), 'tweets' => $tweets_array); file_put_contents(__DIR__ . '/cache.txt', json_encode($cacheContent)); } else { $tweets_array = $cacheContent['tweets']; } set_transient('twitter-bar-tweets', $tweets_array, 0); //convert links to clickable format function convert_links($status) { // convert link to url $status = preg_replace_callback("/((http:\\/\\/|https:\\/\\/)[^ )]+)/i", function ($u) { return '<a href="' . $u[0] . '" target="_blank">' . $u[0] . '</a>'; }, $status); // convert @ to follow $status = preg_replace_callback("/(@([_a-z0-9\\-]+))/i", function ($u) { return '<a href="http://twitter.com/' . $u[2] . '" title="Follow ' . $u[1] . '" target="_blank">' . $u[1] . '</a>'; }, $status); // convert # to search $status = preg_replace_callback("/(#([_a-z0-9\\-]+))/i", function ($u) { return '<a href="https://twitter.com/search?q=' . $u[2] . '" title="Search ' . $u[0] . '" target="_blank">' . $u[0] . '</a>'; }, $status); // return the status return $status; } //convert dates to readable format function relative_time($a) { //get current timestampt $b = strtotime("now"); //get timestamp when tweet created $c = strtotime($a); //get difference $d = $b - $c; //calculate different time values $minute = 60; $hour = $minute * 60; $day = $hour * 24; $week = $day * 7; if (is_numeric($d) && $d > 0) { //if less then 3 seconds if ($d < 3) { return "right now"; } //if less then minute if ($d < $minute) { return floor($d) . " seconds ago"; } //if less then 2 minutes if ($d < $minute * 2) { return "about 1 minute ago"; } //if less then hour if ($d < $hour) { return floor($d / $minute) . " minutes ago"; } //if less then 2 hours if ($d < $hour * 2) { return "about 1 hour ago"; } //if less then day if ($d < $day) { return floor($d / $hour) . " hours ago"; } //if more then day, but less then 2 days if ($d > $day && $d < $day * 2) { return "yesterday"; } //if less then year if ($d < $day * 365) { return floor($d / $day) . " days ago"; } //else return more than a year return "over a year ago"; } } //print tweets $tp_twitter_plugin_tweets = maybe_unserialize(get_transient('twitter-bar-tweets')); if (!empty($tp_twitter_plugin_tweets)) { $fctr = '1'; foreach ($tp_twitter_plugin_tweets as $tweet) { print '<div>' . convert_links($tweet['text']) . '</div>'; if ($fctr == $notweets) { break; } $fctr++; } } }
function get_theme_tweets($username, $consumerkey, $consumerkeysecret, $accesstoken, $accesstokensecret, $notweets) { //check settings and die if not set if (empty($username) || empty($consumerkey) || empty($consumerkeysecret) || empty($accesstoken) || empty($accesstokensecret)) { echo '<strong>Please fill all Twitter settings!</strong>'; return; } // yes, it needs update if (!(require_once 'twitter_oauth.php')) { echo '<strong>Couldn\'t find twitter_oauth.php!</strong>'; return; } if (!function_exists('getConnectionWithAccessToken')) { function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) { $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret); return $connection; } } $connection = getConnectionWithAccessToken($consumerkey, $consumerkeysecret, $accesstoken, $accesstokensecret); $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $username . "&count=5") or die('Couldn\'t retrieve tweets! Wrong username?'); if (!empty($tweets->errors)) { if ($tweets->errors[0]->message == 'Invalid or expired token') { echo '<strong>' . $tweets->errors[0]->message . '!</strong><br />You will need to regenerate it <a href="https://dev.twitter.com/apps" target="_blank">here</a>!' . $after_widget; } else { echo '<strong>' . $tweets->errors[0]->message . '</strong>' . $after_widget; } return; } for ($i = 0; $i <= count($tweets); $i++) { if (!empty($tweets[$i])) { $tweets_array[$i]['created_at'] = $tweets[$i]->created_at; $tweets_array[$i]['text'] = $tweets[$i]->text; $tweets_array[$i]['status_id'] = $tweets[$i]->id_str; } } set_transient('twitter-bar-tweets', $tweets_array, 0); //convert links to clickable format function convert_links($status, $targetBlank = true, $linkMaxLen = 250) { // the target $target = $targetBlank ? " target=\"_blank\" " : ""; // convert link to url $status = preg_replace("/((http:\\/\\/|https:\\/\\/)[^ )\n]+)/e", "'<a href=\"\$1\" title=\"\$1\" {$target} >'. ((strlen('\$1')>={$linkMaxLen} ? substr('\$1',0,{$linkMaxLen}).'...':'\$1')).'</a>'", $status); // convert @ to follow $status = preg_replace("/(@([_a-z0-9\\-]+))/i", "<a href=\"http://twitter.com/\$2\" title=\"Follow \$2\" {$target} >\$1</a>", $status); // convert # to search $status = preg_replace("/(#([_a-z0-9\\-]+))/i", "<a href=\"https://twitter.com/search?q=\$2\" title=\"Search \$1\" {$target} >\$1</a>", $status); // return the status return $status; } //convert dates to readable format function relative_time($a) { //get current timestampt $b = strtotime("now"); //get timestamp when tweet created $c = strtotime($a); //get difference $d = $b - $c; //calculate different time values $minute = 60; $hour = $minute * 60; $day = $hour * 24; $week = $day * 7; if (is_numeric($d) && $d > 0) { //if less then 3 seconds if ($d < 3) { return "right now"; } //if less then minute if ($d < $minute) { return floor($d) . " seconds ago"; } //if less then 2 minutes if ($d < $minute * 2) { return "about 1 minute ago"; } //if less then hour if ($d < $hour) { return floor($d / $minute) . " minutes ago"; } //if less then 2 hours if ($d < $hour * 2) { return "about 1 hour ago"; } //if less then day if ($d < $day) { return floor($d / $hour) . " hours ago"; } //if more then day, but less then 2 days if ($d > $day && $d < $day * 2) { return "yesterday"; } //if less then year if ($d < $day * 365) { return floor($d / $day) . " days ago"; } //else return more than a year return "over a year ago"; } } //print tweets $tp_twitter_plugin_tweets = maybe_unserialize(get_transient('twitter-bar-tweets')); if (!empty($tp_twitter_plugin_tweets)) { $fctr = '1'; foreach ($tp_twitter_plugin_tweets as $tweet) { print '<li><span>' . convert_links($tweet['text']) . '</span><a class="created radius label blue" target="_blank" href="http://twitter.com/' . $username . '/statuses/' . $tweet['status_id'] . '">' . relative_time($tweet['created_at']) . '</a></li>'; if ($fctr == $notweets) { break; } $fctr++; } } }
public function widget($args, $instance) { extract($args); if (!empty($instance['title'])) { $title = apply_filters('widget_title', $instance['title']); } echo $before_widget; if (!empty($title)) { echo $before_title . $title . $after_title; } //check settings and die if not set if (empty($instance['consumerkey']) || empty($instance['consumersecret']) || empty($instance['accesstoken']) || empty($instance['accesstokensecret']) || empty($instance['cachetime']) || empty($instance['username'])) { echo '<strong>Please fill all widget settings!</strong>' . $after_widget; return; } //check if cache needs update $tp_twitter_plugin_last_cache_time = get_option('tp_twitter_plugin_last_cache_time'); $diff = time() - $tp_twitter_plugin_last_cache_time; $crt = $instance['cachetime'] * 3600; // yes, it needs update if ($diff >= $crt || empty($tp_twitter_plugin_last_cache_time)) { if (!class_exists('TwitterOAuth')) { if (!(require_once TEMPLATEPATH . '/widgets/twitter/twitteroauth.php')) { echo '<strong>Couldn\'t find twitteroauth.php!</strong>' . $after_widget; return; } } function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) { $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret); return $connection; } $connection = getConnectionWithAccessToken($instance['consumerkey'], $instance['consumersecret'], $instance['accesstoken'], $instance['accesstokensecret']); $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $instance['username'] . "&count=10") or die('Couldn\'t retrieve tweets! Wrong username?'); if (!empty($tweets->errors)) { if ($tweets->errors[0]->message == 'Invalid or expired token') { echo '<strong>' . $tweets->errors[0]->message . '!</strong><br />You\'ll need to regenerate it <a href="https://dev.twitter.com/apps" target="_blank">here</a>!' . $after_widget; } else { echo '<strong>' . $tweets->errors[0]->message . '</strong>' . $after_widget; } return; } for ($i = 0; $i <= count($tweets); $i++) { if (!empty($tweets[$i])) { $tweets_array[$i]['created_at'] = $tweets[$i]->created_at; $tweets_array[$i]['text'] = $tweets[$i]->text; $tweets_array[$i]['status_id'] = $tweets[$i]->id_str; } } //save tweets to wp option update_option('tp_twitter_plugin_tweets', serialize($tweets_array)); update_option('tp_twitter_plugin_last_cache_time', time()); echo '<!-- twitter cache has been updated! -->'; } //convert links to clickable format function convert_links($status, $targetBlank = true, $linkMaxLen = 250) { // the target $target = $targetBlank ? " target=\"_blank\" " : ""; // convert link to url $status = preg_replace("/((http:\\/\\/|https:\\/\\/)[^ )\n]+)/e", "'<a href=\"\$1\" title=\"\$1\" {$target} >'. ((strlen('\$1')>={$linkMaxLen} ? substr('\$1',0,{$linkMaxLen}).'...':'\$1')).'</a>'", $status); // convert @ to follow $status = preg_replace("/(@([_a-z0-9\\-]+))/i", "<a href=\"http://twitter.com/\$2\" title=\"Follow \$2\" {$target} >\$1</a>", $status); // convert # to search $status = preg_replace("/(#([_a-z0-9\\-]+))/i", "<a href=\"https://twitter.com/search?q=\$2\" title=\"Search \$1\" {$target} >\$1</a>", $status); // return the status return $status; } //convert dates to readable format function relative_time($a) { //get current timestampt $b = strtotime("now"); //get timestamp when tweet created $c = strtotime($a); //get difference $d = $b - $c; //calculate different time values $minute = 60; $hour = $minute * 60; $day = $hour * 24; $week = $day * 7; if (is_numeric($d) && $d > 0) { //if less then 3 seconds if ($d < 3) { return "right now"; } //if less then minute if ($d < $minute) { return floor($d) . " seconds ago"; } //if less then 2 minutes if ($d < $minute * 2) { return "about 1 minute ago"; } //if less then hour if ($d < $hour) { return floor($d / $minute) . " minutes ago"; } //if less then 2 hours if ($d < $hour * 2) { return "about 1 hour ago"; } //if less then day if ($d < $day) { return floor($d / $hour) . " hours ago"; } //if more then day, but less then 2 days if ($d > $day && $d < $day * 2) { return "yesterday"; } //if less then year if ($d < $day * 365) { return floor($d / $day) . " days ago"; } //else return more than a year return "over a year ago"; } } $tp_twitter_plugin_tweets = maybe_unserialize(get_option('tp_twitter_plugin_tweets')); if (!empty($tp_twitter_plugin_tweets)) { //print '<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="http://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>'; print '<script>jQuery(window).load(function () { jQuery.getScript(\'http://platform.twitter.com/widgets.js\'); });</script>'; print '<div class="twitter-feed">'; print '<div class="tweets" id="twitterFeed">'; $fctr = '1'; if (is_array($tp_twitter_plugin_tweets)) { foreach ($tp_twitter_plugin_tweets as $tweet) { print '<div><a class="twTime" target="_blank" href="http://twitter.com/' . $instance['username'] . '/statuses/' . $tweet['status_id'] . '"><span>' . relative_time($tweet['created_at']) . '</span></a>' . convert_links($tweet['text']) . '</div>'; if ($fctr == $instance['tweetstoshow']) { break; } $fctr++; } } print '</div>'; print '<a href="https://twitter.com/' . $instance['username'] . '" class="twitter-follow-button" data-show-count="false">Follow @' . $instance['username'] . '</a>'; print '</div><!-- end twitter-feed -->'; // print ' // <div class="tp_recent_tweets"> // <ul>'; // $fctr = '1'; // foreach($tp_twitter_plugin_tweets as $tweet){ // print '<li><span>'.convert_links($tweet['text']).'</span><br /><a class="twitter_time" target="_blank" href="http://twitter.com/'.$instance['username'].'/statuses/'.$tweet['status_id'].'">'.relative_time($tweet['created_at']).'</a></li>'; // if($fctr == $instance['tweetstoshow']){ break; } // $fctr++; // } // print ' // </ul> // </div>'; } echo $after_widget; }
<?php if (isset($_POST['msg']) && $_POST['msg'] != '') { require_once 'config.php'; require_once 'functions.php'; $message = strip_tags(trim($_POST['msg'])); //get hashtag from message $hashtag = gethashtags($message); //insert into database $query = mysql_query("INSERT INTO `messages` (`message`, `hashtag`) VALUES ('{$message}', '{$hashtag}')") or die(mysql_error()); $ins_id = mysql_insert_id(); ?> <div class="msg_body" id="<?php echo $ins_id; ?> "> <div class="msg_img"><img src="http://0.gravatar.com/avatar/82620dd66b22b34a915303b93b92929b" /></div> <div class="msg_text"> <?php echo convert_links($message); ?> <div class="time">5 seconds ago</div> </div> </div> <?php mysql_close(); }
function shortcode_jw_twitter_carousel($atts, $content) { $jw_twitter_tweets = twitter_build($atts); if (is_array($jw_twitter_tweets)) { $arrow = '<div class="carousel-arrow jw-carrow">'; $arrow .= '<a class="carousel-prev" href="#"><i class="icon-angle-left"></i></a>'; $arrow .= '<a class="carousel-next" href="#"><i class="icon-angle-right"></i></a>'; $arrow .= '</div>'; $output = '<div class="jw-twitter">'; $output .= '<div class="carousel-container">'; $output .= '<div class="jw-carousel-twitter list_carousel">'; $output .= '<i class="icon-twitter"></i>'; $output .= '<ul class="jtwt jw-carousel">'; $fctr = '1'; foreach ($jw_twitter_tweets as $tweet) { $output .= '<li><span>' . convert_links($tweet['text']) . '</span><br />- <a class="twitter_time" target="_blank" href="http://twitter.com/' . $atts['username'] . '/statuses/' . $tweet['status_id'] . '">' . relative_time($tweet['created_at']) . '</a></li>'; if ($fctr == $atts['tweetstoshow']) { break; } $fctr++; } $output .= '</ul>'; $output .= '<div class="twitter-follow">' . (jw_option('jw_car_follow') ? jw_option('jw_car_follow') : __('Follow Us', 'designinvento')) . ' - <a target="_blank" href="http://twitter.com/' . $atts['username'] . '">@' . $atts['username'] . '</a></div>'; $output .= $arrow; $output .= '</div>'; $output .= '</div>'; $output .= '</div>'; return $output; } else { return $jw_twitter_tweets; } }
/** * Icons Shortcode */ function mtheme_latest_tweets($atts, $content = null) { extract(shortcode_atts(array('username' => 'twitter', 'cache_id' => '1', 'count' => '1'), $atts)); $cache_combo = $cache_id . $username . $count; //check if cache needs update $mtheme_shortcode_last_cache_time = get_option('mtheme_shortcode_last_cache_time_' . $cache_combo); $diff = time() - $mtheme_shortcode_last_cache_time; $crt = 24 * 3600; // yes, it needs update if ($diff >= $crt || empty($mtheme_shortcode_last_cache_time)) { // Setting our Authentication Variables that we got after creating an application $settings = array('oauth_access_token' => "30495696-kAHw8UpFZgh78pQIKHdipr3UcZGkZfj043ZGIKUrb", 'oauth_access_token_secret' => "eQlT9pstlIfO4Brqwr9jjTMNbN9LafGT4pUIC36mAs", 'consumer_key' => "PGqIcUVjeWRpoaNx363Qw", 'consumer_secret' => "ooDTnNeXRC8fTyMDwqPZN9UZwsRYLQm1I4ftgIEz8"); // We are using GET Method to Fetch the latest tweets. $url = 'https://api.twitter.com/1.1/statuses/user_timeline.json'; // Set your screen_name to your twitter screen name. Also set the count to the number of tweets you want to be fetched. Here we are fetching 5 latest tweets. $getfield = '?screen_name=' . $username . '&count=' . $count; $requestMethod = 'GET'; // Making an object to access our library class $twitter = new TwitterAPIExchange($settings); $store = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest(); // Since the returned result is in json format, we need to decode it $result = json_decode($store); for ($i = 0; $i <= count($result); $i++) { if (!empty($result[$i])) { $tweets_array[$i]['profile_image_url'] = $result[$i]->user->profile_image_url; $tweets_array[$i]['created_at'] = $result[$i]->created_at; $tweets_array[$i]['text'] = $result[$i]->text; $tweets_array[$i]['status_id'] = $result[$i]->id_str; } } //print_r($tweets_array); update_option('mtheme_shortcode_tweets_' . $cache_combo, serialize($tweets_array)); update_option('mtheme_shortcode_last_cache_time_' . $cache_combo, time()); } //convert links to clickable format function convert_links($status, $targetBlank = true, $linkMaxLen = 250) { // the target $target = $targetBlank ? " target=\"_blank\" " : ""; // convert link to url $status = preg_replace("/((http:\\/\\/|https:\\/\\/)[^ )\n]+)/e", "'<a href=\"\$1\" title=\"\$1\" {$target} >'. ((strlen('\$1')>={$linkMaxLen} ? substr('\$1',0,{$linkMaxLen}).'...':'\$1')).'</a>'", $status); // convert @ to follow $status = preg_replace("/(@([_a-z0-9\\-]+))/i", "<a href=\"http://twitter.com/\$2\" title=\"Follow \$2\" {$target} >\$1</a>", $status); // convert # to search $status = preg_replace("/(#([_a-z0-9\\-]+))/i", "<a href=\"https://twitter.com/search?q=\$2\" title=\"Search \$1\" {$target} >\$1</a>", $status); // return the status return $status; } //convert dates to readable format function relative_time($a) { //get current timestampt $b = strtotime("now"); //get timestamp when tweet created $c = strtotime($a); //get difference $d = $b - $c; //calculate different time values $minute = 60; $hour = $minute * 60; $day = $hour * 24; $week = $day * 7; if (is_numeric($d) && $d > 0) { //if less then 3 seconds if ($d < 3) { return "right now"; } //if less then minute if ($d < $minute) { return floor($d) . " seconds ago"; } //if less then 2 minutes if ($d < $minute * 2) { return "about 1 minute ago"; } //if less then hour if ($d < $hour) { return floor($d / $minute) . " minutes ago"; } //if less then 2 hours if ($d < $hour * 2) { return "about 1 hour ago"; } //if less then day if ($d < $day) { return floor($d / $hour) . " hours ago"; } //if more then day, but less then 2 days if ($d > $day && $d < $day * 2) { return "yesterday"; } //if less then year if ($d < $day * 365) { return floor($d / $day) . " days ago"; } //else return more than a year return "over a year ago"; } } $mtheme_shortcode_tweets = maybe_unserialize(get_option('mtheme_shortcode_tweets_' . $cache_combo)); if (!empty($mtheme_shortcode_tweets)) { //print_r($tp_twitter_plugin_tweets); $tweet_shortcode = '<div class="entry-content mtheme-tweets-shortcode">'; $tweet_shortcode .= '<ul class="tweet_list">'; $fctr = '1'; foreach ($mtheme_shortcode_tweets as $tweet) { $tweet_shortcode .= '<li>'; $tweet_shortcode .= '<span class="tweet_avatar"><i class="icon-twitter icon-2x"></i></span>'; $tweet_shortcode .= '<span class="tweet_time">'; $tweet_shortcode .= '<a class="twitter_time" target="_blank" href="http://twitter.com/' . $username . '/statuses/' . $tweet['status_id'] . '">' . relative_time($tweet['created_at']) . '</a>'; $tweet_shortcode .= '</span>'; $tweet_shortcode .= '<span class="tweet_text">' . convert_links($tweet['text']) . '</span>'; $tweet_shortcode .= '</li>'; if (isset($instance['tweetstoshow'])) { if ($fctr == $instance['tweetstoshow']) { break; } } $fctr++; } $tweet_shortcode .= '</ul>'; $tweet_shortcode .= '</div>'; } return $tweet_shortcode; }
$accesstoken = "1166043541-Y6De2NsoBToaMwUDWGhMXrwe2EZdpM9AqMaiDw1"; $accesstokensecret = "qDMHE24IIlMTu7VmB51kSJv6SxfUwhCk5oApP78"; } } function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) { $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret); return $connection; } function convert_links($status, $targetBlank = true, $linkMaxLen = 250) { // the target $target = $targetBlank ? " target=\"_blank\" " : ""; // convert link to url $status = preg_replace("/((http:\\/\\/|https:\\/\\/)[^ )\n\t]+)/e", "'<a class=\"met_color\" href=\"\$1\" title=\"\$1\" {$target} >'. ((strlen('\$1')>={$linkMaxLen} ? substr('\$1',0,{$linkMaxLen}).'...':'\$1')).'</a>'", $status); // convert @ to follow $status = preg_replace("/(@([_a-z0-9\\-]+))/i", "<a class=\"met_color\" href=\"http://twitter.com/\$2\" title=\"Follow \$2\" {$target} >\$1</a>", $status); // convert # to search $status = preg_replace("/(#([_a-z0-9\\-]+))/i", "<a class=\"met_color\" href=\"https://twitter.com/search?q=\$2\" title=\"Search \$1\" {$target} >\$1</a>", $status); // return the status return $status; } $connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret); $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $twitteruser . "&count=" . $notweets); $tweets = json_encode($tweets); $tweets = json_decode($tweets, true); $tweets[0]["screen_name"] = $twitteruser; for ($i = 0; $i <= count($tweets) - 1; $i++) { $tweets[$i]["text"] = convert_links($tweets[$i]["text"]); } echo json_encode($tweets);