2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Recent Blog Entries Block page.
20 * @package block_blog_recent
21 * @copyright 2009 Nicolas Connault
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') ||
die();
28 * This block simply outputs a list of links to recent blog entries, depending on
29 * the context of the current page.
31 class block_blog_recent
extends block_base
{
34 $this->title
= get_string('pluginname', 'block_blog_recent');
35 $this->content_type
= BLOCK_TYPE_TEXT
;
38 function applicable_formats() {
39 return array('all' => true, 'my' => false, 'tag' => false);
42 function instance_allow_config() {
46 function get_content() {
49 if ($this->content
!== NULL) {
50 return $this->content
;
53 // verify blog is enabled
54 if (empty($CFG->enableblogs
)) {
55 $this->content
= new stdClass();
56 $this->content
->text
= '';
57 if ($this->page
->user_is_editing()) {
58 $this->content
->text
= get_string('blogdisable', 'blog');
60 return $this->content
;
62 } else if ($CFG->bloglevel
< BLOG_GLOBAL_LEVEL
and (!isloggedin() or isguestuser())) {
63 $this->content
= new stdClass();
64 $this->content
->text
= '';
65 return $this->content
;
68 require_once($CFG->dirroot
.'/blog/lib.php');
69 require_once($CFG->dirroot
.'/blog/locallib.php');
71 if (empty($this->config
)) {
72 $this->config
= new stdClass();
75 if (empty($this->config
->recentbloginterval
)) {
76 $this->config
->recentbloginterval
= 8400;
79 if (empty($this->config
->numberofrecentblogentries
)) {
80 $this->config
->numberofrecentblogentries
= 4;
83 $this->content
= new stdClass();
84 $this->content
->footer
= '';
85 $this->content
->text
= '';
87 $context = $this->page
->context
;
89 $url = new moodle_url('/blog/index.php');
91 if ($context->contextlevel
== CONTEXT_MODULE
) {
92 $filter['module'] = $context->instanceid
;
94 $a->type
= get_string('modulename', $this->page
->cm
->modname
);
95 $strview = get_string('viewallmodentries', 'blog', $a);
96 $url->param('modid', $context->instanceid
);
97 } else if ($context->contextlevel
== CONTEXT_COURSE
) {
98 $filter['course'] = $context->instanceid
;
100 $a->type
= get_string('course');
101 $strview = get_string('viewblogentries', 'blog', $a);
102 $url->param('courseid', $context->instanceid
);
104 $strview = get_string('viewsiteentries', 'blog');
106 $filter['since'] = $this->config
->recentbloginterval
;
108 $bloglisting = new blog_listing($filter);
109 $entries = $bloglisting->get_entries(0, $this->config
->numberofrecentblogentries
, 4);
111 if (!empty($entries)) {
112 $entrieslist = array();
113 $viewblogurl = new moodle_url('/blog/index.php');
115 foreach ($entries as $entryid => $entry) {
116 $viewblogurl->param('entryid', $entryid);
117 $entrylink = html_writer
::link($viewblogurl, shorten_text($entry->subject
));
118 $entrieslist[] = $entrylink;
121 $this->content
->text
.= html_writer
::alist($entrieslist, array('class'=>'list'));
122 $viewallentrieslink = html_writer
::link($url, $strview);
123 $this->content
->text
.= $viewallentrieslink;
125 $this->content
->text
.= get_string('norecentblogentries', 'block_blog_recent');