1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 00:42:41 +01:00

Rough implementation of the "Add Meme" button

Summary: This needs some tweaks but I'll follow up with @DeedyDas in T2353.

Test Plan: So many memes.

Reviewers: chad, btrahan, DeedyDas

Reviewed By: chad

CC: aran

Maniphest Tasks: T2353

Differential Revision: https://secure.phabricator.com/D4616
This commit is contained in:
epriestley 2013-01-24 09:57:58 -08:00
parent 99e7810572
commit cd6a4e764a
5 changed files with 62 additions and 0 deletions

View file

@ -1122,6 +1122,7 @@ phutil_register_library_map(array(
'PhabricatorRemarkupRuleImageMacro' => 'infrastructure/markup/rule/PhabricatorRemarkupRuleImageMacro.php',
'PhabricatorRemarkupRuleManiphest' => 'infrastructure/markup/rule/PhabricatorRemarkupRuleManiphest.php',
'PhabricatorRemarkupRuleManiphestHandle' => 'infrastructure/markup/rule/handle/PhabricatorRemarkupRuleManiphestHandle.php',
'PhabricatorRemarkupRuleMeme' => 'infrastructure/markup/rule/PhabricatorRemarkupRuleMeme.php',
'PhabricatorRemarkupRuleMention' => 'infrastructure/markup/rule/PhabricatorRemarkupRuleMention.php',
'PhabricatorRemarkupRuleObjectHandle' => 'infrastructure/markup/rule/PhabricatorRemarkupRuleObjectHandle.php',
'PhabricatorRemarkupRuleObjectName' => 'infrastructure/markup/rule/PhabricatorRemarkupRuleObjectName.php',
@ -2499,6 +2500,7 @@ phutil_register_library_map(array(
'PhabricatorRemarkupRuleImageMacro' => 'PhutilRemarkupRule',
'PhabricatorRemarkupRuleManiphest' => 'PhabricatorRemarkupRuleObjectName',
'PhabricatorRemarkupRuleManiphestHandle' => 'PhabricatorRemarkupRuleObjectHandle',
'PhabricatorRemarkupRuleMeme' => 'PhutilRemarkupRule',
'PhabricatorRemarkupRuleMention' => 'PhutilRemarkupRule',
'PhabricatorRemarkupRuleObjectHandle' => 'PhutilRemarkupRule',
'PhabricatorRemarkupRuleObjectName' => 'PhutilRemarkupRule',

View file

@ -419,6 +419,7 @@ final class PhabricatorMarkupEngine {
if ($options['macros']) {
$rules[] = new PhabricatorRemarkupRuleImageMacro();
$rules[] = new PhabricatorRemarkupRuleMeme();
}
$rules[] = new PhabricatorRemarkupRuleMention();

View file

@ -0,0 +1,42 @@
<?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']);
$img = phutil_render_tag(
'img',
array(
'src' => (string)$uri,
));
return $this->getEngine()->storeText($img);
}
}

View file

@ -49,6 +49,12 @@ final class PhabricatorRemarkupControl extends AphrontFormTextAreaControl {
'table' => array(
'tip' => pht('Table'),
),
array(
'spacer' => true,
),
'meme' => array(
'tip' => pht('Meme'),
),
'help' => array(
'tip' => pht('Help'),
'align' => 'right',

View file

@ -59,6 +59,17 @@ JX.behavior('phabricator-remarkup-assist', function(config) {
case 'table':
update(area, (r.start == 0 ? '' : '\n\n') + '| ', sel || 'data', ' |');
break;
case 'meme':
new JX.Workflow('/macro/meme/create/')
.setHandler(function(response) {
update(
area,
'',
sel,
(r.start == 0 ? '' : '\n\n') + response.text + '\n\n');
})
.start();
break;
}
}