@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Adding macro create method.

authored by

Alex Quach and committed by
epriestley
0f6e5ced 2d87bb29

+74 -3
+2
src/__phutil_library_map__.php
··· 183 183 'ConduitAPI_flag_edit_Method' => 'applications/flag/conduit/ConduitAPI_flag_edit_Method.php', 184 184 'ConduitAPI_flag_query_Method' => 'applications/flag/conduit/ConduitAPI_flag_query_Method.php', 185 185 'ConduitAPI_macro_Method' => 'applications/macro/conduit/ConduitAPI_macro_Method.php', 186 + 'ConduitAPI_macro_creatememe_Method' => 'applications/macro/conduit/ConduitAPI_macro_creatememe_Method.php', 186 187 'ConduitAPI_macro_query_Method' => 'applications/macro/conduit/ConduitAPI_macro_query_Method.php', 187 188 'ConduitAPI_maniphest_Method' => 'applications/maniphest/conduit/ConduitAPI_maniphest_Method.php', 188 189 'ConduitAPI_maniphest_createtask_Method' => 'applications/maniphest/conduit/ConduitAPI_maniphest_createtask_Method.php', ··· 2121 2122 'ConduitAPI_flag_edit_Method' => 'ConduitAPI_flag_Method', 2122 2123 'ConduitAPI_flag_query_Method' => 'ConduitAPI_flag_Method', 2123 2124 'ConduitAPI_macro_Method' => 'ConduitAPIMethod', 2125 + 'ConduitAPI_macro_creatememe_Method' => 'ConduitAPI_macro_Method', 2124 2126 'ConduitAPI_macro_query_Method' => 'ConduitAPI_macro_Method', 2125 2127 'ConduitAPI_maniphest_Method' => 'ConduitAPIMethod', 2126 2128 'ConduitAPI_maniphest_createtask_Method' => 'ConduitAPI_maniphest_Method',
+57
src/applications/macro/conduit/ConduitAPI_macro_creatememe_Method.php
··· 1 + <?php 2 + 3 + /** 4 + * @group conduit 5 + */ 6 + final class ConduitAPI_macro_creatememe_Method 7 + extends ConduitAPI_macro_Method { 8 + 9 + public function getMethodStatus() { 10 + return self::METHOD_STATUS_UNSTABLE; 11 + } 12 + 13 + public function getMethodDescription() { 14 + return pht('Generate a meme.'); 15 + } 16 + 17 + public function defineParamTypes() { 18 + return array( 19 + 'macroName' => 'string', 20 + 'upperText' => 'optional string', 21 + 'lowerText' => 'optional string', 22 + ); 23 + } 24 + 25 + public function defineReturnType() { 26 + return 'string'; 27 + } 28 + 29 + public function defineErrorTypes() { 30 + return array( 31 + 'ERR-NOT-FOUND' => 'Macro was not found.', 32 + ); 33 + } 34 + 35 + protected function execute(ConduitAPIRequest $request) { 36 + $user = $request->getUser(); 37 + 38 + $macro_name = $request->getValue('macroName'); 39 + $upper_text = $request->getValue('upperText'); 40 + $lower_text = $request->getValue('lowerText'); 41 + 42 + $uri = PhabricatorMacroMemeController::generateMacro( 43 + $user, 44 + $macro_name, 45 + $upper_text, 46 + $lower_text); 47 + 48 + if (!$uri) { 49 + throw new ConduitException('ERR-NOT-FOUND'); 50 + } 51 + 52 + return array( 53 + 'uri' => $uri, 54 + ); 55 + } 56 + 57 + }
+15 -3
src/applications/macro/controller/PhabricatorMacroMemeController.php
··· 9 9 $upper_text = $request->getStr('uppertext'); 10 10 $lower_text = $request->getStr('lowertext'); 11 11 $user = $request->getUser(); 12 + 13 + $uri = PhabricatorMacroMemeController::generateMacro($user, $macro_name, 14 + $upper_text, $lower_text); 15 + if ($uri === false) { 16 + return new Aphront404Response(); 17 + } 18 + return id(new AphrontRedirectResponse())->setURI($uri); 19 + } 20 + 21 + public static function generateMacro($user, $macro_name, $upper_text, 22 + $lower_text) { 12 23 $macro = id(new PhabricatorMacroQuery()) 13 24 ->setViewer($user) 14 25 ->withNames(array($macro_name)) 15 26 ->executeOne(); 16 27 if (!$macro) { 17 - return new Aphront404Response(); 28 + return false; 18 29 } 19 30 $file = $macro->getFile(); 20 31 ··· 29 40 if ($xform) { 30 41 $memefile = id(new PhabricatorFile())->loadOneWhere( 31 42 'phid = %s', $xform->getTransformedPHID()); 32 - return id(new AphrontRedirectResponse())->setURI($memefile->getBestURI()); 43 + return $memefile->getBestURI(); 33 44 } 34 45 $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); 35 46 $transformers = (new PhabricatorImageTransformer()); ··· 40 51 $xfile->setTransformedPHID($newfile->getPHID()); 41 52 $xfile->setTransform($hash); 42 53 $xfile->save(); 43 - return id(new AphrontRedirectResponse())->setURI($newfile->getBestURI()); 54 + 55 + return $newfile->getBestURI(); 44 56 } 45 57 }