Skip to content

Instantly share code, notes, and snippets.

@fleeting
Created February 3, 2010 15:36
Show Gist options
  • Save fleeting/293688 to your computer and use it in GitHub Desktop.
Save fleeting/293688 to your computer and use it in GitHub Desktop.
<?php
//The following code was submitted by Tycho Lyben for inclusion in WP-TwitterSearch. Has not been tested yet.
$path = CACHE_PATH."/".md5("'phrase'=>$phrase,'from'=>$from,'rpp'=>$rpp,'lang'=>$lang,'nots'=>$nots");
if (file_exists($path) && filectime($path)>time()-1800) { // cache for 30 min
$x = unserialize(file_get_contents($path));
echo $x;
exit;
}
// Search Twitter API Request
$response = $twitter->searchAPI('ATOM');
$feed = $response->search($q,array('phrase'=>$phrase,'from'=>$from,'rpp'=>$rpp,'lang'=>$lang,'nots'=>$nots));
if (!file_exists($path)) @mkdir($path);
if (file_exists($path) && !@trim($feed->getData())) {
$x = unserialize(file_get_contents($path));
echo $x;
} else if (!@trim($feed->getData())) {
echo $feed;
} else {
file_put_contents($path, serialize($feed));
echo $feed;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment