1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-04 13:47:31 +02:00

Code clean-up - Fixes to user profile: forum and chatbox counts and forum link working again.

This commit is contained in:
Moc
2013-04-15 12:26:49 +02:00
parent b1bcacc593
commit 384cb63c07

View File

@@ -9,6 +9,7 @@
* User information - shortcodes * User information - shortcodes
* *
*/ */
if (!defined('e107_INIT')) { exit; } if (!defined('e107_INIT')) { exit; }
@@ -17,14 +18,14 @@ class user_shortcodes extends e_shortcode
function sc_total_chatposts($parm) { function sc_total_chatposts($parm) {
$sql = e107::getDb(); $sql = e107::getDb();
if(!$chatposts = getcachedvars('total_chatposts')) if(!$chatposts = e107::getRegistry('total_chatposts'))
{ {
$chatposts = 0; // In case plugin not installed $chatposts = 0; // In case plugin not installed
if (isset($pref['plug_installed']['chatbox_menu'])) if(e107::isInstalled("chatbox_menu"))
{ {
$chatposts = $sql->count("chatbox"); $chatposts = $sql->count("chatbox");
} }
cachevars('total_chatposts', $chatposts); e107::setRegistry('total_chatposts', $chatposts);
} }
return $chatposts; return $chatposts;
} }
@@ -34,10 +35,10 @@ class user_shortcodes extends e_shortcode
function sc_total_commentposts($parm) function sc_total_commentposts($parm)
{ {
$sql = e107::getDb(); $sql = e107::getDb();
if(!$commentposts = getcachedvars('total_commentposts')) if(!$commentposts = e107::getRegistry('total_commentposts'))
{ {
$commentposts = $sql->count("comments"); $commentposts = $sql->count("comments");
cachevars('total_commentposts', $commentposts); e107::setRegistry('total_commentposts', $commentposts);
} }
return $commentposts; return $commentposts;
} }
@@ -47,10 +48,10 @@ class user_shortcodes extends e_shortcode
function sc_total_forumposts($parm) function sc_total_forumposts($parm)
{ {
$sql = e107::getDb(); $sql = e107::getDb();
if(!$forumposts = getcachedvars('total_forumposts')) if(!$forumposts = e107::getRegistry('total_forumposts'))
{ {
$forumposts = $sql->count("forum_thread"); $forumposts = $sql->count("forum_thread");
cachevars('total_forumposts', $forumposts); e107::setRegistry('total_forumposts', $forumposts);
} }
return $forumposts; return $forumposts;
} }
@@ -66,7 +67,8 @@ class user_shortcodes extends e_shortcode
function sc_user_forumposts($parm) function sc_user_forumposts($parm)
{ {
return $this->var['user_forums']; //return $this->var['user_forums']; //FIXME column not present in v2. Possible fix on next line.
return e107::getDb()->count("forum_thread","(*)","where thread_user=".$this->var['user_id']);
} }
@@ -84,14 +86,15 @@ class user_shortcodes extends e_shortcode
function sc_user_chatper($parm) function sc_user_chatper($parm)
{ {
$sql = e107::getDb(); $sql = e107::getDb();
if(!$chatposts = getcachedvars('total_chatposts'))
if(!$chatposts = e107::getRegistry('total_chatposts'))
{ {
$chatposts = 0; // In case plugin not installed $chatposts = 0; // In case plugin not installed
if (isset($pref['plug_installed']['chatbox_menu'])) if (e107::isInstalled("chatbox_menu"))
{ {
$chatposts = $sql->count("chatbox"); $chatposts = $sql->count("chatbox");
} }
cachevars('total_chatposts', $chatposts); e107::setRegistry('total_chatposts', $chatposts);
} }
return ($chatposts!=0) ? round(($this->var['user_chats']/$chatposts) * 100, 2): 0; return ($chatposts!=0) ? round(($this->var['user_chats']/$chatposts) * 100, 2): 0;
} }
@@ -101,10 +104,10 @@ class user_shortcodes extends e_shortcode
function sc_user_commentper($parm) function sc_user_commentper($parm)
{ {
$sql = e107::getDb(); $sql = e107::getDb();
if(!$commentposts = getcachedvars('total_commentposts')) if(!$commentposts = e107::getRegistry('total_commentposts'))
{ {
$commentposts = $sql->count("comments"); $commentposts = $sql->count("comments");
cachevars('total_commentposts', $commentposts); e107::setRegistry('total_commentposts', $commentposts);
} }
return ($commentposts!=0) ? round(($this->var['user_comments']/$commentposts) * 100, 2): 0; return ($commentposts!=0) ? round(($this->var['user_comments']/$commentposts) * 100, 2): 0;
} }
@@ -114,12 +117,13 @@ class user_shortcodes extends e_shortcode
function sc_user_forumper($parm) function sc_user_forumper($parm)
{ {
$sql = e107::getDb(); $sql = e107::getDb();
if(!$forumposts = getcachedvars('total_forumposts')) if(!$forumposts = e107::getRegistry('total_forumposts'))
{ {
$forumposts = (isset($pref['plug_installed']['forum'])) ? $sql->count("forum_thread"): 0; $forumposts = (e107::isInstalled("forum")) ? $sql->count("forum_thread"): 0;
cachevars('total_forumposts', $forumposts); e107::setRegistry('total_forumposts', $forumposts);
$user_forumposts = $sql->count("forum_thread","(*)","where thread_user=".$this->var['user_id']);
} }
return ($forumposts!==0) ? round(($this->var['user_forums']/$forumposts) * 100, 2): 0; return ($forumposts!==0) ? round(($user_forumposts/$forumposts) * 100, 2): 0;
} }
@@ -349,7 +353,8 @@ class user_shortcodes extends e_shortcode
function sc_user_forum_link($parm) function sc_user_forum_link($parm)
{ {
return $this->var['user_forums'] ? "<a href='".e_HTTP."userposts.php?0.forums.".$this->var['user_id']."'>".LAN_USER_37."</a>" : ""; $user_forumposts = e107::getDb()->count("forum_thread","(*)","where thread_user=".$this->var['user_id']);
return $user_forumposts ? "<a href='".e_HTTP."userposts.php?0.forums.".$this->var['user_id']."'>".LAN_USER_37."</a>" : "";
} }
@@ -358,7 +363,7 @@ class user_shortcodes extends e_shortcode
{ {
$pref = e107::getPref(); $pref = e107::getPref();
$tp = e107::getParser(); $tp = e107::getParser();
if(isset($pref['plug_installed']['pm']) && ($this->var['user_id'] > 0)) if(e107::isInstalled("pm") && ($this->var['user_id'] > 0))
{ {
return $tp->parseTemplate("{SENDPM={$this->var['user_id']}}"); return $tp->parseTemplate("{SENDPM={$this->var['user_id']}}");
} }
@@ -432,7 +437,7 @@ class user_shortcodes extends e_shortcode
$sql = e107::getDb(); $sql = e107::getDb();
if (!$full_perms) return; if (!$full_perms) return;
$url = e107::getUrl(); $url = e107::getUrl();
if(!$userjump = getcachedvars('userjump')) if(!$userjump = e107::getRegistry('userjump'))
{ {
// $sql->db_Select("user", "user_id, user_name", "`user_id` > ".intval($this->var['user_id'])." AND `user_ban`=0 ORDER BY user_id ASC LIMIT 1 "); // $sql->db_Select("user", "user_id, user_name", "`user_id` > ".intval($this->var['user_id'])." AND `user_ban`=0 ORDER BY user_id ASC LIMIT 1 ");
$sql->gen("SELECT user_id, user_name FROM `#user` FORCE INDEX (PRIMARY) WHERE `user_id` > ".intval($this->var['user_id'])." AND `user_ban`=0 ORDER BY user_id ASC LIMIT 1 "); $sql->gen("SELECT user_id, user_name FROM `#user` FORCE INDEX (PRIMARY) WHERE `user_id` > ".intval($this->var['user_id'])." AND `user_ban`=0 ORDER BY user_id ASC LIMIT 1 ");
@@ -448,7 +453,7 @@ class user_shortcodes extends e_shortcode
$userjump['prev']['id'] = $row['user_id']; $userjump['prev']['id'] = $row['user_id'];
$userjump['prev']['name'] = $row['user_name']; $userjump['prev']['name'] = $row['user_name'];
} }
cachevars('userjump', $userjump); e107::setRegistry('userjump', $userjump);
} }
if($parm == 'prev') if($parm == 'prev')
{ {