Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion includes/handler/class-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) ) {
Expand Down Expand Up @@ -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;
}
}
7 changes: 6 additions & 1 deletion includes/handler/class-timeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down