|
Cookbook /
AutoGroupPagesSummary: How to create a number of pages for a new group automatically
Version: 2006-08-05
Prerequisites: pmwiki 2.1
Status: stable
Maintainer:
Discussion: AutoGroupPages-Talk
Categories: Editing, Administration
Questions answered by this recipeHow can I have a number of pages created automatically for a new group? DescriptionHere's a brief recipe that will create HomePage, GroupHeader, and GroupFooter automatically if they don't exist when a page is created in a group: function AutoGroupPages($pagename, &$page, &$new) {
global $IsPagePosted, $GroupPagesFmt;
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);
$t = FmtPageName($t, $pagename);
if (!PageExists($n) && $n != $pagename) {
WritePage($n, ReadPage($t));
}
}
}
$EditFunctions[] = 'AutoGroupPages';
The last line adds the function to the $AutoGroupPagesFmt can be defined with different pages prior of including the function. NotesThe function is declared and used in newgroupbox.phpΔ. If you wish to use NewGroupBox and also have the function available generally to be used when editing a new page for a new group, then you should only add to config.php: $EditFunctions[] = 'AutoGroupPages';
Automatic creation of Uploads DirectoryIf you need to have a group uploads directory created automatically, when a first page in a new group is created, you can add the following to local/config.php: function AutoCreateUploadDirectory($pagename, &$page, &$new) {
global $IsPagePosted, $UploadFileFmt;
if (!$IsPagePosted) return;
$uploaddir = FmtPageName($UploadFileFmt, $pagename);
mkdirp($uploaddir);
}
$EditFunctions[] = 'AutoCreateUploadDirectory';
Note that normally PmWiki manages fine to create uploads directories when the need (i.e. upload) arises. Release Notes
See AlsoContributorsCommentsSee discussion at AutoGroupPages-Talk User notes +1: 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. |