Topic: Rank Icons (Pips) for 1.3

Hi everyone,

I'm in the process of setting up the latest version of PunBB to replace my old 1.2.15 site.  I just love the new version, especially the extensions.  So far, I've managed to find an extension for just about everything I need, but the one thing I cannot find, is a way to add Pips, dependent on a user's rank.

I really don't care if it's an extension or a mod that requires a bit of code editing, I just want the pips!!   big_smile

I've searched high and low and googled until my fingers bled, but I just can't find anything.  Can anyone point me in the right direction?

Re: Rank Icons (Pips) for 1.3

Hi,
there's this extension that needs some tweaking....

Rich Pedley wrote:

Group Images

Adds images for user groups based on number of posts. Several images are included, but you can easily add more.

[code=xml]<?xml version="1.0" encoding="UTF-8"?>

<extension engine="1.0">
    <id>egroups_imgs</id>
    <title>Group Images Beta</title>
    <version>0.5</version>
    <description>WARNING: use at your own risk (written for 1.3 beta) Adds images for user groups based on number of posts. Set images on the Users > Groups page. Set number to display on the Users > Ranks page.</description>
    <author>Rich Pedley</author>
    <minversion>1.3 Beta</minversion>
    <maxtestedon>1.3 Beta</maxtestedon>
    <install><![CDATA[
        if (!array_key_exists('o_egroup_imgs', $forum_config)){
            $forum_db->query("INSERT INTO ".$forum_db->prefix."config (conf_name, conf_value) VALUES ('o_egroup_imgs', '1')");
            $forum_db->add_field('groups', 'g_img', 'VARCHAR(255)', '');
            $forum_db->add_field('ranks', 'img', 'VARCHAR(2)', '');
        }
    ]]>
    </install>
    <uninstall><![CDATA[
        $forum_db->query("DELETE FROM ".$forum_db->prefix."config WHERE conf_name = 'o_egroup_imgs'");
        $forum_db->drop_field($forum_db->prefix.'groups', 'g_img');
        $forum_db->drop_field($forum_db->prefix.'ranks', 'img');
    ]]>
    </uninstall>
    <hooks>
        <hook id="agr_start, ark_start"><![CDATA[
        if(file_exists($ext_info['path'].'/lang/'.$forum_user['language'].'.php'))
            require $ext_info['path'].'/lang/'.$forum_user['language'].'.php';
        else
            require $ext_info['path'].'/lang/English.php';
        ]]>
        </hook>

        <hook id="ark_add_rank_qr_add_rank"><![CDATA[
            $group_image=$_POST['new_group_image'];
            $query['INSERT'].=', img';
            $query['VALUES'].=',\''.$forum_db->escape($group_image).'\'';
        ]]>
        </hook>

        <hook id="ark_update_qr_update_rank"><![CDATA[
            $group_image=$_POST['group_image'][$id];
            $query['SET'].=",img='".$forum_db->escape($group_image)."'";
        ]]>
        </hook>   
        <hook id="ark_pre_add_rank_submit"><![CDATA[
        ?>
        <div class="mf-field select">
            <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span class="fld-label"><?php echo $lang_eg_imgs['Rank Images']; ?></span></label><br />
            <span class="fld-input"><select id="fld<?php echo $forum_page['fld_count'] ?>" name="new_group_image">
            <option value="">0</option>
            <?php
            for($i=1;$i<=10;$i++){
                echo '<option value="'.$i.'">'.$i.'</option>'."\n";
            }
            ?>
            </select>
            </span>
        </div>
        <?php
       
        ]]>
        </hook>
        <hook id="ark_pre_edit_cur_rank_submit"><![CDATA[
        ?>
        <div class="mf-field select">
            <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span class="fld-label"><?php echo $lang_eg_imgs['Group Image']; ?></span></label><br />
            <span class="fld-input"><select id="fld<?php echo $forum_page['fld_count'] ?>" name="group_image[<?php echo $cur_rank['id'] ?>]">
            <option value="">0</option>
            <?php
            for($i=1;$i<=10;$i++){
                $sel='';
                if($cur_rank['img']==$i) $sel=' selected="selected"';
                echo '<option value="'.$i.'"'.$sel.'>'.$i.'</option>'."\n";
            }
            ?>
            </select>
            </span>
        </div>
        <?php
        ]]>
        </hook>
        <hook id="agr_add_end_qr_add_group"><![CDATA[
            $group_image=$_POST['group_image'];
            $query['INSERT'].=', g_img';
            $query['VALUES'].=',\''.$forum_db->escape($group_image).'\'';
        ]]>
        </hook>

        <hook id="agr_edit_end_qr_update_group"><![CDATA[
            $group_image=$_POST['group_image'];
            $query['SET'].=",g_img='".$forum_db->escape($group_image)."'";
        ]]>
        </hook>   
        <hook id="agr_add_edit_group_pre_basic_details_fieldset_end"><![CDATA[
        function get_group_icons(){
            global $ext_info;
            $eranks = array();
            if($handle = opendir($ext_info['path'].'/icons/')){
                /* This is the correct way to loop over the directory. */
                while (false !== ($file = readdir($handle))) {
                    if($file!='.' && $file!='..')
                        $eranks[]=$file;
                }
                closedir($handle);
            }
            return $eranks;
        }
        $group_icons=get_group_icons();
        ?>
        <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">       
        <div class="sf-box select">
            <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span class="fld-label"><?php echo $lang_eg_imgs['Group Image']; ?></span></label><br />
            <span class="fld-input"><select id="fld<?php echo $forum_page['fld_count'] ?>" name="group_image">
            <option value=""><?php echo $lang_eg_imgs['None']; ?></option>
            <?php
            $group_icon_options='';
            foreach ($group_icons as $k){
                $sel='';
                if($group['g_img']==$k) $sel=' selected="selected"';
                $group_icon_options.='<option value="'.$k.'"'.$sel.' style="background: url('.$ext_info['url'].'/icons/'.$k.') no-repeat center left;padding-left:12px;">'.$k.'</option>'."\n";
            }
            echo $group_icon_options;
            ?>
            </select>
            </span>
        </div>
        </div>
        <?php
        ]]>
        </hook>
       
        <hook id="vt_qr_get_posts"><![CDATA[
            $query['SELECT'].=', g.g_img AS groupimage';
            $gresult=$forum_db->query("SELECT min_posts, img FROM ".$forum_db->prefix."ranks ORDER BY min_posts DESC");
        ]]></hook>
       
        <hook id="vt_row_pre_post_actions_merge"><![CDATA[
            if ($cur_post['poster_id'] > 1 && $cur_post['groupimage']!='' && !isset($groupicon[$cur_post['poster_id']])){
                while ($granks = $forum_db->fetch_assoc($gresult)){
                    //reset just in case..
                    $rank_markup='';
                    if(intval($cur_post['num_posts']) >= intval($granks['min_posts'])){
                        for($i=1;$i<=intval($granks['img']);$i++){
                            $rank_markup.='<img src="'.$ext_info['url'].'/icons/'.$cur_post['groupimage'].'" height="10" width="10" style="margin-left:1px;" alt="" />';
                        }
                        $rank_icon_splice = array('rankicon'=>'<li class="userrankicon">'.$rank_markup.'</li>');
                        if (isset($forum_page['author_ident']['avatar'])){
                            array_splice($forum_page['author_ident'], 3, 0, $rank_icon_splice);
                        }else{
                            array_splice($forum_page['author_ident'], 2, 0, $rank_icon_splice);
                        }
                        break;
                    }
                }
                //reset array and set this user as being parsed
                mysql_data_seek($gresult,0);
                $groupicon[$cur_post['poster_id']]='set';
            }
        ]]></hook>
    </hooks>
