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

PhamePostSearchEngine

Summary: A very basic search engine for Phame Posts

Test Plan: Built a dashboard to test various queries. Saw posts.

Reviewers: btrahan, epriestley

Reviewed By: epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T6269

Differential Revision: https://secure.phabricator.com/D13671

+122 -12
+2
src/__phutil_library_map__.php
··· 3034 3034 'PhamePostPreviewController' => 'applications/phame/controller/post/PhamePostPreviewController.php', 3035 3035 'PhamePostPublishController' => 'applications/phame/controller/post/PhamePostPublishController.php', 3036 3036 'PhamePostQuery' => 'applications/phame/query/PhamePostQuery.php', 3037 + 'PhamePostSearchEngine' => 'applications/phame/query/PhamePostSearchEngine.php', 3037 3038 'PhamePostTransaction' => 'applications/phame/storage/PhamePostTransaction.php', 3038 3039 'PhamePostTransactionQuery' => 'applications/phame/query/PhamePostTransactionQuery.php', 3039 3040 'PhamePostUnpublishController' => 'applications/phame/controller/post/PhamePostUnpublishController.php', ··· 7007 7008 'PhamePostPreviewController' => 'PhameController', 7008 7009 'PhamePostPublishController' => 'PhameController', 7009 7010 'PhamePostQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 7011 + 'PhamePostSearchEngine' => 'PhabricatorApplicationSearchEngine', 7010 7012 'PhamePostTransaction' => 'PhabricatorApplicationTransaction', 7011 7013 'PhamePostTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 7012 7014 'PhamePostUnpublishController' => 'PhameController',
+10 -12
src/applications/phame/query/PhamePostQuery.php
··· 81 81 return $posts; 82 82 } 83 83 84 - protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { 85 - $where = array(); 84 + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 85 + $where = parent::buildWhereClauseParts($conn); 86 86 87 87 if ($this->ids) { 88 88 $where[] = qsprintf( 89 - $conn_r, 89 + $conn, 90 90 'p.id IN (%Ld)', 91 91 $this->ids); 92 92 } 93 93 94 94 if ($this->phids) { 95 95 $where[] = qsprintf( 96 - $conn_r, 96 + $conn, 97 97 'p.phid IN (%Ls)', 98 98 $this->phids); 99 99 } 100 100 101 101 if ($this->bloggerPHIDs) { 102 102 $where[] = qsprintf( 103 - $conn_r, 103 + $conn, 104 104 'p.bloggerPHID IN (%Ls)', 105 105 $this->bloggerPHIDs); 106 106 } 107 107 108 108 if ($this->phameTitles) { 109 109 $where[] = qsprintf( 110 - $conn_r, 110 + $conn, 111 111 'p.phameTitle IN (%Ls)', 112 112 $this->phameTitles); 113 113 } 114 114 115 115 if ($this->visibility !== null) { 116 116 $where[] = qsprintf( 117 - $conn_r, 117 + $conn, 118 118 'p.visibility = %d', 119 119 $this->visibility); 120 120 } 121 121 122 122 if ($this->publishedAfter !== null) { 123 123 $where[] = qsprintf( 124 - $conn_r, 124 + $conn, 125 125 'p.datePublished > %d', 126 126 $this->publishedAfter); 127 127 } 128 128 129 129 if ($this->blogPHIDs) { 130 130 $where[] = qsprintf( 131 - $conn_r, 131 + $conn, 132 132 'p.blogPHID in (%Ls)', 133 133 $this->blogPHIDs); 134 134 } 135 135 136 - $where[] = $this->buildPagingClause($conn_r); 137 - 138 - return $this->formatWhereClause($where); 136 + return $where; 139 137 } 140 138 141 139 public function getQueryApplicationClass() {
+110
src/applications/phame/query/PhamePostSearchEngine.php
··· 1 + <?php 2 + 3 + final class PhamePostSearchEngine 4 + extends PhabricatorApplicationSearchEngine { 5 + 6 + public function getResultTypeDescription() { 7 + return pht('Phame Posts'); 8 + } 9 + 10 + public function getApplicationClassName() { 11 + return 'PhabricatorPhameApplication'; 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 (strlen($map['visibility'])) { 22 + $query->withVisibility($map['visibility']); 23 + } 24 + 25 + return $query; 26 + } 27 + 28 + protected function buildCustomSearchFields() { 29 + return array( 30 + id(new PhabricatorSearchSelectField()) 31 + ->setKey('visibility') 32 + ->setOptions(array( 33 + '' => pht('All'), 34 + PhamePost::VISIBILITY_PUBLISHED => pht('Live'), 35 + PhamePost::VISIBILITY_DRAFT => pht('Draft'), 36 + )), 37 + ); 38 + } 39 + 40 + protected function getURI($path) { 41 + return '/phame/post/'.$path; 42 + } 43 + 44 + protected function getBuiltinQueryNames() { 45 + $names = array( 46 + 'all' => pht('All'), 47 + 'live' => pht('Live'), 48 + 'draft' => pht('Draft'), 49 + ); 50 + return $names; 51 + } 52 + 53 + public function buildSavedQueryFromBuiltin($query_key) { 54 + $query = $this->newSavedQuery(); 55 + $query->setQueryKey($query_key); 56 + 57 + switch ($query_key) { 58 + case 'all': 59 + return $query; 60 + case 'live': 61 + return $query->setParameter( 62 + 'visibility', PhamePost::VISIBILITY_PUBLISHED); 63 + case 'draft': 64 + return $query->setParameter( 65 + 'visibility', PhamePost::VISIBILITY_DRAFT); 66 + } 67 + 68 + return parent::buildSavedQueryFromBuiltin($query_key); 69 + } 70 + protected function renderResultList( 71 + array $posts, 72 + PhabricatorSavedQuery $query, 73 + array $handles) { 74 + 75 + assert_instances_of($posts, 'PhamePost'); 76 + $viewer = $this->requireViewer(); 77 + 78 + $list = new PHUIObjectItemListView(); 79 + $list->setUser($viewer); 80 + 81 + foreach ($posts as $post) { 82 + $id = $post->getID(); 83 + $blog = $viewer->renderHandle($post->getBlogPHID())->render(); 84 + $item = id(new PHUIObjectItemView()) 85 + ->setUser($viewer) 86 + ->setObject($post) 87 + ->setHeader($post->getTitle()) 88 + ->setStatusIcon('fa-star') 89 + ->setHref($this->getApplicationURI("/post/view/{$id}/")) 90 + ->addAttribute( 91 + pht('Blog: %s', $blog)); 92 + if ($post->isDraft()) { 93 + $item->setStatusIcon('fa-star-o grey'); 94 + $item->setDisabled(true); 95 + $item->addIcon('none', pht('Draft Post')); 96 + } else { 97 + $date = $post->getDatePublished(); 98 + $item->setEpoch($date); 99 + } 100 + $list->addItem($item); 101 + } 102 + 103 + $result = new PhabricatorApplicationSearchResultView(); 104 + $result->setObjectList($list); 105 + $result->setNoDataString(pht('No blogs found.')); 106 + 107 + return $result; 108 + } 109 + 110 + }