public static function generateMacro($viewer, $macro_name, $upper_text, $lower_text) { $macro = id(new PhabricatorMacroQuery())->setViewer($viewer)->withNames(array($macro_name))->needFiles(true)->executeOne(); if (!$macro) { return false; } $file = $macro->getFile(); $upper_text = strtoupper($upper_text); $lower_text = strtoupper($lower_text); $mixed_text = md5($upper_text) . ':' . md5($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 PhabricatorFileQuery())->setViewer($viewer)->withPHIDs(array($xform->getTransformedPHID()))->executeOne(); if ($memefile) { return $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 $newfile->getBestURI(); }
private function destroyTransform(PhabricatorTransformedFile $xform) { $engine = new PhabricatorDestructionEngine(); $file = id(new PhabricatorFileQuery())->setViewer($engine->getViewer())->withPHIDs(array($xform->getTransformedPHID()))->executeOne(); $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); if (!$file) { if ($xform->getID()) { $xform->delete(); } } else { $engine->destroyObject($file); } unset($unguarded); }
private function buildTransformedFileResponse(PhabricatorTransformedFile $xform) { $file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $xform->getTransformedPHID()); if ($file) { $uri = $file->getBestURI(); } else { $bad_phid = $xform->getTransformedPHID(); throw new Exception("Unable to load file with phid {$bad_phid}."); } // TODO: We could just delegate to the file view controller instead, // which would save the client a roundtrip, but is slightly more complex. return id(new AphrontRedirectResponse())->setURI($uri); }
private function buildTransformedFileResponse(PhabricatorTransformedFile $xform) { $file = id(new PhabricatorFileQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withPHIDs(array($xform->getTransformedPHID()))->executeOne(); if (!$file) { return new Aphront404Response(); } // TODO: We could just delegate to the file view controller instead, // which would save the client a roundtrip, but is slightly more complex. return $file->getRedirectResponse(); }
private function buildTransformedFileResponse(PhabricatorTransformedFile $xform) { // TODO: We could just delegate to the file view controller instead, // which would save the client a roundtrip, but is slightly more complex. return id(new AphrontRedirectResponse())->setURI(PhabricatorFileURI::getViewURIForPHID($xform->getTransformedPHID())); }