@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
3final class PhameBlogSite extends PhameSite {
4
5 private $blog;
6
7 public function setBlog(PhameBlog $blog) {
8 $this->blog = $blog;
9 return $this;
10 }
11
12 public function getBlog() {
13 return $this->blog;
14 }
15
16 public function getDescription() {
17 return pht('Serves blogs with custom domains.');
18 }
19
20 public function shouldRequireHTTPS() {
21 $full_uri = $this->getBlog()->getDomainFullURI();
22 $full_uri = new PhutilURI($full_uri);
23
24 return ($full_uri->getProtocol() == 'https');
25 }
26
27 public function getPriority() {
28 return 3000;
29 }
30
31 public function newSiteForRequest(AphrontRequest $request) {
32 if (!$this->isPhameActive()) {
33 return null;
34 }
35
36 $host = $request->getHost();
37
38 try {
39 $blog = id(new PhameBlogQuery())
40 ->setViewer(new PhabricatorUser())
41 ->withDomain($host)
42 ->needProfileImage(true)
43 ->needHeaderImage(true)
44 ->withStatuses(
45 array(
46 PhameBlog::STATUS_ACTIVE,
47 ))
48 ->executeOne();
49 } catch (PhabricatorPolicyException $ex) {
50 throw new Exception(
51 pht(
52 'This blog is not visible to logged out users, so it can not be '.
53 'visited from a custom domain.'));
54 }
55
56 if (!$blog) {
57 return null;
58 }
59
60 return id(new PhameBlogSite())->setBlog($blog);
61 }
62
63 public function new404Controller(AphrontRequest $request) {
64 return new PhameBlog404Controller();
65 }
66
67 public function getRoutingMaps() {
68 $app = PhabricatorApplication::getByClass(
69 PhabricatorPhameApplication::class);
70
71 $maps = array();
72 $maps[] = $this->newRoutingMap()
73 ->setApplication($app)
74 ->setRoutes($app->getBlogRoutes());
75 return $maps;
76 }
77
78}