Widget base class
All widgets should extend this class.
Class declared in MODPATH/gleez/classes/widget/comment.php on line 3.
Widget $nameName
Widget $widgetObject
public function recent($widget)
{
// Dont show the widget on edit or delete actions.
quest::current()->action() == 'edit' OR Request::current()->action() == 'delete' )
n false;
= Cache::instance('widgets');
$comments = $cache->get('recent_comments') )
s = ORM::factory('comment')
oin('posts')
on('posts.id', '=', 'comment.post_id')
here('comment.status', '=', 'publish')
here('posts.status', '=', 'publish')
rder_by('comment.created', 'DESC')
imit(10)
ind_all();
ents = array();
ch($blogs as $blog)
ments[$blog->id]['id'] = $blog->id;
ments[$blog->id]['type'] = $blog->type;
ments[$blog->id]['title'] = $blog->title;
ments[$blog->id]['post_url'] = $blog->post->url;
omments[$blog->id] = (object)$blog->as_array();
the cache
e->set('recent_comments', $comments, DATE::HOUR);
View::factory('widgets/comment/list')->set('comments', $comments);
}
public function render()
{
switch($this->name)
{
case 'recent':
return $this->recent($this->widget);
break;
default:
return;
}
}
public function __construct($name, $widget)
{
$this->name = $name;
$this->widget = $widget;
}
public function __toString()
{
return $this->render();
}
Create a new widget instance
$widget = Widget::factory($name);
string
$name
required - Widget namewidget
$widget
required - Widget objectWidgetpublic static function factory($name, $widget)
{
// get class name if it has slash for multiple widgets, ex menu/managemnet or static/donate
$split_name = explode('/', $name);
$name = array_shift($split_name);
// Set class name
$widget_class = 'Widget_'.ucfirst($name);
$name = isset( $split_name[0] ) ? $split_name[0] : $name ;
return new $widget_class($name, $widget);
}