strtotime('-15 minutes')) { $content = json_decode(file_get_contents($cacheFile)); } else { $content = $cb->statuses_userTimeline([ 'screen_name' => $user, 'count' => 200, 'exclude_replies' => TRUE ], TRUE); if (isset($content->rate)) { unset($content->rate); } file_put_contents($cacheFile, json_encode($content)); $cacheTime = time(); } if ($content->httpstatus !== 200) { header('HTTP/1.1 '.$content->httpstatus); if (isset($content->error)) { print $content->error; die(); } if (isset($content->errors)) { foreach ($content->errors as $error) { print $error->message.' ('.$error->code.')
'; } die(); } } unset($content->httpstatus); if ($spamFilter) { $db = new PDO('sqlite:../spamlinks.db'); $spamQuery = $db->prepare('SELECT id FROM spamlinks WHERE username = :name'); $spamQuery->bindParam(':name', $user); $spamQuery->execute(); $spamContent = array_map( function($row) { return $row[0]; }, $spamQuery->fetchAll() ); $spamHashes = []; $filteredContent = []; foreach ($content as $c) { if (!in_array($c->id_str, $spamContent)) { $urls = array_map( function($url) { return $url->expanded_url; }, $c->entities->urls ); if (!$urls) { $filteredContent[] = $c; } else { sort($urls); $urlHash = md5(implode('|', $urls)); if (isset($filteredContent[$urlHash])) { $spamHashes[] = $c->id_str; } $filteredContent[$urlHash] = $c; } } } usort($filteredContent, function($c1, $c2) { return strcmp($c1->id_str, $c2->id_str); }); $content = $filteredContent; if ($spamHashes) { foreach ($spamHashes as $hash) { $insertQuery = $db->prepare( 'INSERT INTO spamlinks(id, username) VALUES (?, ?)' ); $insertQuery->bindParam(1, $hash); $insertQuery->bindParam(2, $user); $insertQuery->execute(); } } } require_once('../lib/smarty3/Smarty.class.php'); $smarty = new Smarty(); $smarty->setCacheDir('../cache/smarty'); $smarty->setCompileDir('../cache/smarty/compile'); $smarty->setTemplateDir('../templates'); $smarty->assign('cacheTime', $cacheTime); $smarty->assign('user', $user); $smarty->assign('content', $content); $format = $_GET['format']; switch ($format) { case 'rss': header('Content-Type: application/rss+xml'); $smarty->display('rss.tpl'); break; case 'atom': default: header('Content-Type: application/atom+xml'); $smarty->display('atom.tpl'); break; } } ?>