Changeset View
Changeset View
Standalone View
Standalone View
src/applications/macro/markup/PhabricatorMemeRemarkupRule.php
| Show All 30 Lines | public function markupMeme(array $matches) { | ||||
| $engine = id(new PhabricatorMemeEngine()) | $engine = id(new PhabricatorMemeEngine()) | ||||
| ->setViewer(PhabricatorUser::getOmnipotentUser()) | ->setViewer(PhabricatorUser::getOmnipotentUser()) | ||||
| ->setTemplate($options['src']) | ->setTemplate($options['src']) | ||||
| ->setAboveText($options['above']) | ->setAboveText($options['above']) | ||||
| ->setBelowText($options['below']); | ->setBelowText($options['below']); | ||||
| $asset = $engine->loadCachedFile(); | $asset = $engine->loadCachedFile(); | ||||
| $uri = $engine->getGenerateURI(); | |||||
| if ($this->getEngine()->isHTMLMailMode()) { | $is_html_mail = $this->getEngine()->isHTMLMailMode(); | ||||
| $uri = PhabricatorEnv::getProductionURI($uri); | $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()) { | if ($asset) { | ||||
| $img = | $uri = $asset->getViewURI(); | ||||
| ($options['above'] != '' ? "\"{$options['above']}\"\n" : ''). | |||||
| $options['src'].' <'.PhabricatorEnv::getProductionURI($uri).'>'. | |||||
| ($options['below'] != '' ? "\n\"{$options['below']}\"" : ''); | |||||
| } else { | } else { | ||||
| $uri = $engine->getGenerateURI(); | |||||
| } | |||||
| 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( | $alt_text = pht( | ||||
| 'Macro %s: %s %s', | 'Macro %s: %s %s', | ||||
| $options['src'], | $options['src'], | ||||
| $options['above'], | $options['above'], | ||||
| $options['below']); | $options['below']); | ||||
| if ($asset) { | if ($asset) { | ||||
| $img = $this->newTag( | $img = $this->newTag( | ||||
| 'img', | 'img', | ||||
| array( | array( | ||||
| 'src' => $asset->getViewURI(), | 'src' => $uri, | ||||
| 'class' => 'phabricator-remarkup-macro', | 'class' => 'phabricator-remarkup-macro', | ||||
| 'alt' => $alt_text, | 'alt' => $alt_text, | ||||
| )); | )); | ||||
| } else { | } else { | ||||
| $img = id(new PHUIRemarkupImageView()) | $img = id(new PHUIRemarkupImageView()) | ||||
| ->setURI($uri) | ->setURI($uri) | ||||
| ->addClass('phabricator-remarkup-macro') | ->addClass('phabricator-remarkup-macro') | ||||
| ->setAlt($alt_text); | ->setAlt($alt_text); | ||||
| } | } | ||||
| } | |||||
| return $this->getEngine()->storeText($img); | return $this->getEngine()->storeText($img); | ||||
| } | } | ||||
| } | } | ||||