diff --git a/includes/handler/class-search.php b/includes/handler/class-search.php index 6dfa2e97..d1bb475b 100644 --- a/includes/handler/class-search.php +++ b/includes/handler/class-search.php @@ -45,7 +45,11 @@ public function search( $search, object $request ) { 'hashtags' => array(), ); - $q = $request->get_param( 'q' ); + $q = trim( $request->get_param( 'q' ) ); + // Don't allow empty search queries. + if ( '' === $q ) { + return $ret; + } if ( ! $type || 'accounts' === $type ) { if ( preg_match( '/^@?' . Mastodon_API::ACTIVITYPUB_USERNAME_REGEXP . '$/i', $q ) && ! $request->get_param( 'offset' ) ) { @@ -100,6 +104,37 @@ public function search( $search, object $request ) { $ret['statuses'] = array_merge( $ret['statuses'], $this->get_posts( $args ) ); } } + if ( ! $type || 'hashtags' === $type ) { + $q_param = $request->get_param( 'q' ); + $categories = get_categories( + array( + 'orderby' => 'name', + 'hide_empty' => false, + 'search' => $q_param, + ) + ); + foreach ( $categories as $category ) { + $ret['hashtags'][] = array( + 'name' => $category->name, + 'url' => get_category_link( $category ), + 'history' => array(), + ); + } + $tags = get_tags( + array( + 'orderby' => 'name', + 'hide_empty' => false, + 'search' => $q_param, + ) + ); + foreach ( $tags as $tag ) { + $ret['hashtags'][] = array( + 'name' => $tag->name, + 'url' => get_tag_link( $tag ), + 'history' => array(), + ); + } + } return $ret; } } diff --git a/includes/handler/class-timeline.php b/includes/handler/class-timeline.php index 541520da..c8954cf9 100644 --- a/includes/handler/class-timeline.php +++ b/includes/handler/class-timeline.php @@ -66,10 +66,15 @@ public function api_timelines( $statuses, $request ) { * * @return Entity\Status[]|array An array of Status objects. */ - public function api_tag_timelines( $statuses, $request ) { + public function api_tag_timeline( $statuses, $request ) { $args = $this->get_posts_query_args( $request ); $args['tag'] = $request->get_param( 'hashtag' ); + $ppp_param = $request->get_param( 'limit' ); + if ( null !== $ppp_param ) { + $args['posts_per_page'] = $ppp_param; + } + /** * Filter the query arguments for the timeline. *