using popen instead of shell_exec. shell_exec is disabled in safe mode.
[squirrelmail.git] / plugins / fortune / functions.php
CommitLineData
28e62e6d 1<?php
4b4abf93 2
28e62e6d 3/**
4 * Fortune plugin functions
5 *
47ccfad4 6 * @copyright &copy; 2004-2006 The SquirrelMail Project Team
28e62e6d 7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
8 * @version $Id$
9 * @package plugins
10 * @subpackage fortune
11 */
12
13/**
c3806a9d 14 * Declare configuration global and set default value
28e62e6d 15 */
c3806a9d 16global $fortune_command;
17$fortune_command = '/usr/games/fortune -s';
28e62e6d 18
19/**
20 * Load site config
21 */
22if (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');
26}
27
28/**
29 * Show fortune
30 * @access private
31 * @since 1.5.1
32 */
33function fortune_function() {
c3806a9d 34 global $fortune_visible, $color, $fortune_command;
28e62e6d 35
36 if (!$fortune_visible) {
37 return;
38 }
39
c3806a9d 40 echo "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" bgcolor=\"$color[10]\" align=\"center\">\n".
28e62e6d 41 "<tr><td><table width=\"100%\" cellpadding=\"2\" cellspacing=\"1\" border=\"0\" bgcolor=\"$color[5]\">\n".
42 "<tr><td align=\"center\">\n";
43 echo '<table><tr><td>';
c3806a9d 44
45 /* open handle and get all command output*/
46 $handle = popen($fortune_command,'r');
47 $fortune = '';
48 while ($read = fread($handle,1024)) {
49 $fortune .= $read;
28e62e6d 50 }
c3806a9d 51 /* if pclose return != 0, popen command failed. Yes, I know that it is broken when --enable-sigchild is used */
52 if (pclose($handle)) {
53 // %s shows executed fortune cookie command.
54 $fortune = sprintf(_("Unable to execute \"%s\"."),$fortune_command);
55 }
56 echo "<div style=\"text-align: center;\"><em>" . _("Today's Fortune") . "</em></div><pre>\n" .
57 htmlspecialchars($fortune) .
58 "</pre>\n";
28e62e6d 59
c3806a9d 60 echo '</td></tr></table></td></tr></table></td></tr></table>';
28e62e6d 61}
62
63/**
64 * Add fortune options
65 * @access private
66 * @since 1.5.1
67 */
68function fortune_function_options() {
69 global $optpage_data;
70
71 $optpage_data['grps']['fortune'] = _("Fortunes:");
72 $optionValues = array();
73 $optionValues[] = array('name' => 'fortune_visible',
74 'caption' => _("Show fortunes at top of mailbox"),
75 'type' => SMOPT_TYPE_BOOLEAN,
76 'initial_value' => false );
77 $optpage_data['vals']['fortune'] = $optionValues;
78}
79
80/**
81 * Get fortune prefs
82 * @access private
83 * @since 1.5.1
84 */
85function fortune_function_load() {
86 global $username, $data_dir, $fortune_visible;
87
88 $fortune_visible = getPref($data_dir, $username, 'fortune_visible');
89}