1
0

link.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. function convert_link($link) {
  3. if (isset($_SERVER["REQUEST_SCHEME"]))
  4. $scheme = $_SERVER["REQUEST_SCHEME"];
  5. elseif (isset($_SERVER["HTTPS"]))
  6. $scheme = "https";
  7. else
  8. $scheme = "http";
  9. $host = $_SERVER["HTTP_HOST"];
  10. $uri = $_SERVER["REQUEST_URI"];
  11. $base = $scheme . "://" . $host . preg_replace("/\/.*.php/", "/", strtok($uri, "?"));
  12. unset($scheme);
  13. unset($host);
  14. unset($uri);
  15. $host = parse_url($link, PHP_URL_HOST);
  16. $path = ltrim(parse_url($link, PHP_URL_PATH), "/");
  17. parse_str(parse_url($link, PHP_URL_QUERY), $query);
  18. if ($host === "bandcamp.com" && $path === "search") {
  19. $file = "search";
  20. $data = [
  21. "query" => $query["q"]
  22. ];
  23. } elseif (str_ends_with($host, ".bandcamp.com") && !$path) {
  24. $file = "artist";
  25. $data = [
  26. "name" => explode(".", $host)[0]
  27. ];
  28. } elseif (str_ends_with($host, ".bandcamp.com")) {
  29. $file = "release";
  30. $data = [
  31. "artist" => explode(".", $host)[0],
  32. "type" => explode("/", $path)[0],
  33. "name" => explode("/", $path)[1]
  34. ];
  35. } elseif ($host === "f4.bcbits.com") {
  36. $file = "image";
  37. $data = [
  38. "file" => basename($link)
  39. ];
  40. } elseif ($host === "t4.bcbits.com") {
  41. $file = "audio";
  42. $data = [
  43. "directory" => explode("/", $path)[1],
  44. "format" => explode("/", $path)[2],
  45. "file" => explode("/", $path)[3],
  46. "token" => $query["token"]
  47. ];
  48. } else
  49. return $link;
  50. return $base . $file . ".php?" . http_build_query($data);
  51. };
  52. function prefix_link($link, $parameter) {
  53. if (!filter_var($link, FILTER_VALIDATE_URL))
  54. return $link = "https://" . urlencode($_GET[$parameter]) . ".bandcamp.com" . $link;
  55. else
  56. return $link;
  57. };
  58. function resize_link($link, $size) {
  59. $host = parse_url($link, PHP_URL_HOST);
  60. if ($host !== "f4.bcbits.com") return $link;
  61. $file = pathinfo($link)["filename"];
  62. $ext = pathinfo($link)["extension"];
  63. return "https://" . $host . "/img/" . explode("_", $file)[0] . "_" . $size . "." . $ext;
  64. };
  65. ?>