[pmwiki-users] powertools / {(pagelist ...)}

Hans design5 at softflow.co.uk
Fri Jan 2 11:52:42 CST 2009


Friday, January 2, 2009, 4:13:01 PM, Stéphane Heckel wrote:

> Is it complex to implement ?
> Would it be a useful enhancement to powertools to provide dynamic format
> driven by the fmt= option ?

> I would need something like :
> [[#createdby]]
> {=$Name}|{=$Title}|{=$CreatedBy}
> [[#createdbyend]]

okay, i played with this, to give you an idea:

adding a fmt=createdby option to {(pagelist ..)}
add to config:

$FPLFormatOpt['createdby'] = array('fn' =>  'FPLcreatedby');
function FPLcreatedby($pagename, &$matches, $opt) {
        $matches = MakePageList($pagename, $opt, 0);
        ##  extract page subset according to 'count=' parameter
        if (@$opt['count']) {
                list($r0, $r1) = CalcRange($opt['count'], count($matches));
                if ($r1 < $r0) 
                        $matches = array_reverse(array_slice($matches, $r1-1, $r0-$r1+1));
        else 
                $matches = array_slice($matches, $r0-1, $r1-$r0+1);
        }
        $opt['sep'] = ((@$opt['sep']) ? $opt['sep'] : "\n");
        $opt['sep'] = str_replace('\n',"\n",$opt['sep']);
        if ($opt['sep']=='LF') $opt['sep'] = "\n";
        
        $item = array();
        foreach ($matches as $k => $pn) {
                $name = PageVar($pn, '$Name');
                $title = PageVar($pn, '$Title');
                $createdby = PageVar($pn, '$CreatedBy');
                $item[$k] = "[[".$name."|".$title."]] - ".$createdby;
        }
        return Keep(implode($opt['sep'], $item), 'P');
}

you can see how the formatting is achieved in the function, in the
      foreach ($matches ...) routine.
The line
      $out[$k] =  "[[".$name."|".$title."]] - ".$createdby;
formats page name and title into a link, followed by plain text
CreatedBy var. Change the routine as required.
the newline is set as default separator for each pagelist item.

  ~Hans




More information about the pmwiki-users mailing list