News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Users Online in header

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

Previous topic - Next topic

Novice

Quote from: Novice on April 02, 2011, 08:35:06 AM
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,


Just the part in RED

It would also be nice if it was like an installable mod instead of just adding the code manually. I'm not a coder at all.

Novice

Quote from: ziycon on September 25, 2015, 07:59:57 AM
What are you looking to do?
Quote from: Novice on April 02, 2011, 08:35:06 AM
I would like to place "users active" in the header of each page that is displayed.

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,


The part colored in red is what we had done before and everyone really found it very convenient. No one needed to scroll to the bottom to see who is or was recently online. Any help in allowing us to accomplish this small change would be GREATLY appreciated.

Thanks!!
Terry O. / Novice

C. Davis

#22
It is extremely simple:

Inside of forums/Themes/core/index.template.php, look for:
function template_body_above()
{
global $context, $settings, $options, $scripturl, $txt, $modSettings;

replace it with:
function template_body_above()
{
global $context, $settings, $options, $scripturl, $txt, $modSettings, $sourcedir;

Next, find:
if (!empty($context['open_mod_reports']) && $context['show_open_reports'])
echo '
<li><a href="', $scripturl, '?action=moderate;area=reports">', sprintf($txt['mod_reports_waiting'], $context['open_mod_reports']), '</a></li>';
echo '
</ul>';


and replace it with this:
if (!empty($context['open_mod_reports']) && $context['show_open_reports'])
echo '
<li><a href="', $scripturl, '?action=moderate;area=reports">', sprintf($txt['mod_reports_waiting'], $context['open_mod_reports']), '</a></li>';
//Get users online
require_once($sourcedir . '/Subs-MembersOnline.php');
$membersOnlineOptions = array(
'show_hidden' => allowedTo('moderate_forum'),
'sort' => 'log_time',
'reverse_sort' => true,
);
$return = getMembersOnlineStats($membersOnlineOptions);
                        $active_message = str_replace('%1$d','15',$txt['users_active']);
echo '<li>', $active_message, '</li>';

echo '<li>
', implode(', ', $return['list_users_online']) , '</li>';
//End List
echo '</ul>';

Kindred

That is quite the hack...

while it may work, it is poorly coded for use in the script.
it uses hard coded text and calls to include a Sources file in the template


and it will have a good chance of having a major effect on a server for resources..
Сл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."

C. Davis

#24
Quote from: Kindred on September 30, 2015, 05:37:52 PM
That is quite the hack...

while it may work, it is poorly coded for use in the script.
it uses hard coded text and calls to include a Sources file in the template


and it will have a good chance of having a major effect on a server for resources..
Subs-MembersOnline.php is only 200 lines. 188 of it is used to get the online members.

Also, this is the EXACT SAME THING that happens in BoardIndex.php. See here:


Except, BoardIndex.php is only loaded when you're (surprise) on the board index.

This WILL NOT have 'a major effect on a server for resources'.

You made a good point about the hard coded text. I edited it out for a $txt variable.

Also, this isn't a mod, or else it would be configured in the way you are describing.

Novice

Folks I really do appreciate your responses and I really would like to get this done but, I haven't a clue as to what I'm looking at here. This is way over my head. I can't even make heads or tails of what your saying to each other. I can handle the install of mods but, this is more than a foreign language to me. I guess I should just let it go.

I'm really sorry for wasting your time,

Novice/Terry O.

C. Davis

Quote from: Novice on October 01, 2015, 07:38:01 AM
Folks I really do appreciate your responses and I really would like to get this done but, I haven't a clue as to what I'm looking at here. This is way over my head. I can't even make heads or tails of what your saying to each other. I can handle the install of mods but, this is more than a foreign language to me. I guess I should just let it go.

I'm really sorry for wasting your time,

Novice/Terry O.
All you have to do is locate the file on the server and edit the 2 things I posted above. Just ignore my response to Kendred. If you want to upload your index.template.php I could do it for you.

Novice

I tried the edit...I received a parse error at line 173 - Something about T echo


C. Davis

Quote from: Novice on October 01, 2015, 09:00:56 AM
I tried the edit...I received a parse error at line 173 - Something about T echo
Could you paste your line 173 here?

Also, ensure there is a single semicolon at the end of this line:

global $context, $settings, $options, $scripturl, $txt, $modSettings, $sourcedir;

Novice

#29
Here is a snapshot of the header after adding the code and REMOVING the semicolon after $modsettings. I moved the time to the top so the users online would remain at the bottom. I would like (if possible) to keep the text in alignment with the text above and get rid of the scrollbar at the right. Maybe lengthen (add a row or two) the header box to include the added line of info. Any suggestions?
(By the way...So far you rock!)

C. Davis

Look around this area:
if (!empty($context['open_mod_reports']) && $context['show_open_reports'])
echo '
<li><a href="', $scripturl, '?action=moderate;area=reports">', sprintf($txt['mod_reports_waiting'], $context['open_mod_reports']), '</a></li>';

and make sure this is gone:
echo '
</ul>';

Novice

The scrollbar has disappeared! There were two of those ( </ul>'; ) in the code. The one was at the end of the code for the time and date and the other was  after ( //End List ) and before this (}) bracket. I removed them both and everything seems to be working fine. Is there anything I can do to align the text? It's halfway in the bottom border shading and see how it creeps under the picture. See attachment.

C. Davis

Quote from: Novice on October 02, 2015, 02:14:52 PM
The scrollbar has disappeared! There were two of those ( </ul>'; ) in the code. The one was at the end of the code for the time and date and the other was  after ( //End List ) and before this (}) bracket. I removed them both and everything seems to be working fine. Is there anything I can do to align the text? It's halfway in the bottom border shading and see how it creeps under the picture. See attachment.
There needs to be one at the end. After //End list And before the }

Although, I'm not sure that will fix what you're describing.

Novice

I replaced it like you said... It did nothing for the positioning of the text in the header.

If this is as good as it gets, I'm satisfied. I have been weeks trying to get this to happen and if I had been a little better versed at making these changes it would have taken better part of (5) minutes to accomplish the entire change. I don't know for sure but, I'm guessing you have spent more time communicating with me sending messages than it took to whip up the code needed to do this. I, and the rest of our group is sincerely grateful for the time you gave helping us fixing this.

Terry O.
Novice
C. Davis Rocks!

C. Davis

Quote from: Novice on October 02, 2015, 06:57:24 PM
I'm guessing you have spent more time communicating with me sending messages than it took to whip up the code needed to do this.
This is true. I've got a few ideas for fixing the word wrap thing going on. I'll do a bit of testing and get back to you.

Novice


C. Davis

:/ I just realized why you had so much trouble getting my code to work. I thought you were using the Core Theme. From your screenshot, you're using the Curve theme. My bad.

Novice

What ever the default is, that's what I'm using. Yep I went and looked...It's Curve.

C. Davis

Right underneath:
//End List
echo '</ul>';

Add:
echo '
<style>
div#upper_section div.user ul {
    padding-left: 0px;
    float: left;
}
</style>';


That will fix it :)

Novice

How the h_ll do you get to know all of this? Worked Slick!

Advertisement: