Fortune

Summary: Insert a fortune cookie into a wiki page
Version: 2007-09-17
Status: Stable
Prerequisites: pmwiki-2.x
Maintainer: Dfaure
Categories: Includes
Download: fortune.phpΔ
Discussion: Fortune-Talk?

Description

Fortune adds the (:fortune:) markup directive which provides randomly chosen fortune quotes:

(:fortune:)
A chicken is an egg's way of producing more eggs.

Put fortune.phpΔ in the PmWiki cookbook/ directory, and add the following line to local/config.php:

include_once("$FarmD/cookbook/fortune.php");

Then, depending to your hosting os, you may either:

  • Extract fortunes-min.zipΔ into cookbook/ directory,
  • Set $FortuneDir variable to the appropriate location (usually: /usr/share/games/fortunes), before the include_once... line into local/config.php.

Notes

Fortune quotes are often multiline raw text which don't render very well when injected into html. They are (by default) rendered into <div class='fortune'><pre>...</pre></div> blocks to provide the best readability.

fortunes-min.zipΔ contains only 3 quotes files to avoid heavy download. Full standard distribution and additional quote files are availables from Linux distrib. archives.

The quotes may be selected from a subset of the referenced files with the file=... option (list of comma separated names).

Limitations/Implementation considerations

The $FortuneFilter variable provides the name of the function responsible to reformat the selected quote before outputing it. The default implementation is limited to html special chars translation.

The following code in your configuration file would handle the rendering of utf8 encoded fortune files:

$FortuneFilter = 'FortuneUtf8Filter';

function FortuneUtf8Filter($pagename, $opt, &$file, &$txt, &$rank) {
  $file = basename($file);
  $txt  = htmlspecialchars(utf8_decode($txt), ENT_NOQUOTES);
}

See Also

RandomQuote

Contributors

Dfaure

History

2007-09-17
Rewritten (almost) from scratch.
2006-03-07
Cleaned code, merging unreleased enhancements. Updated licensing terms.
2005-01-18
Initial release

Comments

See discussion at Fortune-Talk?

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.