Revision history for AutoRefreshFromBody


Revision [21819]

Last edited on 2013-10-05 04:55:15 by Curucahm
Additions:
=====Auto-Refresh From Body=====
I use the wiki to display lots of data that is updated constantly. I use actions to generate pages that retrieve data from various places, almost like monitoring software. I needed to be able to find a way to cause specific pages to refresh once a minute. I was inspired by JasonHuebel MetaRefresh hack, but his didn't allow for the flexibility I needed. I updated my themes to include this php code, and I place a specific tag in the body of my pages when I want them to refresh, which follows after the code.
~-Placed the following code in any of the themes header.php files in the <HEAD> block near the other meta tags, for neatness:
~%%(php)
<?php
if ( $this->GetHandler() != 'edit' || $this->GetHandler() != 'clone'|| $this->GetHandler() != 'addcomment' || $this->GetHandler() != 'acls')
{
$mrtablepref = $this->config['table_prefix'];
$mrtable="${mrtablepref}pages";
$mrtag = $this->page["tag"];
$mrsearch="<!--- REFRESH --->";
$mrsql = "SELECT body from $mrtable where tag='$mrtag' ORDER BY id DESC LIMIT 1";
if ($mrresult = mysql_query($mrsql)) {
$BOB=1;
while ($mrlist = mysql_fetch_array($mrresult)) {
if ( preg_match("/".$mrsearch."/","$mrlist[body]")) {
$BOB=2;
}
}
if ($BOB=="2") {
echo " <meta http-equiv='Refresh' content='60'/>\n";
echo " <meta http-equiv='Expires' content='0'/>\n";
}
}
}
?>
~- Now in any page you create that you wish to have refreshed, place the following tag:
""<!--- REFRESH --->""
You can of course adjust the timing by changing the value in the Refresh tag. Although if I have more time to work on this, I may also make it so that it is adjustable via the tag placed in the body of the page.
Please feel free to comment, and help me make this better, I'm willing to learn better ways of doing things if someone sees it. This was the first time I've ever contributed to an Open Source Project.
Deletions:
=====Meta Refresh Hack=====
Here's a quick hack that causes the HomePage to refresh automatically every 60 seconds. Open your actions/header.php file and add these lines anywhere in the <HEAD> block:
%%(php)
<?php if (($this->GetPageTag() == 'HomePage') && ($this->GetMethod() == 'show')) { ?>
<meta http-equiv="Refresh" content="60" />
<meta http-equiv="Expires" content="0" />
<?php } ?>
You can change the refresh time (in seconds) by changing the Refresh META tag.
If you find this action useful, post a comment and let me know! Also, feel free to comment with requests for feature enhancements. --JasonHuebel


Revision [21818]

The oldest known version of this page was created on 2013-10-05 04:34:41 by Curucahm
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki