searchHostPagesTotal('"' . $query . '"'); $sphinxResults = $sphinx->searchHostPages('"' . $query . '"', $page * API_SEARCH_PAGINATION_RESULTS_LIMIT - API_SEARCH_PAGINATION_RESULTS_LIMIT, API_SEARCH_PAGINATION_RESULTS_LIMIT, $sphinxResultsTotal); // Generate results $dbResults = []; foreach ($sphinxResults as $i => $sphinxResult) { if ($hostPage = $db->getFoundHostPage($sphinxResult->id)) { $dbResults[$i] = $hostPage; $dbResults[$i]->weight = $sphinxResult->weight; } } // Make response $response = [ 'status' => true, 'totals' => $sphinxResultsTotal, 'result' => $dbResults, ]; break; // Host API case 'hosts'; // 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), ]; break; default: $response = [ 'status' => false, 'message' => _('Undefined API action request.'), ]; } } else { $response = [ 'status' => false, 'message' => _('API requests disabled by the node owner.'), ]; } // Output header('Content-Type: application/json; charset=utf-8'); echo json_encode($response);