MDL-46346 blog: coding style fixes

This commit is contained in:
Andrew Davis 2014-07-13 18:43:09 +08:00
parent e9fb99b15c
commit 2b6e53e8e2
13 changed files with 340 additions and 276 deletions

View file

@ -1,5 +1,4 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/ // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify
@ -25,8 +24,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
require_once(dirname(dirname(__FILE__)).'/config.php'); require_once(dirname(dirname(__FILE__)).'/config.php');
include_once('lib.php'); require_once('lib.php');
include_once('locallib.php'); require_once('locallib.php');
$action = required_param('action', PARAM_ALPHA); $action = required_param('action', PARAM_ALPHA);
$id = optional_param('entryid', 0, PARAM_INT); $id = optional_param('entryid', 0, PARAM_INT);
@ -38,9 +37,13 @@ if ($action == 'edit') {
$id = required_param('entryid', PARAM_INT); $id = required_param('entryid', PARAM_INT);
} }
$PAGE->set_url('/blog/edit.php', array('action' => $action, 'entryid' => $id, 'confirm' => $confirm, 'modid' => $modid, 'courseid' => $courseid)); $PAGE->set_url('/blog/edit.php', array('action' => $action,
'entryid' => $id,
'confirm' => $confirm,
'modid' => $modid,
'courseid' => $courseid));
// If action is add, we ignore $id to avoid any further problems // If action is add, we ignore $id to avoid any further problems.
if (!empty($id) && $action == 'add') { if (!empty($id) && $action == 'add') {
$id = null; $id = null;
} }
@ -65,7 +68,7 @@ if (!empty($courseid) && empty($modid)) {
$returnurl->param('courseid', $courseid); $returnurl->param('courseid', $courseid);
} }
// If a modid is given, guess courseid // If a modid is given, guess courseid.
if (!empty($modid)) { if (!empty($modid)) {
$returnurl->param('modid', $modid); $returnurl->param('modid', $modid);
$courseid = $DB->get_field('course_modules', 'course', array('id' => $modid)); $courseid = $DB->get_field('course_modules', 'course', array('id' => $modid));
@ -78,7 +81,7 @@ if (!has_capability('moodle/blog:create', $sitecontext) && !has_capability('mood
print_error('cannoteditentryorblog'); print_error('cannoteditentryorblog');
} }
// Make sure that the person trying to edit has access right // Make sure that the person trying to edit has access right.
if ($id) { if ($id) {
if (!$entry = new blog_entry($id)) { if (!$entry = new blog_entry($id)) {
print_error('wrongentryid', 'blog'); print_error('wrongentryid', 'blog');
@ -93,7 +96,7 @@ if ($id) {
} else { } else {
if (!has_capability('moodle/blog:create', $sitecontext)) { if (!has_capability('moodle/blog:create', $sitecontext)) {
print_error('noentry', 'blog'); // manageentries is not enough for adding print_error('noentry', 'blog'); // The capability "manageentries" is not enough for adding.
} }
$entry = new stdClass(); $entry = new stdClass();
$entry->id = null; $entry->id = null;
@ -104,14 +107,14 @@ $returnurl->param('userid', $userid);
// Blog renderer. // Blog renderer.
$output = $PAGE->get_renderer('blog'); $output = $PAGE->get_renderer('blog');
$strblogs = get_string('blogs','blog'); $strblogs = get_string('blogs', 'blog');
if ($action === 'delete'){ if ($action === 'delete') {
if (empty($entry->id)) { if (empty($entry->id)) {
print_error('wrongentryid', 'blog'); print_error('wrongentryid', 'blog');
} }
if (data_submitted() && $confirm && confirm_sesskey()) { if (data_submitted() && $confirm && confirm_sesskey()) {
// Make sure the current user is the author of the blog entry, or has some deleteanyentry capability // Make sure the current user is the author of the blog entry, or has some deleteanyentry capability.
if (!blog_user_can_edit_entry($entry)) { if (!blog_user_can_edit_entry($entry)) {
print_error('nopermissionstodeleteentry', 'blog'); print_error('nopermissionstodeleteentry', 'blog');
} else { } else {
@ -131,7 +134,9 @@ if ($action === 'delete'){
echo $output->render($entry); echo $output->render($entry);
echo '<br />'; echo '<br />';
echo $OUTPUT->confirm(get_string('blogdeleteconfirm', 'blog'), new moodle_url('edit.php', $optionsyes),new moodle_url( 'index.php', $optionsno)); echo $OUTPUT->confirm(get_string('blogdeleteconfirm', 'blog'),
new moodle_url('edit.php', $optionsyes),
new moodle_url('index.php', $optionsno));
echo $OUTPUT->footer(); echo $OUTPUT->footer();
die; die;
} }
@ -166,10 +171,21 @@ $summaryoptions = array('maxfiles'=> 99, 'maxbytes'=>$CFG->maxbytes, 'trusttext'
'subdirs'=>file_area_contains_subdirs($sitecontext, 'blog', 'post', $entry->id)); 'subdirs'=>file_area_contains_subdirs($sitecontext, 'blog', 'post', $entry->id));
$attachmentoptions = array('subdirs'=>false, 'maxfiles'=> 99, 'maxbytes'=>$CFG->maxbytes); $attachmentoptions = array('subdirs'=>false, 'maxfiles'=> 99, 'maxbytes'=>$CFG->maxbytes);
$blogeditform = new blog_edit_form(null, compact('entry', 'summaryoptions', 'attachmentoptions', 'sitecontext', 'courseid', 'modid')); $blogeditform = new blog_edit_form(null, compact('entry',
'summaryoptions',
'attachmentoptions',
'sitecontext',
'courseid',
'modid'));
$entry = file_prepare_standard_editor($entry, 'summary', $summaryoptions, $sitecontext, 'blog', 'post', $entry->id); $entry = file_prepare_standard_editor($entry, 'summary', $summaryoptions, $sitecontext, 'blog', 'post', $entry->id);
$entry = file_prepare_standard_filemanager($entry, 'attachment', $attachmentoptions, $sitecontext, 'blog', 'attachment', $entry->id); $entry = file_prepare_standard_filemanager($entry,
'attachment',
$attachmentoptions,
$sitecontext,
'blog',
'attachment',
$entry->id);
if (!empty($CFG->usetags) && !empty($entry->id)) { if (!empty($CFG->usetags) && !empty($entry->id)) {
include_once($CFG->dirroot.'/tag/lib.php'); include_once($CFG->dirroot.'/tag/lib.php');
@ -177,13 +193,13 @@ if (!empty($CFG->usetags) && !empty($entry->id)) {
} }
$entry->action = $action; $entry->action = $action;
// set defaults // Set defaults.
$blogeditform->set_data($entry); $blogeditform->set_data($entry);
if ($blogeditform->is_cancelled()) { if ($blogeditform->is_cancelled()) {
redirect($returnurl); redirect($returnurl);
} else if ($data = $blogeditform->get_data()){ } else if ($data = $blogeditform->get_data()) {
switch ($action) { switch ($action) {
case 'add': case 'add':
@ -208,23 +224,23 @@ if ($blogeditform->is_cancelled()) {
} }
// gui setup // GUI setup.
switch ($action) { switch ($action) {
case 'add': case 'add':
// prepare new empty form // Prepare new empty form.
$entry->publishstate = 'site'; $entry->publishstate = 'site';
$strformheading = get_string('addnewentry', 'blog'); $strformheading = get_string('addnewentry', 'blog');
$entry->action = $action; $entry->action = $action;
if ($CFG->useblogassociations) { if ($CFG->useblogassociations) {
//pre-select the course for associations // Pre-select the course for associations.
if ($courseid) { if ($courseid) {
$context = context_course::instance($courseid); $context = context_course::instance($courseid);
$entry->courseassoc = $context->id; $entry->courseassoc = $context->id;
} }
//pre-select the mod for associations // Pre-select the mod for associations.
if ($modid) { if ($modid) {
$context = context_module::instance($modid); $context = context_module::instance($modid);
$entry->modassoc = $context->id; $entry->modassoc = $context->id;

View file

@ -1,5 +1,4 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/ // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify
@ -16,7 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
if (!defined('MOODLE_INTERNAL')) { if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
} }
require_once($CFG->libdir.'/formslib.php'); require_once($CFG->libdir.'/formslib.php');
@ -24,7 +23,10 @@ require_once($CFG->libdir.'/formslib.php');
class blog_edit_form extends moodleform { class blog_edit_form extends moodleform {
public $modnames = array(); public $modnames = array();
function definition() { /**
* Blog form definition.
*/
public function definition() {
global $CFG, $DB; global $CFG, $DB;
$mform =& $this->_form; $mform =& $this->_form;
@ -50,12 +52,12 @@ class blog_edit_form extends moodleform {
$mform->addElement('filemanager', 'attachment_filemanager', get_string('attachment', 'forum'), null, $attachmentoptions); $mform->addElement('filemanager', 'attachment_filemanager', get_string('attachment', 'forum'), null, $attachmentoptions);
//disable publishstate options that are not allowed // Disable publishstate options that are not allowed.
$publishstates = array(); $publishstates = array();
$i = 0; $i = 0;
foreach (blog_entry::get_applicable_publish_states() as $state => $desc) { foreach (blog_entry::get_applicable_publish_states() as $state => $desc) {
$publishstates[$state] = $desc; //no maximum was set $publishstates[$state] = $desc; // No maximum was set.
$i++; $i++;
} }
@ -87,7 +89,12 @@ class blog_edit_form extends moodleform {
} }
$mform->addElement('header', 'assochdr', get_string('associations', 'blog')); $mform->addElement('header', 'assochdr', get_string('associations', 'blog'));
$mform->addElement('advcheckbox', 'courseassoc', get_string('associatewithcourse', 'blog', $a), null, null, array(0, $contextid)); $mform->addElement('advcheckbox',
'courseassoc',
get_string('associatewithcourse', 'blog', $a),
null,
null,
array(0, $contextid));
$mform->setDefault('courseassoc', $contextid); $mform->setDefault('courseassoc', $contextid);
} else if ((!empty($entry->modassoc) || !empty($modid))) { } else if ((!empty($entry->modassoc) || !empty($modid))) {
@ -107,7 +114,12 @@ class blog_edit_form extends moodleform {
} }
$mform->addElement('header', 'assochdr', get_string('associations', 'blog')); $mform->addElement('header', 'assochdr', get_string('associations', 'blog'));
$mform->addElement('advcheckbox', 'modassoc', get_string('associatewithmodule', 'blog', $a), null, null, array(0, $context->id)); $mform->addElement('advcheckbox',
'modassoc',
get_string('associatewithmodule', 'blog', $a),
null,
null,
array(0, $context->id));
$mform->setDefault('modassoc', $context->id); $mform->setDefault('modassoc', $context->id);
} }
} }
@ -130,12 +142,17 @@ class blog_edit_form extends moodleform {
$mform->setDefault('courseid', $courseid); $mform->setDefault('courseid', $courseid);
} }
function validation($data, $files) { /**
* Validate the blog form data.
* @param $data array Data to be validated
* @param $files void unused
*/
public function validation($data, $files) {
global $CFG, $DB, $USER; global $CFG, $DB, $USER;
$errors = array(); $errors = array();
// validate course association // Validate course association.
if (!empty($data['courseassoc'])) { if (!empty($data['courseassoc'])) {
$coursecontext = context::instance_by_id($data['courseassoc']); $coursecontext = context::instance_by_id($data['courseassoc']);
@ -144,16 +161,16 @@ class blog_edit_form extends moodleform {
} }
} }
// validate mod association // Validate mod association.
if (!empty($data['modassoc'])) { if (!empty($data['modassoc'])) {
$modcontextid = $data['modassoc']; $modcontextid = $data['modassoc'];
$modcontext = context::instance_by_id($modcontextid); $modcontext = context::instance_by_id($modcontextid);
if ($modcontext->contextlevel == CONTEXT_MODULE) { if ($modcontext->contextlevel == CONTEXT_MODULE) {
// get context of the mod's course // Get context of the mod's course.
$coursecontext = $modcontext->get_course_context(true); $coursecontext = $modcontext->get_course_context(true);
// ensure only one course is associated // Ensure only one course is associated.
if (!empty($data['courseassoc'])) { if (!empty($data['courseassoc'])) {
if ($data['courseassoc'] != $coursecontext->id) { if ($data['courseassoc'] != $coursecontext->id) {
$errors['modassoc'] = get_string('onlyassociateonecourse', 'blog'); $errors['modassoc'] = get_string('onlyassociateonecourse', 'blog');

View file

@ -1,5 +1,4 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/ // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify
@ -35,7 +34,9 @@ require_login();
$context = context_system::instance(); $context = context_system::instance();
require_capability('moodle/blog:manageexternal', $context); require_capability('moodle/blog:manageexternal', $context);
// TODO redirect if $CFG->useexternalblogs is off, $CFG->maxexternalblogsperuser == 0, or if user doesn't have caps to manage external blogs // TODO redirect if $CFG->useexternalblogs is off,
// $CFG->maxexternalblogsperuser == 0,
// or if user doesn't have caps to manage external blogs.
$id = optional_param('id', null, PARAM_INT); $id = optional_param('id', null, PARAM_INT);
$url = new moodle_url('/blog/external_blog_edit.php'); $url = new moodle_url('/blog/external_blog_edit.php');
@ -52,24 +53,24 @@ $action = (empty($id)) ? 'add' : 'edit';
$external = new stdClass(); $external = new stdClass();
// Check that this id exists // Check that this id exists.
if (!empty($id) && !$DB->record_exists('blog_external', array('id' => $id))) { if (!empty($id) && !$DB->record_exists('blog_external', array('id' => $id))) {
print_error('wrongexternalid', 'blog'); print_error('wrongexternalid', 'blog');
} elseif (!empty($id)) { } else if (!empty($id)) {
$external = $DB->get_record('blog_external', array('id' => $id)); $external = $DB->get_record('blog_external', array('id' => $id));
} }
$strformheading = ($action == 'edit') ? get_string('editexternalblog', 'blog') : get_string('addnewexternalblog', 'blog'); $strformheading = ($action == 'edit') ? get_string('editexternalblog', 'blog') : get_string('addnewexternalblog', 'blog');
$strexternalblogs = get_string('externalblogs','blog'); $strexternalblogs = get_string('externalblogs', 'blog');
$strblogs = get_string('blogs','blog'); $strblogs = get_string('blogs', 'blog');
$externalblogform = new blog_edit_external_form(); $externalblogform = new blog_edit_external_form();
if ($externalblogform->is_cancelled()){ if ($externalblogform->is_cancelled()) {
redirect($returnurl); redirect($returnurl);
} else if ($data = $externalblogform->get_data()) { } else if ($data = $externalblogform->get_data()) {
//save stuff in db // Save stuff in db.
switch ($action) { switch ($action) {
case 'add': case 'add':
$rss = new moodle_simplepie($data->url); $rss = new moodle_simplepie($data->url);

View file

@ -1,5 +1,4 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/ // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify
@ -26,7 +25,7 @@
*/ */
if (!defined('MOODLE_INTERNAL')) { if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
} }
require_once($CFG->libdir.'/formslib.php'); require_once($CFG->libdir.'/formslib.php');
@ -120,7 +119,7 @@ class blog_edit_external_form extends moodleform {
$mform->freeze('url'); $mform->freeze('url');
$mform->freeze('filtertags'); $mform->freeze('filtertags');
// TODO change the filtertags element to a multiple select, using the tags of the external blog // TODO change the filtertags element to a multiple select, using the tags of the external blog
// Use $rss->get_channel_tags() // Use $rss->get_channel_tags().
} }
} }
} }

View file

@ -1,5 +1,4 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/ // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify
@ -36,23 +35,25 @@ require_capability('moodle/blog:manageexternal', $context);
$delete = optional_param('delete', null, PARAM_INT); $delete = optional_param('delete', null, PARAM_INT);
$strexternalblogs = get_string('externalblogs','blog'); $strexternalblogs = get_string('externalblogs', 'blog');
$straddnewexternalblog = get_string('addnewexternalblog','blog'); $straddnewexternalblog = get_string('addnewexternalblog', 'blog');
$strblogs = get_string('blogs','blog'); $strblogs = get_string('blogs', 'blog');
$message = null; $message = null;
if ($delete && confirm_sesskey()) { if ($delete && confirm_sesskey()) {
$externalbloguserid = $DB->get_field('blog_external', 'userid', array('id' => $delete)); $externalbloguserid = $DB->get_field('blog_external', 'userid', array('id' => $delete));
if ($externalbloguserid == $USER->id) { if ($externalbloguserid == $USER->id) {
// Delete the external blog // Delete the external blog.
$DB->delete_records('blog_external', array('id' => $delete)); $DB->delete_records('blog_external', array('id' => $delete));
// Delete the external blog's posts // Delete the external blog's posts.
$deletewhere = 'module = :module $deletewhere = 'module = :module
AND userid = :userid AND userid = :userid
AND ' . $DB->sql_isnotempty('post', 'uniquehash', false, false) . ' AND ' . $DB->sql_isnotempty('post', 'uniquehash', false, false) . '
AND ' . $DB->sql_compare_text('content') . ' = ' . $DB->sql_compare_text(':delete'); AND ' . $DB->sql_compare_text('content') . ' = ' . $DB->sql_compare_text(':delete');
$DB->delete_records_select('post', $deletewhere, array('module' => 'blog_external', 'userid' => $USER->id, 'delete' => $delete)); $DB->delete_records_select('post', $deletewhere, array('module' => 'blog_external',
'userid' => $USER->id,
'delete' => $delete));
$message = get_string('externalblogdeleted', 'blog'); $message = get_string('externalblogdeleted', 'blog');
} }
@ -77,7 +78,11 @@ if (!empty($blogs)) {
$table = new html_table(); $table = new html_table();
$table->cellpadding = 4; $table->cellpadding = 4;
$table->attributes['class'] = 'generaltable boxaligncenter'; $table->attributes['class'] = 'generaltable boxaligncenter';
$table->head = array(get_string('name'), get_string('url', 'blog'), get_string('timefetched', 'blog'), get_string('valid', 'blog'), get_string('actions')); $table->head = array(get_string('name'),
get_string('url', 'blog'),
get_string('timefetched', 'blog'),
get_string('valid', 'blog'),
get_string('actions'));
foreach ($blogs as $blog) { foreach ($blogs as $blog) {
if ($blog->failedlastsync) { if ($blog->failedlastsync) {
@ -92,7 +97,11 @@ if (!empty($blogs)) {
$deletelink = new moodle_url('/blog/external_blogs.php', array('delete' => $blog->id, 'sesskey'=>sesskey())); $deletelink = new moodle_url('/blog/external_blogs.php', array('delete' => $blog->id, 'sesskey'=>sesskey()));
$deleteicon = $OUTPUT->action_icon($deletelink, new pix_icon('t/delete', get_string('deleteexternalblog', 'blog'))); $deleteicon = $OUTPUT->action_icon($deletelink, new pix_icon('t/delete', get_string('deleteexternalblog', 'blog')));
$table->data[] = new html_table_row(array($blog->name, $blog->url, userdate($blog->timefetched), $validicon, $editicon . '&nbsp'. $deleteicon)); $table->data[] = new html_table_row(array($blog->name,
$blog->url,
userdate($blog->timefetched),
$validicon,
$editicon . '&nbsp'. $deleteicon));
} }
echo html_writer::table($table); echo html_writer::table($table);
} }

View file

@ -1,4 +1,18 @@
<?php <?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/>.
/** /**
* file index.php * file index.php
@ -34,7 +48,7 @@ foreach ($url_params as $var => $val) {
} }
$PAGE->set_url('/blog/index.php', $url_params); $PAGE->set_url('/blog/index.php', $url_params);
//correct tagid if a text tag is provided as a param // Correct tagid if a text tag is provided as a param.
if (!empty($tag)) { if (!empty($tag)) {
if ($tagrec = $DB->get_record('tag', array('name' => $tag))) { if ($tagrec = $DB->get_record('tag', array('name' => $tag))) {
$tagid = $tagrec->id; $tagid = $tagrec->id;
@ -47,27 +61,27 @@ $sitecontext = context_system::instance();
// Blogs are always in system context. // Blogs are always in system context.
$PAGE->set_context($sitecontext); $PAGE->set_context($sitecontext);
// check basic permissions // Check basic permissions.
if ($CFG->bloglevel == BLOG_GLOBAL_LEVEL) { if ($CFG->bloglevel == BLOG_GLOBAL_LEVEL) {
// everybody can see anything - no login required unless site is locked down using forcelogin // Everybody can see anything - no login required unless site is locked down using forcelogin.
if ($CFG->forcelogin) { if ($CFG->forcelogin) {
require_login(); require_login();
} }
} else if ($CFG->bloglevel == BLOG_SITE_LEVEL) { } else if ($CFG->bloglevel == BLOG_SITE_LEVEL) {
// users must log in and can not be guests // Users must log in and can not be guests.
require_login(); require_login();
if (isguestuser()) { if (isguestuser()) {
// they must have entered the url manually... // They must have entered the url manually.
print_error('blogdisable', 'blog'); print_error('blogdisable', 'blog');
} }
} else if ($CFG->bloglevel == BLOG_USER_LEVEL) { } else if ($CFG->bloglevel == BLOG_USER_LEVEL) {
// users can see own blogs only! with the exception of ppl with special cap // Users can see own blogs only! with the exception of people with special cap.
require_login(); require_login();
} else { } else {
// weird! // Weird!
print_error('blogdisable', 'blog'); print_error('blogdisable', 'blog');
} }
@ -206,13 +220,10 @@ if ($CFG->enablerssfeeds) {
} }
$rsstitle = $blogheaders['heading']; $rsstitle = $blogheaders['heading'];
//check we haven't started output by outputting an error message // Check we haven't started output by outputting an error message.
if ($PAGE->state == moodle_page::STATE_BEFORE_HEADER) { if ($PAGE->state == moodle_page::STATE_BEFORE_HEADER) {
blog_rss_add_http_header($rsscontext, $rsstitle, $filtertype, $thingid, $tagid); blog_rss_add_http_header($rsscontext, $rsstitle, $filtertype, $thingid, $tagid);
} }
//this works but there isn't a great place to put the link
//blog_rss_print_link($rsscontext, $filtertype, $thingid, $tagid);
} }
echo $OUTPUT->header(); echo $OUTPUT->header();

View file

@ -1,5 +1,4 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/ // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify
@ -26,7 +25,7 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
/** /*
* Library of functions and constants for blog * Library of functions and constants for blog
*/ */
require_once($CFG->dirroot .'/blog/rsslib.php'); require_once($CFG->dirroot .'/blog/rsslib.php');
@ -45,11 +44,11 @@ function blog_user_can_edit_entry($blogentry) {
$sitecontext = context_system::instance(); $sitecontext = context_system::instance();
if (has_capability('moodle/blog:manageentries', $sitecontext)) { if (has_capability('moodle/blog:manageentries', $sitecontext)) {
return true; // can edit any blog entry return true; // Can edit any blog entry.
} }
if ($blogentry->userid == $USER->id && has_capability('moodle/blog:create', $sitecontext)) { if ($blogentry->userid == $USER->id && has_capability('moodle/blog:create', $sitecontext)) {
return true; // can edit own when having blog:create capability return true; // Can edit own when having blog:create capability.
} }
return false; return false;
@ -168,12 +167,12 @@ function blog_sync_external_entries($externalblog) {
if (empty($rss->data)) { if (empty($rss->data)) {
return null; return null;
} }
//used to identify blog posts that have been deleted from the source feed // Used to identify blog posts that have been deleted from the source feed.
$oldesttimestamp = null; $oldesttimestamp = null;
$uniquehashes = array(); $uniquehashes = array();
foreach ($rss->get_items() as $entry) { foreach ($rss->get_items() as $entry) {
// If filtertags are defined, use them to filter the entries by RSS category // If filtertags are defined, use them to filter the entries by RSS category.
if (!empty($externalblog->filtertags)) { if (!empty($externalblog->filtertags)) {
$containsfiltertag = false; $containsfiltertag = false;
$categories = $entry->get_categories(); $categories = $entry->get_categories();
@ -201,26 +200,26 @@ function blog_sync_external_entries($externalblog) {
$newentry->uniquehash = $entry->get_permalink(); $newentry->uniquehash = $entry->get_permalink();
$newentry->publishstate = 'site'; $newentry->publishstate = 'site';
$newentry->format = FORMAT_HTML; $newentry->format = FORMAT_HTML;
// Clean subject of html, just in case // Clean subject of html, just in case.
$newentry->subject = clean_param($entry->get_title(), PARAM_TEXT); $newentry->subject = clean_param($entry->get_title(), PARAM_TEXT);
// Observe 128 max chars in DB // Observe 128 max chars in DB.
// TODO: +1 to raise this to 255 // TODO: +1 to raise this to 255.
if (core_text::strlen($newentry->subject) > 128) { if (core_text::strlen($newentry->subject) > 128) {
$newentry->subject = core_text::substr($newentry->subject, 0, 125) . '...'; $newentry->subject = core_text::substr($newentry->subject, 0, 125) . '...';
} }
$newentry->summary = $entry->get_description(); $newentry->summary = $entry->get_description();
//used to decide whether to insert or update // Used to decide whether to insert or update.
//uses enty permalink plus creation date if available // Uses enty permalink plus creation date if available.
$existingpostconditions = array('uniquehash' => $entry->get_permalink()); $existingpostconditions = array('uniquehash' => $entry->get_permalink());
//our DB doesnt allow null creation or modified timestamps so check the external blog supplied one // Our DB doesnt allow null creation or modified timestamps so check the external blog supplied one.
$entrydate = $entry->get_date('U'); $entrydate = $entry->get_date('U');
if (!empty($entrydate)) { if (!empty($entrydate)) {
$existingpostconditions['created'] = $entrydate; $existingpostconditions['created'] = $entrydate;
} }
//the post ID or false if post not found in DB // The post ID or false if post not found in DB.
$postid = $DB->get_field('post', 'id', $existingpostconditions); $postid = $DB->get_field('post', 'id', $existingpostconditions);
$timestamp = null; $timestamp = null;
@ -230,14 +229,14 @@ function blog_sync_external_entries($externalblog) {
$timestamp = $entrydate; $timestamp = $entrydate;
} }
//only set created if its a new post so we retain the original creation timestamp if the post is edited // Only set created if its a new post so we retain the original creation timestamp if the post is edited.
if ($postid === false) { if ($postid === false) {
$newentry->created = $timestamp; $newentry->created = $timestamp;
} }
$newentry->lastmodified = $timestamp; $newentry->lastmodified = $timestamp;
if (empty($oldesttimestamp) || $timestamp < $oldesttimestamp) { if (empty($oldesttimestamp) || $timestamp < $oldesttimestamp) {
//found an older post // Found an older post.
$oldesttimestamp = $timestamp; $oldesttimestamp = $timestamp;
} }
@ -252,7 +251,7 @@ function blog_sync_external_entries($externalblog) {
if ($postid === false) { if ($postid === false) {
$id = $DB->insert_record('post', $newentry); $id = $DB->insert_record('post', $newentry);
// Set tags // Set tags.
if ($tags = tag_get_tags_array('blog_external', $externalblog->id)) { if ($tags = tag_get_tags_array('blog_external', $externalblog->id)) {
tag_set('post', $id, $tags, 'core', context_user::instance($externalblog->userid)->id); tag_set('post', $id, $tags, 'core', context_user::instance($externalblog->userid)->id);
} }
@ -273,7 +272,7 @@ function blog_sync_external_entries($externalblog) {
$dbposts = $DB->get_records_sql($sql, array('blogid' => $externalblog->id, 'ts' => $oldesttimestamp)); $dbposts = $DB->get_records_sql($sql, array('blogid' => $externalblog->id, 'ts' => $oldesttimestamp));
$todelete = array(); $todelete = array();
foreach($dbposts as $dbpost) { foreach ($dbposts as $dbpost) {
if ( !in_array($dbpost->uniquehash, $uniquehashes) ) { if ( !in_array($dbpost->uniquehash, $uniquehashes) ) {
$todelete[] = $dbpost->id; $todelete[] = $dbpost->id;
} }
@ -324,13 +323,13 @@ function blog_get_all_options(moodle_page $page, stdClass $userid = null) {
$options = array(); $options = array();
// If blogs are enabled and the user is logged in and not a guest // If blogs are enabled and the user is logged in and not a guest.
if (blog_is_enabled_for_user()) { if (blog_is_enabled_for_user()) {
// If the context is the user then assume we want to load for the users context // If the context is the user then assume we want to load for the users context.
if (is_null($userid) && $page->context->contextlevel == CONTEXT_USER) { if (is_null($userid) && $page->context->contextlevel == CONTEXT_USER) {
$userid = $page->context->instanceid; $userid = $page->context->instanceid;
} }
// Check the userid var // Check the userid var.
if (!is_null($userid) && $userid!==$USER->id) { if (!is_null($userid) && $userid!==$USER->id) {
// Load the user from the userid... it MUST EXIST throw a wobbly if it doesn't! // Load the user from the userid... it MUST EXIST throw a wobbly if it doesn't!
$user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST); $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
@ -339,33 +338,36 @@ function blog_get_all_options(moodle_page $page, stdClass $userid = null) {
} }
if ($CFG->useblogassociations && $page->cm !== null) { if ($CFG->useblogassociations && $page->cm !== null) {
// Load for the module associated with the page // Load for the module associated with the page.
$options[CONTEXT_MODULE] = blog_get_options_for_module($page->cm, $user); $options[CONTEXT_MODULE] = blog_get_options_for_module($page->cm, $user);
} else if ($CFG->useblogassociations && $page->course->id != SITEID) { } else if ($CFG->useblogassociations && $page->course->id != SITEID) {
// Load the options for the course associated with the page // Load the options for the course associated with the page.
$options[CONTEXT_COURSE] = blog_get_options_for_course($page->course, $user); $options[CONTEXT_COURSE] = blog_get_options_for_course($page->course, $user);
} }
// Get the options for the user // Get the options for the user.
if ($user !== null and !isguestuser($user)) { if ($user !== null and !isguestuser($user)) {
// Load for the requested user // Load for the requested user.
$options[CONTEXT_USER+1] = blog_get_options_for_user($user); $options[CONTEXT_USER+1] = blog_get_options_for_user($user);
} }
// Load for the current user // Load for the current user.
if (isloggedin() and !isguestuser()) { if (isloggedin() and !isguestuser()) {
$options[CONTEXT_USER] = blog_get_options_for_user(); $options[CONTEXT_USER] = blog_get_options_for_user();
} }
} }
// If blog level is global then display a link to view all site entries // If blog level is global then display a link to view all site entries.
if (!empty($CFG->enableblogs) && $CFG->bloglevel >= BLOG_GLOBAL_LEVEL && has_capability('moodle/blog:view', context_system::instance())) { if (!empty($CFG->enableblogs)
&& $CFG->bloglevel >= BLOG_GLOBAL_LEVEL
&& has_capability('moodle/blog:view', context_system::instance())) {
$options[CONTEXT_SYSTEM] = array('viewsite' => array( $options[CONTEXT_SYSTEM] = array('viewsite' => array(
'string' => get_string('viewsiteentries', 'blog'), 'string' => get_string('viewsiteentries', 'blog'),
'link' => new moodle_url('/blog/index.php') 'link' => new moodle_url('/blog/index.php')
)); ));
} }
// Return the options // Return the options.
return $options; return $options;
} }
@ -380,16 +382,16 @@ function blog_get_all_options(moodle_page $page, stdClass $userid = null) {
*/ */
function blog_get_options_for_user(stdClass $user=null) { function blog_get_options_for_user(stdClass $user=null) {
global $CFG, $USER; global $CFG, $USER;
// Cache // Cache.
static $useroptions = array(); static $useroptions = array();
$options = array(); $options = array();
// Blogs must be enabled and the user must be logged in // Blogs must be enabled and the user must be logged in.
if (!blog_is_enabled_for_user()) { if (!blog_is_enabled_for_user()) {
return $options; return $options;
} }
// Sort out the user var // Sort out the user var.
if ($user === null || $user->id == $USER->id) { if ($user === null || $user->id == $USER->id) {
$user = $USER; $user = $USER;
$iscurrentuser = true; $iscurrentuser = true;
@ -397,7 +399,7 @@ function blog_get_options_for_user(stdClass $user=null) {
$iscurrentuser = false; $iscurrentuser = false;
} }
// If we've already generated serve from the cache // If we've already generated serve from the cache.
if (array_key_exists($user->id, $useroptions)) { if (array_key_exists($user->id, $useroptions)) {
return $useroptions[$user->id]; return $useroptions[$user->id];
} }
@ -406,22 +408,22 @@ function blog_get_options_for_user(stdClass $user=null) {
$canview = has_capability('moodle/blog:view', $sitecontext); $canview = has_capability('moodle/blog:view', $sitecontext);
if (!$iscurrentuser && $canview && ($CFG->bloglevel >= BLOG_SITE_LEVEL)) { if (!$iscurrentuser && $canview && ($CFG->bloglevel >= BLOG_SITE_LEVEL)) {
// Not the current user, but we can view and its blogs are enabled for SITE or GLOBAL // Not the current user, but we can view and its blogs are enabled for SITE or GLOBAL.
$options['userentries'] = array( $options['userentries'] = array(
'string' => get_string('viewuserentries', 'blog', fullname($user)), 'string' => get_string('viewuserentries', 'blog', fullname($user)),
'link' => new moodle_url('/blog/index.php', array('userid'=>$user->id)) 'link' => new moodle_url('/blog/index.php', array('userid'=>$user->id))
); );
} else { } else {
// It's the current user // It's the current user.
if ($canview) { if ($canview) {
// We can view our own blogs .... BIG surprise // We can view our own blogs .... BIG surprise.
$options['view'] = array( $options['view'] = array(
'string' => get_string('viewallmyentries', 'blog'), 'string' => get_string('viewallmyentries', 'blog'),
'link' => new moodle_url('/blog/index.php', array('userid'=>$USER->id)) 'link' => new moodle_url('/blog/index.php', array('userid'=>$USER->id))
); );
} }
if (has_capability('moodle/blog:create', $sitecontext)) { if (has_capability('moodle/blog:create', $sitecontext)) {
// We can add to our own blog // We can add to our own blog.
$options['add'] = array( $options['add'] = array(
'string' => get_string('addnewentry', 'blog'), 'string' => get_string('addnewentry', 'blog'),
'link' => new moodle_url('/blog/edit.php', array('action'=>'add')) 'link' => new moodle_url('/blog/edit.php', array('action'=>'add'))
@ -432,12 +434,12 @@ function blog_get_options_for_user(stdClass $user=null) {
$options['rss'] = array( $options['rss'] = array(
'string' => get_string('rssfeed', 'blog'), 'string' => get_string('rssfeed', 'blog'),
'link' => new moodle_url(rss_get_url($sitecontext->id, $USER->id, 'blog', 'user/'.$user->id)) 'link' => new moodle_url(rss_get_url($sitecontext->id, $USER->id, 'blog', 'user/'.$user->id))
); );
} }
// Cache the options // Cache the options.
$useroptions[$user->id] = $options; $useroptions[$user->id] = $options;
// Return the options // Return the options.
return $options; return $options;
} }
@ -451,47 +453,46 @@ function blog_get_options_for_user(stdClass $user=null) {
*/ */
function blog_get_options_for_course(stdClass $course, stdClass $user=null) { function blog_get_options_for_course(stdClass $course, stdClass $user=null) {
global $CFG, $USER; global $CFG, $USER;
// Cache // Cache.
static $courseoptions = array(); static $courseoptions = array();
$options = array(); $options = array();
// User must be logged in and blogs must be enabled // User must be logged in and blogs must be enabled.
if (!blog_is_enabled_for_user()) { if (!blog_is_enabled_for_user()) {
return $options; return $options;
} }
// Check that the user can associate with the course // Check that the user can associate with the course.
$sitecontext = context_system::instance(); $sitecontext = context_system::instance();
// Generate the cache key // Generate the cache key.
$key = $course->id.':'; $key = $course->id.':';
if (!empty($user)) { if (!empty($user)) {
$key .= $user->id; $key .= $user->id;
} else { } else {
$key .= $USER->id; $key .= $USER->id;
} }
// Serve from the cache if we've already generated for this course // Serve from the cache if we've already generated for this course.
if (array_key_exists($key, $courseoptions)) { if (array_key_exists($key, $courseoptions)) {
return $courseoptions[$key]; return $courseoptions[$key];
} }
if (has_capability('moodle/blog:view', $sitecontext)) { if (has_capability('moodle/blog:view', $sitecontext)) {
// We can view! // We can view!
if ($CFG->bloglevel >= BLOG_SITE_LEVEL) { if ($CFG->bloglevel >= BLOG_SITE_LEVEL) {
// View entries about this course // View entries about this course.
$options['courseview'] = array( $options['courseview'] = array(
'string' => get_string('viewcourseblogs', 'blog'), 'string' => get_string('viewcourseblogs', 'blog'),
'link' => new moodle_url('/blog/index.php', array('courseid' => $course->id)) 'link' => new moodle_url('/blog/index.php', array('courseid' => $course->id))
); );
} }
// View MY entries about this course // View MY entries about this course.
$options['courseviewmine'] = array( $options['courseviewmine'] = array(
'string' => get_string('viewmyentriesaboutcourse', 'blog'), 'string' => get_string('viewmyentriesaboutcourse', 'blog'),
'link' => new moodle_url('/blog/index.php', array('courseid' => $course->id, 'userid' => $USER->id)) 'link' => new moodle_url('/blog/index.php', array('courseid' => $course->id, 'userid' => $USER->id))
); );
if (!empty($user) && ($CFG->bloglevel >= BLOG_SITE_LEVEL)) { if (!empty($user) && ($CFG->bloglevel >= BLOG_SITE_LEVEL)) {
// View the provided users entries about this course // View the provided users entries about this course.
$options['courseviewuser'] = array( $options['courseviewuser'] = array(
'string' => get_string('viewentriesbyuseraboutcourse', 'blog', fullname($user)), 'string' => get_string('viewentriesbyuseraboutcourse', 'blog', fullname($user)),
'link' => new moodle_url('/blog/index.php', array('courseid' => $course->id, 'userid' => $user->id)) 'link' => new moodle_url('/blog/index.php', array('courseid' => $course->id, 'userid' => $user->id))
@ -500,17 +501,16 @@ function blog_get_options_for_course(stdClass $course, stdClass $user=null) {
} }
if (has_capability('moodle/blog:create', $sitecontext)) { if (has_capability('moodle/blog:create', $sitecontext)) {
// We can blog about this course // We can blog about this course.
$options['courseadd'] = array( $options['courseadd'] = array(
'string' => get_string('blogaboutthiscourse', 'blog'), 'string' => get_string('blogaboutthiscourse', 'blog'),
'link' => new moodle_url('/blog/edit.php', array('action' => 'add', 'courseid' => $course->id)) 'link' => new moodle_url('/blog/edit.php', array('action' => 'add', 'courseid' => $course->id))
); );
} }
// Cache the options for this course.
// Cache the options for this course
$courseoptions[$key] = $options; $courseoptions[$key] = $options;
// Return the options // Return the options.
return $options; return $options;
} }
@ -524,18 +524,18 @@ function blog_get_options_for_course(stdClass $course, stdClass $user=null) {
*/ */
function blog_get_options_for_module($module, $user=null) { function blog_get_options_for_module($module, $user=null) {
global $CFG, $USER; global $CFG, $USER;
// Cache // Cache.
static $moduleoptions = array(); static $moduleoptions = array();
$options = array(); $options = array();
// User must be logged in, blogs must be enabled // User must be logged in, blogs must be enabled.
if (!blog_is_enabled_for_user()) { if (!blog_is_enabled_for_user()) {
return $options; return $options;
} }
$sitecontext = context_system::instance(); $sitecontext = context_system::instance();
// Generate the cache key // Generate the cache key.
$key = $module->id.':'; $key = $module->id.':';
if (!empty($user)) { if (!empty($user)) {
$key .= $user->id; $key .= $user->id;
@ -543,18 +543,17 @@ function blog_get_options_for_module($module, $user=null) {
$key .= $USER->id; $key .= $USER->id;
} }
if (array_key_exists($key, $moduleoptions)) { if (array_key_exists($key, $moduleoptions)) {
// Serve from the cache so we don't have to regenerate // Serve from the cache so we don't have to regenerate.
return $moduleoptions[$key]; return $moduleoptions[$key];
} }
if (has_capability('moodle/blog:view', $sitecontext)) { if (has_capability('moodle/blog:view', $sitecontext)) {
// Save correct module name for later usage. // Save correct module name for later usage.
$modulename = get_string('modulename', $module->modname); $modulename = get_string('modulename', $module->modname);
// We can view! // We can view!
if ($CFG->bloglevel >= BLOG_SITE_LEVEL) { if ($CFG->bloglevel >= BLOG_SITE_LEVEL) {
// View all entries about this module // View all entries about this module.
$a = new stdClass; $a = new stdClass;
$a->type = $modulename; $a->type = $modulename;
$options['moduleview'] = array( $options['moduleview'] = array(
@ -562,13 +561,13 @@ function blog_get_options_for_module($module, $user=null) {
'link' => new moodle_url('/blog/index.php', array('modid'=>$module->id)) 'link' => new moodle_url('/blog/index.php', array('modid'=>$module->id))
); );
} }
// View MY entries about this module // View MY entries about this module.
$options['moduleviewmine'] = array( $options['moduleviewmine'] = array(
'string' => get_string('viewmyentriesaboutmodule', 'blog', $modulename), 'string' => get_string('viewmyentriesaboutmodule', 'blog', $modulename),
'link' => new moodle_url('/blog/index.php', array('modid'=>$module->id, 'userid'=>$USER->id)) 'link' => new moodle_url('/blog/index.php', array('modid'=>$module->id, 'userid'=>$USER->id))
); );
if (!empty($user) && ($CFG->bloglevel >= BLOG_SITE_LEVEL)) { if (!empty($user) && ($CFG->bloglevel >= BLOG_SITE_LEVEL)) {
// View the given users entries about this module // View the given users entries about this module.
$a = new stdClass; $a = new stdClass;
$a->mod = $modulename; $a->mod = $modulename;
$a->user = fullname($user); $a->user = fullname($user);
@ -580,15 +579,15 @@ function blog_get_options_for_module($module, $user=null) {
} }
if (has_capability('moodle/blog:create', $sitecontext)) { if (has_capability('moodle/blog:create', $sitecontext)) {
// The user can blog about this module // The user can blog about this module.
$options['moduleadd'] = array( $options['moduleadd'] = array(
'string' => get_string('blogaboutthismodule', 'blog', $modulename), 'string' => get_string('blogaboutthismodule', 'blog', $modulename),
'link' => new moodle_url('/blog/edit.php', array('action'=>'add', 'modid'=>$module->id)) 'link' => new moodle_url('/blog/edit.php', array('action'=>'add', 'modid'=>$module->id))
); );
} }
// Cache the options // Cache the options.
$moduleoptions[$key] = $options; $moduleoptions[$key] = $options;
// Return the options // Return the options.
return $options; return $options;
} }
@ -626,7 +625,7 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
$action = optional_param('action', null, PARAM_ALPHA); $action = optional_param('action', null, PARAM_ALPHA);
$confirm = optional_param('confirm', false, PARAM_BOOL); $confirm = optional_param('confirm', false, PARAM_BOOL);
// Ignore userid when action == add // Ignore userid when action == add.
if ($action == 'add' && $userid) { if ($action == 'add' && $userid) {
unset($userid); unset($userid);
$PAGE->url->remove_params(array('userid')); $PAGE->url->remove_params(array('userid'));
@ -644,11 +643,11 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
$site = $DB->get_record('course', array('id' => SITEID)); $site = $DB->get_record('course', array('id' => SITEID));
$sitecontext = context_system::instance(); $sitecontext = context_system::instance();
// Common Lang strings // Common Lang strings.
$strparticipants = get_string("participants"); $strparticipants = get_string("participants");
$strblogentries = get_string("blogentries", 'blog'); $strblogentries = get_string("blogentries", 'blog');
// Prepare record objects as needed // Prepare record objects as needed.
if (!empty($courseid)) { if (!empty($courseid)) {
$headers['filters']['course'] = $courseid; $headers['filters']['course'] = $courseid;
$course = $DB->get_record('course', array('id' => $courseid)); $course = $DB->get_record('course', array('id' => $courseid));
@ -659,7 +658,7 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
$user = $DB->get_record('user', array('id' => $userid)); $user = $DB->get_record('user', array('id' => $userid));
} }
if (!empty($groupid)) { // groupid always overrides courseid if (!empty($groupid)) { // The groupid always overrides courseid.
$headers['filters']['group'] = $groupid; $headers['filters']['group'] = $groupid;
$group = $DB->get_record('groups', array('id' => $groupid)); $group = $DB->get_record('groups', array('id' => $groupid));
$course = $DB->get_record('course', array('id' => $group->courseid)); $course = $DB->get_record('course', array('id' => $group->courseid));
@ -667,11 +666,11 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
$PAGE->set_pagelayout('standard'); $PAGE->set_pagelayout('standard');
// modid always overrides courseid, so the $course object may be reset here // The modid always overrides courseid, so the $course object may be reset here.
if (!empty($modid) && $CFG->useblogassociations) { if (!empty($modid) && $CFG->useblogassociations) {
$headers['filters']['module'] = $modid; $headers['filters']['module'] = $modid;
// A groupid param may conflict with this coursemod's courseid. Ignore groupid in that case // A groupid param may conflict with this coursemod's courseid. Ignore groupid in that case.
$courseid = $DB->get_field('course_modules', 'course', array('id'=>$modid)); $courseid = $DB->get_field('course_modules', 'course', array('id'=>$modid));
$course = $DB->get_record('course', array('id' => $courseid)); $course = $DB->get_record('course', array('id' => $courseid));
$cm = $DB->get_record('course_modules', array('id' => $modid)); $cm = $DB->get_record('course_modules', array('id' => $modid));
@ -685,17 +684,16 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
} }
// Case 1: No entry, mod, course or user params: all site entries to be shown (filtered by search and tag/tagid) // Case 1: No entry, mod, course or user params: all site entries to be shown (filtered by search and tag/tagid)
// Note: if action is set to 'add' or 'edit', we do this at the end // Note: if action is set to 'add' or 'edit', we do this at the end.
if (empty($entryid) && empty($modid) && empty($courseid) && empty($userid) && !in_array($action, array('edit', 'add'))) { if (empty($entryid) && empty($modid) && empty($courseid) && empty($userid) && !in_array($action, array('edit', 'add'))) {
$shortname = format_string($site->shortname, true, array('context' => context_course::instance(SITEID))); $shortname = format_string($site->shortname, true, array('context' => context_course::instance(SITEID)));
$PAGE->navbar->add($strblogentries, $blogurl); $PAGE->navbar->add($strblogentries, $blogurl);
$PAGE->set_title("$shortname: " . get_string('blog', 'blog')); $PAGE->set_title("$shortname: " . get_string('blog', 'blog'));
$PAGE->set_heading("$shortname: " . get_string('blog', 'blog')); $PAGE->set_heading("$shortname: " . get_string('blog', 'blog'));
$headers['heading'] = get_string('siteblog', 'blog', $shortname); $headers['heading'] = get_string('siteblog', 'blog', $shortname);
// $headers['strview'] = get_string('viewsiteentries', 'blog');
} }
// Case 2: only entryid is requested, ignore all other filters. courseid is used to give more contextual information // Case 2: only entryid is requested, ignore all other filters. courseid is used to give more contextual information.
if (!empty($entryid)) { if (!empty($entryid)) {
$headers['filters']['entry'] = $entryid; $headers['filters']['entry'] = $entryid;
$sql = 'SELECT u.* FROM {user} u, {post} p WHERE p.id = ? AND p.userid = u.id'; $sql = 'SELECT u.* FROM {user} u, {post} p WHERE p.id = ? AND p.userid = u.id';
@ -720,15 +718,16 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
$PAGE->set_heading("$shortname: " . fullname($user) . ": $entry->subject"); $PAGE->set_heading("$shortname: " . fullname($user) . ": $entry->subject");
$headers['heading'] = get_string('blogentrybyuser', 'blog', fullname($user)); $headers['heading'] = get_string('blogentrybyuser', 'blog', fullname($user));
// We ignore tag and search params // We ignore tag and search params.
if (empty($action) || !$CFG->useblogassociations) { if (empty($action) || !$CFG->useblogassociations) {
$headers['url'] = $blogurl; $headers['url'] = $blogurl;
return $headers; return $headers;
} }
} }
// Case 3: A user's blog entries
if (!empty($userid) && empty($entryid) && ((empty($courseid) && empty($modid)) || !$CFG->useblogassociations)) { if (!empty($userid) && empty($entryid) && ((empty($courseid) && empty($modid)) || !$CFG->useblogassociations)) {
// Case 3: A user's blog entries.
$shortname = format_string($site->shortname, true, array('context' => context_course::instance(SITEID))); $shortname = format_string($site->shortname, true, array('context' => context_course::instance(SITEID)));
$blogurl->param('userid', $userid); $blogurl->param('userid', $userid);
$PAGE->set_title("$shortname: " . fullname($user) . ": " . get_string('blog', 'blog')); $PAGE->set_title("$shortname: " . fullname($user) . ": " . get_string('blog', 'blog'));
@ -736,23 +735,21 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
$headers['heading'] = get_string('userblog', 'blog', fullname($user)); $headers['heading'] = get_string('userblog', 'blog', fullname($user));
$headers['strview'] = get_string('viewuserentries', 'blog', fullname($user)); $headers['strview'] = get_string('viewuserentries', 'blog', fullname($user));
} else } else if (!$CFG->useblogassociations && empty($userid) && !in_array($action, array('edit', 'add'))) {
// Case 4: No blog associations, no userid.
// Case 4: No blog associations, no userid
if (!$CFG->useblogassociations && empty($userid) && !in_array($action, array('edit', 'add'))) {
$shortname = format_string($site->shortname, true, array('context' => context_course::instance(SITEID))); $shortname = format_string($site->shortname, true, array('context' => context_course::instance(SITEID)));
$PAGE->set_title("$shortname: " . get_string('blog', 'blog')); $PAGE->set_title("$shortname: " . get_string('blog', 'blog'));
$PAGE->set_heading("$shortname: " . get_string('blog', 'blog')); $PAGE->set_heading("$shortname: " . get_string('blog', 'blog'));
$headers['heading'] = get_string('siteblog', 'blog', $shortname); $headers['heading'] = get_string('siteblog', 'blog', $shortname);
} else } else if (!empty($userid) && !empty($modid) && empty($entryid)) {
// Case 5: Blog entries associated with an activity by a specific user (courseid ignored).
// Case 5: Blog entries associated with an activity by a specific user (courseid ignored)
if (!empty($userid) && !empty($modid) && empty($entryid)) {
$shortname = format_string($site->shortname, true, array('context' => context_course::instance(SITEID))); $shortname = format_string($site->shortname, true, array('context' => context_course::instance(SITEID)));
$blogurl->param('userid', $userid); $blogurl->param('userid', $userid);
$blogurl->param('modid', $modid); $blogurl->param('modid', $modid);
// Course module navigation is handled by build_navigation as the second param // Course module navigation is handled by build_navigation as the second param.
$headers['cm'] = $cm; $headers['cm'] = $cm;
$PAGE->navbar->add(fullname($user), "$CFG->wwwroot/user/view.php?id=$user->id"); $PAGE->navbar->add(fullname($user), "$CFG->wwwroot/user/view.php?id=$user->id");
$PAGE->navbar->add($strblogentries, $blogurl); $PAGE->navbar->add($strblogentries, $blogurl);
@ -767,10 +764,9 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
$headers['heading'] = get_string('blogentriesbyuseraboutmodule', 'blog', $a); $headers['heading'] = get_string('blogentriesbyuseraboutmodule', 'blog', $a);
$headers['stradd'] = get_string('blogaboutthis', 'blog', $a); $headers['stradd'] = get_string('blogaboutthis', 'blog', $a);
$headers['strview'] = get_string('viewallmodentries', 'blog', $a); $headers['strview'] = get_string('viewallmodentries', 'blog', $a);
} else } else if (!empty($userid) && !empty($courseid) && empty($modid) && empty($entryid)) {
// Case 6: Blog entries associated with a course by a specific user.
// Case 6: Blog entries associated with a course by a specific user
if (!empty($userid) && !empty($courseid) && empty($modid) && empty($entryid)) {
$siteshortname = format_string($site->shortname, true, array('context' => context_course::instance(SITEID))); $siteshortname = format_string($site->shortname, true, array('context' => context_course::instance(SITEID)));
$courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id))); $courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
$blogurl->param('userid', $userid); $blogurl->param('userid', $userid);
@ -789,12 +785,11 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
$headers['stradd'] = get_string('blogaboutthis', 'blog', $a); $headers['stradd'] = get_string('blogaboutthis', 'blog', $a);
$headers['strview'] = get_string('viewblogentries', 'blog', $a); $headers['strview'] = get_string('viewblogentries', 'blog', $a);
// Remove the userid from the URL to inform the blog_menu block correctly // Remove the userid from the URL to inform the blog_menu block correctly.
$blogurl->remove_params(array('userid')); $blogurl->remove_params(array('userid'));
} else } else if (!empty($groupid) && empty($modid) && empty($entryid)) {
// Case 7: Blog entries by members of a group, associated with that group's course.
// Case 7: Blog entries by members of a group, associated with that group's course
if (!empty($groupid) && empty($modid) && empty($entryid)) {
$siteshortname = format_string($site->shortname, true, array('context' => context_course::instance(SITEID))); $siteshortname = format_string($site->shortname, true, array('context' => context_course::instance(SITEID)));
$courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id))); $courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
$blogurl->param('courseid', $course->id); $blogurl->param('courseid', $course->id);
@ -814,10 +809,9 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
$headers['heading'] = get_string('blogentriesbygroupaboutcourse', 'blog', $a); $headers['heading'] = get_string('blogentriesbygroupaboutcourse', 'blog', $a);
$headers['stradd'] = get_string('blogaboutthis', 'blog', $a); $headers['stradd'] = get_string('blogaboutthis', 'blog', $a);
$headers['strview'] = get_string('viewblogentries', 'blog', $a); $headers['strview'] = get_string('viewblogentries', 'blog', $a);
} else } else if (!empty($groupid) && !empty($modid) && empty($entryid)) {
// Case 8: Blog entries by members of a group, associated with an activity in that course.
// Case 8: Blog entries by members of a group, associated with an activity in that course
if (!empty($groupid) && !empty($modid) && empty($entryid)) {
$siteshortname = format_string($site->shortname, true, array('context' => context_course::instance(SITEID))); $siteshortname = format_string($site->shortname, true, array('context' => context_course::instance(SITEID)));
$courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id))); $courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
$headers['cm'] = $cm; $headers['cm'] = $cm;
@ -838,10 +832,9 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
$headers['stradd'] = get_string('blogaboutthis', 'blog', $a); $headers['stradd'] = get_string('blogaboutthis', 'blog', $a);
$headers['strview'] = get_string('viewallmodentries', 'blog', $a); $headers['strview'] = get_string('viewallmodentries', 'blog', $a);
} else } else if (!empty($modid) && empty($userid) && empty($groupid) && empty($entryid)) {
// Case 9: All blog entries associated with an activity.
// Case 9: All blog entries associated with an activity
if (!empty($modid) && empty($userid) && empty($groupid) && empty($entryid)) {
$siteshortname = format_string($site->shortname, true, array('context' => context_course::instance(SITEID))); $siteshortname = format_string($site->shortname, true, array('context' => context_course::instance(SITEID)));
$courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id))); $courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
$PAGE->set_cm($cm, $course); $PAGE->set_cm($cm, $course);
@ -854,10 +847,9 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
$a->type = get_string('modulename', $cm->modname); $a->type = get_string('modulename', $cm->modname);
$headers['stradd'] = get_string('blogaboutthis', 'blog', $a); $headers['stradd'] = get_string('blogaboutthis', 'blog', $a);
$headers['strview'] = get_string('viewallmodentries', 'blog', $a); $headers['strview'] = get_string('viewallmodentries', 'blog', $a);
} else } else if (!empty($courseid) && empty($userid) && empty($groupid) && empty($modid) && empty($entryid)) {
// Case 10: All blog entries associated with a course.
// Case 10: All blog entries associated with a course
if (!empty($courseid) && empty($userid) && empty($groupid) && empty($modid) && empty($entryid)) {
$siteshortname = format_string($site->shortname, true, array('context' => context_course::instance(SITEID))); $siteshortname = format_string($site->shortname, true, array('context' => context_course::instance(SITEID)));
$courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id))); $courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
$blogurl->param('courseid', $courseid); $blogurl->param('courseid', $courseid);
@ -866,20 +858,24 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
$PAGE->set_heading("$siteshortname: $courseshortname: " . get_string('blogentries', 'blog')); $PAGE->set_heading("$siteshortname: $courseshortname: " . get_string('blogentries', 'blog'));
$a = new stdClass(); $a = new stdClass();
$a->type = get_string('course'); $a->type = get_string('course');
$headers['heading'] = get_string('blogentriesabout', 'blog', format_string($course->fullname, true, array('context' => context_course::instance($course->id)))); $headers['heading'] = get_string('blogentriesabout',
'blog',
format_string($course->fullname,
true,
array('context' => context_course::instance($course->id))));
$headers['stradd'] = get_string('blogaboutthis', 'blog', $a); $headers['stradd'] = get_string('blogaboutthis', 'blog', $a);
$headers['strview'] = get_string('viewblogentries', 'blog', $a); $headers['strview'] = get_string('viewblogentries', 'blog', $a);
$blogurl->remove_params(array('userid')); $blogurl->remove_params(array('userid'));
} }
if (!in_array($action, array('edit', 'add'))) { if (!in_array($action, array('edit', 'add'))) {
// Append Tag info // Append Tag info.
if (!empty($tagid)) { if (!empty($tagid)) {
$headers['filters']['tag'] = $tagid; $headers['filters']['tag'] = $tagid;
$blogurl->param('tagid', $tagid); $blogurl->param('tagid', $tagid);
$tagrec = $DB->get_record('tag', array('id'=>$tagid)); $tagrec = $DB->get_record('tag', array('id'=>$tagid));
$PAGE->navbar->add($tagrec->name, $blogurl); $PAGE->navbar->add($tagrec->name, $blogurl);
} elseif (!empty($tag)) { } else if (!empty($tag)) {
if ($tagrec = $DB->get_record('tag', array('name' => $tag))) { if ($tagrec = $DB->get_record('tag', array('name' => $tag))) {
$tagid = $tagrec->id; $tagid = $tagrec->id;
$headers['filters']['tag'] = $tagid; $headers['filters']['tag'] = $tagid;
@ -888,7 +884,7 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
} }
} }
// Append Search info // Append Search info.
if (!empty($search)) { if (!empty($search)) {
$headers['filters']['search'] = $search; $headers['filters']['search'] = $search;
$blogurl->param('search', $search); $blogurl->param('search', $search);
@ -896,7 +892,7 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
} }
} }
// Append edit mode info // Append edit mode info.
if (!empty($action) && $action == 'add') { if (!empty($action) && $action == 'add') {
} else if (!empty($action) && $action == 'edit') { } else if (!empty($action) && $action == 'edit') {

View file

@ -1,5 +1,4 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/ // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify
@ -40,7 +39,7 @@ require_once($CFG->libdir . '/filelib.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
class blog_entry implements renderable { class blog_entry implements renderable {
// Public Database fields // Public Database fields.
public $id; public $id;
public $userid; public $userid;
public $subject; public $subject;
@ -49,7 +48,7 @@ class blog_entry implements renderable {
public $attachment; public $attachment;
public $publishstate; public $publishstate;
// Locked Database fields (Don't touch these) // Locked Database fields (Don't touch these).
public $courseid = 0; public $courseid = 0;
public $groupid = 0; public $groupid = 0;
public $module = 'blog'; public $module = 'blog';
@ -62,14 +61,13 @@ class blog_entry implements renderable {
public $created; public $created;
public $usermodified; public $usermodified;
// Other class variables // Other class variables.
public $form; public $form;
public $tags = array(); public $tags = array();
/** @var StdClass Data needed to render the entry */ /** @var StdClass Data needed to render the entry */
public $renderable; public $renderable;
// Methods
/** /**
* Constructor. If given an id, will fetch the corresponding record from the DB. * Constructor. If given an id, will fetch the corresponding record from the DB.
* *
@ -137,11 +135,12 @@ class blog_entry implements renderable {
if ($externalblog = $DB->get_record('blog_external', array('id' => $this->content))) { if ($externalblog = $DB->get_record('blog_external', array('id' => $this->content))) {
$urlparts = parse_url($externalblog->url); $urlparts = parse_url($externalblog->url);
$this->renderable->externalblogtext = get_string('retrievedfrom', 'blog') . get_string('labelsep', 'langconfig'); $this->renderable->externalblogtext = get_string('retrievedfrom', 'blog') . get_string('labelsep', 'langconfig');
$this->renderable->externalblogtext .= html_writer::link($urlparts['scheme'] . '://'.$urlparts['host'], $externalblog->name); $this->renderable->externalblogtext .= html_writer::link($urlparts['scheme'] . '://' . $urlparts['host'],
$externalblog->name);
} }
} }
// Retrieve associations // Retrieve associations.
$this->renderable->unassociatedentry = false; $this->renderable->unassociatedentry = false;
if (!empty($CFG->useblogassociations)) { if (!empty($CFG->useblogassociations)) {
@ -165,9 +164,11 @@ class blog_entry implements renderable {
// Course associations. // Course associations.
if ($context->contextlevel == CONTEXT_COURSE) { if ($context->contextlevel == CONTEXT_COURSE) {
$instancename = $DB->get_field('course', 'shortname', array('id' => $context->instanceid)); //TODO: performance!!!! // TODO: performance!!!!
$instancename = $DB->get_field('course', 'shortname', array('id' => $context->instanceid));
$associations[$key]->url = $assocurl = new moodle_url('/course/view.php', array('id' => $context->instanceid)); $associations[$key]->url = $assocurl = new moodle_url('/course/view.php',
array('id' => $context->instanceid));
$associations[$key]->text = $instancename; $associations[$key]->text = $instancename;
$associations[$key]->icon = new pix_icon('i/course', $associations[$key]->text); $associations[$key]->icon = new pix_icon('i/course', $associations[$key]->text);
} }
@ -175,15 +176,17 @@ class blog_entry implements renderable {
// Mod associations. // Mod associations.
if ($context->contextlevel == CONTEXT_MODULE) { if ($context->contextlevel == CONTEXT_MODULE) {
// Getting the activity type and the activity instance id // Getting the activity type and the activity instance id.
$sql = 'SELECT cm.instance, m.name FROM {course_modules} cm $sql = 'SELECT cm.instance, m.name FROM {course_modules} cm
JOIN {modules} m ON m.id = cm.module JOIN {modules} m ON m.id = cm.module
WHERE cm.id = :cmid'; WHERE cm.id = :cmid';
$modinfo = $DB->get_record_sql($sql, array('cmid' => $context->instanceid)); $modinfo = $DB->get_record_sql($sql, array('cmid' => $context->instanceid));
$instancename = $DB->get_field($modinfo->name, 'name', array('id' => $modinfo->instance)); //TODO: performance!!!! // TODO: performance!!!!
$instancename = $DB->get_field($modinfo->name, 'name', array('id' => $modinfo->instance));
$associations[$key]->type = get_string('modulename', $modinfo->name); $associations[$key]->type = get_string('modulename', $modinfo->name);
$associations[$key]->url = new moodle_url('/mod/' . $modinfo->name . '/view.php', array('id' => $context->instanceid)); $associations[$key]->url = new moodle_url('/mod/' . $modinfo->name . '/view.php',
array('id' => $context->instanceid));
$associations[$key]->text = $instancename; $associations[$key]->text = $instancename;
$associations[$key]->icon = new pix_icon('icon', $associations[$key]->text, $modinfo->name); $associations[$key]->icon = new pix_icon('icon', $associations[$key]->text, $modinfo->name);
} }
@ -203,7 +206,7 @@ class blog_entry implements renderable {
* Gets the entry attachments list * Gets the entry attachments list
* @return array List of blog_entry_attachment instances * @return array List of blog_entry_attachment instances
*/ */
function get_attachments() { public function get_attachments() {
global $CFG; global $CFG;
@ -293,7 +296,13 @@ class blog_entry implements renderable {
} }
$entry = file_postupdate_standard_editor($entry, 'summary', $summaryoptions, $sitecontext, 'blog', 'post', $entry->id); $entry = file_postupdate_standard_editor($entry, 'summary', $summaryoptions, $sitecontext, 'blog', 'post', $entry->id);
$entry = file_postupdate_standard_filemanager($entry, 'attachment', $attachmentoptions, $sitecontext, 'blog', 'attachment', $entry->id); $entry = file_postupdate_standard_filemanager($entry,
'attachment',
$attachmentoptions,
$sitecontext,
'blog',
'attachment',
$entry->id);
if (!empty($CFG->useblogassociations)) { if (!empty($CFG->useblogassociations)) {
$entry->add_associations(); $entry->add_associations();
@ -427,7 +436,7 @@ class blog_entry implements renderable {
if ($otags = optional_param('otags', '', PARAM_INT)) { if ($otags = optional_param('otags', '', PARAM_INT)) {
foreach ($otags as $tagid) { foreach ($otags as $tagid) {
// TODO : make this use the tag name in the form // TODO : make this use the tag name in the form.
if ($tag = tag_get('id', $tagid)) { if ($tag = tag_get('id', $tagid)) {
$tags[] = $tag->name; $tags[] = $tag->name;
} }
@ -456,11 +465,11 @@ class blog_entry implements renderable {
$sitecontext = context_system::instance(); $sitecontext = context_system::instance();
if (has_capability('moodle/blog:manageentries', $sitecontext)) { if (has_capability('moodle/blog:manageentries', $sitecontext)) {
return true; // can edit any blog entry return true; // Can edit any blog entry.
} }
if ($this->userid == $userid && has_capability('moodle/blog:create', $sitecontext)) { if ($this->userid == $userid && has_capability('moodle/blog:create', $sitecontext)) {
return true; // can edit own when having blog:create capability return true; // Can edit own when having blog:create capability.
} }
return false; return false;
@ -480,23 +489,23 @@ class blog_entry implements renderable {
$sitecontext = context_system::instance(); $sitecontext = context_system::instance();
if (empty($CFG->enableblogs) || !has_capability('moodle/blog:view', $sitecontext)) { if (empty($CFG->enableblogs) || !has_capability('moodle/blog:view', $sitecontext)) {
return false; // blog system disabled or user has no blog view capability return false; // Blog system disabled or user has no blog view capability.
} }
if (isloggedin() && $USER->id == $targetuserid) { if (isloggedin() && $USER->id == $targetuserid) {
return true; // can view own entries in any case return true; // Can view own entries in any case.
} }
if (has_capability('moodle/blog:manageentries', $sitecontext)) { if (has_capability('moodle/blog:manageentries', $sitecontext)) {
return true; // can manage all entries return true; // Can manage all entries.
} }
// coming for 1 entry, make sure it's not a draft // Coming for 1 entry, make sure it's not a draft.
if ($this->publishstate == 'draft' && !has_capability('moodle/blog:viewdrafts', $sitecontext)) { if ($this->publishstate == 'draft' && !has_capability('moodle/blog:viewdrafts', $sitecontext)) {
return false; // can not view draft of others return false; // Can not view draft of others.
} }
// coming for 1 entry, make sure user is logged in, if not a public blog // Coming for 1 entry, make sure user is logged in, if not a public blog.
if ($this->publishstate != 'public' && !isloggedin()) { if ($this->publishstate != 'public' && !isloggedin()) {
return false; return false;
} }
@ -507,7 +516,7 @@ class blog_entry implements renderable {
break; break;
case BLOG_SITE_LEVEL: case BLOG_SITE_LEVEL:
if (isloggedin()) { // not logged in viewers forbidden if (isloggedin()) { // Not logged in viewers forbidden.
return true; return true;
} }
return false; return false;
@ -533,7 +542,7 @@ class blog_entry implements renderable {
global $CFG; global $CFG;
$options = array(); $options = array();
// everyone gets draft access // Everyone gets draft access.
if ($CFG->bloglevel >= BLOG_USER_LEVEL) { if ($CFG->bloglevel >= BLOG_USER_LEVEL) {
$options['draft'] = get_string('publishtonoone', 'blog'); $options['draft'] = get_string('publishtonoone', 'blog');
} }
@ -577,7 +586,7 @@ class blog_listing {
* @param array $filters An associative array of filtername => filterid * @param array $filters An associative array of filtername => filterid
*/ */
public function __construct($filters=array()) { public function __construct($filters=array()) {
// Unset filters overridden by more specific filters // Unset filters overridden by more specific filters.
foreach ($filters as $type => $id) { foreach ($filters as $type => $id) {
if (!empty($type) && !empty($id)) { if (!empty($type) && !empty($id)) {
$this->filters[$type] = blog_filter::get_instance($id, $type); $this->filters[$type] = blog_filter::get_instance($id, $type);
@ -615,50 +624,53 @@ class blog_listing {
public function get_entry_fetch_sql($count=false, $sort='lastmodified DESC', $userid = false) { public function get_entry_fetch_sql($count=false, $sort='lastmodified DESC', $userid = false) {
global $DB, $USER, $CFG; global $DB, $USER, $CFG;
if(!$userid) { if (!$userid) {
$userid = $USER->id; $userid = $USER->id;
} }
$allnamefields = get_all_user_name_fields(true, 'u'); $allnamefields = get_all_user_name_fields(true, 'u');
// The query used to locate blog entries is complicated. It will be built from the following components: // The query used to locate blog entries is complicated. It will be built from the following components:
$requiredfields = "p.*, $allnamefields, u.email"; // the SELECT clause $requiredfields = "p.*, $allnamefields, u.email"; // The SELECT clause.
$tables = array('p' => 'post', 'u' => 'user'); // components of the FROM clause (table_id => table_name) $tables = array('p' => 'post', 'u' => 'user'); // Components of the FROM clause (table_id => table_name).
$conditions = array('u.deleted = 0', 'p.userid = u.id', '(p.module = \'blog\' OR p.module = \'blog_external\')'); // components of the WHERE clause (conjunction) // Components of the WHERE clause (conjunction).
$conditions = array('u.deleted = 0', 'p.userid = u.id', '(p.module = \'blog\' OR p.module = \'blog_external\')');
// build up a clause for permission constraints // Build up a clause for permission constraints.
$params = array(); $params = array();
// fix for MDL-9165, use with readuserblogs capability in a user context can read that user's private blogs // Fix for MDL-9165, use with readuserblogs capability in a user context can read that user's private blogs.
// admins can see all blogs regardless of publish states, as described on the help page // Admins can see all blogs regardless of publish states, as described on the help page.
if (has_capability('moodle/user:readuserblogs', context_system::instance())) { if (has_capability('moodle/user:readuserblogs', context_system::instance())) {
// don't add permission constraints // Don't add permission constraints.
} else if(!empty($this->filters['user']) && has_capability('moodle/user:readuserblogs', } else if (!empty($this->filters['user'])
context_user::instance((empty($this->filters['user']->id) ? 0 : $this->filters['user']->id)))) { && has_capability('moodle/user:readuserblogs',
// don't add permission constraints context_user::instance((empty($this->filters['user']->id) ? 0 : $this->filters['user']->id)))) {
// Don't add permission constraints.
} else { } else {
if (isloggedin() and !isguestuser()) { if (isloggedin() and !isguestuser()) {
$assocexists = $DB->record_exists('blog_association', array()); //dont check association records if there aren't any // Dont check association records if there aren't any.
$assocexists = $DB->record_exists('blog_association', array());
//begin permission sql clause // Begin permission sql clause.
$permissionsql = '(p.userid = ? '; $permissionsql = '(p.userid = ? ';
$params[] = $userid; $params[] = $userid;
if ($CFG->bloglevel >= BLOG_SITE_LEVEL) { // add permission to view site-level entries if ($CFG->bloglevel >= BLOG_SITE_LEVEL) { // Add permission to view site-level entries.
$permissionsql .= " OR p.publishstate = 'site' "; $permissionsql .= " OR p.publishstate = 'site' ";
} }
if ($CFG->bloglevel >= BLOG_GLOBAL_LEVEL) { // add permission to view global entries if ($CFG->bloglevel >= BLOG_GLOBAL_LEVEL) { // Add permission to view global entries.
$permissionsql .= " OR p.publishstate = 'public' "; $permissionsql .= " OR p.publishstate = 'public' ";
} }
$permissionsql .= ') '; //close permissions sql clause $permissionsql .= ') '; // Close permissions sql clause.
} else { // default is access to public entries } else { // Default is access to public entries.
$permissionsql = "p.publishstate = 'public'"; $permissionsql = "p.publishstate = 'public'";
} }
$conditions[] = $permissionsql; //add permission constraints $conditions[] = $permissionsql; // Add permission constraints.
} }
foreach ($this->filters as $type => $blogfilter) { foreach ($this->filters as $type => $blogfilter) {
@ -667,7 +679,7 @@ class blog_listing {
$tables = array_merge($tables, $blogfilter->tables); $tables = array_merge($tables, $blogfilter->tables);
} }
$tablessql = ''; // build up the FROM clause $tablessql = ''; // Build up the FROM clause.
foreach ($tables as $tablename => $table) { foreach ($tables as $tablename => $table) {
$tablessql .= ($tablessql ? ', ' : '').'{'.$table.'} '.$tablename; $tablessql .= ($tablessql ? ', ' : '').'{'.$table.'} '.$tablename;
} }
@ -688,7 +700,7 @@ class blog_listing {
global $CFG, $USER, $DB, $OUTPUT, $PAGE; global $CFG, $USER, $DB, $OUTPUT, $PAGE;
$sitecontext = context_system::instance(); $sitecontext = context_system::instance();
// Blog renderer // Blog renderer.
$output = $PAGE->get_renderer('blog'); $output = $PAGE->get_renderer('blog');
$page = optional_param('blogpage', 0, PARAM_INT); $page = optional_param('blogpage', 0, PARAM_INT);
@ -711,7 +723,7 @@ class blog_listing {
echo $OUTPUT->render($pagingbar); echo $OUTPUT->render($pagingbar);
if (has_capability('moodle/blog:create', $sitecontext)) { if (has_capability('moodle/blog:create', $sitecontext)) {
//the user's blog is enabled and they are viewing their own blog // The user's blog is enabled and they are viewing their own blog.
$userid = optional_param('userid', null, PARAM_INT); $userid = optional_param('userid', null, PARAM_INT);
if (empty($userid) || (!empty($userid) && $userid == $USER->id)) { if (empty($userid) || (!empty($userid) && $userid == $USER->id)) {
@ -744,7 +756,7 @@ class blog_listing {
foreach ($entries as $entry) { foreach ($entries as $entry) {
$blogentry = new blog_entry(null, $entry); $blogentry = new blog_entry(null, $entry);
// Get the required blog entry data to render it // Get the required blog entry data to render it.
$blogentry->prepare_render(); $blogentry->prepare_render();
echo $output->render($blogentry); echo $output->render($blogentry);
@ -762,7 +774,7 @@ class blog_listing {
} }
} }
/// Find the base url from $_GET variables, for print_paging_bar // Find the base url from $_GET variables, for print_paging_bar.
public function get_baseurl() { public function get_baseurl() {
$getcopy = $_GET; $getcopy = $_GET;
@ -897,11 +909,13 @@ class blog_filter_context extends blog_filter {
$this->type = $type; $this->type = $type;
} }
$this->availabletypes = array('site' => get_string('site'), 'course' => get_string('course'), 'module' => get_string('activity')); $this->availabletypes = array('site' => get_string('site'),
'course' => get_string('course'),
'module' => get_string('activity'));
switch ($this->type) { switch ($this->type) {
case 'course': // Careful of site course! case 'course': // Careful of site course!
// Ignore course filter if blog associations are not enabled // Ignore course filter if blog associations are not enabled.
if ($this->id != $SITE->id && !empty($CFG->useblogassociations)) { if ($this->id != $SITE->id && !empty($CFG->useblogassociations)) {
$this->overrides = array('site'); $this->overrides = array('site');
$context = context_course::instance($this->id); $context = context_course::instance($this->id);
@ -910,11 +924,11 @@ class blog_filter_context extends blog_filter {
$this->conditions[] = 'ba.contextid = '.$context->id; $this->conditions[] = 'ba.contextid = '.$context->id;
break; break;
} else { } else {
// We are dealing with the site course, do not break from the current case // We are dealing with the site course, do not break from the current case.
} }
case 'site': case 'site':
// No special constraints // No special constraints.
break; break;
case 'module': case 'module':
if (!empty($CFG->useblogassociations)) { if (!empty($CFG->useblogassociations)) {
@ -961,7 +975,7 @@ class blog_filter_user extends blog_filter {
$this->params = array($this->id); $this->params = array($this->id);
$this->overrides = array('group'); $this->overrides = array('group');
} elseif ($this->type == 'group') { } else if ($this->type == 'group') {
$this->overrides = array('course', 'site'); $this->overrides = array('course', 'site');
$this->tables['gm'] = 'groups_members'; $this->tables['gm'] = 'groups_members';
@ -969,7 +983,7 @@ class blog_filter_user extends blog_filter {
$this->conditions[] = 'gm.groupid = ?'; $this->conditions[] = 'gm.groupid = ?';
$this->params[] = $this->id; $this->params[] = $this->id;
if (!empty($CFG->useblogassociations)) { // only show blog entries associated with this course if (!empty($CFG->useblogassociations)) { // Only show blog entries associated with this course.
$coursecontext = context_course::instance($DB->get_field('groups', 'courseid', array('id' => $this->id))); $coursecontext = context_course::instance($DB->get_field('groups', 'courseid', array('id' => $this->id)));
$this->tables['ba'] = 'blog_association'; $this->tables['ba'] = 'blog_association';
$this->conditions[] = 'gm.groupid = ?'; $this->conditions[] = 'gm.groupid = ?';
@ -1068,7 +1082,8 @@ class blog_entry_attachment implements renderable {
$this->file = $file; $this->file = $file;
$this->filename = $file->get_filename(); $this->filename = $file->get_filename();
$this->url = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.SYSCONTEXTID.'/blog/attachment/'.$entryid.'/'.$this->filename); $this->url = file_encode_url($CFG->wwwroot . '/pluginfile.php',
'/' . SYSCONTEXTID . '/blog/attachment/' . $entryid . '/' . $this->filename);
} }
} }

View file

@ -1,5 +1,4 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/ // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify
@ -66,7 +65,7 @@ if (empty($CFG->enableblogs)) {
// The preference is site wide not blog specific. Hence user should have permissions in site level. // The preference is site wide not blog specific. Hence user should have permissions in site level.
require_capability('moodle/blog:view', $sitecontext); require_capability('moodle/blog:view', $sitecontext);
/// If data submitted, then process and store. // If data submitted, then process and store.
$mform = new blog_preferences_form('preferences.php'); $mform = new blog_preferences_form('preferences.php');
$mform->set_data(array('pagesize' => get_user_preferences('blogpagesize'))); $mform->set_data(array('pagesize' => get_user_preferences('blogpagesize')));
@ -80,7 +79,7 @@ if (!$mform->is_cancelled() && $data = $mform->get_data()) {
set_user_preference('blogpagesize', $pagesize); set_user_preference('blogpagesize', $pagesize);
} }
if ($mform->is_cancelled()){ if ($mform->is_cancelled()) {
redirect($CFG->wwwroot . '/blog/index.php'); redirect($CFG->wwwroot . '/blog/index.php');
} }

View file

@ -1,5 +1,4 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/ // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify
@ -26,7 +25,7 @@
*/ */
if (!defined('MOODLE_INTERNAL')) { if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
} }
require_once($CFG->libdir.'/formslib.php'); require_once($CFG->libdir.'/formslib.php');

View file

@ -63,7 +63,9 @@ class core_blog_renderer extends plugin_renderer_base {
$o .= $this->output->container_start('topic starter header clearfix'); $o .= $this->output->container_start('topic starter header clearfix');
// Title. // Title.
$titlelink = html_writer::link(new moodle_url('/blog/index.php', array('entryid' => $entry->id)), format_string($entry->subject)); $titlelink = html_writer::link(new moodle_url('/blog/index.php',
array('entryid' => $entry->id)),
format_string($entry->subject));
$o .= $this->output->container($titlelink, 'subject'); $o .= $this->output->container($titlelink, 'subject');
// Post by. // Post by.
@ -244,9 +246,14 @@ class core_blog_renderer extends plugin_renderer_base {
$o = html_writer::empty_tag('img', $attrs); $o = html_writer::empty_tag('img', $attrs);
$class = 'attachedimages'; $class = 'attachedimages';
} else { } else {
$image = $this->output->pix_icon(file_file_icon($attachment->file), $attachment->filename, 'moodle', array('class'=>'icon')); $image = $this->output->pix_icon(file_file_icon($attachment->file),
$attachment->filename,
'moodle',
array('class' => 'icon'));
$o = html_writer::link($attachment->url, $image); $o = html_writer::link($attachment->url, $image);
$o .= format_text(html_writer::link($attachment->url, $attachment->filename), FORMAT_HTML, array('context' => $syscontext)); $o .= format_text(html_writer::link($attachment->url, $attachment->filename),
FORMAT_HTML,
array('context' => $syscontext));
$class = 'attachments'; $class = 'attachments';
} }

View file

@ -1,5 +1,4 @@
<?php <?php
// This file is part of Moodle - http://moodle.org/ // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify
@ -97,9 +96,6 @@ function blog_rss_print_link($context, $filtertype, $filterselect=0, $tagid=0, $
function blog_rss_add_http_header($context, $title, $filtertype, $filterselect=0, $tagid=0) { function blog_rss_add_http_header($context, $title, $filtertype, $filterselect=0, $tagid=0) {
global $PAGE, $USER, $CFG; global $PAGE, $USER, $CFG;
//$componentname = 'blog';
//rss_add_http_header($context, $componentname, $filterselect, $title);
if (!isloggedin()) { if (!isloggedin()) {
$userid = $CFG->siteguest; $userid = $CFG->siteguest;
} else { } else {
@ -159,7 +155,7 @@ function blog_rss_get_feed($context, $args) {
if ($CFG->bloglevel == BLOG_SITE_LEVEL) { if ($CFG->bloglevel == BLOG_SITE_LEVEL) {
if (isguestuser()) { if (isguestuser()) {
debugging(get_string('nopermissiontoshow','error')); debugging(get_string('nopermissiontoshow', 'error'));
return ''; return '';
} }
} }
@ -170,7 +166,7 @@ function blog_rss_get_feed($context, $args) {
} }
$type = clean_param($args[3], PARAM_ALPHA); $type = clean_param($args[3], PARAM_ALPHA);
$id = clean_param($args[4], PARAM_INT); // could be groupid / courseid / userid depending on $type $id = clean_param($args[4], PARAM_INT); // Could be groupid / courseid / userid depending on $type.
$tagid=0; $tagid=0;
if ($args[5] != 'rss.xml') { if ($args[5] != 'rss.xml') {
@ -183,14 +179,13 @@ function blog_rss_get_feed($context, $args) {
if (file_exists($filename)) { if (file_exists($filename)) {
if (filemtime($filename) + 3600 > time()) { if (filemtime($filename) + 3600 > time()) {
return $filename; // It's already done so we return cached version return $filename; // It's already done so we return cached version.
} }
} }
$courseid = $groupid = $userid = null; $courseid = $groupid = $userid = null;
switch ($type) { switch ($type) {
case 'site': case 'site':
//$siteid = $id;
break; break;
case 'course': case 'course':
$courseid = $id; $courseid = $id;
@ -203,26 +198,26 @@ function blog_rss_get_feed($context, $args) {
break; break;
} }
// Get all the entries from the database // Get all the entries from the database.
require_once($CFG->dirroot .'/blog/locallib.php'); require_once($CFG->dirroot .'/blog/locallib.php');
$blogheaders = blog_get_headers($courseid, $groupid, $userid, $tagid); $blogheaders = blog_get_headers($courseid, $groupid, $userid, $tagid);
$bloglisting = new blog_listing($blogheaders['filters']); $bloglisting = new blog_listing($blogheaders['filters']);
$blogentries = $bloglisting->get_entries(); $blogentries = $bloglisting->get_entries();
// Now generate an array of RSS items // Now generate an array of RSS items.
if ($blogentries) { if ($blogentries) {
$items = array(); $items = array();
foreach ($blogentries as $blog_entry) { foreach ($blogentries as $blogentry) {
$item = NULL; $item = null;
$item->author = fullname($DB->get_record('user', array('id'=>$blog_entry->userid))); // TODO: this is slow $item->author = fullname($DB->get_record('user', array('id' => $blogentry->userid))); // TODO: this is slow.
$item->title = $blog_entry->subject; $item->title = $blogentry->subject;
$item->pubdate = $blog_entry->lastmodified; $item->pubdate = $blogentry->lastmodified;
$item->link = $CFG->wwwroot.'/blog/index.php?entryid='.$blog_entry->id; $item->link = $CFG->wwwroot.'/blog/index.php?entryid='.$blogentry->id;
$summary = file_rewrite_pluginfile_urls($blog_entry->summary, 'pluginfile.php', $summary = file_rewrite_pluginfile_urls($blogentry->summary, 'pluginfile.php',
$sitecontext->id, 'blog', 'post', $blog_entry->id); $sitecontext->id, 'blog', 'post', $blogentry->id);
$item->description = format_text($summary, $blog_entry->format); $item->description = format_text($summary, $blogentry->format);
if ( !empty($CFG->usetags) && ($blogtags = tag_get_tags_array('post', $blog_entry->id)) ) { if ( !empty($CFG->usetags) && ($blogtags = tag_get_tags_array('post', $blogentry->id)) ) {
if ($blogtags) { if ($blogtags) {
$item->tags = $blogtags; $item->tags = $blogtags;
} }
@ -230,12 +225,12 @@ function blog_rss_get_feed($context, $args) {
} }
$items[] = $item; $items[] = $item;
} }
$articles = rss_add_items($items); /// Change structure to XML $articles = rss_add_items($items); // Change structure to XML.
} else { } else {
$articles = ''; $articles = '';
} }
/// Get header and footer information // Get header and footer information.
switch ($type) { switch ($type) {
case 'user': case 'user':
@ -250,7 +245,7 @@ function blog_rss_get_feed($context, $args) {
break; break;
case 'group': case 'group':
$group = groups_get_group($id); $group = groups_get_group($id);
$info = $group->name; //TODO: $DB->get_field('groups', 'name', array('id'=>$id)) $info = $group->name; // TODO: $DB->get_field('groups', 'name', array('id'=>$id)).
break; break;
default: default:
$info = ''; $info = '';
@ -261,18 +256,18 @@ function blog_rss_get_feed($context, $args) {
$info .= ': '.$DB->get_field('tags', 'text', array('id'=>$tagid)); $info .= ': '.$DB->get_field('tags', 'text', array('id'=>$tagid));
} }
$header = rss_standard_header(get_string($type.'blog','blog', $info), $header = rss_standard_header(get_string($type.'blog', 'blog', $info),
$CFG->wwwroot.'/blog/index.php', $CFG->wwwroot.'/blog/index.php',
get_string('intro','blog')); get_string('intro', 'blog'));
$footer = rss_standard_footer(); $footer = rss_standard_footer();
// Save the XML contents to file. // Save the XML contents to file.
$rssdata = $header.$articles.$footer; $rssdata = $header.$articles.$footer;
if (blog_rss_save_file($type,$id,$tagid,$rssdata)) { if (blog_rss_save_file($type, $id, $tagid, $rssdata)) {
return $filename; return $filename;
} else { } else {
return false; // Couldn't find it or make it return false; // Couldn't find it or make it.
} }
} }
@ -308,12 +303,12 @@ function blog_rss_save_file($type, $id, $tagid=0, $contents='') {
$status = true; $status = true;
//blog creates some additional dirs within the rss cache so make sure they all exist // Blog creates some additional dirs within the rss cache so make sure they all exist.
make_cache_directory('rss/blog'); make_cache_directory('rss/blog');
make_cache_directory('rss/blog/'.$type); make_cache_directory('rss/blog/'.$type);
$filename = blog_rss_file_name($type, $id, $tagid); $filename = blog_rss_file_name($type, $id, $tagid);
$expandfilename = false; //we're supplying a full file path $expandfilename = false; // We are supplying a full file path.
$status = rss_save_file('blog', $filename, $contents, $expandfilename); $status = rss_save_file('blog', $filename, $contents, $expandfilename);
return $status; return $status;

View file

@ -32,7 +32,7 @@ require_once($CFG->dirroot . '/blog/lib.php');
*/ */
class core_bloglib_testcase extends advanced_testcase { class core_bloglib_testcase extends advanced_testcase {
private $courseid; // To store important ids to be used in tests private $courseid;
private $cmid; private $cmid;
private $groupid; private $groupid;
private $userid; private $userid;
@ -45,22 +45,22 @@ class core_bloglib_testcase extends advanced_testcase {
$this->resetAfterTest(); $this->resetAfterTest();
// Create default course // Create default course.
$course = $this->getDataGenerator()->create_course(array('category'=>1, 'shortname'=>'ANON')); $course = $this->getDataGenerator()->create_course(array('category'=>1, 'shortname'=>'ANON'));
$this->assertNotEmpty($course); $this->assertNotEmpty($course);
$page = $this->getDataGenerator()->create_module('page', array('course'=>$course->id)); $page = $this->getDataGenerator()->create_module('page', array('course'=>$course->id));
$this->assertNotEmpty($page); $this->assertNotEmpty($page);
// Create default group // Create default group.
$group = new stdClass(); $group = new stdClass();
$group->courseid = $course->id; $group->courseid = $course->id;
$group->name = 'ANON'; $group->name = 'ANON';
$group->id = $DB->insert_record('groups', $group); $group->id = $DB->insert_record('groups', $group);
// Create default user // Create default user.
$user = $this->getDataGenerator()->create_user(array('username'=>'testuser', 'firstname'=>'Jimmy', 'lastname'=>'Kinnon')); $user = $this->getDataGenerator()->create_user(array('username'=>'testuser', 'firstname'=>'Jimmy', 'lastname'=>'Kinnon'));
// Create default tag // Create default tag.
$tag = new stdClass(); $tag = new stdClass();
$tag->userid = $user->id; $tag->userid = $user->id;
$tag->name = 'testtagname'; $tag->name = 'testtagname';
@ -68,14 +68,14 @@ class core_bloglib_testcase extends advanced_testcase {
$tag->tagtype = 'official'; $tag->tagtype = 'official';
$tag->id = $DB->insert_record('tag', $tag); $tag->id = $DB->insert_record('tag', $tag);
// Create default post // Create default post.
$post = new stdClass(); $post = new stdClass();
$post->userid = $user->id; $post->userid = $user->id;
$post->groupid = $group->id; $post->groupid = $group->id;
$post->content = 'test post content text'; $post->content = 'test post content text';
$post->id = $DB->insert_record('post', $post); $post->id = $DB->insert_record('post', $post);
// Grab important ids // Grab important ids.
$this->courseid = $course->id; $this->courseid = $course->id;
$this->cmid = $page->cmid; $this->cmid = $page->cmid;
$this->groupid = $group->id; $this->groupid = $group->id;
@ -88,7 +88,7 @@ class core_bloglib_testcase extends advanced_testcase {
public function test_overrides() { public function test_overrides() {
global $SITE; global $SITE;
// Try all the filters at once: Only the entry filter is active // Try all the filters at once: Only the entry filter is active.
$filters = array('site' => $SITE->id, 'course' => $this->courseid, 'module' => $this->cmid, $filters = array('site' => $SITE->id, 'course' => $this->courseid, 'module' => $this->cmid,
'group' => $this->groupid, 'user' => $this->userid, 'tag' => $this->tagid, 'entry' => $this->postid); 'group' => $this->groupid, 'user' => $this->userid, 'tag' => $this->tagid, 'entry' => $this->postid);
$blog_listing = new blog_listing($filters); $blog_listing = new blog_listing($filters);
@ -100,7 +100,7 @@ class core_bloglib_testcase extends advanced_testcase {
$this->assertFalse(array_key_exists('tag', $blog_listing->filters)); $this->assertFalse(array_key_exists('tag', $blog_listing->filters));
$this->assertTrue(array_key_exists('entry', $blog_listing->filters)); $this->assertTrue(array_key_exists('entry', $blog_listing->filters));
// Again, but without the entry filter: This time, the tag, user and module filters are active // Again, but without the entry filter: This time, the tag, user and module filters are active.
$filters = array('site' => $SITE->id, 'course' => $this->courseid, 'module' => $this->cmid, $filters = array('site' => $SITE->id, 'course' => $this->courseid, 'module' => $this->cmid,
'group' => $this->groupid, 'user' => $this->userid, 'tag' => $this->postid); 'group' => $this->groupid, 'user' => $this->userid, 'tag' => $this->postid);
$blog_listing = new blog_listing($filters); $blog_listing = new blog_listing($filters);
@ -111,7 +111,7 @@ class core_bloglib_testcase extends advanced_testcase {
$this->assertTrue(array_key_exists('user', $blog_listing->filters)); $this->assertTrue(array_key_exists('user', $blog_listing->filters));
$this->assertTrue(array_key_exists('tag', $blog_listing->filters)); $this->assertTrue(array_key_exists('tag', $blog_listing->filters));
// We should get the same result by removing the 3 inactive filters: site, course and group: // We should get the same result by removing the 3 inactive filters: site, course and group.
$filters = array('module' => $this->cmid, 'user' => $this->userid, 'tag' => $this->tagid); $filters = array('module' => $this->cmid, 'user' => $this->userid, 'tag' => $this->tagid);
$blog_listing = new blog_listing($filters); $blog_listing = new blog_listing($filters);
$this->assertFalse(array_key_exists('site', $blog_listing->filters)); $this->assertFalse(array_key_exists('site', $blog_listing->filters));
@ -128,26 +128,26 @@ class core_bloglib_testcase extends advanced_testcase {
public function test_blog_get_headers_case_1() { public function test_blog_get_headers_case_1() {
global $CFG, $PAGE, $OUTPUT; global $CFG, $PAGE, $OUTPUT;
$blog_headers = blog_get_headers(); $blogheaders = blog_get_headers();
$this->assertEquals($blog_headers['heading'], get_string('siteblog', 'blog', 'phpunit')); $this->assertEquals($blogheaders['heading'], get_string('siteblog', 'blog', 'phpunit'));
} }
public function test_blog_get_headers_case_6() { public function test_blog_get_headers_case_6() {
global $CFG, $PAGE, $OUTPUT; global $CFG, $PAGE, $OUTPUT;
$blog_headers = blog_get_headers($this->courseid, NULL, $this->userid); $blogheaders = blog_get_headers($this->courseid, null, $this->userid);
$this->assertNotEquals($blog_headers['heading'], ''); $this->assertNotEquals($blogheaders['heading'], '');
} }
public function test_blog_get_headers_case_7() { public function test_blog_get_headers_case_7() {
global $CFG, $PAGE, $OUTPUT; global $CFG, $PAGE, $OUTPUT;
$blog_headers = blog_get_headers(NULL, $this->groupid); $blogheaders = blog_get_headers(null, $this->groupid);
$this->assertNotEquals($blog_headers['heading'], ''); $this->assertNotEquals($blogheaders['heading'], '');
} }
public function test_blog_get_headers_case_10() { public function test_blog_get_headers_case_10() {
global $CFG, $PAGE, $OUTPUT; global $CFG, $PAGE, $OUTPUT;
$blog_headers = blog_get_headers($this->courseid); $blogheaders = blog_get_headers($this->courseid);
$this->assertNotEquals($blog_headers['heading'], ''); $this->assertNotEquals($blogheaders['heading'], '');
} }
/** /**