Compare commits
No commits in common. "783e9515706ceb18f390a4c49cec478dd4e4df44" and "d78de57b84f8d9b72c58a47cf2098dd40ed56d1f" have entirely different histories.
783e951570
...
d78de57b84
@ -15,7 +15,10 @@ class AjaxController extends BaseController
|
||||
require_once APPS_PATH . '/Ajax/ajax-actions.php';
|
||||
$context['result'] = "";
|
||||
|
||||
$action = $_POST['action'] ?? false;
|
||||
$json = file_get_contents('php://input');
|
||||
$data = json_decode($json, true);
|
||||
|
||||
$action = $data['action'] ?? false;
|
||||
|
||||
// If request from other site
|
||||
if (!in_array($_SERVER['HTTP_HOST'], ALLOWED_HOSTS)) {
|
||||
@ -31,7 +34,7 @@ class AjaxController extends BaseController
|
||||
$action = "ajax_" . $action;
|
||||
|
||||
try {
|
||||
$context['result'] = $action();
|
||||
$context['result'] = $action($data['args']);
|
||||
} catch (\Exception $ex) {
|
||||
$context['result'] = get_ajax_error($ex->getMessage());
|
||||
}
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
<?php
|
||||
|
||||
use Lycoreco\Apps\Recipes\Models\RecipeModel;
|
||||
|
||||
function get_ajax_error($message, $error_code = 500)
|
||||
{
|
||||
http_response_code($error_code);
|
||||
@ -15,27 +13,35 @@ function get_ajax_error($message, $error_code = 500)
|
||||
/**
|
||||
* Ajax actions
|
||||
*/
|
||||
function ajax_search() {
|
||||
$search_query = $_POST['query'] ?? null;
|
||||
if (!isset($search_query)) {
|
||||
return get_ajax_error("Missing 'query' parameter.", 400);
|
||||
}
|
||||
if (!CURRENT_USER) {
|
||||
return get_ajax_error('You are not authorized', 401);
|
||||
}
|
||||
$result = array();
|
||||
function ajax_search($args) {
|
||||
$search_query = $args['query'];
|
||||
|
||||
$recipes = RecipeModel::filter(
|
||||
array(),
|
||||
array(),
|
||||
5,
|
||||
'AND',
|
||||
0,
|
||||
$search_query
|
||||
);
|
||||
$result = [];
|
||||
$data = [
|
||||
[
|
||||
'id' => 2,
|
||||
'name' => 'Genshin Impact'
|
||||
],
|
||||
[
|
||||
'id' => 3,
|
||||
'name' => 'Zenless zone zero'
|
||||
],
|
||||
[
|
||||
'id' => 4,
|
||||
'name' => 'Honkai Star Rail'
|
||||
],
|
||||
[
|
||||
'id' => 5,
|
||||
'name' => 'Honkai Impact'
|
||||
],
|
||||
];
|
||||
$result['results'] = [];
|
||||
|
||||
$result['count'] = count($recipes);
|
||||
$result['result'] = $recipes;
|
||||
foreach ($data as $key => $value) {
|
||||
if(str_contains($value['name'], $search_query))
|
||||
$result['results'][] = $value;
|
||||
}
|
||||
sleep(3);
|
||||
|
||||
return json_encode($result, JSON_PRETTY_PRINT);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user