1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-03 20:22:46 +01:00
phorge-phorge/src/infrastructure/markup/interpreter/PhabricatorRemarkupCowsayBlockInterpreter.php
epriestley 5a874ba0a8 Put cows and figlet bannners in <pre> in HTML mail bodies
Summary: Fixes T9538. Ref T9408. `cowsay` and `figlet` Remarkup rules are being mangled in HTML mail right now. Put them in <pre> to unmangle them.

Test Plan:
Sent myself a cow + figlet in mail.

Used `bin/mail show-outbound --id ... --dump-html > dump.html` + open that HTML file in Safari to preview HTML mail.

Saw linebreaks and monospaced formatting.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9538, T9408

Differential Revision: https://secure.phabricator.com/D14248
2015-10-08 20:03:15 -07:00

74 lines
1.7 KiB
PHP

<?php
final class PhabricatorRemarkupCowsayBlockInterpreter
extends PhutilRemarkupBlockInterpreter {
public function getInterpreterName() {
return 'cowsay';
}
public function markupContent($content, array $argv) {
$action = idx($argv, 'think') ? 'think' : 'say';
$eyes = idx($argv, 'eyes', 'oo');
$tongue = idx($argv, 'tongue', ' ');
$map = self::getCowMap();
$cow = idx($argv, 'cow');
$cow = phutil_utf8_strtolower($cow);
if (empty($map[$cow])) {
$cow = 'default';
}
$result = id(new PhutilCowsay())
->setTemplate($map[$cow])
->setAction($action)
->setEyes($eyes)
->setTongue($tongue)
->setText($content)
->renderCow();
$engine = $this->getEngine();
if ($engine->isTextMode()) {
return $result;
}
if ($engine->isHTMLMailMode()) {
return phutil_tag('pre', array(), $result);
}
return phutil_tag(
'div',
array(
'class' => 'PhabricatorMonospaced remarkup-cowsay',
),
$result);
}
private static function getCowMap() {
$root = dirname(phutil_get_library_root('phabricator'));
$directories = array(
$root.'/externals/cowsay/cows/',
$root.'/resources/cows/builtin/',
$root.'/resources/cows/custom/',
);
$map = array();
foreach ($directories as $directory) {
foreach (Filesystem::listDirectory($directory, false) as $cow_file) {
$matches = null;
if (!preg_match('/^(.*)\.cow\z/', $cow_file, $matches)) {
continue;
}
$cow_name = $matches[1];
$cow_name = phutil_utf8_strtolower($cow_name);
$map[$cow_name] = Filesystem::readFile($directory.$cow_file);
}
}
return $map;
}
}