[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/macro/controller/ -> PhabricatorMacroMemeController.php (source)

   1  <?php
   2  
   3  final class PhabricatorMacroMemeController
   4    extends PhabricatorMacroController {
   5  
   6    public function shouldAllowPublic() {
   7      return true;
   8    }
   9  
  10    public function processRequest() {
  11      $request = $this->getRequest();
  12      $macro_name = $request->getStr('macro');
  13      $upper_text = $request->getStr('uppertext');
  14      $lower_text = $request->getStr('lowertext');
  15      $user = $request->getUser();
  16  
  17      $uri = PhabricatorMacroMemeController::generateMacro($user, $macro_name,
  18        $upper_text, $lower_text);
  19      if ($uri === false) {
  20        return new Aphront404Response();
  21      }
  22      return id(new AphrontRedirectResponse())
  23        ->setIsExternal(true)
  24        ->setURI($uri);
  25    }
  26  
  27    public static function generateMacro($user, $macro_name, $upper_text,
  28        $lower_text) {
  29      $macro = id(new PhabricatorMacroQuery())
  30        ->setViewer($user)
  31        ->withNames(array($macro_name))
  32        ->needFiles(true)
  33        ->executeOne();
  34      if (!$macro) {
  35        return false;
  36      }
  37      $file = $macro->getFile();
  38  
  39      $upper_text = strtoupper($upper_text);
  40      $lower_text = strtoupper($lower_text);
  41      $mixed_text = md5($upper_text).':'.md5($lower_text);
  42      $hash = 'meme'.hash('sha256', $mixed_text);
  43      $xform = id(new PhabricatorTransformedFile())
  44        ->loadOneWhere('originalphid=%s and transform=%s',
  45          $file->getPHID(), $hash);
  46  
  47      if ($xform) {
  48        $memefile = id(new PhabricatorFileQuery())
  49          ->setViewer($user)
  50          ->withPHIDs(array($xform->getTransformedPHID()))
  51          ->executeOne();
  52        if ($memefile) {
  53          return $memefile->getBestURI();
  54        }
  55      }
  56  
  57      $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
  58      $transformers = (new PhabricatorImageTransformer());
  59      $newfile = $transformers
  60        ->executeMemeTransform($file, $upper_text, $lower_text);
  61      $xfile = new PhabricatorTransformedFile();
  62      $xfile->setOriginalPHID($file->getPHID());
  63      $xfile->setTransformedPHID($newfile->getPHID());
  64      $xfile->setTransform($hash);
  65      $xfile->save();
  66  
  67      return $newfile->getBestURI();
  68    }
  69  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1