1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 20:00:37 +02:00

Forum changes...trying to make it much more OO, will probably be lots of breakage.

This commit is contained in:
mcfly
2009-09-06 04:30:46 +00:00
parent 01c5c94475
commit 4177c1607b
9 changed files with 1814 additions and 389 deletions

View File

@@ -9,24 +9,27 @@
* Message Handler
*
* $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_class.php,v $
* $Revision: 1.38 $
* $Date: 2009-01-25 17:44:13 $
* $Revision: 1.39 $
* $Date: 2009-09-06 04:30:46 $
* $Author: mcfly_e107 $
*
*/
if (!defined('e107_INIT')) { exit; }
class e107forum
class plugin_forum_forumClass
{
var $permList = array();
var $fieldTypes = array();
var $userViewed = array();
var $modArray = array();
var $e107;
private $threadList = array();
private $postList = array();
function e107forum()
function __construct()
{
$this->e107 = e107::getInstance();
$this->loadPermList();
$this->fieldTypes['forum_post']['post_user'] = 'int';
$this->fieldTypes['forum_post']['post_forum'] = 'int';
@@ -49,21 +52,20 @@ class e107forum
$this->fieldTypes['forum_thread']['thread_options'] = 'escape';
$this->fieldTypes['forum']['forum_lastpost_user'] = 'int';
$this->e107 = e107::getInstance();
}
function loadPermList()
{
global $e107;
if($tmp = $e107->ecache->retrieve_sys('forum_perms'))
// var_dump($this->e107);
if($tmp = $this->e107->ecache->retrieve_sys('forum_perms'))
{
$this->permList = $e107->arrayStorage->ReadArray($tmp);
}
else
{
$this->getForumPermList();
$tmp = $e107->arrayStorage->WriteArray($this->permList, false);
$e107->ecache->set_sys('forum_perms', $tmp);
$tmp = $this->e107->arrayStorage->WriteArray($this->permList, false);
$this->e107->ecache->set_sys('forum_perms', $tmp);
}
unset($tmp);
@@ -72,26 +74,24 @@ class e107forum
function getForumPermList()
{
global $e107;
$this->permList = array();
$qryList = array();
$qryList[view] = "
$qryList['view'] = "
SELECT f.forum_id
FROM `#forum` AS f
LEFT JOIN `#forum` AS fp ON f.forum_parent = fp.forum_id AND fp.forum_class IN (".USERCLASS_LIST.")
WHERE f.forum_class IN (".USERCLASS_LIST.") AND f.forum_parent != 0 AND fp.forum_id IS NOT NULL
";
$qryList[post] = "
$qryList['post'] = "
SELECT f.forum_id
FROM `#forum` AS f
LEFT JOIN `#forum` AS fp ON f.forum_parent = fp.forum_id AND fp.forum_postclass IN (".USERCLASS_LIST.")
WHERE f.forum_postclass IN (".USERCLASS_LIST.") AND f.forum_parent != 0 AND fp.forum_id IS NOT NULL
";
$qryList[thread] = "
$qryList['thread'] = "
SELECT f.forum_id
FROM `#forum` AS f
LEFT JOIN `#forum` AS fp ON f.forum_parent = fp.forum_id AND fp.forum_threadclass IN (".USERCLASS_LIST.")
@@ -100,9 +100,9 @@ class e107forum
foreach($qryList as $key => $qry)
{
if($e107->sql->db_Select_gen($qry))
if($this->e107->sql->db_Select_gen($qry))
{
while($row = $e107->sql->db_Fetch(MYSQL_ASSOC))
while($row = $this->e107->sql->db_Fetch())
{
$this->permList[$key][] = $row['forum_id'];
}
@@ -110,19 +110,36 @@ class e107forum
}
}
/**
* Test for forum permissions.
*
* 'view' - user is able to view forumId
* 'post' - user is able to create new post in forumId
* 'thread' - user is able to create new thread in forumId
*
* @param integer $forumId
* @param string $type (view, post, thread)
* @return boolean
*/
function checkPerm($forumId, $type='view')
{
return (in_array($forumId, $this->permList[$type]));
}
/**
* Check to see of thread has been viewed by current user
*
*
* @param integer $threadId
* @return boolean
*/
function threadViewed($threadId)
{
$e107 = e107::getInstance();
if(!$this->userViewed)
{
if(isset($e107->currentUser['user_plugin_forum_viewed']))
if(isset($this->e107->currentUser['user_plugin_forum_viewed']))
{
$this->userViewed = explode(',', $e107->currentUser['user_plugin_forum_viewed']);
$this->userViewed = explode(',', $this->e107->currentUser['user_plugin_forum_viewed']);
}
}
return (is_array($this->userViewed) && in_array($threadId, $this->userViewed));
@@ -130,11 +147,10 @@ class e107forum
function getTrackedThreadList($id, $retType = 'array')
{
$e107 = e107::getInstance();
$id = (int)$id;
if($e107->sql->db_Select('forum_track', 'track_thread', 'track_userid = '.$id))
if($this->e107->sql->db_Select('forum_track', 'track_thread', 'track_userid = '.$id))
{
while($row = $e107->sql->db_Fetch(MYSQL_ASSOC))
while($row = $this->e107->sql->db_Fetch())
{
$ret[] = $row['track_thread'];
}
@@ -151,16 +167,14 @@ class e107forum
*/
function postAdd($postInfo, $updateThread = true, $updateForum = true)
{
// var_dump($postInfo);
//Future option, will just set to true here
$addUserPostCount = true;
$result = false;
$e107 = e107::getInstance();
$info = array();
$info['_FIELD_TYPES'] = $this->fieldTypes['forum_post'];
$info['data'] = $postInfo;
$postId = $e107->sql->db_Insert('forum_post', $info);
$postId = $this->e107->sql->db_Insert('forum_post', $info);
$forumInfo = array();
if($postId && $updateThread)
@@ -189,7 +203,7 @@ class e107forum
$info['_FIELD_TYPES'] = $this->fieldTypes['forum_thread'];
$info['_FIELD_TYPES']['thread_total_replies'] = 'cmd';
$result = $e107->sql->db_Update('forum_thread', $info);
$result = $this->e107->sql->db_Update('forum_thread', $info);
}
@@ -222,7 +236,7 @@ class e107forum
$info['data'] = $forumInfo;
$info['data']['forum_lastpost_info'] = $postInfo['post_datestamp'].'.'.$postInfo['post_thread'];
$info['WHERE'] = 'forum_id = '.$postInfo['post_forum'];
$result = $e107->sql->db_Update('forum', $info);
$result = $this->e107->sql->db_Update('forum', $info);
}
if($result && USER && $addUserPostCount)
@@ -232,18 +246,17 @@ class e107forum
VALUES ('.USERID.', 1)
ON DUPLICATE KEY UPDATE user_plugin_forum_posts = user_plugin_forum_posts + 1
';
$result = $e107->sql->db_Select_gen($qry);
$result = $this->e107->sql->db_Select_gen($qry);
}
return $postId;
}
function threadAdd($threadInfo, $postInfo)
{
$e107 = e107::getInstance();
$info = array();
$info['_FIELD_TYPES'] = $this->fieldTypes['forum_thread'];
$info['data'] = $threadInfo;
if($newThreadId = $e107->sql->db_Insert('forum_thread', $info))
if($newThreadId = $this->e107->sql->db_Insert('forum_thread', $info))
{
$postInfo['post_thread'] = $newThreadId;
$newPostId = $this->postAdd($postInfo, false);
@@ -255,34 +268,30 @@ class e107forum
function threadUpdate($threadId, $threadInfo)
{
$e107 = e107::getInstance();
$info = array();
$info['data'] = $threadInfo;
$info['_FIELD_TYPES'] = $this->fieldTypes['forum_thread'];
$info['WHERE'] = 'thread_id = '.(int)$threadId;
$e107->sql->db_Update('forum_thread', $info);
$this->e107->sql->db_Update('forum_thread', $info);
}
function postUpdate($postId, $postInfo)
{
$e107 = e107::getInstance();
$info = array();
$info['data'] = $postInfo;
$info['_FIELD_TYPES'] = $this->fieldTypes['forum_post'];
$info['WHERE'] = 'post_id = '.(int)$postId;
$e107->sql->db_Update('forum_post', $info);
$this->e107->sql->db_Update('forum_post', $info);
}
function threadGet($id, $joinForum = true, $uid = USERID)
{
global $pref;
$e107 = e107::getInstance();
$id = (int)$id;
$uid = (int)$uid;
if($joinForum)
{
//TODO: Fix query to get only forum and parent info needed, with correct naming
// TODO: Fix query to get only forum and parent info needed, with correct naming
$qry = '
SELECT t.*, f.*,
fp.forum_id as parent_id, fp.forum_name as parent_name,
@@ -302,9 +311,9 @@ class e107forum
FROM `#forum_thread`
WHERE thread_id = '.$id;
}
if($e107->sql->db_Select_gen($qry))
if($this->e107->sql->db_Select_gen($qry))
{
$tmp = $e107->sql->db_Fetch(MYSQL_ASSOC);
$tmp = $this->e107->sql->db_Fetch();
if($tmp)
{
if(trim($tmp['thread_options']) != '')
@@ -321,7 +330,6 @@ class e107forum
{
$id = (int)$id;
$ret = false;
$e107 = e107::getInstance();
if('post' === $start)
{
$qry = '
@@ -346,10 +354,10 @@ class e107forum
LIMIT {$start}, {$num}
";
}
if($e107->sql->db_Select_gen($qry))
if($this->e107->sql->db_Select_gen($qry))
{
$ret = array();
while($row = $e107->sql->db_Fetch(MYSQL_ASSOC))
while($row = $this->e107->sql->db_Fetch())
{
$ret[] = $row;
}
@@ -362,17 +370,16 @@ class e107forum
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))
if($this->e107->sql->db_Select_gen($qry))
{
$ret = array();
while($row = $e107->sql->db_Fetch(MYSQL_ASSOC))
while($row = $this->e107->sql->db_Fetch())
{
$ret[$row['post_user']] = $row['post_count'];
}
@@ -382,10 +389,9 @@ class e107forum
function threadGetUserViewed($uid = USERID)
{
$e107 = e107::getInstance();
if($uid == USERID)
{
$viewed = $e107->currentUser['user_plugin_forum_viewed'];
$viewed = $this->e107->currentUser['user_plugin_forum_viewed'];
}
else
{
@@ -505,7 +511,7 @@ class e107forum
{
if ($sql->db_Select('forum', 'forum_id', 'forum_parent != 0'))
{
while ($row = $sql->db_Fetch(MYSQL_ASSOC))
while ($row = $sql->db_Fetch())
{
$parentList[] = $row['forum_id'];
}
@@ -635,7 +641,7 @@ class e107forum
}
return $this->modArray;
}
function isModerator($uid)
{
return ($uid && in_array($uid, array_keys($this->modArray)));
@@ -857,8 +863,10 @@ class e107forum
function forumGetThreads($forumId, $from, $view)
{
$e107 = e107::getInstance();
$forumId = (int)$forumId;
$from = (int)$from;
$view = (int)$view;
$qry = "
SELECT t.*, u.user_name, lpu.user_name AS lastpost_username from `#forum_thread` as t
LEFT JOIN `#user` AS u ON t.thread_user = u.user_id
@@ -867,17 +875,18 @@ class e107forum
ORDER BY
t.thread_sticky DESC,
t.thread_lastpost DESC
LIMIT ".(int)$from.','.(int)$view;
LIMIT {$from},{$view}";
$ret = array();
if ($e107->sql->db_Select_gen($qry))
$this->threadList = array();
if ($this->e107->sql->db_Select_gen($qry))
{
while ($row = $e107->sql->db_Fetch(MYSQL_ASSOC))
while ($row = $this->e107->sql->db_Fetch())
{
$ret[] = $row;
$this->threadList = $row;
}
return true;
}
return $ret;
return false;
}
function threadGetLastpost($id)
@@ -1218,12 +1227,11 @@ class e107forum
function postDelete($postId, $updateCounts = true)
{
$postId = (int)$postId;
$e107 = e107::getInstance();
if(!$e107->sql->db_Select('forum_post', '*', 'post_id = '.$postId))
if(!$e107->sql->db_Select('forum_post', 'post_user, post_forum, post_thread', 'post_id = '.$postId))
{
echo 'NOT FOUND!'; return;
}
$row = $e107->sql->db_Fetch(MYSQL_ASSOC);
$row = $this->e107->sql->db_Fetch();
//delete attachments if they exist
if($row['post_attachments'])
@@ -1232,21 +1240,21 @@ class e107forum
}
// delete post
$e107->sql->db_Delete('forum_post', 'post_id='.$postId);
$this->e107->sql->db_Delete('forum_post', 'post_id='.$postId);
if($updateCounts)
{
//decrement user post counts
if ($row['post_user'])
{
$e107->sql->db_Update('user_extended', 'user_plugin_forum_posts=GREATEST(user_plugin_forum_posts-1,0) WHERE user_id='.$row['post_user']);
$this->e107->sql->db_Update('user_extended', 'user_plugin_forum_posts=GREATEST(user_plugin_forum_posts-1,0) WHERE user_id='.$row['post_user']);
}
// update thread with correct reply counts
$e107->sql->db_Update('forum_thread', "thread_total_replies=GREATEST(thread_total_replies-1,0) WHERE thread_id=".$row['post_thread']);
$this->e107->sql->db_Update('forum_thread', "thread_total_replies=GREATEST(thread_total_replies-1,0) WHERE thread_id=".$row['post_thread']);
// update forum with correct thread/reply counts
$e107->sql->db_Update('forum', "forum_replies=GREATEST(forum_replies-1,0) WHERE forum_id=".$row['post_forum']);
$this->e107->sql->db_Update('forum', "forum_replies=GREATEST(forum_replies-1,0) WHERE forum_id=".$row['post_forum']);
// update thread lastpost info
$this->forumUpdateLastpost('thread', $row['post_thread']);