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 retrieveWSDL($wsdl) { $parts = parse_url($wsdl); if (!isset($parts['scheme'], $parts['host'])) { return $wsdl; } //use the md5 of the baseURL as the folder $baseURL = $this->buildURL($parts); $cacheFolder = CACHE_DIR . '/WSDL/' . md5($baseURL); //save the filename as is $cacheFile = basename($this->buildURL($parts, true)); if (!($wsdl_cache = ini_get('soap.wsdl_cache_ttl'))) { $wsdl_cache = 86400; // one day } $cache = new DiskCache($cacheFolder, $wsdl_cache, true); $cache->preserveFormat(); //make sure we save the raw data if ($cache->isFresh($cacheFile)) { $wsdl_data = $cache->read($cacheFile); } else { $ch = curl_init($wsdl); foreach ($this->initArgs as $key => $value) { if (preg_match("/CURLOPT_/", $key)) { curl_setopt($ch, constant($key), $value); } } if ($this->authUser) { curl_setopt($ch, CURLOPT_HTTPAUTH, constant('CURLAUTH_' . strtoupper($this->authType))); curl_setopt($ch, CURLOPT_USERPWD, $this->authUser . ':' . $this->authPassword); } curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); if (!($wsdl_data = curl_exec($ch))) { if (!($error = curl_error($ch))) { $error = "Unable to retrieve WSDL {$wsdl}"; } Kurogo::log(LOG_WARNING, "Unable to retrieve WSDL {$wsdl}: {$error}", 'soap'); throw new KurogoException($error); } //save the WSDL to cache $cache->write($wsdl_data, $cacheFile); curl_close($ch); } /* retrieve the imports */ $parsedWSDL = $this->parseWSDL($wsdl_data); foreach ($parsedWSDL->getImports() as $import) { $url = $baseURL . $import; $this->retrieveWSDL($url); } // use the local cached WSDL file $wsdl = $cache->getFullPath($cacheFile); return $wsdl; }
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; }