function et_get_tweets($consumer_key = 'Ev0u7mXhBvvVaLOfPg2Fg', $consumer_secret = 'SPdZaKNIeBlUo99SMAINojSJRHr4EQXPSkR0Dw97o', $user_token = '435115014-LVrLsvzVAmQWjLw1r8KjNy93QiXHWKH09kcIQCKh', $user_secret = 'eTxZP8jQfB7DjKAAoJx1AFsTd3wPfImNaqau6HIVw', $user = '******', $count = 10) { if (etheme_twitter_cache_enabled()) { //setting the location to cache file $cachefile = ETHEME_CODE_DIR . '/cache/twitterSliderCache.json'; $cachetime = 50; // the file exitsts but is outdated, update the cache file if (file_exists($cachefile) && time() - $cachetime > filemtime($cachefile) && filesize($cachefile) > 0) { //capturing fresh tweets $tweets = etheme_capture_tweets($consumer_key, $consumer_secret, $user_token, $user_secret, $user, $count); $tweets_decoded = json_decode($tweets, true); //if get error while loading fresh tweets - load outdated file if (isset($tweets_decoded['error'])) { $tweets = etheme_pick_tweets($cachefile); } else { etheme_store_tweets($cachefile, $tweets); } } elseif (!file_exists($cachefile) || filesize($cachefile) == 0) { $tweets = etheme_capture_tweets($consumer_key, $consumer_secret, $user_token, $user_secret, $user, $count); $tweets_decoded = json_decode($tweets, true); //if request fails, and there is no old cache file - print error if (isset($tweets_decoded['error'])) { return 'Error: ' . $tweets_decoded['error']; } else { etheme_store_tweets($cachefile, $tweets); } } else { $tweets = etheme_pick_tweets($cachefile); } } else { $tweets = etheme_capture_tweets($consumer_key, $consumer_secret, $user_token, $user_secret, $user, $count); } $tweets = json_decode($tweets, true); return $tweets; }
function etheme_print_tweets($consumer_key, $consumer_secret, $user_token, $user_secret, $user, $count, $cachetime = 50) { if (etheme_twitter_cache_enabled()) { //setting the location to cache file $cachefile = ETHEME_CODE_DIR . '/cache/twitterCache.json'; // the file exitsts but is outdated, update the cache file if (file_exists($cachefile) && time() - $cachetime > filemtime($cachefile) && filesize($cachefile) > 0) { //capturing fresh tweets $tweets = etheme_capture_tweets($consumer_key, $consumer_secret, $user_token, $user_secret, $user, $count); $tweets_decoded = json_decode($tweets, true); //if get error while loading fresh tweets - load outdated file if (isset($tweets_decoded['error'])) { $tweets = etheme_pick_tweets($cachefile); } else { etheme_store_tweets($cachefile, $tweets); } } elseif (!file_exists($cachefile) || filesize($cachefile) == 0) { $tweets = etheme_capture_tweets($consumer_key, $consumer_secret, $user_token, $user_secret, $user, $count); $tweets_decoded = json_decode($tweets, true); //if request fails, and there is no old cache file - print error if (isset($tweets_decoded['error'])) { return 'Error: ' . $tweets_decoded['error']; } else { etheme_store_tweets($cachefile, $tweets); } } else { $tweets = etheme_pick_tweets($cachefile); } } else { $tweets = etheme_capture_tweets($consumer_key, $consumer_secret, $user_token, $user_secret, $user, $count); } $tweets = json_decode($tweets, true); $html = '<ul class="twitter-list">'; foreach ($tweets as $tweet) { $html .= '<li class="lastItem firstItem"><div class="media"><i class="pull-left fa fa-twitter"></i><div class="media-body">' . $tweet['text'] . '</div></div></li>'; } $html .= '</ul>'; $html = etheme_tweet_linkify($html); return $html; }