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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-26 20:53:11 +02:00
|
|
|
$view = id(new PHUIFormLayoutView())
|
2013-01-22 03:46:04 +01:00
|
|
|
->appendChild(
|
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'))
|
|
|
|
->appendChild($view)
|
|
|
|
->addCancelButton('/')
|
|
|
|
->addSubmitButton(pht('rofllolo!!~'));
|
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|