diff --git a/e107_plugins/forum/forum_post.php b/e107_plugins/forum/forum_post.php index bcb27ac82..2c6d59662 100644 --- a/e107_plugins/forum/forum_post.php +++ b/e107_plugins/forum/forum_post.php @@ -796,6 +796,13 @@ class forum_post_handler $postInfo['post_attachments'] = e107::serialize($newValues); } + + //Allows directly overriding the method of adding files (or other data) as attachments + if($attachmentsPosted = $this->processAttachmentsPosted()) + { + $postInfo['post_attachments'] = $attachmentsPosted; + } + // var_dump($uploadResult); switch($this->action) @@ -1005,7 +1012,13 @@ class forum_post_handler $postVals['post_attachments'] = e107::serialize($newValues); // $postVals['post_attachments'] = implode(',', $attachments); } - + + //Allows directly overriding the method of adding files (or other data) as attachments + if($attachmentsPosted = $this->processAttachmentsPosted($this->data['post_attachments'])) + { + $postVals['post_attachments'] = $attachmentsPosted; + } + $postVals['post_edit_datestamp'] = time(); $postVals['post_edit_user'] = USERID; $postVals['post_entry'] = $_POST['post']; @@ -1071,7 +1084,12 @@ class forum_post_handler $postVals['post_attachments'] = e107::serialize($newValues); } - + + //Allows directly overriding the method of adding files (or other data) as attachments + if($attachmentsPosted = $this->processAttachmentsPosted($this->data['post_attachments'])) + { + $postVals['post_attachments'] = $attachmentsPosted; + } $this->forumObj->postUpdate($this->data['post_id'], $postVals); @@ -1223,6 +1241,31 @@ class forum_post_handler } */ } + + + //Allows directly overriding the method of adding files (or other data) as attachments + function processAttachmentsPosted($existingValues = '') + { + if(isset($_POST['post_attachments_json']) && trim($_POST['post_attachments_json'])) + { + $postedAttachments = json_decode($_POST['post_attachments_json'], true); + $attachmentsJsonErrors = json_last_error(); + if($attachmentsJsonErrors === JSON_ERROR_NONE) + { + if($existingValues) + { + $existingValues = e107::unserialize($existingValues); + return e107::serialize(array_merge_recursive($existingValues,$postedAttachments)); + } + else + { + return e107::serialize($postedAttachments); + } + } + } + + return false; + } }