@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3/**
4 * This is a bare HTML page view which has access to Phabricator page
5 * infrastructure like Celerity, but no content or builtin static resources.
6 * You basically get a valid HMTL5 document and an empty body tag.
7 *
8 * @concrete-extensible
9 */
10class PhabricatorBarePageView extends AphrontPageView {
11
12 private $request;
13 private $controller;
14 private $frameable;
15 private $deviceReady;
16
17 private $bodyContent;
18
19 public function setController(AphrontController $controller) {
20 $this->controller = $controller;
21 return $this;
22 }
23
24 public function getController() {
25 return $this->controller;
26 }
27
28 public function setRequest(AphrontRequest $request) {
29 $this->request = $request;
30 return $this;
31 }
32
33 public function getRequest() {
34 return $this->request;
35 }
36
37 public function setFrameable($frameable) {
38 $this->frameable = $frameable;
39 return $this;
40 }
41
42 public function getFrameable() {
43 return $this->frameable;
44 }
45
46 public function setDeviceReady($device_ready) {
47 $this->deviceReady = $device_ready;
48 return $this;
49 }
50
51 public function getDeviceReady() {
52 return $this->deviceReady;
53 }
54
55 protected function willRenderPage() {
56 // We render this now to resolve static resources so they can appear in the
57 // document head.
58 $this->bodyContent = phutil_implode_html('', $this->renderChildren());
59 }
60
61 protected function getHead() {
62 $viewport_tag = null;
63 if ($this->getDeviceReady()) {
64 $viewport_tag = phutil_tag(
65 'meta',
66 array(
67 'name' => 'viewport',
68 'content' => 'width=device-width, '.
69 'initial-scale=1, '.
70 'user-scalable=yes',
71 ));
72 }
73
74 $referrer_tag = phutil_tag(
75 'meta',
76 array(
77 'name' => 'referrer',
78 'content' => 'no-referrer',
79 ));
80
81
82 $mask_icon = phutil_tag(
83 'link',
84 array(
85 'rel' => 'mask-icon',
86 'color' => '#3D4B67',
87 'href' => celerity_get_resource_uri(
88 '/rsrc/favicons/mask-icon.svg'),
89 ));
90
91 $favicon_links = $this->newFavicons();
92
93 $response = CelerityAPI::getStaticResourceResponse();
94
95 if ($this->getRequest()) {
96 $viewer = $this->getRequest()->getViewer();
97 if ($viewer) {
98 $postprocessor_key = $viewer->getUserSetting(
99 PhabricatorAccessibilitySetting::SETTINGKEY);
100 if (strlen($postprocessor_key)) {
101 $response->setPostProcessorKey($postprocessor_key);
102 }
103 }
104 }
105
106 return hsprintf(
107 '%s%s%s%s%s',
108 $viewport_tag,
109 $mask_icon,
110 $favicon_links,
111 $referrer_tag,
112 $response->renderResourcesOfType('css'));
113 }
114
115 protected function getBody() {
116 return $this->bodyContent;
117 }
118
119 protected function getTail() {
120 $response = CelerityAPI::getStaticResourceResponse();
121 return $response->renderResourcesOfType('js');
122 }
123
124 private function newFavicons() {
125 $favicon_refs = array(
126 array(
127 'rel' => 'apple-touch-icon',
128 'sizes' => '76x76',
129 'width' => 76,
130 'height' => 76,
131 ),
132 array(
133 'rel' => 'apple-touch-icon',
134 'sizes' => '120x120',
135 'width' => 120,
136 'height' => 120,
137 ),
138 array(
139 'rel' => 'apple-touch-icon',
140 'sizes' => '152x152',
141 'width' => 152,
142 'height' => 152,
143 ),
144 array(
145 'rel' => 'icon',
146 'id' => 'favicon',
147 'width' => 64,
148 'height' => 64,
149 ),
150 );
151
152 $fetch_refs = array();
153 foreach ($favicon_refs as $key => $spec) {
154 $ref = id(new PhabricatorFaviconRef())
155 ->setWidth($spec['width'])
156 ->setHeight($spec['height']);
157
158 $favicon_refs[$key]['ref'] = $ref;
159 $fetch_refs[] = $ref;
160 }
161
162 id(new PhabricatorFaviconRefQuery())
163 ->withRefs($fetch_refs)
164 ->execute();
165
166 $favicon_links = array();
167 foreach ($favicon_refs as $spec) {
168 $favicon_links[] = phutil_tag(
169 'link',
170 array(
171 'rel' => $spec['rel'],
172 'sizes' => idx($spec, 'sizes'),
173 'id' => idx($spec, 'id'),
174 'href' => $spec['ref']->getURI(),
175 ));
176 }
177
178 return $favicon_links;
179 }
180
181}