public static final function get_instance() { if (!is_object(self::$_instance)) { self::$_instance = new cms_cache_handler(); } return self::$_instance; }
public static function cache_end($tag_arg, &$smarty) { if (!cms_cache_handler::can_cache()) { return '}'; } if (!is_array(self::$_cge_cache_keystack) || count(self::$_cge_cache_keystack) == 0) { throw new Exception('in /cge_cache smarty tag without existing cache data'); } $key = array_pop(self::$_cge_cache_keystack); if ($key == '') { throw new Exception('in /cge_cache with invalid key'); } $output = "\${$key}=@ob_get_contents();@ob_end_clean();echo \${$key};cms_cache_handler::get_instance()->set('{$key}',\${$key},'cge_cache');}"; return $output; }
/** * The constructor. * This method does numerous things, including setup an extended autoloader, * create defines for the module itself. i.e: MOD_CGEXTENSIONS, or MOD_FRONTENDUSERS. * sets up a built in cache driver for temporarily caching data. * and register numerous smarty plugins (see the documentation for those). */ public function __construct() { spl_autoload_register(array($this, 'autoload')); parent::__construct(); global $CMS_INSTALL_PAGE, $CMS_PHAR_INSTALL; if (isset($CMS_INSTALL_PAGE) || isset($CMS_PHAR_INSTALL)) { return; } $class = get_class($this); if (!defined('MOD_' . strtoupper($class))) { /** * @ignore */ define('MOD_' . strtoupper($class), $class); } if (self::$_initialized || $class != 'CGExtensions') { return; } self::$_initialized = TRUE; // from here down only happens once per request (for CGExtensions only) // setup caching if ($class == MOD_CGEXTENSIONS && !is_object(cms_cache_handler::get_instance()->get_driver())) { $lifetime = (int) $this->GetPreference('cache_lifetime', 300); $filelock = (int) $this->GetPreference('cache_filelock', 1); $autoclean = (int) $this->GetPreference('cache_autoclean', 1); if ($autoclean) { // autoclean is enabled... but we don't want to search through the directory for files to delete // on each request... so we just do that once per interval. $tmp = $this->GetPreference('cache_autoclean_last', 0); if (time() - $tmp < $lifetime) { $autoclean = 0; } else { $autoclean = 1; $this->SetPreference('cache_autoclean_last', time()); } } $driver = new cms_filecache_driver(array('cache_dir' => TMP_CACHE_LOCATION, 'lifetime' => $lifetime, 'locking' => $filelock, 'auto_cleaning' => $autoclean)); cms_cache_handler::get_instance()->set_driver($driver); } $smarty = CmsApp::get_instance()->GetSmarty(); if (!$smarty) { return; } $smarty->register_function('cge_yesno_options', 'cge_smarty_plugins::smarty_function_cge_yesno_options'); $smarty->register_function('cge_have_module', array('cge_smarty_plugins', 'plugin_have_module')); $smarty->register_block('cgerror', array('cge_smarty_plugins', 'blockDisplayError')); $smarty->register_block('jsmin', array('cge_smarty_plugins', 'jsmin')); $smarty->register_function('cge_cached_url', array('cge_smarty_plugins', 'cge_cached_url')); $smarty->register_function('cgimage', array('cge_smarty_plugins', 'smarty_function_cgimage')); $smarty->register_function('cge_helptag', array('cge_smarty_plugins', 'smarty_function_helptag')); $smarty->register_function('cge_helphandler', array('cge_smarty_plugins', 'smarty_function_helphandler')); $smarty->register_function('cge_helpcontent', array('cge_smarty_plugins', 'smarty_function_helpcontent')); $smarty->register_function('cge_state_options', array('cge_smarty_plugins', 'smarty_function_cge_state_options')); $smarty->register_function('cge_country_options', array('cge_smarty_plugins', 'smarty_function_cge_country_options')); $smarty->register_function('cge_textarea', array('cge_smarty_plugins', 'smarty_function_cge_textarea')); $smarty->register_function('get_current_url', array('cge_smarty_plugins', 'smarty_function_get_current_url')); $smarty->register_function('cge_str_to_assoc', array('cge_smarty_plugins', 'smarty_function_str_to_assoc')); $smarty->register_modifier('rfc_date', array('cge_smarty_plugins', 'smarty_modifier_rfc_date')); $smarty->register_modifier('time_fmt', array('cge_smarty_plugins', 'smarty_modifier_time_fmt')); $smarty->register_modifier('cge_entity_decode', array('cge_smarty_plugins', 'smarty_modifier_cge_entity_decode')); $smarty->register_compiler_function('cge_cache', array('cge_smarty_plugins', 'cache_start')); $smarty->register_compiler_function('cge_cacheclose', array('cge_smarty_plugins', 'cache_end')); $smarty->register_function('cge_module_hint', array('cge_smarty_plugins', 'cge_module_hint')); $smarty->register_function('cge_file_list', array('cge_smarty_plugins', 'cge_file_list')); $smarty->register_function('cge_image_list', array('cge_smarty_plugins', 'cge_image_list')); $smarty->register_function('cge_array_set', array('cge_smarty_plugins', 'cge_array_set')); $smarty->register_function('cge_array_erase', array('cge_smarty_plugins', 'cge_array_erase')); $smarty->register_function('cge_array_get', array('cge_smarty_plugins', 'cge_array_get')); $smarty->register_function('cge_array_getall', array('cge_smarty_plugins', 'cge_array_getall')); $smarty->register_function('cge_admin_error', array('cge_smarty_plugins', 'cge_admin_error')); $smarty->register_function('cge_wysiwyg', array('cge_smarty_plugins', 'cge_wysiwyg')); $smarty->register_modifier('cge_createurl', array('cge_smarty_plugins', 'smarty_modifier_createurl')); $smarty->register_function('cge_setlist', array('cge_smarty_plugins', 'cge_setlist')); $smarty->register_function('cge_unsetlist', array('cge_smarty_plugins', 'cge_unsetlist')); $smarty->register_function('cge_message', array('cge_smarty_plugins', 'cge_message')); $smarty->register_function('cge_isbot', array('cge_smarty_plugins', 'cge_isbot')); $smarty->register_function('cge_is_smartphone', array('cge_smarty_plugins', 'cge_is_smartphone')); $smarty->register_function('cge_getbrowser', array('cge_smarty_plugins', 'cge_get_browser')); $smarty->register_function('cge_isie', array('cge_smarty_plugins', 'cge_isie')); $smarty->register_function('cge_content_type', array('cge_smarty_plugins', 'cge_content_type')); $smarty->register_function('cge_start_tabs', array('cge_smarty_plugins', 'cge_start_tabs')); $smarty->register_function('cge_end_tabs', array('cge_smarty_plugins', 'cge_end_tabs')); $smarty->register_function('cge_tabheader', array('cge_smarty_plugins', 'cge_tabheader')); $smarty->register_function('cge_tabcontent_start', array('cge_smarty_plugins', 'cge_tabcontent_start')); $smarty->register_function('cge_tabcontent_end', array('cge_smarty_plugins', 'cge_tabcontent_end')); $smarty->register_function('cgjs_render', array('cge_smarty_plugins', 'cgjs_render')); $smarty->register_function('cgjs_require', array('cge_smarty_plugins', 'cgjs_require')); $smarty->register_block('cgjs_add', array('cge_smarty_plugins', 'cgjs_add')); $smarty->register_block('cgcss_add', array('cge_smarty_plugins', 'cgcss_add')); // should be admin only $smarty->register_function('cge_pageoptions', array('cge_smarty_plugins', 'cge_pageoptions')); $db = cms_utils::get_db(); if (is_object($db)) { $query = 'SET @CG_ZEROTIME = NOW() - INTERVAL 150 YEAR,@CG_FUTURETIME = NOW() + INTERVAL 5 YEAR'; $db->Execute($query); } }
public static function cache_end($tag_arg, $smarty) { $output = ''; if (!cms_cache_handler::get_instance()->can_cache()) { $output = '}'; } else { if (!is_array(self::$_cge_cache_keystack) || count(self::$_cge_cache_keystack) == 0) { throw new Exception('in /cge_cache smarty tag without existing cache data'); } $key = array_pop(self::$_cge_cache_keystack); if ($key == '') { throw new Exception('in /cge_cache with invalid key'); } $output = "\${$key}=@ob_get_contents();@ob_end_clean();echo \${$key};cms_cache_handler::get_instance()->set('{$key}',\${$key},'cge_cache');}"; } if (version_compare(CMS_VERSION, '1.11-alpha0') < 0) { return $output; } return '<?php ' . $output . ' ?>'; }
public function DoAction($name, $id, $params, $returnid = '') { if (!method_exists($this, 'set_action_id') && $this->GetName() != 'CGExtensions') { die('FATAL ERROR: A module derived from CGExtensions is not handling the set_action_id method'); } $this->set_action_id($id); // handle the stupid input type='image' problem. foreach ($params as $key => $value) { if (endswith($key, '_x')) { $base = substr($key, 0, strlen($key) - 2); if (isset($params[$base . '_y']) && !isset($params[$base])) { $params[$base] = $base; } } } $smarty = cmsms()->GetSmarty(); $smarty->assign('actionid', $id); $smarty->assign('actionparams', $params); $smarty->assign('returnid', $returnid); $smarty->assign_by_ref('mod', $this); $smarty->assign_by_ref($this->GetName(), $this); cge_tmpdata::set('module', $this->GetName()); if ($returnid == '') { if (isset($params['cg_activetab'])) { $this->_current_tab = trim($params['cg_activetab']); unset($params['cg_activetab']); } if (isset($params['cg_error'])) { $this->_errormsg = explode(':err:', $params['cg_error']); unset($params['cg_error']); } if (isset($params['cg_message'])) { $this->_messages = explode(':msg:', $params['cg_message']); unset($params['cg_message']); } $this->DisplayErrors(); $this->DisplayMessages(); } $cge = $this->GetModuleInstance('CGExtensions'); if ($cge->GetPreference('cache_modulecalls', 0) && (!isset($params['nocache']) || !$params['nocache']) && cms_cache_handler::can_cache()) { $key = ''; if (isset($params['cache_key'])) { $key = trim($params['cache_key']); } else { $tmp = debug_backtrace(); $bt = array(); foreach ($tmp as $elem) { $bt[] = $elem['file'] . ':' . $elem['line']; } $key = 'm' . md5($this->GetName() . serialize($params) . serialize($bt) . $id . $returnid); } $output = ''; if (!cms_cache_handler::get_instance()->exists($key, 'cge_module')) { @ob_start(); parent::DoAction($name, $id, $params, $returnid); $output = @ob_get_contents(); @ob_end_clean(); if (strlen($output)) { cms_cache_handler::get_instance()->set($key, $output, 'cge_module'); } } else { $output = cms_cache_handler::get_instance()->get($key, 'cge_module'); } echo $output; return; } parent::DoAction($name, $id, $params, $returnid); }