mirror of
https://github.com/e107inc/e107.git
synced 2025-08-02 20:57:26 +02:00
@@ -368,30 +368,137 @@ class e107forum
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function ajaxModerate()
|
/**
|
||||||
|
* Allow a user to delete their own post, if it is the last post in the thread.
|
||||||
|
*/
|
||||||
|
function usersLastPostDeletion()
|
||||||
{
|
{
|
||||||
$ret = array('hide' => false, 'msg' => 'unkown', 'status' => 'error');
|
$ret = array('hide' => false, 'msg' => LAN_FORUM_7008, 'status' => 'error');
|
||||||
$modArray = array();
|
$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
|
||||||
|
* @return an array with user ids how have moderator permissions for the $postId
|
||||||
|
*/
|
||||||
|
public function getModeratorUserIdsByPostId($postId)
|
||||||
|
{
|
||||||
|
$sql = e107::getDb();
|
||||||
|
$query = "SELECT f.forum_moderators
|
||||||
|
FROM #forum AS f
|
||||||
|
INNER JOIN #forum_thread AS ft ON f.forum_id = ft.thread_forum_id
|
||||||
|
INNER JOIN #forum_post AS fp ON ft.thread_id = fp.post_thread
|
||||||
|
WHERE fp.post_id = ". $postId;
|
||||||
|
if ($sql->gen($query) > 0)
|
||||||
|
{
|
||||||
|
$row = $sql->fetch();
|
||||||
|
return array_keys($this->forumGetMods($row['forum_moderators']));
|
||||||
|
}
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get user ids with moderator permissions for the given $threadId
|
||||||
|
* @param $threadId id of a forum thread
|
||||||
|
* @return an array with user ids how have moderator permissions for the $threadId
|
||||||
|
*/
|
||||||
|
public function getModeratorUserIdsByThreadId($threadId)
|
||||||
|
{
|
||||||
// get moderator-class for the thread to check permissions of the user
|
// get moderator-class for the thread to check permissions of the user
|
||||||
if (isset($_POST['thread']))
|
|
||||||
{
|
|
||||||
$threadId = intval($_POST['thread']);
|
|
||||||
|
|
||||||
$sql = e107::getDb();
|
$sql = e107::getDb();
|
||||||
$query = "SELECT f.forum_moderators
|
$query = "SELECT f.forum_moderators
|
||||||
FROM #forum AS f
|
FROM #forum AS f
|
||||||
INNER JOIN #forum_thread AS ft ON f.forum_id = ft.thread_forum_id
|
INNER JOIN #forum_thread AS ft ON f.forum_id = ft.thread_forum_id
|
||||||
WHERE ft.thread_id = ". $threadId;
|
WHERE ft.thread_id = ". $threadId;
|
||||||
$sql->gen($query);
|
if ($sql->gen($query) > 0)
|
||||||
|
{
|
||||||
$row = $sql->fetch();
|
$row = $sql->fetch();
|
||||||
$modArray = $this->forumGetMods($row[forum_moderators]);
|
return array_keys($this->forumGetMods($row['forum_moderators']));
|
||||||
|
}
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get user ids with moderator permissions for the given $forumId
|
||||||
|
* @param $forumId id of a forum
|
||||||
|
* @return an array with user ids how have moderator permissions for the $forumId
|
||||||
|
*/
|
||||||
|
public function getModeratorUserIdsByForumId($forumId)
|
||||||
|
{
|
||||||
|
// get moderator-class for the thread to check permissions of the user
|
||||||
|
$sql = e107::getDb();
|
||||||
|
$query = "SELECT f.forum_moderators
|
||||||
|
FROM #forum AS f
|
||||||
|
WHERE f.forum_id = ". $forumId;
|
||||||
|
if ($sql->gen($query) > 0)
|
||||||
|
{
|
||||||
|
$row = $sql->fetch();
|
||||||
|
return array_keys($this->forumGetMods($row['forum_moderators']));
|
||||||
|
}
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function ajaxModerate()
|
||||||
|
{
|
||||||
|
$ret = array('hide' => false, 'msg' => 'unkown', 'status' => 'error');
|
||||||
|
$moderatorUserIds = array();
|
||||||
|
|
||||||
|
if (isset($_POST['thread']) && is_numeric($_POST['thread']))
|
||||||
|
{
|
||||||
|
$threadId = intval($_POST['thread']);
|
||||||
|
$moderatorUserIds = $this->getModeratorUserIdsByThreadId($threadId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If both, a thread-operation and a post-operation is submitted, the
|
||||||
|
* thread-permissions MUST be overwritten by the post-permissions!
|
||||||
|
* Otherwise it is possible that a moderator can transfer his
|
||||||
|
* permissions from one forum to another forum, where he has no permissions. */
|
||||||
|
if (isset($_POST['post']) && is_numeric($_POST['post']))
|
||||||
|
{
|
||||||
|
$postId = intval($_POST['post']);
|
||||||
|
$moderatorUserIds = $this->getModeratorUserIdsByPostId($postId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if user has moderator permissions for this thread
|
// Check if user has moderator permissions for this thread
|
||||||
if(!in_array(USERID, array_keys($modArray)))
|
if(!in_array(USERID, $moderatorUserIds))
|
||||||
{
|
{
|
||||||
$ret['msg'] = ''.LAN_FORUM_8030.' '. json_encode($_POST);
|
$ret['msg'] = ''.LAN_FORUM_8030.'';
|
||||||
$ret['hide'] = false;
|
$ret['hide'] = false;
|
||||||
$ret['status'] = 'error';
|
$ret['status'] = 'error';
|
||||||
}
|
}
|
||||||
@@ -414,7 +521,7 @@ class e107forum
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'deletepost':
|
case 'deletepost':
|
||||||
if(!$postId = vartrue($_POST['post']))
|
if(!$postId)
|
||||||
{
|
{
|
||||||
// echo "No Post";
|
// echo "No Post";
|
||||||
// exit;
|
// exit;
|
||||||
@@ -2420,27 +2527,24 @@ class e107forum
|
|||||||
* Delete a Post
|
* Delete a Post
|
||||||
* @param $postId integer
|
* @param $postId integer
|
||||||
* @param $updateCounts boolean
|
* @param $updateCounts boolean
|
||||||
*
|
* @return "null" if this post does not exist, "true" if post could deleted, otherwise "false"
|
||||||
*/
|
*/
|
||||||
function postDelete($postId, $updateCounts = true)
|
function postDelete($postId, $updateCounts = true)
|
||||||
{
|
{
|
||||||
$postId = (int)$postId;
|
$postId = (int)$postId;
|
||||||
$e107 = e107::getInstance();
|
|
||||||
$sql = e107::getDb();
|
$sql = e107::getDb();
|
||||||
$deleted = false;
|
$deleted = false;
|
||||||
|
|
||||||
$postInfo = $sql->retrieve('forum_post', '*', 'post_id = '.$postId);
|
$postInfo = $sql->retrieve('forum_post', '*', 'post_id = '.$postId);
|
||||||
//if(!$sql->select('forum_post', '*', 'post_id = '.$postId))
|
|
||||||
if(!is_array($postInfo) || empty($postInfo))
|
if(!is_array($postInfo) || empty($postInfo))
|
||||||
{
|
{
|
||||||
echo 'NOT FOUND!'; return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$row = $sql->fetch();
|
|
||||||
|
|
||||||
//delete attachments if they exist
|
//delete attachments if they exist
|
||||||
if($row['post_attachments'])
|
if($postInfo['post_attachments'])
|
||||||
{
|
{
|
||||||
$this->postDeleteAttachments('post', $postId);
|
$this->postDeleteAttachments('post', $postId);
|
||||||
}
|
}
|
||||||
@@ -2456,24 +2560,24 @@ class e107forum
|
|||||||
if($updateCounts)
|
if($updateCounts)
|
||||||
{
|
{
|
||||||
// decrement user post counts
|
// decrement user post counts
|
||||||
if ($row['post_user'])
|
if ($postInfo['post_user'])
|
||||||
{
|
{
|
||||||
$sql->update('user_extended', 'user_plugin_forum_posts=GREATEST(user_plugin_forum_posts-1,0) WHERE user_extended_id='.$row['post_user']);
|
$sql->update('user_extended', 'user_plugin_forum_posts=GREATEST(user_plugin_forum_posts-1,0) WHERE user_extended_id='.$postInfo['post_user']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// update thread with correct reply counts
|
// update thread with correct reply counts
|
||||||
$sql->update('forum_thread', "thread_total_replies=GREATEST(thread_total_replies-1,0) WHERE thread_id=".$row['post_thread']);
|
$sql->update('forum_thread', "thread_total_replies=GREATEST(thread_total_replies-1,0) WHERE thread_id=".$postInfo['post_thread']);
|
||||||
|
|
||||||
// update forum with correct thread/reply counts
|
// update forum with correct thread/reply counts
|
||||||
$sql->update('forum', "forum_replies=GREATEST(forum_replies-1,0) WHERE forum_id=".$row['post_forum']);
|
$sql->update('forum', "forum_replies=GREATEST(forum_replies-1,0) WHERE forum_id=".$postInfo['post_forum']);
|
||||||
|
|
||||||
// update thread lastpost info
|
// update thread lastpost info
|
||||||
$this->forumUpdateLastpost('thread', $row['post_thread']);
|
$this->forumUpdateLastpost('thread', $postInfo['post_thread']);
|
||||||
|
|
||||||
// update forum lastpost info
|
// update forum lastpost info
|
||||||
$this->forumUpdateLastpost('forum', $row['post_forum']);
|
$this->forumUpdateLastpost('forum', $postInfo['post_forum']);
|
||||||
}
|
}
|
||||||
return $deleted; // return boolean. $threadInfo['thread_total_replies'];
|
return $deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -66,8 +66,9 @@ class forum_post_handler
|
|||||||
$this->id = (int) $_GET['id']; // forum thread/topic id.
|
$this->id = (int) $_GET['id']; // forum thread/topic id.
|
||||||
$this->post = (int) $_GET['post']; // post ID if needed.
|
$this->post = (int) $_GET['post']; // post ID if needed.
|
||||||
|
|
||||||
define('MODERATOR', USER && $this->forumObj->isModerator(USERID));
|
|
||||||
|
|
||||||
|
$moderatorUserIds = $forum->getModeratorUserIdsByPostId($this->post);
|
||||||
|
define('MODERATOR', (USER && in_array(USERID, $moderatorUserIds)));
|
||||||
|
|
||||||
|
|
||||||
$this->data = $this->processGet();
|
$this->data = $this->processGet();
|
||||||
|
@@ -200,21 +200,15 @@ if(!empty($forumInfo['forum_description']))
|
|||||||
), 250, '...'));
|
), 250, '...'));
|
||||||
}
|
}
|
||||||
|
|
||||||
//define('MODERATOR', $forum_info['forum_moderators'] != '' && check_class($forum_info['forum_moderators']));
|
$moderatorUserIds = $forum->getModeratorUserIdsByForumId($forumId);
|
||||||
//$modArray = $forum->forum_getmods($forum_info['forum_moderators']);
|
define('MODERATOR', (USER && in_array(USERID, $moderatorUserIds)));
|
||||||
|
|
||||||
// $thread???
|
|
||||||
$modArray = $forum->forumGetMods($thread->forum_info['forum_moderators']);
|
|
||||||
define('MODERATOR', (USER && is_array($modArray) && in_array(USERID, array_keys($modArray))));
|
|
||||||
|
|
||||||
//----$message = '';
|
|
||||||
if (MODERATOR)
|
if (MODERATOR)
|
||||||
{
|
{
|
||||||
if ($_POST)
|
if ($_POST)
|
||||||
{
|
{
|
||||||
require_once(e_PLUGIN.'forum/forum_mod.php');
|
require_once(e_PLUGIN.'forum/forum_mod.php');
|
||||||
//-- $message = forum_thread_moderate($_POST);
|
$forumSCvars['message'] = forum_thread_moderate($_POST);
|
||||||
$forumSCvars['message']=forum_thread_moderate($_POST);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -69,6 +69,24 @@ if(vartrue($_GET['id']) && isset($_GET['dl']))
|
|||||||
exit;
|
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(e_AJAX_REQUEST)
|
||||||
{
|
{
|
||||||
if(varset($_POST['action']) == 'quickreply')
|
if(varset($_POST['action']) == 'quickreply')
|
||||||
@@ -85,23 +103,13 @@ if(e_AJAX_REQUEST)
|
|||||||
{
|
{
|
||||||
$forum->ajaxModerate();
|
$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']))
|
if(isset($_POST['track_toggle']))
|
||||||
{
|
{
|
||||||
@@ -142,8 +150,9 @@ if (USER && (USERID != $thread->threadInfo['thread_user'] || $thread->threadInfo
|
|||||||
}
|
}
|
||||||
|
|
||||||
define('e_PAGETITLE', strip_tags($tp->toHTML($thread->threadInfo['thread_name'], true, 'no_hook, emotes_off')).' / '.$tp->toHTML($thread->threadInfo['forum_name'], true, 'no_hook, emotes_off').' / '.LAN_FORUM_1001);
|
define('e_PAGETITLE', strip_tags($tp->toHTML($thread->threadInfo['thread_name'], true, 'no_hook, emotes_off')).' / '.$tp->toHTML($thread->threadInfo['forum_name'], true, 'no_hook, emotes_off').' / '.LAN_FORUM_1001);
|
||||||
|
|
||||||
$forum->modArray = $forum->forumGetMods($thread->threadInfo['forum_moderators']);
|
$forum->modArray = $forum->forumGetMods($thread->threadInfo['forum_moderators']);
|
||||||
define('MODERATOR', (USER && $forum->isModerator(USERID)));
|
|
||||||
|
|
||||||
e107::getScBatch('view', 'forum')->setScVar('forum', $forum);
|
e107::getScBatch('view', 'forum')->setScVar('forum', $forum);
|
||||||
//var_dump(e107::getScBatch('forum', 'forum'));
|
//var_dump(e107::getScBatch('forum', 'forum'));
|
||||||
@@ -481,6 +490,8 @@ $i = $thread->page;
|
|||||||
$sc->wrapper('forum_viewtopic/end');
|
$sc->wrapper('forum_viewtopic/end');
|
||||||
$forend = $tp->parseTemplate($FORUMEND, true, $sc);
|
$forend = $tp->parseTemplate($FORUMEND, true, $sc);
|
||||||
|
|
||||||
|
$lastPostDetectionCounter = count($postList);
|
||||||
|
$sc->setScVar('thisIsTheLastPost', false);
|
||||||
|
|
||||||
foreach ($postList as $c => $postInfo)
|
foreach ($postList as $c => $postInfo)
|
||||||
{
|
{
|
||||||
@@ -490,6 +501,9 @@ foreach ($postList as $c => $postInfo)
|
|||||||
}
|
}
|
||||||
$loop_uid = (int)$postInfo['post_user'];
|
$loop_uid = (int)$postInfo['post_user'];
|
||||||
|
|
||||||
|
$lastPostDetectionCounter--;
|
||||||
|
if ($lastPostDetectionCounter == 0) $sc->setScVar('thisIsTheLastPost', true);
|
||||||
|
|
||||||
//---- Orphan $tnum????
|
//---- Orphan $tnum????
|
||||||
$tnum = $i;
|
$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'))
|
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'];
|
$url = e107::url('forum', 'post') . "?f=quote&id=" . $this->postInfo['post_thread'] . "&post=" . $this->postInfo['post_id'];
|
||||||
@@ -889,7 +900,7 @@
|
|||||||
// if(!$this->forum->threadDetermineInitialPost($this->postInfo['post_id']))
|
// if(!$this->forum->threadDetermineInitialPost($this->postInfo['post_id']))
|
||||||
if(empty($this->postInfo['thread_start']))
|
if(empty($this->postInfo['thread_start']))
|
||||||
{
|
{
|
||||||
$text .= "<li class='text-right'><a href='" . e_REQUEST_URI . "' data-forum-action='deletepost' data-forum-thread='" . $this->postInfo['post_thread'] . "' data-forum-post='" . $this->postInfo['post_id'] . "'>" . LAN_DELETE . " " . $tp->toGlyph('trash') . "</a></li>";
|
$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($type == 'thread')
|
if($type == 'thread')
|
||||||
|
@@ -971,18 +971,18 @@
|
|||||||
|
|
||||||
function sc_adminoptions()
|
function sc_adminoptions()
|
||||||
{
|
{
|
||||||
/*--
|
|
||||||
if(!deftrue('BOOTSTRAP'))
|
if(!deftrue('BOOTSTRAP'))
|
||||||
{
|
{
|
||||||
return $this->sc_admin_icons;
|
return $this->sc_admin_icons();
|
||||||
}
|
}
|
||||||
if (MODERATOR)
|
else if (MODERATOR)
|
||||||
{
|
{
|
||||||
return fadminoptions($this->var);
|
return fadminoptions($this->var);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return '';
|
return '';
|
||||||
--*/
|
}
|
||||||
return (!deftrue('BOOTSTRAP') ? $this->sc_admin_icons() : ((MODERATOR) ? fadminoptions($this->var) : ''));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user