Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

AutomaticPageRefresh

Summary: How to create pages that refresh automatically.
Version: 2006-09-26
Prerequisites: pmwiki-2.0 (and possibly earlier)
Status: stable
Maintainer:
Categories: Layout

Description

This recipe makes it possible for a page to refresh at set intervals, or by an interval set in a ?refresh=nn addition to a page URL.

Notes

general automatic page refresh

The following will cause a browser to refresh the page every 30 seconds:

if ($action == 'browse')
    $HTMLHeaderFmt['refresh'] =
       "<meta http-equiv='Refresh' Content='30; URL={\$PageUrl}' />";

It can be done sitewide in local/config.php (probably not recommended, because it will work for all pages), or in a per-page or per-group customization file.

refresh markup

Alternatively, set individual page refresh with markup directive.
Example: page refresh every 20 seconds: (:refresh 20:)

# markup (:refresh nn:)
Markup('refresh', '<include',
  '/\\(:refresh\\s+(.*?):\\)/ei',
  "RefreshMarkup(\$pagename, PSS('$1'))");

function RefreshMarkup($pagename, $secs) {
        global $HTMLHeaderFmt;
            $HTMLHeaderFmt['refresh'] =
               "<meta http-equiv='Refresh' Content='$secs; URL={\$PageUrl}' />";
        return '';
}

refresh url parameter

Or, one could use the following customization to add a '?refresh=nn' option to all pages:

if (@$_GET['refresh']) {
   $r = $_GET['refresh'];
   $HTMLHeaderFmt['refresh'] =
     "<meta http-equiv='Refresh' Content='$r; URL={\$PageUrl}?refresh=$r' />";
 }

As a demonstration, this latter version is enabled at: Test.Refresh.

Release Notes

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".

Comments

refresh url, with the ability to re-visit an anchor

In the example above, it's not possible to continually refresh Group/Name#anchor - it will always refresh to Group/Name, and drop the anchor. The code below offers an optional anchor= parameter, so that refreshing will always return you to the part of the page you desire:

if (@$_GET['refresh']) {
	# determine duration of refresh
	$r = $_GET['refresh'];
	# determine an anchorname
	if (@$_GET['anchor']) {
		$a = "#".$_GET['anchor'];	    # get the specified anchorname
		$aQ = "&anchor=".$_GET['anchor'];   # make sure to call the same anchor on the next page
	}
	$HTMLHeaderFmt['refresh'] =
	"<meta http-equiv='Refresh' Content='$r; URL={\$PageUrl}?refresh=$r$aQ$a' />";
}

overtones99 September 02, 2009, at 08:56 PM

See Also

  • SlideshowRefresh - uses the code above as a basis for a recipe that enables "slideshows" consisting of wikipages getting automatically loaded, one-after-another, via the Refresh meta tag.

Contributors

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.

Edit - History - Print - Recent Changes - Search
Page last modified on September 10, 2011, at 11:42 AM