Exemplo n.º 1
0
 /**
  * Process Post
  *
  * Process data that was not part of the 
  * initial streams call.
  *
  * @return 	void
  */
 private function _process_post(&$post)
 {
     $this->load->helper('text');
     // Keywords array
     $keywords = Keywords::get($post['keywords']);
     $formatted_keywords = array();
     $keywords_arr = array();
     foreach ($keywords as $key) {
         $formatted_keywords[] = array('keyword' => $key->name);
         $keywords_arr[] = $key->name;
     }
     $post['keywords'] = $formatted_keywords;
     $post['keywords_arr'] = $keywords_arr;
     // Full URL for convenience.
     $post['url'] = site_url('movie/' . date('Y/m', $post['created_on']) . '/' . $post['slug']);
     // What is the preview? If there is a field called intro,
     // we will use that, otherwise we will cut down the movie post itself.
     $post['preview'] = isset($post['intro']) ? $post['intro'] : $post['body'];
     // Category
     if ($post['category_id'] > 0 and isset($this->categories[$post['category_id']])) {
         $post['category'] = $this->categories[$post['category_id']];
     }
 }
Exemplo n.º 2
0
 /**
  * Process Post
  *
  * Process data that was not part of the 
  * initial streams call.
  *
  * @return 	void
  */
 private function _process_post(&$post)
 {
     $this->load->helper('text');
     // Keywords array
     $keywords = Keywords::get($post['keywords']);
     $formatted_keywords = array();
     $keywords_arr = array();
     foreach ($keywords as $key) {
         $formatted_keywords[] = array('keyword' => $key->name);
         $keywords_arr[] = $key->name;
     }
     $post['keywords'] = $formatted_keywords;
     $post['keywords_arr'] = $keywords_arr;
     // Full URL for convenience.
     $post['url'] = site_url('alert/' . $post['id'] . '/' . date('Y/m/d', $post['created_on']) . '/' . $post['slug']);
     if (file_exists(UPLOAD_PATH . 'alert/' . $post['image']) && is_file(UPLOAD_PATH . 'alert/' . $post['image'])) {
         $image = UPLOAD_PATH . 'alert/' . $post['image'];
     } else {
         $image = UPLOAD_PATH . 'no_image.jpg';
     }
     $this->load->model('files/image_m');
     $post['thumb_detail'] = $this->image_m->resize($image, 200, 150, 'crop');
     // What is the preview? If there is a field called intro,
     // we will use that, otherwise we will cut down the alert post itself.
     $post['preview'] = isset($post['intro']) ? $post['intro'] : $post['body'];
     // Category
     /*if ($post['category_id'] > 0 and isset($this->categories[$post['category_id']]))
     		{
     			$post['category'] = $this->categories[$post['category_id']];
     		}*/
 }
