public static function start($lifetime = 0, $path = '/', $domain = NULL) { if (!self::$_initialized) { if (!is_object(Symphony::Database()) || !Symphony::Database()->connected()) { return false; } $cache = Cache::instance()->read('_session_config'); if (is_null($cache) || $cache === false) { self::create(); Cache::instance()->write('_session_config', true); } if (!session_id()) { ini_set('session.save_handler', 'user'); ini_set('session.gc_maxlifetime', $lifetime); ini_set('session.gc_probability', '1'); ini_set('session.gc_divisor', '3'); } session_set_save_handler(array('Session', 'open'), array('Session', 'close'), array('Session', 'read'), array('Session', 'write'), array('Session', 'destroy'), array('Session', 'gc')); session_set_cookie_params($lifetime, $path, $domain ? $domain : self::getDomain(), false, false); if (strlen(session_id()) == 0) { if (headers_sent()) { throw new Exception('Headers already sent. Cannot start session.'); } session_start(); } self::$_initialized = true; } return session_id(); }
public function index($feedtype = 'rss2') { if (!Kohana::config('settings.allow_feed')) { throw new Kohana_404_Exception(); } if ($feedtype != 'atom' and $feedtype != 'rss2') { throw new Kohana_404_Exception(); } // How Many Items Should We Retrieve? $limit = (isset($_GET['l']) and !empty($_GET['l']) and (int) $_GET['l'] <= 200) ? (int) $_GET['l'] : 20; // Start at which page? $page = (isset($_GET['p']) and !empty($_GET['p']) and (int) $_GET['p'] >= 1) ? (int) $_GET['p'] : 1; $page_position = $page == 1 ? 0 : $page * $limit; // Query position $site_url = url::base(); // Cache the Feed with subdomain in the cache name if mhi is set $subdomain = ''; if (substr_count($_SERVER["HTTP_HOST"], '.') > 1 and Kohana::config('config.enable_mhi') == TRUE) { $subdomain = substr($_SERVER["HTTP_HOST"], 0, strpos($_SERVER["HTTP_HOST"], '.')); } $cache = Cache::instance(); $feed_items = $cache->get($subdomain . '_feed_' . $limit . '_' . $page); if ($feed_items == NULL) { // Cache is Empty so Re-Cache $incidents = ORM::factory('incident')->where('incident_active', '1')->orderby('incident_date', 'desc')->limit($limit, $page_position)->find_all(); $items = array(); foreach ($incidents as $incident) { $categories = array(); foreach ($incident->category as $category) { $categories[] = (string) $category->category_title; } $item = array(); $item['id'] = $incident->id; $item['title'] = $incident->incident_title; $item['link'] = $site_url . 'reports/view/' . $incident->id; $item['description'] = $incident->incident_description; $item['date'] = $incident->incident_date; $item['categories'] = $categories; if ($incident->location_id != 0 and $incident->location->longitude and $incident->location->latitude) { $item['point'] = array($incident->location->latitude, $incident->location->longitude); $items[] = $item; } } $cache->set($subdomain . '_feed_' . $limit . '_' . $page, $items, array('feed'), 3600); // 1 Hour $feed_items = $items; } $feedpath = $feedtype == 'atom' ? 'feed/atom/' : 'feed/'; header('Content-Type: application/' . ($feedtype == 'atom' ? 'atom' : 'rss') . '+xml; charset=utf-8'); $view = new View('feed/' . $feedtype); $view->feed_title = Kohana::config('settings.site_name'); $view->site_url = $site_url; $view->georss = 1; // this adds georss namespace in the feed $view->feed_url = $site_url . $feedpath; $view->feed_date = gmdate("D, d M Y H:i:s T", time()); $view->feed_description = Kohana::lang('ui_admin.incident_feed') . ' ' . Kohana::config('settings.site_name'); $view->items = $feed_items; $view->render(TRUE); }
public static function getSeriesPinyin() { $redis = Cache::instance('redis'); $cache_key = '_ALL_SERIES_PINYIN_'; $data = $redis->get($cache_key); if (empty($data)) { $m_brand = Model::factory('auto_series'); $data = $m_brand->getAll('', 'id,pinyin')->as_array(); $data = array_column($data, 'pinyin', 'id'); $data = array_map(function ($v) { return preg_replace('/[^0-9a-z]/', '', strtolower($v)); }, $data); $tmp = array(); foreach ($data as $id => $pinyin) { if (isset($tmp[$pinyin])) { $tmp[$pinyin] += 1; $data[$id] = $pinyin . $tmp[$pinyin]; } else { $tmp[$pinyin] = 1; } } $redis->setex($cache_key, 86400, json_encode($data)); } else { $data = json_decode($data, true); } return $data; }
public static function create() { if (!is_object(self::$instance)) { self::$instance = new Cache(); } return self::$instance; }
/** * 更新首页,公共社区,图书馆首页 */ public function action_clean() { $cid = (int) $this->getQuery('cid'); switch ($cid) { case 1: @unlink(DOCROOT . 'cache/index.html'); shell_exec('. /server/wal8/www/bin/clearcache.sh http://www.wal8.com/cache/index.html'); break; case 2: @unlink(DOCROOT . 'cache/pic.html'); shell_exec('. /server/wal8/www/bin/clearcache.sh http://www.wal8.com/cache/pic.html'); break; break; case 3: @unlink(DOCROOT . 'cache/book.html'); shell_exec('. /server/wal8/www/bin/clearcache.sh http://www.wal8.com/cache/book.html'); break; break; case 4: Cache::instance()->delete(); break; break; } $links[] = array('text' => '缓存状况', 'href' => '/admin/cache'); $this->show_message('缓存更新成功', 1, $links, true); $this->auto_render = false; }
/** * 静态方法,返回数据库连接实例 * * @return Cache */ public static function getInstance() { if (self::$instance == null) { self::$instance = new Cache(); } return self::$instance; }
public function action_index() { $select = DB::select()->from('imgup_config')->order_by('id', 'DESC')->limit('1')->execute()->current(); $this->template->rows = $select; if ($this->isPost()) { $post = Validate::factory($this->getPost())->filter(TRUE, 'trim')->rule('allowed_ext', 'not_empty')->rule('admin_email', 'not_empty')->rule('max_upload', 'not_empty')->rule('max_upload', 'numeric')->rule('unit', 'not_empty'); if ($post->check()) { $id = (int) $this->getPost('id'); $max_B = $this->getPost('max_upload') . ':' . $this->getPost('unit'); $set = array('allowed_ext' => trim($this->getPost('allowed_ext')), 'admin_email' => $this->getPost('admin_email'), 'max_upload' => $max_B, 'tmp_message_top' => trim($this->getPost('tmp_message_top')), 'marquee_message' => trim($this->getPost('marquee_message')), 'show_top' => (int) $this->getPost('show_top')); if ($id > 0) { DB::update('imgup_config')->set($set)->where('id', '=', $id)->execute(); Cache::instance()->delete('sys_configs'); @unlink(DOCROOT . 'cache/index.html'); @shell_exec('. /server/wal8/www/bin/clearcache.sh http://www.wal8.com/cache/index.html'); $links[] = array('text' => '返回列表', 'href' => '/admin/system'); $this->show_message('修改资料成功', 1, $links, true); } } else { // 校验失败,获得错误提示 $str = ''; $this->template->registerErr = $errors = $post->errors('admin/module'); foreach ($errors as $item) { $str .= $item . '<br>'; } $this->show_message($str); } } }
/** * Retrieves the metadata for all the supported spatial reference systems. * * @param boolean $refresh Set to true to force a full refresh, otherwise the result is cached. */ public static function system_metadata($refresh = false) { $cacheId = 'spatial-ref-systems'; if ($refresh) { $cache = Cache::instance(); $cache->delete($cacheId); self::$system_metadata = false; } if (self::$system_metadata === false) { $latlong_systems = Kohana::config('sref_notations.lat_long_systems'); $cache = Cache::instance(); if ($cached = $cache->get($cacheId)) { self::$system_metadata = $cached; } else { self::$system_metadata = array(); // fetch any systems that are just declared as srids, with no notation module required foreach (Kohana::config('sref_notations.sref_notations') as $code => $title) { self::$system_metadata["EPSG:{$code}"] = array('title' => $title, 'srid' => $code, 'treat_srid_as_x_y_metres' => !isset($latlong_systems[$code])); } // Now look for any modules which extend the sref systems available foreach (Kohana::config('config.modules') as $path) { $plugin = basename($path); if (file_exists("{$path}/plugins/{$plugin}.php")) { require_once "{$path}/plugins/{$plugin}.php"; if (function_exists($plugin . '_sref_systems')) { $metadata = call_user_func($plugin . '_sref_systems'); self::$system_metadata = array_merge(self::$system_metadata, $metadata); } } } $cache->set($cacheId, self::$system_metadata); } } return self::$system_metadata; }
/** * Delete a named variable value. * @param string $name Name of the variable to delete. */ public static function delete($name) { $db = new Database(); $db->delete('variables', array('name' => $name)); $cache = Cache::instance(); $cache->delete("variable-{$name}"); }
protected function _clear_cache() { if (Kohana::$caching === TRUE) { Cache::instance()->delete('Database::cache(' . Plugin::CACHE_KEY . '::plugin::' . $this->id() . ')'); } return parent::_clear_cache(); }
public static function clear_all() { Cache::instance()->delete_all(); Cache::clear_file(); Cache::clear_routes(); Cache::clear_profiler(); }
/** * Returns new users * * @param int|string $limit week, 50 */ public static function get_new($max = 'week') { $where = ''; $limit = ''; switch ($max) { case 'week': $where = " WHERE registered > CURRENT_DATE - INTERVAL '1 week' "; break; default: if (is_numeric($max)) { $limit = ' LIMIT ' . $max; } else { throw new Kohana_Exception('member.error_invalid_type'); } } $cache = Cache::instance(); $key = $cache->key('users', $max); $users = $cache->get($key); if (empty($users)) { $users = array(); if ($result = Database::instance()->query("SELECT id, username, registered, DATE_TRUNC('day', registered) AS day FROM users " . $where . ' ORDER BY id DESC ' . $limit)) { foreach ($result as $user) { $users[$user->day][] = $user; } $cache->set($key, $users, null, 3600); } } return $users; }
/** * @return void */ public function action_index() { $this->template->header->title = $this->bucket->bucket_name . ' ~ ' . __('Display Settings'); $this->active = 'display'; $this->settings_content = View::factory('pages/bucket/settings/display'); $this->settings_content->bucket = $this->bucket; $session = Session::instance(); if ($this->request->method() == "POST") { try { $this->bucket->bucket_name = $this->request->post('bucket_name'); $this->bucket->bucket_publish = $this->request->post('bucket_publish'); $this->bucket->default_layout = $this->request->post('default_layout'); $this->bucket->save(); // Force refresh of cached buckets Cache::instance()->delete('user_buckets_' . $this->user->id); // Redirect to the new URL with a success messsage $session->set("messages", array(__("Display settings were saved successfully."))); $this->request->redirect($this->bucket->get_base_url($this->bucket) . '/settings/display'); } catch (ORM_Validation_Exception $e) { $this->settings_content->errors = $e->errors('validation'); } catch (Database_Exception $e) { $this->settings_content->errors = array(__("A bucket with the name ':name' name already exists", array(":name" => $this->request->post('bucket_name')))); } } // Check for messages $this->settings_content->messages = $session->get('messages'); $session->delete('messages'); }
public static function beforeInit() { $cache = Cache::instance('file'); self::$cache = $cache; $cacheAPI = new Wi3TikoCacheAPI($cache, Request::instance()); self::$tiko = new tikoCacheController($cacheAPI); }
public function article($uri) { $this->template->content = View::factory('blog/view')->bind('post', $post)->bind('comments', $comments)->bind('form', $form); $post = ORM::factory('blog_post', (string) $uri); // Show 404 if we don't find posts if (!$post->loaded) { Event::run('system.404'); } $comments = $post->blog_comments; $this->head->title->prepend($post->title); if (!($post->comment_status === 'open' and config::get('blog.comment_status') === 'open')) { return; } $form = Formo::factory()->plugin('csrf')->add('text', 'author', array('label' => __('Name')))->add('text', 'email', array('label' => __('Email')))->add('text', 'url', array('label' => __('Homepage')))->add('textarea', 'content', array('label' => __('Comment')))->add('submit', 'submit', array('label' => __('Submit')))->pre_filter('all', 'trim')->pre_filter('author', 'security::xss_clean')->pre_filter('content', 'security::xss_clean')->pre_filter('url', 'security::xss_clean')->pre_filter('url', 'format::url')->add_rule('author', 'required', __('You must provide your name'))->add_rule('author', 'length[2,40]', __('Your Name is too long'))->add_rule('email', 'valid::email', __('Email address is not valid'))->add_rule('content', 'required', __('You must enter a comment')); if (config::get('blog.enable_captcha') === 'yes') { $form->add('captcha', 'security', array('label' => __('Security code'))); $form->security->error_msg = __('Invalid security code'); } if ($form->validate()) { $comment = ORM::factory('blog_comment'); $comment->author = $form->author->value; $comment->email = $form->email->value; $comment->content = $form->content->value; $comment->url = $form->url->value; $comment->ip = $this->input->ip_address(); $comment->agent = Kohana::$user_agent; $comment->date = date("Y-m-d H:i:s", time()); $post->add_comment($comment); Event::run('blog.comment_added', $comment); Cache::instance()->delete('s7n_blog_feed'); Cache::instance()->delete('s7n_blog_feed_comments'); url::redirect($post->url()); } $form = View::factory('blog/form_comment', $form->get(TRUE)); }
/** * в массив сообщений добавляем еще одно * * @param $text * @param $type */ public static function put($text, $type = 'error') { $messages = self::get(); $messages[] = ['type' => $type, 'text' => $text]; $cache = $cache = Cache::instance(); return $cache->set('messages', $messages); }
/** * 构造函数, * 为了避免循环实例化,请尽量调用单例模式 */ public function __construct() { $this->contact_mapper = Contact_Mapper::instance(); $this->contact_model = Contact_Model::instance(); $this->cache_pre = CACHE_PRE . 'category_'; $this->cache = Cache::instance(); }
/** * More feature-rich caching using the optional cache library if available. The default * Kohana cache doesn't support all the use cases below as expected. The default cache checks lifetime * when getting based on the file modified time. * * Simplified usage for both internal Kohana cache and cache module: * - cache() - Get/set. * - cache(true, 60) - Get/set. * - cache(true, 0) - Delete. * - cache(false) - Refresh. * - cache(false, 60) - Refresh. * - cache(false, 0) - Delete. * * Specific usage for cache module: * - cache() - Get or set cache. Get cache. If empty, set cache using default lifetime. * - cache(true, 60) - Get or set cache. Same as above cache() but using specified lifetime. * - cache(true, 0) - Delete cache. Check and return cache if it exists, but also delete cache. * for this query. If a cached result doesn't exist, then same effect as not using cache(). * - cache(false) - Refresh cache. Don't check cache, but cache the new results using the default lifetime. * - cache(false, 60) - Refresh cache. Same as above cache(false) but using specified lifetime. * - cache(false, 0) - Delete cache. Don't check cache and delete cache for this query if it was previously cached. * * Specific usage if no cache module. Note that lifetime is meaningless when setting cache: * - cache() - 1) Get cache. If cache exists and is younger than default lifetime, then get cache. * If older than default time, delete cache. * 2) Else set cache. Lifetime not used when setting. * - cache(true, 60) - Same as above cache(), but use specified lifetime instead of default lifetime. * - cache(true, 0) - Delete cache. Doesn't get or set cache. * - cache(false) - Refresh cache. Don't check cache, but cache the new results ignoring lifetime. * - cache(false, 60) - Refresh cache. Same as above cache(false). * - cache(false, 0) - Delete cache. Same as cache(true, 0); * * @param boolean $check [optional] Check cache and return cached result if available. * @param integer $specific_lifetime [optional] Set cache lifetime. If null, use default. If "0", delete. * @param string $type [optional] Cache type name if using cache module. If null use default. * @return object $this */ public function cache($check = TRUE, $specific_lifetime = NULL, $type = NULL) { if (!isset($this->_cache)) { // TODO: is this the best way to check for the "cache" module? $modules = Kohana::modules(); if (isset($modules['cache'])) { // Use the "unofficial" Kohana cache module. $this->_cache = Cache::instance($type); } else { // Default internal Kohana cache. $this->_cache = true; } } if ($specific_lifetime === NULL) { if (is_object($this->_cache)) { // Use the default internal Kohana cache lifetime which is 60 seconds. $this->_cache_lifetime = 60; } else { // Use the default lifetime from the Cache module. $this->_cache_lifetime = Kohana::config('cache.default-expire'); } } else { $this->_cache_lifetime = $specific_lifetime; } $this->_cache_check = $check; return $this; }
public static function me() { if (is_null(self::$instance)) { self::$instance = new Cache(); } return self::$instance; }
public function action_preview2() { $dir = $this->uploads_dir(); // build image file name $filename = $this->request->param('filename'); // check if file exists if (!file_exists($filename) or !is_file($filename)) { throw new HTTP_Exception_404('Picture not found'); } $cachenamearr = explode('/', $filename); $name = array_pop($cachenamearr); $cachename = 'a2' . $name; $cachename = str_replace($name, $cachename, $filename); /** @var Image $image **/ // trying get picture preview from cache if (($image = Cache::instance()->get($cachename)) === NULL) { // create new picture preview $image = Image::factory($filename)->resize(null, 50)->crop(50, 50)->render(NULL, 90); // store picture in cache Cache::instance()->set($cachename, $image, Date::MONTH); } // gets image type $info = getimagesize($filename); $mime = image_type_to_mime_type($info[2]); // display image $this->response->headers('Content-type', $mime); $this->response->body($image); }
static function getStreamByIds($ids) { $cache = Cache::instance(); if (!empty($cache)) { $notices = array(); foreach ($ids as $id) { $n = Notice::staticGet('id', $id); if (!empty($n)) { $notices[] = $n; } } return new ArrayWrapper($notices); } else { $notice = new Notice(); if (empty($ids)) { //if no IDs requested, just return the notice object return $notice; } $notice->whereAdd('id in (' . implode(', ', $ids) . ')'); $notice->find(); $temp = array(); while ($notice->fetch()) { $temp[$notice->id] = clone $notice; } $wrapped = array(); foreach ($ids as $id) { if (array_key_exists($id, $temp)) { $wrapped[] = $temp[$id]; } } return new ArrayWrapper($wrapped); } }
public function action_save() { if (isset($_POST['id'])) { $task = ORM::factory('task', (int) $_POST['id']); if (!$task->id) { exit; } } else { $task = ORM::factory('task'); $task->sequence = 0; $task->user_id = $this->user->id; } $content = trim($_POST['task']); if ($content) { $task->content = $content; } $task->list_id = (int) $_POST['list']; $task->save(); $cache_key = $this->user ? $this->user->id : 0; Cache::instance()->delete($cache_key); if ($this->mobile) { echo 'test'; } else { $this->request->response = json_encode(array('status' => 'success', 'message' => 'Successfully saved!', 'id' => $task->id)); } }
public function before() { parent::before(); // This must be included // start session if not started if (!isset($_SESSION)) { session_start(); } // cache $this->cache = Cache::instance(); // include helpers include_once APPPATH . '/classes/helpers/email.php'; include_once APPPATH . '/classes/helpers/flash.php'; include_once APPPATH . '/classes/helpers/cli.php'; include_once APPPATH . '/classes/library/task_queue.php'; // set default layout props $this->template->title = 'Social Mention'; $this->template->content = ''; //$this->db = Database::instance(); //$this->session = Session::instance(); // load user auth class include_once APPPATH . '/classes/library/authorize.php'; $this->auth = new Authorize(); // user details $this->user_id = $this->auth->get_user(); $this->_user_id = $this->auth->get_user(); $this->_user = false; if ($this->user_id) { $this->_user = $this->auth->get_user_details(); } // if ($this->user_id) { $this->set_projects(); } }
public function validate(Validation $array, $save = FALSE) { // uses PHP trim() to remove whitespace from beginning and end of all fields before validation $array->pre_filter('trim'); // merge unvalidated fields, in case the subclass has set any. if (!isset($this->unvalidatedFields)) { $this->unvalidatedFields = array(); } $this->unvalidatedFields = array_merge($this->unvalidatedFields, array('validation_rules', 'public', 'multi_value', 'deleted')); $array->add_rules('caption', 'required'); $array->add_rules('data_type', 'required'); if (array_key_exists('data_type', $array->as_array()) && $array['data_type'] == 'L') { if (empty($array['termlist_id'])) { $array->add_rules('termlist_id', 'required'); } else { array_push($this->unvalidatedFields, 'termlist_id'); } } $array->add_rules('system_function', 'length[1,30]'); $parent_valid = parent::validate($array, $save); // clean up cached required fields in case validation rules have changed $cache = Cache::instance(); $cache->delete_tag('required-fields'); if ($save && $parent_valid) { // clear the cache used for attribute datatype and validation rules since the attribute has changed $cache = new Cache(); // Type is the object name with _attribute stripped from the end $type = substr($this->object_name, 0, strlen($this->object_name) - 10); $cache->delete('attrInfo_' . $type . '_' . $this->id); } return $save && $parent_valid; }
public static function getInstance() { if (!isset(self::$instance)) { self::$instance = new Cache(); } return self::$instance; }
/** * * Clears the config cache and loads it * @return boolean */ public function reload_config() { // Clears cached data Cache::instance()->delete('config_db'); //load config return $this->load_config(); }
public function index($f3) { $f3->set("title", $f3->get("dict.administration")); $f3->set("menuitem", "admin"); if ($f3->get("POST.action") == "clearcache") { \Cache::instance()->reset(); $f3->set("success", "Cache cleared successfully."); } $db = $f3->get("db.instance"); // Gather some stats $result = $db->exec("SELECT COUNT(id) AS `count` FROM user WHERE deleted_date IS NULL AND role != 'group'"); $f3->set("count_user", $result[0]["count"]); $result = $db->exec("SELECT COUNT(id) AS `count` FROM issue WHERE deleted_date IS NULL"); $f3->set("count_issue", $result[0]["count"]); $result = $db->exec("SELECT COUNT(id) AS `count` FROM issue_update"); $f3->set("count_issue_update", $result[0]["count"]); $result = $db->exec("SELECT COUNT(id) AS `count` FROM issue_comment"); $f3->set("count_issue_comment", $result[0]["count"]); $result = $db->exec("SELECT value as version FROM config WHERE attribute = 'version'"); $f3->set("version", $result[0]["version"]); if ($f3->get("CACHE") == "apc") { $f3->set("apc_stats", apc_cache_info("user", true)); } $this->_render("admin/index.html"); }
public static function getRegistrations($SIPInterface) { $cache = Cache::instance(); $sipRegCache = $cache->get('cache_' . $SIPInterface); if (!$sipRegCache) { $eslManager = new EslManager(); $cmd = 'sofia xmlstatus profile ' . $SIPInterface; $result = $eslManager->api($cmd); $xml = $eslManager->getResponse($result); $registrations = array(); if ($xml !== 'Command execution failed.') { $xml = @simplexml_load_string($xml); if ($xml and $xml->registrations and $xml->registrations->registration and $xml->registrations->registration != '') { $registrations = $xml->registrations->registration; } else { Kohana::log('info', 'No XML returned'); } } else { Kohana::log('info', $cmd . ': ' . 'Command execution failed.'); } $result = array(); foreach ($registrations as $r) { $r = (array) $r; $r['interface'] = $SIPInterface; $result[] = $r; } return $result; //array ('user' => 'blah', '') } else { Kohana::log('info', 'Using cached registration'); return $sipRegCache; } }
/** * Retrieves the XML geocode address lookup. * ! Results of this method are cached for 1 day. * * @param string $address adress * @return object SimpleXML */ public static function address_to_xml($address) { static $cache; // Load Cache if ($cache === NULL) { $cache = Cache::instance(); } // Address cache key $key = 'gmap-address-' . sha1($address); if ($xml = $cache->get($key)) { // Return the cached XML return simplexml_load_string($xml); } else { // Set the XML URL $xml = Gmap::api_url('maps/geo', array('output' => 'xml', 'q' => $address), '&'); // Disable error reporting while fetching the feed $ER = error_reporting(~E_NOTICE); // Load the XML $xml = simplexml_load_file($xml); if (is_object($xml) and $xml instanceof SimpleXMLElement and (int) $xml->Response->Status->code === 200) { // Cache the XML $cache->set($key, $xml->asXML(), array('gmaps'), 86400); } else { // Invalid XML response $xml = FALSE; } // Turn error reporting back on error_reporting($ER); } return $xml; }
/** * Override the delete method to clear cache */ public function delete($soft = FALSE) { parent::delete($soft); //cleanup the cache Cache::instance('roles')->delete_all(); return $this; }