/** * testTimeDefinition * * @retun void * @access public */ function testTimeDefinition() { $result = __c('abday', 5, true); $expected = array('Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sab'); $this->assertEqual($result, $expected); $result = __c('day', 5, true); $expected = array('Domingo', 'Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sábado'); $this->assertEqual($result, $expected); $result = __c('abmon', 5, true); $expected = array('Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez'); $this->assertEqual($result, $expected); $result = __c('mon', 5, true); $expected = array('Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'); $this->assertEqual($result, $expected); $result = __c('d_fmt', 5, true); $expected = '%d/%m/%Y'; $this->assertEqual($result, $expected); $result = __c('am_pm', 5, true); $expected = array('AM', 'PM'); $this->assertEqual($result, $expected); }
public function __construct() { // add tokens $token = Model::factory('BacboxConfigModel')->create(); $token->key = 'mailer.host'; $token->value = serialize('localhost'); $token->allow_override = true; $token->save(); $token = Model::factory('BacboxConfigModel')->create(); $token->key = 'mailer.port'; $token->value = serialize(587); $token->allow_override = true; $token->save(); $token = Model::factory('BacboxConfigModel')->create(); $token->key = 'mailer.username'; $token->value = serialize('*****@*****.**'); $token->allow_override = true; $token->save(); $token = Model::factory('BacboxConfigModel')->create(); $token->key = 'mailer.password'; $token->value = serialize('123456'); $token->allow_override = true; $token->save(); // clear cache __c()->delete('_configTokens'); }
/** * Tries to build the complete locale name, including charset. * Integrated fallback for systems that use uppercase Charset-appendices */ private function buildLocale() { if (!($availableLocales = __c()->_availableLocales)) { ob_start(); if (system('locale -a')) { $availableLocales = ob_get_contents(); ob_end_clean(); $availableLocales = explode("\n", trim($availableLocales)); __c()->_availableLocales = array($availableLocales, 3600); } else { return false; } } // charset format can differ depending on system - prepare different formats $charsetStack = array($this->charset, strtoupper($this->charset), str_replace('-', '', $this->charset), str_replace('-', '', strtoupper($this->charset))); // verify if requested locale is available on this system foreach ($charsetStack as $test) { if (in_array($this->localeShort . '.' . $test, $availableLocales)) { // match! register $this->charset = $test; $this->locale = $this->localeShort . '.' . $this->charset; return true; } } // requested locale is not available on this system! throw new Exception('locale ' . $this->localeShort . '.' . $this->charset . ' not supported on this system (variations fallback failed)!'); }
public function _initCache() { //$servers = array(); $cacheCfg = $this->_config->memcached->config; $servers = $cacheCfg->toArray(); if (!empty($servers)) { phpFastCache::$storage = "auto"; $cache = __c($cacheCfg->type); $server = array(array($cacheCfg->host, $cacheCfg->port, $cacheCfg->timeout)); $cache->option("server", $server); Registry::set("cache", $cache); } }
function fetchAndCache($query, $cacheTime, $cb = null) { $cacheKey = 'ED-' . md5($query); $result = __c()->get($cacheKey); if ($result === null) { $result = $this->endPoint->query($query); $result = $result["result"]["rows"]; if (is_callable($cb)) { $result = $cb($result); } __c()->set($cacheKey, $result, $cacheTime * 3600); //cache for cacheTime hours } return $result; }
public function testAction() { phpFastCache::$storage = "auto"; $cache = __c("memcache"); $server = array(array("192.168.10.122", 11211, 100)); $cache->option("server", $server); $cache->keyword = array("something here++++++++++++++++_________", 600); // var_dump($cache->get("31lh9kj9cs3627fauu90njuj26")); var_dump($cache->keyword); $excel = new CreateExcel(); // $excel->setHeader('高子航' . date('Y年m月d日 H:i:s', time())); // $excel->setTitle(array( '高子航')); // $excel->setData(array()); // $excel->echoExcel('show_' . date('Y_m_d_H_i_s', time())); die; }
function __construct() { global $gStatsToplistAPI; global $gCacheLocal; if ($gCacheLocal) { $cacheKey = 'LD-' . md5($gStatsToplistAPI); $result = __c()->get($cacheKey); if ($result === null) { $result = $this->_fetch($gStatsToplistAPI); global $gExternalStatsCacheTime; __c()->set($cacheKey, $result, $gExternalStatsCacheTime * 3600); } } else { $result = $this->_fetch($gStatsToplistAPI); } $this->list = $result; }
/** * load configuration tokens from database */ public static function load() { if (!($configTokens = __c()->_configTokens)) { try { // try to load configuration tokens $configTokens = Model::factory('BacboxConfigModel')->order_by_asc('key')->find_many(); __c()->_configTokens = array($configTokens, 3600); } catch (PDOException $e) { if ($e->getCode() == '42S02') { /** * table '_config' has not yet been defined / run initial migration * we first augment max_execution_time to avoid initial migrations causing * a time-out error on slow systems */ ini_set('max_execution_time', 180); // init first migration -> this chains all the remaining initial migrations automagically new InstallBacbox(); // clear cache __c()->delete('_configTokens'); /** * redirect the user so he doesn't see ugly errors after * initial set-up */ header("Location: " . BACBOX_URLBASE); exit; } else { // other database error - re-throw exception throw $e; } } } // assign configuration tokens foreach ($configTokens as $configToken) { // register each token self::set($configToken->key, unserialize($configToken->value)); // if token is overrideable, store it appropriatly if ($configToken->allow_override) { self::$overrideable_tokens[] = $configToken->key; } } // set internal system settings based on defined configuration tokens self::set_system_settings(); }
/** * category method * * @access private * @return void */ function __category($category = 3) { $singular = __c('Plural Rule 1', $category, true); return $singular; }
private static function load_sites() { if (!($sites = __c()->_coreSites)) { if (!($sites = Model::factory('BacboxSiteModel')->find_many())) { throw new Exception('Failed to load site entities'); } // @todo: find a proper way to cache the sites //__c()->_coreSites = array($sites->as_array(), 3600); } foreach ($sites as $site) { self::$site_cache[$site->host_id][$site->site_regex] = $site; } }
/** * Auxiliary function to translate a matched specifier element from a regular expresion into * a windows safe and i18n aware specifier * * @param array $specifier match from regular expression * @return string converted element * @access private */ function __translateSpecifier($specifier) { switch ($specifier[1]) { case 'a': $abday = __c('abday', 5, true); if (is_array($abday)) { return $abday[date('w', $this->__time)]; } break; case 'A': $day = __c('day', 5, true); if (is_array($day)) { return $day[date('w', $this->__time)]; } break; case 'c': $format = __c('d_t_fmt', 5, true); if ($format != 'd_t_fmt') { return $this->convertSpecifiers($format, $this->__time); } break; case 'C': return sprintf("%02d", date('Y', $this->__time) / 100); case 'D': return '%m/%d/%y'; case 'e': if (DS === '/') { return '%e'; } $day = date('j', $this->__time); if ($day < 10) { $day = ' ' . $day; } return $day; case 'eS': return date('jS', $this->__time); case 'b': case 'h': $months = __c('abmon', 5, true); if (is_array($months)) { return $months[date('n', $this->__time) - 1]; } return '%b'; case 'B': $months = __c('mon', 5, true); if (is_array($months)) { return $months[date('n', $this->__time) - 1]; } break; case 'n': return "\n"; case 'p': case 'P': $default = array('am' => 0, 'pm' => 1); $meridiem = $default[date('a', $this->__time)]; $format = __c('am_pm', 5, true); if (is_array($format)) { $meridiem = $format[$meridiem]; return $specifier[1] == 'P' ? strtolower($meridiem) : strtoupper($meridiem); } break; case 'r': $complete = __c('t_fmt_ampm', 5, true); if ($complete != 't_fmt_ampm') { return str_replace('%p', $this->__translateSpecifier(array('%p', 'p')), $complete); } break; case 'R': return date('H:i', $this->__time); case 't': return "\t"; case 'T': return '%H:%M:%S'; case 'u': return ($weekDay = date('w', $this->__time)) ? $weekDay : 7; case 'x': $format = __c('d_fmt', 5, true); if ($format != 'd_fmt') { return $this->convertSpecifiers($format, $this->__time); } break; case 'X': $format = __c('t_fmt', 5, true); if ($format != 't_fmt') { return $this->convertSpecifiers($format, $this->__time); } break; } return $specifier[0]; }
/** * testTimeDefinitionJapanese method * * @return void */ public function testTimeDefinitionJapanese() { Configure::write('Config.language', 'ja_jp'); $result = __c('d_fmt', 5); $expected = "%Y年%m月%d日"; $this->assertEquals($expected, $result); $result = __c('am_pm', 5); $expected = array("午前", "午後"); $this->assertEquals($expected, $result); $result = __c('abmon', 5); $expected = array(" 1月", " 2月", " 3月", " 4月", " 5月", " 6月", " 7月", " 8月", " 9月", "10月", "11月", "12月"); $this->assertEquals($expected, $result); }
if (isset($_POST)) { $caching = false; } // no caching if have some $_GET ?string=var if (isset($_GET['somevar']) && $_GET['somevar'] == "something") { $caching = false; } // No caching for logined user // can use with $_COOKIE AND $_SESSION if (isset($_SESSION) && $_SESSION['logined'] == true) { $caching = false; } // ONLY ACCESS CACHE IF $CACHE = TRUE if ($caching == true) { $html = __c("files")->get($keyword_webpage); } if ($html == null) { ob_start(); /* ALL OF YOUR CODE GO HERE RENDER YOUR PAGE, DB QUERY, WHATEVER */ echo " WEBSITE HTML HERE "; echo " MY WEB SITE CONTENTS IS HERE"; echo " ENDING WEBSITE CONTENT"; // GET HTML CONTENT $html = ob_get_contents(); // Save to Cache 30 minutes __c("files")->set($keyword_webpage, $html, 1800); } echo $html;
/** * test __c() * * @return void */ public function testTranslateCategory() { Configure::write('Config.language', 'rule_1_po'); $result = __c('Plural Rule 1', 6); $expected = 'Plural Rule 1 (translated)'; $this->assertEquals($expected, $result); $result = __c('Plural Rule 1 (from core)', 6); $expected = 'Plural Rule 1 (from core translated)'; $this->assertEquals($expected, $result); $result = __c('Some string with %s', 6, 'arguments'); $expected = 'Some string with arguments'; $this->assertEquals($expected, $result); $result = __c('Some string with %s %s', 6, 'multiple', 'arguments'); $expected = 'Some string with multiple arguments'; $this->assertEquals($expected, $result); $result = __c('Some string with %s %s', 6, array('multiple', 'arguments')); $expected = 'Some string with multiple arguments'; $this->assertEquals($expected, $result); }
/** * test __c() * * @access public * @return void */ function test__c() { Configure::write('Config.language', 'rule_1_po'); $result = __c('Plural Rule 1', 6, true); $expected = 'Plural Rule 1 (translated)'; $this->assertEqual($result, $expected); $result = __c('Plural Rule 1 (from core)', 6, true); $expected = 'Plural Rule 1 (from core translated)'; $this->assertEqual($result, $expected); ob_start(); __c('Plural Rule 1 (from core)', 6); $result = ob_get_clean(); $expected = 'Plural Rule 1 (from core translated)'; $this->assertEqual($result, $expected); }
*/ return null; $singularReturn = __('Singular string return __()', true); $singularEcho = __('Singular string echo __()'); $pluralReturn = __n('% apple in the bowl (plural string return __n())', '% apples in the blowl (plural string 2 return __n())', 3, true); $pluralEcho = __n('% apple in the bowl (plural string 2 echo __n())', '% apples in the blowl (plural string 2 echo __n()', 3); $singularDomainReturn = __d('controllers', 'Singular string domain lookup return __d()', true); $singularDomainEcho = __d('controllers', 'Singular string domain lookup echo __d()'); $pluralDomainReturn = __dn('controllers', '% pears in the bowl (plural string domain lookup return __dn())', '% pears in the blowl (plural string domain lookup return __dn())', 3, true); $pluralDomainEcho = __dn('controllers', '% pears in the bowl (plural string domain lookup echo __dn())', '% pears in the blowl (plural string domain lookup echo __dn())', 3); $singularDomainCategoryReturn = __dc('controllers', 'Singular string domain and category lookup return __dc()', 5, true); $singularDomainCategoryEcho = __dc('controllers', 'Singular string domain and category lookup echo __dc()', 5); $pluralDomainCategoryReturn = __dcn('controllers', '% apple in the bowl (plural string 1 domain and category lookup return __dcn())', '% apples in the blowl (plural string 2 domain and category lookup return __dcn())', 3, 5, true); $pluralDomainCategoryEcho = __dcn('controllers', '% apple in the bowl (plural string 1 domain and category lookup echo __dcn())', '% apples in the blowl (plural string 2 domain and category lookup echo __dcn())', 3, 5); $categoryReturn = __c('Category string lookup line return __c()', 5, true); $categoryEcho = __c('Category string lookup line echo __c()', 5); /** * Language string extractor * * @package cake * @subpackage cake.cake.console.libs */ class ExtractShell extends Shell { var $path = null; var $files = array(); var $__filename = 'default'; var $__oneFile = true; var $__file = null; var $__tokens = array(); var $__strings = array();
$cache1->set("keyword1", "string|number|array|object", 300); $cache2->keyword2 = array("something here", 600); __c()->keyword3 = array("array|object", 3600 * 24); // How to Read? $data = $cache1->get("keyword1"); $data = $cache2->keyword2; $data = __c()->keyword3; $data = __c()->get("keyword4"); // Free to Travel between any caching methods $cache1 = phpFastCache("files"); $cache1->set("keyword1", $value, $time); $cache1->memcache->set("keyword1", $value, $time); $cache1->apc->set("whatever", $value, 300); $cache2 = __c("apc"); $cache2->keyword1 = array("so cool", 300); $cache2->files->keyword1 = array("Oh yeah!", 600); $data = __c("memcache")->get("keyword1"); $data = __c("files")->get("keyword2"); $data = __c()->keyword3; // Multiple ? No Problem $list = $cache1->getMulti(array("key1", "key2", "key3")); $cache2->setMulti(array("key1", "value1", 300), array("key2", "value2", 600), array("key3", "value3", 1800)); $list = $cache1->apc->getMulti(array("key1", "key2", "key3")); __c()->memcache->getMulti(array("a", "b", "c")); // Others $cache->delete("keyword"); $cache->increment("keyword", $step = 1); $cache->decrement("keyword", $step = 1); $cache->clean(); $cache->stats(); $cache->isExisting("keyword");
/** * export teams header * * @param string $content * @return the content */ function exportTeamsHeader($content) { $content .= "\t" . _c('RF|Runs for', 'leaguemanager') . "\t" . _c('RA|Runs against', 'leaguemanager') . "\t" . _c('PCT|Percentage win') . "\t" . _c('GB|games behind', 'leaguemanager') . "\t" . __c('SO|Shutouts', 'leaguemanager'); return $content; }
<?php /* * shortcut! to make it faster! * phpFastCache can use 2 functions: * __c() and phpFastCache() at any where without limit * * Example 1 */ require_once "../phpfastcache/phpfastcache.php"; // get from cache $products = __c()->my_products; if ($products == null) { $products = "ARRAY | OBJECT | FUNCTION GET PRODUCTS"; // write to cache; __c()->my_products = array($products, 300); } echo $products; /* * Example 2 - Short Cut */ $products = __c("files")->get("keyword"); // Write to Files Cache 24 hours; __c("files")->set("keyword", "data | something | array | object", 3600 * 24);
<?php /* Purges all the cache. You will probably need to run as root if using the filec cache. Usage: php purgeCache.php or sudo php purgeCache.php */ require 'maintenance.php'; fwrite(STDOUT, "Cache settings:\n"); $config_str = print_r(\phpFastCache::$config, true); fwrite(STDOUT, $config_str); fwrite(STDOUT, "\n\nClearing cache\n"); __c()->clean(); fwrite(STDOUT, "Done!");
/** * category method * * @return void */ protected function _category($category = I18n::LC_MONETARY) { $singular = __c('Plural Rule 1', $category); return $singular; }
<?php /* * Here is how to setup and work on phpFastCache fast! */ require_once "phpfastcache/phpfastcache.php"; // auto, files, sqlite, xcache, memcache, apc, memcached, wincache phpFastCache::setup("storage", "auto"); // SET a Data into Cache __c()->set("keyword", "array|object|string|data", $time_in_second); // GET a Data from Cache $data = __c()->get("keyword"); $object = __c()->getInfo("keyword"); // ARRAY // Others Funtions __c()->delete("keyword"); __c()->increment("keyword", $step = 1); // TRUE | FALSE __c()->decrement("keyword", $step = 1); // TRUE | FALSE __c()->touch("keyword", $more_time_in_second); // TRUE | FALSE __c()->clean(); __c()->stats(); // ARRAY __c()->isExisting("keyword"); // TRUE | FALSE // Direct Keyword SET & GET __c()->keyword = array("array|object|string|data", $time_in_second); $data = __c()->keyword;
/** * category method * * @return void */ protected function _category($category = 3) { $singular = __c('Plural Rule 1', $category); return $singular; }
function __construct($parameters) { $endpoint = new \Endpoint($this->endpoint); /* Add namespace prefixes to query */ $query = $this->_joinAndAffix($this->prefixes, "\n", "PREFIX "); /* Add select statement to query */ $query .= "\nSELECT DISTINCT * "; /* Add where clauses to query */ $wheres = array('?laur rdf:type nobel:Laureate', '?laur rdfs:label ?label', 'optional { ?laur dbpedia-owl:birthPlace ?birthPlace }', 'optional { ?laur owl:sameAs ?sameAs }', '?laur nobel:laureateAward ?award', '?laur nobel:nobelPrize ?prize', '?laur foaf:gender ?gender'); /* Select by award */ if (isset($parameters['award'])) { $award = $parameters['award']; if (in_array($award, $this->awards)) { $wheres[] = "?award nobel:category <http://data.nobelprize.org/resource/category/{$award}>"; } } /* Select by gender */ if (isset($parameters['gender'])) { $gender = $parameters['gender']; if (in_array($gender, array('male', 'female'))) { $wheres[] = "?laur foaf:gender '{$gender}'"; } } $whereString = $this->_joinAndAffix($wheres, "\n", "\t", ' .'); /* Select by region */ if (isset($parameters['region'])) { global $baseUrl; $url = "{$baseUrl}/regions-api.php"; $regions_json = file_get_contents($url); $regionMapping = json_decode($regions_json, true); // assure that region is in list if (in_array($parameters['region'], array_keys($regionMapping))) { $filters = array(); $data = $regionMapping[$parameters['region']]; foreach ($data as $str) { $str = urlencode(str_replace(" ", "_", $str)); $filters[] = "?birthPlace = <http://data.nobelprize.org/resource/country/{$str}>"; } $filter = implode(' || ', $filters); $whereString .= "\n\tFILTER( {$filter} )"; } } $query .= "WHERE {\n{$whereString}\n}\n"; $this->_query = $query; global $gCacheLocal; if ($gCacheLocal) { $cacheKey = 'LD-' . md5($query); $result = __c()->get($cacheKey); if ($result === null) { $result = $endpoint->query($query); global $gExternalLaureateDataCacheTime; __c()->set($cacheKey, $result, $gExternalLaureateDataCacheTime * 3600); } } else { $result = $endpoint->query($query); } $this->_result = $result["result"]["rows"]; }
// exclude stuff $continue = true; foreach ($settings["galnet_excludes"] as $exclude) { $find = $exclude; $pos = strpos($title, $find); if ($pos !== false) { $continue = false; break 1; } } if ($continue !== false) { echo '<h3><a href="#" onclick="$(\'#' . $i . '\').fadeToggle()"><img src="/style/img/plus.png" alt="expand" style="width:16px;height:16px;margin-right:5px;padding-bottom:3px" />' . $title . '</a></h3>'; echo '<p id="' . $i . '" style="display:none;padding-left:22px;max-width:800px">'; echo str_replace('<p><sub><i>-- Delivered by <a href="http://feed43.com/">Feed43</a> service</i></sub></p>', "", $text); echo '<br /><br /><br /><span style="margin-bottom:15px"><a href="' . $link . '" target="_BLANK">Read on elitedangerous.com</a><img src="style/img/external_link.png" style="margin-bottom:3px;margin-left:5px" alt="ext" /></span>'; echo '</p>'; $i++; } } ?> </div> </div> <?php $html = ob_get_contents(); // Save to Cache for 30 minutes __c("files")->set("galnet", $html, 1800); require_once "" . $_SERVER["DOCUMENT_ROOT"] . "/style/footer.php"; die; } echo $html; require_once "" . $_SERVER["DOCUMENT_ROOT"] . "/style/footer.php";
public function testReplaceTranslate() { $result = $this->Table->replaceTranslate('[__]Translate this[/__]'); $expected = __('Translate this'); $this->assertEqual($result, $expected); $result = $this->Table->replaceTranslate('[__][/__]'); $expected = ''; $this->assertEqual($result, $expected); $result = $this->Table->replaceTranslate('[__d|common]Translate this[/__d]'); $expected = __d('common', 'Translate this'); $this->assertEqual($result, $expected); $result = $this->Table->replaceTranslate('[__d|common][/__d]'); $expected = ''; $this->assertEqual($result, $expected); $result = $this->Table->replaceTranslate('[link][__d|affiliates]View[/__d]|/admin/affiliates/affiliates/view/1[/link]|[link][__d|affiliates]Suspend[/__d]|/admin/affiliates/affiliates/suspend/1[/link]'); $expected = '[link]' . __d('affiliates', "View") . '|/admin/affiliates/affiliates/view/1[/link]|[link]' . __d('affiliates', "Suspend") . '|/admin/affiliates/affiliates/suspend/1[/link]'; $this->assertEqual($result, $expected); $result = $this->Table->replaceTranslate('[__c|3]$5.00[/__c]'); $expected = __c('$5.00', LC_MONETARY); $this->assertEqual($result, $expected); $result = $this->Table->replaceTranslate('[__c|3][/__c]'); $expected = ''; $this->assertEqual($result, $expected); }