Skip to content

Commit

Permalink
MDL-18910 full support for module intro editor with embedded images
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Apr 22, 2009
1 parent 3268cf9 commit 43b44d5
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 25 deletions.
1 change: 1 addition & 0 deletions course/modedit.php
Expand Up @@ -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');
Expand Down
5 changes: 3 additions & 2 deletions lib/weblib.php
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion mod/label/backuplib.php
Expand Up @@ -48,7 +48,7 @@ function label_backup_one_mod($bf,$preferences,$label) {
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));
Expand Down
13 changes: 7 additions & 6 deletions mod/label/db/install.xml
@@ -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"
>
Expand All @@ -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>
26 changes: 26 additions & 0 deletions mod/label/db/upgrade.php
Expand Up @@ -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;
}

Expand Down
11 changes: 6 additions & 5 deletions mod/label/lib.php
Expand Up @@ -8,7 +8,7 @@
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)."...";
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 1 addition & 5 deletions mod/label/mod_form.php
Expand Up @@ -7,10 +7,7 @@ function definition() {

$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();

Expand All @@ -21,4 +18,3 @@ function definition() {
}

}
?>
6 changes: 3 additions & 3 deletions mod/label/restorelib.php
Expand Up @@ -35,7 +35,7 @@ function label_restore_mods($mod,$restore) {
//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
Expand Down Expand Up @@ -71,12 +71,12 @@ function label_decode_content_links_caller($restore) {
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')) {
Expand Down
4 changes: 2 additions & 2 deletions mod/label/version.php
Expand Up @@ -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)

?>
2 changes: 1 addition & 1 deletion mod/label/view.php
Expand Up @@ -30,7 +30,7 @@
}
}

require_login($course->id);
require_login($course, true, $cm);

redirect("$CFG->wwwroot/course/view.php?id=$course->id");

Expand Down

0 comments on commit 43b44d5

Please sign in to comment.