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

${task.key} (${task.type}): User ranks now configurable and render properly. Still need to work on moving config from forum, and establishing a default config.

This commit is contained in:
mcfly
2010-03-13 18:59:28 +00:00
parent 568859aef2
commit 5306afd727
6 changed files with 335 additions and 395 deletions

View File

@@ -9,10 +9,8 @@
*
* Administration Area - Users
*
* $Source: /cvs_backup/e107_0.8/e107_admin/users.php,v $
* $Revision$
* $Date$
* $Author$
* $URL$
* $Id$
*
*/
require_once ('../class2.php');
@@ -99,7 +97,7 @@ $from = varset($from,0);
$amount = 30;
if ($action == 'ranks')
{
show_ranks();
showRanks();
}
// ------- Check for Bounces --------------
$bounce_act = '';
@@ -284,14 +282,14 @@ if (isset ($_POST['adduser']))
$user_data = & $allData['data'];
if (!$error)
{
if(varset($_POST['perms']))
{
$allData['data']['user_admin'] = 1;
$allData['data']['user_perms'] = implode('.',$_POST['perms']);
}
$message = '';
$user_data['user_password'] = $userMethods->HashPassword($savePassword,$loginname);
$user_data['user_join'] = time();
@@ -439,12 +437,12 @@ if ((varset($_POST['useraction'])== "admin" || varset($_POST['useraction'])== "a
{
$sql->db_Select("user","user_id, user_name, user_perms","user_id='".$_POST['userid']."'");
$row = $sql->db_Fetch();
if(varset($_POST['useraction'])== "admin")
{
$sql->db_Update("user","user_admin='1' WHERE user_id='".$_POST['userid']."' ");
}
$admin_log->log_event('USET_08',str_replace(array('--UID--','--NAME--'),array($row['user_id'],$row['user_name']),USRLAN_164),E_LOG_INFORMATIVE);
$user->show_message($row['user_name']." ".USRLAN_3." <a href='".e_ADMIN."administrator.php?edit.{$row['user_id']}'>".USRLAN_4."</a>");
$action = "main";
@@ -456,16 +454,16 @@ if ((varset($_POST['useraction'])== "admin" || varset($_POST['useraction'])== "a
{
$id = "DESC";
}
$prm->edit_administrator($row);
require_once ("footer.php");
exit;
}
if (varset($_POST['update_admin'])) // Update admin Perms.
{
$prm->updatePerms($_POST['a_id'],$_POST['perms']);
if (varset($_POST['update_admin'])) // Update admin Perms.
{
$prm->updatePerms($_POST['a_id'],$_POST['perms']);
}
@@ -599,7 +597,7 @@ class users
'user_signature' => array('title' => LAN_USER_09,'type' => 'text','width' => 'auto'),
'user_hideemail' => array('title' => LAN_USER_10,'type' => 'boolean','width' => 'auto'),
'user_xup' => array('title' => LAN_USER_11,'type' => 'text','width' => 'auto'),
'user_class' => array('title' => LAN_USER_12,'type' => 'class'),
'user_class' => array('title' => LAN_USER_12,'type' => 'class'),
'user_join' => array('title' => LAN_USER_14,'type' => 'date', 'width' => 'auto'),
'user_lastvisit' => array('title' => LAN_USER_15,'type' => 'date', 'width' => 'auto'),
'user_currentvisit' => array('title' => LAN_USER_16,'type' => 'date', 'width' => 'auto'),
@@ -631,30 +629,30 @@ class users
{
list($type,$tmp,$uclass) = explode("_",$_POST['execute_batch']);
$method = "user_".$type;
if($method == "user_remuserclass")
{
$method = "user_userclass";
$method = "user_userclass";
}
if (method_exists($this,$method) && isset($_POST['user_selected']) )
{
foreach ($_POST['user_selected'] as $userid)
{
if($type=='userclass' || $type=='remuserclass')
{
{
switch($type)
{
case 'userclass':
$mode = 'append';
break;
case 'remuserclass' :
$mode = ($uclass != '0') ? 'remove' : 'clear';
break;
}
$this->$method($userid,array($uclass),$mode);
}
else
@@ -1065,13 +1063,13 @@ class users
}
}
// $user_total = db_Count($table, $fields = '(*)',
if($_SESSION['filter']==e_UC_ADMIN)
{
$this->fieldpref[] = 'user_perms';
}
}
$qry_insert = 'SELECT u.*, ue.* FROM `#user` AS u LEFT JOIN `#user_extended` AS ue ON ue.user_extended_id = u.user_id ';
return ($query) ? $qry_insert." WHERE ".$query.$qry_order : $qry_insert.$qry_order;
@@ -1080,15 +1078,15 @@ class users
function show_existing_users($action,$sub_action,$id,$from,$amount)
{
global $mySQLdefaultdb,$pref,$unverified,$userMethods;
$sql = e107::getDb();
$frm = e107::getForm();
$ns = e107::getRender();
$tp = e107::getParser();
$e107 = e107 :: getInstance();
$qry = $this->get_search_query();
$this->fieldpref = array_unique($this->fieldpref);
$text = "<div>".$this->show_search_filter();
@@ -1102,7 +1100,7 @@ class users
$frm->colGroup($this->fields,$this->fieldpref).
$frm->thead($this->fields,$this->fieldpref,"main.[FIELD].[ASC].[FROM]").
"<tbody>\n";
while ($row = $sql->db_Fetch())
{
@@ -1110,29 +1108,29 @@ class users
<tr>
<td class='center' >".$frm->checkbox('user_selected[]',$row['user_id'])."</td>
<td class='center' style='width:5%; text-align:center' >{$row['user_id']}</td>";
foreach ($this->fieldpref as $disp)
{
$class = vartrue($this->fields[$disp]['thclass']) ? "class='".$this->fields[$disp]['thclass']."'" : "";
$class = vartrue($this->fields[$disp]['thclass']) ? "class='".$this->fields[$disp]['thclass']."'" : "";
$text .= "<td ".$class." style='white-space:nowrap'>".$this->renderValue($disp,$row)."</td>\n";
}
$text .= "
<td style='width:30%' class='center'>".$this->showUserOptions($row)."</td></tr>\n";
}
$text .= "</tbody>
</table>
<div class='buttons-bar center'>".$this->show_batch_options();
$users = (e_QUERY != "unverified") ? $sql->db_Count("user") : $unverified;
if ($users > $amount && !$_GET['srch'])
{
$parms = "{$users},{$amount},{$from},".e_SELF."?".(e_QUERY ? "$action.$sub_action.$id." : "main.user_id.desc.")."[FROM]";
$text .= $tp->parseTemplate("{NEXTPREV={$parms}}");
}
if ($action == "unverified")
{
$qry = (e_QUERY) ? "?".e_QUERY : "";
@@ -1150,7 +1148,7 @@ class users
$text .= "</fieldset></form>
</div>";
$emessage = & eMessage :: getInstance();
$total_cap = (isset ($_GET['srch'])) ? $user_total : $users;
@@ -1166,8 +1164,8 @@ class users
$type = $this->fields[$key]['type'];
$pref = e107::getConfig()->getPref();
$prm = e107::getUserPerms();
switch($key) // switch based on field.
switch($key) // switch based on field.
{
case 'user_class':
if ($row['user_class'])
@@ -1175,7 +1173,7 @@ class users
$tmp = explode(",",$row['user_class']);
while (list($key,$class_id) = each($tmp))
{
$text .= $frm->uc_label($class_id)."<br />\n";
$text .= $frm->uc_label($class_id)."<br />\n";
}
return $text;
}
@@ -1184,7 +1182,7 @@ class users
return "&nbsp;";
}
break;
case 'user_ip':
return $e107->ipDecode($row['user_ip']);
break;
@@ -1193,28 +1191,28 @@ class users
case 'user_status':
return $this->showUserStatus($row);
break;
case 'user_name':
return "<a href='".$e107->url->getUrl('core:user','main','func=profile&id='.$row['user_id'])."'>{$row['user_name']}</a>";
return "<a href='".$e107->url->getUrl('core:user','main','func=profile&id='.$row['user_id'])."'>{$row['user_name']}</a>";
break;
case 'user_perms': //TODO display link to popup window with editable perms.
// return $row[$key].'&nbsp;';
case 'user_perms': //TODO display link to popup window with editable perms.
// return $row[$key].'&nbsp;';
return $prm->renderPerms($row[$key],$row['user_id']);
break;
case 'user_ban' :
return ($row[$key] == 1) ? ADMIN_TRUE_ICON : ''; // We may want to show more of the status later
break;
}
switch($type) // switch based on type.
switch($type) // switch based on type.
{
case 'date':
return ($row[$key]) ? strftime($pref['shortdate'],$row[$key]).'&nbsp;' : '&nbsp';
break;
case 'boolean':
return ($row[$key] == 1) ? ADMIN_TRUE_ICON : '';
break;
@@ -1222,12 +1220,12 @@ class users
case 'user_status':
return $this->showUserStatus($row);
break;
break;
}
return $row[$key].'&nbsp;';
}
@@ -1238,7 +1236,7 @@ class users
$classObj = $e107->getUserClass();
$frm = new e_form();
$classes = $classObj->uc_get_classlist();
$assignClasses = array(); // Userclass list of userclasses that can be assigned
foreach ($classes as $key => $val)
@@ -1249,12 +1247,12 @@ class users
}
}
unset($assignClasses[0]);
$removeClasses = $assignClasses; // Userclass list of userclasses that can be removed
$removeClasses[0] = array('userclass_name'=>array('userclass_id'=>0, 'userclass_name'=>USRLAN_220));
if(count($assignClasses))
{
$uclasses = array(
@@ -1264,18 +1262,18 @@ class users
}
else
{
$uclasses = FALSE;
}
$uclasses = FALSE;
}
return $frm->batchoptions(
array(
'ban_selected' =>USRLAN_30,
'unban_selected' =>USRLAN_33,
'activate_selected' =>USRLAN_32,
'delete_selected' =>LAN_DELETE
),$uclasses
),$uclasses
);
}
@@ -1305,8 +1303,8 @@ class users
$var ['unveri']['text'] = USRLAN_138." ($unverified)";
$var ['unveri']['link'] = e_ADMIN.'users.php?unverified';
}
$var ['rank']['text'] = USRLAN_196;
$var ['rank']['link'] = e_ADMIN.'users.php?ranks';
$var ['ranks']['text'] = USRLAN_196;
$var ['ranks']['link'] = e_ADMIN.'users.php?ranks';
// $var['mailing']['text']= USRLAN_121;
// $var['mailing']['link']="mailout.php";
show_admin_menu(USRLAN_76,$action,$var);
@@ -1453,16 +1451,16 @@ class users
function user_add($user_data)
{
global $rs,$pref,$e_userclass;
$prm = e107::getUserPerms();
$list = $prm->getPermList();
$frm = e107::getForm();
$ns = e107::getRender();
$mes = e107::getMessage();
//TODO Better Password generation.
// ie. a "Generate" button, which will place the text into the text field automatically.
//TODO Better Password generation.
// ie. a "Generate" button, which will place the text into the text field automatically.
if (!is_object($e_userclass))
$e_userclass = new user_class;
$text = "<div>".$rs->form_open("post",e_SELF.(e_QUERY ? '?'.e_QUERY : ''),"adduserform")."
@@ -1500,14 +1498,14 @@ class users
".$frm->checkbox_label(USRLAN_171,'generatepassword', 1)."
</td>
</tr>
<tr>
<td>".USRLAN_63."</td>
<td>
".$rs->form_password("password2",40,"",20)."
</td>
</tr>
<tr>
<td>".USRLAN_64."</td>
<td>
@@ -1519,14 +1517,14 @@ class users
<td>Require Confirmation</td>
<td class='center'>".$frm->checkbox_label(USRLAN_181,'sendconfemail', 1)."</td>
</tr>";
//FIXME check what this is doing exactly.. is it a confirmation email (activation link) or just a notification?
// Give drop-down option to: 1) Notify User and Activate. 2) Notify User and require activation. 3) Don't Notify
if (!isset ($user_data['user_class']))
$user_data['user_class'] = varset($pref['initial_user_classes'],'');
$temp = $e_userclass->vetted_tree('class',array($e_userclass,'checkbox_desc'),$user_data['user_class'],'classes');
if ($temp)
{
$text .= "<tr style='vertical-align:top'>
@@ -1539,32 +1537,32 @@ class users
</div></td>
</tr>\n";
}
// Make Admin.
// Make Admin.
$text .= "<tr>
<td>".USRLAN_35."</td>
<td>
<a href='#set_perms' class='e-expandit'>Set Permissions</a>
<div class='e-hideme' id='set_perms' >\n";
$groupedList = $prm->getPermList('grouped');
foreach($groupedList as $section=>$list)
{
$text .= "\t\t<div class='field-section'><h4>".$prm->renderSectionDiz($section)."</h4>"; //XXX Lan - General
$text .= "\t\t<div class='field-section'><h4>".$prm->renderSectionDiz($section)."</h4>"; //XXX Lan - General
foreach($list as $key=>$diz)
{
$text .= $prm->checkb($key, '', $diz);
$text .= $prm->checkb($key, '', $diz);
}
$text .= "</div>";
}
$text .= "</div></td>
</tr>\n";
$text .= "
</table>
<div class='buttons-bar center'>
<input class='button' type='submit' name='adduser' value='".USRLAN_60."' />
@@ -1965,7 +1963,7 @@ class users
{
global $admin_log, $e_userclass;
$sql = e107::getDb();
$remuser = true;
$emessage = &eMessage::getInstance();
@@ -1973,14 +1971,14 @@ class users
{
$sql->db_Select("user","*","user_id={$userid} ");
$row = $sql->db_Fetch();
$curClass = varset($row['user_class']) ? explode(",",$row['user_class']) : array();
$curClass = varset($row['user_class']) ? explode(",",$row['user_class']) : array();
}
foreach ($uclass as $a)
{
$a = intval($a);
$this->check_allowed($a);
if($a !=0) // if 0 - then do not add.
if($a !=0) // if 0 - then do not add.
{
$curClass[] = $a;
}
@@ -1988,12 +1986,12 @@ class users
if($mode == "remove") // remove selected classes
{
$curClass = array_diff($curClass,$uclass);
$curClass = array_diff($curClass,$uclass);
}
if($mode == "clear") // clear all classes
{
// $curClass = array();
// $curClass = array();
}
$curClass = array_unique($curClass);
@@ -2145,21 +2143,34 @@ function updateRanks()
}
function show_ranks()
function showRanks()
{
global $pref,$emessage;
$e107 = e107 :: getInstance();
$frm = new e_form;
$e107 = e107::getInstance();
include_once (e_HANDLER.'file_class.php');
include_once (e_HANDLER.'level_handler.php');
require_once (e_HANDLER.'message_handler.php');
require_once (e_HANDLER."form_handler.php");
$frm = new e_form(true);
//enable inner tabindex counter
$f = new e_file;
$ranks = new e107UserRank;
$imageList = $f->get_files(e_IMAGE.'ranks','.*?\.(png|gif|jpg)');
/*
$daysregged = max(1, round((time() - $user_join) / 86400))."days";
$level = ceil((($user_forums * 5) + ($user_comments * 5) + ($user_chats * 2) + $user_visits)/4);
*/
$ranks = e107::getRank()->getRankData();
$tmp = e107::getFile()->get_files(e_IMAGE.'ranks', '.*?\.(png|gif|jpg)');
foreach($tmp as $k => $v){
$imageList[] = $v['fname'];
}
unset($tmp);
natsort($imageList);
$text = "
<form method='post' action='".e_SELF."?".e_QUERY."'>
";
/*
$config = array();
if ($e107->sql->db_Select('generic','gen_chardata',"gen_type='user_rank_config'",'default'))
if ($e107->sql->db_Select('generic','gen_chardata', "gen_type='user_rank_config'", 'default'))
{
$row = $e107->sql->db_Fetch(MYSQL_ASSOC);
$config = unserialize($row['gen_chardata']);
@@ -2173,17 +2184,21 @@ function show_ranks()
$fieldList['extended'][] = substr($field['Field'],5);
}
}
$fields = array(
'source' => array('title' => USRLAN_197, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'class' => 'left'),
'fieldName' => array('title' => USRLAN_198, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'class' => 'left'),
'operation' => array('title' => USRLAN_199, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'class' => 'left'),
'value' => array('title' => USRLAN_200, 'type' => 'int', 'width' => 'auto', 'thclass' => 'left', 'class' => 'left'),
);
$opArray = array('*','+','-');
$text .= "
<form method='post' action='".e_SELF."?".e_QUERY."'>
<table style='".ADMIN_WIDTH."'>
<tr>
<td class='label'>".USRLAN_197."</td>
<td class='label'>".USRLAN_198."</td>
<td class='control'>".USRLAN_199."</td>
<td class='control'>".USRLAN_200."</td>
</tr>
";
<fieldset id='core-userranks-list'>
<table cellpadding='0' cellspacing='0' class='adminlist'>".
$frm->colGroup($fields, array_keys($fields)).
$frm->thead($fields, array_keys($fields));
foreach ($fieldList['core'] as $k => $f)
{
$text .= "
@@ -2242,19 +2257,25 @@ function show_ranks()
";
}
$text .= '</table>';
*/
$e107->ns->tablerender('',$emessage->render());
$e107->ns->tablerender('Rank Calculation fields',$text);
$text = "
<table style='".ADMIN_WIDTH."'>
<tr>
<td class='label'>".USRLAN_207."</td>
<td class='label'>".USRLAN_208."</td>
<td class='label'>".USRLAN_209."</td>
<td class='label'>".USRLAN_210."</td>
<td class='label'>".USRLAN_211."</td>
</tr>
";
$info = $ranks->ranks['special'][1];
// $e107->ns->tablerender('Rank Calculation fields',$text);
$fields = array(
'type' => array('title' => USRLAN_207, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'class' => 'left'),
'rankName' => array('title' => USRLAN_208, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'class' => 'left'),
'lowThresh' => array('title' => USRLAN_209, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'class' => 'left'),
'langPrefix' => array('title' => USRLAN_210, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'class' => 'left'),
'rankImage' => array('title' => USRLAN_210, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'class' => 'left'),
);
$text .= "
<table cellpadding='0' cellspacing='0' class='adminlist'>".
$frm->colGroup($fields, array_keys($fields)).
$frm->thead($fields, array_keys($fields));
$info = $ranks['special'][1];
$val = $e107->tp->toForm($info['name']);
$pfx = ($info['lan_pfx'] ? "checked='checked'" : '');
$text .= "
@@ -2268,7 +2289,7 @@ function show_ranks()
<td class='control'>".RankImageDropdown($imageList,'calc_img[main_admin]',$info['image'])."</td>
</tr>
";
$info = $ranks->ranks['special'][2];
$info = $ranks['special'][2];
$val = $e107->tp->toForm($info['name']);
$pfx = ($info['lan_pfx'] ? "checked='checked'" : '');
$text .= "
@@ -2285,7 +2306,7 @@ function show_ranks()
<td colspan='5'>&nbsp;</td>
</tr>
";
foreach ($ranks->ranks['data'] as $k => $r)
foreach ($ranks['data'] as $k => $r)
{
$pfx_checked = ($r['lan_pfx'] ? "checked='checked'" : '');
$text .= "
@@ -2328,7 +2349,7 @@ function show_ranks()
}
function RankImageDropdown(& $imgList,$field,$curVal = '')
function RankImageDropdown(&$imgList, $field, $curVal = '')
{
$ret = "
<select class='tbox' name='{$field}'>
@@ -2336,8 +2357,8 @@ function RankImageDropdown(& $imgList,$field,$curVal = '')
";
foreach ($imgList as $img)
{
$sel = ($img['fname'] == $curVal ? "selected='selected'" : '');
$ret .= "\n<option {$sel}>{$img['fname']}</option>";
$sel = ($img == $curVal ? "selected='selected'" : '');
$ret .= "\n<option {$sel}>{$img}</option>";
}
$ret .= '</select>';
return $ret;

View File

@@ -155,6 +155,7 @@ class e107
'e_news_tree' => '{e_HANDLER}news_class.php',
'e_online' => '{e_HANDLER}online_class.php',
'e_parse' => '{e_HANDLER}e_parse_class.php',
'e_ranks' => '{e_HANDLER}e_ranks_class.php',
'e_upgrade' => '{e_HANDLER}e_upgrade_class.php',
'e_userperms' => '{e_HANDLER}user_handler.php',
'e_validator' => '{e_HANDLER}validator_class.php',
@@ -1068,6 +1069,15 @@ class e107
return self::getSingleton('e107_user_extended', true);
}
/**
* Retrieve online users handler singleton object
* @return e_online
*/
public static function getRank()
{
return self::getSingleton('e_ranks', true);
}
/**
* Retrieve online users handler singleton object
* @return e_online

View File

@@ -0,0 +1,169 @@
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2009 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
*
*
* $URL$
* $Id$
*/
if (!defined('e107_INIT')) { exit; }
class e_ranks
{
private $ranks;
private $userRanks;
public function __construct($force=true)
{
$this->ranks = array();
$this->userRanks = array();
$e107 = e107::getInstance();
//Check to see if we can get it from cache
if($force == false && ($this->ranks = $e107->ecache->retrieve_sys('nomd5_user_ranks')))
{
$this->ranks = $e107->arrayStorage->ReadArray($ranks);
}
else
{
//force is true, or cache doesn't exist, or system cache disabled, let's get it from table
$this->ranks = array();
if($e107->sql->db_Select('generic', '*', "gen_type = 'user_rank_data' ORDER BY gen_intdata ASC"))
{
$i=0;
while($row = $e107->sql->db_Fetch())
{
$tmp = array();
$tmp['name'] = $row['gen_ip'];
$tmp['thresh'] = $row['gen_intdata'];
$tmp['lan_pfx'] = $row['gen_user_id'];
$tmp['image'] = $row['gen_chardata'];
$tmp['id'] = $row['gen_id'];
if($row['gen_datestamp'])
{
$this->ranks['special'][$row['gen_datestamp']] = $tmp;
}
else
{
$this->ranks['data'][$i++] = $tmp;
}
}
}
$e107->ecache->set_sys('nomd5_user_ranks', $e107->arrayStorage->WriteArray($this->ranks, false));
}
}
public function getRankData()
{
return $this->ranks;
}
private function _getImage(&$info)
{
$img = $info['image'];
if($info['lan_pfx'] && strpos('_', $info['image']))
{
$_tmp = explode('_', $info['image'], 2);
$img = e_LANGUAGE.'_'.$_tmp[1];
}
return e_IMAGE_ABS.'ranks/'.$img;
}
function getRanks($userId)
{
$e107 = e107::getInstance();
if(!$userId && USER) { $userId = USERID; }
if(isset($this->userRanks[$userId]))
{
return $this->userRanks[$userId];
}
$ret = array();
$userData = get_user_data($userId);
if($userData['user_admin'])
{
if($userData['user_perms'] == '0')
{
//Main Site Admin
$data['special'] = "<img src='".$this->_getImage($this->ranks['special'][1])."' /><br />";
}
else
{
//Site Admin
$data['special'] = "<img src='".$this->_getImage($this->ranks['special'][2])."' /><br />";
}
}
$userData['user_daysregged'] = max(1, round((time() - $userData['user_join']) / 86400));
$level = $this->_calcLevel($userData);
$lastRank = count($this->ranks['data']) - 1;
$rank = false;
if($level <= $this->ranks['data'][0]['thresh'])
{
$rank = 0;
}
elseif($level >= $this->ranks['data'][$lastRank]['thresh'])
{
$rank = $lastRank;
}
else
{
for($i=0; $i < $lastRank; $i++)
{
if($level >= $this->ranks['data'][$i]['thresh'] && $level < $this->ranks['data'][($i+1)]['thresh'])
{
$rank = $i;
break;
}
}
}
if($rank !== false)
{
$data['name'] = '[ '.$e107->tp->toHTML($this->ranks['data'][$rank]['name'], FALSE, 'defs').' ]';
$img_title = ($this->ranks['data'][$rank]['name'] ? "title='".$this->ranks['data'][$rank]['name']."'" : '');
$data['pic'] = "<img {$img_title} src='".$this->_getImage($this->ranks['data'][$rank])."' /><br />";
}
$this->userRanks[$userId] = $data;
return $data;
}
private function _calcLevel(&$userData)
{
$forumCount = varset($userData['user_plugin_forum_posts'], 0) * 5;
$commentCount = $userData['user_comments'] * 5;
$chatCount = $userData['user_chats'] * 2;
$visitCount = $userData['user_visits'];
return ceil(($forumCount + $commentCount + $chatCount + $visitCount) / 4);
/*
global $pref;
$value = 0;
$calc = $pref['ranks_calc'];
$search = array();
$replace = array();
foreach(explode(',', $pref['ranks_flist']) as $f)
{
$search[] = '{'.$f.'}';
$replace[] = $userData['user_'.$f];
}
$_calc = trim(str_replace($search, $replace, $calc));
if($_calc == '') { return 0; }
$calc = '$userLevelValue = '.$_calc.';';
$value = eval($calc);
return $value;
*/
}
}
?>

View File

@@ -1,259 +0,0 @@
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2009 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
*
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/level_handler.php,v $
* $Revision$
* $Date$
* $Author$
*/
if (!defined('e107_INIT')) { exit; }
function get_level($user_id, $user_forums, $user_comments, $user_chats, $user_visits, $user_join, $user_admin, $user_perms, $pref, $fmod = "")
{
global $tp;
if (!$user_id) {
return FALSE;
}
if($fmod === TRUE)
{
$data['special'] = "<div class='spacer'>".IMAGE_rank_moderator_image."</div>";
$data[0] = "<div class='spacer'>".IMAGE_rank_moderator_image."</div>";
}
if ($user_admin)
{
if ($user_perms == "0")
{
$data['special'] = IMAGE_rank_main_admin_image."<br />";
$data[0] = IMAGE_rank_main_admin_image."<br />";
}
else
{
$data['special'] = IMAGE_rank_admin_image."<br />";
$data[0] = IMAGE_rank_admin_image."<br />";
}
}
$data[0] = "<span class='smalltext'>".LAN_195." #".$user_id."</span><br />";
$data['userid'] = "<span class='smalltext'>".LAN_195." #".$user_id."</span><br />";
$level_thresholds = ($pref['forum_thresholds'] ? explode(",", $pref['forum_thresholds']) : array(20, 100, 250, 410, 580, 760, 950, 1150, 1370, 1600));
$level_images = explode(",", $pref['forum_images']);
$level_names = explode(",", $pref['forum_levels']);
if(!$pref['forum_images'])
{
if(!$level_names[0])
{
$level_images = array("lev1.png", "lev2.png", "lev3.png", "lev4.png", "lev5.png", "lev6.png", "lev7.png", "lev8.png", "lev9.png", "lev10.png");
}
}
$daysregged = max(1, round((time() - $user_join) / 86400))."days";
$level = ceil((($user_forums * 5) + ($user_comments * 5) + ($user_chats * 2) + $user_visits)/4);
$ltmp = $level;
if ($level <= $level_thresholds[0]) {
$rank = 0;
}
else if($level >= ($level_thresholds[0]+1) && $level <= $level_thresholds[1]) {
$rank = 1;
}
else if($level >= ($level_thresholds[1]+1) && $level <= $level_thresholds[2]) {
$rank = 2;
}
else if($level >= ($level_thresholds[2]+1) && $level <= $level_thresholds[3]) {
$rank = 3;
}
else if($level >= ($level_thresholds[3]+1) && $level <= $level_thresholds[4]) {
$rank = 4;
}
else if($level >= ($level_thresholds[4]+1) && $level <= $level_thresholds[5]) {
$rank = 5;
}
else if($level >= ($level_thresholds[5]+1) && $level <= $level_thresholds[6]) {
$rank = 6;
}
else if($level >= ($level_thresholds[6]+1) && $level <= $level_thresholds[7]) {
$rank = 7;
}
else if($level >= ($level_thresholds[7]+1) && $level <= $level_thresholds[8]) {
$rank = 8;
}
else if($level >= ($level_thresholds[8]+1)) {
$rank = 9;
}
$data['pic'] = (file_exists(THEME."forum/".$level_images[$rank]) ? THEME."forum/".$level_images[$rank] : e_IMAGE."rate/".$level_images[$rank]);
$data['name'] = "[ ".$tp->toHTML($level_names[$rank], FALSE, 'defs')." ]";
if($level_names[$rank])
{
$data[1] = "<div class='spacer'>{$data['name']}</div>";
$img_title = "title='{$data['name']}'";
$data['pic'] = "<img src='".$data['pic']."' alt='' {$img_title} />";
}
else
{
$data['pic'] = "<img src='".$data['pic']."' alt='' />";
$data[1] = "<div class='spacer'>{$data['pic']}</div>";
}
if($data['special']) { $data[0] = $data['special'];}
return ($data);
}
class e107UserRank
{
var $ranks = array();
var $userRanks = array();
function e107UserRank()
{
$this->_loadRankData();
}
function getRankData()
{
return $this->ranks;
}
function _loadRankData($force=false)
{
$e107 = e107::getInstance();
//Check to see if we can get it from cache
if($force == false && ($ranks = $e107->ecache->retrieve_sys('nomd5_user_ranks')))
{
$this->ranks = $e107->arrayStorage->ReadArray($ranks);
}
else
{
//force is true, or cache doesn't exist, or system cache disabled, let's get it from table
$this->ranks = array();
if($e107->sql->db_Select('generic', '*', "gen_type = 'user_rank_data' ORDER BY gen_intdata ASC"))
{
$i=0;
while($row = $e107->sql->db_Fetch(MYSQL_ASSOC))
{
$tmp = array();
$tmp['name'] = $row['gen_ip'];
$tmp['thresh'] = $row['gen_intdata'];
$tmp['lan_pfx'] = $row['gen_user_id'];
$tmp['image'] = $row['gen_chardata'];
$tmp['id'] = $row['gen_id'];
if($row['gen_datestamp'])
{
$this->ranks['special'][$row['gen_datestamp']] = $tmp;
}
else
{
$this->ranks['data'][$i++] = $tmp;
}
}
}
$e107->ecache->set_sys('nomd5_user_ranks', $e107->arrayStorage->WriteArray($this->ranks, false));
}
}
function _getImage(&$info)
{
$img = $info['image'];
if($info['lan_pfx'] && strpos('_', $info['image']))
{
$_tmp = explode('_', $info['image'], 2);
$img = e_LANGUAGE.'_'.$_tmp[1];
}
return e_IMAGE_ABS.'ranks/'.$img;
}
function getRanks($userId)
{
$e107 = e107::getInstance();
if(!$userId && USER) { $userId = USERID; }
if(isset($this->userRanks[$userId]))
{
return $this->userRanks[$userId];
}
$ret = array();
$userData = get_user_data($userId);
if($userData['user_admin'])
{
if($userData['user_perms'] == '0')
{
//Main Site Admin
$data['special'] = "<img src='".$this->_getImage($this->ranks['special'][1])."' /><br />";
}
else
{
//Site Admin
$data['special'] = "<img src='".$this->_getImage($this->ranks['special'][2])."' /><br />";
}
}
$userData['user_daysregged'] = max(1, round((time() - $userData['user_join']) / 86400));
$level = $this->_calcLevel($userData);
$lastRank = count($this->ranks['data']) - 1;
$rank = false;
if($level <= $this->ranks['data'][0]['thresh'])
{
$rank = 0;
}
elseif($level >= $this->ranks['data'][$lastRank]['thresh'])
{
$rank = $lastRank;
}
else
{
for($i=0; $i < $lastRank; $i++)
{
if($level >= $this->ranks['data'][$i]['thresh'] && $level < $this->ranks['data'][($i+1)]['thresh'])
{
$rank = $i;
break;
}
}
}
if($rank !== false)
{
$data['name'] = '[ '.$e107->tp->toHTML($this->ranks['data'][$rank]['name'], FALSE, 'defs').' ]';
$img_title = ($this->ranks['data'][$rank]['name'] ? "title='".$this->ranks['data'][$rank]['name']."'" : '');
$data['pic'] = "<img {$img_title} src='".$this->_getImage($this->ranks['data'][$rank])."' /><br />";
}
$this->userRanks[$userId] = $data;
return $data;
}
function _calcLevel(&$userData)
{
global $pref;
$value = 0;
$calc = $pref['ranks_calc'];
$search = array();
$replace = array();
foreach(explode(',', $pref['ranks_flist']) as $f)
{
$search[] = '{'.$f.'}';
$replace[] = $userData['user_'.$f];
}
$_calc = trim(str_replace($search, $replace, $calc));
if($_calc == '') { return 0; }
$calc = '$userLevelValue = '.$_calc.';';
$value = eval($calc);
return $value;
}
}
?>

View File

@@ -11,7 +11,7 @@ class forum_shortcodes
var $postInfo;
var $thread;
var $forum;
function forum_shortcodes()
{
$this->e107 = e107::getInstance();
@@ -276,16 +276,17 @@ class forum_shortcodes
{
if (!$this->postInfo['post_user']) { return ''; }
$rankInfo = $this->e107->userRank->getRanks($this->postInfo['post_user']);
$rankInfo = e107::getRank()->getRanks($this->postInfo['post_user']);
if(!$parm) { $parm = 'name'; }
switch($parm)
{
case 'userid' :
return $this->sc_memberid();
break;
case 'special':
if(isset($rankInfo['special'])) { return $rankInfo['special']; }
if($this->forum->isModerator($this->postInfo['post_user']))
@@ -294,7 +295,7 @@ class forum_shortcodes
}
return '';
break;
default:
return varset($rankInfo[$parm], '');
break;

View File

@@ -59,8 +59,6 @@ if(isset($_GET['f']))
if($_GET['f'] != 'last') { $thread->init(); }
}
e107::getScParser();
require_once (e_HANDLER . 'level_handler.php');
if (!is_object($e107->userRank)) { $e107->userRank = new e107UserRank; }
require_once (e_PLUGIN . 'forum/forum_shortcodes.php');
setScVar('forum_shortcodes', 'thread', $thread);