/** * * @param Model_Page_Front $page * @param string $part * @param boolean $inherit * @param integer $cache_lifetime * @return void */ public static function content(Model_Page_Front $page, $part = 'body', $inherit = FALSE, $cache_lifetime = NULL, array $tags = array()) { if (self::exists($page, $part)) { $view = self::get($page->id(), $part); if ($cache_lifetime !== NULL and !Fragment::load($page->id() . $part . Request::current()->uri(), (int) $cache_lifetime)) { echo $view; Fragment::save_with_tags((int) $cache_lifetime, array('page_parts')); } else { if ($cache_lifetime === NULL) { echo $view; } } } else { if ($inherit !== FALSE and $page->parent() instanceof Model_Page_Front) { self::content($page->parent(), $part, TRUE, $cache_lifetime); } } }
/** * * @param string $snippet_name * @param array $vars * @param integer $cache_lifetime * @param boolean $cache_by_uri * @param array $tags * @param boolean $i18n * @return void */ public static function render($snippet_name, $vars = NULL, $cache_lifetime = NULL, $cache_by_uri = FALSE, array $tags = array(), $i18n = NULL) { $view = Snippet::get($snippet_name, $vars); if ($view === NULL) { return NULL; } $cache_key = self::_cache_key($snippet_name, $cache_by_uri); if (!in_array($snippet_name, $tags)) { $tags[] = $snippet_name; } if (Kohana::$caching === TRUE and $cache_lifetime !== NULL and !Fragment::load($cache_key, (int) $cache_lifetime, $i18n)) { echo $view; Fragment::save_with_tags((int) $cache_lifetime, $tags); } else { if ($cache_lifetime === NULL) { echo $view; } } }
/** * Рендер виджета во Frontend * * Отключение комментариев для блока * * Block::run('block_name', array('comments' => FALSE)); * * Отключение кеширования виджетов в блоке * * Block::run('block_name', array('caching' => FALSE)); * * @param array $params Дополнительные параметры */ public function render(array $params = array()) { // Проверка прав на видимость виджета if (!empty($this->roles)) { if (Auth::is_logged_in()) { if (!Auth::has_permissions($this->roles, FALSE)) { return; } } else { return; } } if (Kohana::$profiling === TRUE) { $benchmark = Profiler::start('Widget render', $this->name); } $this->_fetch_template(); $this->set_params($params); $allow_omments = (bool) Arr::get($this->template_params, 'comments', TRUE); $caching = (bool) Arr::get($this->template_params, 'caching', $this->caching); if ($this->block == 'PRE' or $this->block == 'POST') { $allow_omments = FALSE; } if (Kohana::$caching === FALSE or $caching === FALSE) { $this->caching = FALSE; } if (Arr::get($this->template_params, 'return') === TRUE) { return $this->_fetch_render(); } if ($allow_omments) { echo "<!--{Widget: {$this->name}}-->"; } if ($this->caching === TRUE and !Fragment::load($this->get_cache_id(), $this->cache_lifetime, TRUE)) { echo $this->_fetch_render(); Fragment::save_with_tags($this->cache_lifetime, $this->cache_tags); } else { if (!$this->caching) { echo $this->_fetch_render(); } } if ($allow_omments) { echo "<!--{/Widget: {$this->name}}-->"; } if (isset($benchmark)) { Profiler::stop($benchmark); } }