@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
fork

Configure Feed

Select the types of activity you want to include in your feed.

at recaptime-dev/main 205 lines 5.6 kB view raw
1<?php 2 3final class PhameBlogViewController extends PhameLiveController { 4 5 public function handleRequest(AphrontRequest $request) { 6 $response = $this->setupLiveEnvironment(); 7 if ($response) { 8 return $response; 9 } 10 11 $viewer = $this->getViewer(); 12 $blog = $this->getBlog(); 13 14 $is_live = $this->getIsLive(); 15 $is_external = $this->getIsExternal(); 16 17 $pager = id(new AphrontCursorPagerView()) 18 ->readFromRequest($request); 19 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 )); 28 29 if ($is_live) { 30 $post_query->withVisibility(array(PhameConstants::VISIBILITY_PUBLISHED)); 31 } 32 33 $posts = $post_query->executeWithCursorPager($pager); 34 35 $hero = $this->buildPhameHeader($blog); 36 37 $header = id(new PHUIHeaderView()) 38 ->addClass('phame-header-bar') 39 ->setUser($viewer); 40 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'; 50 } 51 $header->setStatus($header_icon, $header_color, $header_name); 52 53 $actions = $this->renderActions($blog); 54 $header->setActionList($actions); 55 $header->setPolicyObject($blog); 56 } 57 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); 71 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.')); 77 78 $can_edit = PhabricatorPolicyFilter::hasCapability( 79 $viewer, 80 $blog, 81 PhabricatorPolicyCapability::CAN_EDIT); 82 83 if ($can_edit) { 84 $post_list->addAction($create_button); 85 } 86 } 87 88 $page = id(new PHUIDocumentView()) 89 ->setHeader($header) 90 ->appendChild($post_list); 91 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.')); 99 } 100 101 $about = id(new PhameDescriptionView()) 102 ->setTitle(pht('About %s', $blog->getName())) 103 ->setDescription($description) 104 ->setImage($blog->getProfileImageURI()); 105 106 $crumbs = $this->buildApplicationCrumbs() 107 ->setBorder(false); 108 109 $page = $this->newPage() 110 ->setTitle($blog->getName()) 111 ->setPageObjectPHIDs(array($blog->getPHID())) 112 ->setCrumbs($crumbs) 113 ->appendChild( 114 array( 115 $hero, 116 $page, 117 $about, 118 )); 119 120 $page->addHeadItem(phutil_tag( 121 'link', 122 array( 123 'rel' => 'alternate', 124 'type' => 'application/atom+xml', 125 'href' => $blog->getFeedURI(), 126 'title' => $blog->getName(), 127 ))); 128 129 return $page; 130 } 131 132 private function renderActions(PhameBlog $blog) { 133 $viewer = $this->getViewer(); 134 135 $actions = id(new PhabricatorActionListView()) 136 ->setObject($blog) 137 ->setUser($viewer); 138 139 $can_edit = PhabricatorPolicyFilter::hasCapability( 140 $viewer, 141 $blog, 142 PhabricatorPolicyCapability::CAN_EDIT); 143 144 $actions->addAction( 145 id(new PhabricatorActionView()) 146 ->setIcon('fa-plus') 147 ->setHref($this->getApplicationURI('post/edit/?blog='.$blog->getID())) 148 ->setName(pht('Write Post')) 149 ->setDisabled(!$can_edit) 150 ->setWorkflow(!$can_edit)); 151 152 $actions->addAction( 153 id(new PhabricatorActionView()) 154 ->setUser($viewer) 155 ->setIcon('fa-search') 156 ->setHref( 157 $this->getApplicationURI('post/?blog='.$blog->getPHID())) 158 ->setName(pht('Search Posts'))); 159 160 $actions->addAction( 161 id(new PhabricatorActionView()) 162 ->setUser($viewer) 163 ->setIcon('fa-globe') 164 ->setHref($blog->getLiveURI()) 165 ->setName(pht('View Live'))); 166 167 $actions->addAction( 168 id(new PhabricatorActionView()) 169 ->setIcon('fa-pencil') 170 ->setHref($this->getApplicationURI('blog/manage/'.$blog->getID().'/')) 171 ->setName(pht('Manage Blog'))); 172 173 return $actions; 174 } 175 176 private function buildPhameHeader( 177 PhameBlog $blog) { 178 179 $image = null; 180 if ($blog->getHeaderImagePHID()) { 181 $image = phutil_tag( 182 'div', 183 array( 184 'class' => 'phame-header-hero', 185 ), 186 phutil_tag( 187 'img', 188 array( 189 'src' => $blog->getHeaderImageURI(), 190 'class' => 'phame-header-image', 191 ))); 192 } 193 194 $title = phutil_tag_div('phame-header-title', $blog->getName()); 195 $subtitle = null; 196 if ($blog->getSubtitle()) { 197 $subtitle = phutil_tag_div('phame-header-subtitle', $blog->getSubtitle()); 198 } 199 200 return phutil_tag_div( 201 'phame-mega-header', array($image, $title, $subtitle)); 202 203 } 204 205}