Changeset View
Changeset View
Standalone View
Standalone View
src/applications/macro/markup/PhabricatorMemeRemarkupRule.php
| Show All 23 Lines | $options = array( | ||||
| 'src' => null, | 'src' => null, | ||||
| 'above' => null, | 'above' => null, | ||||
| 'below' => null, | 'below' => null, | ||||
| ); | ); | ||||
| $parser = new PhutilSimpleOptions(); | $parser = new PhutilSimpleOptions(); | ||||
| $options = $parser->parse($matches[1]) + $options; | $options = $parser->parse($matches[1]) + $options; | ||||
| $uri = id(new PhutilURI('/macro/meme/')) | $engine = id(new PhabricatorMemeEngine()) | ||||
| ->alter('macro', $options['src']) | ->setViewer(PhabricatorUser::getOmnipotentUser()) | ||||
| ->alter('uppertext', $options['above']) | ->setTemplate($options['src']) | ||||
| ->alter('lowertext', $options['below']); | ->setAboveText($options['above']) | ||||
| ->setBelowText($options['below']); | |||||
| $asset = $engine->loadCachedFile(); | |||||
| $uri = $engine->getGenerateURI(); | |||||
| if ($this->getEngine()->isHTMLMailMode()) { | if ($this->getEngine()->isHTMLMailMode()) { | ||||
| $uri = PhabricatorEnv::getProductionURI($uri); | $uri = PhabricatorEnv::getProductionURI($uri); | ||||
| } | } | ||||
| if ($this->getEngine()->isTextMode()) { | if ($this->getEngine()->isTextMode()) { | ||||
| $img = | $img = | ||||
| ($options['above'] != '' ? "\"{$options['above']}\"\n" : ''). | ($options['above'] != '' ? "\"{$options['above']}\"\n" : ''). | ||||
| $options['src'].' <'.PhabricatorEnv::getProductionURI($uri).'>'. | $options['src'].' <'.PhabricatorEnv::getProductionURI($uri).'>'. | ||||
| ($options['below'] != '' ? "\n\"{$options['below']}\"" : ''); | ($options['below'] != '' ? "\n\"{$options['below']}\"" : ''); | ||||
| } else { | } else { | ||||
| $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) { | |||||
| $img = $this->newTag( | |||||
| 'img', | |||||
| array( | |||||
| 'src' => $asset->getViewURI(), | |||||
| 'class' => 'phabricator-remarkup-macro', | |||||
| 'alt' => $alt_text, | |||||
| )); | |||||
| } 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); | ||||
| } | } | ||||
| } | } | ||||