Exemplo n.º 3
0
 /**
  * Blog List
  *
  * Creates a list of blog posts. Takes all of the parameters
  * available to streams, sans stream, where, and namespace.
  *
  * Usage:
  * {{ blog:posts limit="5" }}
  *		<h2>{{ title }}</h2>
  * {{ /blog:posts }}
  *
  * @param	array
  * @return	array
  */
 public function posts()
 {
     $this->load->driver('Streams');
     // Get all of our default entry items:
     $params = $this->streams->entries->entries_params;
     // Override them with some settings
     // that should be these values:
     $overrides = array('stream' => 'news', 'namespace' => 'news', 'where' => array("`status` = 'live'"), 'order_by' => 'created_on', 'sort' => 'desc', 'show_past' => 'no', 'date_by' => 'created_on', 'limit' => $this->attribute('limit', null), 'offset' => $this->attribute('offset'));
     foreach ($overrides as $k => $v) {
         $params[$k] = $v;
     }
     // Convert our two non-matching posts params to their
     // stream counterparts. This is for backwards compatability.
     // Order by
     if ($this->attribute('order-by')) {
         $params['order_by'] = $this->attribute('order-by');
     } elseif ($this->attribute('order_by')) {
         $params['order_by'] = $this->attribute('order_by');
     }
     // Sort
     if ($this->attribute('order-dir')) {
         $params['sort'] = $this->attribute('order-dir');
     } elseif ($this->attribute('order_by')) {
         $params['sort'] = $this->attribute('sort');
     }
     // See if we have any attributes to contribute.
     foreach ($params as $key => $default_value) {
         if (!in_array($key, array('where', 'stream', 'namespace'))) {
             $params[$key] = $this->attribute($key, $default_value);
         }
     }
     // Categories
     // We need to filter by certain categories
     if ($category_string = $this->attribute('category')) {
         $categories = explode('|', $category_string);
         $cate_filter_by = array();
         foreach ($categories as $category) {
             $cate_filter_by[] = '`' . $this->db->dbprefix('news_categories') . '`.`' . (is_numeric($category) ? 'id' : 'slug') . '` = \'' . $category . "'";
         }
         if ($cate_filter_by) {
             $params['where'][] = implode(' OR ', $cate_filter_by);
         }
     }
     // Extra join and selects for categories.
     $this->row_m->sql['select'][] = $this->db->protect_identifiers('news_categories.title', true) . " as 'category_title'";
     $this->row_m->sql['select'][] = $this->db->protect_identifiers('news_categories.slug', true) . " as 'category_slug'";
     $this->row_m->sql['select'][] = $this->db->protect_identifiers('news_categories.title', true) . " as 'category||title'";
     $this->row_m->sql['select'][] = $this->db->protect_identifiers('news_categories.slug', true) . " as 'category||slug'";
     $this->row_m->sql['join'][] = 'LEFT JOIN ' . $this->db->protect_identifiers('news_categories', true) . ' ON ' . $this->db->protect_identifiers('news_categories.id', true) . ' = ' . $this->db->protect_identifiers('news.category_id', true);
     // Get our posts.
     $posts = $this->streams->entries->get_entries($params);
     if ($posts['entries']) {
         // Process posts.
         // Each post needs some special treatment.
         foreach ($posts['entries'] as &$post) {
             $this->load->helper('text');
             $this->load->model('files/image_m');
             // Keywords array
             $keywords = Keywords::get($post['keywords']);
             $formatted_keywords = array();
             $keywords_arr = array();
             foreach ($keywords as $key) {
                 $formatted_keywords[] = array('keyword' => $key->name);
                 $keywords_arr[] = $key->name;
             }
             $post['keywords'] = $formatted_keywords;
             $post['keywords_arr'] = $keywords_arr;
             // Full URL for convenience.
             $post['url'] = site_url('news/' . date('Y/m/d', $post['created_on']) . '/' . $post['slug']);
             $post['date'] = indonesian_date(date('Y/m/d H:i:s', $post['created_on']));
             $post['intro'] = word_limiter($post['intro'], 15);
             if (file_exists(UPLOAD_PATH . 'news/' . $post['image']) && is_file(UPLOAD_PATH . 'news/' . $post['image'])) {
                 $image = UPLOAD_PATH . 'news/' . $post['image'];
             } else {
                 $image = UPLOAD_PATH . 'no_image.jpg';
             }
             $post['thumb_70x70'] = $this->image_m->resize($image, 70, 70, 'crop');
             $post['thumb_690x370'] = $this->image_m->resize($image, 690, 370, 'crop');
             // What is the preview? If there is a field called intro,
             // we will use that, otherwise we will cut down the blog post itself.
             $post['preview'] = isset($post['intro']) ? $post['intro'] : $post['body'];
         }
     }
     // {{ entries }} Bypass.
     // However, users can use {{ entries }} if using pagination.
     $loop = false;
     if (preg_match('/\\{\\{\\s?entries\\s?\\}\\}/', $this->content()) == 0) {
         $posts = $posts['entries'];
         $loop = true;
     }
     // Return our content.
     return $this->streams->parse->parse_tag_content($this->content(), $posts, 'news', 'news', $loop);
 }
Exemplo n.º 4
0
 /**
  * Process Post
  *
  * Process data that was not part of the 
  * initial streams call.
  *
  * @return 	void
  */
 public function process_post(&$post)
 {
     $this->load->helper('text');
     // Keywords array
     $keywords = Keywords::get($post->keywords);
     $formatted_keywords = array();
     $keywords_arr = array();
     foreach ($keywords as $key) {
         $formatted_keywords[] = array('keyword' => $key->name);
         $keywords_arr[] = $key->name;
     }
     $post->keywords = $formatted_keywords;
     $post->keywords_arr = $keywords_arr;
     // Full URL for convenience.
     $post->url = site_url('news/' . date('Y/m/d', $post->created_on) . '/' . $post->slug);
     // What is the preview? If there is a field called intro,
     // we will use that, otherwise we will cut down the news post itself.
     $post->preview = isset($post->intro) ? $post->intro : $post->body;
     // Category
     if ($post->category_id > 0 and isset($this->categories[$post->category_id])) {
         $post->category = $this->categories[$post->category_id];
     }
 }
