Cookbook /
Wildcard attachexists condition
List of attachments to the Mini page :
(:attachtable Mini list=all:) | ||||||||||||||||||||||||||||||||||||||||||
|
Conditionals :
(:if attachexists Mini/*.jpg:) * attachexists *.jpg (:if attachexists Mini/*.png:) * attachexists *.png (:if attachexists Mini/*.avi:) * attachexists *.avi (:if attachexists Mini/Test.jpg:) * attachexists Test.jpg (:if attachexists Mini/te*.jpg:) * attachexists te*.jpg (case insensitive) (:if attachexists Mini/Test.html:) * attachexists Test.html (:if attachexists Mini/th*---*.jpg:) * Mini or Thumblist thumbnails exist (:if attachexists *:) * current page has an attachment (:ifend:) |
|
In a pagelist :
(:pagelist group=Cookbook if="attachexists {=$FullName}/*" fmt=#simplename:) |
Multiple file matches. Note that this may seem counter-intuitive, but works exactly the same way as the pagelist name=*Page1,*Page2,-A*
parameter.
(:if attachexists *.ogg,*.mp3,*.wav,*.au:) * at least one audio file (not all types) (:if attachexists Mini/*.png,*.avi:) * either *.png, or *.avi exist (not both) (:if attachexists Mini/*,-*.avi,-*.zip:) * there are attachments other than *.avi, or *.zip (:if [ attachexists Mini/*.png && attachexists Mini/*.jpg ]:) * both *.png, and *.jpg exist (:ifend:) |
|
Code to add in config.php :
$Conditions['attachexists'] = 'WildcardAttachExists($pagename, $condparm)'; function WildcardAttachExists($PN, $path='*') { global $UploadFileFmt; if (preg_match('!^(.*)/([^/]+)$!', $path, $m)) { $path = $m[2]; $PN = MakePageName($PN, $m[1]); } $uploaddir = FmtPageName($UploadFileFmt, $PN); $flist = array(); if(preg_match("/(^|,)[!-]|[\\*\\?]/", $path)){ if($dirp=@opendir($uploaddir)){ while (($f=readdir($dirp))!==false) if($f{0}!='.' && ! preg_match("/,\\d+$/", $f) ) $flist[$f]=$f; closedir($dirp); } $flist = MatchPageNames($flist, array($path)); return count($flist); } $upname = MakeUploadName($PN,$path); $filepath = FmtPageName("$UploadFileFmt/$upname", $PN); return file_exists($filepath); }