<?php include_once 'config.php'; include_once 'caching.php'; include_once './httpful.phar'; include_once 'newsparser.php'; header('Content-Type: text/html; charset=utf-8'); getNewsObjects(); 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); }
<?php include_once "news.php"; include_once "location.php"; header("content-type: application/x-javascript; charset=utf-8"); //Generate markers based on news tag $newsObjects = getNewsObjects(); $customMarkers = ''; $results = $newsObjects; $resultsnum = sizeof($results); for ($i = 0; $i <= $resultsnum; $i++) { $caption = $results[$i]['caption']; $abstract = $results[$i]['abstract']; $originalURL = $results[$i]['url']; $geoFacet = $results[$i]['geo_facet']; $locationStr = ""; $determinateLocation = false; $lat = -1; $lng = -1; if ($geoFacet != "") { $determinateLocation = true; $locationStr = $geoFacet[0]; //Assign to first location tag //Get coords from GMaps $latlng = parseLatLngStrJsonForCoordinates(getLatLngJson($locationStr)); $lat = $latlng['lat']; $lng = $latlng['lng']; } $title = $results[$i]['title']; $currentResultMarker = <<<EOT var marker=new google.maps.Marker({