X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=plugins%2Ffortune%2Ffunctions.php;h=f5851d9f31e0d272fb9fcbfdf38245444bab565b;hp=5bded0573c64049cd91385523383e75ba8130bf2;hb=8ab3c1bd38409d09e1c336107ebee474b5a7dd39;hpb=f265009a3bf872cf6c9d9aaefe7949e1688555a0 diff --git a/plugins/fortune/functions.php b/plugins/fortune/functions.php index 5bded057..f5851d9f 100644 --- a/plugins/fortune/functions.php +++ b/plugins/fortune/functions.php @@ -3,7 +3,7 @@ /** * Fortune plugin functions * - * @copyright © 2004-2006 The SquirrelMail Project Team + * @copyright © 2004-2007 The SquirrelMail Project Team * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version $Id$ * @package plugins @@ -11,14 +11,10 @@ */ /** - * Declare configuration globals + * Declare configuration global and set default value */ -global $fortune_location, $fortune_options; - -/** - * Load default config - */ -include_once(SM_PATH . 'plugins/fortune/config_default.php'); +global $fortune_command; +$fortune_command = '/usr/games/fortune -s'; /** * Load site config @@ -35,33 +31,29 @@ if (file_exists(SM_PATH . 'config/fortune_config.php')) { * @since 1.5.1 */ function fortune_function() { - global $fortune_visible, $color, $fortune_location, $fortune_options; + global $oTemplate, $fortune_visible, $color, $fortune_command; if (!$fortune_visible) { return; } - $exist = file_exists($fortune_location); - - if ($fortune_options!='') { - $fortune_command=$fortune_location . ' ' . $fortune_options; - } else { - $fortune_command=$fortune_location; + /* open handle and get all command output*/ + $handle = popen($fortune_command,'r'); + $fortune = ''; + while ($read = fread($handle,1024)) { + $fortune .= $read; } - - echo "
\n". - "
\n". - "
\n"; - echo '
'; - if (!$exist) { - printf(_("%s is not found."),$fortune_location); - } else { - echo "
" . _("Today's Fortune") . "
\n" .
-            htmlspecialchars(shell_exec($fortune_command)) .
-            "
\n"; + /* if pclose return != 0, popen command failed. Yes, I know that it is broken when --enable-sigchild is used */ + if (pclose($handle)) { + // %s shows executed fortune cookie command. + $fortune = sprintf(_("Unable to execute \"%s\"."),$fortune_command); } - echo '
'; + $oTemplate->assign('color', $color); + $oTemplate->assign('fortune', htmlspecialchars($fortune)); + $output = $oTemplate->fetch('plugins/fortune/mailbox_index_before.tpl'); + return array('mailbox_index_before' => $output); + } /** @@ -91,4 +83,3 @@ function fortune_function_load() { $fortune_visible = getPref($data_dir, $username, 'fortune_visible'); } -?> \ No newline at end of file