Skip to content
Open
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
45 changes: 43 additions & 2 deletions includes/class-mastodon-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,12 @@ public function api_timelines( $request ) {
public function api_tag_timelines( $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;
}

$args = apply_filters( 'mastodon_api_timelines_args', $args, $request );

return $this->get_posts( $args, $request->get_param( 'min_id' ), $request->get_param( 'max_id' ) );
Expand All @@ -1543,7 +1549,12 @@ public function api_search( $request ) {
'hashtags' => array(),
);

$q = $request->get_param( 'q' );
$q = trim( $request->get_param( 'q' ) );
// Don't allow empty search queries.
if ( '' === $search_query ) {
return $ret;
}

$query_is_url = parse_url( $q );
if ( $query_is_url ) {
if ( 'true' !== $request->get_param( 'resolve' ) || ! is_user_logged_in() ) {
Expand Down Expand Up @@ -1592,7 +1603,6 @@ public function api_search( $request ) {
array(
'id' => $json['id'] . '#create-activity',
'object' => $json,

),
$user_id
);
Expand All @@ -1605,6 +1615,37 @@ public function api_search( $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;
}
Expand Down