protected function calendarQuery($url, $parameters, $headers=null, $unique=true) { if (!$this->user instanceOf GoogleAppsUser) { return array(); } $cache = new DiskCache(CACHE_DIR . "/" . 'GoogleCalendar', $this->cacheLifetime, TRUE); $cache->setSuffix('.json'); $cache->preserveFormat(); $cacheURL = $url . count($parameters) ? '?' . http_build_query($parameters) : $url; $cacheFilename = $unique ? md5($cacheURL. $this->user->getEmail()) : md5($cacheURL); if ($cache->isFresh($cacheFilename)) { $data = $cache->read($cacheFilename); } else { $authority = $this->user->getAuthenticationAuthority(); $method = 'GET'; if ($data = $authority->oAuthRequest($method, $url, $parameters, $headers)) { $cache->write($data, $cacheFilename); } } return $data; }
protected function calendarQuery($url, $parameters, $headers = null, $unique = true) { $oauth = $this->oauth(); if (!($token = $oauth->getToken())) { return false; } $cache = new DiskCache(CACHE_DIR . '/GoogleCalendar' . ($unique ? '/' . md5($token) : ''), $this->cacheLifetime, TRUE); $cache->setSuffix('.cache'); $cache->preserveFormat(); $cacheURL = count($parameters) ? $url . '?' . http_build_query($parameters) : $url; $cacheFilename = md5($cacheURL); if ($cache->isFresh($cacheFilename)) { $response = unserialize($cache->read($cacheFilename)); $data = $response->getResponse(); } else { $oauth = $this->oauth(); $method = 'GET'; if ($data = $oauth->oAuthRequest($method, $url, $parameters, $headers)) { $response = $oauth->getResponse(); $cache->write(serialize($response), $cacheFilename); } } return $data; }
public static function getProjSpecs($wkid) { $contents = null; $projCache = new DiskCache(Kurogo::getSiteVar('PROJ_CACHE', 'maps'), null, true); $projCache->setSuffix('.proj4'); $projCache->preserveFormat(); $filename = $wkid; if (!$projCache->isFresh($filename)) { $file = fopen(DATA_DIR . '/maps/proj_list.txt', 'r'); $wkidID = "<{$wkid}>"; $strlen = strlen($wkidID); while ($line = fgets($file)) { if (substr($line, 0, $strlen) == $wkidID) { preg_match("/<\\d+> (.+) <>/", $line, $matches); $contents = $matches[1]; break; } } fclose($file); if ($contents) { $projCache->write($contents, $filename); } else { // TODO get config for logging Kurogo::LOG(LOG_WARNING, "{$wkid} is not a known projection", 'maps'); } } else { $contents = $projCache->read($filename); } return $contents; }
public static function getProjSpecs($wkid) { $wkid = self::convertWkid($wkid); $projCache = new DiskCache($GLOBALS['siteConfig']->getVar('PROJ_CACHE'), null, true); $projCache->setSuffix('.proj4'); $projCache->preserveFormat(); $filename = $wkid; if (!$projCache->isFresh($filename)) { $url = 'http://spatialreference.org/ref/epsg/'.$wkid.'/proj4/'; $contents = file_get_contents($url); if ($contents) $projCache->write($contents, $filename); } else { $contents = $projCache->read($filename); } return $contents; }