thanks a bunch to peter!
a better version of AutoLink is now online, with the ability to
declare autolink definitions on a wikipage instead of in config.php
thanks!
a
http://www.pmwiki.org/wiki/Cookbook/AutoLink
On 27 Aug 2009, at 7:00 AM, Peter Bowers wrote:
On Wed, Aug 26, 2009 at 11:24 PM, adam
overton<[email protected]> wrote:
# all keys must be completely lowercase in order for this to work
$NameToLinkArray = array(
'john doe' => 'http://www.johndoe.com',
'sally struthers' => 'http://www.def.com'
);
Markup('names', 'inline',
'/(`?)\b(' . join('|', array_keys($NameToLinkArray)) . ')\b/ei',
'AutoNameToLinkFunc("$2","$1")'
);
function AutoNameToLinkFunc($name, $escape) {
global $NameToLinkArray;
if ($escape) return $name;
$link =
'%newwin%[['.$NameToLinkArray[strtolower($name)].'|'.Keep
($name).']]';
return $link;
}
* i had to substitute the AutoNameToLinkFunc because i couldn't
figure out
how to get pmwiki to find $NameToLinkArray - i got errors, and had
to resort
to calling it as a global in a function. perhaps someone knows how to
finagle this without having to declare a separate function, as PM
did in his
recent example?
Use the $GLOBALS super-global, thus $GLOBALS['NameToLinkArr...']
question/next step:
is there a way to set up my list of names on a wiki page (like
Site.NamesToLinks), like InterMap is setup?
Just set up your page using one link-pair per line and some delimiter
(colon?) between the name and the link. Then read in the page and
parse the $page['text'] into an array:
$AutoLinkPage = "SiteAdmin.AutoLink";
$page = ReadPage($AutoLinkPage);
$NameToLinkArray = array();
foreach (explode("\n", $page['text']) as $line) {
if (!strpos($line, '|')) continue;
$foo = explode("|",$line);
echo "<p>foo=".print_r($foo,true).", count=".count($foo)."<p><br>\n";
if (count($foo) == 2)
$NameToLinkArray[strtolower($foo[0])] = $foo[1];
}
echo "<p>N2LA=".print_r($NameToLinkArray,true)."<p><br>\n";
if ($NameToLinkArray)
Markup('names', 'inline',
'/(?<!\`)\b(' . join('|', array_keys($NameToLinkArray)) . ')\b/
ei',
'"%newwin%[[".$GLOBALS["NameToLinkArray"][strtolower
("$1")]."|".Keep("$1")."]]"'
);
-Peter
_______________________________________________
pmwiki-users mailing list
[email protected]
http://www.pmichaud.com/mailman/listinfo/pmwiki-users