1
0
mirror of https://github.com/e107inc/e107.git synced 2025-04-15 01:56:34 +02:00

Forum fix. post_forum field was being sent the thread value instead of the forum value when using the "Post Reply" page. Attachments now working correctly. Fixes download issues associated with forum permissions. Also corrected pagination issue.

This commit is contained in:
Cameron 2015-05-07 11:49:36 -07:00
parent 8b57748d3f
commit 81bff06041
5 changed files with 154 additions and 128 deletions

View File

@ -222,6 +222,12 @@ class e107forum
// Check if user is allowed to download this file (has 'view' permissions to forum)
if(!$this->checkPerm($forum_id, 'view'))
{
if(E107_DEBUG_LEVEL > 0)
{
echo "You don't have 'view' access to forum-id: : ".$forum_id;
print_a($this->permList);
return;
}
header('Location:'.e107::getUrl()->create('forum/forum/main')); // FIXME needs proper redirect and 403 header
exit;
}
@ -237,6 +243,12 @@ class e107forum
}
else
{
if(E107_DEBUG_LEVEL > 0)
{
echo "Couldn't find file: ".$file;
return;
}
header('Location:'.e107::getUrl()->create('forum/forum/main', TRUE, 404)); // FIXME needs proper redirect and 404 header
exit;
}

View File

