[pmwiki-users] Arbitrary filtering for (:pagelist:) - is there a better way?
Michael Tempest
michael.tempest at ate-aerospace.com
Tue Jul 18 08:43:35 CDT 2006
Hi
I have pages in my PmWiki that are applicable to a specific date, like a
calendar. I've encoded the data in the name (for example "Event-2006-07-13"),
which lets me order by name (or -name) and the pages are ordered by date. (I
can't use creation date or last-modified date - these pages may be created in
any order and will often be modified after the applicable date.)
So far, it works without a problem.
I want to list pages for future dates or for past dates. I cannot think of a
regular expression that would let me do that - I think actual code is
necessary.
I added a "filter" option to MakePageList() in pagelist.php, configured with a
new global called $SearchFilterFunctions. Here is the modification to
MakePageList():
....
if (@$opt['trail']) {
...
} else $list = ListPages($pats);
> if (@$opt['filter']) {
> if (function_exists(@$SearchFilterFunctions[$opt['filter']])) {
> $list = $SearchFilterFunctions[$opt['filter']]($list);
> }
> }
if (IsEnabled($EnablePageListProtect, 1)) $readf = 1000;
$matches = array();
$FmtV['$MatchSearched'] = count($list);
....
Here is an example of how I use it (from config.php):
# This is accessible as (:pagelist filter=future:)
$SearchFilterFunctions['future'] = 'SearchFilterFuture';
function SearchFilterFuture(&$input_list)
{
$output_list = array();
foreach ($input_list as $page)
{
if (preg_match('/(\d\d\d\d-\d\d-\d\d)/', $page, $matches))
{
$event_date = $matches[1];
$today = date("Y-m-d");
if ($event_date >= $today)
{
$output_list[] = $page;
}
}
else
{
$output_list[] = $page;
}
}
return $output_list;
}
This all works. My question is - is there a better way?
1) Is there a way to do with without modifying pagelist.php?
2) I'm not very familiar with php's array functions (in fact, PmWiki is my
first encounter with php), so is there a better way to reduce the list than
"$list = $SearchFilterFunctions[$opt['filter']]($list);" ?
3) I've not been working with (:pagelist:) for very long. As a generalisation,
is it better to be inclusive or exclusive with pagelists and the like? I've
chosen to include pages that don't match the desired form. Would it be better
to exclude them?
Have a great day
Michael
More information about the pmwiki-users
mailing list