2013-01-22 03:46:04 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorMacroMemeDialogController
|
|
|
|
extends PhabricatorMacroController {
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
2013-11-26 04:22:06 +01:00
|
|
|
$phid = head($request->getArr('macro'));
|
2013-01-22 03:46:04 +01:00
|
|
|
$above = $request->getStr('above');
|
|
|
|
$below = $request->getStr('below');
|
|
|
|
|
|
|
|
$e_macro = true;
|
|
|
|
$errors = array();
|
|
|
|
if ($request->isDialogFormPost()) {
|
2013-11-26 04:22:06 +01:00
|
|
|
if (!$phid) {
|
2013-01-22 03:46:04 +01:00
|
|
|
$e_macro = pht('Required');
|
|
|
|
$errors[] = pht('Macro name is required.');
|
|
|
|
} else {
|
2013-03-22 21:07:20 +01:00
|
|
|
$macro = id(new PhabricatorMacroQuery())
|
|
|
|
->setViewer($user)
|
2013-11-26 04:22:06 +01:00
|
|
|
->withPHIDs(array($phid))
|
2013-03-22 21:07:20 +01:00
|
|
|
->executeOne();
|
2013-01-22 03:46:04 +01:00
|
|
|
if (!$macro) {
|
|
|
|
$e_macro = pht('Invalid');
|
|
|
|
$errors[] = pht('No such macro.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$errors) {
|
2013-02-22 01:36:54 +01:00
|
|
|
$options = new PhutilSimpleOptions();
|
|
|
|
$data = array(
|
2013-11-26 04:22:06 +01:00
|
|
|
'src' => $macro->getName(),
|
2013-02-22 01:36:54 +01:00
|
|
|
'above' => $above,
|
|
|
|
'below' => $below,
|
|
|
|
);
|
|
|
|
$string = $options->unparse($data, $escape = '}');
|
|
|
|
|
2013-01-22 03:46:04 +01:00
|
|
|
$result = array(
|
2013-02-22 01:36:54 +01:00
|
|
|
'text' => "{meme, {$string}}",
|
2013-01-22 03:46:04 +01:00
|
|
|
);
|
|
|
|
return id(new AphrontAjaxResponse())->setContent($result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-31 23:10:55 +02:00
|
|
|
$view = id(new AphrontFormView())
|
|
|
|
->setUser($user)
|
|
|
|
->appendControl(
|
2013-11-26 04:22:06 +01:00
|
|
|
id(new AphrontFormTokenizerControl())
|
2013-01-22 03:46:04 +01:00
|
|
|
->setLabel(pht('Macro'))
|
|
|
|
->setName('macro')
|
2013-11-26 04:22:06 +01:00
|
|
|
->setLimit(1)
|
2014-07-11 01:18:15 +02:00
|
|
|
->setDatasource(new PhabricatorMacroDatasource())
|
2013-01-22 03:46:04 +01:00
|
|
|
->setError($e_macro))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setLabel(pht('Above'))
|
|
|
|
->setName('above')
|
|
|
|
->setValue($above))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setLabel(pht('Below'))
|
|
|
|
->setName('below')
|
|
|
|
->setValue($below));
|
|
|
|
|
|
|
|
$dialog = id(new AphrontDialogView())
|
|
|
|
->setUser($user)
|
|
|
|
->setTitle(pht('Create Meme'))
|
2015-03-31 23:10:55 +02:00
|
|
|
->appendForm($view)
|
2013-01-22 03:46:04 +01:00
|
|
|
->addCancelButton('/')
|
2015-03-31 23:10:55 +02:00
|
|
|
->addSubmitButton(pht('Llama Diorama'));
|
2013-01-22 03:46:04 +01:00
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|