[pmwiki-users] Subfolders in "Uploads"? Esp. for Mini recipe

Rogutės Sparnuotos rogutes at googlemail.com
Wed Feb 3 05:26:21 CST 2010


Mike (2010-02-02 18:04):
> Hello again,
> 
> just trying again - would anybody be able to provide some help here?
> 
> Basically, I'm trying to make the Mini recipe work with images clustered 
> in subfolders - but all of the same PmWiki group. If possible, I'd also 
> love to see subfolders for PmWiki attachments in general, but this would 
> probably require a bit more reprogramming.
> 
> Changing the Mini recipe to take subfolders as an argument should be 
> easily possible thought... but when I tried, I failed as the folder 
> structure is deeply coded into the Mini recipe...

Hey, Mike,

I have attached an excerpt from "config.php" as "up_pref_by_fname.php".
It is probably not what you are searching for, but it shows what is
possible with PmWiki's $*Fmt variables and the FmtPageName() function.
Note that this example might be incompatible with some recipes and
I haven't tested it much, although it is heavily used on a rather big wiki
with the Mini recipe.

Look for a comment in the attached file to find out what it does and
sorry if I misunderstood your request and this doesn't help you at all.

Regards,
--  Rogutės Sparnuotos
-------------- next part --------------
<?php

# CHOOSING THE UPLOAD PREFIX BY UPLOADED FILE NAME

## The name of every uploaded file determines where it will go in $UploadDir.
## If the name starts with a-z letters, all these letters up to the first
## non-letter character will be used to check if a directory with such a name 
## exists under $UploadDir/. If the directory will be found, the uploaded file 
## will land in it, otherwise it will go under $UploadDir/$MyUploadPrefix/. 
## This is controlled by the custom function FmtUploadPrefixByName down below.

$MyUploadPrefix = '/00_others';

$FmtP['#\\$FmtUpPrefByName\\b#e'] = 'FmtUploadPrefixByName($pagename, $fmt)';
$UploadFileFmt = $UploadDir.'$FmtUpPrefByName';
$UploadPrefixFmt = $MyUploadPrefix;
$LinkFunctions['Attach:'] = 'LinkUploadByName';
$MarkupTable['Mini:']['rep'] = str_replace('(LinkMini(', '(LinkUploadByName(', $MarkupTable['Mini:']['rep']);

function LinkUploadByName($pagename, $imap, $path, $alt, $txt, $fmt=NULL) {
  global $UploadPrefixFmt;
  $UploadPrefixFmt = FmtUploadPrefixByName($pagename, $path);

  if (ucfirst($imap)=='Mini:') $linkfu = 'LinkMini';
  else $linkfu = 'LinkUpload';

  return $linkfu($pagename, $imap, $path, $alt, $txt, $fmt);
}

function FmtUploadPrefixByName($pagename, $fmt) {
  global $UploadDir, $MyUploadPrefix;
  $upname = basename($fmt);
  if (preg_match("#^(th\d+---)?([[:alpha:]]+)[^/]+$#", $upname, $m))
    if (is_dir("$UploadDir/$m[2]"))
      $res='/'.$m[2];
  else
    $res=$MyUploadPrefix;

  return $res;
}



More information about the pmwiki-users mailing list