Browse Source

それじゃ便利だね

諏訪子 1 year ago
parent
commit
52576db947
4 changed files with 18 additions and 9 deletions
  1. 5 0
      include/lib.php
  2. 8 6
      www/artworks/index.php
  3. 2 1
      www/index.php
  4. 3 2
      www/search/index.php

+ 5 - 0
include/lib.php

@@ -0,0 +1,5 @@
+<?php
+  function imgprx (string $url): string {
+    return "/proxy.php?url=".str_replace("https://", "", $url);
+  }
+?>

+ 8 - 6
www/artworks/index.php

@@ -1,5 +1,7 @@
 <?php
   require_once("../../api.php");
+  require_once("../../include/lib.php");
+  if (!isset($_GET["id"])) header("Location: /404.php");
   $id = (int)$_GET["id"];
   $res = get("illust/".$id);
   if (!isset($res->body)) {
@@ -15,20 +17,20 @@
   $icon = "";
   foreach ($res->userIllusts as $k => $v) {
     if (is_null($v)) continue;
-    if (isset($v->profileImageUrl)) $icon = str_replace("https://", "", $v->profileImageUrl);
+    if (isset($v->profileImageUrl)) $icon = imgprx($v->profileImageUrl);
   }
 ?>
 
 <?php include("../../include/header.php"); ?>
     <div style="text-align: center;">
-      <a href="/proxy.php?url=<?= str_replace("https://", "", $res->urls->original) ?>">
-        <img src="/proxy.php?url=<?= str_replace("https://", "", $res->urls->regular) ?>" alt="<?= $res->illustTitle ?>" />
+      <a href="<?= imgprx($res->urls->original) ?>">
+        <img src="<?= imgprx($res->urls->regular) ?>" alt="<?= $res->illustTitle ?>" />
       </a>
     </div>
     <h1><?= $res->illustTitle ?></h1>
     <p>
       好:<?= $res->likeCount ?> 保:<?= $res->bookmarkCount ?> 視:<?= $res->viewCount ?><br /> 
-      <img src="/proxy.php?url=<?= $icon ?>" alt="<?= $res->userName ?>" /> <a href="/users?id=<?= $res->userId ?>"><?= $res->userName ?></a>
+      <img src="<?= $icon ?>" alt="<?= $res->userName ?>" /> <a href="/users?id=<?= $res->userId ?>"><?= $res->userName ?></a>
     </p>
     <h2>コメント (<?= $res->commentCount ?>)</h2>
     <table>
@@ -37,7 +39,7 @@
     foreach ($com->body->comments as $c) {
 ?>
       <tr>
-        <td rowspan="2" style="vertical-align: top;"><img src="/proxy.php?url=<?= str_replace("https://", "", $c->img) ?>" alt="<?= $c->userName ?>" style="width: 40px; height: 40px;" /></td>
+        <td rowspan="2" style="vertical-align: top;"><img src="<?= imgprx($c->img) ?>" alt="<?= $c->userName ?>" style="width: 40px; height: 40px;" /></td>
         <td style="padding-left: 12px;"><a href="/users/?id=<?= $c->userId ?>"><?= $c->userName ?></a> <?= $c->commentDate ?></td>
       </tr>
       <tr>
@@ -68,7 +70,7 @@
     foreach ($rec->body->illusts as $r) {
 ?>
     <a href="/artworks/?id=<?= $r->id ?>">
-      <img src="/proxy.php?url=<?= str_replace("https://", "", $r->url) ?>" alt="<?= $r->alt ?>" />
+      <img src="<?= imgprx($r->url) ?>" alt="<?= $r->alt ?>" />
     </a>
 <?php
     }

+ 2 - 1
www/index.php

@@ -1,5 +1,6 @@
 <?php
   require_once("../api.php");
+  require_once("../include/lib.php");
   $res = (array)get("top/illust");
   $out = ["title" => "トップ", "desc" => ""];
 ?>
@@ -9,7 +10,7 @@
 <?php
   foreach ($res["body"]->thumbnails->illust as $o) {
 ?>
-        <a href="/artworks?id=<?= $o->id ?>"><img src="/proxy.php?url=<?= str_replace("https://", "", $o->url) ?>" alt="<?= $o->alt ?>" /></a>
+        <a href="/artworks?id=<?= $o->id ?>"><img src="<?= imgprx($o->url) ?>" alt="<?= $o->alt ?>" /></a>
 <?php
   }
 ?>

+ 3 - 2
www/search/index.php

@@ -1,5 +1,6 @@
 <?php
   require_once("../../api.php");
+  require_once("../../include/lib.php");
   $q = htmlspecialchars($_GET["q"]);
   if (!isset($q) || $q == "" || is_null($q)) {
     header("Location: /");
@@ -31,12 +32,12 @@
 ?>
       <div class="searchres">
         <a href="/artworks/?id=<?= $r->id ?>">
-          <img src="/proxy.php?url=<?= str_replace("https://", "", $r->url) ?>" alt="<?= $r->alt ?>" />
+          <img src="<?= imgprx($r->url) ?>" alt="<?= $r->alt ?>" />
           <?= $r->title ?>
         </a>
         <br />
         <a href="/users/?id=<?= $r->userId ?>">
-          <img src="/proxy.php?url=<?= str_replace("https://", "", $r->profileImageUrl) ?>" alt="<?= $r->userName ?>" style="width: 24px; height: 24px;" />
+          <img src="<?= imgprx($r->profileImageUrl) ?>" alt="<?= $r->userName ?>" style="width: 24px; height: 24px;" />
           <?= $r->userName ?>
         </a>
       </div>