[ Index ]
 

Code source de Horde 3.1.3

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/Block/ -> fortune.php (source)

   1  <?php
   2  
   3  $block_name = _("Random Fortune");
   4  
   5  /**
   6   * $Horde: horde/lib/Block/fortune.php,v 1.14.10.2 2005/10/18 11:33:39 jan Exp $
   7   *
   8   * @package Horde_Block
   9   */
  10  class Horde_Block_Horde_fortune extends Horde_Block {
  11  
  12      var $_app = 'horde';
  13  
  14      /**
  15       * The title to go in this block.
  16       *
  17       * @return string   The title text.
  18       */
  19      function _title()
  20      {
  21          return _("Fortune");
  22      }
  23  
  24      function _params()
  25      {
  26          global $conf;
  27  
  28          $descriptions = array('art' => _("Art"),
  29                                'ascii-art' => _("Ascii Art"),
  30                                'bofh-excuses' => _("BOFH Excuses"),
  31                                'computers' => _("Computers"),
  32                                'cookie' => _("Cookie"),
  33                                'definitions' => _("Definitions"),
  34                                'drugs' => _("Drugs"),
  35                                'education' => _("Education"),
  36                                'ethnic' => _("Ethnic"),
  37                                'food' => _("Food"),
  38                                'fortunes' => _("Fortunes"),
  39                                'fortunes2' => _("Fortunes 2"),
  40                                'goedel' => _("Goedel"),
  41                                'humorists' => _("Humorists"),
  42                                'kernelnewbies' => _("Kernel Newbies"),
  43                                'kids' => _("Kids"),
  44                                'law' => _("Law"),
  45                                'limerick' => _("Limerick"),
  46                                'linuxcookie' => _("Linux Cookie"),
  47                                'literature' => _("Literature"),
  48                                'love' => _("Love"),
  49                                'magic' => _("Magic"),
  50                                'medicine' => _("Medicine"),
  51                                'miscellaneous' => _("Miscellaneous"),
  52                                'news' => _("News"),
  53                                'osfortune' => _("Operating System"),
  54                                'people' => _("People"),
  55                                'pets' => _("Pets"),
  56                                'platitudes' => _("Platitudes"),
  57                                'politics' => _("Politics"),
  58                                'riddles' => _("Riddles"),
  59                                'science' => _("Science"),
  60                                'songs-poems' => _("Songs & Poems"),
  61                                'sports' => _("Sports"),
  62                                'startrek' => _("Star Trek"),
  63                                'translate-me' => _("Translations"),
  64                                'wisdom' => _("Wisdom"),
  65                                'work' => _("Work"),
  66                                'zippy' => _("Zippy"));
  67  
  68          $values = null;
  69          if (isset($conf['fortune']['exec_path']) &&
  70              is_executable($conf['fortune']['exec_path'])) {
  71              exec($conf['fortune']['exec_path'] . ' -f 2>&1', $output, $status);
  72              if (!$status) {
  73                  for ($i = 1; $i < count($output); $i++) {
  74                      $fortune = substr($output[$i], strrpos($output[$i], ' ') + 1);
  75                      if (isset($descriptions[$fortune])) {
  76                          $values[$fortune] = $descriptions[$fortune];
  77                      } else {
  78                          $values[$fortune] = $fortune;
  79                      }
  80                  }
  81              }
  82          }
  83          if (is_null($values)) {
  84              $values = $descriptions;
  85          }
  86          asort($values);
  87          $values = array_merge(array('' => _("All")), $values);
  88  
  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      /**
 105       * The content to go in this block.
 106       *
 107       * @return string   The content
 108       */
 109      function _content()
 110      {
 111          global $conf;
 112  
 113          if (isset($conf['fortune']['exec_path']) &&
 114              is_executable($conf['fortune']['exec_path'])) {
 115              $cmdLine = $conf['fortune']['exec_path'];
 116              $cmdLine .= $this->_params['offend'];
 117              $cmdLine .= ' ' . implode(' ', $this->_params['fortune']);
 118              return nl2br(htmlspecialchars(shell_exec($cmdLine)));
 119          } else {
 120              return '';
 121          }
 122      }
 123  
 124  }


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7