Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blog Module + Fixes #316

Merged
merged 2 commits into from
May 5, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
186 changes: 186 additions & 0 deletions modules/gleez/classes/controller/feeds/blog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Blog Feed Controller
*
* @package Gleez\Feed\Controller
* @author Sandeep Sangamreddi - Gleez
* @copyright (c) 2011-2013 Gleez Technologies
* @license http://gleezcms.org/license Gleez CMS License
*/
class Controller_Feeds_Blog extends Controller_Feeds_Template {

/**
* Get list of pages
*
* @uses Config::load
* @uses Config_Group::get
* @uses URL::site
* @uses Cache::set
*/
public function action_list()
{
if ($this->_items === NULL OR empty($this->_items))
{
$config = Kohana::$config->load('blog');
// Cache is Empty so Re-Cache
$blogs = ORM::factory('blog')
->where('status', '=', 'publish')
->order_by('pubdate', 'DESC')
->limit($this->_limit)
->offset($this->_offset)
->find_all();

$items = array();
foreach($blogs as $blog)
{
$item = array();
$item['id'] = $blog->id;
$item['title'] = $blog->title;
$item['link'] = URL::site($blog->url, TRUE);
if ($config->get('use_submitted', FALSE))
{
$item['author'] = $blog->user->nick;
}
$item['description'] = $blog->teaser;
$item['pubDate'] = $blog->pubdate;

$items[] = $item;
}

$this->_cache->set($this->_cache_key, $items, DATE::HOUR); // 1 Hour
$this->_items = $items;
}

if (isset($this->_items[0]))
{
$this->_info['title'] = __('Pages - Recent updates');
$this->_info['pubDate'] = $this->_items[0]['pubDate'];
}
}

/**
* Get a list of pages with a specific term
*
* @throws HTTP_Exception_404
* @uses Config::load
* @uses Config_Group::get
* @uses Cache::set
* @uses Log::add
* @uses URL::site
*/
public function action_term()
{
if ($this->_items === NULL OR empty($this->_items))
{
$config = Kohana::$config->load('blog');
// Cache is Empty so Re-Cache
$id = (int) $this->request->param('id', 0);
$term = ORM::factory('term')
->where('id', '=', $id)
->where('type', '=', 'blog')
->where('lvl', '!=', 1)
->find();

if ( ! $term->loaded())
{
Kohana::$log->add(LOG::ERROR, 'Attempt to access non-existent blog term feed');
throw new HTTP_Exception_404(__('Term ":term" Not Found'), array(':term' => $id));
}

$posts = $term->posts
->where('status', '=', 'publish')
->order_by('pubdate', 'DESC')
->limit($this->_limit)
->offset($this->_offset)
->find_all();

$items = array();
foreach($posts as $blog)
{
$item = array();
$item['id'] = $blog->id;
$item['title'] = $blog->title;
$item['link'] = URL::site($blog->url, TRUE);
if ($config->get('use_submitted', FALSE))
{
$item['author'] = $blog->user->nick;
}
$item['description'] = $blog->teaser;
$item['pubDate'] = $blog->pubdate;

$items[] = $item;
}

$items['title'] = $term->name;
$this->_cache->set($this->_cache_key, $items, Date::HOUR); // 1 Hour
$this->_items = $items;
}

if (isset($this->_items[0]))
{
$this->_info['title'] = __(':term - Recent updates', array(':term' => ucfirst($this->_items['title'])));
$this->_info['pubDate'] = $this->_items[0]['pubDate'];
}
}

/**
* Get a list of pages with a specific tag
*
* @throws HTTP_Exception_404
* @uses Config::load
* @uses Config_Group::get
* @uses Log::add
* @uses URL::site
* @uses Cache::set
*/
public function action_tag()
{
if ($this->_items === NULL OR empty($this->_items))
{
$config = Kohana::$config->load('blog');
// Cache is Empty so Re-Cache
$id = (int) $this->request->param('id', 0);
$tag = ORM::factory('tag', array('id' => $id, 'type' => 'blog'));

if ( ! $tag->loaded())
{
Kohana::$log->add(LOG::ERROR, 'Attempt to access non-existent blog tag feed');
throw new HTTP_Exception_404(__('Tag ":tag" Not Found'), array(':tag' => $id));
}

$posts = $tag->posts
->where('status', '=', 'publish')
->order_by('pubdate', 'DESC')
->limit($this->_limit)
->offset($this->_offset)
->find_all();

$items = array();
foreach($posts as $blog)
{
$item = array();
$item['id'] = $blog->id;
$item['title'] = $blog->title;
$item['link'] = URL::site($blog->url, TRUE);
if ($config->get('use_submitted', FALSE))
{
$item['author'] = $blog->user->nick;
}
$item['description'] = $blog->teaser;
$item['pubDate'] = $blog->pubdate;

$items[] = $item;
}

$items['title'] = $tag->name;
$this->_cache->set($this->_cache_key, $items, Date::HOUR); // 1 Hour
$this->_items = $items;
}

if( isset($this->_items[0]))
{
$this->_info['title'] = __(':tag - Recent updates', array(':tag' => ucfirst($this->_items['title'])));
$this->_info['pubDate'] = $this->_items[0]['pubDate'];
}
}
}
26 changes: 26 additions & 0 deletions modules/gleez/classes/gleez/html.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,4 +377,30 @@ public static function label($text, $label = 'default')
{
return '<span class="label label-'.$label.'">'.$text.'</span>';
}

