discover.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php require_once "../utilities/index.php" ?>
  2. <?php
  3. if (isset($_GET["tags"]))
  4. $title = htmlspecialchars(str_replace([" ", "-"], [", ", " "], $_GET["tags"]));
  5. ?>
  6. <?php require_once "../elements/header.php" ?>
  7. <?php require_once "../elements/item.php" ?>
  8. <?php
  9. echo "<h1>Discover";
  10. if (isset($_GET["tags"]))
  11. echo ": " . htmlspecialchars(str_replace([" ", "-"], [", ", " "], $_GET["tags"]));
  12. echo "</h1>";
  13. $ch = curl_init("https://bandcamp.com/api/discover/1/discover_web");
  14. curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]);
  15. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
  16. "tag_norm_names" => isset($_GET["tags"]) ? explode(" ", $_GET["tags"]) : [],
  17. "include_result_types" => ["a", "s"],
  18. "slice" => "top"
  19. ]));
  20. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  21. $results = json_decode(curl_exec($ch))->results;
  22. if (empty($results))
  23. echo_error_message();
  24. echo "<div class=\"results\">";
  25. foreach ($results as $result) {
  26. $link = convert_bandcamp_link($result->item_url);
  27. $image = convert_bandcamp_link(resize_link("https://f4.bcbits.com/img/" . $result->item_image_id . ".jpg", 3));
  28. $text = htmlspecialchars($result->title);
  29. $description = "by " . htmlspecialchars($result->band_name);
  30. echo_item($link, $image, $text, $description);
  31. };
  32. echo "</div>";
  33. ?>
  34. <?php require_once "../elements/footer.php" ?>