@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 upstream/main 122 lines 3.3 kB view raw
1<?php 2 3final class PhameBlogSearchEngine 4 extends PhabricatorApplicationSearchEngine { 5 6 public function getResultTypeDescription() { 7 return pht('Phame Blogs'); 8 } 9 10 public function getApplicationClassName() { 11 return PhabricatorPhameApplication::class; 12 } 13 14 public function newQuery() { 15 return id(new PhameBlogQuery()) 16 ->needProfileImage(true); 17 } 18 19 protected function buildQueryFromParameters(array $map) { 20 $query = $this->newQuery(); 21 if ($map['statuses']) { 22 $query->withStatuses(array($map['statuses'])); 23 } 24 return $query; 25 } 26 27 protected function buildCustomSearchFields() { 28 return array( 29 id(new PhabricatorSearchSelectField()) 30 ->setKey('statuses') 31 ->setLabel(pht('Status')) 32 ->setDescription(pht('Search for blogs with given statuses.')) 33 ->setOptions(array( 34 '' => pht('All'), 35 PhameBlog::STATUS_ACTIVE => pht('Active'), 36 PhameBlog::STATUS_ARCHIVED => pht('Archived'), 37 )), 38 ); 39 } 40 41 protected function getURI($path) { 42 return '/phame/blog/'.$path; 43 } 44 45 protected function getBuiltinQueryNames() { 46 $names = array( 47 'active' => pht('Active Blogs'), 48 'archived' => pht('Archived Blogs'), 49 'all' => pht('All Blogs'), 50 ); 51 return $names; 52 } 53 54 public function buildSavedQueryFromBuiltin($query_key) { 55 $query = $this->newSavedQuery(); 56 $query->setQueryKey($query_key); 57 58 switch ($query_key) { 59 case 'all': 60 return $query; 61 case 'active': 62 return $query->setParameter( 63 'statuses', PhameBlog::STATUS_ACTIVE); 64 case 'archived': 65 return $query->setParameter( 66 'statuses', PhameBlog::STATUS_ARCHIVED); 67 } 68 69 return parent::buildSavedQueryFromBuiltin($query_key); 70 } 71 72 /** 73 * @param array<PhameBlog> $blogs 74 * @param PhabricatorSavedQuery $query 75 * @param array<PhabricatorObjectHandle> $handles 76 */ 77 protected function renderResultList( 78 array $blogs, 79 PhabricatorSavedQuery $query, 80 array $handles) { 81 82 assert_instances_of($blogs, PhameBlog::class); 83 $viewer = $this->requireViewer(); 84 85 $list = new PHUIObjectItemListView(); 86 $list->setUser($viewer); 87 88 foreach ($blogs as $blog) { 89 $id = $blog->getID(); 90 if ($blog->getDomain()) { 91 $domain = $blog->getDomain(); 92 } else { 93 $domain = pht('Local Blog'); 94 } 95 $item = id(new PHUIObjectItemView()) 96 ->setUser($viewer) 97 ->setObject($blog) 98 ->setHeader($blog->getName()) 99 ->setImageURI($blog->getProfileImageURI()) 100 ->setDisabled($blog->isArchived()) 101 ->setHref($this->getApplicationURI("/blog/view/{$id}/")) 102 ->addAttribute($domain); 103 if (!$blog->isArchived()) { 104 $button = id(new PHUIButtonView()) 105 ->setTag('a') 106 ->setText('New Post') 107 ->setHref($this->getApplicationURI('/post/edit/?blog='.$id)) 108 ->setButtonType(PHUIButtonView::BUTTONTYPE_SIMPLE); 109 $item->setSideColumn($button); 110 } 111 112 $list->addItem($item); 113 } 114 115 $result = new PhabricatorApplicationSearchResultView(); 116 $result->setObjectList($list); 117 $result->setNoDataString(pht('No blogs found.')); 118 119 return $result; 120 } 121 122}