Browse Source

Improve formatting

Sunny 2 years ago
parent
commit
a71772a5c5
5 changed files with 51 additions and 60 deletions
  1. 2 3
      elements/header.php
  2. 13 15
      elements/item.php
  3. 11 13
      elements/sidebar.php
  4. 2 2
      pages/image.php
  5. 23 27
      utilities/link.php

+ 2 - 3
elements/header.php

@@ -4,11 +4,10 @@
   if (!isset($config["title"]))
     $config["title"] = "Tent";
 
-  if (isset($title) && !empty($title)) {
+  if (isset($title) && !empty($title))
     $title = $config["title"] . " · " . $title;
-  } else {
+  else
     $title = $config["title"];
-  };
 ?>
 
 <!doctype html>

+ 13 - 15
elements/item.php

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

+ 11 - 13
elements/sidebar.php

@@ -1,19 +1,17 @@
 <?php
+  function echo_sidebar ($image, $text, $links = null) {
+    echo "<div class=\"sidebar\">";
 
-function echo_sidebar ($image, $text, $links = null) {
-  echo "<div class=\"sidebar\">";
+    if (isset($image)) echo "<img src=\"" . convert_link($image) . "\">";
+    if (!empty($text)) echo "<p>" . nl2br(trim(preg_replace("/\.\.\...more\s*\n\s*$/", "", $text))) . "</p>";
 
-  if (isset($image)) echo "<img src=\"" . convert_link($image) . "\">";
-  if (!empty($text)) echo "<p>" . nl2br(trim(preg_replace("/\.\.\...more\s*\n\s*$/", "", $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->length) echo "</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>";
+    echo "</div>";
   };
-  if ($links->length) echo "</p>";
-
-  echo "</div>";
-};
-
 ?>

+ 2 - 2
pages/image.php

@@ -11,11 +11,11 @@
       ]
     ]);
     $image = file_get_contents($image, false, $context);
-    
+
     if (explode(" ", $http_response_header[0])[1] === "200") {
       $mime = new finfo(FILEINFO_MIME_TYPE);
       $mime = $mime->buffer($image);
-    
+
       header("Content-Type: " . $mime);
       echo $image;
 

+ 23 - 27
utilities/link.php

@@ -1,35 +1,31 @@
 <?php
+  function convert_link($link) {
+    $scheme = $_SERVER["REQUEST_SCHEME"];
+    $host = $_SERVER["HTTP_HOST"];
+    $uri = $_SERVER["REQUEST_URI"];
 
-function convert_link($link) {
-  $scheme = $_SERVER["REQUEST_SCHEME"];
-  $host = $_SERVER["HTTP_HOST"];
-  $uri = $_SERVER["REQUEST_URI"];
+    $base = $scheme . "://" . $host . preg_replace("/\/.*.php/", "/", strtok($uri, "?"));
 
-  $base = $scheme . "://" . $host . preg_replace("/\/.*.php/", "/", strtok($uri, "?"));
+    $host = parse_url($link, PHP_URL_HOST);
+    $path = ltrim(parse_url($link, PHP_URL_PATH), "/");
+    parse_str(parse_url($link, PHP_URL_QUERY), $query);
 
-  $host = parse_url($link, PHP_URL_HOST);
-  $path = ltrim(parse_url($link, PHP_URL_PATH), "/");
-  parse_str(parse_url($link, PHP_URL_QUERY), $query);
-
-  if ($host === "bandcamp.com" && $path === "search") {
-    return $base . "search.php?query=" . $query["q"];
-  } elseif (str_ends_with($host, ".bandcamp.com") && !$path) {
-    return $base . "artist.php?name=" . explode(".", $host)[0];
-  } elseif (str_ends_with($host, ".bandcamp.com") && explode("/", $path)[0] === "album") {
-    return $base . "album.php?artist=" . explode(".", $host)[0] . "&name=" . explode("/", $path)[1];
-  } elseif ($host === "f4.bcbits.com") {
-    return $base . "image.php?file=" . basename($link);
-  } else {
-    return $link;
+    if ($host === "bandcamp.com" && $path === "search")
+      return $base . "search.php?query=" . $query["q"];
+    elseif (str_ends_with($host, ".bandcamp.com") && !$path)
+      return $base . "artist.php?name=" . explode(".", $host)[0];
+    elseif (str_ends_with($host, ".bandcamp.com") && explode("/", $path)[0] === "album")
+      return $base . "album.php?artist=" . explode(".", $host)[0] . "&name=" . explode("/", $path)[1];
+    elseif ($host === "f4.bcbits.com")
+      return $base . "image.php?file=" . basename($link);
+    else
+      return $link;
   };
-};
 
-function prefix_link($link, $parameter) {
-  if (!filter_var($link, FILTER_VALIDATE_URL)) {
-    return $link = "https://" . urlencode($_GET[$parameter]) . ".bandcamp.com" . $link;
-  } else {
-    return $link;
+  function prefix_link($link, $parameter) {
+    if (!filter_var($link, FILTER_VALIDATE_URL))
+      return $link = "https://" . urlencode($_GET[$parameter]) . ".bandcamp.com" . $link;
+    else
+      return $link;
   };
-};
-
 ?>