mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-01 01:18:22 +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:
parent
99e7810572
commit
cd6a4e764a
5 changed files with 62 additions and 0 deletions
|
@ -1122,6 +1122,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorRemarkupRuleImageMacro' => 'infrastructure/markup/rule/PhabricatorRemarkupRuleImageMacro.php',
|
'PhabricatorRemarkupRuleImageMacro' => 'infrastructure/markup/rule/PhabricatorRemarkupRuleImageMacro.php',
|
||||||
'PhabricatorRemarkupRuleManiphest' => 'infrastructure/markup/rule/PhabricatorRemarkupRuleManiphest.php',
|
'PhabricatorRemarkupRuleManiphest' => 'infrastructure/markup/rule/PhabricatorRemarkupRuleManiphest.php',
|
||||||
'PhabricatorRemarkupRuleManiphestHandle' => 'infrastructure/markup/rule/handle/PhabricatorRemarkupRuleManiphestHandle.php',
|
'PhabricatorRemarkupRuleManiphestHandle' => 'infrastructure/markup/rule/handle/PhabricatorRemarkupRuleManiphestHandle.php',
|
||||||
|
'PhabricatorRemarkupRuleMeme' => 'infrastructure/markup/rule/PhabricatorRemarkupRuleMeme.php',
|
||||||
'PhabricatorRemarkupRuleMention' => 'infrastructure/markup/rule/PhabricatorRemarkupRuleMention.php',
|
'PhabricatorRemarkupRuleMention' => 'infrastructure/markup/rule/PhabricatorRemarkupRuleMention.php',
|
||||||
'PhabricatorRemarkupRuleObjectHandle' => 'infrastructure/markup/rule/PhabricatorRemarkupRuleObjectHandle.php',
|
'PhabricatorRemarkupRuleObjectHandle' => 'infrastructure/markup/rule/PhabricatorRemarkupRuleObjectHandle.php',
|
||||||
'PhabricatorRemarkupRuleObjectName' => 'infrastructure/markup/rule/PhabricatorRemarkupRuleObjectName.php',
|
'PhabricatorRemarkupRuleObjectName' => 'infrastructure/markup/rule/PhabricatorRemarkupRuleObjectName.php',
|
||||||
|
@ -2499,6 +2500,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorRemarkupRuleImageMacro' => 'PhutilRemarkupRule',
|
'PhabricatorRemarkupRuleImageMacro' => 'PhutilRemarkupRule',
|
||||||
'PhabricatorRemarkupRuleManiphest' => 'PhabricatorRemarkupRuleObjectName',
|
'PhabricatorRemarkupRuleManiphest' => 'PhabricatorRemarkupRuleObjectName',
|
||||||
'PhabricatorRemarkupRuleManiphestHandle' => 'PhabricatorRemarkupRuleObjectHandle',
|
'PhabricatorRemarkupRuleManiphestHandle' => 'PhabricatorRemarkupRuleObjectHandle',
|
||||||
|
'PhabricatorRemarkupRuleMeme' => 'PhutilRemarkupRule',
|
||||||
'PhabricatorRemarkupRuleMention' => 'PhutilRemarkupRule',
|
'PhabricatorRemarkupRuleMention' => 'PhutilRemarkupRule',
|
||||||
'PhabricatorRemarkupRuleObjectHandle' => 'PhutilRemarkupRule',
|
'PhabricatorRemarkupRuleObjectHandle' => 'PhutilRemarkupRule',
|
||||||
'PhabricatorRemarkupRuleObjectName' => 'PhutilRemarkupRule',
|
'PhabricatorRemarkupRuleObjectName' => 'PhutilRemarkupRule',
|
||||||
|
|
|
@ -419,6 +419,7 @@ final class PhabricatorMarkupEngine {
|
||||||
|
|
||||||
if ($options['macros']) {
|
if ($options['macros']) {
|
||||||
$rules[] = new PhabricatorRemarkupRuleImageMacro();
|
$rules[] = new PhabricatorRemarkupRuleImageMacro();
|
||||||
|
$rules[] = new PhabricatorRemarkupRuleMeme();
|
||||||
}
|
}
|
||||||
|
|
||||||
$rules[] = new PhabricatorRemarkupRuleMention();
|
$rules[] = new PhabricatorRemarkupRuleMention();
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -49,6 +49,12 @@ final class PhabricatorRemarkupControl extends AphrontFormTextAreaControl {
|
||||||
'table' => array(
|
'table' => array(
|
||||||
'tip' => pht('Table'),
|
'tip' => pht('Table'),
|
||||||
),
|
),
|
||||||
|
array(
|
||||||
|
'spacer' => true,
|
||||||
|
),
|
||||||
|
'meme' => array(
|
||||||
|
'tip' => pht('Meme'),
|
||||||
|
),
|
||||||
'help' => array(
|
'help' => array(
|
||||||
'tip' => pht('Help'),
|
'tip' => pht('Help'),
|
||||||
'align' => 'right',
|
'align' => 'right',
|
||||||
|
|
|
@ -59,6 +59,17 @@ JX.behavior('phabricator-remarkup-assist', function(config) {
|
||||||
case 'table':
|
case 'table':
|
||||||
update(area, (r.start == 0 ? '' : '\n\n') + '| ', sel || 'data', ' |');
|
update(area, (r.start == 0 ? '' : '\n\n') + '| ', sel || 'data', ' |');
|
||||||
break;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue