mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
Possibly fix memes in email
Summary: Depends on D19201. Ref T13101. This likely produces relatively stable-ish image references for email. They currently TTL after 30 days but this makes the jokes more exclusive and special so it's a feature, not a bug. Test Plan: I'm just going to test this in production because I'm a ninja superstar developer. Maniphest Tasks: T13101 Differential Revision: https://secure.phabricator.com/D19203
This commit is contained in:
parent
a3d282d33e
commit
10b3ddf426
2 changed files with 57 additions and 27 deletions
|
@ -163,8 +163,11 @@ final class PhabricatorMemeEngine extends Phobject {
|
|||
$data,
|
||||
array(
|
||||
'name' => 'meme-'.$template->getName(),
|
||||
'ttl.relative' => phutil_units('24 hours in seconds'),
|
||||
'canCDN' => true,
|
||||
|
||||
// In modern code these can end up linked directly in email, so let
|
||||
// them stick around for a while.
|
||||
'ttl.relative' => phutil_units('30 days in seconds'),
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -36,38 +36,65 @@ final class PhabricatorMemeRemarkupRule extends PhutilRemarkupRule {
|
|||
->setBelowText($options['below']);
|
||||
|
||||
$asset = $engine->loadCachedFile();
|
||||
$uri = $engine->getGenerateURI();
|
||||
|
||||
if ($this->getEngine()->isHTMLMailMode()) {
|
||||
$uri = PhabricatorEnv::getProductionURI($uri);
|
||||
$is_html_mail = $this->getEngine()->isHTMLMailMode();
|
||||
$is_text = $this->getEngine()->isTextMode();
|
||||
$must_inline = ($is_html_mail || $is_text);
|
||||
|
||||
if ($must_inline) {
|
||||
if (!$asset) {
|
||||
try {
|
||||
$asset = $engine->newAsset();
|
||||
} catch (Exception $ex) {
|
||||
return $matches[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->getEngine()->isTextMode()) {
|
||||
$img =
|
||||
($options['above'] != '' ? "\"{$options['above']}\"\n" : '').
|
||||
$options['src'].' <'.PhabricatorEnv::getProductionURI($uri).'>'.
|
||||
($options['below'] != '' ? "\n\"{$options['below']}\"" : '');
|
||||
if ($asset) {
|
||||
$uri = $asset->getViewURI();
|
||||
} else {
|
||||
$alt_text = pht(
|
||||
'Macro %s: %s %s',
|
||||
$options['src'],
|
||||
$options['above'],
|
||||
$options['below']);
|
||||
$uri = $engine->getGenerateURI();
|
||||
}
|
||||
|
||||
if ($asset) {
|
||||
$img = $this->newTag(
|
||||
'img',
|
||||
array(
|
||||
'src' => $asset->getViewURI(),
|
||||
'class' => 'phabricator-remarkup-macro',
|
||||
'alt' => $alt_text,
|
||||
));
|
||||
} else {
|
||||
$img = id(new PHUIRemarkupImageView())
|
||||
->setURI($uri)
|
||||
->addClass('phabricator-remarkup-macro')
|
||||
->setAlt($alt_text);
|
||||
if ($is_text) {
|
||||
$parts = array();
|
||||
|
||||
$above = $options['above'];
|
||||
if (strlen($above)) {
|
||||
$parts[] = pht('"%s"', $above);
|
||||
}
|
||||
|
||||
$parts[] = $options['src'].' <'.$uri.'>';
|
||||
|
||||
$below = $options['below'];
|
||||
if (strlen($below)) {
|
||||
$parts[] = pht('"%s"', $below);
|
||||
}
|
||||
|
||||
$parts = implode("\n", $parts);
|
||||
return $this->getEngine()->storeText($parts);
|
||||
}
|
||||
|
||||
$alt_text = pht(
|
||||
'Macro %s: %s %s',
|
||||
$options['src'],
|
||||
$options['above'],
|
||||
$options['below']);
|
||||
|
||||
if ($asset) {
|
||||
$img = $this->newTag(
|
||||
'img',
|
||||
array(
|
||||
'src' => $uri,
|
||||
'class' => 'phabricator-remarkup-macro',
|
||||
'alt' => $alt_text,
|
||||
));
|
||||
} else {
|
||||
$img = id(new PHUIRemarkupImageView())
|
||||
->setURI($uri)
|
||||
->addClass('phabricator-remarkup-macro')
|
||||
->setAlt($alt_text);
|
||||
}
|
||||
|
||||
return $this->getEngine()->storeText($img);
|
||||
|
|
Loading…
Reference in a new issue