Example #1
0
 /**
  * 
  * @param type Model_Page_Front
  */
 private function _render(Model_Page_Front $page)
 {
     View::set_global('page_object', $page);
     View::set_global('page', $page);
     $this->_ctx->set_page($page);
     // If page needs login, redirect to login
     if ($page->needs_login() == Model_Page::LOGIN_REQUIRED) {
         Observer::notify('frontpage_login_required', $page);
         if (!Auth::is_logged_in()) {
             Flash::set('redirect', $page->url());
             $this->redirect(Route::get('user')->uri(array('action' => 'login')));
         }
     }
     Observer::notify('frontpage_found', $page);
     $this->_ctx->set_crumbs($page);
     $this->_ctx->build_crumbs();
     // Если установлен статус 404, то выводим страницу 404
     // Страницу 404 могут выкидывать также Виджеты
     if (Request::current()->is_initial() and $this->response->status() == 404) {
         $message = $this->_ctx->get('throw_message');
         $this->_ctx = NULL;
         if (!$message) {
             $message = 'Page not found';
         }
         Model_Page_Front::not_found($message);
     }
     $html = (string) $page->render_layout();
     // Если пользователь Администраторо или девелопер, в конец шаблона
     // добавляем View 'system/blocks/toolbar', в котором можно добавлять
     // собственный HTML, например панель администратора
     if (Auth::is_logged_in() and Auth::has_permissions(array('administrator', 'developer'))) {
         $inject_html = (string) View::factory('system/blocks/toolbar');
         // Insert system HTML before closed tag body
         $matches = preg_split('/(<\\/body>)/i', $html, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
         if (count($matches) > 1) {
             /* assemble the HTML output back with the iframe code in it */
             $html = $matches[0] . $inject_html . $matches[1] . $matches[2];
         }
     }
     // Если в наcтройках выключен режим отладки, то выключить etag кеширование
     if (Config::get('site', 'debug') == Config::NO) {
         $this->check_cache(sha1($html));
         $this->response->headers('last-modified', date('r', strtotime($page->updated_on)));
     }
     $this->response->headers('Content-Type', $page->mime());
     if (Config::get('global', 'x_powered_header') == Config::YES) {
         $this->response->headers('X-Powered-CMS', CMS_NAME . '/' . CMS_VERSION);
     }
     $this->response->body($html);
 }