Skip to content

Commit

Permalink
files MDL-20601 Conversion of many of the uses of print_textarea, and…
Browse files Browse the repository at this point in the history
… the mforms htmleditor to the new editor

Please forgive me if I have missed converting any output statements. If you do find an output statement that is not formatting correctly please refere to the table I added to this bug in regards to how it should be formatted.
  • Loading branch information
Sam Hemelryk committed Nov 4, 2009
1 parent 8432f5e commit 8bdc9ca
Show file tree
Hide file tree
Showing 58 changed files with 1,532 additions and 625 deletions.
6 changes: 5 additions & 1 deletion admin/report/spamcleaner/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,11 @@ function print_user_entry($user, $keywords, $count) {
$user->description = highlight($keyword, $user->description);
}

$html .= '<td align="left">'.format_text($user->description, FORMAT_MOODLE).'</td>';
if (!isset($user->descriptionformat)) {
$user->descriptionformat = FORMAT_MOODLE;
}

$html .= '<td align="left">'.format_text($user->description, $user->descriptionformat).'</td>';
$html .= '<td width="100px" align="center">';
$html .= '<button onclick="del_user(this,'.$user->id.')">'.get_string('deleteuser', 'admin').'</button><br />';
$html .= '<button onclick="ignore_user(this,'.$user->id.')">'.get_string('ignore', 'admin').'</button>';
Expand Down
2 changes: 1 addition & 1 deletion admin/uploaduser.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
'maildisplay', 'maildigest', 'htmleditor', 'ajax', 'autosubscribe',
'mnethostid', 'institution', 'department', 'idnumber', 'skype',
'msn', 'aim', 'yahoo', 'icq', 'phone1', 'phone2', 'address',
'url', 'description', 'oldusername', 'emailstop', 'deleted',
'url', 'description', 'descriptionformat', 'oldusername', 'emailstop', 'deleted',
'password');

$PRF_FIELDS = array();
Expand Down
21 changes: 19 additions & 2 deletions admin/uploaduser_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,9 @@ function definition (){
$mform->setDefault('lang', $templateuser->lang);
$mform->setAdvanced('lang');

$mform->addElement('htmleditor', 'description', get_string('userdescription'));
$mform->setType('description', PARAM_CLEAN);
$editoroptions = array('maxfiles'=>0, 'maxbytes'=>0, 'trusttext'=>false, 'forcehttps'=>false);
$mform->addElement('editor', 'description', get_string('userdescription'), null, $editoroptions);
$mform->setType('description', PARAM_CLEANHTML);
$mform->setHelpButton('description', array('text2', get_string('helptext')));
$mform->setAdvanced('description');

Expand Down Expand Up @@ -334,5 +335,21 @@ function validation($data, $files) {

return $errors;
}

/**
* Used to reformat the data from the editor component
*
* @return stdClass
*/
function get_data() {
$data = parent::get_data();

if ($data !== null) {
$data->descriptionformat = $data->description['format'];
$data->description = $data->description['text'];
}

return $data;
}
}

4 changes: 3 additions & 1 deletion blocks/course_summary/block_course_summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ function get_content() {
$this->content = new object();
$options = new object();
$options->noclean = true; // Don't clean Javascripts etc
$this->content->text = format_text($this->page->course->summary, FORMAT_HTML, $options);
$context = get_context_instance(CONTEXT_COURSE, $this->page->course->id);
$this->page->course->summary = file_rewrite_pluginfile_urls($this->page->course->summary, 'pluginfile.php', $context->id, 'course_summary', $this->page->course->id);
$this->content->text = format_text($this->page->course->summary, $this->page->course->summaryformat, $options);
if ($this->page->user_is_editing()) {
if($this->page->course->id == SITEID) {
$editpage = $CFG->wwwroot.'/'.$CFG->admin.'/settings.php?section=frontpagesettings';
Expand Down
6 changes: 5 additions & 1 deletion calendar/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,9 @@ function calendar_print_event($event, $showactions=true) {
static $strftimetime;

$event = calendar_add_event_metadata($event);
if (!($event instanceof calendar_event)) {
$event = new calendar_event($event);
}
echo '<a name="event_'.$event->id.'"></a><table class="event" cellspacing="0">';
echo '<tr><td class="picture">';
if (!empty($event->icon)) {
Expand Down Expand Up @@ -571,7 +574,8 @@ function calendar_print_event($event, $showactions=true) {
} else {
echo '<td class="description">';
}
echo format_text($event->description, FORMAT_HTML);

echo $event->description;
if (calendar_edit_event_allowed($event) && $showactions) {
echo '<div class="commands">';
$calendarcourseid = '';
Expand Down
8 changes: 7 additions & 1 deletion course/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,13 @@
/// Print current category description
if (!$editingon && $category->description) {
echo $OUTPUT->box_start();
echo format_text($category->description); // for multilang filter
$options = new stdClass;
$options->noclean = true;
$options->para = false;
if (!isset($category->descriptionformat)) {
$category->descriptionformat = FORMAT_MOODLE;
}
echo format_text($category->description, $category->descriptionformat, $options);
echo $OUTPUT->box_end();
}

Expand Down
33 changes: 24 additions & 9 deletions course/edit.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php // $Id$
<?php
// Edit course settings

require_once('../config.php');
Expand All @@ -24,8 +24,8 @@
}
require_login($course->id);
$category = $DB->get_record('course_categories', array('id'=>$course->category));
require_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id));

$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('moodle/course:update', $coursecontext);
} else if ($categoryid) { // creating new course in this category
$course = null;
require_login();
Expand All @@ -45,7 +45,8 @@
$PAGE->url->param('category',$categoryid);
}

/// prepare course
/// Prepare course and the editor
$editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>false, 'noclean'=>true);
if (!empty($course)) {
$allowedmods = array();
if (!empty($course)) {
Expand All @@ -60,12 +61,15 @@
}
$course->allowedmods = $allowedmods;
}
$course = file_prepare_standard_editor($course, 'summary', $editoroptions, $coursecontext, 'course_summary', $course->id);
} else {
$course = file_prepare_standard_editor($course, 'summary', $editoroptions, null, 'course_summary', null);
}

