Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/infrastructure/markup/interpreter/PhabricatorRemarkupCowsayBlockInterpreter.php
12242 views
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
$action = idx($argv, 'think') ? 'think' : 'say';
12
$eyes = idx($argv, 'eyes', 'oo');
13
$tongue = idx($argv, 'tongue', ' ');
14
15
$map = self::getCowMap();
16
17
$cow = idx($argv, 'cow');
18
$cow = ($cow === null ? '' : $cow);
19
$cow = phutil_utf8_strtolower($cow);
20
if (empty($map[$cow])) {
21
$cow = 'default';
22
}
23
24
$result = id(new PhutilCowsay())
25
->setTemplate($map[$cow])
26
->setAction($action)
27
->setEyes($eyes)
28
->setTongue($tongue)
29
->setText($content)
30
->renderCow();
31
32
$engine = $this->getEngine();
33
34
if ($engine->isTextMode()) {
35
return $result;
36
}
37
38
if ($engine->isHTMLMailMode()) {
39
return phutil_tag('pre', array(), $result);
40
}
41
42
return phutil_tag(
43
'div',
44
array(
45
'class' => 'PhabricatorMonospaced remarkup-cowsay',
46
),
47
$result);
48
}
49
50
private static function getCowMap() {
51
$root = dirname(phutil_get_library_root('phabricator'));
52
53
$directories = array(
54
$root.'/externals/cowsay/cows/',
55
$root.'/resources/cows/builtin/',
56
$root.'/resources/cows/custom/',
57
);
58
59
$map = array();
60
foreach ($directories as $directory) {
61
foreach (Filesystem::listDirectory($directory, false) as $cow_file) {
62
$matches = null;
63
if (!preg_match('/^(.*)\.cow\z/', $cow_file, $matches)) {
64
continue;
65
}
66
$cow_name = $matches[1];
67
$cow_name = phutil_utf8_strtolower($cow_name);
68
$map[$cow_name] = Filesystem::readFile($directory.$cow_file);
69
}
70
}
71
72
return $map;
73
}
74
75
}
76
77