From dfea7f2f244864ffc8fc82975a8cf99ab4d63993 Mon Sep 17 00:00:00 2001 From: eai04191 Date: Mon, 14 Jan 2019 11:29:16 +0900 Subject: [PATCH 01/14] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E3=82=A4?= =?UTF-8?q?=E3=83=B3=E3=83=9D=E3=83=BC=E3=83=88=E3=81=AE=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MetadataResolver/DLsiteResolver.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/MetadataResolver/DLsiteResolver.php b/app/MetadataResolver/DLsiteResolver.php index 866bde0..a2ead81 100644 --- a/app/MetadataResolver/DLsiteResolver.php +++ b/app/MetadataResolver/DLsiteResolver.php @@ -2,8 +2,6 @@ namespace App\MetadataResolver; -use Illuminate\Support\Facades\Log; - class DLsiteResolver implements Resolver { public function resolve(string $url): Metadata From 9eb42f19919c73eace6ecac084e3cbec098bb141 Mon Sep 17 00:00:00 2001 From: Eai Date: Mon, 14 Jan 2019 14:19:43 +0900 Subject: [PATCH 02/14] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E3=82=A4?= =?UTF-8?q?=E3=83=B3=E3=83=9D=E3=83=BC=E3=83=88=E3=81=AE=E5=89=8A=E9=99=A4?= =?UTF-8?q?=20(#23)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MetadataResolver/DLsiteResolver.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/MetadataResolver/DLsiteResolver.php b/app/MetadataResolver/DLsiteResolver.php index 866bde0..a2ead81 100644 --- a/app/MetadataResolver/DLsiteResolver.php +++ b/app/MetadataResolver/DLsiteResolver.php @@ -2,8 +2,6 @@ namespace App\MetadataResolver; -use Illuminate\Support\Facades\Log; - class DLsiteResolver implements Resolver { public function resolve(string $url): Metadata From 6105f6c8600222e9894045b7c3dbf4f180f6c93b Mon Sep 17 00:00:00 2001 From: eai04191 Date: Mon, 14 Jan 2019 16:01:58 +0900 Subject: [PATCH 03/14] =?UTF-8?q?PixivResolver=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MetadataResolver/MetadataResolver.php | 1 + app/MetadataResolver/PixivResolver.php | 88 +++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 app/MetadataResolver/PixivResolver.php diff --git a/app/MetadataResolver/MetadataResolver.php b/app/MetadataResolver/MetadataResolver.php index 8180589..528c73c 100644 --- a/app/MetadataResolver/MetadataResolver.php +++ b/app/MetadataResolver/MetadataResolver.php @@ -12,6 +12,7 @@ class MetadataResolver implements Resolver '~ec\.toranoana\.jp/tora_r/ec/item/.*~' => ToranoanaResolver::class, '~iwara\.tv/videos/.*~' => IwaraResolver::class, '~www\.dlsite\.com/.*/work/=/product_id/..\d+\.html~' => DLsiteResolver::class, + '~www\.pixiv\.net/member_illust\.php\?illust_id=\d+~' => PixivResolver::class, '/.*/' => OGPResolver::class ]; diff --git a/app/MetadataResolver/PixivResolver.php b/app/MetadataResolver/PixivResolver.php new file mode 100644 index 0000000..30db7d5 --- /dev/null +++ b/app/MetadataResolver/PixivResolver.php @@ -0,0 +1,88 @@ +get($url); + if ($res->getStatusCode() === 200) { + $ogpResolver = new OGPResolver(); + $metadata = $ogpResolver->parse($res->getBody()); + + preg_match("~https://i\.pximg\.net/c/128x128/img-master/img/\d{4}/\d{2}/\d{2}/\d{2}/\d{2}/\d{2}/{$illust_id}_p0_square1200\.jpg~", $res->getBody(), $match); + $illust_thumbnail_url = $match[0]; + Log::debug($illust_thumbnail_url); + + $illust_url = $this->thumbnail_to_master_url($illust_thumbnail_url); + Log::debug($illust_url); + + // 指定ページに変換 + $illust_url = str_replace("p0_master", "p{$page}_master", $illust_url); + Log::debug($illust_url); + + $metadata->image = $this->proxize($illust_url);; + + return $metadata; + } else { + throw new \RuntimeException("{$res->getStatusCode()}: $url"); + } + }else { + $client = new \GuzzleHttp\Client(); + $res = $client->get($url); + if ($res->getStatusCode() === 200) { + $ogpResolver = new OGPResolver(); + $metadata = $ogpResolver->parse($res->getBody()); + + // OGP がデフォルト画像であるようならなんとかして画像を取得する + if (strpos($metadata->image, "pixiv_logo.gif") || strpos($metadata->image, "pictures.jpg")) { + + // 作品ページの場合のみ対応 + if(strpos(parse_url($url)["query"], "mode=medium")){ + preg_match("~https://i\.pximg\.net/c/128x128/img-master/img/\d{4}/\d{2}/\d{2}/\d{2}/\d{2}/\d{2}/{$illust_id}(_p0)?_square1200\.jpg~", $res->getBody(), $match); + $illust_thumbnail_url = $match[0]; + + $illust_url = $this->thumbnail_to_master_url($illust_thumbnail_url); + + $metadata->image = $this->proxize($illust_url);; + } + } + + return $metadata; + } else { + throw new \RuntimeException("{$res->getStatusCode()}: $url"); + } + + } + } +} From a645cb497f8bf3b5303f50e271fe00be82440734 Mon Sep 17 00:00:00 2001 From: eai04191 Date: Mon, 14 Jan 2019 16:03:46 +0900 Subject: [PATCH 04/14] =?UTF-8?q?=E8=AC=9D=E8=BE=9E=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MetadataResolver/PixivResolver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/MetadataResolver/PixivResolver.php b/app/MetadataResolver/PixivResolver.php index 30db7d5..6c82d59 100644 --- a/app/MetadataResolver/PixivResolver.php +++ b/app/MetadataResolver/PixivResolver.php @@ -14,7 +14,7 @@ class PixivResolver implements Resolver } public function proxize(string $url):string { - // pixiv.cat のプロキシ URL に変換する + // pixiv.cat のプロキシ URL に変換する HUGE THANKS TO PIXIV.CAT! $url = str_replace("i.pximg.net", "i.pixiv.cat", $url); return $url; } From b0a7504691b4068454c7c6e165a901bf7fe5a1e7 Mon Sep 17 00:00:00 2001 From: eai04191 Date: Mon, 14 Jan 2019 16:11:14 +0900 Subject: [PATCH 05/14] =?UTF-8?q?Logging=E3=81=AE=E5=89=8A=E9=99=A4?= =?UTF-8?q?=E3=83=BB=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89=E3=81=AE=E8=AA=AC?= =?UTF-8?q?=E6=98=8E=E3=82=92=E3=81=BE=E3=81=A8=E3=82=82=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MetadataResolver/PixivResolver.php | 40 +++++++++++++++----------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/app/MetadataResolver/PixivResolver.php b/app/MetadataResolver/PixivResolver.php index 6c82d59..99c54b6 100644 --- a/app/MetadataResolver/PixivResolver.php +++ b/app/MetadataResolver/PixivResolver.php @@ -2,19 +2,31 @@ namespace App\MetadataResolver; -use Illuminate\Support\Facades\Log; - class PixivResolver implements Resolver { - public function thumbnail_to_master_url(string $url):string { - // 最大長辺 1200 の画像に変換 + + /** + * サムネイル画像 URL から最大長辺 1200px の画像 URL に変換する + * + * @param string サムネイル画像 URL + * @return string 1200px の画像 URL + */ + public function thumbnail_to_master_url(string $url):string + { $url = str_replace("/c/128x128", "", $url); $url = str_replace("square1200.jpg", "master1200.jpg", $url); return $url; } - public function proxize(string $url):string { - // pixiv.cat のプロキシ URL に変換する HUGE THANKS TO PIXIV.CAT! + /** + * 直リン可能な pixiv.cat のプロキシ URL に変換する + * HUGE THANKS TO PIXIV.CAT! + * + * @param string i.pximg URL + * @return string i.pixiv.cat URL + */ + public function proxize(string $url):string + { $url = str_replace("i.pximg.net", "i.pixiv.cat", $url); return $url; } @@ -30,9 +42,7 @@ class PixivResolver implements Resolver $page = $match[1]; // 未ログインでは漫画ページを開けないため、URL を作品ページに変換する - Log::debug($url); $url = str_replace("mode=manga_big", "mode=medium", $url); - Log::debug($url); $client = new \GuzzleHttp\Client(); $res = $client->get($url); @@ -42,22 +52,20 @@ class PixivResolver implements Resolver preg_match("~https://i\.pximg\.net/c/128x128/img-master/img/\d{4}/\d{2}/\d{2}/\d{2}/\d{2}/\d{2}/{$illust_id}_p0_square1200\.jpg~", $res->getBody(), $match); $illust_thumbnail_url = $match[0]; - Log::debug($illust_thumbnail_url); $illust_url = $this->thumbnail_to_master_url($illust_thumbnail_url); - Log::debug($illust_url); // 指定ページに変換 $illust_url = str_replace("p0_master", "p{$page}_master", $illust_url); - Log::debug($illust_url); - $metadata->image = $this->proxize($illust_url);; + $metadata->image = $this->proxize($illust_url); + ; return $metadata; } else { throw new \RuntimeException("{$res->getStatusCode()}: $url"); } - }else { + } else { $client = new \GuzzleHttp\Client(); $res = $client->get($url); if ($res->getStatusCode() === 200) { @@ -68,13 +76,14 @@ class PixivResolver implements Resolver if (strpos($metadata->image, "pixiv_logo.gif") || strpos($metadata->image, "pictures.jpg")) { // 作品ページの場合のみ対応 - if(strpos(parse_url($url)["query"], "mode=medium")){ + if (strpos(parse_url($url)["query"], "mode=medium")) { preg_match("~https://i\.pximg\.net/c/128x128/img-master/img/\d{4}/\d{2}/\d{2}/\d{2}/\d{2}/\d{2}/{$illust_id}(_p0)?_square1200\.jpg~", $res->getBody(), $match); $illust_thumbnail_url = $match[0]; $illust_url = $this->thumbnail_to_master_url($illust_thumbnail_url); - $metadata->image = $this->proxize($illust_url);; + $metadata->image = $this->proxize($illust_url); + ; } } @@ -82,7 +91,6 @@ class PixivResolver implements Resolver } else { throw new \RuntimeException("{$res->getStatusCode()}: $url"); } - } } } From e6abcc44026ec9fb8d8d764db698050f003b9d84 Mon Sep 17 00:00:00 2001 From: shibafu Date: Mon, 14 Jan 2019 14:47:16 +0900 Subject: [PATCH 06/14] =?UTF-8?q?=E4=BE=9D=E5=AD=98=E9=96=A2=E4=BF=82?= =?UTF-8?q?=E3=81=ABreCAPTCHA=E7=94=A8=E3=83=91=E3=83=83=E3=82=B1=E3=83=BC?= =?UTF-8?q?=E3=82=B8=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 3 +++ composer.json | 1 + composer.lock | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 244e6a5..06c004b 100644 --- a/.env.example +++ b/.env.example @@ -35,3 +35,6 @@ SPARKPOST_SECRET= PUSHER_APP_ID= PUSHER_APP_KEY= PUSHER_APP_SECRET= + +NOCAPTCHA_SECRET= +NOCAPTCHA_SITEKEY= \ No newline at end of file diff --git a/composer.json b/composer.json index b309ae6..b64f2d1 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,7 @@ "type": "project", "require": { "php": ">=7.0.0", + "anhskohbo/no-captcha": "^3.0", "doctrine/dbal": "^2.9", "fideloper/proxy": "~3.3", "guzzlehttp/guzzle": "^6.3", diff --git a/composer.lock b/composer.lock index 0d47d7a..ac5ace9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,67 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "6ac4cd158b1f93a24e21fce57d4404c8", + "content-hash": "4a3dffd3f7adecbb805a02c43f5c1f25", "packages": [ + { + "name": "anhskohbo/no-captcha", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/anhskohbo/no-captcha.git", + "reference": "164715a2de0fded5979e7a9b7721785d72a4a7d3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/anhskohbo/no-captcha/zipball/164715a2de0fded5979e7a9b7721785d72a4a7d3", + "reference": "164715a2de0fded5979e7a9b7721785d72a4a7d3", + "shasum": "" + }, + "require": { + "guzzlehttp/guzzle": "^6.2", + "illuminate/support": "5.0.*|5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*", + "php": ">=5.5.5" + }, + "require-dev": { + "phpunit/phpunit": "~4.8" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Anhskohbo\\NoCaptcha\\NoCaptchaServiceProvider" + ], + "aliases": { + "NoCaptcha": "Anhskohbo\\NoCaptcha\\Facades\\NoCaptcha" + } + } + }, + "autoload": { + "psr-4": { + "Anhskohbo\\NoCaptcha\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "anhskohbo", + "email": "anhskohbo@gmail.com" + } + ], + "description": "No CAPTCHA reCAPTCHA For Laravel.", + "keywords": [ + "captcha", + "laravel", + "laravel4", + "laravel5", + "no-captcha", + "recaptcha" + ], + "time": "2018-08-27T02:16:31+00:00" + }, { "name": "dnoegel/php-xdg-base-dir", "version": "0.1", From fcdb9d7aba0f8cf17424b25a10ea551f2379dc2d Mon Sep 17 00:00:00 2001 From: shibafu Date: Mon, 14 Jan 2019 15:01:50 +0900 Subject: [PATCH 07/14] =?UTF-8?q?reCAPTCHA=E3=81=AE=E8=A8=AD=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Auth/RegisterController.php | 1 + resources/lang/ja/validation.php | 4 ++++ resources/views/auth/register.blade.php | 12 ++++++++++++ 3 files changed, 17 insertions(+) diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index c68ed7e..d3052d1 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -51,6 +51,7 @@ class RegisterController extends Controller 'name' => 'required|string|regex:/^[a-zA-Z0-9_-]+$/u|max:15|unique:users', 'email' => 'required|string|email|max:255|unique:users', 'password' => 'required|string|min:6|confirmed', + 'g-recaptcha-response' => 'required|captcha' ], ['name.regex' => 'ユーザー名には半角英数字とアンダーバー、ハイフンのみ使用できます。'], ['name' => 'ユーザー名'] diff --git a/resources/lang/ja/validation.php b/resources/lang/ja/validation.php index 7b11851..9c9217f 100644 --- a/resources/lang/ja/validation.php +++ b/resources/lang/ja/validation.php @@ -99,6 +99,10 @@ return [ 'attribute-name' => [ 'rule-name' => 'custom-message', ], + 'g-recaptcha-response' => [ + 'required' => '「私はロボットではありません」にチェックを入れてください。', + 'captcha' => 'reCAPTCHAチェックに失敗しました。何度試しても解決しない場合、管理者にお問い合わせください。', + ], ], /* diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php index 7ef6a7d..59b2fa9 100644 --- a/resources/views/auth/register.blade.php +++ b/resources/views/auth/register.blade.php @@ -2,6 +2,10 @@ @section('title', '新規登録') +@push('head') + {!! NoCaptcha::renderJs() !!} +@endpush + @section('content')

新規登録

@@ -53,6 +57,14 @@
+
+
+ {!! NoCaptcha::display() !!} +
+ @if ($errors->has('g-recaptcha-response')) +
{{ $errors->first('g-recaptcha-response') }}
+ @endif +
From 2299ac3fe74bb7cff22b4016f28287afcb525cef Mon Sep 17 00:00:00 2001 From: shibafu Date: Mon, 14 Jan 2019 15:18:41 +0900 Subject: [PATCH 08/14] =?UTF-8?q?=E9=96=8B=E7=99=BA=E7=92=B0=E5=A2=83?= =?UTF-8?q?=E5=90=91=E3=81=91=E3=81=AE=E6=8E=AA=E7=BD=AE=E3=81=A8=E3=81=97?= =?UTF-8?q?=E3=81=A6=E3=80=81reCAPTCHA=E3=81=AF=E4=BB=BB=E6=84=8F=E8=A8=AD?= =?UTF-8?q?=E5=AE=9A=E3=81=A8=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 4 +++- .../Controllers/Auth/RegisterController.php | 14 +++++++++---- resources/views/auth/register.blade.php | 20 +++++++++++-------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/.env.example b/.env.example index 06c004b..84e517d 100644 --- a/.env.example +++ b/.env.example @@ -36,5 +36,7 @@ PUSHER_APP_ID= PUSHER_APP_KEY= PUSHER_APP_SECRET= +# (Optional) reCAPTCHA Key +# https://www.google.com/recaptcha NOCAPTCHA_SECRET= -NOCAPTCHA_SITEKEY= \ No newline at end of file +NOCAPTCHA_SITEKEY= diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index d3052d1..0e79f03 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -47,12 +47,18 @@ class RegisterController extends Controller */ protected function validator(array $data) { - return Validator::make($data, [ + $rules = [ 'name' => 'required|string|regex:/^[a-zA-Z0-9_-]+$/u|max:15|unique:users', 'email' => 'required|string|email|max:255|unique:users', - 'password' => 'required|string|min:6|confirmed', - 'g-recaptcha-response' => 'required|captcha' - ], + 'password' => 'required|string|min:6|confirmed' + ]; + + // reCAPTCHAのキーが設定されている場合、判定を有効化 + if (!empty(config('captcha.secret'))) { + $rules['g-recaptcha-response'] = 'required|captcha'; + } + + return Validator::make($data, $rules, ['name.regex' => 'ユーザー名には半角英数字とアンダーバー、ハイフンのみ使用できます。'], ['name' => 'ユーザー名'] ); diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php index 59b2fa9..ff9fc34 100644 --- a/resources/views/auth/register.blade.php +++ b/resources/views/auth/register.blade.php @@ -3,7 +3,9 @@ @section('title', '新規登録') @push('head') - {!! NoCaptcha::renderJs() !!} + @if (!empty(config('captcha.secret'))) + {!! NoCaptcha::renderJs() !!} + @endif @endpush @section('content') @@ -57,14 +59,16 @@
-
-
- {!! NoCaptcha::display() !!} + @if (!empty(config('captcha.secret'))) +
+
+ {!! NoCaptcha::display() !!} +
+ @if ($errors->has('g-recaptcha-response')) +
{{ $errors->first('g-recaptcha-response') }}
+ @endif
- @if ($errors->has('g-recaptcha-response')) -
{{ $errors->first('g-recaptcha-response') }}
- @endif -
+ @endif
From d359a41033a93082bfb94e115723ab87fce31031 Mon Sep 17 00:00:00 2001 From: eai04191 Date: Mon, 14 Jan 2019 17:58:45 +0900 Subject: [PATCH 09/14] =?UTF-8?q?=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89?= =?UTF-8?q?=E5=90=8D=E3=82=92camelCase=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MetadataResolver/PixivResolver.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/MetadataResolver/PixivResolver.php b/app/MetadataResolver/PixivResolver.php index 99c54b6..996b82c 100644 --- a/app/MetadataResolver/PixivResolver.php +++ b/app/MetadataResolver/PixivResolver.php @@ -11,7 +11,7 @@ class PixivResolver implements Resolver * @param string サムネイル画像 URL * @return string 1200px の画像 URL */ - public function thumbnail_to_master_url(string $url):string + public function thumbnailToMasterUrl(string $url):string { $url = str_replace("/c/128x128", "", $url); $url = str_replace("square1200.jpg", "master1200.jpg", $url); @@ -53,7 +53,7 @@ class PixivResolver implements Resolver preg_match("~https://i\.pximg\.net/c/128x128/img-master/img/\d{4}/\d{2}/\d{2}/\d{2}/\d{2}/\d{2}/{$illust_id}_p0_square1200\.jpg~", $res->getBody(), $match); $illust_thumbnail_url = $match[0]; - $illust_url = $this->thumbnail_to_master_url($illust_thumbnail_url); + $illust_url = $this->thumbnailToMasterUrl($illust_thumbnail_url); // 指定ページに変換 $illust_url = str_replace("p0_master", "p{$page}_master", $illust_url); @@ -80,7 +80,7 @@ class PixivResolver implements Resolver preg_match("~https://i\.pximg\.net/c/128x128/img-master/img/\d{4}/\d{2}/\d{2}/\d{2}/\d{2}/\d{2}/{$illust_id}(_p0)?_square1200\.jpg~", $res->getBody(), $match); $illust_thumbnail_url = $match[0]; - $illust_url = $this->thumbnail_to_master_url($illust_thumbnail_url); + $illust_url = $this->thumbnailToMasterUrl($illust_thumbnail_url); $metadata->image = $this->proxize($illust_url); ; From 2d04ed8dd7ec2b3334f87ac7c3a12f8eef29e660 Mon Sep 17 00:00:00 2001 From: eai04191 Date: Mon, 14 Jan 2019 18:16:48 +0900 Subject: [PATCH 10/14] =?UTF-8?q?thumbnailToMasterUrl=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ドキュメントコメントを修正 - 変数名をより正確なものに修正 --- app/MetadataResolver/PixivResolver.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/MetadataResolver/PixivResolver.php b/app/MetadataResolver/PixivResolver.php index 996b82c..86d00cd 100644 --- a/app/MetadataResolver/PixivResolver.php +++ b/app/MetadataResolver/PixivResolver.php @@ -8,14 +8,14 @@ class PixivResolver implements Resolver /** * サムネイル画像 URL から最大長辺 1200px の画像 URL に変換する * - * @param string サムネイル画像 URL + * @param string $thumbnail_url サムネイル画像 URL * @return string 1200px の画像 URL */ - public function thumbnailToMasterUrl(string $url):string + public function thumbnailToMasterUrl(string $thumbnail_url):string { - $url = str_replace("/c/128x128", "", $url); - $url = str_replace("square1200.jpg", "master1200.jpg", $url); - return $url; + $temp = str_replace("/c/128x128", "", $thumbnail_url); + $large_url = str_replace("square1200.jpg", "master1200.jpg", $temp); + return $large_url; } /** @@ -23,12 +23,14 @@ class PixivResolver implements Resolver * HUGE THANKS TO PIXIV.CAT! * * @param string i.pximg URL + * @param string $pixiv_url i.pximg URL * @return string i.pixiv.cat URL */ public function proxize(string $url):string { $url = str_replace("i.pximg.net", "i.pixiv.cat", $url); return $url; + return str_replace("i.pximg.net", "i.pixiv.cat", $pixiv_url); } public function resolve(string $url): Metadata From 6ff247acd7139e95601dbec83ca3ecf73f54c7dd Mon Sep 17 00:00:00 2001 From: eai04191 Date: Mon, 14 Jan 2019 18:18:06 +0900 Subject: [PATCH 11/14] =?UTF-8?q?proxize=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ドキュメントコメントを修正 - 引数名をより正確なものに修正 --- app/MetadataResolver/PixivResolver.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/MetadataResolver/PixivResolver.php b/app/MetadataResolver/PixivResolver.php index 86d00cd..ad82f48 100644 --- a/app/MetadataResolver/PixivResolver.php +++ b/app/MetadataResolver/PixivResolver.php @@ -22,14 +22,11 @@ class PixivResolver implements Resolver * 直リン可能な pixiv.cat のプロキシ URL に変換する * HUGE THANKS TO PIXIV.CAT! * - * @param string i.pximg URL * @param string $pixiv_url i.pximg URL * @return string i.pixiv.cat URL */ - public function proxize(string $url):string + public function proxize(string $pixiv_url):string { - $url = str_replace("i.pximg.net", "i.pixiv.cat", $url); - return $url; return str_replace("i.pximg.net", "i.pixiv.cat", $pixiv_url); } From 98e933b833ef600436cc922674987dffb93c7432 Mon Sep 17 00:00:00 2001 From: eai04191 Date: Mon, 14 Jan 2019 18:34:33 +0900 Subject: [PATCH 12/14] =?UTF-8?q?=E5=A4=89=E6=95=B0=E5=90=8D=E3=82=92camel?= =?UTF-8?q?Case=20=E3=81=AB=E7=B5=B1=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MetadataResolver/PixivResolver.php | 38 +++++++++++++------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/app/MetadataResolver/PixivResolver.php b/app/MetadataResolver/PixivResolver.php index ad82f48..c395892 100644 --- a/app/MetadataResolver/PixivResolver.php +++ b/app/MetadataResolver/PixivResolver.php @@ -8,32 +8,32 @@ class PixivResolver implements Resolver /** * サムネイル画像 URL から最大長辺 1200px の画像 URL に変換する * - * @param string $thumbnail_url サムネイル画像 URL + * @param string $thumbnailUrl サムネイル画像 URL * @return string 1200px の画像 URL */ - public function thumbnailToMasterUrl(string $thumbnail_url):string + public function thumbnailToMasterUrl(string $thumbnailUrl):string { - $temp = str_replace("/c/128x128", "", $thumbnail_url); - $large_url = str_replace("square1200.jpg", "master1200.jpg", $temp); - return $large_url; + $temp = str_replace("/c/128x128", "", $thumbnailUrl); + $largeUrl = str_replace("square1200.jpg", "master1200.jpg", $temp); + return $largeUrl; } /** * 直リン可能な pixiv.cat のプロキシ URL に変換する * HUGE THANKS TO PIXIV.CAT! * - * @param string $pixiv_url i.pximg URL + * @param string $pixivUrl i.pximg URL * @return string i.pixiv.cat URL */ - public function proxize(string $pixiv_url):string + public function proxize(string $pixivUrl):string { - return str_replace("i.pximg.net", "i.pixiv.cat", $pixiv_url); + return str_replace("i.pximg.net", "i.pixiv.cat", $pixivUrl); } public function resolve(string $url): Metadata { - preg_match("~illust_id=(\d+)~", parse_url($url)["query"], $illust_id); - $illust_id = $illust_id[1]; + preg_match("~illust_id=(\d+)~", parse_url($url)["query"], $match); + $illustId = $match[1]; // 漫画ページかつページ数あり if (strpos(parse_url($url)["query"], "mode=manga_big") && strpos(parse_url($url)["query"], "page=")) { @@ -49,15 +49,15 @@ class PixivResolver implements Resolver $ogpResolver = new OGPResolver(); $metadata = $ogpResolver->parse($res->getBody()); - preg_match("~https://i\.pximg\.net/c/128x128/img-master/img/\d{4}/\d{2}/\d{2}/\d{2}/\d{2}/\d{2}/{$illust_id}_p0_square1200\.jpg~", $res->getBody(), $match); - $illust_thumbnail_url = $match[0]; + preg_match("~https://i\.pximg\.net/c/128x128/img-master/img/\d{4}/\d{2}/\d{2}/\d{2}/\d{2}/\d{2}/{$illustId}_p0_square1200\.jpg~", $res->getBody(), $match); + $illustThumbnailUrl = $match[0]; - $illust_url = $this->thumbnailToMasterUrl($illust_thumbnail_url); + $illustUrl = $this->thumbnailToMasterUrl($illustThumbnailUrl); // 指定ページに変換 - $illust_url = str_replace("p0_master", "p{$page}_master", $illust_url); + $illustUrl = str_replace("p0_master", "p{$page}_master", $illustUrl); - $metadata->image = $this->proxize($illust_url); + $metadata->image = $this->proxize($illustUrl); ; return $metadata; @@ -76,12 +76,12 @@ class PixivResolver implements Resolver // 作品ページの場合のみ対応 if (strpos(parse_url($url)["query"], "mode=medium")) { - preg_match("~https://i\.pximg\.net/c/128x128/img-master/img/\d{4}/\d{2}/\d{2}/\d{2}/\d{2}/\d{2}/{$illust_id}(_p0)?_square1200\.jpg~", $res->getBody(), $match); - $illust_thumbnail_url = $match[0]; + preg_match("~https://i\.pximg\.net/c/128x128/img-master/img/\d{4}/\d{2}/\d{2}/\d{2}/\d{2}/\d{2}/{$illustId}(_p0)?_square1200\.jpg~", $res->getBody(), $match); + $illustThumbnailUrl = $match[0]; - $illust_url = $this->thumbnailToMasterUrl($illust_thumbnail_url); + $illustUrl = $this->thumbnailToMasterUrl($illustThumbnailUrl); - $metadata->image = $this->proxize($illust_url); + $metadata->image = $this->proxize($illustUrl); ; } } From d6e981ac39434c191727d228c699803c62e27624 Mon Sep 17 00:00:00 2001 From: eai04191 Date: Mon, 14 Jan 2019 18:35:34 +0900 Subject: [PATCH 13/14] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E3=82=BB?= =?UTF-8?q?=E3=83=9F=E3=82=B3=E3=83=AD=E3=83=B3=E3=81=AE=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MetadataResolver/PixivResolver.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/MetadataResolver/PixivResolver.php b/app/MetadataResolver/PixivResolver.php index c395892..c06f0e4 100644 --- a/app/MetadataResolver/PixivResolver.php +++ b/app/MetadataResolver/PixivResolver.php @@ -58,7 +58,6 @@ class PixivResolver implements Resolver $illustUrl = str_replace("p0_master", "p{$page}_master", $illustUrl); $metadata->image = $this->proxize($illustUrl); - ; return $metadata; } else { @@ -82,7 +81,6 @@ class PixivResolver implements Resolver $illustUrl = $this->thumbnailToMasterUrl($illustThumbnailUrl); $metadata->image = $this->proxize($illustUrl); - ; } } From 0e410ef342197647b594c73b5c3441f46453cb95 Mon Sep 17 00:00:00 2001 From: mohemohe Date: Mon, 14 Jan 2019 18:37:42 +0900 Subject: [PATCH 14/14] =?UTF-8?q?composer=20install=E3=81=A7dist=E3=81=8B?= =?UTF-8?q?=E3=82=89=E5=8F=96=E3=82=8C=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E3=81=99=E3=82=8B=20(#26)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9301d92..4960985 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM php:7.1-apache ENV APACHE_DOCUMENT_ROOT /var/www/html/public RUN apt-get update \ - && apt-get install -y git libpq-dev \ + && apt-get install -y git libpq-dev unzip \ && docker-php-ext-install pdo_pgsql \ && curl -sS https://getcomposer.org/installer | php \ && mv composer.phar /usr/local/bin/composer \