Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / phame / controller / PhameHomeController.php
blobbf263e97a87bdcbcca92650a4f2a974b1a48129f
1 <?php
3 final class PhameHomeController extends PhamePostController {
5 public function shouldAllowPublic() {
6 return true;
9 protected function buildApplicationCrumbs() {
10 $crumbs = parent::buildApplicationCrumbs();
12 id(new PhameBlogEditEngine())
13 ->setViewer($this->getViewer())
14 ->addActionToCrumbs($crumbs);
16 return $crumbs;
19 public function handleRequest(AphrontRequest $request) {
20 $viewer = $request->getViewer();
22 $blogs = id(new PhameBlogQuery())
23 ->setViewer($viewer)
24 ->withStatuses(array(PhameBlog::STATUS_ACTIVE))
25 ->needProfileImage(true)
26 ->execute();
28 $post_list = null;
29 if ($blogs) {
30 $blog_phids = mpull($blogs, 'getPHID');
32 $pager = id(new AphrontCursorPagerView())
33 ->readFromRequest($request);
35 $posts = id(new PhamePostQuery())
36 ->setViewer($viewer)
37 ->withBlogPHIDs($blog_phids)
38 ->withVisibility(array(PhameConstants::VISIBILITY_PUBLISHED))
39 ->setOrder('datePublished')
40 ->executeWithCursorPager($pager);
42 if ($posts) {
43 $post_list = id(new PhamePostListView())
44 ->setPosts($posts)
45 ->setViewer($viewer)
46 ->showBlog(true);
47 } else {
48 $post_list = id(new PHUIBigInfoView())
49 ->setIcon('fa-star')
50 ->setTitle('No Visible Posts')
51 ->setDescription(
52 pht('There aren\'t any visible blog posts.'));
54 } else {
55 $create_button = id(new PHUIButtonView())
56 ->setTag('a')
57 ->setText(pht('Create a Blog'))
58 ->setHref('/phame/blog/edit/')
59 ->setColor(PHUIButtonView::GREEN);
61 $post_list = id(new PHUIBigInfoView())
62 ->setIcon('fa-star')
63 ->setTitle('Welcome to Phame')
64 ->setDescription(
65 pht('There aren\'t any visible blog posts.'))
66 ->addAction($create_button);
69 $view_all = id(new PHUIButtonView())
70 ->setTag('a')
71 ->setText(pht('View All'))
72 ->setHref($this->getApplicationURI('post/'))
73 ->setIcon('fa-list-ul');
75 $title = pht('Recent Posts');
77 $header = id(new PHUIHeaderView())
78 ->setHeader($title)
79 ->addActionLink($view_all);
81 $crumbs = $this->buildApplicationCrumbs();
82 $crumbs->setBorder(true);
83 $crumbs->addTextCrumb(
84 pht('Recent Posts'),
85 $this->getApplicationURI('post/'));
87 $page = id(new PHUIDocumentView())
88 ->setHeader($header)
89 ->appendChild($post_list);
91 $blog_list = id(new PhameBlogListView())
92 ->setBlogs($blogs)
93 ->setViewer($viewer);
95 $draft_list = null;
96 if ($viewer->isLoggedIn() && $blogs) {
97 $drafts = id(new PhamePostQuery())
98 ->setViewer($viewer)
99 ->withBloggerPHIDs(array($viewer->getPHID()))
100 ->withBlogPHIDs(mpull($blogs, 'getPHID'))
101 ->withVisibility(array(PhameConstants::VISIBILITY_DRAFT))
102 ->setLimit(5)
103 ->execute();
105 $draft_list = id(new PhameDraftListView())
106 ->setPosts($drafts)
107 ->setBlogs($blogs)
108 ->setViewer($viewer);
111 $phame_view = id(new PHUITwoColumnView())
112 ->setMainColumn(array(
113 $page,
115 ->setSideColumn(array(
116 $blog_list,
117 $draft_list,
119 ->addClass('phame-home-container');
121 $phame_home = phutil_tag_div('phame-home-view', $phame_view);
123 return $this->newPage()
124 ->setTitle($title)
125 ->setCrumbs($crumbs)
126 ->appendChild(
127 array(
128 $phame_home,