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; }
function getMinifyGroupsConfig() { $minifyConfig = array(); $key = $_GET['g']; // // Check for specific file request // if (strpos($key, MIN_FILE_PREFIX) === 0) { // file path relative to either templates or the theme (check theme first) $path = substr($key, strlen(MIN_FILE_PREFIX)); $config = array('include' => 'all', 'files' => array(THEME_DIR . $path, SITE_APP_DIR . $path, APP_DIR . $path)); return array($key => buildFileList($config)); } // // Page request // $pageOnly = isset($_GET['pageOnly']) && $_GET['pageOnly']; // if this is a copied module also pull in files from that module $configModule = isset($_GET['config']) ? $_GET['config'] : ''; list($ext, $module, $page, $pagetype, $platform, $pathHash) = explode('-', $key); $cache = new DiskCache(CACHE_DIR . '/minify', Kurogo::getOptionalSiteVar('MINIFY_CACHE_TIMEOUT', 30), true); $cacheName = "group_{$key}"; if ($configModule) { $cacheName .= "-{$configModule}"; } if ($pageOnly) { $cacheName .= "-pageOnly"; } if ($cache->isFresh($cacheName)) { $minifyConfig = $cache->read($cacheName); } else { $dirs = array(APP_DIR, SITE_APP_DIR, THEME_DIR); if ($pageOnly || ($pagetype == 'tablet' || $platform == 'computer') && in_array($module, array('info', 'admin'))) { // Info module does not inherit from common files $subDirs = array('/modules/' . $module); } else { $subDirs = array('/common', '/modules/' . $module); } if ($configModule) { $subDirs[] = '/modules/' . $configModule; } $checkFiles = array('css' => getCSSFileConfigForDirs($page, $pagetype, $platform, $dirs, $subDirs, $pageOnly), 'js' => getJSFileConfigForDirs($page, $pagetype, $platform, $dirs, $subDirs, $pageOnly)); //error_log(print_r($checkFiles, true)); $minifyConfig[$key] = buildFileList($checkFiles[$ext]); //error_log(__FUNCTION__."($pagetype-$platform) scanned filesystem for $key"); $cache->write($minifyConfig, $cacheName); } // Add minify source object for the theme config.ini if ($ext == 'css') { $themeVarsFile = realpath_exists(THEME_DIR . '/config.ini'); if ($themeVarsFile) { $minifyConfig[$key][] = new Minify_Source(array('id' => 'themeConfigModTimeChecker', 'getContentFunc' => 'minifyThemeConfigModTimeCheckerContent', 'minifier' => '', 'contentType' => Minify::TYPE_CSS, 'lastModified' => filemtime($themeVarsFile))); } } //error_log(__FUNCTION__."($pagetype-$platform) returning: ".print_r($minifyConfig, true)); return $minifyConfig; }
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 function exportCSSAndJavascript() { $minifyURLs = $this->getMinifyUrls(true); $cache = new DiskCache(CACHE_DIR . '/minify', Kurogo::getOptionalSiteVar('MINIFY_CACHE_TIMEOUT', 30), true); $cacheName = "export_{$this->configModule}-{$this->page}-{$this->pagetype}-{$this->platform}-" . md5($minifyURLs['js'] . $minifyURLs['css']); if ($cache->isFresh($cacheName)) { $data = $cache->read($cacheName); } else { $properties = array('inlineCSSBlocks', 'cssURLs', 'inlineJavascriptBlocks', 'inlineJavascriptFooterBlocks', 'onOrientationChangeBlocks', 'onLoadBlocks', 'javascriptURLs'); $data = array('properties' => array(), 'minifyCSS' => '', 'minifyJS' => ''); foreach ($properties as $property) { $data['properties'][$property] = $this->{$property}; } // Add page Javascript and CSS if any $context = stream_context_create(array('http' => array('user_agent' => $_SERVER['HTTP_USER_AGENT']))); $javascript = @file_get_contents(FULL_URL_PREFIX . ltrim($minifyURLs['js'], '/'), false, $context); if ($javascript) { $data['minifyJS'] = $javascript; } $css = @file_get_contents(FULL_URL_PREFIX . ltrim($minifyURLs['css'], '/'), false, $context); if ($css) { $data['minifyCSS'] = $css; } $cache->write($data, $cacheName); } return $data; }
function getMinifyGroupsConfig() { $minifyConfig = array(); $key = $_GET['g']; // // Check for specific file request // if (strpos($key, MIN_FILE_PREFIX) === 0) { // file path relative to either templates or the theme (check theme first) $path = substr($key, strlen(MIN_FILE_PREFIX)); $config = array( 'include' => 'all', 'files' => array( THEME_DIR.$path, SITE_APP_DIR.$path, APP_DIR.$path, ), ); return array($key => buildFileList($config)); } // // Page request // $pageOnly = isset($_GET['pageOnly']) && $_GET['pageOnly']; // if this is a copied module also pull in files from that module $configModule = isset($_GET['config']) ? $_GET['config'] : ''; list($ext, $module, $page, $pagetype, $platform, $pathHash) = explode('-', $key); $cache = new DiskCache(CACHE_DIR.'/minify', 30, true); $cacheName = "group_$key"; if ($cache->isFresh($cacheName)) { $minifyConfig = $cache->read($cacheName); } else { // CSS includes all in order. JS prefers theme $cssDirs = array( APP_DIR, SITE_APP_DIR, THEME_DIR, ); $jsDirs = array( THEME_DIR, SITE_APP_DIR, APP_DIR, ); if ($pageOnly || ($platform=='computer' && in_array($module, array('info', 'admin')))) { // Info module does not inherit from common files $subDirs = array( '/modules/'.$module ); } else { $subDirs = array( '/common', '/modules/'.$module, ); } if ($configModule) { $subDirs[] = '/modules/' . $configModule; } $checkFiles = array( 'css' => getCSSFileConfigForDirs( $page, $pagetype, $platform, $cssDirs, $subDirs, $pageOnly), 'js' => getJSFileConfigForDirs ( $page, $pagetype, $platform, $jsDirs, $subDirs, $pageOnly), ); //error_log(print_r($checkFiles, true)); $minifyConfig[$key] = buildFileList($checkFiles[$ext]); //error_log(__FUNCTION__."($pagetype-$platform) scanned filesystem for $key"); $cache->write($minifyConfig, $cacheName); } //error_log(__FUNCTION__."($pagetype-$platform) returning: ".print_r($minifyConfig, true)); return $minifyConfig; }
protected function detectDeviceExternal($user_agent) { if (!$user_agent) { return; } // see if the server has cached the results from the the device detection server $cache = new DiskCache($this->cacheFolder(), $this->cacheLifetime(), TRUE); $cacheFilename = md5($user_agent); if ($cache->isFresh($cacheFilename)) { $json = $cache->read($cacheFilename); Kurogo::log(LOG_INFO, "Using cached data for external device detection", 'deviceDetection'); } else { $query = http_build_query(array('user-agent' => $user_agent, 'version' => $this->version)); $url = Kurogo::getSiteVar('MOBI_SERVICE_URL') . '?' . $query; Kurogo::log(LOG_INFO, "Detecting device using external device detection: {$url}", 'deviceDetection'); $json = file_get_contents($url); $test = json_decode($json, true); // make sure the response is valid if ($json && isset($test['pagetype'], $test['platform'])) { $cache->write($json, $cacheFilename); } else { Kurogo::log(LOG_WARNING, "Error receiving device detection data from {$url}. Reading expired cache.", 'deviceDetection'); $json = $cache->read($cacheFilename); } } $data = json_decode($json, true); // fix values when using old version if ($this->version == 1) { switch (strtolower($data['pagetype'])) { case 'basic': if ($data['platform'] == 'computer' || $data['platform'] == 'spider') { $data['pagetype'] = 'compliant'; } else { if ($data['platform'] == 'bbplus') { $data['pagetype'] = 'compliant'; } else { $data['pagetype'] = 'basic'; } } break; case 'touch': if ($data['platform'] == 'blackberry') { $data['pagetype'] = 'compliant'; // Storm, Storm 2 } else { if ($data['platform'] == 'winphone7') { $data['pagetype'] = 'compliant'; // Windows Phone 7 } else { $data['pagetype'] = 'touch'; } } break; case 'compliant': case 'webkit': default: $data['pagetype'] = 'compliant'; break; } } return $data; }
function getMinifyGroupsConfig() { $minifyConfig = array(); $key = $_GET['g']; // javascript and css search directory order $dirs = array(APP_DIR, SHARED_APP_DIR, SITE_APP_DIR, SHARED_THEME_DIR, THEME_DIR); // // Check for specific file request // if (strpos($key, MIN_FILE_PREFIX) === 0) { // file path relative to either templates or the theme (check theme first) $path = substr($key, strlen(MIN_FILE_PREFIX)); $files = array(); foreach ($dirs as $dir) { if ($dir) { $files[] = $dir . $path; } } $config = array('include' => 'all', 'files' => $files); return array($key => buildFileList($config)); } // // Page request // $pageOnly = isset($_GET['pageOnly']) && $_GET['pageOnly']; $noCommon = $pageOnly || isset($_GET['noCommon']) && $_GET['noCommon']; // if this is a copied module also pull in files from that module $configModule = isset($_GET['config']) ? $_GET['config'] : ''; list($ext, $module, $page, $pagetype, $platform, $browser, $pathHash) = explode('-', $key); $cache = new DiskCache(CACHE_DIR . '/minify', Kurogo::getOptionalSiteVar('MINIFY_CACHE_TIMEOUT', 30), true); $cacheName = "group_{$key}"; $Kurogo = Kurogo::sharedInstance(); $Kurogo->setCurrentModuleID($module); if ($configModule) { $Kurogo->setCurrentConfigModule($configModule); $cacheName .= "-{$configModule}"; } if ($pageOnly) { $cacheName .= "-pageOnly"; } if ($cache->isFresh($cacheName)) { $minifyConfig = $cache->read($cacheName); } else { if ($noCommon) { // Info module does not inherit from common files $subDirs = array('/modules/' . $module); } else { $subDirs = array('/common', '/modules/' . $module); } if ($configModule && $configModule !== $module) { $subDirs[] = '/modules/' . $configModule; } $checkFiles = array('css' => getFileConfigForDirs('css', 'css', $page, $pagetype, $platform, $browser, $dirs, $subDirs, $pageOnly), 'js' => getFileConfigForDirs('js', 'javascript', $page, $pagetype, $platform, $browser, $dirs, $subDirs, $pageOnly)); //error_log(print_r($checkFiles, true)); $minifyConfig[$key] = buildFileList($checkFiles[$ext]); //error_log(__FUNCTION__."($pagetype-$platform-$browser) scanned filesystem for $key"); $cache->write($minifyConfig, $cacheName); } // Add minify source object for the theme config if ($ext == 'css') { $themeConfig = Kurogo::getThemeConfig(); if ($themeConfig) { $minifyConfig[$key][] = new Minify_Source(array('id' => 'themeConfigModTimeChecker', 'getContentFunc' => 'minifyThemeConfigModTimeCheckerContent', 'minifier' => '', 'contentType' => Minify::TYPE_CSS, 'lastModified' => $themeConfig->getLastModified())); } } //error_log(__FUNCTION__."($pagetype-$platform-$browser) returning: ".print_r($minifyConfig, true)); return $minifyConfig; }
private function detectDeviceExternal($user_agent) { if (!$user_agent) { return; } // see if the server has cached the results from the the device detection server $cache = new DiskCache($this->cacheFolder(), $this->cacheLifetime(), TRUE); $cacheFilename = md5($user_agent); if ($cache->isFresh($cacheFilename)) { $json = $cache->read($cacheFilename); } else { $query = http_build_query(array( 'user-agent' => $user_agent, 'version'=> $this->version )); $url = $GLOBALS['siteConfig']->getVar('MOBI_SERVICE_URL').'?'.$query; $json = file_get_contents($url); $cache->write($json, $cacheFilename); } $data = json_decode($json, true); // fix values when using old version if ($this->version == 1) { switch (strtolower($data['pagetype'])) { case 'basic': if ($data['platform'] == 'computer' || $data['platform'] == 'spider') { $data['pagetype'] = 'compliant'; } else if ($data['platform'] == 'bbplus') { $data['pagetype'] = 'compliant'; } else { $data['pagetype'] = 'basic'; } break; case 'touch': if ($data['platform'] == 'blackberry') { $data['pagetype'] = 'compliant'; // Storm, Storm 2 } else if ($data['platform'] == 'winphone7') { $data['pagetype'] = 'compliant'; // Windows Phone 7 } else { $data['pagetype'] = 'touch'; } break; case 'compliant': case 'webkit': default: $data['pagetype'] = 'compliant'; break; } } return $data; }
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; }