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
// This file is part of Moodle - http://moodle.org/
//
// 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
*/
require_once(dirname(dirname(__FILE__)).'/config.php');
include_once('lib.php');
include_once('locallib.php');
require_once('lib.php');
require_once('locallib.php');
$action = required_param('action', PARAM_ALPHA);
$id = optional_param('entryid', 0, PARAM_INT);
@ -38,9 +37,13 @@ if ($action == 'edit') {
$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') {
$id = null;
}
@ -65,7 +68,7 @@ if (!empty($courseid) && empty($modid)) {
$returnurl->param('courseid', $courseid);
}
// If a modid is given, guess courseid
// If a modid is given, guess courseid.
if (!empty($modid)) {
$returnurl->param('modid', $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');
}
// 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 (!$entry = new blog_entry($id)) {
print_error('wrongentryid', 'blog');
@ -93,7 +96,7 @@ if ($id) {
} else {
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->id = null;
@ -104,14 +107,14 @@ $returnurl->param('userid', $userid);
// Blog renderer.
$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)) {
print_error('wrongentryid', 'blog');
}
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)) {
print_error('nopermissionstodeleteentry', 'blog');
} else {
@ -131,7 +134,9 @@ if ($action === 'delete'){
echo $output->render($entry);
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();
die;
}
@ -166,10 +171,21 @@ $summaryoptions = array('maxfiles'=> 99, 'maxbytes'=>$CFG->maxbytes, 'trusttext'
'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', '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_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)) {
include_once($CFG->dirroot.'/tag/lib.php');
@ -177,13 +193,13 @@ if (!empty($CFG->usetags) && !empty($entry->id)) {
}
$entry->action = $action;
// set defaults
// Set defaults.
$blogeditform->set_data($entry);
if ($blogeditform->is_cancelled()) {
redirect($returnurl);
} else if ($data = $blogeditform->get_data()){
} else if ($data = $blogeditform->get_data()) {
switch ($action) {
case 'add':
@ -208,23 +224,23 @@ if ($blogeditform->is_cancelled()) {
}
// gui setup
// GUI setup.
switch ($action) {
case 'add':
// prepare new empty form
// Prepare new empty form.
$entry->publishstate = 'site';
$strformheading = get_string('addnewentry', 'blog');
$entry->action = $action;
if ($CFG->useblogassociations) {
//pre-select the course for associations
// Pre-select the course for associations.
if ($courseid) {
$context = context_course::instance($courseid);
$entry->courseassoc = $context->id;
}
//pre-select the mod for associations
// Pre-select the mod for associations.
if ($modid) {
$context = context_module::instance($modid);
$entry->modassoc = $context->id;