search options

main
cynic 4 years ago
parent ff058bf28e
commit edb71eb42e
  1. 9
      instance.php
  2. 29
      routes.php

@ -20,6 +20,15 @@ class ml
}
return(0);
}
function getAllMangaInfo()
{
$response = [];
foreach ($this->db["manga"] as $manga)
{
array_push($response, $manga["info"]);
}
return $response;
}
function run()
{
echo(route($_SERVER["PATH_INFO"], $this));

@ -1,5 +1,16 @@
<?php
include_once("instance.php");
function substrInArr($needle, $haystack)
{
foreach ($haystack as $str)
{
if (strpos($str, $needle))
{
return true;
}
}
return false;
}
function route($path, $ml)
{
header('Content-Type:application/json');
@ -10,9 +21,16 @@ function route($path, $ml)
break;
case "/manga/search":
$response = [];
foreach ($ml->db["manga"] as $manga)
foreach ($ml->getAllMangaInfo() as $manga)
{
if ((isset($_GET["title"]) && substrInArr($_GET["title"], $manga["titles"])) ||
(isset($_GET["author"]) && in_array($_GET["author"], $manga["authors"])) ||
(isset($_GET["artist"]) && in_array($_GET["artist"], $manga["artists"])) ||
(isset($_GET["genre"]) && in_array($_GET["genre"], $manga["genres"])) ||
(isset($_GET["sort"])))
{
array_push($response, $manga["info"]);
array_push($response, $manga);
}
}
return json_encode($response);
break;
@ -39,6 +57,13 @@ function route($path, $ml)
}
http_response_code(400);
break;
case "/manga/people":
return json_encode($ml->db["people"]);
break;
case "/manga/scanlators":
return json_encode($ml->db["scanlators"]);
break;
default:
http_response_code(404);
}

Loading…
Cancel
Save