Path: blob/master/src/applications/files/controller/PhabricatorFileLightboxController.php
12242 views
<?php12final class PhabricatorFileLightboxController3extends PhabricatorFileController {45public function shouldAllowPublic() {6return true;7}89public function handleRequest(AphrontRequest $request) {10$viewer = $request->getViewer();11$phid = $request->getURIData('phid');12$comment = $request->getStr('comment');1314$file = id(new PhabricatorFileQuery())15->setViewer($viewer)16->withPHIDs(array($phid))17->executeOne();18if (!$file) {19return new Aphront404Response();20}2122if ($comment !== null && strlen($comment)) {23$xactions = array();24$xactions[] = id(new PhabricatorFileTransaction())25->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)26->attachComment(27id(new PhabricatorFileTransactionComment())28->setContent($comment));2930$editor = id(new PhabricatorFileEditor())31->setActor($viewer)32->setContinueOnNoEffect(true)33->setContentSourceFromRequest($request);3435$editor->applyTransactions($file, $xactions);36}3738$transactions = id(new PhabricatorFileTransactionQuery())39->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT));40$timeline = $this->buildTransactionTimeline($file, $transactions);4142$comment_form = $this->renderCommentForm($file);4344$info = phutil_tag(45'div',46array(47'class' => 'phui-comment-panel-header',48),49$file->getName());5051require_celerity_resource('phui-comment-panel-css');52$content = phutil_tag(53'div',54array(55'class' => 'phui-comment-panel',56),57array(58$info,59$timeline,60$comment_form,61));6263return id(new AphrontAjaxResponse())64->setContent($content);65}6667private function renderCommentForm(PhabricatorFile $file) {68$viewer = $this->getViewer();6970if (!$viewer->isLoggedIn()) {71$login_href = id(new PhutilURI('/auth/start/'))72->replaceQueryParam('next', '/'.$file->getMonogram());73return id(new PHUIFormLayoutView())74->addClass('phui-comment-panel-empty')75->appendChild(76id(new PHUIButtonView())77->setTag('a')78->setText(pht('Log In to Comment'))79->setHref((string)$login_href));80}8182$draft = PhabricatorDraft::newFromUserAndKey(83$viewer,84$file->getPHID());85$post_uri = $this->getApplicationURI('thread/'.$file->getPHID().'/');8687$form = id(new AphrontFormView())88->setUser($viewer)89->setAction($post_uri)90->addSigil('lightbox-comment-form')91->addClass('lightbox-comment-form')92->setWorkflow(true)93->appendChild(94id(new PhabricatorRemarkupControl())95->setUser($viewer)96->setName('comment')97->setValue($draft->getDraft()))98->appendChild(99id(new AphrontFormSubmitControl())100->setValue(pht('Comment')));101102$view = phutil_tag_div('phui-comment-panel', $form);103104return $view;105106}107108}109110111