1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-03 05:07:27 +02:00

Some moderator functions now working, last post info and user post count should be accurate. Other fixes.

This commit is contained in:
mcfly
2008-12-09 21:46:14 +00:00
parent ceaae186e6
commit 3cf2171b31
7 changed files with 175 additions and 167 deletions

View File

@@ -1,11 +1,11 @@
<?php
// $Id: forum.php,v 1.1 2008-12-02 00:33:29 secretr Exp $
// $Id: forum.php,v 1.2 2008-12-09 21:46:14 mcfly_e107 Exp $
function url_forum_forum($parms)
{
switch($parms['func'])
{
case 'view':
return e_PLUGIN_ABS."forum/viewforum.php?id={$parms['id']}";
return e_PLUGIN_ABS."forum/forum_viewforum.php?id={$parms['id']}";
break;
case 'track':

View File

@@ -11,8 +11,8 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum.php,v $
| $Revision: 1.8 $
| $Date: 2008-12-05 01:30:56 $
| $Revision: 1.9 $
| $Date: 2008-12-09 21:46:14 $
| $Author: mcfly_e107 $
+----------------------------------------------------------------------------+
*/
@@ -299,14 +299,16 @@ function parse_forum($f, $restricted_string = "")
$NEWFLAG = IMAGE_nonew;
}
if(substr($f['forum_name'], 0, 1) == "*")
if(substr($f['forum_name'], 0, 1) == '*')
{
$f['forum_name'] = substr($f['forum_name'], 1);
}
$f['forum_name'] = $tp -> toHTML($f['forum_name'], TRUE, "no_hook");
$f['forum_description'] = $tp -> toHTML($f['forum_description'], TRUE, "no_hook");
$f['forum_name'] = $tp -> toHTML($f['forum_name'], TRUE, 'no_hook');
$f['forum_description'] = $tp -> toHTML($f['forum_description'], TRUE, 'no_hook');
$FORUMNAME = "<a href='".e_PLUGIN."forum/viewforum.php?id={$f['forum_id']}'>{$f['forum_name']}</a>";
// $e107->url->getUrl('forum', 'thread', array('func' => 'track')))
$FORUMNAME = "<a href='".$e107->url->getUrl('forum', 'forum', "func=view&id={$f['forum_id']}")."'>{$f['forum_name']}</a>";
$FORUMDESCRIPTION = $f['forum_description'].($restricted_string ? "<br /><span class='smalltext'><i>$restricted_string</i></span>" : "");
$THREADS = $f['forum_threads'];
$REPLIES = $f['forum_replies'];
@@ -389,7 +391,12 @@ if (e_QUERY == 'track')
// $sql2 = new db;
// $tmp = explode("-", USERREALM);
$qry = "SELECT * from `#forum_thread` WHERE thread_id IN({$trackedThreadList}) ORDER BY thread_lastpost DESC";
$qry = "
SELECT t.*, p.* from `#forum_thread` AS t
LEFT JOIN `#forum_post` AS p ON p.post_thread = t.thread_id AND p.post_datestamp = t.thread_datestamp
WHERE thread_id IN({$trackedThreadList})
ORDER BY thread_lastpost DESC
";
if($e107->sql->db_Select_gen($qry))
{
while($row = $e107->sql->db_Fetch(MYSQL_ASSOC))

View File

@@ -11,8 +11,8 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_class.php,v $
| $Revision: 1.20 $
| $Date: 2008-12-07 04:16:38 $
| $Revision: 1.21 $
| $Date: 2008-12-09 21:46:14 $
| $Author: mcfly_e107 $
+----------------------------------------------------------------------------+
*/
@@ -186,13 +186,13 @@ class e107forum
$threadInfo['_FIELD_TYPES'] = $this->fieldTypes['forum_thread'];
$threadInfo['_FIELD_TYPES']['thread_total_replies'] = 'cmd';
// print_a($threadInfo);
// var_dump($threadInfo);
// exit;
$result = $e107->sql->db_Update('forum_thread', $threadInfo);
}
if($result && $updateForum)
if(($result || !$updateThread) && $updateForum)
{
if(varset($postInfo['post_user']))
{
@@ -232,7 +232,6 @@ class e107forum
$result = $e107->sql->db_Select_gen($qry);
}
return $postId;
}
function threadAdd($threadInfo, $postInfo)
@@ -322,6 +321,29 @@ class e107forum
return $ret;
}
function threadGetUserPostcount($threadId)
{
$threadId = (int)$threadId;
$e107 = e107::getInstance();
$ret = false;
$qry = "
SELECT post_user, count(post_user) AS post_count FROM `#forum_post`
WHERE post_thread = {$threadId} AND post_user IS NOT NULL
GROUP BY post_user
";
if($e107->sql->db_Select_gen($qry))
{
$ret = array();
while($row = $e107->sql->db_Fetch(MYSQL_ASSOC))
{
$ret[$row['post_user']] = $row['post_count'];
}
}
return $ret;
}
function thread_postnum($thread_id)
{
global $sql;
@@ -343,7 +365,7 @@ class e107forum
return $ret;
}
function update_lastpost($type, $id, $update_threads = FALSE)
function forumUpdateLastpost($type, $id, $update_threads = FALSE)
{
global $sql, $tp;
$sql2 = new db;
@@ -385,10 +407,10 @@ class e107forum
}
else
{
$id = intval($id);
$forum_lp_user = '';
$forum_lp_info = '';
if($update_threads == TRUE)
$id = (int)$id;
$lp_info = '';
$lp_user = 'NULL';
if($update_threads == true)
{
if ($sql2->db_Select('forum_t', 'thread_id', "thread_forum_id = $id AND thread_parent = 0"))
{
@@ -398,15 +420,20 @@ class e107forum
}
}
}
if ($sql->db_Select("forum_t", "*", "thread_forum_id={$id} ORDER BY thread_datestamp DESC LIMIT 0,1"))
if ($sql->db_Select('forum_thread', 'thread_id, thread_lastuser, thread_lastuser_anon, thread_datestamp', 'thread_forum_id='.$id.' ORDER BY thread_datestamp DESC LIMIT 1'))
{
$row = $sql->db_Fetch(MYSQL_ASSOC);
$tmp = explode(chr(1), $row['thread_user']);
$forum_lp_user = $tmp[0];
$last_id = $row['thread_parent'] ? $row['thread_parent'] : $row['thread_id'];
$forum_lp_info = $row['thread_datestamp'].".".$last_id;
$lp_info = $row['thread_datestamp'].'.'.$row['thread_id'];
$lp_user = $row['thread_lastuser'];
}
if($row['thread_lastuser_anon'])
{
$sql->db_Update('forum', "forum_lastpost_user = 0, forum_lastpost_anon = '{$row['thread_lastuser_anon']}', forum_lastpost_info = '{$lp_info}' WHERE forum_id=".$id);
}
else
{
$sql->db_Update('forum', "forum_lastpost_user = {$lp_user}, forum_lastpost_user_anon = NULL, forum_lastpost_info = '{$lp_info}' WHERE forum_id=".$id);
}
$sql->db_Update('forum', "forum_lastpost_user = '{$forum_lp_user}', forum_lastpost_info = '{$forum_lp_info}' WHERE forum_id={$id}");
}
}
}

