News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Users Online in header

Started by cnywrestling, February 03, 2011, 07:49:40 PM

Previous topic - Next topic

cnywrestling

I'm trying to get the users online from the main page info center up into the "above post" section of the template.  I can move the code ok and get it in there, but all the counts are zero and no users currently online show up there.  Can it be moved from the home page to another page, or am I just doing something wrong?
Thanks.

Matthew K.

Unfortunately, you cannot just move a piece of code from one place to another and expect it to work, as there are some other internal things that make it work that would also have to be moved.

I honestly would suggest using a portal for this, and modifying it to fit your needs.

Masterd

Well, you can use and modify ssi_logOnline();.

Novice

Excuse me gentlemen, if you would...I was hoping I could maybe have you get me pointed in the right direction. I'm interested in the same type of mod but,in SMF 1.1.13. I am a long way from being a php programmer so I will need time to absorb what I need to do. I searched everywhere in this site and this thread was the closest I have found so far.

Any help?

Thx-Novice

Arantor

Quote from: Novice on April 01, 2011, 08:05:05 PM
Excuse me gentlemen, if you would...I was hoping I could maybe have you get me pointed in the right direction. I'm interested in the same type of mod but,in SMF 1.1.13. I am a long way from being a php programmer so I will need time to absorb what I need to do. I searched everywhere in this site and this thread was the closest I have found so far.

Any help?

Thx-Novice


What, exactly are you trying to do, would be a good start?

Novice

#5
I would like to place "users active" in the header of each page that is displayed.

You have 0 messages, 0 are new
Show unread posts since last visit.
Show new replies to your posts.
There is one member awaiting approval.
Total time logged in: 20 days, 6 hours and 17 minutes.
Users active in past 15 minutes:
TKO,

Masterd

Wich theme are you using? Attach your Index.template.php here.

Novice

#7
I'm using the defaut SMF theme. I can get it to appear on the main index page but, can't seem to figure out how to get it to appear on all of them.

Masterd

Why didn't you attached Index.template.php?

Novice

I was there and now it's not...

Here is the file again.

Kays

Hi, just modifying Index.template.php ain't going to do it.

There's a block of code in BoardIndex.php starting at line 277 which populates the data for $context['list_users_online'], Which is what I assume you are trying to get to show. This code should be moved out to where it can be accessed on each page load.

One way might be to create a function and to call that function.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Novice

Well, this has me stuck in the mud. I'm not versed well enough to put all the pieces together. I do appreciate your input and hope that I haven't been too much of a bother.

Kays

OK, I didn't know what your comfort level was. :)

In Sources/Load.php, just before the closing ?> at the bottom add:


function showOnline()
{
global $context, $db_prefix, $scripturl, $user_info;

if(isset($context['list_users_online']))
{
$output = implode(', ', $context['list_users_online']);
return $output;
}

$result = db_query("
SELECT
lo.ID_MEMBER, lo.logTime, mem.realName, mem.memberName, mem.showOnline,
mg.onlineColor, mg.ID_GROUP, mg.groupName, IFNULL(banmem.ID_MEMBER, 0) AS isBanned
FROM {$db_prefix}log_online AS lo
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = lo.ID_MEMBER)
LEFT JOIN {$db_prefix}ban_items AS banmem ON (banmem.ID_MEMBER = lo.ID_MEMBER)
LEFT JOIN {$db_prefix}membergroups AS mg ON (mg.ID_GROUP = IF(mem.ID_GROUP = 0, mem.ID_POST_GROUP, mem.ID_GROUP))", __FILE__, __LINE__);

$context['list_users_online'] = array();
$context['num_guests'] = 0;
$context['num_buddies'] = 0;
$context['num_users_hidden'] = 0;

$context['show_buddies'] = !empty($user_info['buddies']);

while ($row = mysql_fetch_assoc($result))
{
if (empty($row['realName']))
{
$context['num_guests']++;
continue;
}
elseif (empty($row['showOnline']) && !allowedTo('moderate_forum'))
{
$context['num_users_hidden']++;
continue;
}

// Some basic color coding...
if (!empty($row['onlineColor']))
$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '" style="color: ' . $row['onlineColor'] . ';">' . $row['realName'] . '</a>';
else
$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a>';

$is_buddy = in_array($row['ID_MEMBER'], $user_info['buddies']);
if ($is_buddy)
{
$context['num_buddies']++;
$link = '<b>' . $link . '</b>';
}

$context['users_online'][$row['logTime'] . $row['memberName']] = array(
'id' => $row['ID_MEMBER'],
'username' => ($row['isBanned'] == 0 ? $row['memberName'] : '<del>' . $row['memberName'] . '</del>'),
'name' => $row['realName'],
'group' => $row['ID_GROUP'],
'href' => $scripturl . '?action=profile;u=' . $row['ID_MEMBER'],
'link' => $link,
'is_buddy' => $is_buddy,
'hidden' => empty($row['showOnline']),
);

$context['list_users_online'][$row['logTime'] . $row['memberName']] = empty($row['showOnline']) ? '<i>' . $link . '</i>' : $link;
}
mysql_free_result($result);

krsort($context['list_users_online']);

$output = implode(', ', $context['list_users_online']);
return $output;
}



Then index.template.php look for the following:


// But, let's always show minutes - Time wasted here: 0 minutes ;).
echo $context['user']['total_time_logged_in']['minutes'], $txt['totalTimeLogged4'], '<br />';
}


And add this after that code. (do note the closing bracket "}" in the above)


// Added to show who's online
echo '
', $txt[140], ':<br />', showOnline();


Hope that's what you wanted to accomplish. :)

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

DJ mixmun


Novice

Well, I braved the task of adding the code using Adobe Extended Script Toolkit. I had a parse error and it told me where it was and I tinkered around reading other parts of the code to see what might be out of place or missing on that line and sure enough there was a [ and a $ missing on one of the lines and once they were put into place, it took right off. And by the way it is exactly what I wanted to do.

By now you are probably laughing your backside off at my level of ignorance with working on .php code along with the terms I use to describe what went on, but I couldn't be prouder than a peacock for what interaction I have had in doing this.

The president of this coin club roped me into being the administrator four years ago and I have fixed and tweaked stuff to make things happen ever since. This kind of tweaking though was entirely out of my league.

I'm 52 with no programming experience at all. It is good people like yourself that help idiots like me do wonderful things with this program. My hat is off to you and there are 136 individuals from 37 countries that use the SMF forum at our URL that would like to thank you also.

Again, thanks!!
Terry O.
aka-Novice

Novice

Well, I'm back to ground zero here. Our forum has been updated to SMF 2.0.11 and this feature exists no more. I have solicited this community for assistance in replacing it in the code but, no takers for the task. I also solicited a third party that is directly associated with SMF and they were glad to assist me...for $350.00. Unfortunately this is more than I can afford to acquire this modification.

If there is anyone out there that could help me out with conjuring up the code for this, I will do what I can to add it to the necessary files if it can't be put into a regular mod install form. This thread shows the code KAYS wrote for me that worked in ver.1.1.12  I'm just not sure if this would be compatible with the new version.

ANY help would be greatly appreciated!

Terry O.
Novice (for real)

Kindred

Do note, there is no "directly associated with smf" who will charge like that.

The ONLY thing that is directly associated with smf is the charter membership donation (which does not cover mods)

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Novice

My apologies! I thought 2by2host was associated.

Again...my apologies.

ziycon


Kindred

well, if you are looking to do the same thing in 2.0.11 that was done previously --   then , yes, the code is going to have to be modified slightly -- some of the database details and calls changed between 1.1.x  and 2.0.x.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Advertisement: