Path: blob/master/src/infrastructure/markup/interpreter/PhabricatorRemarkupCowsayBlockInterpreter.php
12242 views
<?php12final class PhabricatorRemarkupCowsayBlockInterpreter3extends PhutilRemarkupBlockInterpreter {45public function getInterpreterName() {6return 'cowsay';7}89public function markupContent($content, array $argv) {10$action = idx($argv, 'think') ? 'think' : 'say';11$eyes = idx($argv, 'eyes', 'oo');12$tongue = idx($argv, 'tongue', ' ');1314$map = self::getCowMap();1516$cow = idx($argv, 'cow');17$cow = ($cow === null ? '' : $cow);18$cow = phutil_utf8_strtolower($cow);19if (empty($map[$cow])) {20$cow = 'default';21}2223$result = id(new PhutilCowsay())24->setTemplate($map[$cow])25->setAction($action)26->setEyes($eyes)27->setTongue($tongue)28->setText($content)29->renderCow();3031$engine = $this->getEngine();3233if ($engine->isTextMode()) {34return $result;35}3637if ($engine->isHTMLMailMode()) {38return phutil_tag('pre', array(), $result);39}4041return phutil_tag(42'div',43array(44'class' => 'PhabricatorMonospaced remarkup-cowsay',45),46$result);47}4849private static function getCowMap() {50$root = dirname(phutil_get_library_root('phabricator'));5152$directories = array(53$root.'/externals/cowsay/cows/',54$root.'/resources/cows/builtin/',55$root.'/resources/cows/custom/',56);5758$map = array();59foreach ($directories as $directory) {60foreach (Filesystem::listDirectory($directory, false) as $cow_file) {61$matches = null;62if (!preg_match('/^(.*)\.cow\z/', $cow_file, $matches)) {63continue;64}65$cow_name = $matches[1];66$cow_name = phutil_utf8_strtolower($cow_name);67$map[$cow_name] = Filesystem::readFile($directory.$cow_file);68}69}7071return $map;72}7374}757677