<?php
/**
* Forum Tab Class for handling the CB tab api
* @version $Id: cb.simpleboardtab.php 415 2006-09-08 16:59:59Z beat $
* @package Community Builder
* @subpackage plug_cbsimpleboardtab.php
* @author JoomlaJoe and Beat
* @copyright (C) JoomlaJoe and Beat, www.joomlapolis.com
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU/GPL version 2
* Thanks to LucaZone, www.lucazone.net for Fireboard adaptation suggestions
*/
// ensure this file is being included by a parent file
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
class getForumTab extends cbTabHandler {
var $com_name = null;
var $config_filename = null;
/**
* Constructor
*/
function getForumTab() {
$this->cbTabHandler();
}
/**
* Private method of CB: don't expect it to work after CB 1.1...couldn't do it in the
constructor, since params are loaded after...
*/
function _loadParams( $pluginid, &$extraParams ) {
global $mainframe;
parent::_loadParams( $pluginid, $extraParams );
$params = $this->params;
$forumType = $params->get( 'forumType', 0 );
if ( in_array( $forumType, array( 0, 2 ) ) && file_exists( $mainframe->getCfg('absolute_path').'/administrator/components/com_joomlaboard/joomlaboard_config.php' )) {
$this->com_name = 'com_joomlaboard';
$this->sql_prefix = 'sb';
$this->config_filename = $mainframe->getCfg('absolute_path') . '/administrator/components/com_joomlaboard/joomlaboard_config.php';
} else if ( in_array( $forumType, array( 0, 3 ) ) && file_exists( $mainframe->getCfg('absolute_path') . '/administrator/components/com_simpleboard/simpleboard_config.php' )) {
$this->com_name = 'com_simpleboard';
$this->sql_prefix = 'sb';
$this->config_filename = $mainframe->getCfg('absolute_path') . '/administrator/components/com_simpleboard/simpleboard_config.php';
} elseif ( in_array( $forumType, array( 0, 1 ) ) && file_exists( $mainframe->getCfg('absolute_path').'/administrator/components/com_fireboard/fireboard_config.php' )) {
$this->com_name = 'com_fireboard';
$this->sql_prefix = 'fb';
$this->config_filename = $mainframe->getCfg('absolute_path') . '/administrator/components/com_fireboard/fireboard_config.php';
}
}
/**
* ForumTab Internal method: returns an unescaped string if magic_quotes_gpc is on, correcting a
SB 1.1.0 double-escaping bug!
* @access private
* @param string to unescape
* @return string unescaped if needed
*/
function _sbUnEscape($string) {
return ((get_magic_quotes_gpc()==1) ? stripslashes($string) : $string); // correcting a SB 1.1.0 double-escaping bug!
}
/**
* ForumTab Internal method: returns an escaped string if magic_quotes_gpc is on, correcting a
SB 1.1.0 double-escaping bug!
* @access private
* @param string to escape
* @return string escaped if needed
*/
function _sbEscape($string) {
return ((get_magic_quotes_gpc()==1) ? addslashes($string) : $string); // correcting a SB 1.1.0 double-escaping bug!
}
/**
* ForumTab Internal method: returns $sbUserDetails for the $user
* @access private
* @param array sbConfig
* @param object user being displayed
* @return object sbUserDetails
*/
function _getSBstats($sbConfig, $user) {
global $database,$mosConfig_live_site,$acl,$my;
if($sbConfig['showstats'] || (!$sbConfig['showranking'] && !$sbConfig['showkarma'] && !$sbConfig['postStats'])) {
$database->setQuery("SELECT posts,karma,moderator,gid FROM #__" . $this->sql_prefix . "_users sb, #__users u where sb.userid=u.id AND sb.userid=" . (int) $user->id);
$sbUserDetails=$database->loadObjectList();
if(count($sbUserDetails)>0) $sbUserDetails=$sbUserDetails[0];
if( (isset($sbUserDetails->posts)) and $sbUserDetails->posts != 0) {
if($sbConfig['showranking']) {
$uIsAdm="";
$uIsMod="";
if ( $sbUserDetails->gid > 0 ) { //only get the groupname from the ACL if we're sure there is one
$agrp=strtolower( $acl->get_group_name( $sbUserDetails->gid, 'ARO' ) );
if(strtolower($agrp)=="administrator" || strtolower($agrp)=="superadministrator"|| strtolower($agrp)=="super administrator") $uIsAdm=1;
}
$uIsMod=$sbUserDetails->moderator;
if ( $this->com_name == 'com_fireboard' ) {
$params = $this->params;
$pathTemplate = $params->get('TemplateRank', '/template/default/images/english');
$sbs = $mosConfig_live_site.'/components/'.$this->com_name.$pathTemplate;
} else {
$sbs = $mosConfig_live_site.'/components/'.$this->com_name;
}
$numPosts=$sbUserDetails->posts;
$rText="";
$rImg="";
if ($numPosts>=0 && $numPosts<(int)$sbConfig['rank1']) { $rText=$sbConfig['rank1txt']; $rImg=$sbs.'/ranks/rank1.gif'; }
if ($numPosts>=(int)$sbConfig['rank1'] && $numPosts<(int)$sbConfig['rank2']){$rText=$sbConfig['rank2txt']; $rImg=$sbs.'/ranks/rank2.gif';}
if ($numPosts>=(int)$sbConfig['rank2'] && $numPosts<(int)$sbConfig['rank3']){$rText=$sbConfig['rank3txt']; $rImg=$sbs.'/ranks/rank3.gif';}
if ($numPosts>=(int)$sbConfig['rank3'] && $numPosts<(int)$sbConfig['rank4']){$rText=$sbConfig['rank4txt']; $rImg=$sbs.'/ranks/rank4.gif';}
if ($numPosts>=(int)$sbConfig['rank4'] && $numPosts<(int)$sbConfig['rank5']){$rText=$sbConfig['rank5txt']; $rImg=$sbs.'/ranks/rank5.gif';}
if ($numPosts>=(int)$sbConfig['rank5']){$rText=$sbConfig['rank6txt']; $rImg=$sbs.'/ranks/rank6.gif';}
if ($uIsMod){$rText=_RANK_MODERATOR; $rImg=$sbs.'/ranks/rankmod.gif';}
if ($uIsAdm){$rText=_RANK_ADMINISTRATOR; $rImg=$sbs.'/ranks/rankadmin.gif';}
if($sbConfig['rankimages']){$sbUserDetails->msg_userrankimg = '<br /><img src="'.$rImg.'" alt="" />';}
$sbUserDetails->msg_userrank = $rText;
}
} else $sbUserDetails = false;
} else $sbUserDetails = false;
return $sbUserDetails;
}
/**
* ForumTab Internal method: returns html output of $sbUserDetails for the $user
* @access private
* @param array sbConfig
* @param object user being displayed
* @param object sbUserDetails
* @return html code for tab
*/
function _getDisplaySBstats($sbConfig, $user, $params, $sbUserDetails) {
$return="";
$return .= "<div class=\"sectiontableheader\" style=\"text-align:left;padding-left:0px;padding-right:0px;width:50%;\">"._UE_FORUM_STATS."</div>";
if ($sbUserDetails !== false) {
$return .= "<table cellpadding=\"5\" cellspacing=\"0\" style=\"border:0;margin:0;padding:0;\" width=\"50%\">";
if($sbConfig['showranking'] && ($params->get('statRanking', '1') == 1)) $return .= "<tr class=\"sectiontableentry1\"><td style=\"font-weight:bold;width:50%;\">".getLangDefinition($params->get('statRankingText', "_UE_FORUM_FORUMRANKING"))."</td><td>".$sbUserDetails->msg_userrank.($params->get('statRankingImg', '1')==1 ? $sbUserDetails->msg_userrankimg : "")."</td></tr>";
if ($sbConfig['postStats'] && (($params->get('statPosts', '1')==2) || (($params->get('statPosts', '1')==1)&&($sbUserDetails !== false)))) {
$return .= "<tr class=\"sectiontableentry2\"><td style=\"font-weight:bold;width:50%;\">"
.getLangDefinition($params->get('statPostsText', "_UE_FORUM_TOTALPOSTS"))."</td><td>".$sbUserDetails->posts."</td></tr>";
}
if ($sbConfig['showkarma'] && ($sbUserDetails !== false) && (($params->get('statKarma', '1')==2)||(($params->get('statKarma', '1')==1)&&($sbUserDetails->karma!=0)))) {
$return .= "<tr class=\"sectiontableentry1\"><td style=\"font-weight:bold;width:50%;\">"
.getLangDefinition($params->get('statKarmaText', "_UE_FORUM_KARMA"))."</td><td>".$sbUserDetails->karma."</td></tr>";
}
$return .= "</table>";
} else {
$return = "";
}
return $return;
}
/**
* ForumTab Internal method: sets User Status display according to $sbUserDetails for the $user
* @access private
* @param array sbConfig
* @param object user being displayed
* @param object sbUserDetails
*/
function _setStatusMenuSBstats($sbConfig, $user, &$params, $sbUserDetails) {
if ($sbConfig['showranking'] && ($params->get('statRanking', '1') == 1) && ($sbUserDetails !== false)) {
$mi = array(); $mi["_UE_MENU_STATUS"][$params->get('statRankingText', "_UE_FORUM_FORUMRANKING")]["_UE_FORUM_FORUMRANKING"]=null;
$this->addMenu( array( "position" => "menuList" , // "menuBar", "menuList"
"arrayPos" => $mi ,
"caption" => $sbUserDetails->msg_userrank.($params->get('statRankingImg', '1')==1 ? $sbUserDetails->msg_userrankimg : "") ,
"url" => "" , // can also be "<a ....>" or "javascript:void(0)" or ""
"target" => "" , // e.g. "_blank"
"img" => null , // e.g. "<img src='plugins/user/myplugin/images/icon.gif' width='16' height='16' alt='' />"
"alt" => null , // e.g. "text"
"tooltip" => "") );
}
if ($sbConfig['postStats'] && (($params->get('statPosts', '1')==2) || (($params->get('statPosts', '1')==1)&&($sbUserDetails !== false)))) {
$mi = array(); $mi["_UE_MENU_STATUS"][$params->get('statPostsText', "_UE_FORUM_TOTALPOSTS")]["_UE_FORUM_TOTALPOSTS"]=null;
$this->addMenu( array( "position" => "menuList" ,
"arrayPos" => $mi ,
"caption" => (($sbUserDetails !== false) ? $sbUserDetails->posts : "0") ,
"url" => "" ,
"target" => "" ,
"img" => null ,
"alt" => null ,
"tooltip" => "") );
}
if ($sbConfig['showkarma'] && ($sbUserDetails !== false) && (($params->get('statKarma', '1')==2)||(($params->get('statKarma', '1')==1)&&($sbUserDetails->karma!=0)))) {
$mi = array(); $mi["_UE_MENU_STATUS"][$params->get('statKarmaText', "_UE_FORUM_KARMA")]["_UE_FORUM_KARMA"]=null;
$this->addMenu( array( "position" => "menuList" ,
"arrayPos" => $mi ,
"caption" => $sbUserDetails->karma ,
"url" => "" ,
"target" => "" ,
"img" => null ,
"alt" => null ,
"tooltip" => "") );
}
}
/**
* Generates the menu and user status to display on the user profile by calling back $this->
addMenu
* @param object tab reflecting the tab database entry
* @param object mosUser reflecting the user being displayed
* @param int 1 for front-end, 2 for back-end
* @returns boolean : either true, or false if ErrorMSG generated
*/
function getMenuAndStatus($tab,$user,$ui) {
if ( $this->com_name == 'com_fireboard' ) {
global $fbConfig;
} else {
global $sbConfig;
$fbConfig =& $sbConfig;
}
$params=$this->params;
$newslettersRegList=$params->get('statDisplay', '1');
if ($newslettersRegList==1) {
if($this->config_filename) {
include_once ( $this->config_filename );
} else {
$this->_setErrorMSG(_UE_SBNOTINSTALLED);
return false;
}
$sbUserDetails = $this->_getSBstats($fbConfig, $user);
$this->_setStatusMenuSBstats($fbConfig, $user, $params, $sbUserDetails);
}
return true;
}
/**
* Generates the HTML to display the user profile tab
* @param object tab reflecting the tab database entry
* @param object mosUser reflecting the user being displayed
* @param int 1 for front-end, 2 for back-end
* @returns mixed : either string HTML for tab content, or false if ErrorMSG generated
*/
function getDisplayTab($tab,$user,$ui) {
global $database,$mosConfig_live_site,$acl,$my;
if ( $this->com_name == 'com_fireboard' ) {
global $fbConfig;
} else {
global $sbConfig;
$fbConfig =& $sbConfig;
}
$return="";
$searchForm="";
if ($this->config_filename) {
include_once ( $this->config_filename );
} else {
$return = _UE_SBNOTINSTALLED;
return $return;
}
$database->setQuery("SELECT id FROM #__menu WHERE link='index.php?option=".$this->com_name."' AND published=1");
$Itemid=$database->loadResult();
$return .= $this->_writeTabDescription( $tab, $user );
$params=$this->params;
$newslettersRegList=$params->get('statDisplay', '1');
$sbUserDetails = $this->_getSBstats($fbConfig, $user);
if ($newslettersRegList==2) $return .= $this->_getDisplaySBstats($fbConfig, $user, $params, $sbUserDetails);
if($my->id == $user->id && $fbConfig['allowsubscriptions']) {
$database->setQuery("SELECT thread FROM #__" . $this->sql_prefix . "_subscriptions WHERE userid=" . (int) $my->id);
$subslist=$database->loadObjectList();
$csubslist=count($subslist);
$return .= "<br /><div class=\"sectiontableheader\" style=\"text-align:left;padding-left:0px;padding-right:0px;margin:0px 0px 10px 0px;height:auto;width:100%;\">"
. ( defined('_UE_USER_SUBSCRIPTIONS') ? getLangDefinition( "_UE_USER_SUBSCRIPTIONS" ) :
( ( defined('_UE_fb_CONFIRMUNSUBSCRIBEALL') ) ? getLangDefinition( "_UE_fb_CONFIRMUNSUBSCRIBEALL" ) : "" ) )
. "<br />";
$return .= "\n<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"margin:0px;padding:0px;width:100%;\">";
$enum=1;//reset value
$tabclass = array("sectiontableentry1", "sectiontableentry2");//alternating row CSS classes
$k=1; //value for alternating rows
if($csubslist >0){
foreach($subslist as $subs) { //get all message details for each subscription
$database->setQuery("SELECT * FROM #__" . $this->sql_prefix . "_messages WHERE id=$subs->thread");
$subdet=$database->loadObjectList();
foreach($subdet as $sub){
$k=1-$k;
$return .= "\n\t<tr class=\"".$tabclass[$k]."\">";
$return .= "\n\t\t<td>".$enum.": <a href=\""
.sefRelToAbs('index.php?option='.$this->com_name.($Itemid ? '&Itemid='
.$Itemid : '').'&func=view&catid='.$sub->catid.'&id='.$sub->id)
.'">'.$this->_sbUnescape($sub->subject).'</a> - ' ._UE_GEN_BY. ' ' .$sub->name."</td>";
$return .= "\n\t\t<td><a href=\""
.sefRelToAbs('index.php?option='.$this->com_name.($Itemid ? '&Itemid='.$Itemid : '').'&func=userprofile&do=unsubscribe&thread='.$subs->thread)
.'">' ._UE_THREAD_UNSUBSCRIBE. "</a></td>";
$return .= "\n\t</tr>";
$enum++;
}
}
$return .= "\n\t<tr>\n\t\t<td colspan=\"2\"><form action=\""
.sefRelToAbs('index.php?option='.$this->com_name.($Itemid ? '&Itemid='.$Itemid : '').'&func=userprofile&do=update')
.'" method="post" name="postform" id="postform">'
.'<input type="hidden" name="do" value="upda
|