]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-16075 adding support for embedded Glossary images
authorskodak <skodak>
Thu, 16 Apr 2009 06:36:11 +0000 (06:36 +0000)
committerskodak <skodak>
Thu, 16 Apr 2009 06:36:11 +0000 (06:36 +0000)
14 files changed:
lang/en_utf8/glossary.php
mod/glossary/approve.php
mod/glossary/deleteentry.php
mod/glossary/edit.php
mod/glossary/edit_form.php
mod/glossary/formats/TEMPLATE/TEMPLATE_format.php
mod/glossary/formats/continuous/continuous_format.php
mod/glossary/formats/dictionary/dictionary_format.php
mod/glossary/formats/encyclopedia/encyclopedia_format.php
mod/glossary/formats/entrylist/entrylist_format.php
mod/glossary/formats/faq/faq_format.php
mod/glossary/formats/fullwithauthor/fullwithauthor_format.php
mod/glossary/formats/fullwithoutauthor/fullwithoutauthor_format.php
mod/glossary/lib.php

index 54dea3622c8006f9e1a879531e6f771a7af9029d..d3c9da79d60fb49bd10cd00ee6656e0011af3abd 100644 (file)
@@ -27,9 +27,7 @@ $string['back'] = 'Back';
 $string['cantexportentry'] = 'Could not export the entry to the main glossary';
 $string['cantinsertcat'] = 'Can\'t insert category';
 $string['cantinsertrec'] = 'Can\'t insert record';
-$string['cantinsertent'] = 'Could not insert this new entry';
 $string['cantinsertrel'] = 'Can\'t insert relation category-entry';
-$string['cantupdateglossary'] = 'Could not update your glossary';
 $string['casesensitive'] = 'This entry is case sensitive';
 $string['cat'] = 'cat';
 $string['categories'] = 'Categories';
index cb3892552b9418f077c0b7ce115639aae32f2f96..6fbf476b965cb78e5a045024f51d10f70f172987 100644 (file)
     $newentry->approved     = 1;
     $newentry->timemodified = time(); // wee need this date here to speed up recent activity, TODO: use timestamp in approved field instead in 2.0
 
-    if (! $DB->update_record("glossary_entries", $newentry)) {
-        print_error('cantupdateglossary', 'glossary');
-    } else {
-        add_to_log($course->id, "glossary", "approve entry", "showentry.php?id=$cm->id&amp;eid=$eid", "$eid",$cm->id);
-    }
+    $DB->update_record("glossary_entries", $newentry);
+    add_to_log($course->id, "glossary", "approve entry", "showentry.php?id=$cm->id&amp;eid=$eid", "$eid",$cm->id);
     redirect("view.php?id=$cm->id&amp;mode=$mode&amp;hook=$hook",get_string("entryapproved","glossary"),1);
     die;
 ?>
index 0ed6e15d466c243846732857ef6353a880930925..4996d561e34e80bbe28efbfa8d6c482b02ca650a 100644 (file)
@@ -61,9 +61,7 @@
 
             $entry->glossaryid       = $entry->sourceglossaryid;
             $entry->sourceglossaryid = 0;
-            if (!$DB->update_record('glossary_entries', $entry)) {
-                print_error('cantupdateglossary', 'glossary');
-            }
+            $DB->update_record('glossary_entries', $entry);
 
             // move attachments too
             $fs = get_file_storage();
index 7450360b3cbab06cb163c67e42244c34c74ab9bf..ae3b554d7907325ee6450b57a3ab49ac922f7831 100644 (file)
@@ -4,8 +4,6 @@ require_once('../../config.php');
 require_once('lib.php');
 require_once('edit_form.php');
 
-global $CFG, $USER;
-
 $cmid = required_param('cmid', PARAM_INT);            // Course Module ID
 $id   = optional_param('id', 0, PARAM_INT);           // EntryID
 
@@ -17,7 +15,7 @@ if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
     print_error('coursemisconf');
 }
 
-require_login($course->id, false, $cm);
+require_login($course, false, $cm);
 
 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
 
@@ -54,14 +52,25 @@ if ($id) { // if entry is specified
         // TODO: this fetches cats from both main and secondary glossary :-(
         $entry->categories = array_values($categoriesarr);
     }
-    $entry->cmid = $cm->id;
 
 } else { // new entry
     require_capability('mod/glossary:write', $context);
     $entry = new object();
-    $entry->cmid = $cm->id;
+    $entry->id         = null;
+    $entry->definition = '';
+    $entry->format     = FORMAT_HTML; // TODO: better default value
 }
 
