| 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 | * FIXME |
| 18 | * There should be no code in setup.php, just hook registrations. Create functions.php |
| 19 | * and move the code there. |
| 20 | */ |
| 21 | |
| 22 | /** |
| 23 | * Init plugin |
| 24 | * @access private |
| 25 | */ |
| 26 | function squirrelmail_plugin_init_fortune() { |
| 27 | global $squirrelmail_plugin_hooks; |
| 28 | |
| 29 | $squirrelmail_plugin_hooks['mailbox_index_before']['fortune'] = 'fortune'; |
| 30 | $squirrelmail_plugin_hooks['options_display_inside']['fortune'] = 'fortune_options'; |
| 31 | $squirrelmail_plugin_hooks['options_display_save']['fortune'] = 'fortune_save'; |
| 32 | $squirrelmail_plugin_hooks['loading_prefs']['fortune'] = 'fortune_load'; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Show fortune |
| 37 | * @access private |
| 38 | */ |
| 39 | function fortune() { |
| 40 | global $fortune_visible, $color; |
| 41 | |
| 42 | if (!$fortune_visible) { |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | $fortune_location = '/usr/games/fortune'; |
| 47 | $exist = file_exists($fortune_location); |
| 48 | echo "<center><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" bgcolor=\"$color[10]\">\n". |
| 49 | "<tr><td><table width=\"100%\" cellpadding=\"2\" cellspacing=\"1\" border=\"0\" bgcolor=\"$color[5]\">\n". |
| 50 | "<tr><td align=\"center\">\n"; |
| 51 | echo '<table><tr><td>'; |
| 52 | if (!$exist) { |
| 53 | echo "$fortune_location" . _(" not found."); |
| 54 | } else { |
| 55 | echo "<center><em>" . _("Today's Fortune") . "</em><br /></font></center><pre>"; |
| 56 | htmlspecialchars(system($fortune_location)); |
| 57 | } |
| 58 | |
| 59 | echo '</pre></td></tr></table></td></tr></table></td></tr></table></center>'; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Get fortune prefs |
| 64 | * @access private |
| 65 | */ |
| 66 | function fortune_load() { |
| 67 | global $username, $data_dir, $fortune_visible; |
| 68 | |
| 69 | $fortune_visible = getPref($data_dir, $username, 'fortune_visible'); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Add fortune options |
| 74 | * @access private |
| 75 | */ |
| 76 | function fortune_options() { |
| 77 | global $fortune_visible; |
| 78 | |
| 79 | echo "<tr>" . html_tag('td',_("Fortunes:"),'right','','nowrap') . "\n"; |
| 80 | echo '<td><input name="fortune_fortune_visible" type="checkbox"'; |
| 81 | if ($fortune_visible) |
| 82 | echo ' checked="checked"'; |
| 83 | echo " /> " . _("Show fortunes at top of mailbox") . "</td></tr>\n"; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Save fortune prefs |
| 88 | * @access private |
| 89 | */ |
| 90 | function fortune_save() { |
| 91 | global $username,$data_dir; |
| 92 | |
| 93 | if (sqgetGlobalVar('fortune_fortune_visible',$fortune_fortune_visible,SQ_POST)) { |
| 94 | setPref($data_dir, $username, 'fortune_visible', '1'); |
| 95 | } else { |
| 96 | setPref($data_dir, $username, 'fortune_visible', ''); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | ?> |