Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F441515
PhabricatorRemarkupBlockInterpreterCowsay.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
PhabricatorRemarkupBlockInterpreterCowsay.php
View Options
<?php
final
class
PhabricatorRemarkupBlockInterpreterCowsay
extends
PhutilRemarkupBlockInterpreter
{
public
function
getInterpreterName
()
{
return
'cowsay'
;
}
public
function
markupContent
(
$content
,
array
$argv
)
{
if
(!
Filesystem
::
binaryExists
(
'cowsay'
))
{
return
$this
->
markupError
(
pht
(
'Unable to locate the `cowsay` binary. Install cowsay.'
));
}
$bin
=
idx
(
$argv
,
'think'
)
?
'cowthink'
:
'cowsay'
;
$eyes
=
idx
(
$argv
,
'eyes'
,
'oo'
);
$tongue
=
idx
(
$argv
,
'tongue'
,
' '
);
$cow
=
idx
(
$argv
,
'cow'
,
'default'
);
// NOTE: Strip this aggressively to prevent nonsense like
// `cow=/etc/passwd`. We could build a whiltelist with `cowsay -l`.
$cow
=
preg_replace
(
'/[^a-z.-]+/'
,
''
,
$cow
);
$future
=
new
ExecFuture
(
'%s -e %s -T %s -f %s '
,
$bin
,
$eyes
,
$tongue
,
$cow
);
$future
->
setTimeout
(
15
);
$future
->
write
(
$content
);
list
(
$err
,
$stdout
,
$stderr
)
=
$future
->
resolve
();
if
(
$err
)
{
return
$this
->
markupError
(
pht
(
'Execution of `cowsay` failed:'
,
$stderr
));
}
if
(
$this
->
getEngine
()->
isTextMode
())
{
return
$stdout
;
}
return
phutil_tag
(
'div'
,
array
(
'class'
=>
'PhabricatorMonospaced remarkup-cowsay'
,
),
$stdout
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, May 4, 7:31 AM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
64490
Default Alt Text
PhabricatorRemarkupBlockInterpreterCowsay.php (1 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment