Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/files/controller/PhabricatorFileLightboxController.php
12242 views
1
<?php
2
3
final class PhabricatorFileLightboxController
4
extends PhabricatorFileController {
5
6
public function shouldAllowPublic() {
7
return true;
8
}
9
10
public function handleRequest(AphrontRequest $request) {
11
$viewer = $request->getViewer();
12
$phid = $request->getURIData('phid');
13
$comment = $request->getStr('comment');
14
15
$file = id(new PhabricatorFileQuery())
16
->setViewer($viewer)
17
->withPHIDs(array($phid))
18
->executeOne();
19
if (!$file) {
20
return new Aphront404Response();
21
}
22
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));
30
31
$editor = id(new PhabricatorFileEditor())
32
->setActor($viewer)
33
->setContinueOnNoEffect(true)
34
->setContentSourceFromRequest($request);
35
36
$editor->applyTransactions($file, $xactions);
37
}
38
39
$transactions = id(new PhabricatorFileTransactionQuery())
40
->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT));
41
$timeline = $this->buildTransactionTimeline($file, $transactions);
42
43
$comment_form = $this->renderCommentForm($file);
44
45
$info = phutil_tag(
46
'div',
47
array(
48
'class' => 'phui-comment-panel-header',
49
),
50
$file->getName());
51
52
require_celerity_resource('phui-comment-panel-css');
53
$content = phutil_tag(
54
'div',
55
array(
56
'class' => 'phui-comment-panel',
57
),
58
array(
59
$info,
60
$timeline,
61
$comment_form,
62
));
63
64
return id(new AphrontAjaxResponse())
65
->setContent($content);
66
}
67
68
private function renderCommentForm(PhabricatorFile $file) {
69
$viewer = $this->getViewer();
70
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));
81
}
82
83
$draft = PhabricatorDraft::newFromUserAndKey(
84
$viewer,
85
$file->getPHID());
86
$post_uri = $this->getApplicationURI('thread/'.$file->getPHID().'/');
87
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')));
102
103
$view = phutil_tag_div('phui-comment-panel', $form);
104
105
return $view;
106
107
}
108
109
}
110
111