diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 51373419d9..95b5de1304 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -3794,6 +3794,7 @@ phutil_register_library_map(array( 'PhameBlogArchiveController' => 'applications/phame/controller/blog/PhameBlogArchiveController.php', 'PhameBlogController' => 'applications/phame/controller/blog/PhameBlogController.php', 'PhameBlogCreateCapability' => 'applications/phame/capability/PhameBlogCreateCapability.php', + 'PhameBlogDatasource' => 'applications/phame/typeahead/PhameBlogDatasource.php', 'PhameBlogEditConduitAPIMethod' => 'applications/phame/conduit/PhameBlogEditConduitAPIMethod.php', 'PhameBlogEditController' => 'applications/phame/controller/blog/PhameBlogEditController.php', 'PhameBlogEditEngine' => 'applications/phame/editor/PhameBlogEditEngine.php', @@ -8698,6 +8699,7 @@ phutil_register_library_map(array( 'PhameBlogArchiveController' => 'PhameBlogController', 'PhameBlogController' => 'PhameController', 'PhameBlogCreateCapability' => 'PhabricatorPolicyCapability', + 'PhameBlogDatasource' => 'PhabricatorTypeaheadDatasource', 'PhameBlogEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod', 'PhameBlogEditController' => 'PhameBlogController', 'PhameBlogEditEngine' => 'PhabricatorEditEngine', diff --git a/src/applications/phame/controller/blog/PhameBlogViewController.php b/src/applications/phame/controller/blog/PhameBlogViewController.php index 1e751c905b..08b23e5a95 100644 --- a/src/applications/phame/controller/blog/PhameBlogViewController.php +++ b/src/applications/phame/controller/blog/PhameBlogViewController.php @@ -139,6 +139,14 @@ final class PhameBlogViewController extends PhameLiveController { ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit)); + $actions->addAction( + id(new PhabricatorActionView()) + ->setUser($viewer) + ->setIcon('fa-search') + ->setHref( + $this->getApplicationURI('post/?blog='.$blog->getPHID())) + ->setName(pht('Search Posts'))); + $actions->addAction( id(new PhabricatorActionView()) ->setUser($viewer) diff --git a/src/applications/phame/query/PhamePostSearchEngine.php b/src/applications/phame/query/PhamePostSearchEngine.php index dbc248d8b2..8f81c9362e 100644 --- a/src/applications/phame/query/PhamePostSearchEngine.php +++ b/src/applications/phame/query/PhamePostSearchEngine.php @@ -18,25 +18,36 @@ final class PhamePostSearchEngine protected function buildQueryFromParameters(array $map) { $query = $this->newQuery(); - if (strlen($map['visibility'])) { - $query->withVisibility(array($map['visibility'])); + if ($map['visibility']) { + $query->withVisibility($map['visibility']); } + if ($map['blogPHIDs']) { + $query->withBlogPHIDs($map['blogPHIDs']); + } + return $query; } protected function buildCustomSearchFields() { return array( - id(new PhabricatorSearchSelectField()) + id(new PhabricatorSearchCheckboxesField()) ->setKey('visibility') ->setLabel(pht('Visibility')) ->setOptions( array( - '' => pht('All'), PhameConstants::VISIBILITY_PUBLISHED => pht('Published'), PhameConstants::VISIBILITY_DRAFT => pht('Draft'), PhameConstants::VISIBILITY_ARCHIVED => pht('Archived'), )), + id(new PhabricatorSearchDatasourceField()) + ->setLabel(pht('Blogs')) + ->setKey('blogPHIDs') + ->setAliases(array('blog', 'blogs', 'blogPHIDs')) + ->setDescription( + pht('Search for posts within certain blogs.')) + ->setDatasource(new PhameBlogDatasource()), + ); } @@ -63,13 +74,13 @@ final class PhamePostSearchEngine return $query; case 'live': return $query->setParameter( - 'visibility', PhameConstants::VISIBILITY_PUBLISHED); + 'visibility', array(PhameConstants::VISIBILITY_PUBLISHED)); case 'draft': return $query->setParameter( - 'visibility', PhameConstants::VISIBILITY_DRAFT); + 'visibility', array(PhameConstants::VISIBILITY_DRAFT)); case 'archived': return $query->setParameter( - 'visibility', PhameConstants::VISIBILITY_ARCHIVED); + 'visibility', array(PhameConstants::VISIBILITY_ARCHIVED)); } return parent::buildSavedQueryFromBuiltin($query_key); diff --git a/src/applications/phame/typeahead/PhameBlogDatasource.php b/src/applications/phame/typeahead/PhameBlogDatasource.php new file mode 100644 index 0000000000..0658dec3b9 --- /dev/null +++ b/src/applications/phame/typeahead/PhameBlogDatasource.php @@ -0,0 +1,53 @@ +getViewer(); + + $blogs = id(new PhameBlogQuery()) + ->setViewer($viewer) + ->needProfileImage(true) + ->requireCapabilities( + array( + PhabricatorPolicyCapability::CAN_VIEW, + PhabricatorPolicyCapability::CAN_EDIT, + )) + ->execute(); + + $results = array(); + foreach ($blogs as $blog) { + $closed = null; + + $status = $blog->getStatus(); + if ($status === PhabricatorBadgesBadge::STATUS_ARCHIVED) { + $closed = pht('Archived'); + } + + $results[] = id(new PhabricatorTypeaheadResult()) + ->setName($blog->getName()) + ->setClosed($closed) + ->addAttribute(pht('Phame Blog')) + ->setImageURI($blog->getProfileImageURI()) + ->setPHID($blog->getPHID()); + } + + $results = $this->filterResultsAgainstTokens($results); + + return $results; + } + +}