[Pmwiki-users] Re: random signatures or quotes (random anything ;)

J. Meijer commentgg
Wed May 5 18:48:06 CDT 2004


> Thomas -Balu- Walter schrieb:
> No comments so far?

Hi, it was the script that got me started in pmwiki/php :-)

In the mean time I made the following changes:

  1.. Changed syntax to [[quote:QuotesPage]]
  2. Provided for the [[quote]] shortcut-syntax with $QuotesPage substituted
as the quotes-page in the current group. When  $QuotesPage is not set in
local/config.php, it is defaulted to 'QuotesPage'.
  3. When no QuotesPage exists in the current group, $DefaultGroup is tried
instead. When no page is found, '[[quote:page]]' is returned as the text.
  4. Removed the original PrintText() function to allow markup by the
client!
  5. All quotes include a link to the QuotesPage (with text '...') to the
page that should have contained the quotes. Note that this might not be the
page that actually sourced the quotes! You might want to change this.

-jm

-------------------------------------
The code is here to be improved upon:


SDV($QuotesPage,'QuotesPage');

function Quotes($link)
{   $quotepage = ReadPage(FmtWikiLink('', $link, NULL, 'PageName'));
    if (!$quotepage) return '';
    $s = array();
    foreach (explode("\n", $quotepage['text']) as $x) {
        if (!preg_match('/[#*]+\s*(.*)/', $x, $match)) continue;
        $s[] = $match[1];
    }
    return $s;
}

function RandomQuote($link) {
  global $pagename,$DefaultGroup;
  $quotes = Quotes($link);
  $quotescount = count($quotes)-1;
  if ($quotescount<=0) {
    $quotes = Quotes($DefaultGroup.'.'.substr($link,strstr($link,'.')));
    $quotescount = count($quotes)-1;
    if ($quotescount<=0) { return "[[quote:$link]]"; }
  }
  return $quotes[rand(0,$quotescount)]."[[$link ...]]";
}

$DoubleBrackets['/\\[\\[quote:\s*([a-zA-Z0-9_.\/]+)\s*\\]\\]/e']
    = 'RandomQuote("$1");';
$DoubleBrackets['/\\[\\[quote\\]\\]/e']
    = "RandomQuote($QuotesPage);";







More information about the pmwiki-users mailing list