/** * Render cached view * * @param string $filename the cache file to include * @param string $timeStart the page render start time */ function renderCache($filename, $timeStart) { ob_start(); include $filename; if (Configure::read() > 0 && $this->layout != 'xml') { echo "<!-- Cached Render Time: " . round(S2getMicrotime() - $timeStart, 4) . "s -->"; } $out = ob_get_clean(); if (preg_match('/^<!--cachetime:(\\d+)-->/', $out, $match)) { if (time() >= $match['1']) { @unlink($filename); unset($out); return false; } else { if ($this->layout === 'xml') { header('Content-type: text/xml'); } $out = str_replace('<!--cachetime:' . $match['1'] . '-->', '', $out); // Remove the nocache from all pages for xhtml compliance $replace = array('<s2:nocache>', '</s2:nocache>'); $out = str_replace($replace, '', $out); return $out; } } }
function cached($path) { if (Configure::read('Cache.enable') && Configure::read('Cache.view')) { $path = Inflector::slug($path); $filename = CACHE . 'views' . DS . $path . '.php'; if (!file_exists($filename)) { $filename = CACHE . 'views' . DS . $path . '_index.php'; } if (file_exists($filename)) { if (!class_exists('MyView')) { App::import('Core', 'View', $this->app); } $view = new MyView($this, false); $view->ajaxRequest = $this->ajaxRequest; $view->viewSuffix = $this->viewSuffix; $view->name = $this->name; // $view->helpers = $this->helpers; // $view->layout = $this->layout; return $view->renderCache($filename, S2getMicrotime()); } } return false; }
/** * Outputs cached dispatch view cache * * @param string $url Requested URL * @access public */ function cached($url) { App::import('Component', 'config', $this->app); $controller = new stdClass(); if (class_exists('ConfigComponent')) { $Config = new ConfigComponent(); $Config->startup($controller); } $User = cmsFramework::getUser(); if ($User->id === 0 && !Configure::read('Cache.disable') && Configure::read('Cache.view') && !defined('MVC_FRAMEWORK_ADMIN')) { $path = $this->here; if ($this->here == '/') { $path = 'home'; } $path = Inflector::slug($path); $filename = CACHE . 'views' . DS . $path . '.php'; if (!file_exists($filename)) { $filename = CACHE . 'views' . DS . $path . '_index.php'; } if (file_exists($filename)) { if (!class_exists('MyView')) { App::import('Core', 'View', $this->app); } $controller = null; $view = new MyView($controller, false); // Pass the configuration object to the view and set the theme variable for helpers $view->name = $this->controller; $view->action = $this->action; $view->page = Sanitize::getInt($this->params, 'page'); $view->limit = Sanitize::getInt($this->params, 'limit'); $view->Config = $Config; $view->viewTheme = $Config->template; $view->xajaxRequest = false; $view->ajaxRequest = $this->isAjax(); $out = $view->renderCache($filename, S2getMicrotime()); return $out; } } return false; }