1) { $page = $_GET['page']; $thisUrl = $_SERVER['REQUEST_URI']; $thisUrl = preg_replace('/page=\d+/','page=' . ($page - 1), $thisUrl, 1, $count); if ($count == 0) { if (strpos($thisUrl, '?') > 0) { $thisUrl .= '&page=' . ($page - 1); } else { $thisUrl .= '?page=' . ($page - 1); } } return $thisUrl; } else { return null; } } function getOlderUrl() { $page = 1; if (array_key_exists('page', $_GET) && $_GET['page'] > 1) { $page = $_GET['page']; } $thisUrl = $_SERVER['REQUEST_URI']; $thisUrl = preg_replace('/page=\d+/','page=' . ($page + 1), $thisUrl, 1, $count); if ($count == 0) { if (strpos($thisUrl, '?') > 0) { $thisUrl .= '&page=' . ($page + 1); } else { $thisUrl .= '?page=' . ($page + 1); } } return $thisUrl; } function getFeedFromQuery() { global $resultsPerPage; if (array_key_exists('search', $_GET)) { $twitterSearchValue = $_GET['search']; } else { $twitterSearchValue = 'npr'; } if ($twitterSearchValue == 'All Things Considered') { $twitterSearchValue = '"' . $twitterSearchValue . '" OR ATC'; } if ($twitterSearchValue == 'Wait Wait...Don\'t Tell Me!') { $twitterSearchValue = '"' . $twitterSearchValue . '" OR WWDTM'; } if ($twitterSearchValue == 'Talk of the Nation') { $twitterSearchValue = '"' . $twitterSearchValue . '" OR TOTN'; } if ($twitterSearchValue == 'Weekend Edition Saturday') { $twitterSearchValue = '"' . $twitterSearchValue . '" OR WESAT'; } if ($twitterSearchValue == 'Weekend Edition Sunday') { $twitterSearchValue = '"' . $twitterSearchValue . '" OR WESUN'; } if ($twitterSearchValue == 'Tell Me More') { $twitterSearchValue = '"' . $twitterSearchValue . '" NPR'; } $page = 1; if (array_key_exists('page', $_GET) && $_GET['page'] > 1) { $page = $_GET['page']; } $feed = 'http://search.twitter.com/search.json?q=+' . urlencode($twitterSearchValue) . '&rpp=' . $resultsPerPage . '&page=' . $page; return $feed; } function printResult($item, $index) { // add links $content = preg_replace('/(http:\S+)\b/', '$1', $item->text); $content = preg_replace('/(@(\S+))\b/', '$1', $content); print '
#' . $index . '';
print ': ';
print '' . html_entity_decode($content) . '';
$twitterDate = strtotime($item->created_at);
print('
');
if (date('ymd') == date('ymd', $twitterDate))
{
print 'Today at ' . date('g:i:s a', $twitterDate) . '';
}
else
{
print '' . date('F jS, Y', $twitterDate) . ' at ' . date('g:i:s a', $twitterDate) . '';
}
print '
' . print_r($twitterResults, true) . ''; //return; $page = 1; if (array_key_exists('page', $_GET) && $_GET['page'] > 1) { $page = $_GET['page']; } $index = (($page - 1) * $resultsPerPage) + 1; foreach ($twitterResults->results as $item) { printResult($item, $index++); preg_match('/http:\S+\b/', $item->text, $matches); if (count($matches) > 0) { $twitterUrl = $matches[0]; $headers = curl_get_headers($twitterUrl); if ($headers != null) { foreach ($headers as $headerElm) { if (preg_match('/^Location: (.*)$/i', $headerElm, $headerMatches)) { $realUrl = urldecode($headerMatches[1]); error_log($realUrl); if (preg_match('/storyId=(\d+)/', $realUrl, $nprMatches)) { $storyId = $nprMatches[1]; $apiUrl = 'http://api.npr.org/query?id=' . $storyId . '&output=HTML&apiKey=' . $apiKey; print(curl_file_get_contents($apiUrl)); } if (preg_match('/prgId=(\d+)/', $realUrl, $nprMatches)) { $prgId = $nprMatches[1]; $apiUrl = 'http://api.npr.org/query?id=' . $prgId . '&output=HTML&apiKey=' . $apiKey; print(curl_file_get_contents($apiUrl)); } } } } } print '