Code to auto-refresh the who's online page

Started by Trevor Hale, November 11, 2009, 06:52:49 PM

Previous topic - Next topic

darrenbeige

That's correct. The code should be active. Remember, you won't see any change if nobody's currently active. If you do want me to check that the code is working correctly, send me the URL and I can run a Firebug check on it.

Trevor Hale

Thanks Darren,  I see you in there now..  Do you think it is working correctly?

Trev

darrenbeige

#22
No, I know what's wrong. You already have jQuery running, but you obviously didn't know. That changes things slightly. Instead of the current code use:


<?php
echo '
<script type="text/javascript">
function grabLatestWho() {
    $("#whos_online").load(window.location.href + " #whos_online");
    }
$(document).ready(function () {
setInterval("grabLatestWho()", 15000);
});
</script>'
;

?>


Trevor Hale

Ok, let me see if I make that change and I will let you know..  Put it in the same spot then?

Trev

darrenbeige

Same place should do. If it doesn't then I'm gonna have to move it to script.js, but I don't wanna do that for efficiency.

You are currently showing a parse error BTW.

Trevor Hale

<?php
// Version: 2.0 RC2; Who

// The only template in the file.
function template_main()
{
global $context$settings$options$scripturl$txt;

// Display the table header and linktree.
echo '
<div class="main_section" id="whos_online">
<form action="'
$scripturl'?action=who" method="post" id="whoFilter" accept-charset="'$context['character_set'], '">
<h4 class="titlebg margin_lower"><span class="left"></span>
'
$txt['who_title'], '
</h4>
<div class="topic_table" id="mlist">
<div class="pagesection">
<div class="pagelinks">'
$txt['pages'], ': '$context['page_index'], '</div>
</div>
<table class="table_grid" cellspacing="0">
<thead>
<tr class="catbg">
<th scope="col" class="smalltext" width="40%"><a href="'
$scripturl'?action=who;start='$context['start'], ';show='$context['show_by'], ';sort=user'$context['sort_direction'] != 'down' && $context['sort_by'] == 'user' '' ';asc''" rel="nofollow">'$txt['who_user'], ' '$context['sort_by'] == 'user' '<img src="' $settings['images_url'] . '/sort_' $context['sort_direction'] . '.gif" alt="" />' '''</a></th>
<th scope="col" class="smalltext" width="10%"><a href="'
$scripturl'?action=who;start='$context['start'], ';show='$context['show_by'], ';sort=time'$context['sort_direction'] == 'down' && $context['sort_by'] == 'time' ';asc' '''" rel="nofollow">'$txt['who_time'], ' '$context['sort_by'] == 'time' '<img src="' $settings['images_url'] . '/sort_' $context['sort_direction'] . '.gif" alt="" />' '''</a></th>
<th scope="col" class="smalltext" width="50%">'
$txt['who_action'], '</th>
</tr>
</thead>
<tbody>'
;

// For every member display their name, time and action (and more for admin).
$alternate 0;

foreach ($context['members'] as $member)
{
// $alternate will either be true or false. If it's true, use "windowbg2" and otherwise use "windowbg".
echo '
<tr class="windowbg'
$alternate '2' '''">
<td>'
;

// Guests don't have information like icq, msn, y!, and aim... and they can't be messaged.
if (!$member['is_guest'])
{
echo '
<span class="contact_info floatright">
'
$context['can_send_pm'] ? '<a href="' $member['online']['href'] . '" title="' $member['online']['label'] . '">' ''$settings['use_image_buttons'] ? '<img src="' $member['online']['image_href'] . '" alt="' $member['online']['text'] . '" align="bottom" />' $member['online']['text'], $context['can_send_pm'] ? '</a>' '''
'
$member['icq']['link'], ' '$member['msn']['link'], ' '$member['yim']['link'], ' '$member['aim']['link'], '
</span>'
;
}

echo '
<span class="member'
$member['is_hidden'] ? ' hidden' '''">
'
$member['is_guest'] ? $member['name'] : '<a href="' $member['href'] . '" title="' $txt['profile_of'] . ' ' $member['name'] . '"' . (empty($member['color']) ? '' ' style="color: ' $member['color'] . '"') . '>' $member['name'] . '</a>''
</span>'
;

if (!empty($member['ip']))
echo '
(<a href="' 
$scripturl '?action=', ($member['is_guest'] ? 'trackip' 'profile;area=tracking;sa=ip;u=' $member['id']), ';searchip=' $member['ip'] . '">' $member['ip'] . '</a>)';

echo '
</td>
<td nowrap="nowrap">'
$member['time'], '</td>
<td>'
$member['action'], '</td>
</tr>'
;

// Switch alternate to whatever it wasn't this time. (true -> false -> true -> false, etc.)
$alternate = !$alternate;
}

// No members?
if (empty($context['members']))
{
echo '
<tr class="windowbg2">
<td colspan="3" align="center">
'
$txt['who_no_online_' . ($context['show_by'] == 'guests' || $context['show_by'] == 'spiders' $context['show_by'] : 'members')], '
</td>
</tr>'
;
}

echo '
</tbody>
</table>
</div>
<div class="pagesection">
<div class="pagelinks align_left">'
$txt['pages'], ': '$context['page_index'], '</div>';

echo '
<div class="selectbox align_right">'
$txt['who_show1'], '
<select name="show" onchange="document.forms.whoFilter.submit();">'
;

foreach ($context['show_methods'] as $value => $label)
echo '
<option value="'
$value'" '$value == $context['show_by'] ? ' selected="selected"' '''>'$label'</option>';
echo '
</select>
<noscript>
<input type="submit" value="'
$txt['go'], '" class="button_submit" />
</noscript>
</div>
</div>
</form>
</div>'
;

// Ajax Who's online Page
<?php
echo '
<script type="text/javascript">
function grabLatestWho() {
    $("#whos_online").load(window.location.href + " #whos_online");
    }
$(document).ready(function () {
setInterval("grabLatestWho()", 15000);
});
</script>'
;
}
?>

}


