Development > Feature Requests
Auto refresh the portal
[SiNaN]:
--- Quote from: Leppie on August 23, 2013, 05:56:42 PM ---Is it possible to have the "Who's Online" box auto-refresh like the ShoutBox?
--- End quote ---
Unfortunately that's not possible at this time.
Leppie:
--- Quote from: [SiNaN] on August 23, 2013, 06:08:50 PM ---Unfortunately that's not possible at this time.
--- End quote ---
I'm currently using auto-refresh for the whole portal using the code you provided. Set the interval to 1 minute as to make it a bit less intrusive.
Thanks for the assistance again :applause:
[SiNaN]:
A little extra here...
To make Who's Online block auto refresh:
Sources/Subs-Portal.php
--- Code: (Find) --- // Load the headers if necessary.
--- End code ---
--- Code: (Replace) --- if (!empty($_REQUEST['spajaxwhosonline']))
{
ob_start();
sp_whosOnline(null, (int) $_REQUEST['spajaxwhosonline']);
$data = ob_get_contents();
ob_end_clean();
header('Content-Type: text/xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
<smf>
<id>', (int) $_REQUEST['spajaxwhosonline'], '</id>
<data>', htmlspecialchars($data), '</data>
</smf>';
exit();
}
// Load the headers if necessary.
--- End code ---
Then you can use the following code in a Custom PHP block to display a Who's Online block that automatically updates:
--- Code: --- $seconds = 5;
$id = 123;
echo '
<div id="sp_ajax_whos_online_', $id, '">';
sp_whosOnline(null, $id);
echo '
</div>
<script language="Javascript" type="text/javascript"><!-- // --><![CDATA[
var sp_ajax_whos_online_interval_', $id, ' = setInterval("sp_ajax_whos_online_refresh_', $id, '()", ', $seconds, ' * 1000);
function sp_ajax_whos_online_refresh_', $id, '()
{
if (window.XMLHttpRequest)
sp_ajax_whos_online_refresh(', $id, ');
else
clearInterval(sp_ajax_whos_online_interval_', $id, ');
}
function sp_ajax_whos_online_refresh(id)
{
if (window.XMLHttpRequest)
{
getXMLDocument(smf_prepareScriptUrl(smf_scripturl) + "spajaxwhosonline=" + id + ";xml", onListReceived);
return false;
}
}
function onListReceived(XMLDoc)
{
var id = XMLDoc.getElementsByTagName("smf")[0].getElementsByTagName("id")[0].childNodes[0].nodeValue;
var data = XMLDoc.getElementsByTagName("smf")[0].getElementsByTagName("data")[0].childNodes[0].nodeValue;
setInnerHTML(document.getElementById("sp_ajax_whos_online_" + id), data);
return false;
}
// ]]></script>';
--- End code ---
You can change the value of $seconds variable from 5 to whatever amount of time you want it to automatically refresh.
Leppie:
--- Quote from: [SiNaN] on August 24, 2013, 02:32:01 PM ---A little extra here...
--- End quote ---
You are awesome 8)
Maybe a silly question, but where do I create the custom block?
[SiNaN]:
To create Custom PHP blocks, go to Admin > SimplePortal > Blocks > Add Block and select Custom PHP as the type of the block. You can then use the PHP codes like in the post I made above in the large text box of that Add Block page. You can also create blocks with Custom BBC and HTML codes in the same manner.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version