Browse Source

Fix PHP warnings

Sunny 2 years ago
parent
commit
97c321a865
5 changed files with 17 additions and 9 deletions
  1. 7 5
      elements/sidebar.php
  2. 2 2
      pages/artist.php
  3. 5 1
      pages/release.php
  4. 1 1
      pages/search.php
  5. 2 0
      utilities/dom.php

+ 7 - 5
elements/sidebar.php

@@ -5,12 +5,14 @@
     if (isset($image)) echo "<img src=\"" . convert_link($image) . "\">";
     if (!empty($text)) echo "<p>" . nl2br(trim($text)) . "</p>";
 
-    if ($links->length) echo "<p>";
-    foreach ($links as $index => $link) {
-      echo "<a href=\"" . convert_link($link->attr("href")) . "\">" . htmlspecialchars($link->text()) . "</a>";
-      if ($index !== count($links) - 1) echo "<br>";
+    if ($links) {
+      echo "<p>";
+      foreach ($links as $index => $link) {
+        echo "<a href=\"" . convert_link($link->attr("href")) . "\">" . htmlspecialchars($link->text()) . "</a>";
+        if ($index !== count($links) - 1) echo "<br>";
+      };
+      echo "</p>";
     };
-    if ($links->length) echo "</p>";
 
     echo "</div>";
   };

+ 2 - 2
pages/artist.php

@@ -26,7 +26,7 @@
     $title = preg_split("/\n[\n\s]+/", trim($release->find(".title")->text()));
 
     unset($text);
-    if ($title[1]) $text = "by " . htmlspecialchars($title[1]);
+    if (array_key_exists(1, $title)) $text = "by " . htmlspecialchars($title[1]);
 
     $image = $release->find("img");
     $image = $image->hasAttr("data-original") ? $image->attr("data-original") : $image->attr("src");
@@ -36,7 +36,7 @@
     $link = prefix_link($link, "name");
     $link = convert_link($link);
 
-    echo_item($link, $image, htmlspecialchars($title[0]), $text);
+    echo_item($link, $image, htmlspecialchars($title[0]), $text ?? null);
   };
 
   if (!$releases->length)

+ 5 - 1
pages/release.php

@@ -70,7 +70,11 @@
     echo "</div>";
 
     $image = $document->find(".bio-pic a")->attr("href");
-    $text = json_decode($document->find("script[type=\"application/ld+json\"]")->text())->publisher->description;
+    $text = json_decode($document->find("script[type=\"application/ld+json\"]")->text());
+    if (isset($text->publisher->description))
+      $text = $text->publisher->description;
+    else
+      $text = null;
     $links = $document->find("#band-links li a");
 
     echo_sidebar($image, $text, $links);

+ 1 - 1
pages/search.php

@@ -41,7 +41,7 @@
         break;
     };
 
-    echo_item($link, convert_link($result->img), htmlspecialchars($result->name), $text);
+    echo_item($link, convert_link($result->img), htmlspecialchars($result->name), $text ?? null);
   };
 
   if (empty($results))

+ 2 - 0
utilities/dom.php

@@ -1,5 +1,7 @@
 <?php
   function encode_document($text) {
+    libxml_use_internal_errors(true);
+
     $document = new DOMDocument();
     $document->loadHTML("<?xml encoding=\"UTF-8\">" . $text);