Skip to content

Commit

Permalink
Merge branch 'wip-MDL-51239-master' of git://github.com/abgreeve/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Dec 22, 2015
2 parents 40b6fbd + f0899a2 commit 3e0540b
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 84 deletions.
14 changes: 9 additions & 5 deletions blog/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,12 @@
redirect($returnurl);
}
} else if (blog_user_can_edit_entry($entry)) {
$optionsyes = array('entryid'=>$id, 'action'=>'delete', 'confirm'=>1, 'sesskey'=>sesskey(), 'courseid'=>$courseid);
$optionsno = array('userid'=>$entry->userid, 'courseid'=>$courseid);
$optionsyes = array('entryid' => $id,
'action' => 'delete',
'confirm' => 1,
'sesskey' => sesskey(),
'courseid' => $courseid);
$optionsno = array('userid' => $entry->userid, 'courseid' => $courseid);
$PAGE->set_title("$SITE->shortname: $strblogs");
$PAGE->set_heading($SITE->fullname);
echo $OUTPUT->header();
Expand Down Expand Up @@ -182,9 +186,9 @@
}

require_once('edit_form.php');
$summaryoptions = array('maxfiles'=> 99, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>true, 'context'=>$sitecontext,
'subdirs'=>file_area_contains_subdirs($sitecontext, 'blog', 'post', $entry->id));
$attachmentoptions = array('subdirs'=>false, 'maxfiles'=> 99, 'maxbytes'=>$CFG->maxbytes);
$summaryoptions = array('maxfiles' => 99, 'maxbytes' => $CFG->maxbytes, 'trusttext' => true, 'context' => $sitecontext,
'subdirs' => file_area_contains_subdirs($sitecontext, 'blog', 'post', $entry->id));
$attachmentoptions = array('subdirs' => false, 'maxfiles' => 99, 'maxbytes' => $CFG->maxbytes);

$blogeditform = new blog_edit_form(null, compact('entry',
'summaryoptions',
Expand Down
2 changes: 1 addition & 1 deletion blog/external_blogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
$editurl = new moodle_url('/blog/external_blog_edit.php', array('id' => $blog->id));
$editicon = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('editexternalblog', 'blog')));

$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')));

