]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-18910 full support for module intro editor with embedded images
authorskodak <skodak>
Wed, 22 Apr 2009 07:14:19 +0000 (07:14 +0000)
committerskodak <skodak>
Wed, 22 Apr 2009 07:14:19 +0000 (07:14 +0000)
course/modedit.php
lib/weblib.php
mod/label/backuplib.php
mod/label/db/install.xml
mod/label/db/upgrade.php
mod/label/lib.php
mod/label/mod_form.php
mod/label/restorelib.php
mod/label/version.php
mod/label/view.php

index 54a514117499d23eede99119f1707c46b3254b6f..b3fd4e06b05ec9335959aa67b9f767ad747de51f 100644 (file)
@@ -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');
index 540b4646bc2729945e5af95b25c29be1ac555d11..a386f27871b41485af9b1c27629f67388dc52ed0 100644 (file)
@@ -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));
index 6b075572bd86283eca5c91a97126d153ab887c55..9d996dfa359ebcee50c706cae20d94c78308104f 100644 (file)
@@ -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));
index 4269fb7805ef7a8caba4e2ceb0bf64b5ce16d0d4..ceb78d478ba9fef2c9ef1327e5c9b9b24b0e9f43 100644 (file)
@@ -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>
\ No newline at end of file
index b975c1836569f0ef7c1a5353c8a9a15435bb5ef9..86ff2ed0e3b86f8bb4e7d60c496e340111a36753 100644 (file)
@@ -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;
 }
 
index e7768349e659d139298e54af65586a6b0e7e3f97..af9acbf689c917f4549667025275adbcc0846667 100644 (file)
@@ -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;
index c8611cf64dacb765441f330b576e6ca3af1a5ba1..653e63b24616e06e7394e3eafe3b53f950430757 100644 (file)
@@ -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 {
     }
 
 }
-?>
index 99536593e2478d8c8c3de291c3e248542a082aaa..513974a444190850924bc858015c04f111d367fc 100644 (file)
@@ -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
             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')) {
index b25e9847c8d30c8e6c17e13f6e84204d071cc7ad..cb56f2d38eb48f87baf6998f4368a8bdcbb34e3f 100644 (file)
@@ -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)
 
 ?>
index 727ec6403553777cf8afe3136ca4fa51df499aa5..b4b660f0b83d8bbe0148a982da9a0bf5eb7172bc 100644 (file)
@@ -30,7 +30,7 @@
         }
     }
 
-    require_login($course->id);
+    require_login($course, true, $cm);
 
     redirect("$CFG->wwwroot/course/view.php?id=$course->id");