1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-11 08:06:13 +01:00
phorge-phorge/src/applications/macro/remarkup/PhabricatorRemarkupRuleMeme.php

50 lines
1.1 KiB
PHP
Raw Normal View History

<?php
/**
* @group markup
*/
final class PhabricatorRemarkupRuleMeme
extends PhutilRemarkupRule {
private $images;
public function apply($text) {
return preg_replace_callback(
'@{meme,((?:[^}\\\\]+|\\\\.)+)}$@m',
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']);
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,
));
}
return $this->getEngine()->storeText($img);
}
}