MDL-18910 full support for module intro editor with embedded images

This commit is contained in:
skodak
2009-04-22 05:10:08 +00:00
parent 106815a4f1
commit ac3668bfae
19 changed files with 33 additions and 78 deletions
+4 -2
View File
@@ -1558,10 +1558,12 @@ function filter_text($text, $courseid=NULL) {
* @return text
*/
function format_module_intro($module, $activity, $cmid) {
$options = (object)array('noclean'=>true);
global $CFG;
require_once("$CFG->libdir/filelib.php");
$options = (object)array('noclean'=>true, 'para'=>false);
$context = get_context_instance(CONTEXT_MODULE, $cmid);
$intro = file_rewrite_pluginfile_urls($activity->intro, 'pluginfile.php', $context->id, $module.'_intro', 0);
return format_text($intro, $activity->introformat, $options);
return trim(format_text($intro, $activity->introformat, $options));
}
/**
+2 -4
View File
@@ -47,8 +47,6 @@
}
$currentsection = "";
$options->para = false;
$options->noclean = true;
foreach ($resources as $resource) {
if ($course->format == "weeks" or $course->format == "topics") {
$printsection = "";
@@ -72,12 +70,12 @@
if (!$resource->visible) { // Show dimmed if the mod is hidden
$table->data[] = array ($printsection,
"<a class=\"dimmed\" $extra href=\"view.php?id=$resource->coursemodule\">".format_string($resource->name,true)."</a>",
format_text($resource->intro, $resource->introformat, $options) );
format_module_intro('resource', $resource, $resource->coursemodule));
} else { //Show normal if the mod is visible
$table->data[] = array ($printsection,
"<a $extra href=\"view.php?id=$resource->coursemodule\">".format_string($resource->name,true)."</a>",
format_text($resource->intro, $resource->introformat, $options) );
format_module_intro('resource', $resource, $resource->coursemodule));
}
}
+1 -7
View File
@@ -28,8 +28,6 @@ class mod_resource_mod_form extends moodleform_mod {
//-------------------------------------------------------------------------------
$mform->addElement('header', 'general', get_string('general', 'form'));
// $mform->addElement('static', 'statictype', get_string('assignmenttype', 'assignment'), get_string('type'.$type,'assignment'));
$mform->addElement('text', 'name', get_string('name'), array('size'=>'48'));
if (!empty($CFG->formatstringstriptags)) {
$mform->setType('name', PARAM_TEXT);
@@ -38,11 +36,7 @@ class mod_resource_mod_form extends moodleform_mod {
}
$mform->addRule('name', null, 'required', null, 'client');
$mform->addElement('htmleditor', 'intro', get_string('summary'));
$mform->setType('intro', PARAM_RAW);
$mform->setHelpButton('intro', array('summary', get_string('summary'), 'resource'));
// summary should be optional again MDL-9485
//$mform->addRule('summary', get_string('required'), 'required', null, 'client');
$this->add_intro_editor(false);
$mform->addElement('header', 'typedesc', resource_get_name($type));
$this->_resinstance->setup_elements($mform);
@@ -40,10 +40,6 @@ function display() {
$subdir = optional_param('subdir','', PARAM_PATH);
$resource->reference = clean_param($resource->reference, PARAM_PATH);
$formatoptions = new object();
$formatoptions->noclean = true;
$formatoptions->para = false; // MDL-12061, <p> in html editor breaks xhtml strict
add_to_log($course->id, "resource", "view", "view.php?id={$cm->id}", $resource->id, $cm->id);
if ($resource->reference) {
@@ -91,7 +87,7 @@ function display() {
if (trim(strip_tags($resource->intro))) {
print_simple_box(format_text($resource->intro, $resource->introformat, $formatoptions, $course->id), "center");
print_simple_box(format_module_intro('resource', $resource, $cm->id), "center");
print_spacer(10,10);
}
+4 -10
View File
@@ -223,9 +223,6 @@ class resource_file extends resource_base {
$mimetype = mimeinfo("type", $resource->reference);
$pagetitle = strip_tags($course->shortname.': '.format_string($resource->name));
$formatoptions = new object();
$formatoptions->noclean = true;
if ($resource->options != "forcedownload") { // TODO nicolasconnault 14-03-07: This option should be renamed "embed"
if (in_array($mimetype, array('image/gif','image/jpeg','image/png'))) { // It's an image
$resourcetype = "image";
@@ -365,7 +362,7 @@ class resource_file extends resource_base {
echo '</script>';
if (trim(strip_tags($resource->intro))) {
print_simple_box(format_text($resource->intro, $resource->introformat, $formatoptions, $course->id), "center");
print_simple_box(format_module_intro('resource', $resource, $cm->id), "center");
}
$link = "<a href=\"$CFG->wwwroot/mod/resource/view.php?inpopup=true&amp;id={$cm->id}\" "
@@ -451,7 +448,7 @@ class resource_file extends resource_base {
///print the intro
if (!empty($resource->intro)) {
print_simple_box(format_text($resource->intro, $resource->introformat, $formatoptions, $course->id), "center");
print_simple_box(format_module_intro('resource', $resource, $cm->id), "center");
}
echo "</body></html>";
exit;
@@ -489,10 +486,7 @@ class resource_file extends resource_base {
print_header($pagetitle, $course->fullname, $navigation,
"", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm, "parent"));
$options = new object();
$options->para = false;
$options->noclean = true;
echo '<div class="summary">'.format_text($resource->intro, $resource->introformat, $options).'</div>';
echo '<div class="summary">'.format_module_intro('resource', $resource, $cm->id).'</div>';
if (!empty($localpath)) { // Show some help
echo '<div class="mdl-right helplink">';
link_to_popup_window ('/mod/resource/type/file/localpath.php', get_string('localfile', 'resource'),
@@ -706,7 +700,7 @@ class resource_file extends resource_base {
}
if (trim($resource->intro)) {
print_simple_box(format_text($resource->intro, $resource->introformat, $formatoptions, $course->id), "center");
print_simple_box(format_module_intro('resource', $resource, $cm->id), "center");
}
if ($inpopup) {
+1 -1
View File
@@ -103,7 +103,7 @@ function display() {
echo '</script>';
if (trim(strip_tags($resource->intro))) {
print_simple_box(format_text($resource->intro, $resource->introformat, $formatoptions, $course->id), "center");
print_simple_box(format_module_intro('resource', $resource, $cm->id), "center");
}
$link = "<a href=\"$CFG->wwwroot/mod/resource/view.php?inpopup=true&amp;id={$cm->id}\" onclick=\"this.target='resource{$resource->id}'; return openpopup('/mod/resource/view.php?inpopup=true&amp;id={$cm->id}', 'resource{$resource->id}','{$resource->popup}');\">".format_string($resource->name,true)."</a>";
+1 -4
View File
@@ -340,9 +340,6 @@ class resource_ims extends resource_base {
$mimetype = mimeinfo("type", $resource->reference);
$pagetitle = strip_tags($course->shortname.': '.format_string($resource->name));
$formatoptions = new object();
$formatoptions->noclean = true;
/// Cache this per request
static $items;
@@ -435,7 +432,7 @@ class resource_ims extends resource_base {
echo '</script>';
if (trim(strip_tags($resource->intro))) {
print_simple_box(format_text($resource->intro, $resource->introformat, $formatoptions, $course->id), "center");
print_simple_box(format_module_intro('resource', $resource, $cm->id), "center");
}
$link = "<a href=\"$CFG->wwwroot/mod/resource/view.php?inpopup=true&amp;id={$cm->id}\" target=\"resource{$resource->id}\" onclick=\"return openpopup('/mod/resource/view.php?inpopup=true&amp;id={$cm->id}', 'resource{$resource->id}','{$resource->popup}');\">".format_string($resource->name,true)."</a>";
@@ -212,9 +212,6 @@ function display() {
$mimetype = mimeinfo("type", $resource->reference);
$pagetitle = strip_tags($course->shortname.': '.format_string($resource->name));
$formatoptions = new object();
$formatoptions->noclean = true;
if ($resource->options != "frame") {
if (in_array($mimetype, array('image/gif','image/jpeg','image/png'))) { // It's an image
$resourcetype = "image";
@@ -314,8 +311,7 @@ function display() {
echo '</script>';
if (trim(strip_tags($resource->intro))) {
$formatoptions->noclean = true;
print_simple_box(format_text($resource->intro, $resource->introformat, $formatoptions, $course->id), "center");
print_simple_box(format_module_intro('resource', $resource, $cm->id), "center");
}
$link = "<a href=\"$CFG->wwwroot/mod/resource/view.php?inpopup=true&amp;id={$cm->id}\" target=\"resource{$resource->id}\" onclick=\"return openpopup('/mod/resource/view.php?inpopup=true&amp;id={$cm->id}', 'resource{$resource->id}','{$resource->popup}');\">".format_string($resource->name,true)."</a>";
@@ -365,7 +361,7 @@ function display() {
print_header($pagetitle, $course->fullname, $navigation, "", "", true,
update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm, "parent"));
echo '<div class="summary">'.format_text($resource->intro, $resource->introformat, $formatoptions).'</div>';
echo '<div class="summary">'.format_module_intro('resource', $resource, $cm->id).'</div>';
if (!empty($localpath)) { // Show some help
echo '<div class="mdl-right helplink">';
link_to_popup_window ('/mod/resource/type/file/localpath.php', get_string('localfile', 'resource'), get_string('localfilehelp','resource'), 400, 500, get_string('localfilehelp', 'resource'));
@@ -467,9 +463,8 @@ function display() {
echo "</p></center>";
}
if (trim($resource->summary)) {
$formatoptions->noclean = true;
print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions, $course->id), "center");
if (trim($resource->intro)) {
print_simple_box(format_module_intro('resource', $resource, $cm->id), "center");
}
if ($inpopup) {
+1 -1
View File
@@ -101,7 +101,7 @@ function display() {
echo '</script>';
if (trim(strip_tags($resource->intro))) {
print_simple_box(format_text($resource->intro, $resource->introformat, $formatoptions, $course->id), "center");
print_simple_box(format_module_intro('resource', $resource, $cm->id), "center");
}
$link = "<a href=\"$CFG->wwwroot/mod/resource/view.php?inpopup=true&amp;id={$cm->id}\" onclick=\"this.target='resource{$resource->id}'; return openpopup('/mod/resource/view.php?inpopup=true&amp;id={$cm->id}', 'resource{$resource->id}','{$resource->popup}');\">".format_string($resource->name,true)."</a>";
+2 -2
View File
@@ -84,11 +84,11 @@
if (!$scorm->visible) {
//Show dimmed if the mod is hidden
$table->data[] = array ($tt, "<a class=\"dimmed\" href=\"view.php?id=$scorm->coursemodule\">".format_string($scorm->name)."</a>",
format_text($scorm->intro, $scorm->introformat, $options), $reportshow);
format_module_intro('scorm', $scorm, $scorm->coursemodule), $reportshow);
} else {
//Show normal if the mod is visible
$table->data[] = array ($tt, "<a href=\"view.php?id=$scorm->coursemodule\">".format_string($scorm->name)."</a>",
format_text($scorm->intro, $scorm->introformat, $options), $reportshow);
format_module_intro('scorm', $scorm, $scorm->coursemodule), $reportshow);
}
}
+1 -11
View File
@@ -774,17 +774,7 @@ function scorm_pluginfile($course, $cminfo, $context, $filearea, $args) {
$lifetime = isset($CFG->filelifetime) ? $CFG->filelifetime : 86400;
if ($filearea === 'scorm_intro') {
// all users may access it
$relativepath = '/'.implode('/', $args);
$fullpath = $context->id.'scorm_intro0'.$relativepath;
$fs = get_file_storage();
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
return false;
}
} else if ($filearea === 'scorm_content') {
if ($filearea === 'scorm_content') {
$revision = (int)array_shift($args); // prevents caching problems - ignored here
$relativepath = '/'.implode('/', $args);
$fullpath = $context->id.'scorm_content0'.$relativepath;
+1 -1
View File
@@ -701,7 +701,7 @@ function scorm_course_format_display($user,$course) {
$colspan = ' colspan="2"';
}
$options = (object)array('noclean'=>true);
$headertext .= '</td></tr><tr><td'.$colspan.'>'.get_string('summary').':<br />'.format_text($scorm->intro, $scorm->introformat, $options).'</td></tr></table>';
$headertext .= '</td></tr><tr><td'.$colspan.'>'.get_string('summary').':<br />'.format_module_intro('scorm', $scorm, $scorm->coursemodule).'</td></tr></table>';
print_simple_box($headertext,'','100%');
scorm_view_display($user, $scorm, 'view.php?id='.$course->id, $cm, '100%');
} else {
+1 -4
View File
@@ -30,10 +30,7 @@ class mod_scorm_mod_form extends moodleform_mod {
$mform->addRule('name', null, 'required', null, 'client');
// Summary
$mform->addElement('htmleditor', 'intro', get_string('summary'));
$mform->setType('intro', PARAM_RAW);
$mform->addRule('intro', get_string('required'), 'required', null, 'client');
$mform->setHelpButton('intro', array('writing', 'questions', 'richtext2'), false, 'editorhelpbutton');
$this->add_intro_editor(true);
// Scorm types
$options = array(SCORM_TYPE_LOCAL => get_string('typelocal', 'scorm'));
+2 -3
View File
@@ -72,11 +72,10 @@
// Print the main part of the page
print_heading(format_string($scorm->name));
$attemptstatus = '';
if($scorm->displayattemptstatus == 1) {
if ($scorm->displayattemptstatus == 1) {
$attemptstatus = scorm_get_attempt_status($USER,$scorm);
}
$options = (object)array('noclean'=>true);
print_simple_box(format_text($scorm->intro, $scorm->introformat, $options).$attemptstatus, 'center', '70%', '', 5, 'generalbox', 'intro');
print_simple_box(format_module_intro('scorm', $scorm, $cm->id).$attemptstatus, 'center', '70%', '', 5, 'generalbox', 'intro');
$scormopen = true;
$timenow = time();
+2 -4
View File
@@ -4,8 +4,8 @@ require_once ($CFG->dirroot.'/course/moodleform_mod.php');
class mod_survey_mod_form extends moodleform_mod {
function definition() {
global $CFG, $DB;
$mform =& $this->_form;
$strrequired = get_string('required');
@@ -33,9 +33,7 @@ class mod_survey_mod_form extends moodleform_mod {
$mform->addRule('template', $strrequired, 'required', null, 'client');
$mform->setHelpButton('template', array('surveys', get_string('helpsurveys', 'survey')));
$mform->addElement('textarea', 'intro', get_string('customintro', 'survey'), 'wrap="virtual" rows="20" cols="75"');
$mform->setType('intro', PARAM_RAW);
$this->add_intro_editor(false, get_string('customintro', 'survey'));
$this->standard_coursemodule_elements();
+2 -3
View File
@@ -80,8 +80,7 @@
} else {
$options = (object)array('noclean'=>true);
print_box(format_text($survey->intro, $survey->introformat, $options), 'generalbox', 'intro');
print_box(format_module_intro('survey', $survey, $cm->id), 'generalbox', 'intro');
print_spacer(30);
$questions = $DB->get_records_list("survey_questions", "id", explode(',', $survey->questions));
@@ -112,7 +111,7 @@
echo '<div>';
echo "<input type=\"hidden\" name=\"id\" value=\"$id\" />";
print_simple_box(format_text($survey->intro), 'center', '70%', '', 5, 'generalbox', 'intro');
print_simple_box(format_module_intro('survey', $survey, $cm->id), 'center', '70%', '', 5, 'generalbox', 'intro');
// Get all the major questions and their proper order
if (! $questions = $DB->get_records_list("survey_questions", "id", explode(',', $survey->questions))) {
+1 -1
View File
@@ -69,7 +69,7 @@
$timmod = '<span class="smallinfo">'.userdate($wiki->timemodified).'</span>';
$options = (object)array('noclean'=>true);
$summary = '<div class="smallinfo">'.format_text($wiki->intro, $wiki->introformat, $options).'</div>';
$summary = '<div class="smallinfo">'.format_module_intro('wiki', $wiki, $wiki->coursemodule).'</div>';
$site = get_site();
switch ($wiki->wtype) {
+1 -4
View File
@@ -21,10 +21,7 @@ class mod_wiki_mod_form extends moodleform_mod {
$mform->setType('name', PARAM_NOTAGS);
$mform->addRule('name', null, 'required', null, 'client');
$mform->addElement('htmleditor', 'intro', get_string('summary'));
$mform->setType('intro', PARAM_RAW);
$mform->setHelpButton('intro', array('writing', 'questions', 'richtext2'), false, 'editorhelpbutton');
$mform->addRule('intro', get_string('required'), 'required', null, 'client');
$this->add_intro_editor(true);
if (!$wikihasentries){
asort($WIKI_TYPES);
+1 -2
View File
@@ -347,8 +347,7 @@
if($wiki_entry && $ewiki_title==$wiki_entry->pagename && !empty($wiki->intro)) {
if (trim(strip_tags($wiki->intro))) {
$options = (object)array('noclean'=>true);
print_box(format_text($wiki->intro, $wiki->introformat, $options), 'generalbox', 'intro');
print_box(format_module_intro('wiki', $wiki, $cm->id), 'generalbox', 'intro');
}
}