0173e3bb91bd0789ba29a57d1126a97b3fdcfbab
4 * Fortune plugin functions
6 * @copyright © 2004-2009 The SquirrelMail Project Team
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
14 * Declare configuration global and set default value
16 global $fortune_command;
17 $fortune_command = '/usr/games/fortune -s';
22 if (file_exists(SM_PATH
. 'config/fortune_config.php')) {
23 include_once(SM_PATH
. 'config/fortune_config.php');
24 } elseif (file_exists(SM_PATH
. 'plugins/fortune/config.php')) {
25 include_once(SM_PATH
. 'plugins/fortune/config.php');
33 function fortune_function() {
34 global $oTemplate, $fortune_visible, $color, $fortune_command;
36 if (!$fortune_visible) {
40 /* open handle and get all command output*/
41 $handle = popen($fortune_command,'r');
43 while ($read = fread($handle,1024)) {
46 /* if pclose return != 0, popen command failed. Yes, I know that it is broken when --enable-sigchild is used */
47 if (pclose($handle)) {
48 // i18n: %s shows executed fortune cookie command.
49 $fortune = sprintf(_("Unable to execute \"%s\"."),$fortune_command);
52 $oTemplate->assign('color', $color);
53 $oTemplate->assign('fortune', htmlspecialchars($fortune));
54 $output = $oTemplate->fetch('plugins/fortune/mailbox_index_before.tpl');
55 return array('mailbox_index_before' => $output);
64 function fortune_function_options() {
67 $optpage_data['grps']['fortune'] = _("Fortunes:");
68 $optionValues = array();
69 $optionValues[] = array('name' => 'fortune_visible',
70 'caption' => _("Show fortunes at top of mailbox"),
71 'type' => SMOPT_TYPE_BOOLEAN
,
72 'initial_value' => false );
73 $optpage_data['vals']['fortune'] = $optionValues;
81 function fortune_function_load() {
82 global $username, $data_dir, $fortune_visible;
84 $fortune_visible = getPref($data_dir, $username, 'fortune_visible');