コード例 #1
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;
     }
 }
コード例 #2
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;
 }
コード例 #3
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();
}
コード例 #4
0
 /**
  * Create new fragment
  * @param array $data
  */
 public function create($data)
 {
     // First validate the input
     if ($this->validation->passes($data)) {
         $fragment = new Fragment(array('title' => array_get($data, 'title'), 'slug' => Str::slug(array_get($data, 'slug')), 'body' => array_get($data, 'body')));
         $fragment->save();
         return $fragment->id;
     }
     // Set errors
     $this->errors = $this->validation->errors();
     return false;
 }