MyBB Community Forums

Full Version: Use {$onlinemembers} In Footer
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I know I asked this like 2 times already and I am sorry but I seem to can't get a answer or find out myself.

I want to use {$onlinemembers} in the footer just to display the online usernames of those users who are online I prefer to have this done by a plugin because its for a custom theme but I will make core edits if needed.
here is a jQuery method which can be tried in the footer template
<script type="text/javascript">
    jQuery(function(){ 
	var url = location.pathname; 
	if (url.indexOf('index.php') > -1){} else {
    jQuery(".onlinemembers").load("{$mybb->settings['bburl']}/index.php #boardstats_e");}
    }); </script>
   <table cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder onlinemembers">
</table>
Shall I give you a quick nasty core edit?

Open index.php, go to line number  381 and find:
$plugins->run_hooks('index_end');

Add the following line before that:
$cache->update('onmems', $onlinemembers);

Save the file.

Now open global.php, go to line 763 and find:
eval('$footer = "'.$templates->get('footer').'";');

Add the following line before that:
$onmems = $cache->read('onmems');

Save the file.

Now you can use {$onmems} to your footer template and it will show online members.

Note:
As I said its a quick nasty core edit this is not the way it should be done. The proper way is to mimic the whole function to build the list with all good queries which I have avoided. Drawback of this method is:
  1. As long as someone not accessing index.php for atleast once; the footer will not show the list.
  2. The cache will be updated everytime someone is accessing index.php. If no one access index.php for a long time the footer will still show outdated incorrect data. But its a rare case as its your index.php Big Grin
(2018-04-17, 04:18 AM)effone Wrote: [ -> ]Shall I give you a quick nasty core edit?

Open index.php, go to line number  381 and find:
$plugins->run_hooks('index_end');

Add the following line before that:
$cache->update('onmems', $onlinemembers);

Save the file.

Now open global.php, go to line 763 and find:
eval('$footer = "'.$templates->get('footer').'";');

Add the following line before that:
$onmems = $cache->read('onmems');

Save the file.

Now you can use {$onmems} to your footer template and it will show online members.

Note:
As I said its a quick nasty core edit this is not the way it should be done. The proper way is to mimic the whole function to build the list with all good queries which I have avoided. Drawback of this method is:
  1. As long as someone not accessing index.php for atleast once; the footer will not show the list.
  2. The cache will be updated everytime someone is accessing index.php. If no one access index.php for a long time the footer will still show outdated incorrect data. But its a rare case as its your index.php Big Grin

Haven't tried it yet but is there away to turn that into a plugin? IDC that it is a core edit just want a plugin just in case I ever release the theme.

(2018-04-17, 04:05 AM).m. Wrote: [ -> ]here is a jQuery method which can be tried in the footer template
<script type="text/javascript">
    jQuery(function(){ 
	var url = location.pathname; 
	if (url.indexOf('index.php') > -1){} else {
    jQuery(".onlinemembers").load("{$mybb->settings['bburl']}/index.php #boardstats_e");}
    }); </script>
   <table cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder onlinemembers">
</table>

Do I just paste it into the footer? Because I did that and nothing happened.
^ if you are using SEF / SEO URLs then given code needs to be improved.

Thanks effone for the alert through PM Smile
Its easy to convert it to a plugin but you should not include the method I stated to your product which is meant to be served to mass.
The method is improper and a way around. Sorry.
though not optimized,
suggested jQuery code can be used along with template conditionals plugin

code can be like below
<if THIS_SCRIPT != "index.php" then>
<script type="text/javascript">
    jQuery(function(){ 
	jQuery(".onlinemembers").load("{$mybb->settings['bburl']}/index.php #boardstats_e");
    }); </script>
   <table cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder onlinemembers">
</table>
</if>
The fact is, .m.'s solution is too powerful. But it is pulling out the total table of statistics, not the {$onlinemembers} part only, which you need. getting only that part you can edit index_whosonline template:

{$onlinemembers}

to

<span id="onlinemembers">{$onlinemembers}</span>

and add this to footer template:
<script>jQuery(function(){jQuery(".onlinemembers").load("{$mybb->settings['bburl']}/index.php #onlinemembers")});</script>
<div class="onlinemembers"></div>
Sorry, I can't get any of your guys methods to work
The provided codes are tested. 'Not working' doesn't show a guideline to helpers for further assistance.
Pages: 1 2