MDL-18910 full support for module intro editor with embedded images
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
require_once("../config.php");
|
||||
require_once("lib.php");
|
||||
require_once($CFG->libdir.'/filelib.php');
|
||||
require_once($CFG->libdir.'/gradelib.php');
|
||||
require_once($CFG->libdir.'/completionlib.php');
|
||||
require_once($CFG->libdir.'/conditionlib.php');
|
||||
|
||||
+3
-2
@@ -1555,12 +1555,13 @@ function filter_text($text, $courseid=NULL) {
|
||||
* @param string $module name of module
|
||||
* @param object $activity instance of activity
|
||||
* @param int $cmid course module id
|
||||
* @param bool $filter filter resulting html text
|
||||
* @return text
|
||||
*/
|
||||
function format_module_intro($module, $activity, $cmid) {
|
||||
function format_module_intro($module, $activity, $cmid, $filter=true) {
|
||||
global $CFG;
|
||||
require_once("$CFG->libdir/filelib.php");
|
||||
$options = (object)array('noclean'=>true, 'para'=>false);
|
||||
$options = (object)array('noclean'=>true, 'para'=>false, 'filter'=>false);
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cmid);
|
||||
$intro = file_rewrite_pluginfile_urls($activity->intro, 'pluginfile.php', $context->id, $module.'_intro', 0);
|
||||
return trim(format_text($intro, $activity->introformat, $options));
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
fwrite ($bf,full_tag("ID",4,false,$label->id));
|
||||
fwrite ($bf,full_tag("MODTYPE",4,false,"label"));
|
||||
fwrite ($bf,full_tag("NAME",4,false,$label->name));
|
||||
fwrite ($bf,full_tag("CONTENT",4,false,$label->content));
|
||||
fwrite ($bf,full_tag("CONTENT",4,false,$label->intro));
|
||||
fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$label->timemodified));
|
||||
//End mod
|
||||
$status = fwrite ($bf,end_tag("MOD",3,true));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="mod/label/db" VERSION="20060905" COMMENT="XMLDB file for Moodle mod/label"
|
||||
<XMLDB PATH="mod/label/db" VERSION="20090422" COMMENT="XMLDB file for Moodle mod/label"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
@@ -8,16 +8,17 @@
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="course"/>
|
||||
<FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="name"/>
|
||||
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="course" NEXT="content"/>
|
||||
<FIELD NAME="content" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="name" NEXT="timemodified"/>
|
||||
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="content"/>
|
||||
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="course" NEXT="intro"/>
|
||||
<FIELD NAME="intro" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="name" NEXT="introformat"/>
|
||||
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="false" UNSIGNED="true" DEFAULT="4" SEQUENCE="false" ENUM="false" PREVIOUS="intro" NEXT="timemodified"/>
|
||||
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="introformat"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
</KEYS>
|
||||
<INDEXES>
|
||||
<INDEX NAME="course" UNIQUE="false" FIELDS="course"/>
|
||||
</INDEXES>
|
||||
</TABLE>
|
||||
</TABLES>
|
||||
</XMLDB>
|
||||
</XMLDB>
|
||||
@@ -34,6 +34,32 @@ function xmldb_label_upgrade($oldversion) {
|
||||
upgrade_mod_savepoint($result, 2007101510, 'label');
|
||||
}
|
||||
|
||||
if ($result && $oldversion < 2009042200) {
|
||||
|
||||
/// Rename field content on table label to intro
|
||||
$table = new xmldb_table('label');
|
||||
$field = new xmldb_field('content', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null, 'name');
|
||||
|
||||
/// Launch rename field content
|
||||
$dbman->rename_field($table, $field, 'intro');
|
||||
|
||||
/// label savepoint reached
|
||||
upgrade_mod_savepoint($result, 2009042200, 'label');
|
||||
}
|
||||
|
||||
if ($result && $oldversion < 2009042201) {
|
||||
|
||||
/// Define field introformat to be added to label
|
||||
$table = new xmldb_table('label');
|
||||
$field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, null, null, '4', 'intro');
|
||||
|
||||
/// Launch add field introformat
|
||||
$dbman->add_field($table, $field);
|
||||
|
||||
/// label savepoint reached
|
||||
upgrade_mod_savepoint($result, 2009042201, 'label');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
+6
-5
@@ -8,7 +8,7 @@ define("LABEL_MAX_NAME_LENGTH", 50);
|
||||
function get_label_name($label) {
|
||||
$textlib = textlib_get_instance();
|
||||
|
||||
$name = strip_tags(format_string($label->content,true));
|
||||
$name = strip_tags(format_string($label->intro,true));
|
||||
if ($textlib->strlen($name) > LABEL_MAX_NAME_LENGTH) {
|
||||
$name = $textlib->substr($name, 0, LABEL_MAX_NAME_LENGTH)."...";
|
||||
}
|
||||
@@ -84,15 +84,16 @@ function label_get_participants($labelid) {
|
||||
function label_get_coursemodule_info($coursemodule) {
|
||||
global $DB;
|
||||
|
||||
if ($label = $DB->get_record('label', array('id'=>$coursemodule->instance), 'id, content, name')) {
|
||||
if ($label = $DB->get_record('label', array('id'=>$coursemodule->instance), 'id, name, intro, introformat')) {
|
||||
if (empty($label->name)) {
|
||||
// label name missing, fix it
|
||||
$label->name = "label{$label->id}";
|
||||
$DB->set_field('label', 'name', $label->name, array('id'=>$label->id));
|
||||
}
|
||||
$info = new object();
|
||||
$info->extra = urlencode($label->content);
|
||||
$info->name = urlencode($label->name);
|
||||
// no filtering hre because this info is cached and filtered later
|
||||
$info->extra = urlencode(format_module_intro('label', $label, $coursemodule->id, false));
|
||||
$info->name = urlencode($label->name);
|
||||
return $info;
|
||||
} else {
|
||||
return null;
|
||||
@@ -145,7 +146,7 @@ function label_supports($feature) {
|
||||
case FEATURE_GROUPS: return false;
|
||||
case FEATURE_GROUPINGS: return false;
|
||||
case FEATURE_GROUPMEMBERSONLY: return true;
|
||||
case FEATURE_MOD_INTRO: return false;
|
||||
case FEATURE_MOD_INTRO: return true;
|
||||
case FEATURE_COMPLETION_TRACKS_VIEWS: return false;
|
||||
case FEATURE_GRADE_HAS_GRADE: return false;
|
||||
case FEATURE_GRADE_OUTCOMES: return false;
|
||||
|
||||
@@ -7,10 +7,7 @@ class mod_label_mod_form extends moodleform_mod {
|
||||
|
||||
$mform =& $this->_form;
|
||||
|
||||
$mform->addElement('htmleditor', 'content', get_string('labeltext', 'label'), array('size'=>'64'));
|
||||
$mform->setType('content', PARAM_RAW);
|
||||
$mform->addRule('content', get_string('required'), 'required', null, 'client');
|
||||
$mform->setHelpButton('content', array('questions', 'richtext2'), false, 'editorhelpbutton');
|
||||
$this->add_intro_editor(true, get_string('labeltext', 'label'));
|
||||
|
||||
$this->standard_coursemodule_elements();
|
||||
|
||||
@@ -21,4 +18,3 @@ class mod_label_mod_form extends moodleform_mod {
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
//Now, build the LABEL record structure
|
||||
$label->course = $restore->course_id;
|
||||
$label->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
|
||||
$label->content = backup_todb($info['MOD']['#']['CONTENT']['0']['#']);
|
||||
$label->intro = backup_todb($info['MOD']['#']['CONTENT']['0']['#']);
|
||||
$label->timemodified = $info['MOD']['#']['TIMEMODIFIED']['0']['#'];
|
||||
|
||||
//The structure is equal to the db, so insert the label
|
||||
@@ -71,12 +71,12 @@
|
||||
foreach ($labels as $label) {
|
||||
//Increment counter
|
||||
$i++;
|
||||
$content = $label->content;
|
||||
$content = $label->intro;
|
||||
$result = restore_decode_content_links_worker($content,$restore);
|
||||
|
||||
if ($result != $content) {
|
||||
//Update record
|
||||
$label->content = $result;
|
||||
$label->intro = $result;
|
||||
$status = $DB->update_record("label", $label);
|
||||
if (debugging()) {
|
||||
if (!defined('RESTORE_SILENTLY')) {
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
/// This fragment is called by moodle_needs_upgrading() and /admin/index.php
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$module->version = 2007101510; // The current module version (Date: YYYYMMDDXX)
|
||||
$module->requires = 2007101509; // Requires this Moodle version
|
||||
$module->version = 2009042201; // The current module version (Date: YYYYMMDDXX)
|
||||
$module->requires = 2009041700; // Requires this Moodle version
|
||||
$module->cron = 0; // Period for cron to check this module (secs)
|
||||
|
||||
?>
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
require_login($course->id);
|
||||
require_login($course, true, $cm);
|
||||
|
||||
redirect("$CFG->wwwroot/course/view.php?id=$course->id");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user