Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Fixed T2353 Test Plan: Checked whether same text generated the same URL Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2353 Differential Revision: https://secure.phabricator.com/D4551
- Loading branch information
Showing
5 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/applications/macro/controller/PhabricatorMacroMemeController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
final class PhabricatorMacroMemeController | ||
extends PhabricatorMacroController { | ||
|
||
public function processRequest() { | ||
$request = $this->getRequest(); | ||
$macro_name = $request->getStr('macro'); | ||
$upper_text = $request->getStr('uppertext'); | ||
$lower_text = $request->getStr('lowertext'); | ||
$user = $request->getUser(); | ||
$macro = id(new PhabricatorFileImageMacro()) | ||
->loadOneWhere('name=%s', $macro_name); | ||
if (!$macro) { | ||
return new Aphront404Response(); | ||
} | ||
$file = id(new PhabricatorFile())->loadOneWhere( | ||
'phid = %s', | ||
$macro->getFilePHID()); | ||
|
||
$upper_text = strtoupper($upper_text); | ||
$lower_text = strtoupper($lower_text); | ||
$mixed_text = $upper_text.":".$lower_text; | ||
$hash = "meme".hash("sha256", $mixed_text); | ||
$xform = id(new PhabricatorTransformedFile()) | ||
->loadOneWhere('originalphid=%s and transform=%s', | ||
$file->getPHID(), $hash); | ||
|
||
if ($xform) { | ||
$memefile = id(new PhabricatorFile())->loadOneWhere( | ||
'phid = %s', $xform->getTransformedPHID()); | ||
return id(new AphrontRedirectResponse())->setURI($memefile->getBestURI()); | ||
} | ||
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); | ||
$transformers = (new PhabricatorImageTransformer()); | ||
$newfile = $transformers | ||
->executeMemeTransform($file, $upper_text, $lower_text); | ||
$xfile = new PhabricatorTransformedFile(); | ||
$xfile->setOriginalPHID($file->getPHID()); | ||
$xfile->setTransformedPHID($newfile->getPHID()); | ||
$xfile->setTransform($hash); | ||
$xfile->save(); | ||
return id(new AphrontRedirectResponse())->setURI($newfile->getBestURI()); | ||
} | ||
} |
fa19618
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💌