View File

@@ -11,49 +11,54 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_mod.php,v $
| $Revision: 1.2 $
| $Date: 2007-08-14 21:11:29 $
| $Author: e107steved $
| $Revision: 1.3 $
| $Date: 2008-12-09 21:46:14 $
| $Author: mcfly_e107 $
+----------------------------------------------------------------------------+
*/
if (!defined('e107_INIT')) { exit; }
@include_once e_PLUGIN.'forum/languages/'.e_LANGUAGE.'/lan_forum_admin.php';
@include_once e_PLUGIN.'forum/languages/English/lan_forum_admin.php';
if (!defined('e107_INIT'))
{
exit;
}
include_lan(e_PLUGIN.'forum/languages/English/lan_forum_admin.php');
function forum_thread_moderate($p)
{
// var_dump($_POST);
// return;
$e107 = e107::getInstance();
global $sql;
foreach($p as $key => $val) {
foreach ($p as $key => $val)
{
if (preg_match("#(.*?)_(\d+)_x#", $key, $matches))
{
$act = $matches[1];
$id = intval($matches[2]);
$id = (int)$matches[2];
switch($act)
switch ($act)
{
case 'lock' :
$sql->db_Update("forum_t", "thread_active='0' WHERE thread_id='$id' ");
case 'lock':
$e107->sql->db_Update('forum_thread', 'thread_active=0 WHERE thread_id='.$id);
return FORLAN_CLOSE;
break;
case 'unlock' :
$sql->db_Update("forum_t", "thread_active='1' WHERE thread_id='$id' ");
case 'unlock':
$e107->sql->db_Update('forum_thread', 'thread_active=1 WHERE thread_id='.$id);
return FORLAN_OPEN;
break;
case 'stick' :
$sql->db_Update("forum_t", "thread_s='1' WHERE thread_id='$id' ");
case 'stick':
$e107->sql->db_Update('forum_thread', 'thread_s=1 WHERE thread_id='.$id);
return FORLAN_STICK;
break;
case 'unstick' :
$sql->db_Update("forum_t", "thread_s='0' WHERE thread_id='$id' ");
case 'unstick':
$e107->sql->db_Update('forum_thread', 'thread_s=0 WHERE thread_id='.$id);
return FORLAN_UNSTICK;
break;
case 'delete' :
return forum_delete_thread($id);
case 'deleteThread':
return forumDeleteThread($id);
break;
}
@@ -61,82 +66,41 @@ function forum_thread_moderate($p)
}
}
function forum_delete_thread($thread_id)
function forumDeleteThread($threadId)
{
global $sql;
@require_once(e_PLUGIN.'forum/forum_class.php');
$f =& new e107forum;
$sql->db_Select("forum_t", "*", "thread_id='".intval($thread_id)."' ");
$row = $sql->db_Fetch();
if ($row['thread_parent'])
require_once (e_PLUGIN.'forum/forum_class.php');
$e107 = e107::getInstance();
$f = &new e107forum;
if ($threadInfo = $f->threadGet($threadId))
{
// post is a reply?
$sql->db_Delete("forum_t", "thread_id='".intval($thread_id)."' ");
// dec forum reply count by 1
$sql->db_Update("forum", "forum_replies=forum_replies-1 WHERE forum_id='".$row['thread_forum_id']."' AND forum_replies>0");
// dec thread reply count by 1
$sql->db_Update("forum_t", "thread_total_replies=thread_total_replies-1 WHERE thread_id='".$row['thread_parent']."' AND thread_total_replies>0");
// dec user forum post count by 1
$tmp = explode(".", $row['thread_user']);
$uid = intval($tmp[0]);
if($uid > 0)
{
$sql->db_Update("user", "user_forums=user_forums-1 WHERE user_id='".$uid."' AND user_forums>0");
}
// update lastpost info
$f->update_lastpost('thread', $row['thread_parent']);
$f->update_lastpost('forum', $row['thread_forum_id']);
return FORLAN_154;
}
else
{
// post is thread
// delete poll if there is one
$sql->db_Delete("poll", "poll_datestamp='".intval($thread_id)."'");
$e107->sql->db_Delete('poll', 'poll_datestamp='.$threadId);
//decrement user post counts
forum_userpost_count("WHERE thread_id = '".intval($thread_id)."' OR thread_parent = '".intval($thread_id)."'", "dec");
// delete replies and grab how many there were
$count = $sql->db_Delete("forum_t", "thread_parent='".intval($thread_id)."'");
// delete the post itself
$sql->db_Delete("forum_t", "thread_id='".intval($thread_id)."'");
// update thread/reply counts
$sql->db_Update("forum", "forum_threads=LEAST(forum_threads-1,0), forum_replies=LEAST(forum_replies-{$count},0) WHERE forum_id='".$row['thread_forum_id']."'");
if ($postCount = $f->threadGetUserPostcount($threadId))
{
foreach ($postCount as $k => $v)
{
$e107->sql->db_Update('user_extended', 'user_plugin_forum_posts=GREATEST(user_plugin_forum_posts-'.$v.',0) WHERE user_id='.$k);
}
}
// delete all posts
$e107->sql->db_Delete('forum_post', 'post_thread='.$threadId);
// delete the thread itself
$e107->sql->db_Delete('forum_thread', 'thread_id='.$threadId);
//Delete any thread tracking
$e107->sql->db_Delete('forum_track', 'track_thread='.$threadId);
// update forum with correct thread/reply counts
$e107->sql->db_Update('forum', "forum_threads=GREATEST(forum_threads-1,0), forum_replies=GREATEST(forum_replies-{$threadInfo['thread_total_replies']},0) WHERE forum_id=".$threadInfo['thread_forum_id']);
// update lastpost info
$f->update_lastpost('forum', $row['thread_forum_id']);
return FORLAN_6.($count ? ", ".$count." ".FORLAN_7."." : ".");
$f->forumUpdateLastpost('forum', $threadInfo['thread_forum_id']);
return FORLAN_6.' and '.$threadInfo['thread_total_replies'].' '.FORLAN_7.'.';
}
}
function forum_userpost_count($where = "", $type = "dec")
{
global $sql;
$qry = "
SELECT thread_user, count(thread_user) AS cnt FROM #forum_t
{$where}
GROUP BY thread_user
";
if($sql->db_Select_gen($qry))
{
$uList = $sql->db_getList();
foreach($uList as $u)
{
$tmp = explode(".", $u['thread_user']);
$uid = intval($tmp[0]);
if($uid > 0)
{
if("set" == $type)
{
$sql->db_Update("user", "user_forums={$u['cnt']} WHERE user_id='".$uid."'");
}
else
{ // user_forums is unsigned, so underflow will give a very big number
$sql->db_Update("user", "user_forums=LEAST(user_forums-{$u['cnt']},0) WHERE user_id='".$uid."'");
}
}
}
}
}
?>

View File

@@ -11,8 +11,8 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_post.php,v $
| $Revision: 1.26 $
| $Date: 2008-12-08 02:33:34 $
| $Revision: 1.27 $
| $Date: 2008-12-09 21:46:14 $
| $Author: mcfly_e107 $
+----------------------------------------------------------------------------+
*/
@@ -272,7 +272,7 @@ if (isset($_POST['newthread']) || isset($_POST['reply']))
// New thread started. Add the thread info (with lastest post info), add the post.
// Update forum with latest post info
case 'nt':
$threadInfo['thread_s'] = (MODERATOR ? $_POST['threadtype'] : 0);
$threadInfo['thread_s'] = (MODERATOR ? (int)$_POST['threadtype'] : 0);
$threadInfo['thread_name'] = $_POST['subject'];
$threadInfo['thread_forum_id'] = $forumId;
$threadInfo['thread_active'] = 1;
@@ -281,21 +281,26 @@ if (isset($_POST['newthread']) || isset($_POST['reply']))
{
$threadOptions['poll'] = '1';
}
if(is_array($threadOptions) && count($threadOptions))
{
$threadInfo['thread_options'] = serialize($threadOptions);
}
else
{
$threadInfo['thread_options'] = '';
}
if($postResult = $forum->threadAdd($threadInfo, $postInfo))
{
$newPostId = $postResult['postid'];
$newThreadId = $postResult['threadid'];
if($_POST['email_notify'])
{
$forum->track('add', USERID, $newThreadId);
}
}
break;
}
// $email_notify = ($_POST['email_notify'] ? 99 : 1);
// if ($_POST['poll_title'] != "" && $_POST['poll_option'][0] != "" && $_POST['poll_option'][1] != "")
// {
// $subject = "[".LAN_402."] ".$subject;
// }
// print_a($threadInfo);
// print_a($postInfo);
// exit;

View File

@@ -12,8 +12,8 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_viewtopic.php,v $
| $Revision: 1.10 $
| $Date: 2008-12-08 02:33:34 $
| $Revision: 1.11 $
| $Date: 2008-12-09 21:46:14 $
| $Author: mcfly_e107 $
+----------------------------------------------------------------------------+
*/
@@ -208,6 +208,10 @@ $i = $thread->page;
global $postInfo;
foreach ($postList as $postInfo)
{
if($postInfo['post_options'])
{
$postInfo['post_options'] = unserialize($postInfo['post_options']);
}
$loop_uid = (int)$postInfo['post_user'];
$i++;

View File

@@ -4,8 +4,8 @@
| e107 website system - Language File.
|
| $Source: /cvs_backup/e107_0.8/e107_plugins/forum/languages/English/lan_forum_viewforum.php,v $
| $Revision: 1.1.1.1 $
| $Date: 2006-12-02 04:35:18 $
| $Revision: 1.2 $
| $Date: 2008-12-09 21:46:14 $
| $Author: mcfly_e107 $
+----------------------------------------------------------------------------+
*/
@@ -90,5 +90,6 @@ define('FORLAN_19', '[user deleted]');
define('FORLAN_20', 'Sub-forum');
define('FORLAN_21', 'Threads');
define('FORLAN_22', 'Last Post');
define('FORLAN_23', 'Poll');
?>