@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
3abstract class AphrontPageView extends AphrontView {
4
5 private $title;
6
7 public function setTitle($title) {
8 $this->title = $title;
9 return $this;
10 }
11
12 public function getTitle() {
13 $title = $this->title;
14 if (is_array($title)) {
15 $title = implode(" \xC2\xB7 ", $title);
16 }
17 return $title;
18 }
19
20 protected function getHead() {
21 return '';
22 }
23
24 protected function getBody() {
25 return phutil_implode_html('', $this->renderChildren());
26 }
27
28 protected function getTail() {
29 return '';
30 }
31
32 protected function willRenderPage() {
33 return;
34 }
35
36 protected function willSendResponse($response) {
37 return $response;
38 }
39
40 protected function getBodyClasses() {
41 return null;
42 }
43
44 public function render() {
45
46 $this->willRenderPage();
47
48 $title = $this->getTitle();
49 $head = $this->getHead();
50 $body = $this->getBody();
51 $tail = $this->getTail();
52
53 $body_classes = $this->getBodyClasses();
54
55 $body = phutil_tag(
56 'body',
57 array(
58 'class' => nonempty($body_classes, null),
59 ),
60 array($body, $tail));
61
62 if (PhabricatorEnv::getEnvConfig('phabricator.developer-mode')) {
63 $data_fragment = phutil_safe_html(' data-developer-mode="1"');
64 } else {
65 $data_fragment = null;
66 }
67
68 if ($this->hasViewer() && $this->getViewer()->isLoggedIn()) {
69 $html_lang = phutil_safe_html(' lang="'.
70 str_replace('_', '-', $this->getViewer()->getTranslation().'"'));
71 } else {
72 $html_lang = phutil_safe_html(' lang="en"');
73 }
74
75 $response = hsprintf(
76 '<!DOCTYPE html>'.
77 '<html%s%s>'.
78 '<head>'.
79 '<meta charset="UTF-8" />'.
80 '<title>%s</title>'.
81 '%s'.
82 '</head>'.
83 '%s'.
84 '</html>',
85 $data_fragment,
86 $html_lang,
87 $title,
88 $head,
89 $body);
90
91 $response = $this->willSendResponse($response);
92
93 return $response;
94
95 }
96
97}