3 final class PhameBlogViewController
extends PhameLiveController
{
5 public function handleRequest(AphrontRequest
$request) {
6 $response = $this->setupLiveEnvironment();
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())
22 ->withBlogPHIDs(array($blog->getPHID()))
23 ->setOrder('datePublished')
24 ->withVisibility(array(
25 PhameConstants
::VISIBILITY_PUBLISHED
,
26 PhameConstants
::VISIBILITY_DRAFT
,
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')
42 if ($blog->isArchived()) {
43 $header_icon = 'fa-ban';
44 $header_name = pht('Archived');
45 $header_color = 'dark';
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);
59 $post_list = id(new PhamePostListView())
62 ->setIsExternal($is_external)
64 ->setNodata(pht('This blog has no visible posts.'));
66 $create_button = id(new PHUIButtonView())
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())
74 ->setTitle($blog->getName())
76 pht('No one has written any blog posts yet.'));
78 $can_edit = PhabricatorPolicyFilter
::hasCapability(
81 PhabricatorPolicyCapability
::CAN_EDIT
);
84 $post_list->addAction($create_button);
88 $page = id(new PHUIDocumentView())
90 ->appendChild($post_list);
93 if (strlen($blog->getDescription())) {
94 $description = new PHUIRemarkupView(
96 $blog->getDescription());
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()))
122 private function renderActions(PhameBlog
$blog) {
123 $viewer = $this->getViewer();
125 $actions = id(new PhabricatorActionListView())
129 $can_edit = PhabricatorPolicyFilter
::hasCapability(
132 PhabricatorPolicyCapability
::CAN_EDIT
);
135 id(new PhabricatorActionView())
137 ->setHref($this->getApplicationURI('post/edit/?blog='.$blog->getID()))
138 ->setName(pht('Write Post'))
139 ->setDisabled(!$can_edit)
140 ->setWorkflow(!$can_edit));
143 id(new PhabricatorActionView())
145 ->setIcon('fa-search')
147 $this->getApplicationURI('post/?blog='.$blog->getPHID()))
148 ->setName(pht('Search Posts')));
151 id(new PhabricatorActionView())
153 ->setIcon('fa-globe')
154 ->setHref($blog->getLiveURI())
155 ->setName(pht('View Live')));
158 id(new PhabricatorActionView())
159 ->setIcon('fa-pencil')
160 ->setHref($this->getApplicationURI('blog/manage/'.$blog->getID().'/'))
161 ->setName(pht('Manage Blog')));
166 private function buildPhameHeader(
170 if ($blog->getHeaderImagePHID()) {
174 'class' => 'phame-header-hero',
179 'src' => $blog->getHeaderImageURI(),
180 'class' => 'phame-header-image',
184 $title = phutil_tag_div('phame-header-title', $blog->getName());
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));