MDL-16698 towards new general editor element + converted course section summaries

This commit is contained in:
skodak 2009-02-17 16:18:05 +00:00
parent cd010c0b2f
commit 644d506ac1
9 changed files with 86 additions and 69 deletions

View File

@ -1,24 +0,0 @@
<form id="theform" method="post" action="editsection.php">
<table summary="Summary of week" cellpadding="5" class="boxaligncenter">
<tr valign="top">
<td align="right"><p><b><?php print_string("summary") ?>:</b></p>
<?php helpbutton("summaries", get_string("helpsummaries"), "moodle", true, true);
echo "<br />";
if ($usehtmleditor) {
helpbutton("richtext2", get_string("helprichtext"), "moodle", true, true);
} else {
helpbutton("text2", get_string("helptext"), "moodle", true, true);
}
?>
</td>
<td>
<?php print_textarea($usehtmleditor, 25, 60, 0, 0, 'summary', $form->summary, 0, false, 'summary'); ?>
</td>
</tr>
</table>
<div class="singlebutton">
<input type="hidden" name="id" value="<?php echo $form->id ?>" />
<input type="hidden" name="sesskey" value="<?php echo sesskey() ?>" />
<input type="submit" value="<?php print_string("savechanges") ?>" />
</div>
</form>

View File

@ -3,8 +3,10 @@
require_once("../config.php");
require_once("lib.php");
require_once($CFG->libdir.'/filelib.php');
require_once('editsection_form.php');
$id = required_param('id',PARAM_INT); // Week ID
$id = required_param('id',PARAM_INT); // Week/topic ID
if (! $section = $DB->get_record("course_sections", array("id"=>$id))) {
print_error("sectionnotexist");
@ -14,36 +16,29 @@
print_error("invalidcourseid");
}
require_login($course->id);
require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('moodle/course:update', $context);
require_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id));
$draftitemid = file_get_submitted_draftitemid('summary');
$currenttext = file_prepare_draftarea($draftitemid, $context->id, 'course_section', $section->id, true, $section->summary);
$mform = new editsection_form(null, $course);
$data = array('id'=>$section->id, 'summary'=>array('text'=>$currenttext, 'format'=>FORMAT_HTML, 'itemid'=>$draftitemid));
$mform->set_data($data); // set defaults
/// If data submitted, then process and store.
if ($mform->is_cancelled()){
redirect($CFG->wwwroot.'/course/view.php?id='.$course->id);
if ($form = data_submitted() and confirm_sesskey()) {
$timenow = time();
if (!$DB->set_field("course_sections", "summary", $form->summary, array("id"=>$section->id))) {
print_error("cannotupdatesummary");
}
} else if ($data = $mform->get_data()) {
$text = file_convert_draftarea($data->summary['itemid'], $context->id, 'course_section', $section->id, true, $data->summary['text']);
$DB->set_field("course_sections", "summary", $text, array("id"=>$section->id));
add_to_log($course->id, "course", "editsection", "editsection.php?id=$section->id", "$section->section");
redirect("view.php?id=$course->id");
exit;
}
/// Otherwise fill and print the form.
if (empty($form)) {
$form = $section;
}
// !! no db access using data from $form beyond this point !!
$usehtmleditor = can_use_html_editor();
/// Inelegant hack for bug 3408
if ($course->format == 'site') {
$sectionname = get_string('site');
@ -52,15 +47,13 @@
} else {
$sectionname = get_section_name($course->format);
$stredit = get_string('edit', '', " $sectionname $section->section");
$strsummaryof = get_string('summaryof', '', " $sectionname $form->section");
$strsummaryof = get_string('summaryof', '', " $sectionname $section->section");
}
print_header_simple($stredit, '', build_navigation(array(array('name' => $stredit, 'link' => null, 'type' => 'misc'))), 'theform.summary' );
print_heading($strsummaryof);
print_simple_box_start('center');
include('editsection.html');
print_simple_box_end();
print_heading_with_help($strsummaryof, 'summaries');
$mform->display();
print_footer($course);
?>

View File

@ -0,0 +1,22 @@
<?php //$Id$
require_once($CFG->libdir.'/formslib.php');
class editsection_form extends moodleform {
function definition() {
global $CFG, $DB;
$mform = $this->_form;
$course = $this->_customdata;
$mform->addElement('editor', 'summary', get_string('summary'), array('changeformat'=>false, 'maxfiles'=>-1));
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
//--------------------------------------------------------------------------------
$this->add_action_buttons();
}
}

View File

@ -26,6 +26,7 @@
//TODO (nfreear): Accessibility: evaluation, lang/en_utf8/moodle.php: $string['formattopicscss']
require_once($CFG->libdir.'/ajax/ajaxlib.php');
require_once($CFG->libdir.'/filelib.php');
$topic = optional_param('topic', -1, PARAM_INT);
@ -133,10 +134,14 @@
echo '<div class="right side" >&nbsp;</div>';
echo '<div class="content">';
echo '<div class="summary">';
$summaryformatoptions->noclean = true;
echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$summarytext = file_convert_relative_pluginfiles($thissection->summary, 'pluginfile.php', "$coursecontext->id/course_section/$thissection->id/");
$summaryformatoptions = new object();
$summaryformatoptions->noclean = true;
echo format_text($summarytext, FORMAT_HTML, $summaryformatoptions);
if (isediting($course->id) && has_capability('moodle/course:update', $coursecontext)) {
echo '<a title="'.$streditsummary.'" '.
' href="editsection.php?id='.$thissection->id.'"><img src="'.$CFG->pixpath.'/t/edit.gif" '.
' class="icon edit" alt="'.$streditsummary.'" /></a>';

View File

@ -26,6 +26,7 @@
//TODO (nfreear): Accessibility: evaluation, lang/en_utf8/moodle.php: $string['formatweekscss']
require_once($CFG->libdir.'/ajax/ajaxlib.php');
require_once($CFG->libdir.'/filelib.php');
$week = optional_param('week', -1, PARAM_INT);
@ -123,8 +124,12 @@
echo '<div class="content">';
echo '<div class="summary">';
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$summarytext = file_convert_relative_pluginfiles($thissection->summary, 'pluginfile.php', "$coursecontext->id/course_section/$thissection->id/");
$summaryformatoptions = new object();
$summaryformatoptions->noclean = true;
echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
echo format_text($summarytext, FORMAT_HTML, $summaryformatoptions);
if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
echo '<p><a title="'.$streditsummary.'" '.

View File

@ -32,7 +32,8 @@
require_once('config.php');
require_once($CFG->dirroot .'/course/lib.php');
require_once($CFG->dirroot .'/lib/blocklib.php');
require_once($CFG->libdir .'/blocklib.php');
require_once($CFG->libdir .'/filelib.php');
// Bounds for block widths
// more flexible for theme designers taken from theme config.php
@ -144,9 +145,12 @@
echo '</font></p>';
}
$options = NULL;
$options->noclean = true;
echo format_text($section->summary, FORMAT_HTML, $options);
$context = get_context_instance(CONTEXT_COURSE, SITEID);
$summarytext = file_convert_relative_pluginfiles($section->summary, 'pluginfile.php', "$context->id/course_section/$section->id/");
$summaryformatoptions = new object();
$summaryformatoptions->noclean = true;
echo format_text($summarytext, FORMAT_HTML, $summaryformatoptions);
if ($editing) {
$streditsummary = get_string('editsummary');

View File

@ -152,7 +152,6 @@ $string['cannotupdateprofile'] = 'Error updating user record';
$string['cannotupdatecustomprofile'] = 'Error updating user custom record';
$string['cannotupdaterss'] = 'Cannot update RSS';
$string['cannotupdatesecret'] = 'Error resetting user secret string';
$string['cannotupdatesummary'] = 'Could not update the summary!';
$string['cannotupdatesubcate'] = 'Could not update a child category!';
$string['cannotupdatesubcourse'] = 'Could not update a child course!';
$string['cannotuploadfile'] = 'Error processing upload file';

View File

@ -131,20 +131,32 @@ function file_prepare_draftarea(&$draftitemid, $contextid, $filearea, $itemid, $
}
/// relink embedded files - editor can not handle @@PLUGINFILE@@ !
return file_convert_relative_pluginfiles($text, 'draftfile.php', "$usercontext->id/user_draft/$draftitemid/", $forcehttps);
}
/**
* Convert relative @@PLUGINFILE@@ into real absolute paths
* @param string $text
* @param string $file pluginfile.php, draftfile.php, etc
* @param string $pluginstub path 'contextid/area/itemid/'
* @param boot $forcehttps
* @return string text with absolute links
*
*/
function file_convert_relative_pluginfiles($text, $file, $pluginstub, $forcehttps=false) {
global $CFG;
if ($CFG->slasharguments) {
$draftbase = "$CFG->wwwroot/draftfile.php/$usercontext->id/user_draft/$draftitemid/";
$draftbase = "$CFG->wwwroot/$file/$pluginstub";
} else {
$draftbase = "$CFG->wwwroot/draftfile.php?file=/$usercontext->id/user_draft/$draftitemid/";
$draftbase = "$CFG->wwwroot/draftfile.php?file=/$pluginstub";
}
if ($forcehttps) {
$draftbase = str_replace('http://', 'https://', $draftbase);
}
$text = str_replace('@@PLUGINFILE@@/', $draftbase);
return $text;
return str_replace('@@PLUGINFILE@@/', $draftbase, $text);
}
/**
@ -261,7 +273,7 @@ function file_convert_draftarea($draftitemid, $contextid, $filearea, $itemid, $s
$draftbase = str_replace('http://', 'https://', $draftbase);
}
$text = str_ireplace($draftbase, '@@PLUGINFILE@@/');
$text = str_ireplace($draftbase, '@@PLUGINFILE@@/', $text);
return $text;
}

View File

@ -158,6 +158,7 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
$str .= '</select>';
} else {
// no changes of format allowed
$str .= '<input type="hidden" name="'.$elname.'[format]" value="'.s($formats[$format]).'" />';
$str .= $formats[$format];
}
$str .= '</div>';
@ -179,10 +180,10 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
/// TODO: somehow pass 'itemid' to tinymce so that image chooser known where to look for and upload files,
// also include list of expected file types handled by editor array('image', 'video', 'media')
// JS code by Dongsheng goes here
// JS code by Dongsheng goes here - uncomment following block when finished
/// TODO: hide embedded file manager if tinymce used
if ($editorclass === 'form-textarea-advanced') {
/* if ($editorclass === 'form-textarea-advanced') {
$str .= '<script type="text/javascript">
//<![CDATA[
var fileman = document.getElementById("'.$id.'_filemanager");
@ -191,7 +192,7 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
//]]>
</script>';
}
}*/
}