コード例 #1
0
ファイル: part.php プロジェクト: ZerGabriel/cms-1
 /**
  * 
  * @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);
         }
     }
 }
コード例 #2
0
ファイル: snippet.php プロジェクト: ZerGabriel/cms-1
 /**
  * 
  * @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;
         }
     }
 }
コード例 #3
0
ファイル: album.php プロジェクト: andygoo/kohana_demo
 public function action_details()
 {
     $id = $this->request->param('id');
     $album = ORM::factory('album', $id);
     if (!$album->loaded()) {
         $this->redirect_to_list();
     }
     $default_msg = "<h3>click a row to view album details...</h3>";
     $error_msg = "<h3>couldn't find info for that album...</h3>";
     if (!Fragment::load("album_{$id}", Date::DAY * 7)) {
         $album = ORM::factory('album', $id);
         try {
             $config = Kohana::$config->load('lastfm');
             $details = simplexml_load_file("http://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key={$config['api_key']}&artist={$album->artist}&album={$album->name}");
             $view = new View_Pages_Album_Details();
             $view->set('details', $details);
             $this->response->body($view);
             Fragment::save();
         } catch (Exception $e) {
             Log::instance()->add(Log::ERROR, $e);
             echo $error_msg;
         }
     } else {
         echo $default_msg;
     }
 }
コード例 #4
0
ファイル: feed.php プロジェクト: bluehawk/kohanaphp.com
<?php

// Displayed feeds are cached for 5 minutes
if (!Fragment::load('feed:' . $feed . ':' . $limit, Date::MINUTE * 5)) {
    // Parse the feed
    $items = Feed::parse($feed, $limit);
    // Set the "link" and "title" variable names
    isset($link) or $link = 'link';
    isset($title) or $title = 'title';
    foreach ($items as $item) {
        // Clean the title so no one can inject anything
        $clean = html::chars($item[$title]);
        // Shorten it to 50 characters, but don't cut words in half, add 2 so that if the 51st char is a space, it will grab the 52nd character, and the word its attached to, so that the strrpos below works.
        $short = Text::limit_chars($clean, 52, false, true);
        // If the string is longer than 50 chars, cut off the leftover workd from limit_chars, and append '...'
        if (strlen($short) > 50) {
            $short = substr($short, 0, strrpos($short, ' ')) . '&#8230;';
        }
        // At this point, $short is at MAX 51 characters (50 characters of the string + "..."), usually less, because its rare for the words to line up exactly with the 50th character.
        echo '<li>' . HTML::anchor($item[$link], $short, array('title' => $clean)) . '</li>';
    }
    Fragment::save();
}
コード例 #5
0
 public static function cached_fragment($name, $lifetime = NULL, $i18n = NULL)
 {
     if (isset(static::$_cache_buffers[$name]) && static::$_cache_buffers[$name] === TRUE) {
         $buffer_id = array_pop(static::$_cache_buffer_pull);
         unset(static::$_cache_buffers[$name]);
         Fragment::save();
         return FALSE;
     }
     static::$_cache_buffers[$name] = TRUE;
     static::$_cache_buffer_pull[] = $name;
     if (NULL != $lifetime) {
         $lifetime *= 60;
     }
     if (Fragment::load($name, $lifetime, $i18n)) {
         $buffer_id = array_pop(static::$_cache_buffer_pull);
         unset(static::$_cache_buffers[$name]);
         return FALSE;
     }
     return TRUE;
 }
コード例 #6
0
ファイル: decorator.php プロジェクト: ZerGabriel/cms-1
 /**
  * Рендер виджета во 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);
     }
 }
コード例 #7
0
ファイル: manual.php プロジェクト: wintersilence/kohana-cli
<?php

defined('SYSPATH') or die('No direct script access.');
?>

<?php 
if (!Fragment::load('cli_manual' . $kohana_cli_task['name'], 3600, TRUE)) {
    ?>

<?php 
    echo CLI::color($kohana_cli_task['name'] . ' (' . $kohana_cli_task['class'] . ')', 'black', 'light_gray');
    ?>
-------------------------------------------------

<?php 
    echo CLI::color(__('Description'), 'light_gray');
    ?>
-------------------------------------------------
    <?php 
    echo $kohana_cli_task['description'];
    ?>

<?php 
    echo CLI::color(__('Options'), 'light_gray');
    ?>
-------------------------------------------------
<?php 
    foreach ($kohana_cli_task['options'] as $option => $default) {
        echo CLI::color($option, 'light_gray');
        $key = $name . ' ' . $option;
        $info = __($key);