functions.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Fortune plugin functions
  4. *
  5. * @copyright &copy; 2004-2007 The SquirrelMail Project Team
  6. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  7. * @version $Id$
  8. * @package plugins
  9. * @subpackage fortune
  10. */
  11. /**
  12. * Declare configuration global and set default value
  13. */
  14. global $fortune_command;
  15. $fortune_command = '/usr/games/fortune -s';
  16. /**
  17. * Load site config
  18. */
  19. if (file_exists(SM_PATH . 'config/fortune_config.php')) {
  20. include_once(SM_PATH . 'config/fortune_config.php');
  21. } elseif (file_exists(SM_PATH . 'plugins/fortune/config.php')) {
  22. include_once(SM_PATH . 'plugins/fortune/config.php');
  23. }
  24. /**
  25. * Show fortune
  26. * @access private
  27. * @since 1.5.1
  28. */
  29. function fortune_function() {
  30. global $oTemplate, $fortune_visible, $color, $fortune_command;
  31. if (!$fortune_visible) {
  32. return;
  33. }
  34. /* open handle and get all command output*/
  35. $handle = popen($fortune_command,'r');
  36. $fortune = '';
  37. while ($read = fread($handle,1024)) {
  38. $fortune .= $read;
  39. }
  40. /* if pclose return != 0, popen command failed. Yes, I know that it is broken when --enable-sigchild is used */
  41. if (pclose($handle)) {
  42. // i18n: %s shows executed fortune cookie command.
  43. $fortune = sprintf(_("Unable to execute \"%s\"."),$fortune_command);
  44. }
  45. $oTemplate->assign('color', $color);
  46. $oTemplate->assign('fortune', htmlspecialchars($fortune));
  47. $output = $oTemplate->fetch('plugins/fortune/mailbox_index_before.tpl');
  48. return array('mailbox_index_before' => $output);
  49. }
  50. /**
  51. * Add fortune options
  52. * @access private
  53. * @since 1.5.1
  54. */
  55. function fortune_function_options() {
  56. global $optpage_data;
  57. $optpage_data['grps']['fortune'] = _("Fortunes:");
  58. $optionValues = array();
  59. $optionValues[] = array('name' => 'fortune_visible',
  60. 'caption' => _("Show fortunes at top of mailbox"),
  61. 'type' => SMOPT_TYPE_BOOLEAN,
  62. 'initial_value' => false );
  63. $optpage_data['vals']['fortune'] = $optionValues;
  64. }
  65. /**
  66. * Get fortune prefs
  67. * @access private
  68. * @since 1.5.1
  69. */
  70. function fortune_function_load() {
  71. global $username, $data_dir, $fortune_visible;
  72. $fortune_visible = getPref($data_dir, $username, 'fortune_visible');
  73. }