Browse Source

add extended syntax filter to prevent sphinxql query error #9

main
ghost 2 years ago
parent
commit
f7807cf43e
  1. 9
      library/filter.php
  2. 4
      public/api.php
  3. 4
      public/search.php

9
library/filter.php

@ -55,6 +55,15 @@ class Filter {
return $data; return $data;
} }
static public function sphinxSearchQuery(string $query) {
$query = str_replace(['\\', '/', '~', '@', '!'], ['\\\'', '\/', '\~', '\@', '\!'], $query);
$query = trim($query);
return $query;
}
static public function plural(int $number, array $texts) { static public function plural(int $number, array $texts) {
$cases = array (2, 0, 1, 1, 1, 2); $cases = array (2, 0, 1, 1, 1, 2);

4
public/api.php

@ -34,8 +34,8 @@ if (API_ENABLED) {
$page = !empty($_GET['page']) ? Filter::url($_GET['page']) : 1; $page = !empty($_GET['page']) ? Filter::url($_GET['page']) : 1;
// Make search request // Make search request
$sphinxResultsTotal = $sphinx->searchHostPagesTotal($query); $sphinxResultsTotal = $sphinx->searchHostPagesTotal(Filter::sphinxSearchQuery($query));
$sphinxResults = $sphinx->searchHostPages($query, $page * API_SEARCH_PAGINATION_RESULTS_LIMIT - API_SEARCH_PAGINATION_RESULTS_LIMIT, API_SEARCH_PAGINATION_RESULTS_LIMIT, $sphinxResultsTotal); $sphinxResults = $sphinx->searchHostPages(Filter::sphinxSearchQuery($query), $page * API_SEARCH_PAGINATION_RESULTS_LIMIT - API_SEARCH_PAGINATION_RESULTS_LIMIT, API_SEARCH_PAGINATION_RESULTS_LIMIT, $sphinxResultsTotal);
// Generate results // Generate results
$dbResults = []; $dbResults = [];

4
public/search.php

@ -106,8 +106,8 @@ if (filter_var($q, FILTER_VALIDATE_URL) && preg_match(CRAWL_URL_REGEXP, $q)) {
// Search request // Search request
if (!empty($q)) { if (!empty($q)) {
$resultsTotal = $sphinx->searchHostPagesTotal($q); $resultsTotal = $sphinx->searchHostPagesTotal(Filter::sphinxSearchQuery($q));
$results = $sphinx->searchHostPages($q, $p * WEBSITE_PAGINATION_SEARCH_RESULTS_LIMIT - WEBSITE_PAGINATION_SEARCH_RESULTS_LIMIT, WEBSITE_PAGINATION_SEARCH_RESULTS_LIMIT, $resultsTotal); $results = $sphinx->searchHostPages(Filter::sphinxSearchQuery($q), $p * WEBSITE_PAGINATION_SEARCH_RESULTS_LIMIT - WEBSITE_PAGINATION_SEARCH_RESULTS_LIMIT, WEBSITE_PAGINATION_SEARCH_RESULTS_LIMIT, $resultsTotal);
} else { } else {

Loading…
Cancel
Save