Browse Source

fix API_ENABLED condition

main
ghost 2 years ago
parent
commit
0df47efa8b
  1. 100
      public/api.php

100
public/api.php

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

Loading…
Cancel
Save