Exemplo n.º 1
0
function getNewsObjects()
{
    //CACHING ENABLED: The server will only fetch news again if the cache has expired. Set expiry values in caching.php
    /*************** CACHE **************/
    $newsCacheName = 'newscache';
    $responsejson = null;
    $cacheExpired = is_null(checkCache($newsCacheName));
    $noCache = !is_null($_GET["nocache"]);
    ////////////////////////
    if ($cacheExpired || $noCache) {
        $uri = "http://api.nytimes.com/svc/news/v3/content/all/all.json?api-key={$newsapikey}";
        $rawresponsejson = \Httpful\Request::get($uri)->send();
        $responsejson = $rawresponsejson . raw_body;
        setCacheVal($newsCacheName, $responsejson);
        if ($debug) {
            echo "Fetched.";
        }
    } else {
        if ($debug) {
            echo "From cache.";
        }
        $responsejson = getCacheVal($newsCacheName);
    }
    return parseArticleObjectsFromJson($responsejson);
}
Exemplo n.º 2
0
		});
		</script>
		<div id="news">
			<?php 
//CACHING ENABLED: The server will only fetch news again if the cache has expired. Set expiry values in caching.php
/*************** CACHE **************/
$newsCacheName = 'newscache';
$responsejson = null;
$cacheExpired = is_null(checkCache($newsCacheName));
$noCache = !is_null($_GET["nocache"]);
////////////////////////
if ($cacheExpired || $noCache) {
    $uri = "http://api.nytimes.com/svc/news/v3/content/all/all.json?api-key={$newsapikey}";
    $rawresponsejson = \Httpful\Request::get($uri)->send();
    $responsejson = $rawresponsejson . raw_body;
    setCacheVal($newsCacheName, $responsejson);
    if ($debug) {
        echo "Fetched.";
    }
} else {
    if ($debug) {
        echo "From cache.";
    }
    $responsejson = getCacheVal($newsCacheName);
}
echo printArticleObjects(parseArticleObjectsFromJson($responsejson));
?>
		</div>

	</body>
</html>