Commit 36bc9f7d authored by Mike Kelly's avatar Mike Kelly Committed by Aaron Wells

Implement TinyMCE imagebrowser plugin

This is a TinyMCE plugin which allows for browsing and embedding of
Mahara-hosted images as well as the embedding of external web-hosted
images. This makes adding inline images to WYSIWYG text boxes more
user-friendly.

Viewing permissions for these embedded files is set by adding references
to them to a new database table, artefact_file_embedded, then checking
for the existence of the references in the table when serving the files
via artefact/file/download.php. For content blocks in views, such as
text and textboxes, any embedded images are saved as view artefacts, and
viewing permission is granted for those files accordingly via previously
existing checks in artefact/file/download.php.

This patch is designed to allow image embedding in all WYSIWYG text
boxes throughout Mahara, hence the table structure, with resourcetype
and resourceid providing the context for checking the validity of the
image file to be served.

Change-Id: Idcc5ab3495eed44eea6ced171d670ba4c73884f6
Signed-off-by: 's avatarMike Kelly <m.f.kelly@arts.ac.uk>
parent 5fdc45dd
......@@ -45,6 +45,7 @@ $smarty->display('artefact:blog:index.tpl');
function delete_blog_submit(Pieform $form, $values) {
global $SESSION;
require_once('embeddedimage.php');
$blog = new ArtefactTypeBlog($values['delete']);
$blog->check_permission();
if ($blog->get('locked')) {
......@@ -52,6 +53,7 @@ function delete_blog_submit(Pieform $form, $values) {
}
else {
$blog->delete();
EmbeddedImage::delete_embedded_images('blog', $blog->get('id'));
$SESSION->add_ok_msg(get_string('blogdeleted', 'artefact.blog'));
}
redirect('/artefact/blog/index.php');
......
......@@ -327,6 +327,8 @@ class ArtefactTypeBlog extends ArtefactType {
* @param array
*/
public static function new_blog(User $user, array $values) {
require_once('embeddedimage.php');
db_begin();
$artefact = new ArtefactTypeBlog();
$artefact->set('title', $values['title']);
$artefact->set('description', $values['description']);
......@@ -338,6 +340,10 @@ class ArtefactTypeBlog extends ArtefactType {
$artefact->set('licensorurl', $values['licensorurl']);
}
$artefact->commit();
$blogid = $artefact->get('id');
$newdescription = EmbeddedImage::prepare_embedded_images($artefact->get('description'), 'blog', $blogid);
$artefact->set('description', $newdescription);
db_commit();
}
/**
......@@ -347,6 +353,7 @@ class ArtefactTypeBlog extends ArtefactType {
* @param array
*/
public static function edit_blog(User $user, array $values) {
require_once('embeddedimage.php');
if (empty($values['id']) || !is_numeric($values['id'])) {
return;
}
......@@ -357,7 +364,8 @@ class ArtefactTypeBlog extends ArtefactType {
}
$artefact->set('title', $values['title']);
$artefact->set('description', $values['description']);
$newdescription = EmbeddedImage::prepare_embedded_images($values['description'], 'blog', $values['id']);
$artefact->set('description', $newdescription);
$artefact->set('tags', $values['tags']);
if (get_config('licensemetadata')) {
$artefact->set('license', $values['license']);
......@@ -579,10 +587,11 @@ class ArtefactTypeBlogPost extends ArtefactType {
return;
}
require_once('embeddedimage.php');
db_begin();
$this->detach(); // Detach all file attachments
delete_records('artefact_blog_blogpost', 'blogpost', $this->id);
EmbeddedImage::delete_embedded_images('blogpost', $this->id);
parent::delete();
db_commit();
}
......
......@@ -183,7 +183,7 @@ EOF;
$smarty = smarty(array(), array(), array(), array(
'tinymceconfig' => '
plugins: "tooltoggle,textcolor,link,maharaimage,table,emoticons,spellchecker,paste,code,fullscreen,directionality,searchreplace,nonbreaking,charmap",
plugins: "tooltoggle,textcolor,link,imagebrowser,table,emoticons,spellchecker,paste,code,fullscreen,directionality,searchreplace,nonbreaking,charmap",
image_filebrowser: "editpost_filebrowser",
',
'sideblocks' => array(
......
......@@ -103,15 +103,16 @@ function edit_comment_validate(Pieform $form, $values) {
function edit_comment_submit(Pieform $form, $values) {
global $viewid, $comment, $SESSION, $goto, $USER;
require_once('embeddedimage.php');
db_begin();
$comment->set('description', $values['message']);
$comment->set('rating', valid_rating($values['rating']));
require_once(get_config('libroot') . 'view.php');
$view = new View($viewid);
$owner = $view->get('owner');
$group = $comment->get('group');
$newdescription = EmbeddedImage::prepare_embedded_images($values['message'], 'comment', $comment->get('id'), $group);
$comment->set('description', $newdescription);
$approvecomments = $view->get('approvecomments');
if (!empty($group) && ($approvecomments || (!$approvecomments && $view->user_comments_allowed($USER) == 'private')) && $values['ispublic'] && !$USER->can_edit_view($view)) {
$comment->set('requestpublic', 'author');
......
......@@ -1017,6 +1017,7 @@ function make_public_submit(Pieform $form, $values) {
function delete_comment_submit(Pieform $form, $values) {
global $SESSION, $USER, $view;
require_once('embeddedimage.php');
$comment = new ArtefactTypeComment((int) $values['comment']);
......@@ -1084,6 +1085,7 @@ function delete_comment_submit(Pieform $form, $values) {
activity_occurred('feedback', $data, 'artefact', 'comment');
}
EmbeddedImage::delete_embedded_images('comment', $comment->get('id'));
db_commit();
$SESSION->add_ok_msg(get_string('commentremoved', 'artefact.comment'));
......@@ -1091,8 +1093,8 @@ function delete_comment_submit(Pieform $form, $values) {
}
function add_feedback_form_validate(Pieform $form, $values) {
require_once(get_config('libroot') . 'antispam.php');
if ($form->get_property('spam')) {
require_once(get_config('libroot') . 'antispam.php');
$spamtrap = new_spam_trap(array(
array(
'type' => 'body',
......@@ -1120,6 +1122,7 @@ function add_feedback_form_validate(Pieform $form, $values) {
function add_feedback_form_submit(Pieform $form, $values) {
global $view, $artefact, $USER;
require_once('embeddedimage.php');
$data = (object) array(
'title' => get_string('Comment', 'artefact.comment'),
'description' => $values['message'],
......@@ -1174,6 +1177,15 @@ function add_feedback_form_submit(Pieform $form, $values) {
$comment->commit();
$newdescription = EmbeddedImage::prepare_embedded_images($values['message'], 'comment', $comment->get('id'), $data->group);
if ($newdescription !== $values['message']) {
$updatedcomment = new stdClass();
$updatedcomment->id = $comment->get('id');
$updatedcomment->description = $newdescription;
update_record('artefact', $updatedcomment, 'id');
}
$url = $comment->get_view_url($view->get('id'), true, false);
$goto = get_config('wwwroot') . $url;
......
......@@ -28,14 +28,26 @@
<KEY NAME="artefactfk" TYPE="foreign" FIELDS="artefact" REFTABLE="artefact" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="artefact_file_mime_types">
<FIELDS>
<FIELD NAME="mimetype" TYPE="char" LENGTH="128" NOTNULL="true"/>
<FIELD NAME="description" TYPE="char" LENGTH="32" NOTNULL="true"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="mimetype"/>
</KEYS>
</TABLE>
<TABLE NAME="artefact_file_mime_types">
<FIELDS>
<FIELD NAME="mimetype" TYPE="char" LENGTH="128" NOTNULL="true"/>
<FIELD NAME="description" TYPE="char" LENGTH="32" NOTNULL="true"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="mimetype"/>
</KEYS>
</TABLE>
<TABLE NAME="artefact_file_embedded">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
<FIELD NAME="fileid" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="resourcetype" TYPE="char" LENGTH="100" NOTNULL="true" />
<FIELD NAME="resourceid" TYPE="int" LENGTH="10" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
<KEY NAME="artefactfk" TYPE="foreign" FIELDS="fileid" REFTABLE="artefact" REFFIELDS="id" />
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
......@@ -400,5 +400,20 @@ function xmldb_artefact_file_upgrade($oldversion=0) {
execute_sql($sql);
}
if ($oldversion < 2014111200) {
// Create embedded images table
$table = new XMLDBTable('artefact_file_embedded');
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE);
$table->addFieldInfo('fileid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL);
$table->addFieldInfo('resourcetype', XMLDB_TYPE_CHAR, '100', XMLDB_UNSIGNED, XMLDB_NOTNULL);
$table->addFieldInfo('resourceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('artefactfk', XMLDB_KEY_FOREIGN, array('fileid'), 'artefact', array('id'));
$status = $status && create_table($table);
}
return $status;
}
......@@ -14,8 +14,10 @@ define('PUBLIC', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('artefact', 'file');
require_once('file.php');
require_once('embeddedimage.php');
$fileid = param_integer('file');
$groupid = param_integer('group', 0);
$viewid = param_integer('view', null);
$postid = param_integer('post', null);
$size = get_imagesize_parameters();
......@@ -99,7 +101,7 @@ else {
// If the file is in the logged in menu and the user is logged in then
// they can view it
$fileinloggedinmenu = $file->get('institution') == 'mahara';
// check if users are allowed to access files in subfolders
// check if users are allowed to access files in subfolders
if (!get_config('sitefilesaccess')) {
$fileinloggedinmenu = $fileinloggedinmenu && $file->get('parent') == null;
}
......@@ -110,15 +112,36 @@ else {
// Alternatively, if you own the file or you are an admin, it should always work
if (!$USER->can_view_artefact($file)) {
$imagevisible = false;
// Check for resume elements in pages
$resumelements = array('resumecoverletter','resumeinterest','personalgoal','academicgoal','careergoal','personalskill','academicskill','workskill','profileintrotext');
foreach ($resumelements as $element) {
$resourceid = param_integer($element, null);
if ($resourceid && $file instanceof ArtefactTypeImage) {
$imagevisible = EmbeddedImage::can_see_embedded_image($fileid, $element, $resourceid);
}
if ($imagevisible) {
break;
}
}
// Check for images sitting in visible forum posts
$visibleinpost = false;
if ($postid && $file instanceof ArtefactTypeImage) {
if (!$imagevisible && $postid && $file instanceof ArtefactTypeImage) {
safe_require('interaction', 'forum');
$visibleinpost = PluginInteractionForum::can_see_attached_file($file, $postid);
$imagevisible = PluginInteractionForum::can_see_attached_file($file, $postid);
}
if (!$imagevisible && $groupid) {
// check for public embedded image
if (!group_user_access($groupid)){
throw new AccessDeniedException(get_string('accessdenied', 'error'));
}
$imagevisible = EmbeddedImage::can_see_embedded_image($fileid, 'group', $groupid);
}
if (!$visibleinpost) {
if (!$imagevisible) {
throw new AccessDeniedException(get_string('accessdenied', 'error'));
}
}
......
......@@ -779,6 +779,11 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
addElementClass(self.id + '_empty_selectlist', 'hidden');
}
this.update_metadata_to_selected_list();
// are we running inside tinymce imagebrowser plugin?
if (window.imgbrowserconf_artefactid) {
// propagate the click
jQuery('#filebrowserupdatetarget').click();
}
}
this.unselect = function (e) {
......
......@@ -12,6 +12,6 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2014061000;
$config->version = 2014111200;
$config->release = '1.2.4';
......@@ -412,8 +412,20 @@ EOF;
return $elements;
}
public static function delete_instance($instance) {
require_once('embeddedimage.php');
$configdata = $instance->get('configdata');
if (!empty($configdata)) {
$artefactid = $configdata['artefactid'];
if (!empty($artefactid)) {
EmbeddedImage::delete_embedded_images($instance->get('blocktype'), $artefactid);
}
}
}
public static function instance_config_save($values, $instance) {
global $USER;
require_once('embeddedimage.php');
$data = array();
$view = $instance->get_view();
foreach (array('owner', 'group', 'institution') as $f) {
......@@ -462,7 +474,8 @@ EOF;
&& $artefact->get('institution') === $data['institution']
&& !$artefact->get('locked')
&& $USER->can_edit_artefact($artefact)) {
$artefact->set('description', $values['text']);
$newdescription = EmbeddedImage::prepare_embedded_images($values['text'], 'textbox', (int)$values['artefactid'], $view->get('group'));
$artefact->set('description', $newdescription);
if (get_config('licensemetadata')) {
$artefact->set('license', $values['license']);
$artefact->set('licensor', $values['licensor']);
......@@ -475,6 +488,15 @@ EOF;
$artefact->commit();
$newdescription = EmbeddedImage::prepare_embedded_images($values['text'], 'textbox', $artefact->get('id'), $view->get('group'));
if ($newdescription !== $values['text']) {
$updatedartefact = new stdClass();
$updatedartefact->id = $artefact->get('id');
$updatedartefact->description = $newdescription;
update_record('artefact', $updatedartefact, 'id');
}
// Add attachments, if there are any...
$old = $artefact->attachment_id_list();
$new = is_array($values['artefactids']) ? $values['artefactids'] : array();
......
......@@ -164,10 +164,12 @@ $smarty->display('form.tpl');
function editnote_submit(Pieform $form, array $values) {
global $SESSION, $artefact, $goto;
require_once('embeddedimage.php');
db_begin();
$artefact->set('title', $values['title']);
$artefact->set('description', $values['description']);
$newdescription = EmbeddedImage::prepare_embedded_images($values['description'], 'editnote', $artefact->get('id'), $artefact->get('group'));
$artefact->set('description', $newdescription);
$artefact->set('tags', $values['tags']);
$artefact->set('allowcomments', (int) $values['allowcomments']);
if (isset($values['perms'])) {
......
......@@ -257,6 +257,7 @@ function profileform_submit(Pieform $form, $values) {
global $USER;
global $element_list;
global $profilefields;
require_once('embeddedimage.php');
db_begin();
......@@ -399,6 +400,11 @@ function profileform_submit(Pieform $form, $values) {
}
else {
if (!isset($profilefields[$element]) || $values[$element] != $profilefields[$element]) {
if ($element == 'introduction') {
$newintroduction = EmbeddedImage::prepare_embedded_images($values[$element], 'profileintrotext', $USER->get('id'));
$values[$element] = $newintroduction;
}
$classname = generate_artefact_class_name($element);
$profile = new $classname(0, array('owner' => $USER->get('id')));
$profile->set('title', $values[$element]);
......
......@@ -231,9 +231,11 @@ function deletenote_form($id, $notedata) {
function deletenote_submit(Pieform $form, array $values) {
global $SESSION, $data, $baseurl;
require_once('embeddedimage.php');
$id = $data[$values['delete']]->id;
$note = new ArtefactTypeHtml($id);
$note->delete();
EmbeddedImage::delete_embedded_images('editnote', $id);
$SESSION->add_ok_msg(get_string('notedeleted', 'artefact.internal'));
redirect($baseurl);
}
......@@ -149,10 +149,13 @@ $smarty->display('artefact:resume:editgoalsandskills.tpl');
function editgoalsandskills_submit(Pieform $form, array $values) {
global $SESSION, $artefact, $USER;
require_once('embeddedimage.php');
$newdescription = EmbeddedImage::prepare_embedded_images($values['description'], $values['artefacttype'], $USER->get('id'));
db_begin();
$artefact->set('title', get_string($values['artefacttype'], 'artefact.resume'));
$artefact->set('description', $values['description']);
$artefact->set('description', $newdescription);
$artefact->commit();
// Attachments
......
......@@ -2105,8 +2105,18 @@ function simple_resumefield_form($defaults, $goto, $options = array()) {
function simple_resumefield_submit(Pieform $form, $values) {
global $simple_resume_types, $simple_resume_artefacts, $USER;
require_once('embeddedimage.php');
$owner = $USER->get('id');
if (isset($values['coverletter'])) {
$newcoverletter = EmbeddedImage::prepare_embedded_images($values['coverletter'], 'resumecoverletter', $USER->get('id'));
$values['coverletter'] = $newcoverletter;
}
else if (isset($values['interest'])) {
$newinterest = EmbeddedImage::prepare_embedded_images($values['interest'], 'resumeinterest', $USER->get('id'));
$values['interest'] = $newinterest;
}
foreach ($simple_resume_types as $t) {
if (isset($values[$t . 'submit']) && isset($values[$t])) {
if (!isset($simple_resume_artefacts[$t])) {
......
......@@ -25,11 +25,22 @@ class PluginBlocktypeText extends SystemBlocktype {
return array('shortcut');
}
public static function get_artefacts(BlockInstance $instance) {
safe_require('artefact', 'file');
$configdata = $instance->get('configdata');
// Add all artefacts found in the text
$text = $configdata['text'];
$artefacts = array_unique(artefact_get_references_in_html($text));
return $artefacts;
}
public static function render_instance(BlockInstance $instance, $editing=false) {
safe_require('artefact', 'file');
$configdata = $instance->get('configdata');
$smarty = smarty_core();
if (array_key_exists('text', $configdata)) {
$smarty->assign('text', $configdata['text']);
$newtext = ArtefactTypeFolder::append_view_url($configdata['text'], $instance->get('view'));
$smarty->assign('text', $newtext);
}
else {
$smarty->assign('text', '');
......@@ -68,6 +79,13 @@ class PluginBlocktypeText extends SystemBlocktype {
return $elements;
}
public static function instance_config_save($values, $instance) {
require_once('embeddedimage.php');
$newtext = EmbeddedImage::prepare_embedded_images($values['text'], 'text', $instance->get('id'));
$values['text'] = $newtext;
return $values;
}
public static function default_copy_type() {
return 'full';
}
......
......@@ -50,8 +50,10 @@ $smarty->assign('form', $form);
$smarty->display('group/delete.tpl');
function deletegroup_submit(Pieform $form, $values) {
require_once('embeddedimage.php');
global $SESSION, $USER, $groupid;
group_delete($groupid);
EmbeddedImage::delete_embedded_images('group', $groupid);
$SESSION->add_ok_msg(get_string('deletegroup', 'group'));
redirect('/group/mygroups.php');
}
......@@ -15,6 +15,7 @@ require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php');
require_once('group.php');
require_once(get_config('libroot') . 'antispam.php');
require_once('embeddedimage.php');
if ($id = param_integer('id', null)) {
define('TITLE', get_string('editgroup', 'group'));
......@@ -516,6 +517,10 @@ function editgroup_submit(Pieform $form, $values) {
$USER->reset_grouproles();
}
$newvalues['description'] = EmbeddedImage::prepare_embedded_images($newvalues['description'], 'group', $group_data->id, $group_data->id);
$newvalues['id'] = $group_data->id;
group_update((object)$newvalues);
$SESSION->add_ok_msg(get_string('groupsaved', 'group'));
db_commit();
......
......@@ -20,6 +20,7 @@ safe_require('interaction' ,'forum');
require_once('group.php');
require_once('pieforms/pieform.php');
require_once(get_config('docroot') . 'interaction/lib.php');
require_once('embeddedimage.php');
$topicid = param_integer('id');
$returnto = param_alpha('returnto', 'topic');
......@@ -109,6 +110,7 @@ function deletetopic_submit(Pieform $form, $values) {
array('deleted' => 1),
array('id' => $topicid)
);
EmbeddedImage::delete_embedded_images('topic', $topicid);
// mark relevant posts as deleted
update_record(
'interaction_forum_post',
......
......@@ -182,15 +182,26 @@ function editpost_validate(Pieform $form, $values) {
}
}
function get_groupid_from_postid($postid) {
$groupid = get_field_sql("SELECT i.group FROM {interaction_instance} i
INNER JOIN {interaction_forum_topic} t ON i.id = t.forum
INNER JOIN {interaction_forum_post} p on p.topic = t.id
WHERE p.id =?", array($postid));
return $groupid;
}
function editpost_submit(Pieform $form, $values) {
global $USER, $SESSION;
require_once('embeddedimage.php');
$postid = param_integer('id');
$groupid = get_groupid_from_postid($postid);
$newbody = EmbeddedImage::prepare_embedded_images($values['body'], 'post', $postid, $groupid);
db_begin();
update_record(
'interaction_forum_post',
array(
'subject' => $values['subject'],
'body' => PluginInteractionForum::prepare_post_body($values['body'], $postid),
'body' => PluginInteractionForum::prepare_post_body($newbody, $postid),
),
array('id' => $postid)
);
......@@ -211,6 +222,7 @@ function editpost_submit(Pieform $form, $values) {
function addpost_submit(Pieform $form, $values) {
global $USER, $SESSION;
require_once('embeddedimage.php');
$parentid = param_integer('parent');
$post = (object)array(
'topic' => $values['topic'],
......@@ -234,7 +246,9 @@ function addpost_submit(Pieform $form, $values) {
update_record('interaction_forum_post', $postrec);
// Rewrite the post id into links in the body
$newbody = PluginInteractionForum::prepare_post_body($post->body, $postid);
$groupid = get_groupid_from_postid($postid);
$newbody = EmbeddedImage::prepare_embedded_images($post->body, 'post', $postid, $groupid);
$newbody = PluginInteractionForum::prepare_post_body($newbody, $postid);
if (!empty($newbody) && $newbody != $post->body) {
set_field('interaction_forum_post', 'body', $newbody, 'id', $postid);
}
......
......@@ -21,6 +21,7 @@ require_once('group.php');
require_once(get_config('docroot') . 'interaction/lib.php');
require_once('pieforms/pieform.php');
require_once('antispam.php');
require_once('embeddedimage.php');
$userid = $USER->get('id');
$topicid = param_integer('id', 0);
......@@ -194,6 +195,8 @@ function edittopic_validate(Pieform $form, $values) {
function addtopic_submit(Pieform $form, $values) {
global $USER, $SESSION;
$forumid = param_integer('forum');
$groupid = get_field('interaction_instance', 'group', 'id', $forumid);
db_begin();
$topicid = insert_record(
'interaction_forum_topic',
......@@ -214,7 +217,8 @@ function addtopic_submit(Pieform $form, $values) {
$postid = insert_record('interaction_forum_post', $post, 'id', true);
set_field('interaction_forum_post', 'path', sprintf('%010d', $postid), 'id', $postid);
// Rewrite the post id into links in the body
$newbody = PluginInteractionForum::prepare_post_body($post->body, $postid);
$newbody = EmbeddedImage::prepare_embedded_images($post->body, 'topic', $topicid, $groupid);
$newbody = PluginInteractionForum::prepare_post_body($newbody, $postid);
if (!empty($newbody) && $newbody != $post->body) {
set_field('interaction_forum_post', 'body', $newbody, 'id', $postid);
}
......@@ -244,16 +248,20 @@ function edittopic_submit(Pieform $form, $values) {
global $SESSION, $USER, $topic;
$topicid = param_integer('id');
$returnto = param_alpha('returnto', 'topic');
$groupid = get_field_sql("SELECT DISTINCT i.group FROM {interaction_instance} i
INNER JOIN {interaction_forum_topic} t ON i.id = t.forum
WHERE t.id =?", array($topicid));
db_begin();
// check the post content actually changed
// otherwise topic could have been set as sticky/closed
$postchanged = $values['subject'] != $topic->subject || $values['body'] != $topic->body;
if ($postchanged) {
$newbody = EmbeddedImage::prepare_embedded_images($values['body'], 'topic', $topicid, $groupid);
update_record(
'interaction_forum_post',
array(
'subject' => $values['subject'],
'body' => PluginInteractionForum::prepare_post_body($values['body'], $values['post']),
'body' => PluginInteractionForum::prepare_post_body($newbody, $values['post']),
),
array('id' => $values['post'])
);
......
......@@ -243,12 +243,14 @@ function edit_interaction_validation(Pieform $form, $values) {
}
function edit_interaction_submit(Pieform $form, $values) {
require_once('embeddedimage.php');
safe_require('interaction', $values['plugin']);
$classname = generate_interaction_instance_class_name($values['plugin']);
$instance = new $classname($values['id']);
$instance->set('creator', $values['creator']);
$instance->set('title', $values['title']);
$instance->set('description', $values['description']);
$newdescription = EmbeddedImage::prepare_embedded_images($values['description'], 'forum', $instance->get('id'), $instance->get('group'));
$instance->set('description', $newdescription);
if (empty($values['id'])) {
$instance->set('group', $values['group']);
}
......
This diff is collapsed.
<?php
/**
*
* @package mahara
* @subpackage core
* @author Mike Kelly UAL <m.f.kelly@arts.ac.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
require_once('imagebrowser.php');
$change = param_boolean('change', false);
$viewid = param_integer('id', 0);
$forumpostid = param_integer('post', 0);
$groupid = param_integer('group', 0);
$changebrowsetab = param_integer('imgbrowserconf_artefactid_changeowner', 0);
// Folder value is 0 when returning to Home folder
$changefolder = param_exists('imgbrowserconf_artefactid_changefolder')? true : false;
$uploadimg = param_integer('imgbrowserconf_artefactid_upload', 0);
$formsubmit = param_exists('action_submitimage')? true : false;
$formcancel = param_exists('cancel_action_submitimage')? true : false;
if ($forumpostid && !$groupid) {
$sql = "SELECT g.id
FROM {group} g
INNER JOIN {interaction_instance} ii ON ii.group = g.id
INNER JOIN {interaction_forum_topic} ift ON ift.forum = ii.id
INNER JOIN {interaction_forum_post} ifp ON ifp.topic = ift.id
WHERE ifp.id = ?
AND ifp.deleted = 0";
$groupid = get_field_sql($sql, array($forumpostid));
}
// Create new image browser
if ($change) {
$ib = new ImageBrowser(array('view' => $viewid, 'post' => $forumpostid, 'group' => $groupid));
try {
$returndata = $ib->render_image_browser();
json_reply(false, array('data' => $returndata));
}
catch (Exception $e) {
json_reply(true, $e->getMessage());
}
}
// If an image browser was already created and updated somehow, rebuild or submit the form now
// TODO why are other values true when submitting form?
if ($changebrowsetab || $changefolder || $uploadimg || $formsubmit || $formcancel) {
$ib = new ImageBrowser(array('view' => $viewid, 'post' => $forumpostid, 'group' => $groupid));
$ib->render_image_browser();
}
\ No newline at end of file
......@@ -1172,3 +1172,14 @@ $string['wanttoleavewithoutsaving?'] = 'You have made changes - do you want to l
// TinyMCE maharaimage plugin
$string['attachedimage'] = 'Attached image';
$string['imagebrowsertitle'] = 'Insert or Select an Image';
$string['imagebrowserdescription'] = 'Paste in the URL of an external image or use the image browser below to select or upload your own image.';
$string['url'] = 'Image URL';
$string['style'] = 'Style (CSS)';
$string['dimensions'] = 'Dimensions';
$string['constrain'] = 'Constrain?';
$string['vspace'] = 'Vertical space';
$string['hspace'] = 'Horizontal space';
$string['border'] = 'Border width';
$string['alignment'] = 'Alignment';
<?php
/**
*
* @package mahara
* @subpackage core
* @author Mike Kelly UAL <m.f.kelly@arts.ac.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
defined('INTERNAL') || die();