[pmwiki-users] back to an old story : conditional for attachments (fwd)
Eemeli Aro
eemeli at gmail.com
Thu Mar 27 15:10:21 CDT 2008
On Thu, Mar 27, 2008 at 5:57 PM, Alain Castera <castera at in2p3.fr> wrote:
> So I need a way to test the existence of a given attachment at the group level,
> before offering the site-wide attachment.
I can't remember if I've posted this anywhere, but this is what I use
on my sites:
# this adds (:if attach-exists [Group.Page/]filename.ext:) to the markup
$Conditions['attach-exists'] = "AttachFileExists(\$pagename,\$condparm)";
function AttachFileExists( $pagename, $path ) {
global $UploadFileFmt;
if (preg_match('!^(.*)/([^/]+)$!', $path, $match)) {
$pagename = MakePageName($pagename, $match[1]);
$path = $match[2];
}
$upname = MakeUploadName($pagename,$path);
$filepath = FmtPageName("$UploadFileFmt/$upname", $pagename);
return file_exists($filepath);
}
Add the above to your config file, and you'll have a new (:if
attach-exists [Group.Page/]filename.ext:) condition. What it does is
check if filename.ext can be found for for the given Group.Page. You
may of course use Group/filename.ext or just filename.ext to default
to the current page. No permissions are checked, as the conditional
only tells you if a file with that name exists on the server.
eemeli
More information about the pmwiki-users
mailing list