[pmwiki-users] Automatically create pages and groups?
Hans
hans.bracker at googlemail.com
Thu Aug 24 05:58:19 CDT 2006
On 24/08/06, Hsing-Foo Wang <hsingfoo at gmail.com> wrote:
> The pattern may vary, But right now 'Pnnnnn' as in P00001.
>
> With my 'skills' I would write: If $Name = *Pnnnnn* then autocreate else return
Here is a script you can include for pattern matched autopage creation.
Just replace the patterns, add to etc.
And specify your templat epages and target pages.
Re patterns: these are regex patterns:
(.*) matches any character strings
P just the letter P
\\d any digit 0...9
So you get matches for Test-P00001Sample etc
The second pattern is just with a W insted of P, to give you an idea
how to add patterns to the array.
Script code:
<?php if (!defined('PmWiki')) exit();
# automatic creation of a number of pages from template pages
# if a pattern is met
$AutoGroupPagesFmt = array(
'{$Group}.{$Name}-Comments' => 'Templates.PageComments',
'{$Group}.{$Name}-Details' => 'Templates.PageDetails',
);
$AutoGroupPattern = array(
'p1' => '(.*)(P\\d\\d\\d\\d\\d)(.*)', # *P12345*
'p2' => '(.*)(W\\d\\d\\d\\d\\d)(.*)', # *W12345*
);
$group = PageVar($pagename, '$Group');
$name = PageVar($pagename, '$Name');
# below replace $pagename with $name if only Name should match and not Group
# below replace $pagename with $group if only Group should match and not Name
if ($action=='edit') {
foreach ((array)$AutoGroupPattern as $k=>$v) {
$match = preg_match("/^($v)$/i", $pagename);
if($match) $EditFunctions[] = 'AutoGroupPages';
}
}
#if($action=='edit' && preg_match("/^($AutoGroupPattern)$/i", $name))
# $EditFunctions[] = 'AutoGroupPages';
function AutoGroupPages($pagename, &$page, &$new) {
global $IsPagePosted, $AutoGroupPagesFmt;
if (!$IsPagePosted) return;
SDV($AutoGroupPagesFmt, array(
'{$Group}.HomePage' => 'Templates.HomePage',
'{$Group}.GroupHeader' => 'Templates.GroupHeader',
'{$Group}.GroupFooter' => 'Templates.GroupFooter'));
foreach($AutoGroupPagesFmt as $n => $t) {
$n = FmtPageName($n, $pagename);
if (!PageExists($n)) {
$t = FmtPageName($t, $pagename);
WritePage($n, ReadPage($t));
}
}
}
More information about the pmwiki-users
mailing list