private function _verifySign($domain, $text, $sign) { include_once KFL_DIR . '/Libs/Cache.class.php'; $filename = $domain . ".txt"; $cache = new Cache(86400 * 300, 0); $cache->setCacheStore("file"); // or memcache $cache->setCacheDir(APP_TEMP_DIR); $cache->setCacheFile($filename); if ($cache->isCached()) { $client = unserialize($cache->fetch()); } else { require_once 'ClientModel.class.php'; $ClientModel = new ClientModel(); $client = $ClientModel->getClientByName($domain); if ($client) { $cache->save(serialize($client)); } else { return false; } } $this->_private_key = $client['private_key']; if (hmac($this->_private_key, $text, 'sha1') == $sign) { return true; } else { return false; } }
/** * Is the cache available? * * @return boolean * @author Justin Palmer **/ public function isCached() { $this->config = Registry::get('pr-cache-config'); if ($this->config === null) { throw new Exception('Please set up the cache config'); } if (parent::isCached()) { return true; } //Set the file path. $this->path = $this->config->path . '/' . $this->key; //Does the file exist if (!file_exists($this->path)) { return false; } //Make sure we can get the time of the file if (!($filemtime = filemtime($this->path))) { return false; } //Is the file cached with an appropriate ttl? if ($filemtime + $this->config->ttl < time()) { @unlink($this->path); return false; } else { /** * Cache the results of this is_cached() call. Why? So * we don't have to double the overhead for each template. * If we didn't cache, it would be hitting the file system * twice as much (file_exists() & filemtime() [twice each]). */ $this->is_cached = true; return true; } }
/** * The display method that including caching. * * @return string * @author Justin Palmer **/ public function display() { //var_dump($this->Controller); //If the cache type is null just return the template. //Or, if the cache_type is not one of the supported cache_types if ($this->view_path === null || !$this->Controller->pr_do_cache || !$this->isValidCacheType()) { return parent::display(); } //If it is a valid cache type then call the method and return the template view. $cached = $this->Cache->isCached(); if ($cached !== false) { return $this->Cache->get(); } else { $content = parent::display(); $this->Cache->value = $content; $this->Cache->cache(); return $content; } }
public function parse() { if (!Cache::isCached($this->sConfig, $this->sConfig)) { $this->sNotParsedConfig = file_get_contents($this->sConfig); $this->intermediate = simplexml_load_string($this->sNotParsedConfig); $this->parseActions(); $this->parseRequest(); $this->parsePlugins(); $this->parseFilters(); Cache::writeCache($sConfig, serialize($this->aConfig)); Logger::debug('Config: zapisano cache'); } else { $this->aConfig = unserialize(Cache::get($this->sConfig)); Logger::debug('Config: odczytano cache'); } return $this->aConfig; }
function hg_facebook_user_tiles() { $c = new Cache(); $c->setCachePath(HG_DIR . '/sdk/cache/'); $c->seed = NONCE_SALT; $c->eraseExpired(); $_template = '<div id="faces-wrap"> <div class="faces">%s</div> </div>'; $_template_item = sprintf('<img src="%s/sdk/cache/%%s.jpg">', get_bloginfo('template_directory')); $output = ""; if ($c->isCached('attending')) { $attending = $c->retrieve('attending'); } else { $facebook = new Facebook(array('appId' => FACEBOOK_EVENT_APP_ID, 'secret' => FACEBOOK_EVENT_APP_KEY)); $attending = array(); $access_token = $facebook->getAccessToken(); $params = array('access_token' => $access_token); $objs = $facebook->api(FACEBOOK_EVENT_APP_ID . '/events', 'GET', $params); foreach ($objs['data'] as $data) { $objs2 = $facebook->api($data['id'] . '/invited', 'GET', $params); foreach ($objs2['data'] as $attendee) { if ($attendee['rsvp_status'] == 'attending' || $attendee['rsvp_status'] == 'unsure') { if (!is_file(get_stylesheet_directory() . '/sdk/cache/' . $attendee['id'] . '.jpg')) { file_put_contents(get_stylesheet_directory() . '/sdk/cache/' . $attendee['id'] . '.jpg', file_get_contents(get_bloginfo('template_directory') . '/sdk/timthumb.php?src=http://graph.facebook.com/' . $attendee['id'] . '/picture?type=large&w=75&h=75')); } $attending[] = $attendee['id']; } } } $c->store('attending', shuffle($attending), 60 * 60 * 24 * 7); } if (!is_array($attending) || sizeof($attending) < 10) { return ""; } foreach ($attending as $id) { $output .= sprintf($_template_item, $id); } return sprintf($_template, $output); }
include 'feedwriter/Feed.php'; include 'feedwriter/RSS2.php'; setlocale(LC_TIME, 'fr_FR.utf8', 'fra'); date_default_timezone_set('Europe/Paris'); use FeedWriter\RSS2; require_once 'cache.class.php'; $c = new Cache("rss"); $c->eraseExpired(); $emission = $_GET["q"]; if (!isset($emission)) { $emission = ""; } $sans100 = isset($_GET["sans-100"]); header("Content-Type: application/rss+xml"); $feedkey = $sans100 ? "sans100" : ($emission == "" ? "all" : $emission); if ($c->isCached($feedkey)) { echo $c->retrieve($feedkey); return; } $TestFeed = new RSS2(); if ($emission != "") { $TestFeed->setDescription('Tous les podcasts de l\'émission ' . $emission . ' diffusés sur Radio Campus Clermont-Ferrand'); $url = 'http://www.campus-clermont.net/onair/podcast/player/?search=' . urlencode($emission); $title = 'Podcasts de l\'émission ' . $emission . ' sur Radio Campus Clermont-Ferrand'; $jsonObject = json_decode(file_get_contents("http://" . $_SERVER['HTTP_HOST'] . "/ws/?req=image&t=" . urlencode($emission))); $image = 'http://' . $_SERVER["HTTP_HOST"] . $jsonObject[0]->uri; } else { $TestFeed->setDescription('Tous les podcasts de Radio Campus Clermont-Ferrand'); $url = 'http://www.campus-clermont.net/onair/podcast/player/'; $title = 'Le podcast de Radio Campus'; $image = "http://www.campus-clermont.net/onair/podcast/player/images/logo.png";
$Query->Close(); $Query->Connect(); $Info = $Query->QueryOldPre17(); } } catch (MinecraftPingException $e) { $Exception = $e; } if ($Query !== null) { $Query->Close(); } } else { // External query // Check cache $cache = new Cache(); $cache->setCache('query_cache'); if (!$cache->isCached('query')) { // Not cached, query the server // Use cURL $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_URL, 'https://mcapi.us/server/status?ip=' . $default_ip . '&port=' . $default_port); // Execute $ret = curl_exec($ch); // Store in cache $cache->store('query', json_decode($ret, true), 5000); // Format the query $ret = json_decode($ret, true); $Info = array('players' => array('online' => $ret['players']['now']));
<?php date_default_timezone_set('Australia/Sydney'); require_once 'sdk/facebook.php'; require_once 'cache.class.php'; $c = new Cache(); $c->setCachePath('cache/'); $c->eraseExpired(); if ($c->isCached('events')) { $events = $c->retrieve('events'); } else { $facebook = new Facebook(array('appId' => '104236416398654', 'secret' => 'SECRET_KEY')); $access_token = $facebook->getAccessToken(); $params = array('access_token' => $access_token); $events = array(); $i = 0; $objs = $facebook->api('139968802813349/events', 'GET', $params); foreach ($objs['data'] as $data) { $events[$i]['id'] = $data['id']; $events[$i]['name'] = $data['name']; $events[$i]['start_time'] = $data['start_time']; $events[$i]['end_time'] = $data['end_time']; $events[$i]['location'] = $data['location']; $objs2 = $facebook->api($data['id'] . '/invited', 'GET', $params); foreach ($objs2['data'] as $attendee) { if ($attendee['rsvp_status'] == 'attending' || $attendee['rsvp_status'] == 'unsure') { $attending[] = array('id' => $attendee['id'], 'name' => $attendee['name']); } } $events[$i]['attending'] = $attending; $i++;
$Cache = new Cache($Router->getFingerprint(), 60); } $Core->LoadUserPlugins(); $Core->trigger('OnBeforeInitPage'); $Core->DefineDefaultPage(); $html = ""; $errorPage = null; if ($Filter->get($_GET, 'pid', DEFAULT_PAGE) == NOT_FOUND) { if ($errorPage = $Router->pageNotFound()) { $_GET['pid'] = $errorPage->id; } else { header("HTTP/1.0 404 Not Found"); die(NO_404_PAGE); } } if ($Filter->get($config, 'use_cache', 0) && $Cache->isCached()) { $html = $Cache->getCache(); } if (empty($html)) { $Skin = new Skin($Filter->get($_GET, 'pid', DEFAULT_PAGE)); $html = $Skin->getHtml(); $html = str_replace(TOKEN_SKYBLUE_INFO_LINK, SKYBLUE_INFO_LINK, $html); $html = str_replace(TOKEN_BODY_CLASS, null, $html); } $html = $Core->trigger('OnBeforeShowPage', $html); $html = $Core->trigger('OnRenderPage', $html); if ($Filter->get($config, 'use_cache', 0)) { $Cache->saveCache($html); $html .= "\n<!-- page caching enabled -->\n"; } if ($errorPage) {
<?php require_once 'vendor/autoload.php'; require_once 'core/Album.php'; require_once 'core/cache.class.php'; $app = new \Slim\Slim(array('mode' => 'development', 'templates.path' => './templates')); $app->get('/musics/', function () use($app) { $response = $app->response(); $response['Content-Type'] = 'application/json'; $c = new Cache(); $nameCache = 'newcache'; if ($c->isCached($nameCache)) { $result = $c->retrieve($nameCache); $response->body(json_encode($result)); } else { $album = new Album('./mus'); $albuns = array(); $parent = 0; $children = 0; foreach ($album->showFiles() as $album => $musics) { $albuns[] = array('id' => "parent_{$parent}", 'parent' => '#', 'text' => strtoupper($album)); if (is_array($musics) && count($musics)) { foreach ($musics as $music) { $albunsM["parent_{$parent}"][] = array('id' => "children_{$children}", 'parent' => "parent_{$parent}", 'text' => basename($music['music']), 'icon' => 'glyphicon glyphicon-music', 'a_attr' => array('href' => $music['music'])); $children++; } } $parent++; } $albumSorted = array_orderby($albuns, 'text', SORT_ASC); $cont = 0;