/// first create the form
$editform = new course_edit_form('edit.php', compact('course', 'category'));
$editform = new course_edit_form('edit.php', compact('course', 'category', 'editoroptions'));
// now override defaults if course already exists
if (!empty($course)) {
if (!empty($course->id)) {
$course->enrolpassword = $course->password; // we need some other name for password field MDL-9929
$editform->set_data($course);
}
Expand All @@ -84,13 +88,22 @@
//preprocess data
$data->timemodified = time();

if (empty($course)) {
if (empty($course->id)) {
// In creating the course
if (!$course = create_course($data)) {
print_error('coursenotcreated');
}

// Get the context of the newly created course
$context = get_context_instance(CONTEXT_COURSE, $course->id);

// Save the files used in the summary editor
$editordata = new stdClass;
$editordata->id = $course->id;
$editordata->summary_editor = $data->summary_editor;
$editordata = file_postupdate_standard_editor($editordata, 'summary', $editoroptions, $context, 'course_summary', $course->id);
$DB->update_record('course', $editordata);

// assign default role to creator if not already having permission to manage course assignments
if (!has_capability('moodle/course:view', $context) or !has_capability('moodle/role:assign', $context)) {
role_assign($CFG->creatornewroleid, $USER->id, 0, $context->id);
Expand All @@ -109,6 +122,8 @@
}

} else {
// Save any changes to the files used in the editor
$data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $coursecontext, 'course_summary', $data->id);
if (!update_course($data)) {
print_error('coursenotupdated');
}
Expand All @@ -126,7 +141,7 @@
$stradministration = get_string("administration");
$strcategories = get_string("categories");

if (!empty($course)) {
if (!empty($course->id)) {
$PAGE->navbar->add($streditcoursesettings);
$title = $streditcoursesettings;
$fullname = $course->fullname;
Expand All @@ -148,4 +163,4 @@

echo $OUTPUT->footer();

?>
?>
35 changes: 18 additions & 17 deletions course/edit_form.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php //$Id$
<?php

require_once($CFG->libdir.'/formslib.php');

Expand All @@ -12,13 +12,13 @@ function definition() {

$course = $this->_customdata['course'];
$category = $this->_customdata['category'];
$editoroptions = $this->_customdata['editoroptions'];

$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$categorycontext = get_context_instance(CONTEXT_COURSECAT, $category->id);

$disable_meta = false; // basic meta course state protection; server-side security checks not needed

if (!empty($course)) {
if (!empty($course->id)) {
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$context = $coursecontext;

Expand Down Expand Up @@ -52,7 +52,7 @@ function definition() {
$coursecontext = null;
$context = $categorycontext;
}

/// form definition with new course defaults
//--------------------------------------------------------------------------------
$mform->addElement('header','general', get_string('general', 'form'));
Expand All @@ -71,7 +71,7 @@ function definition() {
$mform->setDefault('category', $category->id);
$mform->setType('category', PARAM_INT);

if ($course and !has_capability('moodle/course:changecategory', $coursecontext)) {
if (!empty($course->id) and !has_capability('moodle/course:changecategory', $coursecontext)) {
$mform->hardFreeze('category');
$mform->setConstant('category', $category->id);
}
Expand All @@ -88,7 +88,7 @@ function definition() {
$mform->setHelpButton('fullname', array('coursefullname', get_string('fullnamecourse')), true);
$mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
$mform->setType('fullname', PARAM_MULTILANG);
if ($course and !has_capability('moodle/course:changefullname', $coursecontext)) {
if (!empty($course->id) and !has_capability('moodle/course:changefullname', $coursecontext)) {
$mform->hardFreeze('fullname');
$mform->setConstant('fullname', $course->fullname);
}
Expand All @@ -99,7 +99,7 @@ function definition() {
$mform->setHelpButton('shortname', array('courseshortname', get_string('shortnamecourse')), true);
$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform->setType('shortname', PARAM_MULTILANG);
if ($course and !has_capability('moodle/course:changeshortname', $coursecontext)) {
if (!empty($course->id) and !has_capability('moodle/course:changeshortname', $coursecontext)) {
$mform->hardFreeze('shortname');
$mform->setConstant('shortname', $course->shortname);
}
Expand All @@ -109,17 +109,18 @@ function definition() {
$mform->addElement('text','idnumber', get_string('idnumbercourse'),'maxlength="100" size="10"');
$mform->setHelpButton('idnumber', array('courseidnumber', get_string('idnumbercourse')), true);
$mform->setType('idnumber', PARAM_RAW);
if ($course and !has_capability('moodle/course:changeidnumber', $coursecontext)) {
if (!empty($course->id) and !has_capability('moodle/course:changeidnumber', $coursecontext)) {
$mform->hardFreeze('idnumber');
$mform->setConstants('idnumber', $course->idnumber);
}

$mform->addElement('htmleditor','summary', get_string('summary'), array('rows'=> '10', 'cols'=>'65'));
$mform->setHelpButton('summary', array('text2', get_string('helptext')), true);
$mform->setType('summary', PARAM_RAW);

$mform->addElement('editor','summary_editor', get_string('summary'), null, $editoroptions);
$mform->setHelpButton('summary_editor', array('text2', get_string('helptext')), true);
$mform->setType('summary_editor', PARAM_RAW);

if ($course and !has_capability('moodle/course:changesummary', $coursecontext)) {
$mform->hardFreeze('summary');
if (!empty($course->id) and !has_capability('moodle/course:changesummary', $coursecontext)) {
$mform->hardFreeze('summary_editor');
}

$courseformats = get_plugin_list('format');
Expand Down Expand Up @@ -211,7 +212,7 @@ function definition() {


$roles = get_assignable_roles($context);
if (!empty($course)) {
if (!empty($course->id)) {
// add current default role, so that it is selectable even when user can not assign it
if ($current_role = $DB->get_record('role', array('id'=>$course->defaultrole))) {
$roles[$current_role->id] = strip_tags(format_string($current_role->name, true));
Expand Down Expand Up @@ -311,7 +312,7 @@ function definition() {
$mform->addElement('select', 'visible', get_string('availability'), $choices);
$mform->setHelpButton('visible', array('courseavailability', get_string('availability')), true);
$mform->setDefault('visible', $courseconfig->visible);
if ($course and !has_capability('moodle/course:visibility', $coursecontext)) {
if (!empty($course->id) and !has_capability('moodle/course:visibility', $coursecontext)) {
$mform->hardFreeze('visible');
$mform->setConstant('visible', $course->visible);
}
Expand All @@ -322,7 +323,7 @@ function definition() {
$mform->setDefault('enrolpassword', $courseconfig->enrolpassword);
$mform->setType('enrolpassword', PARAM_RAW);

if (empty($course) or ($course->password !== '' and $course->id != SITEID)) {
if (empty($course->id) or ($course->password !== '' and $course->id != SITEID)) {
// do not require password in existing courses that do not have password yet - backwards compatibility ;-)
if (!empty($CFG->enrol_manual_requirekey)) {
$mform->addRule('enrolpassword', get_string('required'), 'required', null, 'client');
Expand All @@ -339,7 +340,7 @@ function definition() {

// If we are creating a course, its enrol method isn't yet chosen, BUT the site has a default enrol method which we can use here
$enrol_object = $CFG;
if (!empty($course)) {
if (!empty($course->id)) {
$enrol_object = $course;
}
// If the print_entry method exists and the course enrol method isn't manual (both set or inherited from site), show cost
Expand Down
25 changes: 17 additions & 8 deletions course/editcategory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php // $Id$
<?php
/**
* Page for creating or editing course category name/parent/description.
* When called with an id parameter, edits the category with that id.
Expand All @@ -18,8 +18,10 @@
print_error('unknowcategory');
}
$PAGE->set_url('course/editcategory.php', array('id' => $id));
require_capability('moodle/category:manage', get_context_instance(CONTEXT_COURSECAT, $id));
$categorycontext = get_context_instance(CONTEXT_COURSECAT, $id);
require_capability('moodle/category:manage', $categorycontext);
$strtitle = get_string('editcategorysettings');
$editorcontext = $categorycontext;
} else {
$parent = required_param('parent', PARAM_INT);
$PAGE->set_url('course/editcategory.php', array('parent' => $parent));
Expand All @@ -36,9 +38,13 @@
$category->parent = $parent;
require_capability('moodle/category:manage', $context);
$strtitle = get_string("addnewcategory");
$editorcontext = null;
}

$mform = new editcategory_form('editcategory.php', $category);
$editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>true);
$category = file_prepare_standard_editor($category, 'description', $editoroptions, $editorcontext, 'category_description', $category->id);

$mform = new editcategory_form('editcategory.php', compact('category', 'editoroptions'));
$mform->set_data($category);

if ($mform->is_cancelled()) {
Expand All @@ -52,7 +58,7 @@
} else if ($data = $mform->get_data()) {
$newcategory = new stdClass();
$newcategory->name = $data->name;
$newcategory->description = $data->description;
$newcategory->description_editor = $data->description_editor;
$newcategory->parent = $data->parent; // if $data->parent = 0, the new category will be a top-level category

if (isset($data->theme) && !empty($CFG->allowcategorythemes)) {
Expand All @@ -66,17 +72,20 @@
$parent_cat = $DB->get_record('course_categories', array('id' => $newcategory->parent));
move_category($newcategory, $parent_cat);
}
$DB->update_record('course_categories', $newcategory);
fix_course_sortorder();

} else {
// Create a new category.
$newcategory->description = $data->description_editor['text'];
$newcategory->sortorder = 999;
$newcategory->id = $DB->insert_record('course_categories', $newcategory);
$newcategory->context = get_context_instance(CONTEXT_COURSECAT, $newcategory->id);
$categorycontext = $newcategory->context;
mark_context_dirty($newcategory->context->path);
fix_course_sortorder(); // Required to build course_categories.depth and .path.
}

$newcategory = file_postupdate_standard_editor($newcategory, 'description', $editoroptions, $categorycontext, 'category_description', $newcategory->id);
$DB->update_record('course_categories', $newcategory);
fix_course_sortorder();

redirect('category.php?id='.$newcategory->id.'&categoryedit=on');
}

Expand Down
Loading

0 comments on commit 8bdc9ca

Please sign in to comment.