MyBB Community Forums

Full Version: PHP help please once more
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
So I have this code that gets today top poster not is it possible to use templates conditional to show a message on post bit and user profile when the user is returned by this code as top poster?

function today()
{
    global $db, $mybb, $today_today;
    
        $todaytime = TIME_NOW - 86400;
        $query = $db->query("SELECT u.uid,u.username,u.displaygroup,u.usergroup,u.avatar,COUNT(*) AS ptoday FROM ".TABLE_PREFIX."posts p LEFT JOIN ".TABLE_PREFIX."users u ON (p.uid=u.uid) WHERE p.dateline > $todaytime GROUP BY p.uid ORDER BY ptoday DESC LIMIT 1");
        $today_today = '<table border="0" cellspacing="0" cellpadding="0" width="100%">';
        while($user = $db->fetch_array($query))
        {
            $posts = $user['ptoday'];
            if($user['avatar'] != '')
            {
                $user['avatar'] = $user['avatar'];
            }
            else
            {
                $user['avatar'] = "./images/default_avatar.gif";
            }
            
            $userlink = build_profile_link($user['username'], $user['uid']);
            $user['username'] = format_name($user['username'], $user['usergroup'], $user['displaygroup']);
                $ava = '<img src="'.$user['avatar'].'" 	width="42px" height="42px">';
                $today_today .= '<tr><td 	width="50px">'.$ava.'</td><td align="left">'.$userlink.'</td><td align="left">'.$posts.'</td></tr>';
            }
        $today_today .= '</table>';
        
    }
Why dont you just use Conditions in your own code?

Like:

if (X = foo)
{
return ".Bar.";
}
Thank buddy but I am very bad at PHP please explain in more detail.

I am trying to do something like this
<if ($post['profilelink'] || ($script == 'poster.php' && $user['username'])) then>
Please explain more what you are doing! I cant understand Smile

Also why are you using function today()?
Thank, OK.

I use this code/plugin to show today top poster on my index page.

But I also what to show a text next to the user avatar in "user profile" and "postbit" when the user is a top poster

Quote:Also why are you using function today()?
//Add hook for index top posters
$plugins->add_hook('index_start', 'today');
Oh then, add hook to postbit also and then you can display the user.
But what conditional should I use please
Okay. So:

1. Add Hook to Postbit & Index_Start

Then create the new function (with same name as HOOK):

function NAME()
{
        global $db, $mybb, $today_today;
    
        $todaytime = TIME_NOW - 86400;
        $query = $db->query("SELECT u.uid,u.username,u.displaygroup,u.usergroup,u.avatar,COUNT(*) AS ptoday FROM ".TABLE_PREFIX."posts p LEFT JOIN ".TABLE_PREFIX."users u ON (p.uid=u.uid) WHERE p.dateline > $todaytime GROUP BY p.uid ORDER BY ptoday DESC LIMIT 1");

        while($poster = $db->fetch_array($query))
        {
            $posts = $poster['ptoday'];
            if($poster['avatar'] != '')
            {
                $poster['avatar'] = $poster['avatar'];
            }
            else
            {
                $poster['avatar'] = "./images/default_avatar.gif";
            }
            
            $poster['link'] = build_profile_link($poster['username'], $poster['uid']);
            $poster['username'] = format_name($poster['username'], $poster['usergroup'], $poster['displaygroup']);
            $poster['avatar_img'] = '<img src="'.$poster['avatar'].'"     width="42px" height="42px">';
        }

        if($mybb->user['uid'] == $poster['uid'])
        {
           //PUT YOUR HTML HERE!
           $return = "You are today's top poster with {$poster['ptoday']} posts!";
           // SOME MORE HTML
           $return .= " Congrats!";
           return $return;
        }
} 
Wow this is awesome just one question please, what should I put into postbit that will connect to this plugin? I was using {$today_today}
Well.. I looked into it and I created a new plugin. However I couldn't do that for postbit, but I did add support for Header Smile

This plugin adds a template "tp_topposter" in a new group called Top Poster Templates. So you can edit it directly!

Here:

[attachment=30883]

=================================

A word about this plugin:

- This plugin is made by me, I did not use a single stuff from Pars' (MyBBIran.com) code.

By downloading this plugin, you agree
- NOT TO REDISTRIBUTE IT.
- REMOVE MY NAME
Pages: 1 2