/**
* Generates an array for select list with `items per page` values
*
* @return array
*/
public static function per_page()
{
return array(
5 => 5,
10 => 10,
15 => 15,
20 => 20,
25 => 25,
30 => 30,
35 => 35,
40 => 40,
45 => 45,
50 => 50,
70 => 70,
100 => 100,
150 => 150,
250 => 250,
300 => 300,
);
}
}
26 changes: 0 additions & 26 deletions modules/gleez/classes/gleez/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -829,30 +829,4 @@ public static function dcache($id, $type, $config)
return $post;
}

/**
* Generates an array for select list with `items per page` values
*
* @return array
*/
public static function per_page()
{
return array(
5 => 5,
10 => 10,
15 => 15,
20 => 20,
25 => 25,
30 => 30,
35 => 35,
40 => 40,
45 => 45,
50 => 50,
70 => 70,
100 => 100,
150 => 150,
250 => 250,
300 => 300,
);
}

}
4 changes: 2 additions & 2 deletions modules/gleez/views/admin/blog/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class="control-group <?php echo isset($errors['items_per_page']) ? 'error': ''; ?>">
<?php echo Form::label('title', __('Blog entries per page'), array('class' => 'control-label')) ?>
<div class="controls">
<?php echo Form::select('items_per_page', Post::per_page(), $config['items_per_page'], array('class' => 'span2')); ?>
<?php echo Form::select('items_per_page', HTML::per_page(), $config['items_per_page'], array('class' => 'span2')); ?>
</div>
</div>

Expand Down Expand Up @@ -83,7 +83,7 @@
<div class="control-group <?php echo isset($errors['comments_per_page']) ? 'error': ''; ?>">
<?php echo Form::label('comments_per_page', __('Comments per page'), array('class' => 'control-label')); ?>
<div class="controls">
<?php echo Form::select('comments_per_page', Post::per_page(), isset($config['comments_per_page']) ? $config['comments_per_page'] : 50, array('class' => 'span2')); ?>
<?php echo Form::select('comments_per_page', HTML::per_page(), isset($config['comments_per_page']) ? $config['comments_per_page'] : 50, array('class' => 'span2')); ?>
</div>
</div>

Expand Down
4 changes: 2 additions & 2 deletions modules/gleez/views/admin/page/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<div class="control-group <?php echo isset($errors['items_per_page']) ? 'error': ''; ?>">
<?php echo Form::label('title', __('Page entries per page'), array('class' => 'control-label')) ?>
<div class="controls">
<?php echo Form::select('items_per_page', Post::per_page(), $post['items_per_page'], array('class' => 'span2')); ?>
<?php echo Form::select('items_per_page', HTML::per_page(), $post['items_per_page'], array('class' => 'span2')); ?>
</div>
</div>

Expand Down Expand Up @@ -103,7 +103,7 @@
<div class="control-group <?php echo isset($errors['comments_per_page']) ? 'error': ''; ?>">
<?php echo Form::label('comments_per_page', __('Comments per page'), array('class' => 'control-label')) ?>
<div class="controls">
<?php echo Form::select('comments_per_page', Post::per_page(), isset($post['comments_per_page']) ? $post['comments_per_page'] : 50, array('class' => 'span2')); ?>
<?php echo Form::select('comments_per_page', HTML::per_page(), isset($post['comments_per_page']) ? $post['comments_per_page'] : 50, array('class' => 'span2')); ?>
</div>
</div>

Expand Down