PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/horde-3.3.13/lib/Block/fortune.php

#
PHP | 139 lines | 107 code | 13 blank | 19 comment | 9 complexity | d8a11812d2ce9e019b2ad33a8d16149a MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Disable block if not configured. */
  3. if (isset($GLOBALS['conf']['fortune']['exec_path']) &&
  4. is_executable($GLOBALS['conf']['fortune']['exec_path'])) {
  5. $block_name = _("Random Fortune");
  6. }
  7. /**
  8. * $Horde: horde/lib/Block/fortune.php,v 1.14.10.4 2007/12/20 15:01:35 jan Exp $
  9. *
  10. * @package Horde_Block
  11. */
  12. class Horde_Block_Horde_fortune extends Horde_Block {
  13. /**
  14. * Whether this block has changing content.
  15. */
  16. var $updateable = true;
  17. var $_app = 'horde';
  18. /**
  19. * The title to go in this block.
  20. *
  21. * @return string The title text.
  22. */
  23. function _title()
  24. {
  25. return _("Fortune");
  26. }
  27. function _params()
  28. {
  29. global $conf;
  30. $descriptions = array('art' => _("Art"),
  31. 'ascii-art' => _("Ascii Art"),
  32. 'bofh-excuses' => _("BOFH Excuses"),
  33. 'computers' => _("Computers"),
  34. 'cookie' => _("Cookie"),
  35. 'definitions' => _("Definitions"),
  36. 'drugs' => _("Drugs"),
  37. 'education' => _("Education"),
  38. 'ethnic' => _("Ethnic"),
  39. 'food' => _("Food"),
  40. 'fortunes' => _("Fortunes"),
  41. 'fortunes2' => _("Fortunes 2"),
  42. 'goedel' => _("Goedel"),
  43. 'humorists' => _("Humorists"),
  44. 'kernelnewbies' => _("Kernel Newbies"),
  45. 'kids' => _("Kids"),
  46. 'law' => _("Law"),
  47. 'limerick' => _("Limerick"),
  48. 'linuxcookie' => _("Linux Cookie"),
  49. 'literature' => _("Literature"),
  50. 'love' => _("Love"),
  51. 'magic' => _("Magic"),
  52. 'medicine' => _("Medicine"),
  53. 'miscellaneous' => _("Miscellaneous"),
  54. 'news' => _("News"),
  55. 'osfortune' => _("Operating System"),
  56. 'people' => _("People"),
  57. 'pets' => _("Pets"),
  58. 'platitudes' => _("Platitudes"),
  59. 'politics' => _("Politics"),
  60. 'riddles' => _("Riddles"),
  61. 'science' => _("Science"),
  62. 'songs-poems' => _("Songs & Poems"),
  63. 'sports' => _("Sports"),
  64. 'startrek' => _("Star Trek"),
  65. 'translate-me' => _("Translations"),
  66. 'wisdom' => _("Wisdom"),
  67. 'work' => _("Work"),
  68. 'zippy' => _("Zippy"));
  69. $values = null;
  70. if (isset($conf['fortune']['exec_path']) &&
  71. is_executable($conf['fortune']['exec_path'])) {
  72. exec($conf['fortune']['exec_path'] . ' -f 2>&1', $output, $status);
  73. if (!$status) {
  74. for ($i = 1; $i < count($output); $i++) {
  75. $fortune = substr($output[$i], strrpos($output[$i], ' ') + 1);
  76. if (isset($descriptions[$fortune])) {
  77. $values[$fortune] = $descriptions[$fortune];
  78. } else {
  79. $values[$fortune] = $fortune;
  80. }
  81. }
  82. }
  83. }
  84. if (is_null($values)) {
  85. $values = $descriptions;
  86. }
  87. asort($values);
  88. $values = array_merge(array('' => _("All")), $values);
  89. return array(
  90. 'offend' => array(
  91. 'type' => 'enum',
  92. 'name' => _("Offense filter"),
  93. 'default' => '',
  94. 'values' => array('' => _("No offensive fortunes"),
  95. ' -o' => _("Only offensive fortunes"),
  96. ' -a' => _("Both"))),
  97. 'fortune' => array(
  98. 'type' => 'multienum',
  99. 'name' => _("Fortune type"),
  100. 'default' => array(''),
  101. 'values' => $values));
  102. }
  103. /**
  104. * The content to go in this block.
  105. *
  106. * @return string The content
  107. */
  108. function _content()
  109. {
  110. global $conf;
  111. require_once 'Horde/Text/Filter.php';
  112. if (isset($conf['fortune']['exec_path']) &&
  113. is_executable($conf['fortune']['exec_path'])) {
  114. $cmdLine = $conf['fortune']['exec_path']
  115. . $this->_params['offend']
  116. . ' ' . implode(' ', $this->_params['fortune']);
  117. return '<span class="fixed"><small>'
  118. . nl2br(Text_Filter::filter(shell_exec($cmdLine),
  119. array('space2html'),
  120. array(array('encode' => true))))
  121. . '</small></span>';
  122. } else {
  123. return '';
  124. }
  125. }
  126. }