diff --git a/e107_admin/users.php b/e107_admin/users.php index 30fa2e581..549e16636 100644 --- a/e107_admin/users.php +++ b/e107_admin/users.php @@ -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." ".USRLAN_4.""); $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 = "
".$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]"). "\n"; - + while ($row = $sql->db_Fetch()) { @@ -1110,29 +1108,29 @@ class users ".$frm->checkbox('user_selected[]',$row['user_id'])." {$row['user_id']}"; - + 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 .= "".$this->renderValue($disp,$row)."\n"; } - + $text .= " ".$this->showUserOptions($row)."\n"; } - + $text .= " - +
".$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 .= "
"; - + $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)."
\n"; + $text .= $frm->uc_label($class_id)."
\n"; } return $text; } @@ -1184,7 +1182,7 @@ class users return " "; } 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 "{$row['user_name']}"; + return "{$row['user_name']}"; break; - - case 'user_perms': //TODO display link to popup window with editable perms. - // return $row[$key].' '; + + case 'user_perms': //TODO display link to popup window with editable perms. + // return $row[$key].' '; 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]).' ' : ' '; 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].' '; - + } @@ -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 = "
".$rs->form_open("post",e_SELF.(e_QUERY ? '?'.e_QUERY : ''),"adduserform")." @@ -1500,14 +1498,14 @@ class users ".$frm->checkbox_label(USRLAN_171,'generatepassword', 1)." - + ".USRLAN_63." ".$rs->form_password("password2",40,"",20)." - + ".USRLAN_64." @@ -1519,14 +1517,14 @@ class users Require Confirmation ".$frm->checkbox_label(USRLAN_181,'sendconfemail', 1)." "; - + //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 .= " @@ -1539,32 +1537,32 @@ class users
\n"; } - - // Make Admin. + + // Make Admin. $text .= " ".USRLAN_35." Set Permissions
\n"; - + $groupedList = $prm->getPermList('grouped'); - + foreach($groupedList as $section=>$list) { - $text .= "\t\t

".$prm->renderSectionDiz($section)."

"; //XXX Lan - General + $text .= "\t\t

".$prm->renderSectionDiz($section)."

"; //XXX Lan - General foreach($list as $key=>$diz) { - $text .= $prm->checkb($key, '', $diz); + $text .= $prm->checkb($key, '', $diz); } $text .= "
"; } $text .= "
\n"; - - + + $text .= " - +
@@ -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 = " +
+ "; +/* $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 .= " - - - - - - - - "; +
+ +
".USRLAN_197."".USRLAN_198."".USRLAN_199."".USRLAN_200."
". + $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 .= '
'; +*/ $e107->ns->tablerender('',$emessage->render()); - $e107->ns->tablerender('Rank Calculation fields',$text); - $text = " - - - - - - - - - "; - $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 .= " +
".USRLAN_207."".USRLAN_208."".USRLAN_209."".USRLAN_210."".USRLAN_211."
". + $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() "; - $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() "; - 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 = " '; return $ret; diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index d5754af93..6786a3adc 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -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 diff --git a/e107_handlers/e_ranks_class.php b/e107_handlers/e_ranks_class.php new file mode 100644 index 000000000..1f962b862 --- /dev/null +++ b/e107_handlers/e_ranks_class.php @@ -0,0 +1,169 @@ +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'] = "
"; + } + else + { + //Site Admin + $data['special'] = "
"; + } + } + + $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'] = "
"; + } + $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; + */ + } + +} + + +?> \ No newline at end of file diff --git a/e107_handlers/level_handler.php b/e107_handlers/level_handler.php deleted file mode 100644 index eacbd6628..000000000 --- a/e107_handlers/level_handler.php +++ /dev/null @@ -1,259 +0,0 @@ -".IMAGE_rank_moderator_image.""; - $data[0] = "
".IMAGE_rank_moderator_image."
"; - } - if ($user_admin) - { - if ($user_perms == "0") - { - $data['special'] = IMAGE_rank_main_admin_image."
"; - $data[0] = IMAGE_rank_main_admin_image."
"; - } - else - { - $data['special'] = IMAGE_rank_admin_image."
"; - $data[0] = IMAGE_rank_admin_image."
"; - } - } - $data[0] = "".LAN_195." #".$user_id."
"; - $data['userid'] = "".LAN_195." #".$user_id."
"; - - $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] = "
{$data['name']}
"; - $img_title = "title='{$data['name']}'"; - $data['pic'] = ""; - } - else - { - $data['pic'] = ""; - $data[1] = "
{$data['pic']}
"; - } - - 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'] = "
"; - } - else - { - //Site Admin - $data['special'] = "
"; - } - } - - $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'] = "
"; - } - $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; - } - -} - - -?> \ No newline at end of file diff --git a/e107_plugins/forum/forum_shortcodes.php b/e107_plugins/forum/forum_shortcodes.php index 2a3b77111..7d9470c4e 100644 --- a/e107_plugins/forum/forum_shortcodes.php +++ b/e107_plugins/forum/forum_shortcodes.php @@ -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; diff --git a/e107_plugins/forum/forum_viewtopic.php b/e107_plugins/forum/forum_viewtopic.php index 8f99180b8..3660bf492 100644 --- a/e107_plugins/forum/forum_viewtopic.php +++ b/e107_plugins/forum/forum_viewtopic.php @@ -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);
".RankImageDropdown($imageList,'calc_img[main_admin]',$info['image'])."