1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-22 21:40:55 +01:00

Adding macro create method.

This commit is contained in:
Alex Quach 2013-06-07 15:08:34 -07:00 committed by epriestley
parent 2d87bb29ac
commit 0f6e5ced5b
3 changed files with 74 additions and 3 deletions

View file

@ -183,6 +183,7 @@ phutil_register_library_map(array(
'ConduitAPI_flag_edit_Method' => 'applications/flag/conduit/ConduitAPI_flag_edit_Method.php',
'ConduitAPI_flag_query_Method' => 'applications/flag/conduit/ConduitAPI_flag_query_Method.php',
'ConduitAPI_macro_Method' => 'applications/macro/conduit/ConduitAPI_macro_Method.php',
'ConduitAPI_macro_creatememe_Method' => 'applications/macro/conduit/ConduitAPI_macro_creatememe_Method.php',
'ConduitAPI_macro_query_Method' => 'applications/macro/conduit/ConduitAPI_macro_query_Method.php',
'ConduitAPI_maniphest_Method' => 'applications/maniphest/conduit/ConduitAPI_maniphest_Method.php',
'ConduitAPI_maniphest_createtask_Method' => 'applications/maniphest/conduit/ConduitAPI_maniphest_createtask_Method.php',
@ -2121,6 +2122,7 @@ phutil_register_library_map(array(
'ConduitAPI_flag_edit_Method' => 'ConduitAPI_flag_Method',
'ConduitAPI_flag_query_Method' => 'ConduitAPI_flag_Method',
'ConduitAPI_macro_Method' => 'ConduitAPIMethod',
'ConduitAPI_macro_creatememe_Method' => 'ConduitAPI_macro_Method',
'ConduitAPI_macro_query_Method' => 'ConduitAPI_macro_Method',
'ConduitAPI_maniphest_Method' => 'ConduitAPIMethod',
'ConduitAPI_maniphest_createtask_Method' => 'ConduitAPI_maniphest_Method',

View file

@ -0,0 +1,57 @@
<?php
/**
* @group conduit
*/
final class ConduitAPI_macro_creatememe_Method
extends ConduitAPI_macro_Method {
public function getMethodStatus() {
return self::METHOD_STATUS_UNSTABLE;
}
public function getMethodDescription() {
return pht('Generate a meme.');
}
public function defineParamTypes() {
return array(
'macroName' => 'string',
'upperText' => 'optional string',
'lowerText' => 'optional string',
);
}
public function defineReturnType() {
return 'string';
}
public function defineErrorTypes() {
return array(
'ERR-NOT-FOUND' => 'Macro was not found.',
);
}
protected function execute(ConduitAPIRequest $request) {
$user = $request->getUser();
$macro_name = $request->getValue('macroName');
$upper_text = $request->getValue('upperText');
$lower_text = $request->getValue('lowerText');
$uri = PhabricatorMacroMemeController::generateMacro(
$user,
$macro_name,
$upper_text,
$lower_text);
if (!$uri) {
throw new ConduitException('ERR-NOT-FOUND');
}
return array(
'uri' => $uri,
);
}
}

View file

@ -9,12 +9,23 @@ final class PhabricatorMacroMemeController
$upper_text = $request->getStr('uppertext');
$lower_text = $request->getStr('lowertext');
$user = $request->getUser();
$uri = PhabricatorMacroMemeController::generateMacro($user, $macro_name,
$upper_text, $lower_text);
if ($uri === false) {
return new Aphront404Response();
}
return id(new AphrontRedirectResponse())->setURI($uri);
}
public static function generateMacro($user, $macro_name, $upper_text,
$lower_text) {
$macro = id(new PhabricatorMacroQuery())
->setViewer($user)
->withNames(array($macro_name))
->executeOne();
if (!$macro) {
return new Aphront404Response();
return false;
}
$file = $macro->getFile();
@ -29,7 +40,7 @@ final class PhabricatorMacroMemeController
if ($xform) {
$memefile = id(new PhabricatorFile())->loadOneWhere(
'phid = %s', $xform->getTransformedPHID());
return id(new AphrontRedirectResponse())->setURI($memefile->getBestURI());
return $memefile->getBestURI();
}
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
$transformers = (new PhabricatorImageTransformer());
@ -40,6 +51,7 @@ final class PhabricatorMacroMemeController
$xfile->setTransformedPHID($newfile->getPHID());
$xfile->setTransform($hash);
$xfile->save();
return id(new AphrontRedirectResponse())->setURI($newfile->getBestURI());
return $newfile->getBestURI();
}
}