[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/infrastructure/markup/interpreter/ -> PhabricatorRemarkupCowsayBlockInterpreter.php (source)

   1  <?php
   2  
   3  final class PhabricatorRemarkupCowsayBlockInterpreter
   4    extends PhutilRemarkupBlockInterpreter {
   5  
   6    public function getInterpreterName() {
   7      return 'cowsay';
   8    }
   9  
  10    public function markupContent($content, array $argv) {
  11      if (!Filesystem::binaryExists('cowsay')) {
  12        return $this->markupError(
  13          pht('Unable to locate the `cowsay` binary. Install cowsay.'));
  14      }
  15  
  16      $bin = idx($argv, 'think') ? 'cowthink' : 'cowsay';
  17      $eyes = idx($argv, 'eyes', 'oo');
  18      $tongue = idx($argv, 'tongue', '  ');
  19      $cow = idx($argv, 'cow', 'default');
  20  
  21      // NOTE: Strip this aggressively to prevent nonsense like
  22      // `cow=/etc/passwd`. We could build a whiltelist with `cowsay -l`.
  23      $cow = preg_replace('/[^a-z.-]+/', '', $cow);
  24  
  25      $future = new ExecFuture(
  26        '%s -e %s -T %s -f %s ',
  27        $bin,
  28        $eyes,
  29        $tongue,
  30        $cow);
  31  
  32      $future->setTimeout(15);
  33      $future->write($content);
  34  
  35      list($err, $stdout, $stderr) = $future->resolve();
  36  
  37      if ($err) {
  38        return $this->markupError(
  39          pht(
  40            'Execution of `cowsay` failed:', $stderr));
  41      }
  42  
  43  
  44      if ($this->getEngine()->isTextMode()) {
  45        return $stdout;
  46      }
  47  
  48      return phutil_tag(
  49        'div',
  50        array(
  51          'class' => 'PhabricatorMonospaced remarkup-cowsay',
  52        ),
  53        $stdout);
  54    }
  55  
  56  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1