$table->data[] = new html_table_row(array($blog->name,
Expand Down
18 changes: 9 additions & 9 deletions blog/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@

comment::init();

$url_params = compact('id', 'start', 'tag', 'userid', 'tagid', 'modid', 'entryid', 'groupid', 'courseid', 'search');
foreach ($url_params as $var => $val) {
$urlparams = compact('id', 'start', 'tag', 'userid', 'tagid', 'modid', 'entryid', 'groupid', 'courseid', 'search');
foreach ($urlparams as $var => $val) {
if (empty($val)) {
unset($url_params[$var]);
unset($urlparams[$var]);
}
}
$PAGE->set_url('/blog/index.php', $url_params);
$PAGE->set_url('/blog/index.php', $urlparams);

// Correct tagid if a text tag is provided as a param.
if (!empty($tag)) {
Expand Down Expand Up @@ -121,7 +121,7 @@

if (!$userid && has_capability('moodle/blog:view', $sitecontext) && $CFG->bloglevel > BLOG_USER_LEVEL) {
if ($entryid) {
if (!$entryobject = $DB->get_record('post', array('id'=>$entryid))) {
if (!$entryobject = $DB->get_record('post', array('id' => $entryid))) {
print_error('nosuchentry', 'blog');
}
$userid = $entryobject->userid;
Expand All @@ -148,12 +148,12 @@
print_error('cannotviewsiteblog', 'blog');
}

$COURSE = $DB->get_record('course', array('format'=>'site'));
$COURSE = $DB->get_record('course', array('format' => 'site'));
$courseid = $COURSE->id;
}

if (!empty($courseid)) {
if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('invalidcourseid');
}

Expand All @@ -176,7 +176,7 @@
print_error(get_string('invalidgroupid', 'blog'));
}

if (!$course = $DB->get_record('course', array('id'=>$group->courseid))) {
if (!$course = $DB->get_record('course', array('id' => $group->courseid))) {
print_error('invalidcourseid');
}

Expand All @@ -200,7 +200,7 @@
print_error('blogdisable', 'blog');
}

if (!$user = $DB->get_record('user', array('id'=>$userid))) {
if (!$user = $DB->get_record('user', array('id' => $userid))) {
print_error('invaliduserid');
}

Expand Down
52 changes: 26 additions & 26 deletions blog/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,9 @@ function blog_get_all_options(moodle_page $page, stdClass $userid = null) {
$userid = $page->context->instanceid;
}
// 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!
$user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
} else {
$user = null;
}
Expand All @@ -350,7 +350,7 @@ function blog_get_all_options(moodle_page $page, stdClass $userid = null) {
// Get the options for the user.
if ($user !== null and !isguestuser($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.
if (isloggedin() and !isguestuser()) {
Expand Down Expand Up @@ -413,22 +413,22 @@ function blog_get_options_for_user(stdClass $user=null) {
// Not the current user, but we can view and its blogs are enabled for SITE or GLOBAL.
$options['userentries'] = array(
'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 {
// It's the current user.
if ($canview) {
// We can view our own blogs .... BIG surprise.
$options['view'] = array(
'string' => get_string('blogentries', '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)) {
// We can add to our own blog.
$options['add'] = array(
'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'))
);
}
}
Expand Down Expand Up @@ -560,13 +560,13 @@ function blog_get_options_for_module($module, $user=null) {
$a->type = $modulename;
$options['moduleview'] = array(
'string' => get_string('viewallmodentries', 'blog', $a),
'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.
$options['moduleviewmine'] = array(
'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)) {
// View the given users entries about this module.
Expand All @@ -575,7 +575,7 @@ function blog_get_options_for_module($module, $user=null) {
$a->user = fullname($user);
$options['moduleviewuser'] = array(
'string' => get_string('blogentriesbyuseraboutmodule', 'blog', $a),
'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))
);
}
}
Expand All @@ -584,7 +584,7 @@ function blog_get_options_for_module($module, $user=null) {
// The user can blog about this module.
$options['moduleadd'] = array(
'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.
Expand Down Expand Up @@ -673,7 +673,7 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu

$headers['filters']['module'] = $modid;
// 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));
$cm = $DB->get_record('course_modules', array('id' => $modid));
$cm->modname = $DB->get_field('modules', 'name', array('id' => $cm->module));
Expand Down Expand Up @@ -861,7 +861,7 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
if (!empty($tagid)) {
$headers['filters']['tag'] = $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);
} else if (!empty($tag)) {
if ($tagrec = $DB->get_record('tag', array('name' => $tag))) {
Expand Down Expand Up @@ -921,7 +921,7 @@ function blog_get_associated_count($courseid, $cmid=null) {
* @package core_blog
* @category comment
*
* @param stdClass $comment_param {
* @param stdClass $commentparam {
* context => context the context object
* courseid => int course id
* cm => stdClass course module object
Expand All @@ -930,11 +930,11 @@ function blog_get_associated_count($courseid, $cmid=null) {
* }
* @return array
*/
function blog_comment_permissions($comment_param) {
function blog_comment_permissions($commentparam) {
global $DB;

// If blog is public and current user is guest, then don't let him post comments.
$blogentry = $DB->get_record('post', array('id' => $comment_param->itemid), 'publishstate', MUST_EXIST);
$blogentry = $DB->get_record('post', array('id' => $commentparam->itemid), 'publishstate', MUST_EXIST);

if ($blogentry->publishstate != 'public') {
if (!isloggedin() || isguestuser()) {
Expand All @@ -959,7 +959,7 @@ function blog_comment_permissions($comment_param) {
* }
* @return boolean
*/
function blog_comment_validate($comment_param) {
function blog_comment_validate($commentparam) {
global $CFG, $DB, $USER;

// Check if blogs are enabled user can comment.
Expand All @@ -968,22 +968,22 @@ function blog_comment_validate($comment_param) {
}

// Validate comment area.
if ($comment_param->commentarea != 'format_blog') {
if ($commentparam->commentarea != 'format_blog') {
throw new comment_exception('invalidcommentarea');
}

$blogentry = $DB->get_record('post', array('id' => $comment_param->itemid), '*', MUST_EXIST);
$blogentry = $DB->get_record('post', array('id' => $commentparam->itemid), '*', MUST_EXIST);

// Validation for comment deletion.
if (!empty($comment_param->commentid)) {
if ($record = $DB->get_record('comments', array('id'=>$comment_param->commentid))) {
if (!empty($commentparam->commentid)) {
if ($record = $DB->get_record('comments', array('id' => $commentparam->commentid))) {
if ($record->commentarea != 'format_blog') {
throw new comment_exception('invalidcommentarea');
}
if ($record->contextid != $comment_param->context->id) {
if ($record->contextid != $commentparam->context->id) {
throw new comment_exception('invalidcontext');
}
if ($record->itemid != $comment_param->itemid) {
if ($record->itemid != $commentparam->itemid) {
throw new comment_exception('invalidcommentitemid');
}
} else {
Expand All @@ -1005,10 +1005,10 @@ function blog_comment_validate($comment_param) {
*/
function blog_page_type_list($pagetype, $parentcontext, $currentcontext) {
return array(
'*'=>get_string('page-x', 'pagetype'),
'blog-*'=>get_string('page-blog-x', 'blog'),
'blog-index'=>get_string('page-blog-index', 'blog'),
'blog-edit'=>get_string('page-blog-edit', 'blog')
'*' => get_string('page-x', 'pagetype'),
'blog-*' => get_string('page-blog-x', 'blog'),
'blog-index' => get_string('page-blog-index', 'blog'),
'blog-edit' => get_string('page-blog-edit', 'blog')
);
}

Expand Down
8 changes: 4 additions & 4 deletions blog/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function prepare_render() {

$this->renderable = new StdClass();

$this->renderable->user = $DB->get_record('user', array('id'=>$this->userid));
$this->renderable->user = $DB->get_record('user', array('id' => $this->userid));

// Entry comments.
if (!empty($CFG->usecomments) and $CFG->blogusecomments) {
Expand Down Expand Up @@ -163,7 +163,7 @@ public function prepare_render() {
$associations[$key]->contextlevel = $context->contextlevel;

// Course associations.
if ($context->contextlevel == CONTEXT_COURSE) {
if ($context->contextlevel == CONTEXT_COURSE) {
// TODO: performance!!!!
$instancename = $DB->get_field('course', 'shortname', array('id' => $context->instanceid));

Expand All @@ -174,7 +174,7 @@ public function prepare_render() {
}

// Mod associations.
if ($context->contextlevel == CONTEXT_MODULE) {
if ($context->contextlevel == CONTEXT_MODULE) {

// Getting the activity type and the activity instance id.
$sql = 'SELECT cm.instance, m.name FROM {course_modules} cm
Expand Down Expand Up @@ -653,7 +653,7 @@ public function get_entry_fetch_sql($count=false, $sort='lastmodified DESC', $us
$assocexists = $DB->record_exists('blog_association', array());

// Begin permission sql clause.
$permissionsql = '(p.userid = ? ';
$permissionsql = '(p.userid = ? ';
$params[] = $userid;

if ($CFG->bloglevel >= BLOG_SITE_LEVEL) { // Add permission to view site-level entries.
Expand Down
8 changes: 4 additions & 4 deletions blog/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ public function render_blog_entry(blog_entry $entry) {
if ($officialtags) {
$o .= get_string('tags', 'tag') .': '. $this->output->container($officialtags, 'officialblogtags');
if ($defaulttags) {
$o .= ', ';
$o .= ', ';
}
}
$o .= $defaulttags;
$o .= $defaulttags;
$o .= $this->output->container_end();
}

Expand All @@ -155,7 +155,7 @@ public function render_blog_entry(blog_entry $entry) {
$assocstr = '';
$coursesarray = array();
foreach ($entry->renderable->blogassociations as $assocrec) {
if ($assocrec->contextlevel == CONTEXT_COURSE) {
if ($assocrec->contextlevel == CONTEXT_COURSE) {
$coursesarray[] = $this->output->action_icon($assocrec->url, $assocrec->icon, null, array(), true);
}
}
Expand All @@ -166,7 +166,7 @@ public function render_blog_entry(blog_entry $entry) {
// Now show mod association.
$modulesarray = array();
foreach ($entry->renderable->blogassociations as $assocrec) {
if ($assocrec->contextlevel == CONTEXT_MODULE) {
if ($assocrec->contextlevel == CONTEXT_MODULE) {
$str = get_string('associated', 'blog', $assocrec->type) . ': ';
$str .= $this->output->action_icon($assocrec->url, $assocrec->icon, null, array(), true);
$modulesarray[] = $str;
Expand Down
Loading

0 comments on commit 3e0540b

Please sign in to comment.