1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-20 05:11:42 +02:00

Code clean-up (globals, $e107->, headers, $sql)

This commit is contained in:
Moc
2013-03-24 18:59:18 +01:00
parent c4197a76c0
commit afe4b27cf2
18 changed files with 305 additions and 373 deletions

View File

@@ -2,21 +2,20 @@
/*
* e107 website system
*
* Copyright (C) 2008-2011 e107 Inc (e107.org)
* Copyright (C) 2008-2013 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* Forum main page
*
* $URL$
* $Id$
*
*/
if(!defined('e107_INIT'))
{
require_once('../../class2.php');
}
$e107 = e107::getInstance();
$tp = e107::getParser();
if (!$e107->isInstalled('forum'))
{
// FIXME GLOBAL - get rid of all e_BASE|e_HTTP|Whatever/index.php - just point to SITEURL
@@ -87,15 +86,15 @@ if($rules_text != '')
{
$fVars->USERINFO .= " | <a href='".$e107->url->create('forum/forum/rules')."'>".LAN_433.'</a>';
}
$total_topics = $sql->db_Count("forum_thread", "(*)");
$total_replies = $sql->db_Count("forum_post", "(*)");
$total_members = $sql->db_Count("user");
$newest_member = $sql->db_Select("user", "*", "user_ban='0' ORDER BY user_join DESC LIMIT 0,1");
$total_topics = $sql->count("forum_thread", "(*)");
$total_replies = $sql->count("forum_post", "(*)");
$total_members = $sql->count("user");
$newest_member = $sql->select("user", "*", "user_ban='0' ORDER BY user_join DESC LIMIT 0,1");
list($nuser_id, $nuser_name) = $sql->db_Fetch();
if(!defined('e_TRACKING_DISABLED'))
{
$member_users = $sql->db_Select("online", "*", "online_location REGEXP('forum.php') AND online_user_id!='0' ");
$guest_users = $sql->db_Select("online", "*", "online_location REGEXP('forum.php') AND online_user_id='0' ");
$member_users = $sql->select("online", "*", "online_location REGEXP('forum.php') AND online_user_id!='0' ");
$guest_users = $sql->select("online", "*", "online_location REGEXP('forum.php') AND online_user_id='0' ");
$users = $member_users+$guest_users;
$fVars->USERLIST = LAN_426;
global $listuserson;
@@ -137,7 +136,7 @@ $fVars->PERMS = (USER == TRUE || ANON == TRUE ? LAN_204." - ".LAN_206." - ".LAN_
$fVars->INFO = "";
if (USER == TRUE)
{
$total_new_threads = $sql->db_Count('forum_thread', '(*)', "WHERE thread_datestamp>'".USERLV."' ");
$total_new_threads = $sql->count('forum_thread', '(*)', "WHERE thread_datestamp>'".USERLV."' ");
if (USERVIEWED != "")
{
$tmp = explode(".", USERVIEWED); // List of numbers, separated by single period
@@ -305,6 +304,7 @@ function parse_forum($f, $restricted_string = '')
global $FORUM_MAIN_FORUM, $gen, $forum, $newflag_list, $forumList;
$fVars = new e_vars;
$e107 = e107::getInstance();
$tp = e107::getParser();
if(USER && is_array($newflag_list) && in_array($f['forum_id'], $newflag_list))
{
@@ -320,8 +320,8 @@ function parse_forum($f, $restricted_string = '')
{
$f['forum_name'] = substr($f['forum_name'], 1);
}
$f['forum_name'] = $e107->tp->toHTML($f['forum_name'], true, 'no_hook');
$f['forum_description'] = $e107->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');
$fVars->FORUMNAME = "<a href='".$e107->url->create('forum/forum/view', $f)."'>{$f['forum_name']}</a>";
$fVars->FORUMDESCRIPTION = $f['forum_description'].($restricted_string ? "<br /><span class='smalltext'><i>$restricted_string</i></span>" : "");
@@ -364,7 +364,7 @@ function parse_forum($f, $restricted_string = '')
}
else
{
$lastpost_name = $e107->tp->toHTML($f['forum_lastpost_user_anon']);
$lastpost_name = $tp->toHTML($f['forum_lastpost_user_anon']);
}
$fVars->LASTPOSTUSER = $lastpost_name;
$fVars->LASTPOSTDATE .= $gen->computeLapse($lastpost_datestamp, time(), false, false, 'short');
@@ -378,19 +378,20 @@ function parse_forum($f, $restricted_string = '')
$fVars->LASTPOSTDATE = "-";
$fVars->LASTPOST = '-';
}
return $e107->tp->simpleParse($FORUM_MAIN_FORUM, $fVars);
return $tp->simpleParse($FORUM_MAIN_FORUM, $fVars);
}
function parse_subs($subList, $lastpost_datestamp)
{
$e107 = e107::getInstance();
$tp = e107::getParser();
$ret = array();
$ret['text'] = '';
foreach($subList as $sub)
{
$ret['text'] .= ($ret['text'] ? ', ' : '');
$suburl = $e107->url->create('forum/forum/view', $sub);
$ret['text'] .= "<a href='{$suburl}'>".$e107->tp->toHTML($sub['forum_name']).'</a>';
$ret['text'] .= "<a href='{$suburl}'>".$tp->toHTML($sub['forum_name']).'</a>';
$ret['threads'] += $sub['forum_threads'];
$ret['replies'] += $sub['forum_replies'];
$tmp = explode('.', $sub['forum_lastpost_info']);
@@ -429,13 +430,13 @@ if (e_QUERY == 'track')
}
$url = $e107->url->create('forum/thread/view', $row); // configs will be able to map thread_* vars to the url
$trackVars->TRACKPOSTNAME = "<a href='{$url}'>".$e107->tp->toHTML($row['thread_name']).'</a>';
$trackVars->TRACKPOSTNAME = "<a href='{$url}'>".$tp->toHTML($row['thread_name']).'</a>';
$trackVars->UNTRACK = "<a href='".e_SELF."?untrack.".$row['thread_id']."'>".LAN_392."</a>";
$forum_trackstring .= $e107->tp->simpleParse($FORUM_TRACK_MAIN, $trackVars);
$forum_trackstring .= $tp->simpleParse($FORUM_TRACK_MAIN, $trackVars);
}
}
$forum_track_start = $e107->tp->simpleParse($FORUM_TRACK_START, $trackVars);
$forum_track_end = $e107->tp->simpleParse($FORUM_TRACK_END, $trackVars);
$forum_track_start = $tp->simpleParse($FORUM_TRACK_START, $trackVars);
$forum_track_end = $tp->simpleParse($FORUM_TRACK_END, $trackVars);
if ($forum->prefs->get('enclose'))
{
$ns->tablerender($forum->prefs->get('title'), $forum_track_start.$forum_trackstring.$forum_track_end, array('forum', 'main1'));
@@ -464,19 +465,19 @@ if (e_QUERY == 'new')
{
$nVars->STARTERTITLE = "<a href='".$e107->url->create('user/profile/view', array('id' => $thread['thread_lastuser'], 'name' => $author_name))."'>{$author_name}</a><br />".$datestamp;
}
$nVars->NEWSPOSTNAME = "<a href='".$e107->url->create('forum/thread/last', $thread)."'>".$e107->tp->toHTML($thread['thread_name'], TRUE, 'no_make_clickable, no_hook').'</a>';
$nVars->NEWSPOSTNAME = "<a href='".$e107->url->create('forum/thread/last', $thread)."'>".$tp->toHTML($thread['thread_name'], TRUE, 'no_make_clickable, no_hook').'</a>';
$forum_newstring .= $e107->tp->simpleParse($FORUM_NEWPOSTS_MAIN, $nVars);
$forum_newstring .= $tp->simpleParse($FORUM_NEWPOSTS_MAIN, $nVars);
}
if (!$newThreadList)
{
$nVars->NEWSPOSTNAME = LAN_198;
$forum_newstring = $e107->tp->simpleParse($FORUM_NEWPOSTS_MAIN, $nVars);
$forum_newstring = $tp->simpleParse($FORUM_NEWPOSTS_MAIN, $nVars);
}
$forum_new_start = $e107->tp->simpleParse($FORUM_NEWPOSTS_START, $nVars);
$forum_new_end = $e107->tp->simpleParse($FORUM_NEWPOSTS_END, $nVars);
$forum_new_start = $tp->simpleParse($FORUM_NEWPOSTS_START, $nVars);
$forum_new_end = $tp->simpleParse($FORUM_NEWPOSTS_END, $nVars);
if ($forum->prefs->get('enclose'))
{
@@ -488,8 +489,8 @@ if (e_QUERY == 'new')
}
}
$forum_main_start = $e107->tp->simpleParse($FORUM_MAIN_START, $fVars);
$forum_main_end = $e107->tp->simpleParse($FORUM_MAIN_END, $fVars);
$forum_main_start = $tp->simpleParse($FORUM_MAIN_START, $fVars);
$forum_main_end = $tp->simpleParse($FORUM_MAIN_END, $fVars);
if ($forum->prefs->get('enclose'))
{
@@ -503,7 +504,6 @@ require_once(FOOTERF);
function forum_rules($action = 'check')
{
$e107 = e107::getInstance();
if (ADMIN == true)
{
$type = 'forum_rules_admin';
@@ -516,18 +516,19 @@ function forum_rules($action = 'check')
{
$type = 'forum_rules_guest';
}
$result = $e107->sql->db_Select('generic', 'gen_chardata', "gen_type = '$type' AND gen_intdata = 1");
$result = e107::getDb()->select('generic', 'gen_chardata', "gen_type = '$type' AND gen_intdata = 1");
if ($action == 'check') { return $result; }
if ($result)
{
$row = $e107->sql->db_Fetch();
$rules_text = $e107->tp->toHTML($row['gen_chardata'], true);
$row = e107::getDb()->fetch();
$rules_text = e107::getParser()->toHTML($row['gen_chardata'], true);
}
else
{
$rules_text = FORLAN_441;
}
$e107->ns->tablerender(LAN_433, "<div style='text-align:center'>{$rules_text}</div>", array('forum', 'forum_rules'));
e107::getRender()->tablerender(LAN_433, "<div style='text-align:center'>{$rules_text}</div>", array('forum', 'forum_rules'));
}
?>

View File

@@ -27,10 +27,10 @@ require_once(e_PLUGIN.'forum/forum_class.php');
require_once(e_PLUGIN.'forum/forum_admin_class.php');
$mes = e107::getMessage();
//$rs = new form; // FIX TODO needs $frm
$for = new e107forum;
$forum = new forumAdmin;
$sql = e107::getDb();
$tp = e107::GetParser();
$fPref = e107::getPlugConfig('forum', '', false);
@@ -59,7 +59,7 @@ if(isset($_POST['setMods']))
{
foreach($_POST['mods'] as $fid => $modid)
{
$sql->db_Update('forum',"forum_moderators = '{$modid}' WHERE forum_id = {$fid}");
$sql->update('forum',"forum_moderators = '{$modid}' WHERE forum_id = {$fid}");
}
//$forum->show_message(FORLAN_144);
$mes->addSuccess(FORLAN_144);
@@ -117,19 +117,19 @@ if(isset($_POST['create_sub']))
{
$fid = (int)($sub_action);
$tmp = array();
$tmp['forum_name'] = $e107->tp->toDB($_POST['subname_new']);
$tmp['forum_description'] = $e107->tp->toDB($_POST['subdesc_new']);
$tmp['forum_name'] = $tp->toDB($_POST['subname_new']);
$tmp['forum_description'] = $tp->toDB($_POST['subdesc_new']);
$tmp['forum_order'] = (int)$_POST['suborder_new'];
if($tmp['forum_name'] != '' && $sql->db_Select('forum', '*', "forum_id = {$fid}"))
if($tmp['forum_name'] != '' && $sql->select('forum', '*', "forum_id = {$fid}"))
{
$row = $sql->db_Fetch();
$row = $sql->fetch();
$tmp['forum_parent'] = $row['forum_parent'];
$tmp['forum_moderators'] = $row['forum_moderators'];
$tmp['forum_class'] = $row['forum_class'];
$tmp['forum_postclass'] = $row['forum_postclass'];
$tmp['forum_sub'] = $fid;
if($sql->db_Insert('forum', $tmp))
if($sql->insert('forum', $tmp))
{
//$forum->show_message(FORLAN_150.' - '.LAN_CREATED);
$mes->addSuccess(LAN_CREATED);
@@ -151,19 +151,19 @@ if(isset($_POST['update_subs']))
{
if($_POST['subname'][$id] == "")
{
if ($sql->db_Delete("forum", "forum_id='$id' "))
if ($sql->delete("forum", "forum_id='$id' "))
{
$msg .= FORLAN_150." ". LAN_ID.":"." ".$id." ".LAN_DELETED."<br />";
$cnt = $sql->db_Delete("forum_t", "thread_forum_id = {$id}");
$cnt = $sql->delete("forum_t", "thread_forum_id = {$id}");
$msg .= $cnt." ".FORLAN_152." ".LAN_DELETED."<br />";
}
}
else
{
$_name = $e107->tp->toDB($_POST['subname'][$id]);
$_desc = $e107->tp->toDB($_POST['subdesc'][$id]);
$_name = $tp->toDB($_POST['subname'][$id]);
$_desc = $tp->toDB($_POST['subdesc'][$id]);
$_order = (int)$_POST['suborder'][$id];
if($sql->db_Update('forum', "forum_name='{$_name}', forum_description='{$_desc}', forum_order='{$_order}' WHERE forum_id = {$id}"))
if($sql->update('forum', "forum_name='{$_name}', forum_description='{$_desc}', forum_order='{$_order}' WHERE forum_id = {$id}"))
{
$msg .= FORLAN_150 ." ". LAN_ID.":"." ".$id." ".LAN_UPDATED."<br />";
}
@@ -171,7 +171,6 @@ if(isset($_POST['update_subs']))
}
if($msg)
{
//$forum->show_message($msg);
$mes->addSuccess($msg);
$ns->tablerender($caption, $mes->render() . $text);
}
@@ -180,19 +179,17 @@ if(isset($_POST['update_subs']))
if(isset($_POST['submit_parent']))
{
$tmp = array();
$tmp['forum_name'] = $e107->tp->toDB($_POST['forum_name']);
$tmp['forum_name'] = $tp->toDB($_POST['forum_name']);
$tmp['forum_datestamp'] = time();
$tmp['forum_class'] = (int)$_POST['forum_class'];
$tmp['forum_postclass'] = (int)$_POST['forum_postclass'];
$tmp['forum_threadclass'] = (int)$_POST['forum_threadclass'];
if($sql->db_Insert('forum',$tmp))
if($sql->insert('forum',$tmp))
{
//$forum->show_message(FORLAN_22.' - '.LAN_CREATED);
$mes->addSuccess(LAN_CREATED);
}
else
{
//$forum->show_message(FORLAN_22.' - '.LAN_CREATED_FAILED);
$mes->addError(LAN_CREATED_FAILED);
}
}
@@ -213,7 +210,7 @@ if(isset($_POST['update_parent']))
$tmp['data']['forum_class'] = $_POST['forum_class'];
$tmp['data']['forum_postclass'] = $_POST['forum_postclass'];
$tmp['data']['forum_threadclass'] = $_POST['forum_threadclass'];
$sql->db_Update('forum', $tmp);
$sql->update('forum', $tmp);
$mes->addSuccess(LAN_UPDATED);
$action = 'main';
@@ -225,14 +222,14 @@ if(isset($_POST['submit_forum']))
{
$tmp = array();
$tmp['forum_moderators'] = (int)$_POST['forum_moderators'];
$tmp['forum_name'] = $e107->tp->toDB($_POST['forum_name']);
$tmp['forum_description'] = $e107->tp->toDB($_POST['forum_description']);
$tmp['forum_name'] = $tp->toDB($_POST['forum_name']);
$tmp['forum_description'] = $tp->toDB($_POST['forum_description']);
$tmp['forum_datestamp'] = time();
$tmp['forum_class'] = (int)$_POST['forum_class'];
$tmp['forum_postclass'] = (int)$_POST['forum_postclass'];
$tmp['forum_threadclass'] = (int)$_POST['forum_threadclass'];
$tmp['forum_parent'] = (int)$_POST['forum_parent'];
if($sql->db_Insert('forum', $tmp))
if($sql->insert('forum', $tmp))
{
$mes->addSuccess(LAN_CREATED);
}
@@ -256,8 +253,8 @@ if(isset($_POST['update_forum']))
$tmp2['forum_threadclass'] = $tmp['forum_threadclass'];
$tmp2['WHERE'] = 'forum_sub = '.(int)$id;
$sql->db_Update('forum', $tmp);
$sql->db_Update('forum', $tmp2);
$sql->update('forum', $tmp);
$sql->update('forum', $tmp2);
$mes->addSuccess(LAN_UPDATED);
$action = 'main';
@@ -270,7 +267,7 @@ if (isset($_POST['update_order']))
while (list($key, $id) = each($_POST['forum_order']))
{
$tmp = explode('.', $id);
$sql->db_Update('forum', "forum_order=".$tmp[1]." WHERE forum_id=".$tmp[0]);
$sql->update('forum', "forum_order=".$tmp[1]." WHERE forum_id=".$tmp[0]);
}
$mes->addSuccess(LAN_UPDATED);
}
@@ -316,27 +313,28 @@ $ns->tablerender($caption, $mes->render() . $text);
if (isset($_POST['frsubmit']))
{
$guestrules = $e107->tp->toDB($_POST['guestrules']);
$memberrules = $e107->tp->toDB($_POST['memberrules']);
$adminrules = $e107->tp->toDB($_POST['adminrules']);
if(!$sql->db_Update("generic", "gen_chardata ='$guestrules', gen_intdata='".$_POST['guest_active']."' WHERE gen_type='forum_rules_guest' "))
$guestrules = $tp->toDB($_POST['guestrules']);
$memberrules = $tp->toDB($_POST['memberrules']);
$adminrules = $tp->toDB($_POST['adminrules']);
if(!$sql->update("generic", "gen_chardata ='$guestrules', gen_intdata='".$_POST['guest_active']."' WHERE gen_type='forum_rules_guest' "))
{
$sql->db_Insert("generic", "0, 'forum_rules_guest', '".time()."', 0, '', '".$_POST['guest_active']."', '$guestrules' ");
$sql->insert("generic", "0, 'forum_rules_guest', '".time()."', 0, '', '".$_POST['guest_active']."', '$guestrules' ");
}
if(!$sql->db_Update("generic", "gen_chardata ='$memberrules', gen_intdata='".$_POST['member_active']."' WHERE gen_type='forum_rules_member' "))
if(!$sql->update("generic", "gen_chardata ='$memberrules', gen_intdata='".$_POST['member_active']."' WHERE gen_type='forum_rules_member' "))
{
$sql->db_Insert("generic", "0, 'forum_rules_member', '".time()."', 0, '', '".$_POST['member_active']."', '$memberrules' ");
$sql->insert("generic", "0, 'forum_rules_member', '".time()."', 0, '', '".$_POST['member_active']."', '$memberrules' ");
}
if(!$sql->db_Update("generic", "gen_chardata ='$adminrules', gen_intdata='".$_POST['admin_active']."' WHERE gen_type='forum_rules_admin' "))
if(!$sql->update("generic", "gen_chardata ='$adminrules', gen_intdata='".$_POST['admin_active']."' WHERE gen_type='forum_rules_admin' "))
{
$sql->db_Insert("generic", "0, 'forum_rules_admin', '".time()."', 0, '', '".$_POST['admin_active']."', '$adminrules' ");
$sql->insert("generic", "0, 'forum_rules_admin', '".time()."', 0, '', '".$_POST['admin_active']."', '$adminrules' ");
}
}
$ns->tablerender($caption, $mes->render() . $text);
if (vartrue($delete) == 'main') {
if ($sql->db_Delete('forum', "forum_id='$del_id' ")) {
if ($sql->delete('forum', "forum_id='$del_id' "))
{
$mes->addSuccess(LAN_DELETED);
}
else
@@ -349,7 +347,7 @@ $ns->tablerender($caption, $mes->render() . $text);
if (vartrue($action) == 'create')
{
if ($sql->db_Select('forum', '*', "forum_parent='0' "))
if ($sql->select('forum', '*', "forum_parent='0' "))
{
$forum->create_forums($sub_action, $id);
}
@@ -362,9 +360,9 @@ if (vartrue($action) == 'create')
if ($delete == 'cat')
{
if ($sql->db_Delete('forum', "forum_id='$del_id' "))
if ($sql->delete('forum', "forum_id='$del_id' "))
{
$sql->db_Delete('forum', "forum_parent='$del_id' ");
$sql->delete('forum', "forum_parent='$del_id' ");
$mes->addSuccess(LAN_DELETED);
$action = 'main';
}
@@ -422,8 +420,7 @@ switch($action)
if ($delete == 'reported')
{
$sql->db_Delete("generic", "gen_id='$del_id' ");
//$forum->show_message(FORLAN_118);
$sql->delete("generic", "gen_id='$del_id' ");
$mes->addSuccess(LAN_DELETED);
}
@@ -440,15 +437,17 @@ require_once(e_ADMIN.'footer.php');
function headerjs()
{
$e107 = e107::getInstance();
$tp = e107::getParser();
// These functions need to be removed and replaced with the generic jsconfirm() function.
$headerjs = "<script type=\"text/javascript\">
function confirm_(mode, forum_id, forum_name) {
if (mode == 'sr') {
return confirm(\"".$e107->tp->toJS(FORLAN_117)."\");
return confirm(\"".$tp->toJS(FORLAN_117)."\");
} else if(mode == 'parent') {
return confirm(\"".$e107->tp->toJS(FORLAN_81)." [ID: \" + forum_name + \"]\");
return confirm(\"".$tp->toJS(FORLAN_81)." [ID: \" + forum_name + \"]\");
} else {
return confirm(\"".$e107->tp->toJS(FORLAN_82)." [ID: \" + forum_name + \"]\");
return confirm(\"".$tp->toJS(FORLAN_82)." [ID: \" + forum_name + \"]\");
}
}
</script>";

View File

@@ -2,7 +2,7 @@
/*
* e107 website system
*
* Copyright (c) 2008-2011 e107 Inc (e107.org)
* Copyright (c) 2008-2013 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
@@ -254,7 +254,7 @@ class e107forum
break;
case 'lock':
if(e107::getDB()->update('forum_thread', 'thread_active=0 WHERE thread_id='.$id))
if(e107::getDb()->update('forum_thread', 'thread_active=0 WHERE thread_id='.$id))
{
$ret['msg'] = FORLAN_CLOSE;
$ret['status'] = 'ok';
@@ -267,7 +267,7 @@ class e107forum
break;
case 'unlock':
if(e107::getDB()->update('forum_thread', 'thread_active=1 WHERE thread_id='.$id))
if(e107::getDb()->update('forum_thread', 'thread_active=1 WHERE thread_id='.$id))
{
$ret['msg'] = FORLAN_OPEN;
$ret['status'] = 'ok';
@@ -280,7 +280,7 @@ class e107forum
break;
case 'stick':
if(e107::getDB()->update('forum_thread', 'thread_sticky=1 WHERE thread_id='.$id))
if(e107::getDb()->update('forum_thread', 'thread_sticky=1 WHERE thread_id='.$id))
{
$ret['msg'] = FORLAN_STICK;
$ret['status'] = 'ok';
@@ -293,7 +293,7 @@ class e107forum
break;
case 'unstick':
if(e107::getDB()->update('forum_thread', 'thread_sticky=0 WHERE thread_id='.$id))
if(e107::getDb()->update('forum_thread', 'thread_sticky=0 WHERE thread_id='.$id))
{
$ret['msg'] = FORLAN_UNSTICK;
$ret['status'] = 'ok';
@@ -374,6 +374,7 @@ class e107forum
private function _getForumPermList()
{
$e107 = e107::getInstance();
$sql = e107::getDb();
$this->permList = array();
$qryList = array();
@@ -401,10 +402,10 @@ class e107forum
foreach($qryList as $key => $qry)
{
if($e107->sql->gen($qry))
if($sql->gen($qry))
{
$tmp = array();
while($row = $e107->sql->fetch())
while($row = $sql->fetch())
{
$tmp[$row['forum_id']] = 1;
$tmp[$row['forum_parent']] = 1;
@@ -443,10 +444,12 @@ class e107forum
function getTrackedThreadList($id, $retType = 'array')
{
$e107 = e107::getInstance();
$sql = e107::getDb();
$id = (int)$id;
if($e107->sql->db_Select('forum_track', 'track_thread', 'track_userid = '.$id))
if($sql->select('forum_track', 'track_thread', 'track_userid = '.$id))
{
while($row = $e107->sql->fetch(MYSQL_ASSOC))
while($row = $sql->fetch(MYSQL_ASSOC))
{
$ret[] = $row['track_thread'];
}
@@ -469,10 +472,11 @@ class e107forum
$result = false;
$e107 = e107::getInstance();
$sql = e107::getDb();
$info = array();
// $info['_FIELD_TYPES'] = $this->fieldTypes['forum_post'];
$info['data'] = $postInfo;
$postId = $e107->sql->db_Insert('forum_post', $info);
$postId = $sql->insert('forum_post', $info);
$forumInfo = array();
if($postId && $updateThread)
@@ -501,7 +505,7 @@ class e107forum
// $info['_FIELD_TYPES'] = $this->fieldTypes['forum_thread'];
$info['_FIELD_TYPES']['thread_total_replies'] = 'cmd';
$result = $e107->sql->update('forum_thread', $info);
$result = $sql->update('forum_thread', $info);
}
@@ -534,7 +538,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->update('forum', $info);
$result = $sql->update('forum', $info);
}
if($result && USER && $addUserPostCount)
@@ -544,7 +548,7 @@ class e107forum
VALUES ('.USERID.', 1)
ON DUPLICATE KEY UPDATE user_plugin_forum_posts = user_plugin_forum_posts + 1
';
$result = $e107->sql->gen($qry);
$result = $sql->gen($qry);
}
return $postId;
}
@@ -557,7 +561,7 @@ class e107forum
$info = array();
// $info['_FIELD_TYPES'] = $this->fieldTypes['forum_thread'];
$info['data'] = $threadInfo;
if($newThreadId = $e107->sql->db_Insert('forum_thread', $info))
if($newThreadId = e107::getDb()->insert('forum_thread', $info))
{
$postInfo['post_thread'] = $newThreadId;
$newPostId = $this->postAdd($postInfo, false);
@@ -608,36 +612,33 @@ 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->update('forum_thread', $info);
e107::getDb()->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->update('forum_post', $info);
e107::getDb()->update('forum_post', $info);
}
function threadGet($id, $joinForum = true, $uid = USERID)
{
$e107 = e107::getInstance();
$id = (int)$id;
$uid = (int)$uid;
$sql = e107::getDb();
if($joinForum)
{
@@ -661,9 +662,9 @@ class e107forum
FROM `#forum_thread`
WHERE thread_id = '.$id;
}
if($e107->sql->gen($qry))
if($sql->gen($qry))
{
$tmp = $e107->sql->fetch(MYSQL_ASSOC);
$tmp = $sql->fetch(MYSQL_ASSOC);
if($tmp)
{
if(trim($tmp['thread_options']) != '')
@@ -677,12 +678,12 @@ class e107forum
}
function postGet($id, $start, $num = NULL)
{
$id = (int)$id;
$ret = false;
$e107 = e107::getInstance();
$sql = e107::getDb();
if('post' === $start)
{
$qry = '
@@ -709,10 +710,10 @@ class e107forum
LIMIT {$start}, {$num}
";
}
if($e107->sql->gen($qry))
if($sql->gen($qry))
{
$ret = array();
while($row = $e107->sql->fetch(MYSQL_ASSOC))
while($row = $sql->fetch(MYSQL_ASSOC))
{
$ret[] = $row;
}
@@ -722,21 +723,20 @@ class e107forum
}
function threadGetUserPostcount($threadId)
{
$threadId = (int)$threadId;
$e107 = e107::getInstance();
$sql = e107::getDb();
$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->gen($qry))
if($sql->gen($qry))
{
$ret = array();
while($row = $e107->sql->fetch(MYSQL_ASSOC))
while($row = $sql->fetch(MYSQL_ASSOC))
{
$ret[$row['post_user']] = $row['post_count'];
}
@@ -745,7 +745,6 @@ class e107forum
}
function threadGetUserViewed($uid = USERID)
{
$e107 = e107::getInstance();
@@ -763,20 +762,21 @@ class e107forum
}
function postDeleteAttachments($type = 'post', $id='', $f='')
{
$e107 = e107::getInstance();
$sql = $e107::getDb();
$id = (int)$id;
if(!$id) { return; }
if($type == 'thread')
{
if(!$e107->sql->db_Select('forum_post', 'post_id', 'post_attachments IS NOT NULL'))
if(!$sql->select('forum_post', 'post_id', 'post_attachments IS NOT NULL'))
{
return true;
}
$postList = array();
while($row = $e107->sql->dbFetch(MYSQL_ASSOC))
while($row = $sql->Fetch(MYSQL_ASSOC))
{
$postList[] = $row['post_id'];
}
@@ -787,11 +787,11 @@ class e107forum
}
if($type == 'post')
{
if(!$e107->sql->db_Select('forum_post', 'post_attachments', 'post_id = '.$id))
if(!$sql->select('forum_post', 'post_attachments', 'post_id = '.$id))
{
return true;
}
$tmp = $e107->sql->fetch(MYSQL_ASSOC);
$tmp = $sql->fetch(MYSQL_ASSOC);
$attachments = explode(',', $tmp['post_attachments']);
foreach($attachments as $k => $a)
{
@@ -823,12 +823,11 @@ class e107forum
$info['data'] = $tmp;
$info['_FILE_TYPES']['post_attachments'] = 'escape';
$info['WHERE'] = 'post_id = '.$id;
$e107->sql->update('forum_post', $info);
$sql->update('forum_post', $info);
}
}
/**
* Given threadId and postId, determine which number of post in thread the postid is
*
@@ -837,15 +836,15 @@ class e107forum
{
$threadId = (int)$threadId;
$postId = (int)$postId;
$e107 = e107::getInstance();
return $e107->sql->db_Count('forum_post', '(*)', "WHERE post_id <= {$postId} AND post_thread = {$threadId} ORDER BY post_id ASC");
return e107::getDb()->count('forum_post', '(*)', "WHERE post_id <= {$postId} AND post_thread = {$threadId} ORDER BY post_id ASC");
}
function forumUpdateLastpost($type, $id, $updateThreads = false)
{
global $sql, $tp;
$sql = e107::getDb();
$tp = e107::getParser();
$sql2 = new db;
if ($type == 'thread')
{
@@ -875,7 +874,7 @@ class e107forum
{
if ($id == 'all')
{
if ($sql->db_Select('forum', 'forum_id', 'forum_parent != 0'))
if ($sql->select('forum', 'forum_id', 'forum_parent != 0'))
{
while ($row = $sql->fetch(MYSQL_ASSOC))
{
@@ -895,7 +894,7 @@ class e107forum
$lp_user = 'NULL';
if($updateThreads == true)
{
if ($sql2->db_Select('forum_t', 'thread_id', "thread_forum_id = $id AND thread_parent = 0"))
if ($sql2->select('forum_t', 'thread_id', "thread_forum_id = $id AND thread_parent = 0"))
{
while ($row = $sql2->fetch(MYSQL_ASSOC))
{
@@ -904,7 +903,7 @@ class e107forum
}
}
}
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'))
if ($sql->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->fetch(MYSQL_ASSOC);
$lp_info = $row['thread_datestamp'].'.'.$row['thread_id'];
@@ -926,7 +925,7 @@ class e107forum
function forumMarkAsRead($forum_id)
{
$e107 = e107::getInstance();
$sql = e107::getDb();
$extra = '';
$newIdList = array();
if ($forum_id !== 0)
@@ -946,9 +945,9 @@ class e107forum
}
$qry = 'thread_lastpost > '.USERLV.$extra;
if ($e107->sql->db_Select('forum_thread', 'thread_id', $qry))
if ($sql->select('forum_thread', 'thread_id', $qry))
{
while ($row = $e107->sql->fetch(MYSQL_ASSOC))
while ($row = $sql->fetch(MYSQL_ASSOC))
{
$newIdList[] = $row['thread_id'];
}
@@ -966,7 +965,7 @@ class e107forum
function threadMarkAsRead($threadId)
{
global $currentUser;
$e107 = e107::getInstance();
$_tmp = preg_split('#\,+#', $currentUser['user_plugin_forum_viewed']);
if(!is_array($threadId)) { $threadId = array($threadId); }
foreach($threadId as $tid)
@@ -975,17 +974,16 @@ class e107forum
}
$tmp = array_unique($tmp);
$viewed = trim(implode(',', $_tmp), ',');
return $e107->sql->update('user_extended', "user_plugin_forum_viewed = '{$viewed}' WHERE user_extended_id = ".USERID);
return e107::getDb()->update('user_extended', "user_plugin_forum_viewed = '{$viewed}' WHERE user_extended_id = ".USERID);
}
function forum_getparents()
{
global $sql;
if ($sql->db_Select('forum', '*', 'forum_parent=0 ORDER BY forum_order ASC'))
if (e107::getDb()->select('forum', '*', 'forum_parent=0 ORDER BY forum_order ASC'))
{
while ($row = $sql->fetch(MYSQL_ASSOC)) {
while ($row = e107::getDb()->fetch(MYSQL_ASSOC)) {
$ret[] = $row;
}
return $ret;
@@ -997,14 +995,15 @@ class e107forum
function forumGetMods($uclass = e_UC_ADMIN, $force=false)
{
$sql = e107::getDb();
if(count($this->modArray) && !$force)
{
return $this->modArray;
}
if($uclass == e_UC_ADMIN || trim($uclass) == '')
{
$this->e107->sql->db_Select('user', 'user_id, user_name','user_admin = 1 ORDER BY user_name ASC');
while($row = $this->e107->sql->fetch(MYSQL_ASSOC))
$sql->select('user', 'user_id, user_name','user_admin = 1 ORDER BY user_name ASC');
while($row = $sql->fetch(MYSQL_ASSOC))
{
$this->modArray[$row['user_id']] = $row['user_name'];
}
@@ -1027,7 +1026,7 @@ class e107forum
function forumGetForumList($all=false)
{
$e107 = e107::getInstance();
$sql = e107::getDb();
$where = ($all ? '' : " WHERE forum_id IN ({$this->permList['view_list']}) ");
$qry = '
@@ -1035,10 +1034,10 @@ class e107forum
LEFT JOIN `#user` AS u ON f.forum_lastpost_user IS NOT NULL AND u.user_id = f.forum_lastpost_user
'.$where.
'ORDER BY f.forum_order ASC';
if ($e107->sql->gen($qry))
if ($sql->gen($qry))
{
$ret = array();
while ($row = $e107->sql->fetch())
while ($row = $sql->fetch())
{
if(!$row['forum_parent'])
{
@@ -1059,10 +1058,9 @@ class e107forum
}
function forum_getforums($type = 'all')
{
global $sql;
$e107::getDb();
$qry = "
SELECT f.*, u.user_name FROM #forum AS f
LEFT JOIN #user AS u ON SUBSTRING_INDEX(f.forum_lastpost_user,'.',1) = u.user_id
@@ -1088,10 +1086,9 @@ class e107forum
}
function forumGetSubs($forum_id = '')
{
global $sql;
$sql = e107::getDb();
$where = ($forum_id != '' && $forum_id != 'bysub' ? 'AND forum_sub = '.(int)$forum_id : '');
$qry = "
SELECT f.*, u.user_name FROM `#forum` AS f
@@ -1122,7 +1119,6 @@ class e107forum
}
/**
* List of forums with unread threads
*
@@ -1136,6 +1132,7 @@ class e107forum
{
if (!USER) {return false; } // Can't determine new threads for non-logged in users
$e107 = e107::getInstance();
$sql = e107::getDb();
$viewed = '';
if($e107->currentUser['user_plugin_forum_viewed'])
@@ -1147,9 +1144,9 @@ class e107forum
SELECT DISTINCT f.forum_sub, ft.thread_forum_id FROM `#forum_thread` AS ft
LEFT JOIN `#forum` AS f ON f.forum_id = ft.thread_forum_id
WHERE ft.thread_lastpost > '.USERLV.' '.$viewed;
if($e107->sql->gen($_newqry))
if($sql->gen($_newqry))
{
while($row = $e107->sql->fetch(MYSQL_ASSOC))
while($row = $sql->fetch(MYSQL_ASSOC))
{
$ret[] = $row['thread_forum_id'];
if($row['forum_sub'])
@@ -1166,7 +1163,6 @@ class e107forum
}
function thread_user($post_info)
{
if($post_info['user_name'])
@@ -1181,10 +1177,10 @@ class e107forum
}
function track($which, $uid, $threadId, $force=false)
{
$e107 = e107::getInstance();
$sql = e107::getDb();
if ($this->prefs->get('track') != 1 && !$force) { return false; }
@@ -1197,17 +1193,17 @@ class e107forum
$tmp = array();
$tmp['data']['track_userid'] = $uid;
$tmp['data']['track_thread'] = $threadId;
$result = $e107->sql->db_Insert('forum_track', $tmp);
$result = $sql->insert('forum_track', $tmp);
unset($tmp);
break;
case 'delete':
case 'del':
$result = $e107->sql->delete('forum_track', "`track_userid` = {$uid} AND `track_thread` = {$threadId}");
$result = $sql->delete('forum_track', "`track_userid` = {$uid} AND `track_thread` = {$threadId}");
break;
case 'check':
$result = $e107->sql->db_Count('forum_track', '(*)', "WHERE `track_userid` = {$uid} AND `track_thread` = {$threadId}");
$result = $sql->count('forum_track', '(*)', "WHERE `track_userid` = {$uid} AND `track_thread` = {$threadId}");
break;
}
return $result;
@@ -1233,10 +1229,9 @@ class e107forum
}
function forumGetAllowed($type='view')
{
global $sql;
$sql = e107::getDb();
$forumList = implode(',', $this->permList[$type]);
$qry = "
SELECT forum_id, forum_name FROM `#forum`
@@ -1252,12 +1247,12 @@ class e107forum
}
return $ret;
}
function forumGetThreads($forumId, $from, $view)
{
$e107 = e107::getInstance();
$sql = e107::getDb();
$forumId = (int)$forumId;
$qry = "
SELECT t.*, u.user_name, lpu.user_name AS lastpost_username from `#forum_thread` as t
@@ -1270,9 +1265,9 @@ class e107forum
LIMIT ".(int)$from.','.(int)$view;
$ret = array();
if ($e107->sql->gen($qry))
if ($sql->gen($qry))
{
while ($row = $e107->sql->fetch(MYSQL_ASSOC))
while ($row = $sql->fetch(MYSQL_ASSOC))
{
$ret[] = $row;
}
@@ -1281,10 +1276,10 @@ class e107forum
}
function threadGetLastpost($id)
{
$e107 = e107::getInstance();
$sql = e107::getDb();
$id = (int)$id;
$qry = "
SELECT p.post_user, p.post_user_anon, p.post_datestamp, p.post_thread, u.user_name FROM `#forum_post` AS p
@@ -1292,9 +1287,9 @@ class e107forum
WHERE p.post_thread = {$id}
ORDER BY p.post_datestamp DESC LIMIT 0,1
";
if ($e107->sql->gen($qry))
if ($sql->gen($qry))
{
return $e107->sql->fetch(MYSQL_ASSOC);
return $sql->fetch(MYSQL_ASSOC);
}
return false;
}
@@ -1302,11 +1297,10 @@ class e107forum
// function forum_get_topic_count($forum_id)
// {
// $e107 = e107::getInstance();
// return $e107->sql->db_Count('forum_thread', '(*)', 'WHERE thread_forum_id='.(int)$forum_id);
// return $sql->count('forum_thread', '(*)', 'WHERE thread_forum_id='.(int)$forum_id);
// }
function threadGetNextPrev($which, $threadId, $forumId, $lastpost)
{
// echo "threadid = $threadId <br />forum id = $forumId <br />";
@@ -1335,9 +1329,9 @@ class e107forum
thread_sticky DESC,
thread_lastpost {$sort}
LIMIT 1";
if ($e107->sql->gen($qry))
if ($sql->gen($qry))
{
$row = $e107->sql->fetch();
$row = $sql->fetch();
return $row['thread_id'];
}
@@ -1345,7 +1339,6 @@ class e107forum
}
function threadIncView($id)
{
$id = (int)$id;
@@ -1369,7 +1362,7 @@ class e107forum
function threadGetNew($count = 50, $unread = true, $uid = USERID)
{
$e107 = e107::getInstance();
$sql = e107::getDb();
$viewed = '';
if($unread)
{
@@ -1399,27 +1392,27 @@ class e107forum
ORDER BY t.thread_lastpost DESC LIMIT 0, ".(int)$count;
if($e107->sql->gen($qry))
if($sql->gen($qry))
{
$ret = $e107->sql->db_getList();
$ret = $sql->db_getList();
}
return $ret;
}
function forumPrune($type, $days, $forumArray)
{
$e107 = e107::getInstance();
$sql = e107::getDb();
$prunedate = time() - (int)$days * 86400;
$forumList = implode(',', $forumArray);
if($type == 'delete')
{
//Get list of threads to prune
if ($e107->sql->db_Select('forum_thread', 'thread_id', "thread_lastpost < {$prunedate} AND thread_sticky != 1 AND thread_forum_id IN ({$forumList})"))
if ($sql->select('forum_thread', 'thread_id', "thread_lastpost < {$prunedate} AND thread_sticky != 1 AND thread_forum_id IN ({$forumList})"))
{
$threadList = $e107->sql->db_getList();
$threadList = $sql->db_getList();
foreach($threadList as $thread)
{
$this->threadDelete($thread['thread_id'], false);
@@ -1438,20 +1431,20 @@ class e107forum
}
if($type == 'make_inactive')
{
$pruned = $e107->sql->update('forum_thread', "thread_active=0 WHERE thread_lastpost < {$prunedate} thread_forum_id IN ({$forumList})");
$pruned = $sql->update('forum_thread', "thread_active=0 WHERE thread_lastpost < {$prunedate} thread_forum_id IN ({$forumList})");
return FORLAN_8.' '.$pruned.' '.FORLAN_91;
}
}
function forumUpdateCounts($forumId, $recalcThreads = false)
{
$e107 = e107::getInstance();
$sql = e107::getDb();
if($forumId == 'all')
{
$e107->sql->db_Select('forum', 'forum_id', 'forum_parent != 0');
$flist = $e107->sql->db_getList();
$sql->select('forum', 'forum_id', 'forum_parent != 0');
$flist = $sql->db_getList();
foreach($flist as $f)
{
set_time_limit(60);
@@ -1460,19 +1453,19 @@ class e107forum
return;
}
$forumId = (int)$forumId;
$threads = $e107->sql->db_Count('forum_thread', '(*)', 'WHERE thread_forum_id='.$forumId);
$replies = $e107->sql->db_Count('forum_post', '(*)', 'WHERE post_forum='.$forumId);
$e107->sql->update('forum', "forum_threads={$threads}, forum_replies={$replies} WHERE forum_id={$forumId}");
$threads = $sql->count('forum_thread', '(*)', 'WHERE thread_forum_id='.$forumId);
$replies = $sql->count('forum_post', '(*)', 'WHERE post_forum='.$forumId);
$sql->update('forum', "forum_threads={$threads}, forum_replies={$replies} WHERE forum_id={$forumId}");
if($recalcThreads == true)
{
set_time_limit(60);
$e107->sql->db_Select('forum_post', 'post_thread, count(post_thread) AS replies', "post_forum={$forumId} GROUP BY post_thread");
$tlist = $e107->sql->db_getList();
$sql->select('forum_post', 'post_thread, count(post_thread) AS replies', "post_forum={$forumId} GROUP BY post_thread");
$tlist = $sql->db_getList();
foreach($tlist as $t)
{
$tid = $t['post_thread'];
$replies = (int)$t['replies'];
$e107->sql->update('forum_thread', "thread_total_replies={$replies} WHERE thread_id={$tid}");
$sql->update('forum_thread', "thread_total_replies={$replies} WHERE thread_id={$tid}");
}
}
}
@@ -1481,7 +1474,7 @@ class e107forum
function getUserCounts()
{
global $sql;
$sql = e107::getDb();
$qry = "
SELECT post_user, count(post_user) AS cnt FROM `#forum_post`
WHERE post_user > 0
@@ -1586,7 +1579,6 @@ class e107forum
}
/**
* Delete a Thread
* @param $threadId integer
@@ -1595,8 +1587,7 @@ class e107forum
*/
function threadDelete($threadId, $updateForumLastpost = true)
{
$e107 = e107::getInstance();
$e107 = e107::getInstance();
$sql = e107::getDb();
$status = false;
@@ -1651,7 +1642,6 @@ class e107forum
}
/**
* Delete a Post
* @param $postId integer
@@ -1661,12 +1651,11 @@ class e107forum
function postDelete($postId, $updateCounts = true)
{
$postId = (int)$postId;
$e107 = e107::getInstance();
$e107 = e107::getInstance();
$sql = e107::getDb();
$deleted = false;
if(!$sql->db_Select('forum_post', '*', 'post_id = '.$postId))
if(!$sql->select('forum_post', '*', 'post_id = '.$postId))
{
echo 'NOT FOUND!'; return;
}
@@ -1690,14 +1679,14 @@ class e107forum
//decrement user post counts
if ($row['post_user'])
{
$e107->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='.$row['post_user']);
}
// update thread with correct reply counts
$e107->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=".$row['post_thread']);
// update forum with correct thread/reply counts
$e107->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=".$row['post_forum']);
// update thread lastpost info
$this->forumUpdateLastpost('thread', $row['post_thread']);
@@ -1770,7 +1759,6 @@ function img_path($filename)
if (file_exists(THEME.'forum/forum_icons_template.php'))
{
require_once(THEME.'forum/forum_icons_template.php');