Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / files / controller / PhabricatorFileTransformListController.php
blob7b5bc9299df07c122fd49047c222ff4826feec3d
1 <?php
3 final class PhabricatorFileTransformListController
4 extends PhabricatorFileController {
6 public function shouldAllowPublic() {
7 return true;
10 public function handleRequest(AphrontRequest $request) {
11 $viewer = $this->getViewer();
13 $file = id(new PhabricatorFileQuery())
14 ->setViewer($viewer)
15 ->withIDs(array($request->getURIData('id')))
16 ->executeOne();
17 if (!$file) {
18 return new Aphront404Response();
21 $monogram = $file->getMonogram();
23 $xdst = id(new PhabricatorTransformedFile())->loadAllWhere(
24 'transformedPHID = %s',
25 $file->getPHID());
27 $dst_rows = array();
28 foreach ($xdst as $source) {
29 $dst_rows[] = array(
30 $source->getTransform(),
31 $viewer->renderHandle($source->getOriginalPHID()),
34 $dst_table = id(new AphrontTableView($dst_rows))
35 ->setHeaders(
36 array(
37 pht('Key'),
38 pht('Source'),
40 ->setColumnClasses(
41 array(
42 '',
43 'wide',
45 ->setNoDataString(
46 pht(
47 'This file was not created by transforming another file.'));
49 $xsrc = id(new PhabricatorTransformedFile())->loadAllWhere(
50 'originalPHID = %s',
51 $file->getPHID());
52 $xsrc = mpull($xsrc, 'getTransformedPHID', 'getTransform');
54 $src_rows = array();
55 $xforms = PhabricatorFileTransform::getAllTransforms();
56 foreach ($xforms as $xform) {
57 $dst_phid = idx($xsrc, $xform->getTransformKey());
59 if ($xform->canApplyTransform($file)) {
60 $can_apply = pht('Yes');
62 $view_href = $file->getURIForTransform($xform);
63 $view_href = new PhutilURI($view_href);
64 $view_href->replaceQueryParam('regenerate', 'true');
66 $view_text = pht('Regenerate');
68 $view_link = phutil_tag(
69 'a',
70 array(
71 'class' => 'small button button-grey',
72 'href' => $view_href,
74 $view_text);
75 } else {
76 $can_apply = phutil_tag('em', array(), pht('No'));
77 $view_link = phutil_tag('em', array(), pht('None'));
80 if ($dst_phid) {
81 $dst_link = $viewer->renderHandle($dst_phid);
82 } else {
83 $dst_link = phutil_tag('em', array(), pht('None'));
86 $src_rows[] = array(
87 $xform->getTransformName(),
88 $xform->getTransformKey(),
89 $can_apply,
90 $dst_link,
91 $view_link,
95 $src_table = id(new AphrontTableView($src_rows))
96 ->setHeaders(
97 array(
98 pht('Name'),
99 pht('Key'),
100 pht('Supported'),
101 pht('Transform'),
102 pht('View'),
104 ->setColumnClasses(
105 array(
106 'wide',
110 'action',
113 $crumbs = $this->buildApplicationCrumbs();
114 $crumbs->addTextCrumb($monogram, '/'.$monogram);
115 $crumbs->addTextCrumb(pht('Transforms'));
116 $crumbs->setBorder(true);
118 $dst_box = id(new PHUIObjectBoxView())
119 ->setHeaderText(pht('File Sources'))
120 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
121 ->setTable($dst_table);
123 $src_box = id(new PHUIObjectBoxView())
124 ->setHeaderText(pht('Available Transforms'))
125 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
126 ->setTable($src_table);
128 $title = pht('%s Transforms', $file->getName());
130 $header = id(new PHUIHeaderView())
131 ->setHeader($title)
132 ->setHeaderIcon('fa-arrows-alt');
134 $view = id(new PHUITwoColumnView())
135 ->setHeader($header)
136 ->setFooter(array(
137 $dst_box,
138 $src_box,
141 return $this->newPage()
142 ->setTitle($title)
143 ->setCrumbs($crumbs)
144 ->appendChild($view);