$this->version = 2009070900;
}
+ function applicable_formats() {
+ return array('all' => true, 'my' => false, 'tag' => false);
+ }
+
+ function has_config() {
+ return true;
+ }
+
+ function instance_allow_config() {
+ return true;
+ }
+
function get_content() {
- global $CFG, $USER, $PAGE, $DB;
+ global $CFG, $USER, $PAGE, $DB, $OUTPUT;
- $this->content = new stdClass();
- $this->content->footer = '';
+ if (empty($this->config->recentbloginterval)) {
+ $this->config->recentbloginterval = 8400;
+ }
- $tag = optional_param('tag', null, PARAM_NOTAGS);
- $tagid = optional_param('tagid', null, PARAM_INT);
- $entryid = optional_param('entryid', null, PARAM_INT);
- $groupid = optional_param('groupid', null, PARAM_INT);
- $search = optional_param('search', null, PARAM_RAW);
-
- //correct tagid if a text tag is provided as a param
- if (!empty($tag)) { //text tag parameter takes precedence
- if ($tagrec = $DB->get_record_sql("SELECT * FROM {tag} WHERE name LIKE ?", array($tag))) {
- $tagid = $tagrec->id;
- } else {
- unset($tagid);
- }
+ if (empty($this->config->numberofrecentblogentries)) {
+ $this->config->numberofrecentblogentries = 4;
}
- $context = $PAGE->get_context();
-
- $strlevel = '';
-
- switch ($context->contextlevel) {
- case CONTEXT_COURSE:
- $strlevel = ($context->instanceid == SITEID) ? '' : get_string('course');
- break;
- case CONTEXT_MODULE:
- $strlevel = print_context_name($context);
- break;
- case CONTEXT_USER:
- $strlevel = get_string('user');
- break;
+ if (empty($CFG->bloglevel) || ($CFG->bloglevel < BLOG_GLOBAL_LEVEL && !(isloggedin() && !isguestuser()))) {
+ $this->content->text = '';
+ if ($this->page->user_is_editing()) {
+ $this->content->text = get_string('blogdisable', 'blog');
+ }
+ return $this->content;
}
- $filters = array();
+ $this->content = new stdClass();
+ $this->content->footer = '';
- if (!empty($entryid)) {
- $filters['entry'] = $entryid;
- }
+ $context = $PAGE->get_context();
- if (!empty($groupid)) {
- $filters['group'] = $groupid;
- }
+ $blogheaders = blog_get_headers();
- if (!empty($tagid)) {
- $filters['tag'] = $tagid;
+ // Remove entryid filter
+ if (!empty($blogheaders['filters']['entry'])) {
+ unset($blogheaders['filters']['entry']);
+ $blogheaders['url']->remove_params(array('entryid'));
}
- if (!empty($search)) {
- $filters['search'] = $search;
- }
+ $blogheaders['filters']['since'] = $this->config->recentbloginterval;
- $blog_listing = new blog_listing($filters);
- $entries = $blog_listing->get_entries(0, get_user_preferences('blogrecententriesnumber', 4));
+ $bloglisting = new blog_listing($blogheaders['filters']);
+ $entries = $bloglisting->get_entries(0, $this->config->numberofrecentblogentries, 4);
- $this->content->text = '<ul class="list">';
- $viewblog_url = $CFG->wwwroot . '/blog/index.php?entryid=';
+ if (!empty($entries)) {
+ $entrieslist = new html_list();
+ $entrieslist->add_class('list');
+ $viewblogurl = new moodle_url($CFG->wwwroot . '/blog/index.php');
- foreach ($entries as $entry_id => $entry) {
- $this->content->text .= "<li><a href=\"$viewblog_url$entry_id\">".shorten_text($entry->subject)."</a></li>\n";
- }
+ foreach ($entries as $entryid => $entry) {
+ $viewblogurl->param('entryid', $entryid);
+ $entrylink = html_link::make($viewblogurl, shorten_text($entry->subject));
+ $entrieslist->add_item($OUTPUT->link($entrylink));
+ }
- $this->content->text .= '<li> </li>';
- $this->content->text .= '<li><a href="'.blog_get_context_url().'">'.get_string('viewallblogentries', 'blog', $strlevel).'</a></li>';
- $this->content->text .= '</ul>';
+ $this->content->text .= $OUTPUT->htmllist($entrieslist);
+ $strview = get_string('viewsiteentries', 'blog');
+ if (!empty($blogheaders['strview'])) {
+ $strview = $blogheaders['strview'];
+ }
+ $viewallentrieslink = html_link::make($blogheaders['url'], $strview);
+ $this->content->text .= $OUTPUT->link($viewallentrieslink);
+ } else {
+ $this->content->text .= get_string('norecentblogentries', 'block_blog_recent');
+ }
}
}
--- /dev/null
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Form for editing tag block instances.
+ *
+ * @package moodlecore
+ * @copyright 2009 Tim Hunt
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+/**
+ * Form for editing tag block instances.
+ *
+ * @copyright 2009 Tim Hunt
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class block_blog_recent_edit_form extends block_edit_form {
+ protected function specific_definition($mform) {
+ // Fields for editing HTML block title and contents.
+ $mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
+
+ $numberofentries = array();
+ for ($i = 1; $i <= 20; $i++) {
+ $numberofentries[$i] = $i;
+ }
+
+ $mform->addElement('select', 'config_numberofrecentblogentries', get_string('numentriestodisplay', 'block_blog_recent'), $numberofentries);
+ $mform->setDefault('config_numberofrecentblogentries', 4);
+
+
+ $intervals = array(
+ 7200 => get_string('numhours', '', 2),
+ 14400 => get_string('numhours', '', 4),
+ 21600 => get_string('numhours', '', 6),
+ 43200 => get_string('numhours', '', 12),
+ 86400 => get_string('numhours', '', 24),
+ 172800 => get_string('numdays', '', 2),
+ 604800 => get_string('numdays', '', 7)
+ );
+
+ $mform->addElement('select', 'config_recentbloginterval', get_string('recentinterval', 'block_blog_recent'), $intervals);
+ $mform->setDefault('config_recentbloginterval', 86400);
+ }
+}