@ -343,7 +343,7 @@ class forum_post_handler
$tp = e107::getParser();
$ns = e107::getRender();
process_upload();
$this->processAttachments();
require_once(HEADERF);
if (USER)
@ -469,7 +469,7 @@ class forum_post_handler
$time = time();
$postInfo['post_entry'] = $_POST['post'];
$postInfo['post_forum'] = $this->id;
$postInfo['post_forum'] = $this->data['forum_id'];
$postInfo['post_datestamp'] = $time;
$postInfo['post_ip'] = e107::getIPHandler()->getIP(FALSE);
@ -483,7 +483,7 @@ class forum_post_handler
//If we've successfully uploaded something, we'll have to edit the post_entry and post_attachments
$newValues = array();
if($uploadResult = process_upload($newPostId))
if($uploadResult = $this->processAttachments())
{
foreach($uploadResult as $ur)
{
@ -549,8 +549,8 @@ class forum_post_handler
break;
}
e107::getMessage()->addDebug(print_a($postInfo,true));
// e107::getMessage()->addDebug(print_a($this,true));
if($postResult === -1 || $newPostId === -1) //Duplicate post
{
@ -640,7 +640,7 @@ class forum_post_handler
$postVals = array();
$threadVals = array();
if($uploadResult = process_upload($this->data['post_id']))
if($uploadResult = $this->processAttachments())
{
$attachments = explode(',', $this->data['post_attachments']);
foreach($uploadResult as $ur)
@ -718,6 +718,117 @@ class forum_post_handler
function processAttachments()
{
$ret = array();
if (isset($_FILES['file_userfile']['error']))
{
require_once(e_HANDLER.'upload_handler.php');
// retrieve and create attachment directory if needed
$attachmentDir = $this->forumObj->getAttachmentPath(USERID, true);
if($uploaded = process_uploaded_files($attachmentDir, 'attachment', ''))
{
foreach($uploaded as $upload)
{
//print_a($upload); exit;
if ($upload['error'] == 0)
{
$_txt = '';
$_att = '';
$_file = '';
$_thumb = '';
$_fname = '';
$fpath = '';
if(strstr($upload['type'], 'image'))
{
$_type = 'img';
//XXX v2.x Image-resizing is now dynamic.
/*if($forum->prefs->get('maxwidth', 0) > 0)
{
require_once(e_HANDLER.'resize_handler.php');
$orig_file = $upload['name'];
$new_file = 'th_'.$orig_file;
$resizeDir = ($forum->prefs->get('linkimg') ? 'thumb/' : '');
if(resize_image($attachmentDir.$orig_file, $attachmentDir.$resizeDir.$new_file, $forum->prefs->get('maxwidth')))
{
if($forum->prefs->get('linkimg'))
{
$parms = image_getsize($attachmentDir.$new_file);
$_txt = '[br][link='.$fpath.$orig_file."][img{$parms}]".$fpath.$new_file.'[/img][/link][br]';
$_file = $orig_file;
$_thumb = $new_file;
//show resized, link to fullsize
}
else
{
@unlink($attachmentDir.$orig_file);
//show resized
$parms = image_getsize($attachmentDir.$new_file);
$_txt = "[br][img{$parms}]".$fpath.$new_file.'[/img][br]';
$_file = $new_file;
}
}
else
{ //resize failed, show original
$parms = image_getsize($attachmentDir.$upload['name']);
$_txt = "[br][img{$parms}]".$fpath.$upload['name'].'[/img]';
$_file = $upload['name'];
}
}
else
*/
{ //resizing disabled, show original
// $parms = image_getsize($attachmentDir.$upload['name']);
//resizing disabled, show original
$_txt = "[br][img]".$fpath.$upload['name']."[/img]\n";
$_file = $upload['name'];
}
}
else
{
//upload was not an image, link to file
$_type = 'file';
$_fname = (isset($upload['rawname']) ? $upload['rawname'] : $upload['name']);
$_txt = '[br][file='.$fpath.$upload['name'].']'.$_fname.'[/file]';
$_file = $upload['name'];
$_thumb = $_fname;
}
if($_txt && $_file)
{
$ret[] = array('type' => $_type, 'txt' => $_txt, 'file' => $_file, 'thumb' => $_thumb, 'fname' => $_fname);
}
}
else
{
// Error in uploaded file, proceed but add error message.
//echo 'Error in uploaded file: '.(isset($upload['rawname']) ? $upload['rawname'] : $upload['name']).'<br />';
e107::getMessage()->addError('Error in uploading attachment: '.vartrue($upload['message']));
}
}
return $ret;
}
}
/* 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)
else
{
e107::getMessage()->addError('Something went wrong during the attachment uploading process.');
}
*/
}
}
require_once(HEADERF);
@ -1281,117 +1392,6 @@ function forumjump()
return $text;
}
function process_upload()
{
return;
global $forumInfo, $thread_info, $admin_log, $forum;
$postId = (int)$postId;
$ret = array();
if (isset($_FILES['file_userfile']['error']))
{
require_once(e_HANDLER.'upload_handler.php');
// retrieve and create attachment directory if needed
$attachmentDir = $forum->getAttachmentPath(USERID, TRUE);
if($uploaded = process_uploaded_files($attachmentDir, 'attachment', ''))
{
foreach($uploaded as $upload)
{
//print_a($upload); exit;
if ($upload['error'] == 0)
{
$_txt = '';
$_att = '';
$_file = '';
$_thumb = '';
$_fname = '';
$fpath = '';
if(strstr($upload['type'], 'image'))
{
$_type = 'img';
//XXX v2.x Image-resizing is now dynamic.
/*if($forum->prefs->get('maxwidth', 0) > 0)
{
require_once(e_HANDLER.'resize_handler.php');
$orig_file = $upload['name'];
$new_file = 'th_'.$orig_file;
$resizeDir = ($forum->prefs->get('linkimg') ? 'thumb/' : '');
if(resize_image($attachmentDir.$orig_file, $attachmentDir.$resizeDir.$new_file, $forum->prefs->get('maxwidth')))
{
if($forum->prefs->get('linkimg'))
{
$parms = image_getsize($attachmentDir.$new_file);
$_txt = '[br][link='.$fpath.$orig_file."][img{$parms}]".$fpath.$new_file.'[/img][/link][br]';
$_file = $orig_file;
$_thumb = $new_file;
//show resized, link to fullsize
}
else
{
@unlink($attachmentDir.$orig_file);
//show resized
$parms = image_getsize($attachmentDir.$new_file);
$_txt = "[br][img{$parms}]".$fpath.$new_file.'[/img][br]';
$_file = $new_file;
}
}
else
{ //resize failed, show original
$parms = image_getsize($attachmentDir.$upload['name']);
$_txt = "[br][img{$parms}]".$fpath.$upload['name'].'[/img]';
$_file = $upload['name'];
}
}
else
*/
{ //resizing disabled, show original
// $parms = image_getsize($attachmentDir.$upload['name']);
//resizing disabled, show original
$_txt = "[br][img]".$fpath.$upload['name']."[/img]\n";
$_file = $upload['name'];
}
}
else
{
//upload was not an image, link to file
$_type = 'file';
$_fname = (isset($upload['rawname']) ? $upload['rawname'] : $upload['name']);
$_txt = '[br][file='.$fpath.$upload['name'].']'.$_fname.'[/file]';
$_file = $upload['name'];
$_thumb = $_fname;
}
if($_txt && $_file)
{
$ret[] = array('type' => $_type, 'txt' => $_txt, 'file' => $_file, 'thumb' => $_thumb, 'fname' => $_fname);
}
}
else
{
// Error in uploaded file, proceed but add error message.
//echo 'Error in uploaded file: '.(isset($upload['rawname']) ? $upload['rawname'] : $upload['name']).'<br />';
e107::getMessage()->addError('Error in uploading attachment: '.vartrue($upload['message']));
}
}
return $ret;
}
}
/* 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)
else
{
e107::getMessage()->addError('Something went wrong during the attachment uploading process.');
}
*/
}
function image_getsize($fname)
{

View File

@ -251,6 +251,7 @@ if ($thread->pages > 1)
$parms = "total={$thread->pages}&type=page&current={$thread->page}&url=".$url."&caption=off&tmpl=default&navcount=4&glyphs=1";
//XXX FIXME - pull-down template not practical here. Can we force another?
$tVars->GOTOPAGES = $tp->parseTemplate("{NEXTPREV={$parms}}");
/*
$parms = ($thread->pages).",1,{$thread->page},url::forum::thread::func=view&id={$thread->threadId}&page=[FROM],off";
@ -625,6 +626,8 @@ class e107ForumThread
public $perPage;
public $noInc;
public $pages;
public $page;
function init()
{
@ -656,10 +659,14 @@ class e107ForumThread
header('Location:' . $e107->url->create('forum/forum/main', array(), 'encode=0&full=1'));
exit;
}
$this->pages = ceil(($this->threadInfo['thread_total_replies']) / $this->perPage);
$totalPosts = $this->threadInfo['thread_total_replies'] + 1; // add 1 for the original post . ie. not a reply.
$this->pages = ceil(($totalPosts) / $this->perPage);
$this->noInc = false;
}
function toggle_track()
{
global $forum, $thread;
@ -717,7 +724,7 @@ class e107ForumThread
break;
case 'last':
$pages = ceil(($thread->threadInfo['thread_total_replies']) / $thread->perPage);
$pages = ceil(($thread->threadInfo['thread_total_replies'] + 1) / $thread->perPage);
$thread->page = $_GET['p'] = $pages;
break;

View File

@ -93,7 +93,7 @@ class plugin_forum_view_shortcodes extends e_shortcode
function sc_attachments()
function sc_attachments($parm=array())
{
$tp = e107::getParser();
@ -114,14 +114,22 @@ class plugin_forum_view_shortcodes extends e_shortcode
switch($type)
{
case 'file':
case "file":
$url = e_SELF."?id=".$this->postInfo['post_id']."&amp;dl=".$key;
$txt .= IMAGE_attachment." <a href='".$url."'>{$name}</a><br />";
$url = e_REQUEST_SELF."?id=".$this->postInfo['post_id']."&amp;dl=".$key;
if(defset("BOOTSTRAP") == 3)
{
$txt .= "<a class='forum-attachment-file btn btn-sm btn-default' href='".$url."'>".$tp->toGlyph('glyphicon-save')." {$name}</a><br />";
}
else
{
$txt .= IMAGE_attachment." <a href='".$url."'>{$name}</a><br />";
}
break;
case 'img': //Always use thumb to hide the hash.
case 'img': //Always use thumb to hide the hash.
// return $baseDir.$file;
if(file_exists($baseDir.$file))
@ -130,7 +138,7 @@ class plugin_forum_view_shortcodes extends e_shortcode
$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}'><img class='thumbnail' src='{$thumb}' alt='' /></a>";
$images[] = "<a {$inc} rel='external' href='{$full}' class='forum-attachment-image' ><img class='thumbnail' src='{$thumb}' alt='' /></a>";
}
elseif(ADMIN)
{

View File

@ -387,10 +387,9 @@ $FORUM_VIEWTOPIC_TEMPLATE['end'] = "</ul>
$FORUM_VIEWTOPIC_TEMPLATE['replies'] = $FORUM_VIEWTOPIC_TEMPLATE['thread'];
$FORUM_VIEWTOPIC_TEMPLATE['replies'] = $FORUM_VIEWTOPIC_TEMPLATE['thread'];
$FORUM_VIEWTOPIC_WRAPPER['ATTACHMENTS'] = "<div class='alert alert-default alert-block'>{---}</div>";
//$FORUMDELETEDSTYLE = "<br />DELETED";