collapse

* Simple Portal Archived Forum

This is an Archive Forum.

The content in this forum may be out-of-date or have been superseded by newer information, and links in forum pages to other sites may not work.
This forum contains archives for future reference.

Visit our thread at Simple Machines Forum for current support.

SMF 2.1 users: EhPortal is a ported version of Simple Portal specifically designed for the SMF 2.1 branch.
Please visit web-develop.ca to download EhPortal and for its support.

* User Info

 
 
Welcome, Guest. Please login or register.

* Who's Online

  • Dot Guests: 359
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Shoutbox

Refresh History
  • Shoutbox is not for support!
  • {OCS}MasterSeal: Yup, Still adore SP
    April 21, 2019, 07:08:06 PM
  • {OCS}MasterSeal: STILL love SP :)
    November 24, 2018, 05:05:50 AM
  • ♦ Ninja ZX-10RR ♦: <3 aegersz
    September 13, 2018, 03:36:09 PM
  • aegersz: I STILL <3 LOVE SimplePortal
    September 13, 2018, 07:11:39 AM
  • aegersz: o LOVE you guys - Simple Portal rocks !
    May 09, 2018, 05:18:59 AM
  • Chen Zhen: our apologies for the site being down.. please read server issues topic
    March 22, 2018, 05:32:38 AM
  • {OCS}MasterSeal: LOL PLEASE forget I just posted that. I found the answer in my own dang post back in 2015. lol sorry!
    July 04, 2017, 10:47:55 PM
  • {OCS}MasterSeal: I know this SB isnt' for support, but I just have a general question. Who would I contact to find out where SP stores its block info? Is it DB driven or files? I searched the site but came up with nothing. probably my fault any insight is appreciated.
    July 04, 2017, 10:43:36 PM
  • ♦ Ninja ZX-10RR ♦: Excuse me but what does Simpleportal have to deal with that?
    February 05, 2017, 08:21:14 PM
  • WhiteEagle: of course IMHO that site appears to be dead :(
    February 04, 2017, 01:08:05 PM
  • WhiteEagle: If I can get that, then I'll use it for that site...
    February 04, 2017, 01:07:35 PM
  • WhiteEagle: decided to not use SMF for any projects, unless I can get a copy of the premium version of the fanfiction archive plugin
    February 04, 2017, 01:06:54 PM
  • expertdecisions: cloudflare
    January 28, 2017, 08:01:47 AM
  • aegersz: SM release 2.0.13 !
    January 12, 2017, 06:00:13 AM
  • raffo: Tks Emanuele, even if I didn't understand the fix :D
    November 07, 2016, 02:01:20 AM
  • emanuele: [link]
    November 01, 2016, 12:43:50 PM
  • emanuele: raffo: the English support board is a good place. ;)
    November 01, 2016, 12:43:38 PM
  • raffo: Where can I find the fix for the shoutbox?
    November 01, 2016, 05:06:09 AM
  • {OCS}MasterSeal: To the SP team, I make a point to come here and thank you as much as possible for your work.  so again, THANK YOU!
    October 28, 2016, 10:38:05 AM
  • emanuele: That's indeed funny, the limit is present only in the patch and not the full install.
    October 22, 2016, 06:14:58 PM

* Recent Posts

Adding Forums Button to Nav bar by jirapon
[August 01, 2019, 09:07:12 AM]


Re: Board Icons by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 04:03:41 PM]


MOVED: Czech translation???? by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 03:04:51 PM]


Board Icons by jirapon
[July 30, 2019, 07:28:44 AM]


Re: Thankyou Simpleportal, by ♦ Ninja ZX-10RR ♦
[July 29, 2019, 09:41:29 AM]

Blocks speak! Do you have an interest in getting more blocks - or even making your own? The Blocks Board is for you!

Author Topic: Auto refresh the portal  (Read 17902 times)

0 Members and 1 Guest are viewing this topic.

Offline Leppie

  • Semi Newbie
  • *
  • Posts: 27
    • Open Linux Forums
  • SMF Version: 2.0.5
  • SP Version: 2.3.5
Auto refresh the portal
« 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.

Offline [SiNaN]

  • Mr. SimplePortal
  • Developer
  • *
  • Posts: 6782
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: Auto refresh the portal
« Reply #1 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.
And slowly, you come to realize... It's all as it should be...

Offline Burke Knight

  • Sr. Member
  • ****
  • Posts: 394
  • Gender: Male
  • I tell it how I see it. Don't like it? Hit Alt+F4
    • BurkeKnight Enterprises
  • SMF Version: None
  • SP Version: None
  • Elkarte Version: None
