dom.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. function echo_design_style($document) {
  3. if (!isset($_COOKIE["design"]) || $_COOKIE["design"] !== "on")
  4. return;
  5. $design = $document
  6. ->evaluate("//style[@id=\"custom-design-rules-style\"]")
  7. ->item(0)
  8. ->getAttribute("data-design");
  9. if (!$design)
  10. return;
  11. $design = json_decode($design);
  12. if (
  13. $design->body_color === "FFFFFF" &&
  14. $design->text_color === "363636" &&
  15. $design->link_color === "0687F5"
  16. )
  17. return;
  18. echo "<style>
  19. body {
  20. --background: #" . $design->body_color . " !important;
  21. --color: #" . $design->text_color . " !important;
  22. }
  23. a[href] {
  24. color: #" . $design->link_color . ";
  25. }
  26. </style>";
  27. };
  28. function echo_error_message() {
  29. echo "<h1>No results.</h1>";
  30. echo "<p>
  31. If you're certain that something should be here, Bandcamp may be rate limiting this instance.<br>
  32. In that case, try refreshing this page a few times or using a different instance.
  33. </p>";
  34. };
  35. function encode_document($text) {
  36. libxml_use_internal_errors(true);
  37. $document = new DOMDocument();
  38. $document->loadHTML("<?xml encoding=\"UTF-8\">" . $text);
  39. foreach ($document->childNodes as $node) {
  40. if ($node->nodeType === XML_PI_NODE)
  41. $document->removeChild($node);
  42. };
  43. $document->encoding = "UTF-8";
  44. return $document;
  45. };
  46. ?>