1: <?php
2: 3: 4:
5: class Horde_Block_Fortune extends Horde_Core_Block
6: {
7: 8:
9: public $updateable = true;
10:
11: 12:
13: public function __construct($app, $params = array())
14: {
15: parent::__construct($app, $params);
16:
17: $this->enabled = (isset($GLOBALS['conf']['fortune']['exec_path']) && is_executable($GLOBALS['conf']['fortune']['exec_path']));
18: $this->_name = _("Random Fortune");
19: }
20:
21: 22:
23: protected function _title()
24: {
25: return _("Fortune");
26: }
27:
28: 29:
30: protected function _params()
31: {
32: global $conf;
33:
34: $descriptions = array(
35: 'art' => _("Art"),
36: 'ascii-art' => _("Ascii Art"),
37: 'bofh-excuses' => _("BOFH Excuses"),
38: 'computers' => _("Computers"),
39: 'cookie' => _("Cookie"),
40: 'definitions' => _("Definitions"),
41: 'drugs' => _("Drugs"),
42: 'education' => _("Education"),
43: 'ethnic' => _("Ethnic"),
44: 'food' => _("Food"),
45: 'fortunes' => _("Fortunes"),
46: 'fortunes2' => _("Fortunes 2"),
47: 'goedel' => _("Goedel"),
48: 'humorists' => _("Humorists"),
49: 'kernelnewbies' => _("Kernel Newbies"),
50: 'kids' => _("Kids"),
51: 'law' => _("Law"),
52: 'limerick' => _("Limerick"),
53: 'linuxcookie' => _("Linux Cookie"),
54: 'literature' => _("Literature"),
55: 'love' => _("Love"),
56: 'magic' => _("Magic"),
57: 'medicine' => _("Medicine"),
58: 'miscellaneous' => _("Miscellaneous"),
59: 'news' => _("News"),
60: 'osfortune' => _("Operating System"),
61: 'people' => _("People"),
62: 'pets' => _("Pets"),
63: 'platitudes' => _("Platitudes"),
64: 'politics' => _("Politics"),
65: 'riddles' => _("Riddles"),
66: 'science' => _("Science"),
67: 'songs-poems' => _("Songs & Poems"),
68: 'sports' => _("Sports"),
69: 'startrek' => _("Star Trek"),
70: 'translate-me' => _("Translations"),
71: 'wisdom' => _("Wisdom"),
72: 'work' => _("Work"),
73: 'zippy' => _("Zippy")
74: );
75:
76: $values = array();
77:
78: exec($conf['fortune']['exec_path'] . ' -f 2>&1', $output, $status);
79: if (!$status) {
80: for ($i = 1, $ocnt = count($output); $i < $ocnt; ++$i) {
81: $fortune = substr($output[$i], strrpos($output[$i], ' ') + 1);
82: $values[$fortune] = isset($descriptions[$fortune])
83: ? $descriptions[$fortune]
84: : $fortune;
85: }
86: }
87:
88: if (empty($values)) {
89: $values = $descriptions;
90: }
91:
92: asort($values);
93: $values = array_merge(array('' => _("All")), $values);
94:
95: return array(
96: 'offend' => array(
97: 'type' => 'enum',
98: 'name' => _("Offense filter"),
99: 'default' => '',
100: 'values' => array(
101: '' => _("No offensive fortunes"),
102: ' -o' => _("Only offensive fortunes"),
103: ' -a' => _("Both")
104: )
105: ),
106: 'fortune' => array(
107: 'type' => 'multienum',
108: 'name' => _("Fortune type"),
109: 'default' => array(''),
110: 'values' => $values
111: )
112: );
113: }
114:
115: 116:
117: protected function _content()
118: {
119: global $conf;
120:
121: $cmdLine = $conf['fortune']['exec_path']
122: . $this->_params['offend']
123: . ' ' . implode(' ', $this->_params['fortune']);
124:
125: return '<span class="fixed"><small>'
126: . nl2br($GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter(shell_exec($cmdLine), array('space2html'), array(array('encode' => true))))
127: . '</small></span>';
128: }
129:
130: }
131: