<?php if (!defined('PmWiki')) exit();
/*  Copyright 2004 Patrick R. Michaud (pmichaud@pobox.com)
    This script allows for "rotating markup" -- i.e., things that
    someone might want to have changing each time a page is
    viewed or loaded.

    This script introduces a (:rotate:) markup which can be used
    to rotate among several administrator-defined markups based on
    the clock time.  To use this script, set $RotateMarkup['default']
    to be an array of markups you want substituted in place of the
    (:rotate:) directive.  For example:

        $RotateMarkup['default'] = array(
          'http://www.pmwiki.org',
          '[[PmWiki/PmWiki]]',
          '%red%[[DocumentationIndex]]'
        );

    This script then selects one of the markups to be used in place
    of (:rotate:).  Any PmWiki markup can be placed into the array,
    including images, links, wikiwords, wikistyles, (:include:), etc.
    (However, putting (:rotate:) itself here may cause strange and
    unwanted results. :-)

    The $RotateMarkupFreq variable specifies how often (in seconds) 
    the markup should change, by default (:rotate:) switches to a 
    new markup every ten seconds.

    Note that the markup changes only when the page is loaded,
    so if $EnableIMSCaching is set then some browsers will not
    see a change or reload the page.
*/

## $RotateMarkupFreq says how often to rotate the markup
SDV($RotateMarkupFreq, 10);

## first, add the (:rotate:) markup itself.
Markup('rotate', 'directives', '/\\(:rotate:\\)/e', "RotateMarkup(\$pagename)");

function RotateMarkup($pagename) {
  global $RotateMarkup, $Now, $RotateMarkupFreq;
  $r = (array)@$RotateMarkup['default'];
  if (count($r)<1) return '';
  $i = ($Now / $RotateMarkupFreq) % count($r);
  PRR();
  return $r[$i];
}

?>