1
0

search.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. $title = htmlspecialchars($_GET["query"]);
  3. ?>
  4. <?php require_once "../elements/header.php" ?>
  5. <?php require_once "../elements/item.php" ?>
  6. <?php require_once "../utilities/link.php" ?>
  7. <?php
  8. echo "<h1>Search: “" . htmlspecialchars($_GET["query"]) . "”</h1>";
  9. $ch = curl_init("https://bandcamp.com/api/bcsearch_public_api/1/autocomplete_elastic");
  10. curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]);
  11. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
  12. "search_text" => $_GET["query"],
  13. "search_filter" => "",
  14. "full_page" => true
  15. ]));
  16. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  17. $results = json_decode(curl_exec($ch))->auto->results;
  18. echo "<div class=\"results\">";
  19. foreach ($results as $result) {
  20. $link = $result->item_url_path ?? $result->item_url_root;
  21. $link = convert_link($link);
  22. unset($text);
  23. switch ($result->type) {
  24. case "a":
  25. $text = "by " . htmlspecialchars($result->band_name);
  26. break;
  27. case "t":
  28. $text = "by " . htmlspecialchars($result->band_name);
  29. $text .= "<br>";
  30. $text .= "on " . htmlspecialchars($result->album_name ?? $result->name);
  31. break;
  32. };
  33. echo_item($link, convert_link(resize_link($result->img, 3)), htmlspecialchars($result->name), $text ?? null);
  34. };
  35. if (empty($results))
  36. echo "<span>No results.</span>";
  37. echo "</div>";
  38. ?>
  39. <?php require_once "../elements/footer.php" ?>