From bf2db49dd1da75d088881f3be445b2962e7bcb5c Mon Sep 17 00:00:00 2001 From: Cameron Date: Mon, 21 Mar 2016 14:32:02 -0700 Subject: [PATCH] Forum now allows for multiple attachments in a single user selection. For update thread/count should now working with PDO. --- e107_handlers/file_class.php | 38 ++++++++++++++++++- e107_plugins/forum/forum_class.php | 20 +++++++++- e107_plugins/forum/forum_post.php | 35 +++++++++++------ .../forum/languages/English/English_front.php | 2 +- .../shortcodes/batch/post_shortcodes.php | 6 +-- .../shortcodes/batch/view_shortcodes.php | 28 +++++++++++--- 6 files changed, 104 insertions(+), 25 deletions(-) diff --git a/e107_handlers/file_class.php b/e107_handlers/file_class.php index af90627e4..35215e160 100644 --- a/e107_handlers/file_class.php +++ b/e107_handlers/file_class.php @@ -1040,8 +1040,42 @@ class e_file return process_uploaded_files($uploaddir, $fileinfo, $options); } - - + + + /** + * Quickly scan and return a list of files in a directory. + * @param $dir + * @return array + */ + public function scandir($dir, $extensions=null) + { + $list = array(); + + $ext = str_replace(",","|",$extensions); + + $tmp = scandir($dir); + foreach($tmp as $v) + { + if($v == '.' || $v == '..') + { + continue; + } + + if(!empty($ext) && !preg_match("/\.(".$ext.")$/i", $v)) + { + + continue; + } + + $list[] = $v; + } + + return $list ; + } + + + + /** * Unzip Plugin or Theme zip file and move to plugin or theme folder. * @param string $localfile - filename located in e_TEMP diff --git a/e107_plugins/forum/forum_class.php b/e107_plugins/forum/forum_class.php index 9ba7c00c1..247846508 100644 --- a/e107_plugins/forum/forum_class.php +++ b/e107_plugins/forum/forum_class.php @@ -150,7 +150,10 @@ class e107forum $array = $sql->retrieve('forum_post','post_user,post_attachments','post_id='.$post_id); $attach = e107::unserialize($array['post_attachments']); - $file = $this->getAttachmentPath($array['post_user']).varset($attach['file'][$file_id]); + + $filename = is_array($attach['file'][$file_id]) ? $attach['file'][$file_id]['file'] : $attach['file'][$file_id]; + + $file = $this->getAttachmentPath($array['post_user']).varset($filename); // Check if file exists. Send file for download if it does, return 404 error code when file does not exist. if(file_exists($file)) @@ -162,6 +165,7 @@ class e107forum if(E107_DEBUG_LEVEL > 0) { echo "Couldn't find file: ".$file; + print_a($attach); return; } @@ -665,7 +669,15 @@ class e107forum $forumInfo['forum_lastpost_user'] = 0; $forumInfo['forum_lastpost_user_anon'] = $postInfo['post_user_anon']; } - $threadInfo['thread_lastpost'] = $postInfo['post_datestamp']; + + $threadInfo['thread_lastpost'] = !empty($postInfo['post_edit_datestamp']) ? $postInfo['post_edit_datestamp'] : $postInfo['post_datestamp']; + + if(!empty($postInfo['post_edit_user'])) + { + $threadInfo['thread_lastuser'] = $postInfo['post_edit_user']; + } + + $threadInfo['thread_total_replies'] = 'thread_total_replies + 1'; $info = array(); @@ -675,6 +687,10 @@ class e107forum $info['_FIELD_TYPES']['thread_total_replies'] = 'cmd'; $result = $sql->update('forum_thread', $info); + + e107::getMessage()->addDebug("Updating Thread with: ".print_a($info,true)); + + e107::getEvent()->trigger('user_forum_topic_updated', $info); } diff --git a/e107_plugins/forum/forum_post.php b/e107_plugins/forum/forum_post.php index 6f2d9041f..bc04a6adc 100644 --- a/e107_plugins/forum/forum_post.php +++ b/e107_plugins/forum/forum_post.php @@ -219,7 +219,9 @@ class forum_post_handler if(E107_DEBUG_LEVEL > 0) { require_once(HEADERF); + e107::getRender()->tablerender('Debug', "Redirecting to: ".$url.""); + echo e107::getMessage()->render(); require_once(FOOTERF); exit; @@ -781,18 +783,11 @@ class forum_post_handler { foreach($uploadResult as $ur) { - //$postInfo['post_entry'] .= $ur['txt']; - // $_tmp = $ur['type'].'*'.$ur['file']; - // if($ur['thumb']) { $_tmp .= '*'.$ur['thumb']; } - // if($ur['fname']) { $_tmp .= '*'.$ur['fname']; } - $type = $ur['type']; - $newValues[$type][] = $ur['file']; - // $attachments[] = $_tmp; + $newValues[$type][] = array('file'=>$ur['file'], 'name'=>$ur['fname'], 'size'=>$ur['size']); } - // $postInfo['_FIELD_TYPES']['post_attachments'] = 'array'; - $postInfo['post_attachments'] = e107::serialize($newValues); //FIXME XXX - broken encoding when saved to DB. + $postInfo['post_attachments'] = e107::serialize($newValues); } // var_dump($uploadResult); @@ -998,7 +993,7 @@ class forum_post_handler // $attachments[] = $_tmp; $type = $ur['type']; - $newValues[$type][] = $ur['file']; + $newValues[$type][] = array('file'=>$ur['file'], 'name'=>$ur['fname'], 'size'=>$ur['size']); } $postVals['post_attachments'] = e107::serialize($newValues); // $postVals['post_attachments'] = implode(',', $attachments); @@ -1051,10 +1046,26 @@ class forum_post_handler return; } + e107::getMessage()->addDebug(print_a($this->data,true)); + $postVals['post_edit_datestamp'] = time(); $postVals['post_edit_user'] = USERID; $postVals['post_entry'] = $_POST['post']; + if($uploadResult = $this->processAttachments()) + { + $newValues = e107::unserialize($this->data['post_attachments']); + + foreach($uploadResult as $ur) + { + $type = $ur['type']; + $newValues[$type][] = array('file'=>$ur['file'], 'name'=>$ur['fname'], 'size'=>$ur['size']); + } + + $postVals['post_attachments'] = e107::serialize($newValues); + } + + $this->forumObj->postUpdate($this->data['post_id'], $postVals); e107::getCache()->clear('newforumposts'); @@ -1100,7 +1111,7 @@ class forum_post_handler e107::getMessage()->addDebug("Attachment Directory: ".$attachmentDir); - if($uploaded = e107::getFile()->getUploaded($attachmentDir, 'attachment', '')) + if($uploaded = e107::getFile()->getUploaded($attachmentDir, 'attachment', array( 'max_file_count' => 5))) { e107::getMessage()->addDebug("Uploaded Data: ".print_a($uploaded,true)); @@ -1178,7 +1189,7 @@ class forum_post_handler } if($_txt && $_file) { - $ret[] = array('type' => $_type, 'txt' => $_txt, 'file' => $_file, 'thumb' => $_thumb, 'fname' => $_fname); + $ret[] = array('type' => $_type, 'txt' => $_txt, 'file' => $_file, 'thumb' => $_thumb, 'fname' => $upload['origname'], 'size'=>$upload['size']); } } else diff --git a/e107_plugins/forum/languages/English/English_front.php b/e107_plugins/forum/languages/English/English_front.php index 97b9a9f8e..1e6e1652d 100644 --- a/e107_plugins/forum/languages/English/English_front.php +++ b/e107_plugins/forum/languages/English/English_front.php @@ -197,7 +197,7 @@ define("LAN_FORUM_3008", "Unauthorised"); // LAN_95 define("LAN_FORUM_3009", "You are not authorised to edit this forum post."); //LAN_96 define("LAN_FORUM_3010", "Your name"); // LAN_61 define("LAN_FORUM_3011", "Subject"); // LAN_62 -define("LAN_FORUM_3012", "Attach file / image"); // LAN_390 +define("LAN_FORUM_3012", "Attach file(s) / image(s)"); // LAN_390 define("LAN_FORUM_3013", "Attach file"); // LAN_416 define("LAN_FORUM_3014", "File to attach"); // LAN_392 define("LAN_FORUM_3015", "[Please note]"); // LAN_393 1st half - [ and ] are replaced by diff --git a/e107_plugins/forum/shortcodes/batch/post_shortcodes.php b/e107_plugins/forum/shortcodes/batch/post_shortcodes.php index 5ee7b5ba4..f277ae9bf 100644 --- a/e107_plugins/forum/shortcodes/batch/post_shortcodes.php +++ b/e107_plugins/forum/shortcodes/batch/post_shortcodes.php @@ -256,14 +256,14 @@ class plugin_forum_post_shortcodes extends e_shortcode
- toAttribute($tooltip)."\" name='file_userfile[]' type='file' size='47' /> + toAttribute($tooltip)."\" name='file_userfile[]' type='file' size='47' multiple='multiple' />
- +
"; - + // if( $this->forum->prefs->get('attach') && (check_class($pref['upload_class']) || getperms('0'))) { return $fileattach; diff --git a/e107_plugins/forum/shortcodes/batch/view_shortcodes.php b/e107_plugins/forum/shortcodes/batch/view_shortcodes.php index de33d68e2..9add821a2 100644 --- a/e107_plugins/forum/shortcodes/batch/view_shortcodes.php +++ b/e107_plugins/forum/shortcodes/batch/view_shortcodes.php @@ -105,12 +105,23 @@ class plugin_forum_view_shortcodes extends e_shortcode $txt = ''; $attachArray = e107::unserialize($this->postInfo['post_attachments']); - //print_a($attachArray); + //print_a($attachArray); + foreach($attachArray as $type=>$vals) { foreach($vals as $key=>$file) { - list($date,$user, $name) = explode("_", $file, 3); + if(is_array($file)) + { + + $name = !empty($file['name']) ? $file['name'] : $file['file']; + + $file = $file['file']; + } + else + { + list($date,$user, $name) = explode("_", $file, 3); + } switch($type) { @@ -130,14 +141,21 @@ class plugin_forum_view_shortcodes extends e_shortcode break; case 'img': //Always use thumb to hide the hash. - + + + + // return $baseDir.$file; if(file_exists($baseDir.$file)) { $thumb = $tp->thumbUrl($baseDir.$file,'x=1',true); $full = $tp->thumbUrl($baseDir.$file,'w=1000&x=1', true); - - $inc = (vartrue($parm['modal'])) ? "data-modal-caption=\"".$file."\" data-target='#uiModal' " : ""; + + //TODO Use jQuery zoom instead. + + $caption = $name; + + $inc = (vartrue($parm['modal'])) ? "data-modal-caption=\"".$caption."\" data-target='#uiModal' " : ""; $images[] = ""; } elseif(ADMIN)