[Pmwiki-users] code for trees
J. Meijer
commentgg
Fri Jul 30 21:40:29 CDT 2004
Below you'll find code for working with trees, using the tree-syntax I published in another mail. The thing was put together today in a few spare hours. But apparently it is working, at least it is *already* useful.
Limitations: the [[.ParentPage]], [[/SubPage]] and [[//Global.Group.Page] constructs don't work, because this requires reworking of some more regular expressions inside of pmwiki.php (for these to accept the leading '.', '/' and '//'). PM does this best anyway.
Also, because the '/' is used to denote root or groundlevels, this breaks the PmWiki/Documentation style of links: you'll need to use the [[PmWiki.Documentation docs]] style. I'm using [PmWiki.{Documentation}] instead.
I will *not* be pursuing further integration of trees in pmwiki because I am using an entirely different proprietary syntax. So the code below is just a useful proof of concept for others to integrate.
The code is very small. Which is a credit to the pmwiki group.
To make the code work you'll need to make a small patch to pmwiki right after the assignments of $LinkPatterns, see the code below. As said, to enable all functionality, more patches to regular expressions in pmwiki.php are needed.
Goodluck,
Jan
-----------------------------------------
Lloydd Budd, still here?
-----------------------------------------
# put in the local/config.php at the end
# because $GroupnamePattern is replaced.
function resolveLink($lnk) {
global $pagename;
if(false!=$i=strpos($lnk,'/')) { # peer subpage OR global
if($i==0 and $lnk[1]=='/') return substr($link,2);
$lnk=explode('/',$lnk,2);
return resolveLink($lnk[0]).'.'.$lnk[1];
} else { #relative link or anchored link (.Middle.Page)
$lnks=explode('.',$lnk);
$pg=explode('.',$pagename);
if($lnk[0]!='.') { # peer page
$pg=array_splice($pg,0,count($pg)-count($lnks));
if($pg=implode($pg,'.'))$pg.='.';
return $pg.$lnk;
} else { # anchored .Middle.page
while(count($pg) and array_pop($pg)!=$lnks[0]);
return implode('.',$pg).".$lnk";
}
}
}
$treeowl=$FmtWikiLink;
$FmtWikiLink='treeWikiLink';
function treeWikiLink($pat,$ref,$btext,$out=NULL,$rname=NULL) {
global $treeowl;
$ref=resolveLink($ref);
return $treeowl($pat,$ref,$btext,$out,$rname);
}
$OLDGNP=$GroupNamePattern;
$GroupNamePattern="{$OLDGNP}(?:[\\/.]$OLDGNP)*";
### You need to PATCH pmwiki.php, at least: ###
#--- if (preg_match("/^($GroupnamePattern)[\\/.]?\$/",$pagename,$match)) {
#+++ if (preg_match("/^($OLDGNP)[\\/.]?\$/",$pagename,$match)) {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/pmwiki-users_pmichaud.com/attachments/20040730/8744d6a3/attachment-0001.htm
More information about the pmwiki-users
mailing list