mirror of
https://github.com/e107inc/e107.git
synced 2025-07-29 10:50:25 +02:00
ENH allow user to delete his own post, if it is the last post in the thread
This commit is contained in:
@@ -368,6 +368,47 @@ class e107forum
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Allow a user to delete their own post, if it is the last post in the thread.
|
||||
*/
|
||||
function usersLastPostDeletion()
|
||||
{
|
||||
$ret = array('hide' => false, 'msg' => LAN_FORUM_7008, 'status' => 'error');
|
||||
$actionAllowed = false;
|
||||
|
||||
if (isset($_POST['post']) && is_numeric($_POST['post']))
|
||||
{
|
||||
$postId = intval($_POST['post']);
|
||||
$sql = e107::getDb();
|
||||
$query = "SELECT fp.post_user
|
||||
FROM #forum_post AS fp
|
||||
WHERE fp.post_id = ". $postId;
|
||||
if ($sql->gen($query) > 0)
|
||||
{
|
||||
$row = $sql->fetch();
|
||||
if (USERID == $row['post_user']) $actionAllowed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($actionAllowed && $_POST['action'] == 'deletepost')
|
||||
{
|
||||
if ($this->postDelete($postId))
|
||||
{
|
||||
$ret['msg'] = ''.LAN_FORUM_8021.' #'.$postId;
|
||||
$ret['hide'] = true;
|
||||
$ret['status'] = 'ok';
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret['msg'] = "".LAN_FORUM_8021." #".$postId;
|
||||
$ret['status'] = 'error';
|
||||
}
|
||||
}
|
||||
echo json_encode($ret);
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get user ids with moderator permissions for the given $postId
|
||||
* @param $postId id of a forum post
|
||||
|
@@ -69,9 +69,27 @@ if(vartrue($_GET['id']) && isset($_GET['dl']))
|
||||
exit;
|
||||
}
|
||||
|
||||
if (isset($_GET['last']))
|
||||
{
|
||||
$_GET['f'] = 'last';
|
||||
}
|
||||
|
||||
if(isset($_GET['f']) && $_GET['f'] == 'post')
|
||||
{
|
||||
$thread->processFunction();
|
||||
}
|
||||
|
||||
$thread->init();
|
||||
|
||||
|
||||
/* Check if use has moderator permissions for this thread */
|
||||
$moderatorUserIds = $forum->getModeratorUserIdsByThreadId($thread->threadInfo['thread_id']);
|
||||
define('MODERATOR', (USER && in_array(USERID, $moderatorUserIds)));
|
||||
|
||||
|
||||
if(e_AJAX_REQUEST)
|
||||
{
|
||||
if(varset($_POST['action']) == 'quickreply')
|
||||
if(varset($_POST['action']) == 'quickreply')
|
||||
{
|
||||
$forum->ajaxQuickReply();
|
||||
}
|
||||
@@ -85,22 +103,12 @@ if(e_AJAX_REQUEST)
|
||||
{
|
||||
$forum->ajaxModerate();
|
||||
}
|
||||
|
||||
else if(varset($_POST['action']) == 'deletepost')
|
||||
{
|
||||
$forum->usersLastPostDeletion();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (isset($_GET['last']))
|
||||
{
|
||||
$_GET['f'] = 'last';
|
||||
}
|
||||
|
||||
if(isset($_GET['f']) && $_GET['f'] == 'post')
|
||||
{
|
||||
$thread->processFunction();
|
||||
}
|
||||
|
||||
$thread->init();
|
||||
|
||||
|
||||
/*
|
||||
if(isset($_POST['track_toggle']))
|
||||
@@ -145,9 +153,6 @@ define('e_PAGETITLE', strip_tags($tp->toHTML($thread->threadInfo['thread_name'],
|
||||
|
||||
$forum->modArray = $forum->forumGetMods($thread->threadInfo['forum_moderators']);
|
||||
|
||||
/* Check if use has moderator permissions for this thread */
|
||||
$moderatorUserIds = $forum->getModeratorUserIdsByThreadId($thread->threadInfo['thread_id']);
|
||||
define('MODERATOR', (USER && in_array(USERID, $moderatorUserIds)));
|
||||
|
||||
e107::getScBatch('view', 'forum')->setScVar('forum', $forum);
|
||||
//var_dump(e107::getScBatch('forum', 'forum'));
|
||||
@@ -485,6 +490,8 @@ $i = $thread->page;
|
||||
$sc->wrapper('forum_viewtopic/end');
|
||||
$forend = $tp->parseTemplate($FORUMEND, true, $sc);
|
||||
|
||||
$lastPostDetectionCounter = count($postList);
|
||||
$sc->setScVar('thisIsTheLastPost', false);
|
||||
|
||||
foreach ($postList as $c => $postInfo)
|
||||
{
|
||||
@@ -494,6 +501,9 @@ foreach ($postList as $c => $postInfo)
|
||||
}
|
||||
$loop_uid = (int)$postInfo['post_user'];
|
||||
|
||||
$lastPostDetectionCounter--;
|
||||
if ($lastPostDetectionCounter == 0) $sc->setScVar('thisIsTheLastPost', true);
|
||||
|
||||
//---- Orphan $tnum????
|
||||
$tnum = $i;
|
||||
|
||||
|
@@ -859,6 +859,17 @@
|
||||
|
||||
}
|
||||
|
||||
// Delete own post, if it is the last in the thread
|
||||
if($this->thisIsTheLastPost && USER && $this->thread->threadInfo['thread_lastuser'] == USERID)
|
||||
{
|
||||
/* only show delete button when post is not the initial post of the topic
|
||||
* AND if this post is the last post in the thread */
|
||||
if($this->thread->threadInfo['thread_active'] && empty($this->postInfo['thread_start']) )
|
||||
{
|
||||
$text .= "<li class='text-right'><a href='" . e_REQUEST_URI . "' data-forum-action='deletepost' data-forum-post='" . $this->postInfo['post_id'] . "'>" . LAN_DELETE . " " . $tp->toGlyph('trash') . "</a></li>";
|
||||
}
|
||||
}
|
||||
|
||||
if($this->forum->checkperm($this->postInfo['post_forum'], 'post'))
|
||||
{
|
||||
$url = e107::url('forum', 'post') . "?f=quote&id=" . $this->postInfo['post_thread'] . "&post=" . $this->postInfo['post_id'];
|
||||
|
Reference in New Issue
Block a user