| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * plugins/fortune/setup.php |
| 5 | * |
| 6 | * Original code contributed by paulm@spider.org |
| 7 | * |
| 8 | * Simple SquirrelMail WebMail Plugin that displays the output of |
| 9 | * fortune above the message listing. |
| 10 | * |
| 11 | * @copyright (c) 1999-2004 The SquirrelMail Project Team |
| 12 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
| 13 | * @version $Id$ |
| 14 | * @package plugins |
| 15 | * @subpackage fortune |
| 16 | */ |
| 17 | |
| 18 | /** |
| 19 | * Init plugin |
| 20 | * @access private |
| 21 | */ |
| 22 | function squirrelmail_plugin_init_fortune() { |
| 23 | global $squirrelmail_plugin_hooks; |
| 24 | |
| 25 | $squirrelmail_plugin_hooks['mailbox_index_before']['fortune'] = 'fortune'; |
| 26 | $squirrelmail_plugin_hooks['options_display_inside']['fortune'] = 'fortune_options'; |
| 27 | $squirrelmail_plugin_hooks['options_display_save']['fortune'] = 'fortune_save'; |
| 28 | $squirrelmail_plugin_hooks['loading_prefs']['fortune'] = 'fortune_load'; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Show fortune |
| 33 | * @access private |
| 34 | */ |
| 35 | function fortune() { |
| 36 | global $fortune_visible, $color; |
| 37 | |
| 38 | if (!$fortune_visible) { |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | $fortune_location = '/usr/games/fortune'; |
| 43 | $exist = file_exists($fortune_location); |
| 44 | echo "<center><table cellpadding=0 cellspacing=0 border=0 bgcolor=$color[10]><tr><td><table width=100% cellpadding=2 cellspacing=1 border=0 bgcolor=\"$color[5]\"><tr><td align=center>"; |
| 45 | echo '<TABLE><TR><TD>'; |
| 46 | if (!$exist) { |
| 47 | echo "$fortune_location" . _(" not found."); |
| 48 | } else { |
| 49 | echo "<CENTER><FONT=3><EM>" . _("Today's Fortune") . "</EM><BR></FONT></CENTER><pre>"; |
| 50 | system($fortune_location); |
| 51 | } |
| 52 | |
| 53 | echo '</pre></TD></TR></TABLE></td></tr></table></td></tr></table></center>'; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Get fortune prefs |
| 58 | * @access private |
| 59 | */ |
| 60 | function fortune_load() { |
| 61 | global $username, $data_dir, $fortune_visible; |
| 62 | |
| 63 | $fortune_visible = getPref($data_dir, $username, 'fortune_visible'); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Add fortune options |
| 68 | * @access private |
| 69 | */ |
| 70 | function fortune_options() { |
| 71 | global $fortune_visible; |
| 72 | |
| 73 | echo "<tr>" . html_tag('td',_("Fortunes:"),'right','','nowrap') . "\n"; |
| 74 | echo '<td><input name="fortune_fortune_visible" type=CHECKBOX'; |
| 75 | if ($fortune_visible) |
| 76 | echo ' CHECKED'; |
| 77 | echo " /> " . _("Show fortunes at top of mailbox") . "</td></tr>\n"; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Save fortune prefs |
| 82 | * @access private |
| 83 | */ |
| 84 | function fortune_save() { |
| 85 | global $username,$data_dir; |
| 86 | |
| 87 | if (sqgetGlobalVar('fortune_fortune_visible',$fortune_fortune_visible,SQ_POST)) { |
| 88 | setPref($data_dir, $username, 'fortune_visible', '1'); |
| 89 | } else { |
| 90 | setPref($data_dir, $username, 'fortune_visible', ''); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | ?> |