Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / files / controller / PhabricatorFileLightboxController.php
blob078b9b3b12d224a5f8d02d723c987e7314d53d65
1 <?php
3 final class PhabricatorFileLightboxController
4 extends PhabricatorFileController {
6 public function shouldAllowPublic() {
7 return true;
10 public function handleRequest(AphrontRequest $request) {
11 $viewer = $request->getViewer();
12 $phid = $request->getURIData('phid');
13 $comment = $request->getStr('comment');
15 $file = id(new PhabricatorFileQuery())
16 ->setViewer($viewer)
17 ->withPHIDs(array($phid))
18 ->executeOne();
19 if (!$file) {
20 return new Aphront404Response();
23 if ($comment !== null && strlen($comment)) {
24 $xactions = array();
25 $xactions[] = id(new PhabricatorFileTransaction())
26 ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
27 ->attachComment(
28 id(new PhabricatorFileTransactionComment())
29 ->setContent($comment));
31 $editor = id(new PhabricatorFileEditor())
32 ->setActor($viewer)
33 ->setContinueOnNoEffect(true)
34 ->setContentSourceFromRequest($request);
36 $editor->applyTransactions($file, $xactions);
39 $transactions = id(new PhabricatorFileTransactionQuery())
40 ->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT));
41 $timeline = $this->buildTransactionTimeline($file, $transactions);
43 $comment_form = $this->renderCommentForm($file);
45 $info = phutil_tag(
46 'div',
47 array(
48 'class' => 'phui-comment-panel-header',
50 $file->getName());
52 require_celerity_resource('phui-comment-panel-css');
53 $content = phutil_tag(
54 'div',
55 array(
56 'class' => 'phui-comment-panel',
58 array(
59 $info,
60 $timeline,
61 $comment_form,
62 ));
64 return id(new AphrontAjaxResponse())
65 ->setContent($content);
68 private function renderCommentForm(PhabricatorFile $file) {
69 $viewer = $this->getViewer();
71 if (!$viewer->isLoggedIn()) {
72 $login_href = id(new PhutilURI('/auth/start/'))
73 ->replaceQueryParam('next', '/'.$file->getMonogram());
74 return id(new PHUIFormLayoutView())
75 ->addClass('phui-comment-panel-empty')
76 ->appendChild(
77 id(new PHUIButtonView())
78 ->setTag('a')
79 ->setText(pht('Log In to Comment'))
80 ->setHref((string)$login_href));
83 $draft = PhabricatorDraft::newFromUserAndKey(
84 $viewer,
85 $file->getPHID());
86 $post_uri = $this->getApplicationURI('thread/'.$file->getPHID().'/');
88 $form = id(new AphrontFormView())
89 ->setUser($viewer)
90 ->setAction($post_uri)
91 ->addSigil('lightbox-comment-form')
92 ->addClass('lightbox-comment-form')
93 ->setWorkflow(true)
94 ->appendChild(
95 id(new PhabricatorRemarkupControl())
96 ->setUser($viewer)
97 ->setName('comment')
98 ->setValue($draft->getDraft()))
99 ->appendChild(
100 id(new AphrontFormSubmitControl())
101 ->setValue(pht('Comment')));
103 $view = phutil_tag_div('phui-comment-panel', $form);
105 return $view;