function get($count = 20) { $username = $this->username; // Append the count $url = $this->feedUrl; $url .= '&count=' . $count; $tweets_cache_path = THEMEUPLOAD . '/twitter_' . $username . '_' . $count . '.cache'; if (file_exists($tweets_cache_path)) { $tweets_cache_timer = intval((time() - filemtime($tweets_cache_path)) / 60); } else { $tweets_cache_timer = 0; } if (!file_exists($tweets_cache_path) or $tweets_cache_timer > 15) { $connection = getConnectionWithAccessToken($this->consumer_key, $this->consumer_secret, $this->access_token, $this->access_token_secret); $tweets = $connection->get($url); 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>!'; } else { echo '<strong>' . $tweets->errors[0]->message . '</strong>'; } return; } $tweets_data = array(); foreach ($tweets as $tweet) { $tweet_text = auto_link_twitter($tweet->text); $tweets_data[]['text'] = $tweet_text; } if (file_exists($tweets_cache_path)) { unlink($tweets_cache_path); } $myFile = $tweets_cache_path; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = serialize($tweets_data); fwrite($fh, $stringData); fclose($fh); } else { $file = file_get_contents($tweets_cache_path, true); if (!empty($file)) { $tweets = unserialize($file); foreach ($tweets as $tweet) { $tweets_data[]['text'] = $tweet['text']; } } } return $tweets_data; }
function get($count = 20) { $username = $this->username; // Append the count $url = $this->feedUrl; $url .= '&count=' . $count; $tweets_cache_path = get_template_directory() . '/cache/twitter_' . $username . '_' . $count . '.cache'; if (file_exists($tweets_cache_path)) { $tweets_cache_timer = intval((time() - filemtime($tweets_cache_path)) / 60); } else { $tweets_cache_timer = 0; } if (!file_exists($tweets_cache_path) or $tweets_cache_timer > 15) { $connection = getConnectionWithAccessToken($this->consumer_key, $this->consumer_secret, $this->access_token, $this->access_token_secret); $tweets = $connection->get($url); 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(); foreach ($tweets as $tweet) { $tweets_data[]['text'] = $tweet->text; } if (file_exists($tweets_cache_path)) { unlink($tweets_cache_path); } $myFile = $tweets_cache_path; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = serialize($tweets_data); fwrite($fh, $stringData); fclose($fh); //clear data $tweets_data = array(); } error_reporting(0); $file = file_get_contents($tweets_cache_path, true); if (!empty($file)) { $tweets = unserialize($file); // Some reformatting $pattern = array('/[^(:\\/\\/)](www\\.[^ \\n\\r]+)/', '/(https?:\\/\\/[^ \\n\\r]+)/'); $replace = array('<a href="http://$1" rel="nofollow">$1</a>', '<a href="$1" rel="nofollow">$1</a>'); foreach ($tweets as $tweet) { $formatted_tweet = preg_replace($pattern, $replace, $tweet['text']); $formatted_tweet = auto_link_twitter($formatted_tweet); $tweets_data[]['text'] = $formatted_tweet; } } return $tweets_data; }