* Don't autovifivy @fields array entries.
[interchange.git] / code / UserTag / fortune.tag
1 # Copyright 2002-2007 Interchange Development Group and others
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.  See the LICENSE file for details.
7
8 # $Id: fortune.tag,v 1.7 2007-03-30 23:40:57 pajamian Exp $
9
10 UserTag fortune Order   short
11 UserTag fortune addAttr
12 UserTag fortune Version $Revision: 1.7 $
13 UserTag fortune Routine <<EOR
14 sub {
15         my ($short, $opt) = @_;
16         my $cmd = $Global::Variable->{MV_FORTUNE_COMMAND} || '/usr/games/fortune';
17         my @flags;
18         push @flags, '-s' if is_yes($short);
19         for(grep length($_) == 1, keys %$opt) {
20                 push @flags, "-$_" if $opt->{$_};
21         }
22
23         if(is_yes($opt->{no_computer}) ) {
24                 push @flags, qw/
25                         6% education 
26                         6% food 
27                         6% humorists 
28                         6% kids 
29                         6% law 
30                         6% literature 
31                         6% love 
32                         6% medicine 
33                         6% people 
34                         6% pets 
35                         6% platitudes 
36                         6% politics 
37                         6% science 
38                         6% sports 
39                         6% work
40                         10% wisdom
41                         /;
42         }
43
44         my $out = '';
45         open(FORT, '-|') || exec ($cmd, @flags);
46
47         while (<FORT>) {
48                 $out .= $_
49         }
50
51         unless($opt->{raw}) {
52                 $out = filter_value('text2html', $out);
53                 $out =~ s/--(?!:.*--)/<br>--/s;
54         }
55         return $out;
56 }
57 EOR