1
0
Prechádzať zdrojové kódy

Improve error handling

Sunny 2 rokov pred
rodič
commit
56b6cf9917
2 zmenil súbory, kde vykonal 41 pridanie a 36 odobranie
  1. 39 35
      pages/album.php
  2. 2 1
      pages/artist.php

+ 39 - 35
pages/album.php

@@ -12,57 +12,61 @@
 <?php include "../utilities/link.php" ?>
 
 <?php
-  echo "<h1>";
-  echo htmlspecialchars($json->artist) . ": ";
-  echo htmlspecialchars($json->current->title);
-  echo "</h1>";
+  if ($json) {
+    echo "<h1>";
+    echo htmlspecialchars($json->artist) . ": ";
+    echo htmlspecialchars($json->current->title);
+    echo "</h1>";
 
-  echo "<div class=\"subpage\">";
+    echo "<div class=\"subpage\">";
 
-  $image = "https://f4.bcbits.com/img/" . $json->art_id . "_10.jpg";
-  $text = $json->current->about;
+    $image = "https://f4.bcbits.com/img/" . $json->art_id . "_10.jpg";
+    $text = $json->current->about;
 
-  echo_sidebar($image, $text);
+    echo_sidebar($image, $text);
 
-  echo "<div class=\"tracks\">";
+    echo "<div class=\"tracks\">";
 
-  echo "<table>";
+    echo "<table>";
 
-  foreach ($json->trackinfo as $track) {
-    $link = $track->title_link;
-    $link = prefix_link($link, "artist");
-    $link = convert_link($link);
+    foreach ($json->trackinfo as $track) {
+      $link = $track->title_link;
+      $link = prefix_link($link, "artist");
+      $link = convert_link($link);
 
-    $duration = round($track->duration);
-    $duration = floor($duration / 60) . ":" . sprintf("%02d", $duration % 60);
+      $duration = round($track->duration);
+      $duration = floor($duration / 60) . ":" . sprintf("%02d", $duration % 60);
 
-    echo "<tr>";
-    echo "<td>" . $track->track_num . ".</td>";
-    echo "<td><a href=\"" . $link . "\">" . $track->title . "</a></td>";
-    echo "<td>" . $duration . "</td>";
-    echo "</tr>";
-
-    if ($track->file) {
       echo "<tr>";
-      echo "<td></td>";
-      echo "<td colspan=\"2\">";
-      echo "<audio src=\"" . convert_link($track->file->{"mp3-128"}) . "\" controls preload=\"none\"></audio>";
-      echo "</td>";
+      echo "<td>" . $track->track_num . ".</td>";
+      echo "<td><a href=\"" . $link . "\">" . $track->title . "</a></td>";
+      echo "<td>" . $duration . "</td>";
       echo "</tr>";
+
+      if ($track->file) {
+        echo "<tr>";
+        echo "<td></td>";
+        echo "<td colspan=\"2\">";
+        echo "<audio src=\"" . convert_link($track->file->{"mp3-128"}) . "\" controls preload=\"none\"></audio>";
+        echo "</td>";
+        echo "</tr>";
+      };
     };
-  };
 
-  echo "</table>";
+    echo "</table>";
 
-  echo "</div>";
+    echo "</div>";
 
-  $image = $document->find(".bio-pic a")->attr("href");
-  $text = $document->find("#bio-text")->text();
-  $links = $document->find("#band-links li a");
+    $image = $document->find(".bio-pic a")->attr("href");
+    $text = $document->find("#bio-text")->text();
+    $links = $document->find("#band-links li a");
 
-  echo_sidebar($image, $text, $links);
+    echo_sidebar($image, $text, $links);
 
-  echo "</div>";
+    echo "</div>";
+  } else {
+    echo "<span>No results.</span>";
+  };
 ?>
 
 <?php include "../elements/footer.php" ?>

+ 2 - 1
pages/artist.php

@@ -12,7 +12,8 @@
 <?php include "../utilities/link.php" ?>
 
 <?php
-  echo "<h1>" . htmlspecialchars($document->find("#band-name-location .title")->text()) . "</h1>";
+  if ($document->find("#band-name-location .title")->length)
+    echo "<h1>" . htmlspecialchars($document->find("#band-name-location .title")->text()) . "</h1>";
 
   echo "<div class=\"page\">";