[Pmwiki-users] random signatures or quotes (random anything ;)
Thomas -Balu- Walter
list+pmwiki-users
Fri Feb 27 08:26:32 CST 2004
<?php if (!defined('PmWiki')) exit(); // vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap:
/* Copyright 2004 Thomas "Balu" Walter (list+pmwiki-users at b-a-l-u.de)
This file is meant to be an extension to PmWiki; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version. See pmwiki.php for full details.
This script enables markup of the form ~~SigsPage~~ to be used to print a
random signature from the SigsPage.
To enable this feature you have to save this file as
scripts/randomsignature.php
and execute
include_once("scripts/randomsignature.php");
from config.php somewhere.
Once enabled, the ~~SigsPage~~ markup is replaced with a random signature
from the SigsPage on output. SigsPage should contain either a bullet or
number list defining some signatures.
If anyone has a better idea for the markup, please tell me or the PmWiki
mailing list.
*/
function Signatures($link)
{
$sigpage = ReadPage(FmtWikiLink('', $link, NULL, 'PageName'));
if (!$sigpage) return;
$s = array();
foreach (explode("\n", $sigpage['text']) as $x) {
if (!preg_match('/[#*]+\s*(.*)/', $x, $match)) continue;
$s[] = $match[1];
}
return $s;
}
function RandomSignature($link)
{
$sigs = Signatures($link);
$sigscount = count($sigs)-1;
if ($sigscount<=0) return;
print($sigs[rand(0, $sigscount)]); // NOTE: perhaps do WikiFormatting of the output?
}
$DoubleBrackets['/~~(.*)~~/e']
= 'RandomSignature("$1");';
?>
More information about the pmwiki-users
mailing list