|
|
|
@ -9,75 +9,77 @@ require_once('../library/parser.php');
@@ -9,75 +9,77 @@ require_once('../library/parser.php');
|
|
|
|
|
require_once('../library/mysql.php'); |
|
|
|
|
require_once('../library/sphinxql.php'); |
|
|
|
|
|
|
|
|
|
if (!API_ENABLED) { |
|
|
|
|
if (API_ENABLED) { |
|
|
|
|
|
|
|
|
|
$response = [ |
|
|
|
|
'status' => false, |
|
|
|
|
'message' => _('API requests disabled by the node owner.'), |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Action |
|
|
|
|
switch (!empty($_GET['action']) ? $_GET['action'] : false) { |
|
|
|
|
// Action |
|
|
|
|
switch (!empty($_GET['action']) ? $_GET['action'] : false) { |
|
|
|
|
|
|
|
|
|
// Search API |
|
|
|
|
case 'search'; |
|
|
|
|
// Search API |
|
|
|
|
case 'search'; |
|
|
|
|
|
|
|
|
|
// Connect database |
|
|
|
|
$db = new MySQL(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); |
|
|
|
|
// Connect database |
|
|
|
|
$db = new MySQL(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); |
|
|
|
|
|
|
|
|
|
// Connect Sphinx search server |
|
|
|
|
$sphinx = new SphinxQL(SPHINX_HOST, SPHINX_PORT); |
|
|
|
|
// Connect Sphinx search server |
|
|
|
|
$sphinx = new SphinxQL(SPHINX_HOST, SPHINX_PORT); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Filter request data |
|
|
|
|
$query = !empty($_GET['query']) ? Filter::url($_GET['query']) : ''; |
|
|
|
|
$page = !empty($_GET['page']) ? Filter::url($_GET['page']) : 1; |
|
|
|
|
// Filter request data |
|
|
|
|
$query = !empty($_GET['query']) ? Filter::url($_GET['query']) : ''; |
|
|
|
|
$page = !empty($_GET['page']) ? Filter::url($_GET['page']) : 1; |
|
|
|
|
|
|
|
|
|
// Make search request |
|
|
|
|
$sphinxResults = $sphinx->searchHostPages('"' . $query . '"', $page * API_SEARCH_PAGINATION_RESULTS_LIMIT - API_SEARCH_PAGINATION_RESULTS_LIMIT, API_SEARCH_PAGINATION_RESULTS_LIMIT); |
|
|
|
|
$sphinxResultsTotal = $sphinx->searchHostPagesTotal('"' . $query . '"'); |
|
|
|
|
// Make search request |
|
|
|
|
$sphinxResults = $sphinx->searchHostPages('"' . $query . '"', $page * API_SEARCH_PAGINATION_RESULTS_LIMIT - API_SEARCH_PAGINATION_RESULTS_LIMIT, API_SEARCH_PAGINATION_RESULTS_LIMIT); |
|
|
|
|
$sphinxResultsTotal = $sphinx->searchHostPagesTotal('"' . $query . '"'); |
|
|
|
|
|
|
|
|
|
// Generate results |
|
|
|
|
$dbResults = []; |
|
|
|
|
// Generate results |
|
|
|
|
$dbResults = []; |
|
|
|
|
|
|
|
|
|
foreach ($sphinxResults as $sphinxResult) { |
|
|
|
|
foreach ($sphinxResults as $sphinxResult) { |
|
|
|
|
|
|
|
|
|
if ($hostPage = $db->getFoundHostPage($sphinxResult->id)) { |
|
|
|
|
if ($hostPage = $db->getFoundHostPage($sphinxResult->id)) { |
|
|
|
|
|
|
|
|
|
$dbResults[] = $hostPage; |
|
|
|
|
$dbResults[] = $hostPage; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Make response |
|
|
|
|
$response = [ |
|
|
|
|
'status' => true, |
|
|
|
|
'totals' => $sphinxResultsTotal, |
|
|
|
|
'result' => $dbResults, |
|
|
|
|
]; |
|
|
|
|
// Make response |
|
|
|
|
$response = [ |
|
|
|
|
'status' => true, |
|
|
|
|
'totals' => $sphinxResultsTotal, |
|
|
|
|
'result' => $dbResults, |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
// Host API |
|
|
|
|
case 'hosts'; |
|
|
|
|
// Host API |
|
|
|
|
case 'hosts'; |
|
|
|
|
|
|
|
|
|
// Connect database |
|
|
|
|
$db = new MySQL(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); |
|
|
|
|
// Connect database |
|
|
|
|
$db = new MySQL(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); |
|
|
|
|
|
|
|
|
|
$response = [ |
|
|
|
|
'status' => true, |
|
|
|
|
'totals' => $db->getTotalHosts(), |
|
|
|
|
'result' => $db->getAPIHosts(API_HOSTS_FIELDS), |
|
|
|
|
]; |
|
|
|
|
$response = [ |
|
|
|
|
'status' => true, |
|
|
|
|
'totals' => $db->getTotalHosts(), |
|
|
|
|
'result' => $db->getAPIHosts(API_HOSTS_FIELDS), |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
default: |
|
|
|
|
|
|
|
|
|
$response = [ |
|
|
|
|
'status' => false, |
|
|
|
|
'message' => _('Undefined API action request.'), |
|
|
|
|
]; |
|
|
|
|
$response = [ |
|
|
|
|
'status' => false, |
|
|
|
|
'message' => _('Undefined API action request.'), |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
$response = [ |
|
|
|
|
'status' => false, |
|
|
|
|
'message' => _('API requests disabled by the node owner.'), |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Output |
|
|
|
|