Re: Auto refresh the portal
« Reply #2 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.)

Offline Leppie

  • Semi Newbie
  • *
  • Posts: 27
    • Open Linux Forums
  • SMF Version: 2.0.5
  • SP Version: 2.3.5
Re: Auto refresh the portal
« Reply #3 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?

Offline Leppie

  • Semi Newbie
  • *
  • Posts: 27
    • Open Linux Forums
  • SMF Version: 2.0.5
  • SP Version: 2.3.5
Re: Auto refresh the portal
« Reply #4 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.

Offline [SiNaN]

  • Mr. SimplePortal
  • Developer
  • *
  • Posts: 6782
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: Auto refresh the portal
« Reply #5 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.
And slowly, you come to realize... It's all as it should be...

Offline Leppie

  • Semi Newbie
  • *
  • Posts: 27
    • Open Linux Forums
  • SMF Version: 2.0.5
  • SP Version: 2.3.5
Re: Auto refresh the portal
« Reply #6 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:

Offline [SiNaN]

  • Mr. SimplePortal
  • Developer
  • *
  • Posts: 6782
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: Auto refresh the portal
« Reply #7 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.
And slowly, you come to realize... It's all as it should be...

Offline Leppie

  • Semi Newbie
  • *
  • Posts: 27
    • Open Linux Forums
  • SMF Version: 2.0.5
  • SP Version: 2.3.5
Re: Auto refresh the portal
« Reply #8 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?

Offline [SiNaN]

  • Mr. SimplePortal
  • Developer
  • *
  • Posts: 6782
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: Auto refresh the portal
« Reply #9 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.
And slowly, you come to realize... It's all as it should be...

Offline Leppie

  • Semi Newbie
  • *
  • Posts: 27
    • Open Linux Forums
  • SMF Version: 2.0.5
  • SP Version: 2.3.5
Re: Auto refresh the portal
« Reply #10 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
« Last Edit: August 24, 2013, 05:38:33 PM by Leppie »

Offline [SiNaN]

  • Mr. SimplePortal
  • Developer
  • *
  • Posts: 6782
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: Auto refresh the portal
« Reply #11 on: August 25, 2013, 02:55:14 AM »
Lol, you're welcome. I turned out to be a useful experiment for me as well. :)
And slowly, you come to realize... It's all as it should be...

Offline Burke Knight

  • Sr. Member
  • ****
  • Posts: 394
  • Gender: Male
  • I tell it how I see it. Don't like it? Hit Alt+F4
    • BurkeKnight Enterprises
  • SMF Version: None
  • SP Version: None
  • Elkarte Version: None
Re: Auto refresh the portal
« Reply #12 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.

Offline [SiNaN]

  • Mr. SimplePortal
  • Developer
  • *
  • Posts: 6782
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: Auto refresh the portal
« Reply #13 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.
And slowly, you come to realize... It's all as it should be...

Offline Burke Knight

  • Sr. Member
  • ****
  • Posts: 394
  • Gender: Male
  • I tell it how I see it. Don't like it? Hit Alt+F4
    • BurkeKnight Enterprises
  • SMF Version: None
  • SP Version: None
  • Elkarte Version: None
Re: Auto refresh the portal
« Reply #14 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.

Offline Leppie

  • Semi Newbie
  • *
  • Posts: 27
    • Open Linux Forums
  • SMF Version: 2.0.5
  • SP Version: 2.3.5
Re: Auto refresh the portal
« Reply #15 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.

Offline [SiNaN]

  • Mr. SimplePortal
  • Developer
  • *
  • Posts: 6782
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: Auto refresh the portal
« Reply #16 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)
And slowly, you come to realize... It's all as it should be...

Offline Leppie

  • Semi Newbie
  • *
  • Posts: 27
    • Open Linux Forums
  • SMF Version: 2.0.5
  • SP Version: 2.3.5
Re: Auto refresh the portal
« Reply #17 on: August 29, 2013, 10:46:46 AM »
perfect  :thumbsup:
thanks again  :applause:

Offline Leppie

  • Semi Newbie
  • *
  • Posts: 27
    • Open Linux Forums
  • SMF Version: 2.0.5
  • SP Version: 2.3.5
Re: Auto refresh the portal
« Reply #18 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.
« Last Edit: August 29, 2013, 12:43:58 PM by Leppie »

Offline [SiNaN]

  • Mr. SimplePortal
  • Developer
  • *
  • Posts: 6782
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: Auto refresh the portal
« Reply #19 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.
And slowly, you come to realize... It's all as it should be...