2013-01-24 18:57:58 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group markup
|
|
|
|
*/
|
|
|
|
final class PhabricatorRemarkupRuleMeme
|
|
|
|
extends PhutilRemarkupRule {
|
|
|
|
|
|
|
|
private $images;
|
|
|
|
|
|
|
|
public function apply($text) {
|
2013-02-22 01:13:55 +01:00
|
|
|
return preg_replace_callback(
|
2013-02-22 01:36:54 +01:00
|
|
|
'@{meme,((?:[^}\\\\]+|\\\\.)+)}$@m',
|
2013-01-24 18:57:58 +01:00
|
|
|
array($this, 'markupMeme'),
|
|
|
|
$text);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function markupMeme($matches) {
|
|
|
|
$options = array(
|
|
|
|
'src' => null,
|
|
|
|
'above' => null,
|
|
|
|
'below' => null,
|
|
|
|
);
|
|
|
|
|
|
|
|
$parser = new PhutilSimpleOptions();
|
|
|
|
$options = $parser->parse($matches[1]) + $options;
|
|
|
|
|
|
|
|
$uri = id(new PhutilURI('/macro/meme/'))
|
|
|
|
->alter('macro', $options['src'])
|
|
|
|
->alter('uppertext', $options['above'])
|
|
|
|
->alter('lowertext', $options['below']);
|
|
|
|
|
2013-03-23 01:33:36 +01:00
|
|
|
if ($this->getEngine()->isTextMode()) {
|
|
|
|
$img =
|
|
|
|
($options['above'] != '' ? "\"{$options['above']}\"\n" : '').
|
|
|
|
$options['src'].' <'.PhabricatorEnv::getProductionURI($uri).'>'.
|
|
|
|
($options['below'] != '' ? "\n\"{$options['below']}\"" : '');
|
|
|
|
} else {
|
|
|
|
$img = phutil_tag(
|
|
|
|
'img',
|
|
|
|
array(
|
|
|
|
'src' => (string)$uri,
|
|
|
|
));
|
|
|
|
}
|
2013-01-24 18:57:58 +01:00
|
|
|
|
|
|
|
return $this->getEngine()->storeText($img);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|