1 (edited by foxmask 2008-01-31 17:48)

Topic: [extensions] User Online Today Colored

I've played with the new toy "extensions" and "hook"

a basic one display the users that were online today with a specific color for the admin

what do we need to proceed ?
1) open footer.php
2) line 92
replace

 if ($pun_config['o_users_online'] == '1'  )

by

 ($hook = get_hook('ft_get_users_online_colored')) ? eval($hook) : null;

    if ($pun_config['o_users_online'] == '1' and $hook == '' )

that's it ; the hook is in place wink

let's go to exploit it wink

in your extensions directory create a directory named online_today_colored
and create a manifest.xml  in this one with the following content :

<?xml version="1.0" encoding="utf-8"?>

<extension engine="1.0">
  <id>online_today_colored</id>
  <title>Users Online Today (Colored)</title>
  <version>1.0</version>
  <description>Display the users online list with the color of their group</description>
  <author>FoxMaSk</author>
  <minversion>1.3 Beta</minversion>
  <maxtestedon>1.3 Beta</maxtestedon>

  <note type="install">This will display the Online list of users in place of the default PunBB 1.3.</note>

  <install><![CDATA[

  ]]></install>

  <uninstall><![CDATA[


  ]]></uninstall>

  <hooks>
    <hook id="ft_get_users_online_colored"><![CDATA[
        $date = getdate(time());
        $todaystamp = mktime(0,0,0, $date['mon'], $date['mday'], $date['year']);
            
        // fetch the users that came today.
        $query = array(
            'SELECT'    => 'username, id, group_id, last_visit',
            'FROM'        => 'users',
               'WHERE'        => "last_visit >='".$todaystamp."'",
            'ORDER BY'    => 'last_visit DESC'
        );
        
        $result = $db->query_build($query, true) or error(__FILE__, __LINE__);
        $users_today = array();
        while ($pun_user_online_today = $db->fetch_assoc($result)) 
        {
            if ($pun_user_online_today['group_id'] == '1')
                $users_today[] .=  "\n\t\t\t\t".'<a href="'.pun_link($pun_url['user'],$pun_user_online_today['id']).'" title="Last visit of '.htmlspecialchars($pun_user_online_today['username']).' : '.format_time($pun_user_online_today['last_visit']).'"><span style="color: green;font-weight:bold;">'.$pun_user_online_today['username'].'</span></a>';
            else
                $users_today[] .=  "\n\t\t\t\t".'<a href="'.pun_link($pun_url['user'],$pun_user_online_today['id']).'" title="Last visit of '.htmlspecialchars($pun_user_online_today['username']).' : '.format_time($pun_user_online_today['last_visit']).'">'.$pun_user_online_today['username'].'</a>';
        }
       
    
        // Fetch users online info and generate strings for output
        $query = array(
            'SELECT'    => 'o.user_id, o.ident, u.group_id',
            'FROM'        => 'online AS o',
            'JOINS'     => array(
                    array(
                        'LEFT JOIN' => 'users AS u',
                        'ON'    => 'o.user_id=u.id'
                        ),
                    ),
               'WHERE'        => 'o.idle=0',
            'ORDER BY'    => 'o.ident'
        );

        $result = $db->query_build($query, true) or error(__FILE__, __LINE__);
        $num_guests = 0;
        $users = array();

        while ($pun_user_online = $db->fetch_assoc($result))
        {
            if ($pun_user_online['user_id'] > 1) {
                if ( $pun_user_online['group_id'] == '1' ) 
                    $users[] = '<a href="'.pun_link($pun_url['user'], $pun_user_online['user_id']).'"><span style="color:red; font-weight:bold;">'.htmlspecialchars($pun_user_online['ident']).'</span></a>';
                else 
                    $users[] = '<a href="'.pun_link($pun_url['user'], $pun_user_online['user_id']).'">'.htmlspecialchars($pun_user_online['ident']).'</a>';
                
            }
            else
                ++$num_guests;
        }
    
        echo "\t".'<div id="onlinelist">'."\n".
            "\t\t".'<h3>'. printf($lang_index['Online'], $num_guests, count($users)) .'</h3>'."\n";

        // If there are registered users logged in, list them
        if (count($users) > 0)
            echo "\t\t\t".'<p>'.implode(', ', $users).'</p>'."\n";

        echo "\t".'</div>'."\n";

        echo "\t".'<div id="onlinetoday">'."\n".
            "\t\t".'<h3> Online Today : ( '. count($users_today)  .') </h3>'."\n";
        if (count($users_today) > 0)
            echo "\t\t\t".'<p>'.implode(',', $users_today).'</p>'."\n";
        else
            echo '<p><em>None</em></p>'."\n";
            
        echo "\t".'</div>'."\n";

        
    ]]></hook>
  </hooks>
</extension>

then install it and have fun wink


It's very basic and i know it's not perfect by it's the first i made, i hope this could show you how easy it is to make one for septic people wink

Re: [extensions] User Online Today Colored

Suggest places for new hooks, don't direct people to modify their installs to add your hooks? wink

3 (edited by foxmask 2008-01-31 19:52)

Re: [extensions] User Online Today Colored

i already did it in the dedicated post wink

but the purpose of this hook is to illustrate how simple it is to make things like that .
so of course dont change your install until those kind of hook has been integrated .

regards.

Re: [extensions] User Online Today Colored

I know you did, but posting an extension and as a part of asking the user to add a hook defeats the purpose of the extension system: especially since this is a beta, you're better off asking, waiting, and then taking advantage of the official hook tongue

Re: [extensions] User Online Today Colored

so it is a good example of what we havent to do big_smile

Re: [extensions] User Online Today Colored

hi ,
I have changed the options for punbb 1.2.16, but the colours of the peopel, who are online , is not changed

7 (edited by jacofan 2009-05-10 14:15)

Re: [extensions] User Online Today Colored

because the extensions are for 1.3 only and not for 1.2