2006-07-29 23:53:57 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# Include a fortune in a page
|
|
|
|
package IkiWiki::Plugin::fortune;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2008-12-23 22:34:19 +01:00
|
|
|
use IkiWiki 3.00;
|
2006-07-29 23:53:57 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub import {
|
2008-08-03 22:40:12 +02:00
|
|
|
hook(type => "getsetup", id => "fortune", call => \&getsetup);
|
2006-09-10 00:50:27 +02:00
|
|
|
hook(type => "preprocess", id => "fortune", call => \&preprocess);
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2006-07-29 23:53:57 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub getsetup () {
|
2008-08-03 22:40:12 +02:00
|
|
|
return
|
|
|
|
plugin => {
|
|
|
|
safe => 1,
|
|
|
|
rebuild => undef,
|
|
|
|
},
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-08-03 22:40:12 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub preprocess (@) {
|
2006-07-29 23:53:57 +02:00
|
|
|
$ENV{PATH}="$ENV{PATH}:/usr/games:/usr/local/games";
|
2006-11-28 19:16:04 +01:00
|
|
|
my $f = `fortune 2>/dev/null`;
|
2006-07-29 23:53:57 +02:00
|
|
|
|
|
|
|
if ($?) {
|
2008-07-13 21:05:34 +02:00
|
|
|
error gettext("fortune failed");
|
2006-07-29 23:53:57 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return "<pre>$f</pre>\n";
|
|
|
|
}
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2006-07-29 23:53:57 +02:00
|
|
|
|
|
|
|
1
|