. /** * Recent Blog Entries Block page. * * @package moodlecore * @subpackage blog * @copyright 2009 Nicolas Connault * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once($CFG->dirroot .'/blog/lib.php'); require_once($CFG->dirroot .'/blog/locallib.php'); /** * This block simply outputs a list of links to recent blog entries, depending on * the context of the current page. */ class block_blog_recent extends block_base { function init() { $this->title = get_string('blockrecenttitle', 'blog'); $this->content_type = BLOCK_TYPE_TEXT; $this->version = 2009070900; } function get_content() { global $CFG, $USER, $PAGE, $DB; $this->content = new stdClass(); $this->content->footer = ''; $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); } } $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; } $filters = array(); if (!empty($entryid)) { $filters['entry'] = $entryid; } if (!empty($groupid)) { $filters['group'] = $groupid; } if (!empty($tagid)) { $filters['tag'] = $tagid; } if (!empty($search)) { $filters['search'] = $search; } $blog_listing = new blog_listing($filters); $entries = $blog_listing->get_entries(0, get_user_preferences('blogrecententriesnumber', 4)); $this->content->text = '