diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 055cc010ed..f6211c3ff2 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -929,6 +929,7 @@ phutil_register_library_map(array( 'PhabricatorMacroEditor' => 'applications/macro/editor/PhabricatorMacroEditor.php', 'PhabricatorMacroListController' => 'applications/macro/controller/PhabricatorMacroListController.php', 'PhabricatorMacroMemeController' => 'applications/macro/controller/PhabricatorMacroMemeController.php', + 'PhabricatorMacroMemeDialogController' => 'applications/macro/controller/PhabricatorMacroMemeDialogController.php', 'PhabricatorMacroReplyHandler' => 'applications/macro/mail/PhabricatorMacroReplyHandler.php', 'PhabricatorMacroTransaction' => 'applications/macro/storage/PhabricatorMacroTransaction.php', 'PhabricatorMacroTransactionComment' => 'applications/macro/storage/PhabricatorMacroTransactionComment.php', @@ -2317,6 +2318,7 @@ phutil_register_library_map(array( 'PhabricatorMacroEditor' => 'PhabricatorApplicationTransactionEditor', 'PhabricatorMacroListController' => 'PhabricatorMacroController', 'PhabricatorMacroMemeController' => 'PhabricatorMacroController', + 'PhabricatorMacroMemeDialogController' => 'PhabricatorMacroController', 'PhabricatorMacroReplyHandler' => 'PhabricatorMailReplyHandler', 'PhabricatorMacroTransaction' => 'PhabricatorApplicationTransaction', 'PhabricatorMacroTransactionComment' => 'PhabricatorApplicationTransactionComment', diff --git a/src/applications/macro/application/PhabricatorApplicationMacro.php b/src/applications/macro/application/PhabricatorApplicationMacro.php index 1edca56440..fea4d3a75d 100644 --- a/src/applications/macro/application/PhabricatorApplicationMacro.php +++ b/src/applications/macro/application/PhabricatorApplicationMacro.php @@ -32,6 +32,7 @@ final class PhabricatorApplicationMacro extends PhabricatorApplication { 'edit/(?P[1-9]\d*)/' => 'PhabricatorMacroEditController', 'disable/(?P[1-9]\d*)/' => 'PhabricatorMacroDisableController', 'meme/' => 'PhabricatorMacroMemeController', + 'meme/create/' => 'PhabricatorMacroMemeDialogController', ), ); } diff --git a/src/applications/macro/controller/PhabricatorMacroMemeDialogController.php b/src/applications/macro/controller/PhabricatorMacroMemeDialogController.php new file mode 100644 index 0000000000..df07660b3d --- /dev/null +++ b/src/applications/macro/controller/PhabricatorMacroMemeDialogController.php @@ -0,0 +1,66 @@ +getRequest(); + $user = $request->getUser(); + + $name = $request->getStr('macro'); + $above = $request->getStr('above'); + $below = $request->getStr('below'); + + $e_macro = true; + $errors = array(); + if ($request->isDialogFormPost()) { + if (!$name) { + $e_macro = pht('Required'); + $errors[] = pht('Macro name is required.'); + } else { + $macro = id(new PhabricatorFileImageMacro())->loadOneWhere( + 'name = %s', + $name); + if (!$macro) { + $e_macro = pht('Invalid'); + $errors[] = pht('No such macro.'); + } + } + + if (!$errors) { + $result = array( + 'text' => "{meme, src={$name}, above={$above}, below={$below}}", + ); + return id(new AphrontAjaxResponse())->setContent($result); + } + } + + $view = id(new AphrontFormLayoutView()) + ->appendChild( + id(new AphrontFormTextControl()) + ->setLabel(pht('Macro')) + ->setName('macro') + ->setValue($name) + ->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); + } + +}