</extension>
[/code]

Re: Rank Icons (Pips) for 1.3

Thank you for the reply.  I actually did come across that extension, but it seems to be geared towards setting a specific image for each rank.  What I'm looking for is something that will add 1 pip for each rank achieved.  I have this on my current forum, and I think it was a mod that I found in the old wiki, but I'm not sure.

Anyway, here is an example of what I'm after.  The pip itself can be whatever icon I decide to use.

Rank 1 ~ 0-50 posts: no pips
Rank 2 ~ 51-100 posts: 1 pip
Rank 3 ~ 101-300 posts: 2 pips
Etc.

Are you aware of anything like that?  Or were you suggesting that I could use Group Images extension to do this, but it would require some tweaking first?

Thanks again.

Re: Rank Icons (Pips) for 1.3

I'm not aware of any such extension...
Yes, I was suggesting you use group images, if it works...

Will be good if you find the mod code and post it here for anyone who wants to help...

Re: Rank Icons (Pips) for 1.3

Ok, I'll see if I can track it down.

And I guess if the Group Images extension does work, I can just make little images that look like pips.  smile

Re: Rank Icons (Pips) for 1.3

Ok, I found this thread, and the 5th post down has the same code that I used.
http://punbb.informer.com/forums/viewtopic.php?id=7293

shaul26 wrote:

I talked with the mod creator (Ju) very nice person!

and he told me what to do..

this is the mod:

open "viewtopic.php"

find:

    $post_count++;
    $user_avatar = '';
    $user_info = array();
    $user_contacts = array();
    $post_actions = array();
    $is_online = '';
    $signature = '';

    // If the poster is a registered user.
    if ($cur_post['poster_id'] > 1)
    {

after add:

        $rank_pips = "";
        if($cur_post['num_posts'] > 5000) { $num_pips = 10; }
        elseif($cur_post['num_posts'] > 3000) { $num_pips = 9; }
        elseif($cur_post['num_posts'] > 2000) { $num_pips = 8; }
        elseif($cur_post['num_posts'] > 1000) { $num_pips = 7; }
        elseif($cur_post['num_posts'] > 500) { $num_pips = 6; }
        elseif($cur_post['num_posts'] > 300) { $num_pips = 5; }
        elseif($cur_post['num_posts'] > 100) { $num_pips = 4; }
        elseif($cur_post['num_posts'] > 50) { $num_pips = 3; }
        elseif($cur_post['num_posts'] > 10) { $num_pips = 2; }
        else { $num_pips = 1; }

        for($pip=0; $pip<$num_pips; $pip++) {
            $rank_pips .= '<img src="img/pip.gif" alt="" />';
        }

Find:

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

After, add :

                    <?php echo "<dd class=\"usertitle\">".$rank_pips."</dd>\n"; ?>

Save viewtopic.php and upload (overwrite)

I didn't creat this mod... all the credit goes to "Ju" !

I suppose I could use that as a starting point and mod 1.3 to do the same thing.  When I first used that code several years ago, I didn't know anything about PHP, but I've been scripting in PHP for a couple of years now and can probably figure it out.

I might even try my hand at making a real extension for this if I can locate any guides/tutorials on writing extensions.   smile