diff --git a/src/classes/Controllers/Api/MatchSearch.php b/src/classes/Controllers/Api/MatchSearch.php new file mode 100644 index 0000000..a45aff3 --- /dev/null +++ b/src/classes/Controllers/Api/MatchSearch.php @@ -0,0 +1,68 @@ + + */ +class MatchSearch +{ + /** + * @var \Atlas\Pdo\Connection + */ + private $atlas; + /** + * @var \Friendica\Directory\Models\Profile + */ + private $profileModel; + /** + * @var \Gettext\TranslatorInterface + */ + private $l10n; + + public function __construct( + \Atlas\Pdo\Connection $atlas, + \Friendica\Directory\Models\Profile $profileModel, + \Gettext\TranslatorInterface $l10n + ) + { + $this->atlas = $atlas; + $this->profileModel = $profileModel; + $this->l10n = $l10n; + } + + public function render(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args): \Slim\Http\Response + { + $perpage = filter_input(INPUT_POST, 'n', FILTER_SANITIZE_NUMBER_INT); + $query = filter_input(INPUT_POST, 's', FILTER_SANITIZE_STRING); + + if (!$perpage) { + $perpage = 80; + } + + $pager = new Pager($this->l10n, $request, $perpage); + $pager->setPage(filter_input(INPUT_POST, 'p', FILTER_SANITIZE_NUMBER_INT)); + + $sql_where = "MATCH (p.`tags`) AGAINST (:query)"; + + $values = ['query' => $query]; + + $profiles = $this->profileModel->getListForDisplay($pager->getItemsPerPage(), $pager->getStart(), $sql_where, $values); + + $count = $this->profileModel->getCountForDisplay($sql_where, $values); + + $vars = [ + 'query' => $query, + 'page' => $pager->getPage(), + 'itemsperpage' => $pager->getItemsPerPage(), + 'count' => $count, + 'profiles' => $profiles + ]; + + return $response->withJson($vars); + } +} diff --git a/src/classes/Routes/Http/MatchSearch.php b/src/classes/Routes/Http/MatchSearch.php new file mode 100644 index 0000000..54f79e2 --- /dev/null +++ b/src/classes/Routes/Http/MatchSearch.php @@ -0,0 +1,18 @@ + + */ +class MatchSearch extends BaseRoute +{ + public function __invoke(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args): \Slim\Http\Response + { + return (new \Friendica\Directory\Controllers\Api\MatchSearch( + $this->container->atlas, + $this->container->get('\Friendica\Directory\Models\Profile'), + $this->container->l10n + ))->render($request, $response, $args); + } +} diff --git a/src/routes.php b/src/routes.php index b1b8113..7718cc7 100644 --- a/src/routes.php +++ b/src/routes.php @@ -21,6 +21,8 @@ $app->get('/search[/{account_type}]', function (Request $request, Response $resp return $route($request, $response, $args); })->setName('search'); +$app->post('/msearch', \Friendica\Directory\Routes\Http\MatchSearch::class); + $app->get('/stats', \Friendica\Directory\Routes\Web\Statistics::class); $app->get('/submit', \Friendica\Directory\Routes\Http\Submit::class);