12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php require_once "../utilities/index.php" ?>
- <?php
- $title = htmlspecialchars($_GET["query"]);
- ?>
- <?php require_once "../elements/header.php" ?>
- <?php require_once "../elements/item.php" ?>
- <?php
- if (isset($_GET["query"]))
- echo "<h1>Search: “" . htmlspecialchars($_GET["query"]) . "”</h1>";
- $ch = curl_init("https://bandcamp.com/api/bcsearch_public_api/1/autocomplete_elastic");
- curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]);
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
- "search_text" => $_GET["query"],
- "search_filter" => "",
- "full_page" => true
- ]));
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $results = json_decode(curl_exec($ch))->auto->results;
- if (empty($results))
- echo_error_message();
- echo "<div class=\"results\">";
- foreach ($results as $result) {
- $link = $result->item_url_path ?? $result->item_url_root;
- $link = convert_bandcamp_link($link);
- unset($text);
- switch ($result->type) {
- case "a":
- $text = "by " . htmlspecialchars($result->band_name);
- break;
- case "t":
- $text = "by " . htmlspecialchars($result->band_name);
- $text .= "<br>";
- $text .= "on " . htmlspecialchars($result->album_name ?? $result->name);
- break;
- };
- echo_item($link, convert_bandcamp_link(resize_link($result->img, 3)), htmlspecialchars($result->name), $text ?? null);
- };
- echo "</div>";
- ?>
- <?php require_once "../elements/footer.php" ?>
|