mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-11 08:06:13 +01:00
efe0c135fe
Test Plan: lang=remarkup D1 {D1} {C1} {F1} [[ Test ]] iiam {meme, src=iiam, above="I\'m not always", below="But I am"} @{function:pht} @vrana Reviewers: epriestley, edward Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2617 Differential Revision: https://secure.phabricator.com/D5392
49 lines
1.1 KiB
PHP
49 lines
1.1 KiB
PHP
<?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);
|
|
}
|
|
|
|
}
|