SimplePortal

Development => Feature Requests => Topic started by: Leppie on August 21, 2013, 11:50:08 AM

Title: Auto refresh the portal
Post 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.
Title: Re: Auto refresh the portal
Post by: [SiNaN] on August 23, 2013, 06:21:39 AM
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

Code: (Find) [Select]
$initialized = true;
Code: (Replace) [Select]
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.
Title: Re: Auto refresh the portal
Post by: Burke Knight on August 23, 2013, 07:15:47 AM
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.)
Title: Re: Auto refresh the portal
Post by: Leppie on August 23, 2013, 05:56:42 PM
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?
Title: Re: Auto refresh the portal
Post by: Leppie on August 23, 2013, 05:58:16 PM
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.
Title: Re: Auto refresh the portal
Post by: [SiNaN] on August 23, 2013, 06:08:50 PM
Is it possible to have the "Who's Online" box auto-refresh like the ShoutBox?

Unfortunately that's not possible at this time.
Title: Re: Auto refresh the portal
Post by: Leppie on August 23, 2013, 07:14:19 PM
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:
Title: Re: Auto refresh the portal
Post by: [SiNaN] on August 24, 2013, 02:32:01 PM
A little extra here...

To make Who's Online block auto refresh:

Sources/Subs-Portal.php

Code: (Find) [Select]
// Load the headers if necessary.
Code: (Replace) [Select]
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:

Code: [Select]
$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.
Title: Re: Auto refresh the portal
Post by: Leppie on August 24, 2013, 03:09:50 PM
A little extra here...
You are awesome  8)

Maybe a silly question, but where do I create the custom block?
Title: Re: Auto refresh the portal
Post by: [SiNaN] on August 24, 2013, 05:04:12 PM
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.
Title: Re: Auto refresh the portal
Post by: Leppie on August 24, 2013, 05:26:43 PM
Ah ok  :thumbsup:

Many thanks for  the tips  :applause:
At this rate when we meet, I owe you a Starbucks... lol
Title: Re: Auto refresh the portal
Post by: [SiNaN] on August 25, 2013, 02:55:14 AM
Lol, you're welcome. I turned out to be a useful experiment for me as well. :)
Title: Re: Auto refresh the portal
Post by: Burke Knight on August 25, 2013, 04:59:48 AM
Now, the blocks I'd like to see auto-refresh, the Recent blocks.
Recent Topics & Recent Posts refreshing, would be great.
Title: Re: Auto refresh the portal
Post by: [SiNaN] on August 25, 2013, 06:19:04 AM
It would be pretty much the same for recent block:

Sources/Subs-Portal.php

Code: (Find) [Select]
// Load the headers if necessary.
Code: (Replace) [Select]
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:

Code: [Select]
$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.
Title: Re: Auto refresh the portal
Post by: Burke Knight on August 25, 2013, 10:03:17 AM
True.
I may only even use it on block visible to me, so don't have to re-load page all the time.
Title: Re: Auto refresh the portal
Post by: Leppie on August 27, 2013, 09:18:54 AM
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.
Title: Re: Auto refresh the portal
Post by: [SiNaN] on August 28, 2013, 03:49:37 AM
You'll have to use the limit parameter for that.

Code: (Find) [Select]
array('type' => 1, 'display' => 1)
Code: (Replace) [Select]
array('type' => 1, 'display' => 1, 'limit' => 10)
Title: Re: Auto refresh the portal
Post by: Leppie on August 29, 2013, 10:46:46 AM
perfect  :thumbsup:
thanks again  :applause:
Title: Re: Auto refresh the portal
Post by: Leppie on August 29, 2013, 11:17:12 AM
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.
Title: Re: Auto refresh the portal
Post by: [SiNaN] on August 31, 2013, 07:24:58 AM
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.
Title: Re: Auto refresh the portal
Post by: Leppie on August 31, 2013, 06:52:46 PM
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?
Title: Re: Auto refresh the portal
Post by: [SiNaN] on September 01, 2013, 12:32:55 AM
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?
Title: Re: Auto refresh the portal
Post by: Leppie on September 01, 2013, 01:22:38 PM
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.
Title: Re: Auto refresh the portal
Post by: [SiNaN] on September 02, 2013, 04:28:22 PM
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.
Title: Re: Auto refresh the portal
Post by: Tarista on February 02, 2014, 02:27:10 PM
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 :)
SimplePortal 2.3.8 © 2008-2024, SimplePortal