function removeJavascript($id = 0) { $page =& NController::singleton('page'); $page->base_view_dir = ROOT_DIR; $page->view_caching = (bool) PAGE_CACHING; $page->view_cache_lifetime = JS_CACHE_LIFETIME; $view_options = array('action' => 'blank'); // REMOVE JAVASCRIPT CACHES $javascript_caches = array('javascript', 'javascript_secure', 'javascript_qualified', 'admin_javascript', 'admin_edit_javascript'); foreach ($javascript_caches as $javascript_cache) { $page->view_cache_name = $javascript_cache; $view =& NView::singleton($page); $title = ucfirst(str_replace('_', ' ', $javascript_cache)); if ($view->isCached($view_options)) { $cache_cleared = $view->clearCache($view_options); if ($cache_cleared) { NDebug::debug($title . ' cache removed due to page edit on Page ID ' . $id . '.', N_DEBUGTYPE_CACHE); } else { NDebug::debug($title . ' cache failed attempted removal due to page edit on Page ID ' . $id . '.', N_DEBUGTYPE_CACHE); } } else { NDebug::debug($title . ' cache failed attempted removal due to page edit on Page ID ' . $id . ' but cache does not exist.', N_DEBUGTYPE_CACHE); } } unset($view); }
/** * deleteSmartyCache - Delete the entire cache when you make a page change. * If you're including the navigation in the page as ul/li's - this keeps the * navigation always consistent. * * @return void **/ function deleteSmartyCache() { // Only delete the entire cache if the NAV_IN_PAGE is true and we're in production. if (defined('NAV_IN_PAGE') && NAV_IN_PAGE && ENVIRONMENT == 'production' && !isset($this->smarty_cache_cleared)) { NDebug::debug('We are clearing the smarty caches because of a page edit.', N_DEBUGTYPE_INFO); $view =& NView::singleton($this); $view->clear_all_cache(); $site_admin = NController::factory('site_admin'); $site_admin->rmDirFiles(CACHE_DIR . '/smarty_cache'); $site_admin->rmDirFiles(CACHE_DIR . '/templates_c'); $this->smarty_cache_cleared = true; } }
function viewlist($parameter = null, $layout = true, $model = false) { $options = array(); $assigns = array(); $model = $model ? $model : $this->getDefaultModel(); $this->page_title = Inflector::humanize($this->name); $this->auto_render = false; $this->base_dir = APP_DIR; $assigns['TITLE'] = Inflector::humanize($this->name); if ($model) { $this->get_search_field($model, $options); $this->get_viewlist_options($model, $options); $this->get_sort_options($model, $options); $this->set_pagination($model); $model->find($options); $page_content =& NController::singleton('page_content'); $page_content_model =& $page_content->getDefaultModel(); $pk = $model->primaryKey(); $models = array(); $headline = $model->getHeadline() ? $model->getHeadline() : 'cms_headline'; $i = 0; while ($model->fetch()) { $arr = $model->toArray(); $arr['_headline'] = isset($arr['cms_headline']) && $arr['cms_headline'] ? $arr['cms_headline'] : $model->makeHeadline(); $arr['_remove_delete'] = $page_content_model->isWorkflowContent($this->name, $arr[$pk]) ? 1 : 0; // Remove delete for models that have specified this. $arr['_remove_delete'] = isset($model->remove_delete) && $model->remove_delete == true ? 1 : 0; $models[] = $arr; unset($arr); } // Override standard paging limit if chosen in the model file. $paging = isset($model->paging) ? $model->paging : $this->paging; // If paging is not disabled in the model AND the records are > than the paging size AND not searching. if ($paging > 0 && count($models) > $paging && !$options['is_search']) { SmartyPaginate::connect($this->name); SmartyPaginate::setLimit($paging, $this->name); SmartyPaginate::setTotal(count($models), $this->name); $view =& NView::singleton($this); SmartyPaginate::assign($view, 'paginate', $this->name); // TODO: Could be more efficient and only get records it needs to. $models = array_slice($models, SmartyPaginate::getCurrentIndex($this->name), SmartyPaginate::getLimit($this->name)); $this->set('paging', true); } $this->set(array('rows' => $models, 'asset' => $this->name, 'asset_name' => $this->page_title)); unset($models); } $this->render(array('layout' => 'default')); }
function deletePageCache($id) { if (!empty($id)) { // load the model $model =& NModel::singleton($this->name); $model->reset(); if ($model->get($id)) { $pk = $model->primaryKey(); // find the action $action = $this->getTemplate($model->page_template_id); $action = $action ? $action : 'default'; $action = $this->getTemplate($model->page_template_id); $action = $action ? $action : 'default'; // set up caching values $this->base_view_dir = ROOT_DIR; $this->view_caching = true; $this->view_cache_lifetime = $model->cache_lifetime; $this->view_cache_name = 'page' . $id; $view =& NView::singleton($this); if ($this->isCached($action)) { $cleared = $view->clearCache($action); $this->debug('Page cache for Page ID ' . $id . ($cleared ? ' removed' : ' failed attempted removal') . '.', N_DEBUGTYPE_CACHE); } else { $this->debug('Page cache for Page ID ' . $id . ' failed attempted removal since cache does not exist.', N_DEBUGTYPE_CACHE); } // Check the smarty_cache folder for additional caches from query string pages. $query_string_caches = CACHE_DIR . '/smarty_cache/page' . $id . '%*'; if (count(glob($query_string_caches)) != 0) { $files = glob($query_string_caches); foreach ($files as $file) { unlink($file); } NDebug::debug('Deleted query string cache files for page id ' . $id, N_DEBUGTYPE_INFO); } } unset($model); unset($view); } return; }
function deleteCache() { $auth_model =& NModel::factory('cms_auth'); if ($auth_model->find()) { $pk = $auth_model->primaryKey(); while ($auth_model->fetch()) { // remove the site admin cache $this->view_cache_name = 'nterchange_site_admin_' . $auth_model->{$pk}; $view =& NView::singleton($this); $view->clearLayoutCache('default'); } } unset($auth_model); unset($view); }
function error(&$controller, $action = null) { if (is_string($controller)) { $values = array('_NOTICE_' => '<h1>ERROR</h1>The ' . (is_string($controller) ? $controller : $controller->name) . ' controller does not exist.'); } else { $values = array('_NOTICE_' => '<h1>ERROR</h1>The ' . $controller->name . ' controller does not contain the ' . $action . ' action.'); } $view =& NView::singleton($controller); $view->assign($values); $view->render(array('layout' => 'plain')); exit; }
/** * Gets an instance of the view object & prepares it for rendering a layout, then * asks the view to actually do the job. * * @param string $layout - the layout file to use * @param string $main_content * @param string $sidebar_content * @param boolean $return - whether to return the render or print it immediately * @return mixed */ function renderLayout($layout, $main_content, $sidebar_content = null, $return = false) { $view =& NView::singleton($this); return $view->renderLayout($layout, $main_content, $sidebar_content, $return); }