Revision [20685]

This is an old revision of HashAction made by BrianKoontz on 2009-06-06 18:28:25.

 

Word Count Action


Inserts a wordcount (my format, your format, or no format) into a document. Needed something quick and dirty, so there's some refinement yet to be done.

actions/wordcount.php
<?php
/*
 * Word count action
 * Author: Brian Koontz <brian@pongonova.net>
 *
 * Replace instances of {{wordcount}} with the number of words in the
 * text
 *
 * Optionally: {{wordcount preformatted="1"
 *                          pretext="Some pretext"
 *                          posttext="Some posttext"}}
 *
 * where preformatted = "1" produces "+++Word count: 9999 word(s)+++"
 *       pretext is the text to precede the word count (overrides preformatted)
 *       posttest is the text to follow the word count (overrides preformatted)
 *
 * TODO: Probably counts a lot of things it should, and a lot of
 * things it shouldn't.  Probably shouldn't count actions or other
 * special items.
 */


$preformatted = $vars['preformatted'];
$pretext = $vars['pretext'];
$posttext = $vars['posttext'];

if( $pretext || $posttext) {
    $pretext ? 1 : $pretext = '';
    $posttext ? 1 : $posttext = '';
} else if($preformatted) {
    $pretext = "+++Word count: ";
    $posttext = " word(s)+++";
}

$wc = str_word_count($this->page['body']);
echo $pretext.$wc.$posttext;

?>



CategoryUserContributions
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki