1
0
Prechádzať zdrojové kódy

Move item to element

Sunny 2 rokov pred
rodič
commit
092a63f880
3 zmenil súbory, kde vykonal 27 pridanie a 24 odobranie
  1. 20 0
      elements/item.php
  2. 5 14
      pages/artist.php
  3. 2 10
      pages/search.php

+ 20 - 0
elements/item.php

@@ -0,0 +1,20 @@
+<?php
+
+function echo_item ($link, $image, $text, $description) {
+  echo "<a href=\"" . $link . "\">";
+  echo "<img src=\"" . $image . "\">";
+  echo "<span>";
+  echo $text;
+
+  if (isset($description)) {
+    echo "<br>";
+    echo "<small>";
+    echo $description;
+    echo "</small>";
+  };
+
+  echo "</span>";
+  echo "</a>";
+};
+
+?>

+ 5 - 14
pages/artist.php

@@ -7,6 +7,7 @@
 ?>
 
 <?php include "../elements/header.php" ?>
+<?php include "../elements/item.php" ?>
 <?php include "../utilities/link.php" ?>
 
 <?php
@@ -21,6 +22,9 @@
   foreach ($releases as $release) {
     $title = preg_split("/\n[\n\s]+/", trim($release->find(".title")->text()));
 
+    unset($text);
+    if ($title[1]) $text = "by " . htmlspecialchars($title[1]);
+
     $image = $release->find("img");
     $image = $image->hasAttr("data-original") ? $image->attr("data-original") : $image->attr("src");
     $image = convert_link($image);
@@ -29,20 +33,7 @@
     $link = prefix_link($link, "name");
     $link = convert_link($link);
 
-    echo "<a href=\"" . $link . "\">";
-    echo "<img src=\"" . $image . "\">";
-    echo "<span>";
-    echo htmlspecialchars($title[0]);
-
-    if (isset($title[1])) {
-      echo "<br>";
-      echo "<small>";
-      echo "by " . htmlspecialchars($title[1]);
-      echo "</small>";
-    };
-
-    echo "</span>";
-    echo "</a>";
+    echo_item($link, $image, htmlspecialchars($title[0]), $text);
   };
 
   if (!$releases->length)

+ 2 - 10
pages/search.php

@@ -3,6 +3,7 @@
 ?>
 
 <?php include "../elements/header.php" ?>
+<?php include "../elements/item.php" ?>
 <?php include "../utilities/link.php" ?>
 
 <?php
@@ -26,11 +27,6 @@
     $link = $result->item_url_path ?? $result->item_url_root;
     $link = convert_link($link);
 
-    echo "<a href=\"" . $link . "\">";
-    echo "<img src=\"" . convert_link($result->img) . "\">";
-    echo "<span>";
-    echo htmlspecialchars($result->name);
-
     unset($text);
 
     switch ($result->type) {
@@ -45,11 +41,7 @@
         break;
     };
 
-    if (isset($text))
-      echo "<br><small>" . $text . "</small>";
-
-    echo "</span>";
-    echo "</a>";
+    echo_item($link, convert_link($result->img), htmlspecialchars($result->name), $text);
   };
 
   if (empty($results))