1
0
mirror of https://github.com/e107inc/e107.git synced 2025-03-14 01:19:44 +01:00

Fixes #1433 - Forum Attachments/Image data would become corrupted while editing.

This commit is contained in:
Cameron 2016-03-20 18:32:35 -07:00
parent 789e701ff1
commit bda0d9d2a3
4 changed files with 41 additions and 16 deletions

View File

@ -743,7 +743,12 @@ class e107forum
{
e107::getEvent()->trigger('user_forum_topic_created', $info);
$postInfo['post_thread'] = $newThreadId;
$newPostId = $this->postAdd($postInfo, false);
if(!$newPostId = $this->postAdd($postInfo, false))
{
e107::getMessage()->addDebug("There was a problem: ".print_a($postInfo,true));
}
$this->threadMarkAsRead($newThreadId);
$threadInfo['thread_sef'] = $this->getThreadsef($threadInfo);
@ -931,7 +936,7 @@ class e107forum
}
else
{
e107::getMessage()->addDebug("Query Failed: ".$qry);
e107::getMessage()->addDebug('Query failed ('.__METHOD__.' ): '.str_replace('#', MPREFIX,$qry));
}
if('post' === $start) { return $ret[0]; }

View File

@ -988,15 +988,20 @@ class forum_post_handler
if($uploadResult = $this->processAttachments())
{
$attachments = explode(',', $this->data['post_attachments']);
// $attachments = explode(',', $this->data['post_attachments']);
$newValues = e107::unserialize($this->data['post_attachments']);
foreach($uploadResult as $ur)
{
$_tmp = $ur['type'].'*'.$ur['file'];
if($ur['thumb']) { $_tmp .= '*'.$ur['thumb']; }
if($ur['fname']) { $_tmp .= '*'.$ur['fname']; }
$attachments[] = $_tmp;
// $_tmp = $ur['type'].'*'.$ur['file'];
// if($ur['thumb']) { $_tmp .= '*'.$ur['thumb']; }
// if($ur['fname']) { $_tmp .= '*'.$ur['fname']; }
// $attachments[] = $_tmp;
$type = $ur['type'];
$newValues[$type][] = $ur['file'];
}
$postVals['post_attachments'] = implode(',', $attachments);
$postVals['post_attachments'] = e107::serialize($newValues);
// $postVals['post_attachments'] = implode(',', $attachments);
}
$postVals['post_edit_datestamp'] = time();
@ -1074,23 +1079,33 @@ class forum_post_handler
}
/**
* @return array
*/
function processAttachments()
{
$ret = array();
e107::getMessage()->addDebug("Processing Attachments");
if (isset($_FILES['file_userfile']['error']))
{
require_once(e_HANDLER.'upload_handler.php');
e107::getMessage()->addDebug("Attachment Detected");
// retrieve and create attachment directory if needed
$attachmentDir = $this->forumObj->getAttachmentPath(USERID, true);
if($uploaded = process_uploaded_files($attachmentDir, 'attachment', ''))
e107::getMessage()->addDebug("Attachment Directory: ".$attachmentDir);
if($uploaded = e107::getFile()->getUploaded($attachmentDir, 'attachment', ''))
{
e107::getMessage()->addDebug("Uploaded Data: ".print_a($uploaded,true));
foreach($uploaded as $upload)
{
//print_a($upload); exit;
@ -1176,6 +1191,11 @@ class forum_post_handler
return $ret;
}
else
{
// e107::getMessage()->addError('There was a problem with the attachment.');
// e107::getMessage()->addDebug(print_a($_FILES['file_userfile'],true));
}
}
/* no file uploaded at all, proceed with creating the topic or reply
// TODO don't call process_upload() when no attachments are uploaded.. (check user input first, then call if needed)

View File

@ -137,8 +137,8 @@ class plugin_forum_view_shortcodes extends e_shortcode
$thumb = $tp->thumbUrl($baseDir.$file,'x=1',true);
$full = $tp->thumbUrl($baseDir.$file,'w=1000&x=1', true);
$inc = (vartrue($parm['modal'])) ? "data-toggle='modal' data-target='#".$parm['modal']."' " : "";
$images[] = "<a {$inc} rel='external' href='{$full}' class='forum-attachment-image' ><img class='thumbnail' src='{$thumb}' alt='' /></a>";
$inc = (vartrue($parm['modal'])) ? "data-modal-caption=\"".$file."\" data-target='#uiModal' " : "";
$images[] = "<a {$inc} rel='external' href='{$full}' class='forum-attachment-image e-modal' ><img class='thumbnail' src='{$thumb}' alt='' /></a>";
}
elseif(ADMIN)
{

View File

@ -363,7 +363,7 @@ $FORUM_VIEWTOPIC_TEMPLATE['thread'] = "
<div class='col-xs-12 col-md-9 span9 forum-thread-text '>
{POLL}
{THREAD_TEXT}
{ATTACHMENTS}
{ATTACHMENTS: modal=1}
</div>
</div>