/** * Localize given statement * * @param string $str Statement to translate * @param array|mixed $args Array or any number of sprintf-like arguments * * @return string translated statement */ static function tr($str, $args = null) { if (empty($str)) { return ""; } $str = trim($str); // Defined and not empty if (self::$localize) { list($_prefix, $_rest) = CAppUI::splitLocale($str); $_lang_prefix = self::$lang . $_prefix; // Not in self::$locales cache if (empty(self::$locales_loaded[$_lang_prefix])) { $shared_name = "locales-" . self::$lang . "-" . $_prefix; if (SHM::exists($shared_name)) { $_loc = SHM::get($shared_name); if (empty(self::$locales[$_prefix])) { self::$locales[$_prefix] = $_loc; } else { self::$locales[$_prefix] = array_merge(self::$locales[$_prefix], $_loc); } } self::$locales_loaded[$_lang_prefix] = true; } // dereferecing makes the systme a lots slower ! :( //$by_prefix = array_key_exists($_prefix, self::$locales) ? self::$locales[$_prefix] : null; //$by_prefix = self::$locales[$_prefix]; if (isset(self::$locales[$_prefix][$_rest]) && self::$locales[$_prefix][$_rest] !== "") { $str = self::$locales[$_prefix][$_rest]; } elseif (self::$lang) { if (!in_array($str, self::$unlocalized) && !preg_match(self::$localize_ignore, $str)) { self::$unlocalized[] = $str; } // ... and decorate if (self::$locale_mask) { $str = sprintf(self::$locale_mask, $str); } } } if ($args !== null) { if (!is_array($args)) { $args = func_get_args(); unset($args[0]); } if ($args) { $str = vsprintf($str, $args); } } return nl2br($str); }
/** * Inform whether value if avaialble in one of the defined cache layers * * @return bool */ public function exists() { $layers = $this->layers; // Inner cache if ($layers & Cache::INNER) { if (array_key_exists($this->prefix, self::$data) && array_key_exists($this->key, self::$data[$this->prefix])) { return true; } } // Flat key for outer and distributed layers $key = "{$this->prefix}-{$this->key}"; // Outer cache if ($layers & Cache::OUTER) { if (SHM::exists($key)) { return true; } } // Distributed cache if ($layers & Cache::DISTR) { if (SHM::exists($key)) { return true; } } $this->_hit("NONE"); return false; }
* $Id: cache_tester_users.php 24615 2014-09-01 10:52:44Z phenxdesign $ * * @package Mediboard * @subpackage developpement * @author SARL OpenXtrem <*****@*****.**> * @license GNU General Public License, see http://www.gnu.org/licenses/gpl.html * @version $Revision: 24615 $ */ CCanDo::checkRead(); $chrono = new Chronometer(); $chrono->start(); if (CView::get("purge", "bool default|0")) { SHM::rem("mediusers"); $chrono->step("purge"); } if (!SHM::exists("mediusers")) { $chrono->step("acquire (not yet)"); $mediuser = new CMediusers(); $mediusers = $mediuser->loadListFromType(); $chrono->step("load"); SHM::put("mediusers", $mediusers, true); $chrono->step("put"); } /** @var CMediusers[] $mediusers */ $mediusers = SHM::get("mediusers"); $chrono->step("get"); // Création du template $smarty = new CSmartyDP(); $smarty->assign("mediusers", $mediusers); $smarty->assign("chrono", $chrono); $smarty->display("cache_tester_users.tpl");