[pmwiki-users] Highlight pagelist search results based on time thresholds

Peter Bowers pbowers at pobox.com
Sun Jul 13 10:13:21 CDT 2008


On Sun, Jul 13, 2008 at 1:46 PM, Hans <design5 at softflow.co.uk> wrote:
> I was surprised I could not use {(ftime ....)} in the pagelist
> template, that's why I resorted to page variables and unix time
> comparisons.

Yes, I banged my head against the {(ftime ...)} for an hour or more
this morning before giving up and going the FmtPV route (which
presumably is faster anyway).  I revisited ftime just now and it
worked first time -- I think I must have been doing something strange
with my date formats before or something.

Here is the custom fmt def using ftime:

===(snip)===
!!!fmt=#ColorByDate2

A simple bullet list of page names. Colored %red%red%% if within last
7 days, %blue%blue%% if within last 30 days, %green%green%% if older.

[@
[[#ColorByDate2]]
* (:if date {(ftime "%Y-%m-%d" "-7 days")}..{(ftime "%Y-%m-%d")}
{(ftime "%Y-%m-%d" "{=$LastModifiedYMD}")}:)%red%(:elseif date {(ftime
"%Y-%m-%d" "-30 days")}..{(ftime "%Y-%m-%d")} {(ftime "%Y-%m-%d"
@{=$LastModifiedU})}:)%blue%(:else:)%green%(:ifend:) [[{=$FullName}]]
{=$LastModified}%%
[[#ColorByDate2end]]
@]
===(snip)===

You'll note I use {=$LastModifiedYMD} in one place and
@{=$LastModifiedU} in the 2nd place - I was just trying to figure out
where I went bad before. I think my problem was missing the @ sign in
front of the unix time before or maybe I was just trying to use
{$LastModified} straight (which seems impalatable to ftime).  The YMD
is as expected and the U is simply unix time ($page['time']).  Anyway,
here's a (presumably slightly slower) version which does not rely
quite so heavily on config.php customization (a single date variable
needs to be added instead of 3 or 4 of them).

(The block formatting is far superior - this is just to demonstrate
the ftime side of things.)

-Peter



More information about the pmwiki-users mailing list