SimplePortal
Development => Feature Requests => Topic started by: Leppie on August 21, 2013, 11:50:08 AM
-
Would it be possible to add an auto-refresh setting so that the portal updates every now and then.
This way the recent topics, who's online and ShoutBox will be updated and display more recent events.
-
You can make the shoutbox auto-refresh by going to Admin > SimplePortal > Shoutbox > Shoutbox List, clicking the Modify link for the shoutbox and setting the Auto refresh setting.
You can make the whole portal page auto-refresh by the following code edit but it's not suggested:
Sources/Subs-Portal.php
$initialized = true;
if ($context['SPortal']['on_portal'])
{
$context['html_headers'] .= '
<meta http-equiv="refresh" content="5">';
}
$initialized = true;
Change 5 as the number of seconds you want auto-refresh to happen.
-
NOTE:
Auto-refreshing can do the following:
1. Annoy users.
2. Cause server problems, like cpu and memory overloads.
3. Use up a lot of bandwidth.
4. Use up your hit allowance. (A lot of free web hosts have daily hit allowance limitations.)
-
You can make the shoutbox auto-refresh by going to Admin > SimplePortal > Shoutbox > Shoutbox List, clicking the Modify link for the shoutbox and setting the Auto refresh setting.
Thanks for this tip.
Is it possible to have the "Who's Online" box auto-refresh like the ShoutBox?
-
NOTE:
Auto-refreshing can do the following:
1. Annoy users.
Very valid point, and I would like to avoid auto-refresh for the whole portal.
The others a bit less in my case as I have a dedicated server for the forum.
-
Is it possible to have the "Who's Online" box auto-refresh like the ShoutBox?
Unfortunately that's not possible at this time.
-
Unfortunately that's not possible at this time.
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:
-
A little extra here...
To make Who's Online block auto refresh:
Sources/Subs-Portal.php
// Load the headers if necessary.
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.
Then you can use the following code in a Custom PHP block to display a Who's Online block that automatically updates:
$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>';
You can change the value of $seconds variable from 5 to whatever amount of time you want it to automatically refresh.
-
A little extra here...
You are awesome 8)
Maybe a silly question, but where do I create the custom block?
-
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.
-
Ah ok :thumbsup:
Many thanks for the tips :applause:
At this rate when we meet, I owe you a Starbucks... lol
-
Lol, you're welcome. I turned out to be a useful experiment for me as well. :)
-
Now, the blocks I'd like to see auto-refresh, the Recent blocks.
Recent Topics & Recent Posts refreshing, would be great.
-
It would be pretty much the same for recent block:
Sources/Subs-Portal.php
// Load the headers if necessary.
if (!empty($_REQUEST['spajaxrecent']))
{
ob_start();
sp_recent(array('type' => 1, 'display' => 1), (int) $_REQUEST['spajaxrecent']);
$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['spajaxrecent'], '</id>
<data>', htmlspecialchars($data), '</data>
</smf>';
exit();
}
// Load the headers if necessary.
Block code to be used in a Custom PHP block:
$seconds = 5;
$id = 135;
echo '
<div id="sp_ajax_recent_', $id, '">';
sp_recent(array('type' => 1, 'display' => 1), $id);
echo '
</div>
<script language="Javascript" type="text/javascript"><!-- // --><![CDATA[
var sp_ajax_recent_interval_', $id, ' = setInterval("sp_ajax_recent_refresh_', $id, '()", ', $seconds, ' * 1000);
function sp_ajax_recent_refresh_', $id, '()
{
if (window.XMLHttpRequest)
sp_ajax_recent_refresh(', $id, ');
else
clearInterval(sp_ajax_recent_interval_', $id, ');
}
function sp_ajax_recent_refresh(id)
{
if (window.XMLHttpRequest)
{
getXMLDocument(smf_prepareScriptUrl(smf_scripturl) + "spajaxrecent=" + id + ";xml", onRecentReceived);
return false;
}
}
function onRecentReceived(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_recent_" + id), data);
return false;
}
// ]]></script>';
To make it display recent posts or to change the display or number of topics/posts listed, you just need to change the first parameter of sp_recent() function in both of the codeblocks quoted above.
Just remember that having multiple blocks like this refreshing frequently may put a significant strain on the server.
-
True.
I may only even use it on block visible to me, so don't have to re-load page all the time.
-
I was playing around a bit with the recent block you posted, but cannot seem to change the number of posts/topics to list?
I've tried editing the 'display' value, but that doesn't seem to make any difference.
-
You'll have to use the limit parameter for that.
array('type' => 1, 'display' => 1)
array('type' => 1, 'display' => 1, 'limit' => 10)
-
perfect :thumbsup:
thanks again :applause:
-
When the portal loads initially, I get the correct number (15) of entries dipslayed.
However, after an auto-refresh it only displays 5.5 (the 6th entry is cut in the middle) entries?
Update: This actually happens in Firefox, Chrome seems to process the auto-refresh properly.
-
I'm not really sure what might be happening. It might be because 15 recent post items produce a lot of HTML code to pass by JavaScript, so it might be cutting it off. See if there is something in the JavaScript error console. Also try it on Firefox with fewer number of recent posts to see if it works normally then.
-
I've tried some different settings in Subs-Portal.php, but anything higher than 5 for limit will give the same result.
There seem to be errors, but they all refer to websiteLogon.js?
-
When you were changing the parameters (I mean adding 'limit => 15) are you sure you have changed it in both the block code and the code added to Subs-Portal.php?
-
When you were changing the parameters (I mean adding 'limit => 15) are you sure you have changed it in both the block code and the code added to Subs-Portal.php?
Yes.
The block works fine in Opera, Chrome, Midori and other browsers. It's just having this odd behaviour in Firefox.
-
I don't have Firefox to test it unfortunately but keep that block working there and I'll try to test it on a different machine, that has Firefox.
-
I'm using the recent post auto-refresh found in this message:
http://simpleportal.net/index.php?topic=12810.msg63761#msg63761
Is it possible to refresh/update the div without the user also being updated in the forums who's online list and the last_active? Seeing as I only reloaded the div, not the whole site?
Thank you :)