From: skodak Date: Thu, 16 Apr 2009 06:36:11 +0000 (+0000) Subject: MDL-16075 adding support for embedded Glossary images X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=ccde17c3eb5a931b4e57d34ebcfd9eadcd631f0f;p=moodle.git MDL-16075 adding support for embedded Glossary images --- diff --git a/lang/en_utf8/glossary.php b/lang/en_utf8/glossary.php index 54dea3622c..d3c9da79d6 100644 --- a/lang/en_utf8/glossary.php +++ b/lang/en_utf8/glossary.php @@ -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'; diff --git a/mod/glossary/approve.php b/mod/glossary/approve.php index cb3892552b..6fbf476b96 100644 --- a/mod/glossary/approve.php +++ b/mod/glossary/approve.php @@ -31,11 +31,8 @@ $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&eid=$eid", "$eid",$cm->id); - } + $DB->update_record("glossary_entries", $newentry); + add_to_log($course->id, "glossary", "approve entry", "showentry.php?id=$cm->id&eid=$eid", "$eid",$cm->id); redirect("view.php?id=$cm->id&mode=$mode&hook=$hook",get_string("entryapproved","glossary"),1); die; ?> diff --git a/mod/glossary/deleteentry.php b/mod/glossary/deleteentry.php index 0ed6e15d46..4996d561e3 100644 --- a/mod/glossary/deleteentry.php +++ b/mod/glossary/deleteentry.php @@ -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(); diff --git a/mod/glossary/edit.php b/mod/glossary/edit.php index 7450360b3c..ae3b554d79 100644 --- a/mod/glossary/edit.php +++ b/mod/glossary/edit.php @@ -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&mode=entry&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&mode=entry&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&mode=entry&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&mode=entry&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)); diff --git a/mod/glossary/edit_form.php b/mod/glossary/edit_form.php index cc9e00dc37..28f4237827 100644 --- a/mod/glossary/edit_form.php +++ b/mod/glossary/edit_form.php @@ -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); diff --git a/mod/glossary/formats/TEMPLATE/TEMPLATE_format.php b/mod/glossary/formats/TEMPLATE/TEMPLATE_format.php index 5581e7d6b9..4ffa8d1020 100755 --- a/mod/glossary/formats/TEMPLATE/TEMPLATE_format.php +++ b/mod/glossary/formats/TEMPLATE/TEMPLATE_format.php @@ -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 "
\n"; diff --git a/mod/glossary/formats/continuous/continuous_format.php b/mod/glossary/formats/continuous/continuous_format.php index 1184cefdbc..c2f13dc2ba 100644 --- a/mod/glossary/formats/continuous/continuous_format.php +++ b/mod/glossary/formats/continuous/continuous_format.php @@ -12,7 +12,7 @@ function glossary_show_entry_continuous($course, $cm, $glossary, $entry, $mode=' echo '
'; glossary_print_entry_concept($entry); echo ':
'; - glossary_print_entry_definition($entry); + glossary_print_entry_definition($entry, $glossary, $cm); $entry->alias = ''; echo ''; diff --git a/mod/glossary/formats/dictionary/dictionary_format.php b/mod/glossary/formats/dictionary/dictionary_format.php index d671555dde..2454ed5dcc 100644 --- a/mod/glossary/formats/dictionary/dictionary_format.php +++ b/mod/glossary/formats/dictionary/dictionary_format.php @@ -12,7 +12,7 @@ function glossary_show_entry_dictionary($course, $cm, $glossary, $entry, $mode=' echo '
'; glossary_print_entry_concept($entry); echo ':
'; - glossary_print_entry_definition($entry); + glossary_print_entry_definition($entry, $glossary, $cm); echo ''; echo ''; $return = glossary_print_entry_lower_section($course, $cm, $glossary, $entry, $mode, $hook, $printicons, $ratings, $aliases); diff --git a/mod/glossary/formats/encyclopedia/encyclopedia_format.php b/mod/glossary/formats/encyclopedia/encyclopedia_format.php index 831643c2ab..f96e4e9171 100644 --- a/mod/glossary/formats/encyclopedia/encyclopedia_format.php +++ b/mod/glossary/formats/encyclopedia/encyclopedia_format.php @@ -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 ''; diff --git a/mod/glossary/formats/entrylist/entrylist_format.php b/mod/glossary/formats/entrylist/entrylist_format.php index 47b2e5438d..66e285a169 100644 --- a/mod/glossary/formats/entrylist/entrylist_format.php +++ b/mod/glossary/formats/entrylist/entrylist_format.php @@ -51,7 +51,7 @@ function glossary_print_entry_entrylist($course, $cm, $glossary, $entry, $mode=' echo ''; glossary_print_entry_concept($entry); echo ': '; - 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 ''; echo ''; diff --git a/mod/glossary/formats/faq/faq_format.php b/mod/glossary/formats/faq/faq_format.php index ee6b7b481e..03fc0001aa 100644 --- a/mod/glossary/formats/faq/faq_format.php +++ b/mod/glossary/formats/faq/faq_format.php @@ -30,7 +30,7 @@ function glossary_show_entry_faq($course, $cm, $glossary, $entry, $mode="", $hoo echo ''; echo ''.get_string('answer','glossary').': '; - glossary_print_entry_definition($entry); + glossary_print_entry_definition($entry, $glossary, $cm); echo ''; echo ''; diff --git a/mod/glossary/formats/fullwithauthor/fullwithauthor_format.php b/mod/glossary/formats/fullwithauthor/fullwithauthor_format.php index 67af5078ce..fff7d40b06 100644 --- a/mod/glossary/formats/fullwithauthor/fullwithauthor_format.php +++ b/mod/glossary/formats/fullwithauthor/fullwithauthor_format.php @@ -41,7 +41,7 @@ function glossary_show_entry_fullwithauthor($course, $cm, $glossary, $entry, $mo echo ' '; echo ''; - glossary_print_entry_definition($entry); + glossary_print_entry_definition($entry, $glossary, $cm); echo ''; echo ''; diff --git a/mod/glossary/formats/fullwithoutauthor/fullwithoutauthor_format.php b/mod/glossary/formats/fullwithoutauthor/fullwithoutauthor_format.php index 5f29a2d0b0..258d4e5935 100644 --- a/mod/glossary/formats/fullwithoutauthor/fullwithoutauthor_format.php +++ b/mod/glossary/formats/fullwithoutauthor/fullwithoutauthor_format.php @@ -29,7 +29,7 @@ function glossary_show_entry_fullwithoutauthor($course, $cm, $glossary, $entry, echo ''; echo ''; - glossary_print_entry_definition($entry); + glossary_print_entry_definition($entry, $glossary, $cm); echo ''; echo ''; diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index 72bf310fb8..c2242ca81a 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -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 '

'. strip_tags($entry->concept) . ':

'; $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)); } } - -?>