Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / phame / controller / blog / PhameBlogViewController.php
blobe9e422aeb1b33c7a93531c913e6afda132173e87
1 <?php
3 final class PhameBlogViewController extends PhameLiveController {
5 public function handleRequest(AphrontRequest $request) {
6 $response = $this->setupLiveEnvironment();
7 if ($response) {
8 return $response;
11 $viewer = $this->getViewer();
12 $blog = $this->getBlog();
14 $is_live = $this->getIsLive();
15 $is_external = $this->getIsExternal();
17 $pager = id(new AphrontCursorPagerView())
18 ->readFromRequest($request);
20 $post_query = id(new PhamePostQuery())
21 ->setViewer($viewer)
22 ->withBlogPHIDs(array($blog->getPHID()))
23 ->setOrder('datePublished')
24 ->withVisibility(array(
25 PhameConstants::VISIBILITY_PUBLISHED,
26 PhameConstants::VISIBILITY_DRAFT,
27 ));
29 if ($is_live) {
30 $post_query->withVisibility(array(PhameConstants::VISIBILITY_PUBLISHED));
33 $posts = $post_query->executeWithCursorPager($pager);
35 $hero = $this->buildPhameHeader($blog);
37 $header = id(new PHUIHeaderView())
38 ->addClass('phame-header-bar')
39 ->setUser($viewer);
41 if (!$is_external) {
42 if ($blog->isArchived()) {
43 $header_icon = 'fa-ban';
44 $header_name = pht('Archived');
45 $header_color = 'dark';
46 } else {
47 $header_icon = 'fa-check';
48 $header_name = pht('Active');
49 $header_color = 'bluegrey';
51 $header->setStatus($header_icon, $header_color, $header_name);
53 $actions = $this->renderActions($blog);
54 $header->setActionList($actions);
55 $header->setPolicyObject($blog);
58 if ($posts) {
59 $post_list = id(new PhamePostListView())
60 ->setPosts($posts)
61 ->setViewer($viewer)
62 ->setIsExternal($is_external)
63 ->setIsLive($is_live)
64 ->setNodata(pht('This blog has no visible posts.'));
65 } else {
66 $create_button = id(new PHUIButtonView())
67 ->setTag('a')
68 ->setText(pht('Write a Post'))
69 ->setHref($this->getApplicationURI('post/edit/?blog='.$blog->getID()))
70 ->setColor(PHUIButtonView::GREEN);
72 $post_list = id(new PHUIBigInfoView())
73 ->setIcon('fa-star')
74 ->setTitle($blog->getName())
75 ->setDescription(
76 pht('No one has written any blog posts yet.'));
78 $can_edit = PhabricatorPolicyFilter::hasCapability(
79 $viewer,
80 $blog,
81 PhabricatorPolicyCapability::CAN_EDIT);
83 if ($can_edit) {
84 $post_list->addAction($create_button);
88 $page = id(new PHUIDocumentView())
89 ->setHeader($header)
90 ->appendChild($post_list);
92 $description = null;
93 if (strlen($blog->getDescription())) {
94 $description = new PHUIRemarkupView(
95 $viewer,
96 $blog->getDescription());
97 } else {
98 $description = phutil_tag('em', array(), pht('No description.'));
101 $about = id(new PhameDescriptionView())
102 ->setTitle(pht('About %s', $blog->getName()))
103 ->setDescription($description)
104 ->setImage($blog->getProfileImageURI());
106 $crumbs = $this->buildApplicationCrumbs();
108 $page = $this->newPage()
109 ->setTitle($blog->getName())
110 ->setPageObjectPHIDs(array($blog->getPHID()))
111 ->setCrumbs($crumbs)
112 ->appendChild(
113 array(
114 $hero,
115 $page,
116 $about,
119 return $page;
122 private function renderActions(PhameBlog $blog) {
123 $viewer = $this->getViewer();
125 $actions = id(new PhabricatorActionListView())
126 ->setObject($blog)
127 ->setUser($viewer);
129 $can_edit = PhabricatorPolicyFilter::hasCapability(
130 $viewer,
131 $blog,
132 PhabricatorPolicyCapability::CAN_EDIT);
134 $actions->addAction(
135 id(new PhabricatorActionView())
136 ->setIcon('fa-plus')
137 ->setHref($this->getApplicationURI('post/edit/?blog='.$blog->getID()))
138 ->setName(pht('Write Post'))
139 ->setDisabled(!$can_edit)
140 ->setWorkflow(!$can_edit));
142 $actions->addAction(
143 id(new PhabricatorActionView())
144 ->setUser($viewer)
145 ->setIcon('fa-search')
146 ->setHref(
147 $this->getApplicationURI('post/?blog='.$blog->getPHID()))
148 ->setName(pht('Search Posts')));
150 $actions->addAction(
151 id(new PhabricatorActionView())
152 ->setUser($viewer)
153 ->setIcon('fa-globe')
154 ->setHref($blog->getLiveURI())
155 ->setName(pht('View Live')));
157 $actions->addAction(
158 id(new PhabricatorActionView())
159 ->setIcon('fa-pencil')
160 ->setHref($this->getApplicationURI('blog/manage/'.$blog->getID().'/'))
161 ->setName(pht('Manage Blog')));
163 return $actions;
166 private function buildPhameHeader(
167 PhameBlog $blog) {
169 $image = null;
170 if ($blog->getHeaderImagePHID()) {
171 $image = phutil_tag(
172 'div',
173 array(
174 'class' => 'phame-header-hero',
176 phutil_tag(
177 'img',
178 array(
179 'src' => $blog->getHeaderImageURI(),
180 'class' => 'phame-header-image',
181 )));
184 $title = phutil_tag_div('phame-header-title', $blog->getName());
185 $subtitle = null;
186 if ($blog->getSubtitle()) {
187 $subtitle = phutil_tag_div('phame-header-subtitle', $blog->getSubtitle());
190 return phutil_tag_div(
191 'phame-mega-header', array($image, $title, $subtitle));