Skip to content

Commit

Permalink
blog MDL-22058 Fixed up blocks using the naughty blog_get_headers met…
Browse files Browse the repository at this point in the history
…hod, recent blogs and blog tags
  • Loading branch information
Sam Hemelryk committed May 11, 2010
1 parent 7bab527 commit 8eaf1ba
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
35 changes: 19 additions & 16 deletions blocks/blog_recent/block_blog_recent.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,27 @@ function get_content() {
$this->content = new stdClass();
$this->content->footer = '';

$context = $PAGE->context;

$blogheaders = blog_get_headers();

// Remove entryid filter
if (!empty($blogheaders['filters']['entry'])) {
unset($blogheaders['filters']['entry']);
$blogheaders['url']->remove_params(array('entryid'));
$context = $this->page->context;

$filter = array();
if ($context->contextlevel == CONTEXT_MODULE) {
$filter['module'] = $context->instanceid;
$a = new stdClass;
$a->type = get_string('modulename', $page->cm->modname);
$strview = get_string('viewallmodentries', 'blog', $a);
} else if ($context->contextlevel == CONTEXT_COURSE) {
$filter['course'] = $context->instanceid;
$a = new stdClass;
$a->type = get_string('course');
$strview = get_string('viewblogentries', 'blog', $a);
} else {
$strview = get_string('viewsiteentries', 'blog');
}
$filter['since'] = $this->config->recentbloginterval;

$blogheaders['filters']['since'] = $this->config->recentbloginterval;

$bloglisting = new blog_listing($blogheaders['filters']);
$bloglisting = new blog_listing($filter);
$entries = $bloglisting->get_entries(0, $this->config->numberofrecentblogentries, 4);
$url = new moodle_url('/blog/index.php', $filter);

if (!empty($entries)) {
$entrieslist = array();
Expand All @@ -100,11 +107,7 @@ function get_content() {
}

$this->content->text .= html_writer::alist($entrieslist, array('class'=>'list'));
$strview = get_string('viewsiteentries', 'blog');
if (!empty($blogheaders['strview'])) {
$strview = $blogheaders['strview'];
}
$viewallentrieslink = html_writer::link($blogheaders['url'], $strview);
$viewallentrieslink = html_writer::link($url, $strview);
$this->content->text .= $viewallentrieslink;
} else {
$this->content->text .= get_string('norecentblogentries', 'block_blog_recent');
Expand Down
20 changes: 9 additions & 11 deletions blocks/blog_tags/block_blog_tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function get_content() {
/// Get a list of tags
$timewithin = time() - $this->config->timewithin * 24 * 60 * 60; /// convert to seconds

$blogheaders = blog_get_headers();
$context = $this->page->context;

// admins should be able to read all tags
$type = '';
Expand All @@ -85,12 +85,10 @@ function get_content() {
AND ti.itemtype = 'post'
AND ti.timemodified > $timewithin";

if (!empty($blogheaders['filters']['module'])) {
$modulecontext = get_context_instance(CONTEXT_MODULE, $blogheaders['filters']['module']);
$sql .= " AND ba.contextid = $modulecontext->id AND p.id = ba.blogid ";
} else if (!empty($blogheaders['filters']['course'])) {
$coursecontext = get_context_instance(CONTEXT_COURSE, $blogheaders['filters']['course']);
$sql .= " AND ba.contextid = $coursecontext->id AND p.id = ba.blogid ";
if ($context->contextlevel == CONTEXT_MODULE) {
$sql .= " AND ba.contextid = $context->id AND p.id = ba.blogid ";
} else if ($context->contextlevel == CONTEXT_COURSE) {
$sql .= " AND ba.contextid = $context->id AND p.id = ba.blogid ";
}

$sql .= "
Expand Down Expand Up @@ -144,10 +142,10 @@ function get_content() {
break;

default:
if (!empty($blogheaders['filters']['module'])) {
$blogurl->param('modid', $blogheaders['filters']['module']);
} else if (!empty($blogheaders['filters']['course'])) {
$blogurl->param('courseid', $blogheaders['filters']['course']);
if ($context->contextlevel == CONTEXT_MODULE) {
$blogurl->param('modid', $context->instanceid);
} else if ($context->contextlevel == CONTEXT_COURSE) {
$blogurl->param('courseid', $context->instanceid);
}

break;
Expand Down
2 changes: 1 addition & 1 deletion blog/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ public function __construct($id=null, $type='site') {
$this->type = $type;
}

$this->availabletypes = array('site' => get_string('site'), 'course' => get_string('course'), 'module' => get_string('module'));
$this->availabletypes = array('site' => get_string('site'), 'course' => get_string('course'), 'module' => get_string('activity'));

switch ($this->type) {
case 'course': // Careful of site course!
Expand Down

0 comments on commit 8eaf1ba

Please sign in to comment.