+$entry->cmid = $cm->id;
+
+$draftid_editor = file_get_submitted_draft_itemid('entry');
+$currenttext = file_prepare_draft_area($draftid_editor, $context->id, 'glossary_entry', $entry->id, true, $entry->definition);
+$entry->entry = array('text'=>$currenttext, 'format'=>$entry->format, 'itemid'=>$draftid_editor);
+
+$draftitemid = file_get_submitted_draft_itemid('attachments');
+file_prepare_draft_area($draftitemid, $context->id, 'glossary_attachment', $entry->id , false);
+$entry->attachements = $draftitemid;
+
 // set form initial data
 $mform->set_data($entry);
 
@@ -74,8 +83,6 @@ if ($mform->is_cancelled()){
     }
 
 } else if ($data = $mform->get_data()) {
-    trusttext_after_edit($data->definition, $context);
-
     $timenow = time();
 
     if (empty($entry->id)) {
@@ -88,8 +95,8 @@ if ($mform->is_cancelled()){
     }
 
     $entry->concept       = trim($data->concept);
-    $entry->definition    = $data->definition;
-    $entry->format        = $data->format;
+    $entry->definition    = '';          // updated later
+    $entry->format        = FORMAT_HTML; // updated later
     $entry->timemodified  = $timenow;
     $entry->approved      = 0;
     $entry->usedynalink   = isset($data->usedynalink) ?   $data->usedynalink : 0;
@@ -102,42 +109,33 @@ if ($mform->is_cancelled()){
 
     if (empty($entry->id)) {
         //new entry
-        if ($entry->id = $DB->insert_record('glossary_entries', $entry)) {
-            add_to_log($course->id, "glossary", "add entry",
-                       "view.php?id=$cm->id&amp;mode=entry&amp;hook=$enty->id", $entry->id, $cm->id);
-        } else {
-            print_error('cantinsertent', 'glossary');
-        }
-        //refetch complete entry
-        $entry = $DB->get_record('glossary_entries', array('id'=>$entry->id));
+        $entry->id = $DB->insert_record('glossary_entries', $entry);
+        add_to_log($course->id, "glossary", "add entry",
+                   "view.php?id=$cm->id&amp;mode=entry&amp;hook=$enty->id", $entry->id, $cm->id);
 
     } else {
         //existing entry
-        if ($DB->update_record('glossary_entries', $entry)) {
-            add_to_log($course->id, "glossary", "update entry",
-                       "view.php?id=$cm->id&amp;mode=entry&amp;hook=$entry->id",
-                       $entry->id, $cm->id);
-        } else {
-            print_error('cantupdateglossary', 'glossary');
-        }
+        $DB->update_record('glossary_entries', $entry);
+        add_to_log($course->id, "glossary", "update entry",
+                   "view.php?id=$cm->id&amp;mode=entry&amp;hook=$entry->id",
+                   $entry->id, $cm->id);
     }
 
-    // save attachment
-    $filename = $mform->get_new_filename('attachment');
+    // save and relink embedded images
+    $entry->format     = $data->entry['format'];
+    $entry->definition = file_save_draft_area_files($draftid_editor, $context->id, 'glossary_entry', $entry->id, true, $data->entry['text']);
+    trusttext_after_edit($entry->definition, $context);
 
-    if ($filename !== false) {
-        $filearea = 'glossary_attachment';
-        $fs = get_file_storage();
+    // save attachments
+    $info = file_get_draft_area_info($draftitemid);
+    $entry->attachment = ($info['filecount']>0) ? '1' : '';
+    file_save_draft_area_files($draftitemid, $context->id, 'glossary_attachment', $entry->id, false);
 
-        $fs->delete_area_files($context->id, $filearea, $entry->id);
+    // store the final values
+    $DB->update_record('glossary_entries', $entry);
 
-        if ($mform->save_stored_file('attachment', $context->id, $filearea, $entry->id, '/', $filename, true, $USER->id)) {
-            $entry->attachment = '1';
-        } else {
-            $entry->attachment = '';
-        }
-        $DB->update_record('glossary_entries', $entry);
-    }
+    //refetch complete entry
+    $entry = $DB->get_record('glossary_entries', array('id'=>$entry->id));
 
     // update entry categories
     $DB->delete_records('glossary_entries_categories', array('entryid'=>$entry->id));
index cc9e00dc374cc2ae03202fe2f18c0a5aa833ff24..28f4237827a89ebca91eb62899ceb0ba1c3e9ba1 100644 (file)
@@ -17,12 +17,11 @@ class mod_glossary_entry_form extends moodleform {
         $mform->setType('concept', PARAM_TEXT);
         $mform->addRule('concept', null, 'required', null, 'client');
 
-        $mform->addElement('htmleditor', 'definition', get_string('definition', 'glossary'), array('rows'=>20));
-        $mform->setType('definition', PARAM_RAW);
-        $mform->addRule('definition', null, 'required', null, 'client');
-        $mform->setHelpButton('definition', array('writing', 'richtext2'), false, 'editorhelpbutton');
-
-        $mform->addElement('format');
+        $mform->addElement('editor', 'entry', get_string('definition', 'glossary'),
+                           array('maxfiles' => EDITOR_UNLIMITED_FILES, 'filearea' => 'glossary_entry'));
+        $mform->setType('entry', PARAM_RAW);
+        $mform->addRule('entry', get_string('required'), 'required', null, 'client');
+        $mform->setHelpButton('entry', array('reading', 'writing', 'questions', 'richtext2'), false, 'editorhelpbutton');
 
         if ($categories = $DB->get_records_menu('glossary_categories', array('glossaryid'=>$glossary->id), 'name ASC', 'id, name')){
             $categories = array(0 => get_string('notcategorised', 'glossary')) + $categories;
@@ -35,8 +34,14 @@ class mod_glossary_entry_form extends moodleform {
         $mform->setType('aliases', PARAM_TEXT);
         $mform->setHelpButton('aliases', array('aliases2', strip_tags(get_string('aliases', 'glossary')), 'glossary'));
 
-        $mform->addElement('file', 'attachment', get_string('attachment', 'forum'));
-        $mform->setHelpButton('attachment', array('attachment', get_string('attachment', 'glossary'), 'glossary'));
+        $mform->addElement('filemanager', 'attachments', get_string('attachment', 'glossary'),
+            array('subdirs'=>0,
+//                  'maxbytes'=>$glossary->maxbytes,
+//                  'maxfiles'=>-1,
+                  'filetypes'=>'*',
+                  'returnvalue'=>'ref_id'
+            ));
+        $mform->setHelpButton('attachments', array('attachment2', get_string('attachment', 'glossary'), 'glossary'));
 
         if (!$glossary->usedynalink) {
             $mform->addElement('hidden', 'usedynalink',   $CFG->glossary_linkentries);
index 5581e7d6b9b720f66e4ce3d9b5ff617847ff9fc5..4ffa8d102080bff6570f983e5d96221513c66db3 100755 (executable)
@@ -76,7 +76,7 @@ function glossary_show_entry_TEMPLATE($course, $cm, $glossary, $entry, $mode='',
 
         //Use this function to show the definition 
         //Comments: Configuration not supported
-        glossary_print_entry_definition($entry);
+        glossary_print_entry_definition($entry, $glossary, $cm);
 
         //Line separator to show this template fine. :-)
         echo "<br />\n";
index 1184cefdbcf2f0112452db88749397bbd0ebcd0d..c2f13dc2ba4fffdb265219fc5b299d40b245875a 100644 (file)
@@ -12,7 +12,7 @@ function glossary_show_entry_continuous($course, $cm, $glossary, $entry, $mode='
     echo '<div class="concept">';
     glossary_print_entry_concept($entry);
     echo ':</div> ';
-    glossary_print_entry_definition($entry);
+    glossary_print_entry_definition($entry, $glossary, $cm);
     $entry->alias = '';
     echo '</td></tr>';
    
index d671555ddef9989e351c993dec24aad237eb5168..2454ed5dcc0ad3143bb1704ed9fcecbf81253264 100644 (file)
@@ -12,7 +12,7 @@ function glossary_show_entry_dictionary($course, $cm, $glossary, $entry, $mode='
     echo '<div class="concept">';
     glossary_print_entry_concept($entry);
     echo ':</div> ';
-    glossary_print_entry_definition($entry);
+    glossary_print_entry_definition($entry, $glossary, $cm);
     echo '</td></tr>';
     echo '<tr valign="top"><td class="entrylowersection">';
     $return = glossary_print_entry_lower_section($course, $cm, $glossary, $entry, $mode, $hook, $printicons, $ratings, $aliases);
index 831643c2aba5b0052db02dd701a68982e88a0b16..f96e4e9171edf2552e1c2c5498318d83e10c8371 100644 (file)
@@ -48,7 +48,7 @@ function glossary_show_entry_encyclopedia($course, $cm, $glossary, $entry, $mode
             }
             glossary_print_entry_attachment($entry, $cm, null,$align,false);
         }
-        glossary_print_entry_definition($entry);
+        glossary_print_entry_definition($entry, $glossary, $cm);
 
         if ($printicons or $ratings or $aliases) {
             echo '</td></tr>';
index 47b2e5438de604eedb19b086b1b2c74719deee94..66e285a16981f05a369c605405edd4293a8a32b1 100644 (file)
@@ -51,7 +51,7 @@ function glossary_print_entry_entrylist($course, $cm, $glossary, $entry, $mode='
     echo '<b>';
     glossary_print_entry_concept($entry);
     echo ':</b> ';
-    glossary_print_entry_definition($entry);
+    glossary_print_entry_definition($entry, $glossary, $cm);
     $return = glossary_print_entry_lower_section($course, $cm, $glossary, $entry, $mode, $hook, false, false, false);
     echo '</td>';
     echo '</tr>';
index ee6b7b481e2b95e61b1bb5c7393f94ba8238a2b3..03fc0001aadf44dfeb198819450fe284e360cde0 100644 (file)
@@ -30,7 +30,7 @@ function glossary_show_entry_faq($course, $cm, $glossary, $entry, $mode="", $hoo
         echo '<td colspan="2" class="entry">';
         echo '<b>'.get_string('answer','glossary').':</b> ';
 
-        glossary_print_entry_definition($entry);
+        glossary_print_entry_definition($entry, $glossary, $cm);
 
         echo '</td></tr>';
         echo '<tr valign="top"><td colspan="3" class="entrylowersection">';
index 67af5078ce2d0cbd05ee2f32a5361b1b6a99433d..fff7d40b06349633e4d22504f52bc5594db98ec0 100644 (file)
@@ -41,7 +41,7 @@ function glossary_show_entry_fullwithauthor($course, $cm, $glossary, $entry, $mo
         echo '<td class="left">&nbsp;</td>';
         echo '<td colspan="2" class="entry">';
 
-        glossary_print_entry_definition($entry);
+        glossary_print_entry_definition($entry, $glossary, $cm);
 
         echo '</td></tr>';
         echo '<tr valign="top">';
index 5f29a2d0b0808550b08104fd083ab19b9b73c3b0..258d4e59355a3cafb16d080dabd769590dcf4e5d 100644 (file)
@@ -29,7 +29,7 @@ function glossary_show_entry_fullwithoutauthor($course, $cm, $glossary, $entry,
         echo '<tr valign="top">';
         echo '<td width="100%" colspan="2" class="entry">';
 
-        glossary_print_entry_definition($entry);
+        glossary_print_entry_definition($entry, $glossary, $cm);
 
         echo '</td></tr>';
         echo '<tr valign="top"><td colspan="2" class="entrylowersection">';
index 72bf310fb88db28cd760388b01351f72c29c38a4..c2242ca81a207bccfb4eb5bcab7676ab499806fd 100644 (file)
@@ -628,7 +628,7 @@ function glossary_print_entry($course, $cm, $glossary, $entry, $mode='',$hook=''
                 $return = $functionname($course, $cm, $glossary, $entry,$mode,$hook,$printicons,$ratings);
             } else if ($printview) {
                 //If the glossary_print_entry_XXXX function doesn't exist, print default (old) print format
-                $return = glossary_print_entry_default($entry);
+                $return = glossary_print_entry_default($entry, $glossary, $cm);
             }
         }
     }
@@ -636,7 +636,7 @@ function glossary_print_entry($course, $cm, $glossary, $entry, $mode='',$hook=''
 }
 
  //Default (old) print format used if custom function doesn't exist in format
-function glossary_print_entry_default ($entry) {
+function glossary_print_entry_default ($entry, $glossary, $cm) {
     echo '<h3>'. strip_tags($entry->concept) . ': </h3>';
 
     $definition = $entry->definition;
@@ -658,6 +658,9 @@ function glossary_print_entry_default ($entry) {
         $definition = trusttext_strip($definition); //make 100% sure TRUSTTEXT marker was not created
     }
 
+    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+    $definition = file_rewrite_pluginfile_urls($definition, 'pluginfile.php', $context->id, 'glossary_entry', $entry->id);
+    
     $options = new object();
     $options->para = false;
     $options->trusttext = true;
@@ -679,7 +682,7 @@ function  glossary_print_entry_concept($entry) {
     echo $text;
 }
 
-function glossary_print_entry_definition($entry) {
+function glossary_print_entry_definition($entry, $glossary, $cm) {
     global $DB;
 
     $definition = $entry->definition;
@@ -715,6 +718,9 @@ function glossary_print_entry_definition($entry) {
         $definition = trusttext_strip($definition); //make 100% sure TRUSTTEXT marker was not created
     }
 
+    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+    $definition = file_rewrite_pluginfile_urls($definition, 'pluginfile.php', $context->id, 'glossary_entry', $entry->id);
+    
     $text = format_text($definition, $entry->format, $options);
     
     // Stop excluding concepts from autolinking
@@ -1123,7 +1129,7 @@ function glossary_pluginfile($course, $cminfo, $context, $filearea, $args) {
         // finally send the file
         send_stored_file($file, $lifetime, 0);
 
-    } else if ($filearea === 'glossary_attachment') {
+    } else if ($filearea === 'glossary_attachment' or $filearea === 'glossary_entry') {
         $entryid = (int)array_shift($args);
 
         if (!$entry = $DB->get_record('glossary_entries', array('id'=>$entryid))) {
@@ -2434,5 +2440,3 @@ class glossary_entry_portfolio_caller extends portfolio_module_caller_base {
         return sha1(serialize($this->entry));
     }
 }
-
-?>