09 Updated User Functions By pdq

Started by Mindless, July 21, 2012, 11:34:13 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Mindless

#1
Credits to pdq
simply add the code in user_functions.php and delete the existing get_user_class_name, get_user_class_color etc. and get_user_class_image.

Code (php) Select
/** class functions - pdq 2010 **/
$class_names = array(
        UC_USER                 => 'User',
        UC_POWER_USER           => 'Power User',
        UC_VIP                  => 'VIP',
        UC_UPLOADER             => 'Uploader',
        UC_MODERATOR            => 'Moderator',
        UC_ADMINISTRATOR        => 'Administrator',
        UC_SYSOP                => 'SysOp');
       
   $class_colors = array(
        UC_USER                 => '8E35EF',
        UC_POWER_USER           => 'f9a200',
        UC_VIP                  => '009F00',
        UC_UPLOADER             => '0000FF',
        UC_MODERATOR            => 'FE2E2E',
        UC_ADMINISTRATOR        => 'B000B0',
        UC_SYSOP                => '4080B0');

   $class_images = array(
        UC_USER                 => $TBDEV['baseurl'].'/pic/class/user.png',
        UC_POWER_USER           => $TBDEV['baseurl'].'/pic/class/power.png',
        UC_VIP                  => $TBDEV['baseurl'].'/pic/class/vip.png',
        UC_UPLOADER             => $TBDEV['baseurl'].'/pic/class/uploader.png',
        UC_MODERATOR            => $TBDEV['baseurl'].'/pic/class/moderator.png',
        UC_ADMINISTRATOR        => $TBDEV['baseurl'].'/pic/class/administrator.png',
        UC_SYSOP                => $TBDEV['baseurl'].'/pic/class/sysop.png');
       
   function get_user_class_name($class) {
        $class = (int)$class;
        if (!(valid_class($class)))
            return '';
        if (isset($class_names[$class]))
            return $class_names[$class];
        else
            return '';
    }
   
    function get_user_class_color($class) {
        $class = (int)$class;
        if (!(valid_class($class)))
            return '';
        if (isset($class_colors[$class]))
            return $class_colors[$class];
        else
            return '';
    }
   
    function get_user_class_image($class) {
        $class = (int)$class;
        if (!(valid_class($class)))
            return '';
        if (isset($class_images[$class]))
            return $class_images[$class];
        else
            return '';
    }
   
    function valid_class($class) {
        $class = (int)$class;
        return (bool)($class >= UC_MIN && $class <= UC_MAX);
    }

    function min_class($min = UC_MIN, $max = UC_MAX) {
        global $CURUSER;
        $minclass = (int)$min;
        $maxclass = (int)$max;
        if (!isset($CURUSER))
            return false;
        if (!valid_class($minclass) || !valid_class($maxclass))
            return false;
        if ($maxclass < $minclass)
            return false;
        return (bool)($CURUSER['class'] >= $minclass && $CURUSER['class'] <= $maxclass);
    }

    //function format_username($id, $username, $donor = 'no', $warned = 'no', $enabled = 'yes', $class = 0, $title = false,) {       
    function format_username($user, $icons = true) {
        global $TBDEV;
        $user['id']    = (int)$user['id'];
        $user['class'] = (int)$user['class'];
        if ($user['id'] == 0)
            return 'System';
        elseif ($user['username'] == '')
            return 'unknown['.$id.']';
        $username = '<span style="color:#'.get_user_class_color($user['class']).';">'.$user['username'].'</span>';
        $str = '<span style="white-space: nowrap;"><a href="'.$TBDEV['baseurl'].'/userdetails.php?id='.$user['id'].'">'.$username.'</a>';
        if ($icons != false) {
            $str .= ($user['donor'] == 'yes' ? '<img src="'.$TBDEV['baseurl'].'/pic/star.gif" alt="donor" title="donor" />' : '');
            $str .= ($user['warned'] != 'no' ? '<img src="'.$TBDEV['baseurl'].'/pic/warned.gif" alt="Warned" />' : '');
            $str .= ($user['enabled'] != 'yes' ? '<img src="'.$TBDEV['baseurl'].'/pic/disabled.gif" alt="Disabled" />' : '');
        }
        $str .= '</span>';
        return $str;
}


Add to config.php beside the others

Code (php) Select
/** class functions - pdq 2010 **/
define('UC_MIN', 0);   // minimum class
define('UC_MAX', 6);   // maximum class
define('UC_STAFF', 4); // start of staff classes

// examples of use

[code=php]/** old way **/
if (get_user_class() < UC_MODERATOR)
    header( "Location: {$TBDEV['baseurl']}/index.php" );

   
Code (php) Select
/** new way **/
if (!min_class(UC_MODERATOR)) // or just simply: if (!min_class(UC_STAFF))
    header( "Location: {$TBDEV['baseurl']}/index.php");


Code (php) Select
/** old way **/
// taken from forum active users
$forumusers = "";
      if (is_array($forum3))
      foreach ($forum3 as $arr) {
      if ($forumusers) $forumusers .= ",\n";
      $forumusers .= "<span style=\"white-space: nowrap;\">";
      $arr["username"] = "<font color='#" . get_user_class_color($arr['class']) . "'> " . htmlspecialchars($arr['username']) . "</font>";
      $donator = $arr["donor"] === "yes";
      $warned = $arr["warned"] === "yes";

      if ($CURUSER)
      $forumusers .= "<a href='{$TBDEV['baseurl']}/userdetails.php?id={$arr["id"]}'><b>{$arr["username"]}</b></a>";
      else
      $forumusers .= "<b>{$arr["username"]}</b>";
      if ($donator)
      $forumusers .= "<img src='{$TBDEV['pic_base_url']}star.png' alt='Donated' />";
      if ($warned)
      $forumusers .= "<img src='{$TBDEV['pic_base_url']}warned.png' alt='Warned' />";
      $forumusers .= "</span>";
      }

     
Code (php) Select
/** new way **/
// taken from forum active users
$forumusers = '';
      if (is_array($forum3))
      foreach ($forum3 as $arr) {
      if ($forumusers) $forumusers .= ",\n";
      $forumusers .= format_username($arr);
      }



Code (php) Select
// the use of these remains pretty much the same as old
get_user_class_name($user['class']);
get_user_class_color($user['class']);
get_user_class_image($user['class']);