MDL-16075 adding support for embedded Glossary images
This commit is contained in:
@@ -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';
|
||||
|
||||
@@ -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;
|
||||
?>
|
||||
|
||||
@@ -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();
|
||||
|
||||
+38
-40
@@ -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,43 +109,34 @@ 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');
|
||||
}
|
||||
}
|
||||
|
||||
// save attachment
|
||||
$filename = $mform->get_new_filename('attachment');
|
||||
|
||||
if ($filename !== false) {
|
||||
$filearea = 'glossary_attachment';
|
||||
$fs = get_file_storage();
|
||||
|
||||
$fs->delete_area_files($context->id, $filearea, $entry->id);
|
||||
|
||||
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);
|
||||
add_to_log($course->id, "glossary", "update entry",
|
||||
"view.php?id=$cm->id&mode=entry&hook=$entry->id",
|
||||
$entry->id, $cm->id);
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
// 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);
|
||||
|
||||
// store the final values
|
||||
$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));
|
||||
// TODO: this deletes cats from both both main and secondary glossary :-(
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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>';
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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>';
|
||||
|
||||
@@ -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>';
|
||||
|
||||
@@ -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">';
|
||||
|
||||
@@ -41,7 +41,7 @@ function glossary_show_entry_fullwithauthor($course, $cm, $glossary, $entry, $mo
|
||||
echo '<td class="left"> </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">';
|
||||
|
||||
@@ -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">';
|
||||
|
||||
+10
-6
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user