Thats what I have now..

Trev

Trevor Hale

Parse error: syntax error, unexpected '<' in /home/cockpitbuilders/public_html/community/Themes/default/Who.template.php on line 105

OOPS  LOL..  I don't know what else is making a jquery  I had "Enotify" Mod installed which was a Ajax thing, but I have since removed it I believe..

Trev

darrenbeige

You didn't the parse tags, that was just to make SMF highlight it. Use this:


<?php
// Version: 2.0 RC2; Who

// The only template in the file.
function template_main()
{
   global 
$context$settings$options$scripturl$txt;

   
// Display the table header and linktree.
   
echo '
   <div class="main_section" id="whos_online">
      <form action="'
$scripturl'?action=who" method="post" id="whoFilter" accept-charset="'$context['character_set'], '">
         <h4 class="titlebg margin_lower"><span class="left"></span>
            '
$txt['who_title'], '
         </h4>
         <div class="topic_table" id="mlist">
            <div class="pagesection">
               <div class="pagelinks">'
$txt['pages'], ': '$context['page_index'], '</div>
            </div>
            <table class="table_grid" cellspacing="0">
               <thead>
                  <tr class="catbg">
                     <th scope="col" class="smalltext" width="40%"><a href="'
$scripturl'?action=who;start='$context['start'], ';show='$context['show_by'], ';sort=user'$context['sort_direction'] != 'down' && $context['sort_by'] == 'user' '' ';asc''" rel="nofollow">'$txt['who_user'], ' '$context['sort_by'] == 'user' '<img src="' $settings['images_url'] . '/sort_' $context['sort_direction'] . '.gif" alt="" />' '''</a></th>
                     <th scope="col" class="smalltext" width="10%"><a href="'
$scripturl'?action=who;start='$context['start'], ';show='$context['show_by'], ';sort=time'$context['sort_direction'] == 'down' && $context['sort_by'] == 'time' ';asc' '''" rel="nofollow">'$txt['who_time'], ' '$context['sort_by'] == 'time' '<img src="' $settings['images_url'] . '/sort_' $context['sort_direction'] . '.gif" alt="" />' '''</a></th>
                     <th scope="col" class="smalltext" width="50%">'
$txt['who_action'], '</th>
                  </tr>
               </thead>
               <tbody>'
;

   
// For every member display their name, time and action (and more for admin).
   
$alternate 0;

   foreach (
$context['members'] as $member)
   {
      
// $alternate will either be true or false. If it's true, use "windowbg2" and otherwise use "windowbg".
      
echo '
                  <tr class="windowbg'
$alternate '2' '''">
                     <td>'
;

      
// Guests don't have information like icq, msn, y!, and aim... and they can't be messaged.
      
if (!$member['is_guest'])
      {
         echo 
'
                        <span class="contact_info floatright">
                           '
$context['can_send_pm'] ? '<a href="' $member['online']['href'] . '" title="' $member['online']['label'] . '">' ''$settings['use_image_buttons'] ? '<img src="' $member['online']['image_href'] . '" alt="' $member['online']['text'] . '" align="bottom" />' $member['online']['text'], $context['can_send_pm'] ? '</a>' '''
                           '
$member['icq']['link'], ' '$member['msn']['link'], ' '$member['yim']['link'], ' '$member['aim']['link'], '
                        </span>'
;
      }

      echo 
'
                        <span class="member'
$member['is_hidden'] ? ' hidden' '''">
                           '
$member['is_guest'] ? $member['name'] : '<a href="' $member['href'] . '" title="' $txt['profile_of'] . ' ' $member['name'] . '"' . (empty($member['color']) ? '' ' style="color: ' $member['color'] . '"') . '>' $member['name'] . '</a>''
                        </span>'
;

      if (!empty(
$member['ip']))
         echo 
'
                        (<a href="' 
$scripturl '?action=', ($member['is_guest'] ? 'trackip' 'profile;area=tracking;sa=ip;u=' $member['id']), ';searchip=' $member['ip'] . '">' $member['ip'] . '</a>)';

      echo 
'
                     </td>
                     <td nowrap="nowrap">'
$member['time'], '</td>
                     <td>'
$member['action'], '</td>
                  </tr>'
;

      
// Switch alternate to whatever it wasn't this time. (true -> false -> true -> false, etc.)
      
$alternate = !$alternate;
   }

   
// No members?
   
if (empty($context['members']))
   {
      echo 
'
                  <tr class="windowbg2">
                     <td colspan="3" align="center">
                     '
$txt['who_no_online_' . ($context['show_by'] == 'guests' || $context['show_by'] == 'spiders' $context['show_by'] : 'members')], '
                     </td>
                  </tr>'
;
   }

   echo 
'
               </tbody>
            </table>
         </div>
         <div class="pagesection">
            <div class="pagelinks align_left">'
$txt['pages'], ': '$context['page_index'], '</div>';

   echo 
'
            <div class="selectbox align_right">'
$txt['who_show1'], '
               <select name="show" onchange="document.forms.whoFilter.submit();">'
;

   foreach (
$context['show_methods'] as $value => $label)
      echo 
'
                  <option value="'
$value'" '$value == $context['show_by'] ? ' selected="selected"' '''>'$label'</option>';
   echo 
'
               </select>
               <noscript>
                  <input type="submit" value="'
$txt['go'], '" class="button_submit" />
               </noscript>
            </div>
         </div>
      </form>
   </div>'
;

// Ajax Who's online Page
echo '
<script type="text/javascript">
function grabLatestWho() {
    $("#whos_online").load(window.location.href + " #whos_online");
    }
$(document).ready(function () {
setInterval("grabLatestWho()", 15000);
});
</script>'
;
}
?>



