_path = $path; $i->_timeout = $timeout; return $i; } /** * Get value for $key. * * @param mixed $key * * @return mixed */ function get($key = null) { if (is_null($key)) return false; $filename = $this->_get_filename($key); if ($this->_is_valid_file($filename, $this->_timeout)) { return unserialize(file_get_contents($filename)); } return null; } /** * Save $value under $key. * * @param mixed $key * @param mixed $value */ function set($key, $value) { if (is_null($key)) return false; $filename = $this->_get_filename($key); file_put_contents($filename, serialize($value)); return true; } /** * Get cache file from key. * * @param mixed $key * * @return string */ private function _get_filename($key) { $key = hash('sha1', serialize($key)); return $this->_path . '/' . $key . '.cache'; } /** * Check that the cache file exists and has not expired. * * @param string $filename * * @return boolean */ private function _is_valid_file($filename, $timeout) { if (!file_exists($filename)) { //error_log(sprintf('Could not find %s', $filename), 0); return false; } if (filemtime($filename) + $timeout < time()) { //error_log(sprintf('%s timestamp expired (timeout was %ds.).', $filename, $timeout)); unlink($filename); return false; } //error_log(sprintf('Found %s', $filename)); return true; } } class l10n { public static $t; /** * Load langs/$lang.lang into global $_t array. * * @param string $lang * * @return void */ function load($lang) { $lang_file = __DIR__ . '/langs/' . $lang . '.lang'; if (file_exists($lang_file)) { global $_t; $f = file($lang_file); foreach ($f as $k => $v) { if (substr($v, 0, 1) == ';' && !empty($f[$k+1])) { $_t[trim(substr($v, 1))] = trim($f[$k+1]); } } } } /** * Get value for key $s in global array $_t. * * @param string $s * * @return string */ function _t($s) { if (trim($s) == '') return ''; global $_t; return array_key_exists($s, $_t) ? $_t[$s] : $s; } } /** * Produce navigation HTML code. * * @param boolean $wrap = false should it be wrapped in a