[pmwiki-users] Help with tooltips recipe (LinkPageExistsFmtTooltip)

f.r.salomons salomons at wanadoo.nl
Sun Jan 14 10:43:08 CST 2007


f.r.salomons schreef:
> I find the recipe LinkPageExistsFmtTooltip very interesting. However, 
> there seems to be something wrong with it.
> 
> 1. The first part works fine: when I add
> 
> $LinkPageExistsFmt = "<a class='wikilink' title='\$Title' 
> href='\$LinkUrl'>\$LinkText</a>";
> 
> to my config.php, at every link a tooltip shows up nicely with the title 
> of the page.
> 
> 2. In the second part, something goes wrong. When I add the code as 
> stated below, tooltips show up with the wrong content. They should 
> contain what's indside $description, and if there's no description it 
> should contain the title of the page that the link points to. In 
> reality, the tooltips contain "[description]T" (if there's a 
> description) and otherwise only "T". I guess there is some simple 
> mistake in the code, but I cannot correct it. Could anybody help me?
> 
> Thanks,
> Frits
> 
> The second part of the code reads as follows:
> 
> $FmtP['/\$Description/e'] =  'DescriptionFunction($pagename,0)';
> $FmtP['/\$DescriptionT/e'] =  'DescriptionFunction($pagename,1)';
> 
> function DescriptionFunction($pagename,$use_title=0) {
>    global $PCache;
> 
>    if (!isset($PCache[$pagename])) {
>      $page=ReadPage($pagename, READPAGE_CURRENT);
>       @PCache($pagename,$page);
>    }
>    $description=@$PCache[$pagename]['description'];
> 
>    if ( $use_title && ! $description ) {
>  
> $description=((@$PCache[$pagename]['title'])?$PCache[$pagename]['title']:FmtPageName('$Title',$pagename));
>    }
>    $description=preg_replace("/[\"']/","",$description);
>    return $description;
> }
> 
> $LinkPageExistsFmt = "<a class='wikilink' title='\$DescriptionT' 
> href='\$LinkUrl'>\$LinkText</a>";


Andrew sent me the following advice, which works fine for me (thanks 
Andrew!). (By the way, I see no mention of the recipe 
LinkPageExistsFmtTooltip in the Cookbook table of contents. Shouldn't 
that be rectified?) Frits


When the variables are being substituted "$Description" is being matched 
before "$DescriptionT" because "$DescriptionT" contains "$Description", 
you need to change

$FmtP['/\$Description/e'] =  'DescriptionFunction($pagename,0)';
$FmtP['/\$DescriptionT/e'] =  'DescriptionFunction($pagename,1)';

to:

$FmtP['/\$DescriptionT/e'] =  'DescriptionFunction($pagename,1)';
$FmtP['/\$Description/e'] =  'DescriptionFunction($pagename,0)';

or a better solution would be to change "$DescriptionT" to 
"$DescOrTitle", that way you woon't have to worry about the pattern 
matching being in the right order.

Andrew






More information about the pmwiki-users mailing list