@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 147 lines 4.2 kB view raw
1<?php 2 3final class PhamePostSearchEngine 4 extends PhabricatorApplicationSearchEngine { 5 6 public function getResultTypeDescription() { 7 return pht('Phame Posts'); 8 } 9 10 public function getApplicationClassName() { 11 return PhabricatorPhameApplication::class; 12 } 13 14 public function newQuery() { 15 return new PhamePostQuery(); 16 } 17 18 protected function buildQueryFromParameters(array $map) { 19 $query = $this->newQuery(); 20 21 if ($map['visibility']) { 22 $query->withVisibility($map['visibility']); 23 } 24 if ($map['blogPHIDs']) { 25 $query->withBlogPHIDs($map['blogPHIDs']); 26 } 27 28 29 return $query; 30 } 31 32 protected function buildCustomSearchFields() { 33 return array( 34 id(new PhabricatorSearchCheckboxesField()) 35 ->setKey('visibility') 36 ->setLabel(pht('Visibility')) 37 ->setDescription(pht('Search for posts with specific visibility.')) 38 ->setOptions( 39 array( 40 PhameConstants::VISIBILITY_PUBLISHED => pht('Published'), 41 PhameConstants::VISIBILITY_DRAFT => pht('Draft'), 42 PhameConstants::VISIBILITY_ARCHIVED => pht('Archived'), 43 )), 44 id(new PhabricatorSearchDatasourceField()) 45 ->setLabel(pht('Blogs')) 46 ->setKey('blogPHIDs') 47 ->setAliases(array('blog', 'blogs', 'blogPHIDs')) 48 ->setDescription( 49 pht('Search for posts within certain blogs.')) 50 ->setDatasource(new PhameBlogDatasource()), 51 52 ); 53 } 54 55 protected function getURI($path) { 56 return '/phame/post/'.$path; 57 } 58 59 protected function getBuiltinQueryNames() { 60 $names = array( 61 'all' => pht('All Posts'), 62 'live' => pht('Published Posts'), 63 'draft' => pht('Draft Posts'), 64 'archived' => pht('Archived Posts'), 65 ); 66 return $names; 67 } 68 69 public function buildSavedQueryFromBuiltin($query_key) { 70 $query = $this->newSavedQuery(); 71 $query->setQueryKey($query_key); 72 73 switch ($query_key) { 74 case 'all': 75 return $query; 76 case 'live': 77 return $query->setParameter( 78 'visibility', array(PhameConstants::VISIBILITY_PUBLISHED)); 79 case 'draft': 80 return $query->setParameter( 81 'visibility', array(PhameConstants::VISIBILITY_DRAFT)); 82 case 'archived': 83 return $query->setParameter( 84 'visibility', array(PhameConstants::VISIBILITY_ARCHIVED)); 85 } 86 87 return parent::buildSavedQueryFromBuiltin($query_key); 88 } 89 90 /** 91 * @param array<PhamePost> $posts 92 * @param PhabricatorSavedQuery $query 93 * @param array<PhabricatorObjectHandle> $handles 94 */ 95 protected function renderResultList( 96 array $posts, 97 PhabricatorSavedQuery $query, 98 array $handles) { 99 100 assert_instances_of($posts, PhamePost::class); 101 $viewer = $this->requireViewer(); 102 103 $list = new PHUIObjectItemListView(); 104 $list->setUser($viewer); 105 106 foreach ($posts as $post) { 107 $id = $post->getID(); 108 $blog = $post->getBlog(); 109 110 $blog_name = $viewer->renderHandle($post->getBlogPHID())->render(); 111 $blog_name = pht('Blog: %s', $blog_name); 112 113 $item = id(new PHUIObjectItemView()) 114 ->setUser($viewer) 115 ->setObject($post) 116 ->setObjectName($post->getMonogram()) 117 ->setHeader($post->getTitle()) 118 ->setStatusIcon('fa-star') 119 ->setHref($post->getViewURI()) 120 ->addAttribute($blog_name); 121 if ($post->isDraft()) { 122 $item->setStatusIcon('fa-star-o grey'); 123 $item->setDisabled(true); 124 $item->addIcon('fa-star-o', pht('Draft Post')); 125 } else if ($post->isArchived()) { 126 $item->setStatusIcon('fa-ban grey'); 127 $item->setDisabled(true); 128 $item->addIcon('fa-ban', pht('Archived Post')); 129 } else { 130 $date = $post->getDatePublished(); 131 $item->setEpoch($date); 132 } 133 $item->addAction( 134 id(new PHUIListItemView()) 135 ->setIcon('fa-pencil') 136 ->setHref($post->getEditURI())); 137 $list->addItem($item); 138 } 139 140 $result = new PhabricatorApplicationSearchResultView(); 141 $result->setObjectList($list); 142 $result->setNoDataString(pht('No blogs posts found.')); 143 144 return $result; 145 } 146 147}