Exemplo n.º 5
0
 /**
  * Children list
  *
  * Creates a list of child pages one level under the parent page.
  *
  * Attributes:
  * - (int) limit: How many pages to show.
  * - (string) order-by: One of the column names from the `pages` table.
  * - (string) order-dir: Either `asc` or `desc`
  *
  * Usage:
  * {{ pages:children id="1" limit="5" }}
  *  <h2>{{title}}</h2>
  *      {{body}}
  * {{ /pages:children }}
  *
  * @return array
  */
 public function children()
 {
     $limit = $this->attribute('limit', null);
     $offset = $this->attribute('offset');
     $order_by = $this->attribute('order-by', 'order');
     $order_dir = $this->attribute('order-dir', 'ASC');
     $page_types = $this->attribute('include-types', $this->attribute('include_types'));
     // Restrict page types.
     // Page types can be provided in a pipe (|) delimited string.
     // Ex: 4|6
     if ($page_types) {
         $types = explode('|', $page_types);
         foreach ($types as $type) {
             $this->db->where('pages.type_id', $type);
         }
     }
     $pages = $this->db->select('pages.*, page_types.stream_id, page_types.slug as page_type_slug, page_types.title as page_type_title')->where('pages.parent_id', $this->attribute('id'))->where('status', 'live')->join('page_types', 'page_types.id = pages.type_id', 'left')->order_by($order_by, $order_dir)->limit($limit)->offset($offset)->get('pages')->result_array();
     // Custom fields provision.
     // Since page children can have many different page types,
     // we are going to do this in the most economical way possible:
     // Find the entries by ID and attach them to a special custom_fields
     // variable.
     if (is_scalar($this->content()) and strpos($this->content(), 'custom_fields') !== false and $pages) {
         $custom_fields = array();
         $this->load->driver('Streams');
         // Get all of the IDs by page type id.
         // Ex: array('page_type_id' => array('1', '2'))
         $entries = array();
         foreach ($pages as $page) {
             $entries[$page['stream_id']][] = $page['entry_id'];
         }
         // Get our entries by steram
         foreach ($entries as $stream_id => $entry_ids) {
             $stream = $this->streams_m->get_stream($stream_id);
             $params = array('stream' => $stream->stream_slug, 'namespace' => $stream->stream_namespace, 'include' => implode('|', $entry_ids), 'disable' => 'created_by');
             $entries = $this->streams->entries->get_entries($params);
             // Set the entries in our custom fields array for
             // easy reference later when processing our pages.
             foreach ($entries['entries'] as $entry) {
                 $custom_fields[$stream_id][$entry['id']] = $entry;
             }
         }
     } else {
         $custom_fields = false;
     }
     // Legacy support for chunks
     if ($pages and $this->db->table_exists('page_chunks')) {
         foreach ($pages as &$page) {
             // Grab all the chunks that make up the body for this page
             $page['chunks'] = $this->db->get_where('page_chunks', array('page_id' => $page['id']))->result_array();
             $page['body'] = '';
             if ($page['chunks']) {
                 foreach ($page['chunks'] as $chunk) {
                     $page['body'] .= '<div class="page-chunk ' . $chunk['slug'] . '">' . ($chunk['type'] == 'markdown' ? $chunk['parsed'] : $chunk['body']) . '</div>' . PHP_EOL;
                 }
             }
         }
     }
     // Process our pages.
     foreach ($pages as &$page) {
         // First, let's get a full URL. This is just
         // handy to have around.
         $page['url'] = site_url($page['uri']);
         // Now let's process our keywords hash.
         $keywords = Keywords::get($page['meta_keywords']);
         // In order to properly display the keywords in Lex
         // tags, we need to format them.
         $formatted_keywords = array();
         foreach ($keywords as $key) {
             $formatted_keywords[] = array('keyword' => $key->name);
         }
         $page['meta_keywords'] = $formatted_keywords;
         // If we have custom fields, we need to roll our
         // entry values in.
         if ($custom_fields and isset($custom_fields[$page['stream_id']][$page['entry_id']])) {
             $page['custom_fields'] = array($custom_fields[$page['stream_id']][$page['entry_id']]);
         }
     }
     //return '<pre>'.print_r($pages, true).'</pre>';
     return $pages;
 }
Exemplo n.º 6
0
 private function _single_view($post, $build = 'view')
 {
     // if it uses markdown then display the parsed version
     if ($post->type == 'markdown') {
         $post->body = $post->parsed;
     }
     // IF this post uses a category, grab it
     if ($post->category_id && ($category = $this->blog_categories_m->get($post->category_id))) {
         $post->category = $category;
     } else {
         $post->category->id = 0;
         $post->category->slug = '';
         $post->category->title = '';
     }
     $this->session->set_flashdata(array('referrer' => $this->uri->uri_string));
     $this->template->title($post->title, lang('blog_blog_title'))->set_metadata('description', $post->intro)->set_metadata('keywords', implode(', ', Keywords::get_array($post->keywords)))->set_breadcrumb(lang('blog_blog_title'), 'blog');
     if ($post->category->id > 0) {
         $this->template->set_breadcrumb($post->category->title, 'blog/category/' . $post->category->slug);
     }
     $post->keywords = Keywords::get($post->keywords);
     $this->template->set_breadcrumb($post->title)->set('post', $post)->build($build);
 }
Exemplo n.º 7
0
function keys_expand($mid, $sep = "-")
{
    global $xoopsDB, $keywords;
    if (empty($keywords)) {
        require_once dirname(__FILE__) . "/functions.php";
        $keywords = new Keywords();
    }
    $kres = $xoopsDB->query("SELECT keyref FROM " . RELAY . " WHERE midref=" . $mid);
    $keys = array();
    foreach ($keywords->getTree() as $key) {
        // roots order
        $keys[$key['keyid']] = array();
    }
    while (list($keyid) = $xoopsDB->fetchRow($kres)) {
        $root = find_root_id($keyid);
        $depth = find_root_id($keyid, true);
        $key = $keywords->get($keyid);
        if (!empty($key['keyid'])) {
            $keys[$root][$depth] = $key['name'];
        }
    }
    foreach ($keys as $id => $vals) {
        if ($vals) {
            $keys[$id] = join($sep, $vals);
        } else {
            unset($keys[$id]);
        }
    }
    return $keys;
}