X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=plugins%2Ffortune%2Ffunctions.php;h=fd2432a72b7519defeee11faeba04c1dde721b65;hb=353d074afac6827c90f4bb03e846c5e453d3b5b1;hp=c3733dfd6e5e12869c95e42994ffd0070ccf5ea6;hpb=4b4abf93a9624311afef0c385023724ee46a2b60;p=squirrelmail.git diff --git a/plugins/fortune/functions.php b/plugins/fortune/functions.php index c3733dfd..fd2432a7 100644 --- a/plugins/fortune/functions.php +++ b/plugins/fortune/functions.php @@ -3,7 +3,7 @@ /** * Fortune plugin functions * - * @copyright © 2004-2005 The SquirrelMail Project Team + * @copyright 2004-2018 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)) { + // i18n: %s shows executed fortune cookie command. + $fortune = sprintf(_("Unable to execute \"%s\"."),$fortune_command); } - echo '
'; + $oTemplate->assign('color', $color); + $oTemplate->assign('fortune', sm_encode_html_special_chars($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