Trevor Hale

Sorry, I never claimed to be a php expert LOL...

Try now.

darrenbeige

Sorry if that came across in a bit of an arrogant way. I was only trying to show where you went wrong, I wasn't being hypocritical in any sense.

Trevor Hale

He he..   8) I didn't take it as such..  I am happy to admit you have forgotten more about PHP then I will ever know.. :) 

I just appreciate your help with this..  Thanks so much, but it doesn't seem to be working though does it?

darrenbeige

No, it doesn't. And I know why, eNotify hasn't been uninstalled correctly, and its eNotify that is causing the error (clashing). It hasn't properly uninstalled. If you are willing to trust me with your FTP details, I can fix the eNotify error and get this AJAX thing working.

Trevor Hale

If I didn't trust people, I wouldn't have been in the Hobby of Flight Sim Building that I am..  :)  I will PM you with my information on my site if thats ok :)

darrenbeige

#33
Just to let you know, the script is now active and working.

To anyone else who is struggling to make this work, please first check you are using the code on the first page, and if that fails please post here with a link to your forum.

sangwe11


Trevor Hale


darrenbeige

If I'm not mistaken Trevor, you have your Who's Online blocked to guests anyway.

I'll put the code live onto my site. The problem is the effect is dependent on users moving from page to page. If the site is inactive, nothing will (appear to) happen as the list does not need to be updated.

So even if I give you a link, you are likely to not see any effect at all, as my site currently isn't big enough. If a user here has an unrestricted Who's Online page with relatively high traffic levels and has added this code, contact me and I'll use you as the demo.

Trevor Hale

#37
I just made mine not restricted..  that will work easiest for everyone..
Thanks again Darren..

Trev

darrenbeige

Trevor's site (http://www.cockpitbuilders.com/community/index.php?action=who) seems to be quite popular so you can usually see the effect there. Watch the Who's Online listings for about 30 seconds and you see the listing update automatically.

Yahmez

Quote from: darrenbeige on November 14, 2009, 02:57:13 PM
To anyone else who is struggling to make this work, please first check you are using the code on the first page, and if that fails please post here with a link to your forum.

I can't seem to get this tip working. I tried both codes posted but to no avail...

http://marysvilleforum.org/index.php?action=who

Advertisement: