Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / phame / site / PhameBlogSite.php
blobf45aca0266afad7970e88e79232adb6978fc4103
1 <?php
3 final class PhameBlogSite extends PhameSite {
5 private $blog;
7 public function setBlog(PhameBlog $blog) {
8 $this->blog = $blog;
9 return $this;
12 public function getBlog() {
13 return $this->blog;
16 public function getDescription() {
17 return pht('Serves blogs with custom domains.');
20 public function shouldRequireHTTPS() {
21 $full_uri = $this->getBlog()->getDomainFullURI();
22 $full_uri = new PhutilURI($full_uri);
24 return ($full_uri->getProtocol() == 'https');
27 public function getPriority() {
28 return 3000;
31 public function newSiteForRequest(AphrontRequest $request) {
32 if (!$this->isPhameActive()) {
33 return null;
36 $host = $request->getHost();
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,
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.'));
56 if (!$blog) {
57 return null;
60 return id(new PhameBlogSite())->setBlog($blog);
63 public function new404Controller(AphrontRequest $request) {
64 return new PhameBlog404Controller();
67 public function getRoutingMaps() {
68 $app = PhabricatorApplication::getByClass('PhabricatorPhameApplication');
70 $maps = array();
71 $maps[] = $this->newRoutingMap()
72 ->setApplication($app)
73 ->setRoutes($app->getBlogRoutes());
74 return $maps;