mirror of
https://github.com/e107inc/e107.git
synced 2025-08-01 04:10:38 +02:00
Forum plugin: Added check to prevent deleting of initial post in topic
This commit is contained in:
@@ -843,6 +843,37 @@ class e107forum
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if post is the initial post which started the topic.
|
||||
* Retrieves list of post_id's belonging to one post_thread. When lowest value is equal to input param, return true.
|
||||
* Used to prevent deleting of the initial post (so topic shows empty does not get hidden accidently while posts remain in database)
|
||||
*
|
||||
* @param int id of the post
|
||||
* @return boolean true if post is the initial post of the topic (false, if not)
|
||||
*
|
||||
*/
|
||||
function threadDetermineInitialPost($postId)
|
||||
{
|
||||
$sql = e107::getDb();
|
||||
$postId = (int)$postId;
|
||||
$threadId = $sql->retrieve('forum_post', 'post_thread', 'post_id = '.$postId);
|
||||
|
||||
if($rows = $sql->retrieve('forum_post', 'post_id', 'post_thread = '.$threadId, TRUE))
|
||||
{
|
||||
$postids = array();
|
||||
|
||||
foreach($rows as $row)
|
||||
{
|
||||
$postids[] = $row['post_id'];
|
||||
}
|
||||
|
||||
if($postId == min($postids))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function threadGetUserPostcount($threadId)
|
||||
{
|
||||
|
@@ -506,8 +506,12 @@ class plugin_forum_view_shortcodes extends e_shortcode
|
||||
$text .= "<li><a href='".e107::getUrl()->create('forum/thread/edit', array('id' => $this->postInfo['post_id']))."'>".LAN_FORUM_2039." ".$tp->toGlyph('edit')."</a></li>";
|
||||
}
|
||||
|
||||
$text .= "<li><a href='".e_REQUEST_URI."' data-forum-action='deletepost' data-forum-post='".$this->postInfo['post_id']."'>".LAN_FORUM_2040." ".$tp->toGlyph('trash')."</a></li>";
|
||||
|
||||
// only show delete button when post is not the initial post of the topic
|
||||
if(!$this->forum->threadDetermineInitialPost($this->postInfo['post_id']))
|
||||
{
|
||||
$text .= "<li><a href='".e_REQUEST_URI."' data-forum-action='deletepost' data-forum-post='".$this->postInfo['post_id']."'>".LAN_FORUM_2040." ".$tp->toGlyph('trash')."</a></li>";
|
||||
}
|
||||
|
||||
if ($type == 'thread')
|
||||
{
|
||||
$text .= "<li><a href='" . e107::getUrl()->create('forum/thread/move', array('id' => $this->postInfo['post_id']))."'>".LAN_FORUM_2042." ".$tp->toGlyph('move')."</a></a></li>";
|
||||
|
Reference in New Issue
Block a user