Topic: User title + User custom title + User rank at the same time !

Hi wink

http://img355.imageshack.us/img355/8213/modtitres1ff.jpg

##
##
##        Mod title:  User title + User custom title + User rank
##
##      Mod version:  1.0.0
##   Works on PunBB:  1.2.11 (should work with all 1.2.*)
##     Release date:  2006-02-18
##           Author:  Fil1958 (http://multy.freezee.org/)
##
##      Description:  With this Mod you can see:
##                    - User title (Administrator, Moderator, Member,...)
##              - User custom title.
##              - User rank (Rank title or rank image)
##              At the same time !!
##
##   Affected files:  include/functions.php
##                    viewtopic.php
##                    profile.php
##              userlist.php
##              moderate.php
##
##       Affects DB:  No
##
##            Notes:  If someboby can translate this Mod in correct English it was great wink
##
##
##       DISCLAIMER:  Please note that "mods" are not officially supported by
##                    PunBB. Installation of this modification is done at your
##                    own risk. Backup your forum database and any and all
##                    applicable files before proceeding.
##
##

#
#---------[ OPEN ]---------------------------------------------------------
#

include/functions.php


#
#---------[ FIND (line: 444) ]----------------------------------------------
#

//
// Determines the correct title for $user
// $user must contain the elements 'username', 'title', 'posts', 'g_id' and 'g_user_title'
//
function get_title($user)
{
    global $db, $pun_config, $pun_bans, $lang_common;
    static $ban_list, $pun_ranks;

    // If not already built in a previous call, build an array of lowercase banned usernames
    if (empty($ban_list))
    {
        $ban_list = array();

        foreach ($pun_bans as $cur_ban)
            $ban_list[] = strtolower($cur_ban['username']);
    }

    // If not already loaded in a previous call, load the cached ranks
    if ($pun_config['o_ranks'] == '1' && empty($pun_ranks))
    {
        @include PUN_ROOT.'cache/cache_ranks.php';
        if (!defined('PUN_RANKS_LOADED'))
        {
            require_once PUN_ROOT.'include/cache.php';
            generate_ranks_cache();
            require PUN_ROOT.'cache/cache_ranks.php';
        }
    }

    // If the user has a custom title
    if ($user['title'] != '')
        $user_title = pun_htmlspecialchars($user['title']);
    // If the user is banned
    else if (in_array(strtolower($user['username']), $ban_list))
        $user_title = $lang_common['Banned'];
    // If the user group has a default user title
    else if ($user['g_user_title'] != '')
        $user_title = pun_htmlspecialchars($user['g_user_title']);
    // If the user is a guest
    else if ($user['g_id'] == PUN_GUEST)
        $user_title = $lang_common['Guest'];
    else
    {
        // Are there any ranks?
        if ($pun_config['o_ranks'] == '1' && !empty($pun_ranks))
        {
            @reset($pun_ranks);
            while (list(, $cur_rank) = @each($pun_ranks))
            {
                if (intval($user['num_posts']) >= $cur_rank['min_posts'])
                    $user_title = pun_htmlspecialchars($cur_rank['rank']);
            }
        }

        // If the user didn't "reach" any rank (or if ranks are disabled), we assign the default
        if (!isset($user_title))
            $user_title = $lang_common['Member'];
    }

    return $user_title;
}



#
#---------[ REPLACE WITH ]---------------------------------------------------
#

//
// Determines the correct title for $user
// $user must contain the elements 'username', 'title', 'posts', 'g_id' and 'g_user_title'
//
function get_title($user)
{
    global $db, $pun_config, $pun_bans, $lang_common;
    static $ban_list, $pun_ranks;

    // If not already built in a previous call, build an array of lowercase banned usernames
    if (empty($ban_list))
    {
        $ban_list = array();

        foreach ($pun_bans as $cur_ban)
            $ban_list[] = strtolower($cur_ban['username']);
    }

    // If not already loaded in a previous call, load the cached ranks
    if ($pun_config['o_ranks'] == '1' && empty($pun_ranks))
    {
        @include PUN_ROOT.'cache/cache_ranks.php';
        if (!defined('PUN_RANKS_LOADED'))
        {
            require_once PUN_ROOT.'include/cache.php';
            generate_ranks_cache();
            require PUN_ROOT.'cache/cache_ranks.php';
        }
    }

    // If the user has a custom title
    if ($user['title'] != '')
        $user_custom_title = pun_htmlspecialchars($user['title']);
    // If the user is banned
    if (in_array(strtolower($user['username']), $ban_list))
        $user_title = $lang_common['Banned'];
    // If the user group has a default user title
    else if ($user['g_user_title'] != '')
        $user_title = pun_htmlspecialchars($user['g_user_title']);
    // If the user is a guest
    else if ($user['g_id'] == PUN_GUEST)
        $user_title = $lang_common['Guest'];

    // Are there any ranks?
    if ($pun_config['o_ranks'] == '1' && !empty($pun_ranks))
    {
        @reset($pun_ranks);
        while (list(, $cur_rank) = @each($pun_ranks))
        {
            if (intval($user['num_posts']) >= $cur_rank['min_posts'])
                $user_rank = pun_htmlspecialchars($cur_rank['rank']);
        }
    }

        // If the user didn't "reach" any rank (or if ranks are disabled), we assign the default
        //if (!isset($user_title))
            //$user_title = $lang_common['Member'];
   

    return array( $user_title, $user_custom_title, $user_rank );
}

#
#---------[ OPEN ]---------------------------------------------------------
#

viewtopic.php

#
#---------[ FIND ]----------------------------------------------
#

// Retrieve the posts (and their respective poster/online status)
$result = $db->query('SELECT u.email, u.title, u.url, u.location, u.use_avatar, u.signature, u.email_setting, u.num_posts, u.registered, u.admin_note, p.id, p.poster AS username, p.poster_id, p.poster_ip, p.poster_email, p.message, p.hide_smilies, p.posted, p.edited, p.edited_by, g.g_id, g.g_user_title, o.user_id AS is_online FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id INNER JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id LEFT JOIN '.$db->prefix.'online AS o ON (o.user_id=u.id AND o.user_id!=1 AND o.idle=0) WHERE p.topic_id='.$id.' ORDER BY p.id LIMIT '.$start_from.','.$pun_user['disp_posts'], true) or error('Impossible de retrouver les informations des messages', __FILE__, __LINE__, $db->error());

#
#---------[ REPLACE WITH ]---------------------------------------------------
#

// Retrieve the posts (and their respective poster/online status)
$result = $db->query('SELECT u.email, u.title, u.url, u.location, u.use_avatar, u.signature, u.email_setting, u.num_posts, u.registered, u.admin_note, p.id, p.poster AS username, p.poster_id, p.poster_ip, p.poster_email, p.message, p.hide_smilies, p.posted, p.edited, p.edited_by, g.g_id, g.g_user_title, g.g_set_title, o.user_id AS is_online FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id INNER JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id LEFT JOIN '.$db->prefix.'online AS o ON (o.user_id=u.id AND o.user_id!=1 AND o.idle=0) WHERE p.topic_id='.$id.' ORDER BY p.id LIMIT '.$start_from.','.$pun_user['disp_posts'], true) or error('Impossible de retrouver les informations des messages', __FILE__, __LINE__, $db->error());

#
#---------[ FIND ]----------------------------------------------
#

        $user_title = get_title($cur_post);

#
#---------[ REPLACE WITH ]---------------------------------------------------
#

        $user_array = get_title($cur_post);
        $user_title = $user_array[0];
        $user_custom_title = $user_array[1];
        $user_rank = $user_array[2];

#
#---------[ FIND ]----------------------------------------------
#

        if ($pun_config['o_censoring'] == '1')
            $user_title = censor_words($user_title);

#
#---------[ REPLACE WITH ]---------------------------------------------------
#

        if ($pun_config['o_censoring'] == '1')
        {
            $user_title = censor_words($user_title);
            $user_custom_title = censor_words($user_custom_title);
        }

#
#---------[ FIND ]----------------------------------------------
#

    // If the poster is a guest (or a user that has been deleted)
    else
    {
        $username = pun_htmlspecialchars($cur_post['username']);
        $user_title = get_title($cur_post);

#
#---------[ REPLACE WITH ]---------------------------------------------------
#

    // If the poster is a guest (or a user that has been deleted)
    else
    {
        $username = pun_htmlspecialchars($cur_post['username']);
        $user_array = get_title($cur_post);
        $user_title = $user_array[0];

#
#---------[ FIND ]----------------------------------------------
#

                    <dt><strong><?php echo $username ?></strong></dt>
                    <dd class="usertitle"><strong><?php echo $user_title ?></strong></dd>
                    <dd class="postavatar"><?php echo $user_avatar ?></dd>

#
#---------[ REPLACE WITH ]---------------------------------------------------
#

                    <dt><strong><?php echo $username ?></strong></dt>
                    <dd class="usertitle"><strong><?php echo $user_title ?></strong></dd>
                    <dd class="usertitle"><?php if ($cur_post['g_set_title'] == '1') echo $user_custom_title ?></dd>
                    <dd class="postavatar"><?php echo $user_avatar ?></dd>
                    <dd class="usertitle"><?php echo $user_rank ?></dd>

#
#---------[ OPEN ]---------------------------------------------------------
#

userlist.php

#
#---------[ FIND ]----------------------------------------------
#

        $user_title_field = get_title($user_data);

#
#---------[ REPLACE WITH ]---------------------------------------------------
#

        $user_array = get_title($user_data);
        $user_title_field = $user_array[0];

#
#---------[ OPEN ]---------------------------------------------------------
#

profile.php

#
#---------[ FIND ]----------------------------------------------
#

        $user_title_field = get_title($user);

#
#---------[ REPLACE WITH ]---------------------------------------------------
#

    $user_array = get_title($user);
    $user_title_field = $user_array[0];

#
#---------[ OPEN ]---------------------------------------------------------
#

moderate.php

#
#---------[ FIND ]----------------------------------------------
#

            $user_title = get_title($cur_post);

#
#---------[ REPLACE WITH ]---------------------------------------------------
#

            $user_array = get_title($cur_post);
            $user_title = $user_array[0];

#
#---------[ SAVE and UPLOAD ]---------------------------------------------------
#

Enjoy !

Sorry I speak English like a Spanish cow :/
Multy Forums Free (Multi PunBB Project) (on stand by)
http://multy.forums.free.fr/forum_demo/

Re: User title + User custom title + User rank at the same time !

Looks nice, but seems and awful lot of code to display two or three more things tongue