[pmwiki-users] page text variable arithmetic

blues blues4u at supereva.it
Thu Sep 13 03:09:39 CDT 2007


On Thu, 13 Sep 2007 10:54:47 +0300, Hans <design5 at softflow.co.uk> wrote:
> Wednesday, September 12, 2007, 3:44:58 PM, blues wrote:
>
>> i am using pmform to add comments, and i would like
>> to have a way to know how many comments there are on
>> the page.
>
> commentboxplus.php defines a {$PostCount} page variable.
> You could use it or a renamed version I guess.
>
>> From commentboxplus.php:
>
> # add page variable {$PostCount},
> # counts message items per page
> $FmtPV['$PostCount'] = 'StringCount($pn,">>messagehead<<")';
> function StringCount($pagename,$find) {
>    $page = ReadPage($pagename, READPAGE_CURRENT);
>    $n = substr_count($page['text'], $find);
>    if ($n==0) return '';  #suppressing 0
>    return $n;
> }
>
>
> The function counts the occurrences of >>messagehead<<, which is
> inserted in the top of every message, so gives a good indication of
> the number of comments in the page. Yoic an replace >>messagehead<<
> with a suitable string your form adds for every comment.
>

that's very nice.
it's better to count them at run-time than to keep a PTV with
the count, so if the admin deletes a comment he doesn't have
to retouch also the count.

still, a way to do arithmetics on the PTVs would be nice
to have.

blues




More information about the pmwiki-users mailing list