link.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. ?>