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