Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/macro/controller/PhabricatorMacroViewController.php
12241 views
1
<?php
2
3
final class PhabricatorMacroViewController
4
extends PhabricatorMacroController {
5
6
public function shouldAllowPublic() {
7
return true;
8
}
9
10
public function handleRequest(AphrontRequest $request) {
11
$viewer = $request->getViewer();
12
$id = $request->getURIData('id');
13
14
$macro = id(new PhabricatorMacroQuery())
15
->setViewer($viewer)
16
->withIDs(array($id))
17
->needFiles(true)
18
->executeOne();
19
if (!$macro) {
20
return new Aphront404Response();
21
}
22
23
$title_short = pht('Macro "%s"', $macro->getName());
24
$title_long = pht('Image Macro "%s"', $macro->getName());
25
26
$curtain = $this->buildCurtain($macro);
27
$subheader = $this->buildSubheaderView($macro);
28
$file = $this->buildFileView($macro);
29
$details = $this->buildPropertySectionView($macro);
30
31
$crumbs = $this->buildApplicationCrumbs();
32
$crumbs->addTextCrumb($macro->getName());
33
$crumbs->setBorder(true);
34
35
$timeline = $this->buildTransactionTimeline(
36
$macro,
37
new PhabricatorMacroTransactionQuery());
38
39
$comment_form = $this->buildCommentForm($macro, $timeline);
40
41
$header = id(new PHUIHeaderView())
42
->setUser($viewer)
43
->setPolicyObject($macro)
44
->setHeader($macro->getName())
45
->setHeaderIcon('fa-file-image-o');
46
47
if (!$macro->getIsDisabled()) {
48
$header->setStatus('fa-check', 'bluegrey', pht('Active'));
49
} else {
50
$header->setStatus('fa-ban', 'indigo', pht('Archived'));
51
}
52
53
$view = id(new PHUITwoColumnView())
54
->setHeader($header)
55
->setSubheader($subheader)
56
->setCurtain($curtain)
57
->setMainColumn(array(
58
$timeline,
59
$comment_form,
60
))
61
->addPropertySection(pht('Macro'), $file)
62
->addPropertySection(pht('Details'), $details);
63
64
return $this->newPage()
65
->setTitle($title_short)
66
->setCrumbs($crumbs)
67
->setPageObjectPHIDs(array($macro->getPHID()))
68
->appendChild($view);
69
}
70
71
private function buildCommentForm(
72
PhabricatorFileImageMacro $macro, $timeline) {
73
$viewer = $this->getViewer();
74
75
return id(new PhabricatorMacroEditEngine())
76
->setViewer($viewer)
77
->buildEditEngineCommentView($macro)
78
->setTransactionTimeline($timeline);
79
}
80
81
private function buildCurtain(
82
PhabricatorFileImageMacro $macro) {
83
$can_manage = $this->hasApplicationCapability(
84
PhabricatorMacroManageCapability::CAPABILITY);
85
86
$curtain = $this->newCurtainView($macro);
87
88
$curtain->addAction(
89
id(new PhabricatorActionView())
90
->setName(pht('Edit Macro'))
91
->setHref($this->getApplicationURI('/edit/'.$macro->getID().'/'))
92
->setDisabled(!$can_manage)
93
->setWorkflow(!$can_manage)
94
->setIcon('fa-pencil'));
95
96
$curtain->addAction(
97
id(new PhabricatorActionView())
98
->setName(pht('Edit Audio'))
99
->setHref($this->getApplicationURI('/audio/'.$macro->getID().'/'))
100
->setDisabled(!$can_manage)
101
->setWorkflow(!$can_manage)
102
->setIcon('fa-music'));
103
104
if ($macro->getIsDisabled()) {
105
$curtain->addAction(
106
id(new PhabricatorActionView())
107
->setName(pht('Activate Macro'))
108
->setHref($this->getApplicationURI('/disable/'.$macro->getID().'/'))
109
->setWorkflow(true)
110
->setDisabled(!$can_manage)
111
->setIcon('fa-check'));
112
} else {
113
$curtain->addAction(
114
id(new PhabricatorActionView())
115
->setName(pht('Archive Macro'))
116
->setHref($this->getApplicationURI('/disable/'.$macro->getID().'/'))
117
->setWorkflow(true)
118
->setDisabled(!$can_manage)
119
->setIcon('fa-ban'));
120
}
121
122
return $curtain;
123
}
124
125
private function buildSubheaderView(
126
PhabricatorFileImageMacro $macro) {
127
$viewer = $this->getViewer();
128
129
$author_phid = $macro->getAuthorPHID();
130
131
$author = $viewer->renderHandle($author_phid)->render();
132
$date = phabricator_datetime($macro->getDateCreated(), $viewer);
133
$author = phutil_tag('strong', array(), $author);
134
135
$handles = $viewer->loadHandles(array($author_phid));
136
$image_uri = $handles[$author_phid]->getImageURI();
137
$image_href = $handles[$author_phid]->getURI();
138
139
if (!$date) {
140
$content = pht(
141
'Masterfully imagined by %s in ages long past.', $author);
142
} else {
143
$content = pht('Masterfully imagined by %s on %s.', $author, $date);
144
}
145
146
return id(new PHUIHeadThingView())
147
->setImage($image_uri)
148
->setImageHref($image_href)
149
->setContent($content);
150
}
151
152
private function buildPropertySectionView(
153
PhabricatorFileImageMacro $macro) {
154
$viewer = $this->getViewer();
155
156
$view = id(new PHUIPropertyListView())
157
->setUser($viewer);
158
159
switch ($macro->getAudioBehavior()) {
160
case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_ONCE:
161
$view->addProperty(pht('Audio Behavior'), pht('Play Once'));
162
break;
163
case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_LOOP:
164
$view->addProperty(pht('Audio Behavior'), pht('Loop'));
165
break;
166
}
167
168
$audio_phid = $macro->getAudioPHID();
169
if ($audio_phid) {
170
$view->addProperty(
171
pht('Audio'),
172
$viewer->renderHandle($audio_phid));
173
}
174
175
if ($view->hasAnyProperties()) {
176
return $view;
177
}
178
179
return null;
180
}
181
182
private function buildFileView(
183
PhabricatorFileImageMacro $macro) {
184
$viewer = $this->getViewer();
185
186
$view = id(new PHUIPropertyListView())
187
->setUser($viewer);
188
189
$file = $macro->getFile();
190
if ($file) {
191
$view->addImageContent(
192
phutil_tag(
193
'img',
194
array(
195
'src' => $file->getViewURI(),
196
'class' => 'phabricator-image-macro-hero',
197
)));
198
return $view;
199
}
200
return null;
201
}
202
203
}
204
205