1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-04 21:57:51 +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 = '';
@@ -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);
@@ -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

@@ -276,7 +276,8 @@ 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)

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);