1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-06 14:46:56 +02:00

ENH allow user to delete his own post, if it is the last post in the thread

This commit is contained in:
phibel
2018-09-30 23:17:58 +02:00
parent f480064ba4
commit 3848560752
3 changed files with 80 additions and 18 deletions

View File

@@ -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