diff --git a/app/Utilities/Formatter.php b/app/Utilities/Formatter.php index bb87a61..fd7da98 100644 --- a/app/Utilities/Formatter.php +++ b/app/Utilities/Formatter.php @@ -2,8 +2,18 @@ namespace App\Utilities; +use Misd\Linkify\Linkify; + class Formatter { + /** @var Linkify */ + private $linkify; + + public function __construct() + { + $this->linkify = new Linkify(); + } + /** * 通算秒数を日数と時分にフォーマットします。 * @param int|float $value 通算秒数 @@ -16,4 +26,14 @@ class Formatter $minutes = floor($value % 3600 / 60); return "{$days}日 {$hours}時間 {$minutes}分"; } + + /** + * テキスト内のURLをHTMLのリンクに置き換えます。 + * @param string $text テキスト + * @return string URLをリンクに置き換えた文字列 + */ + public function linkify($text) + { + return $this->linkify->processUrls($text); + } } \ No newline at end of file diff --git a/composer.json b/composer.json index 21bfed3..6a8cc49 100644 --- a/composer.json +++ b/composer.json @@ -8,6 +8,7 @@ "php": ">=7.0.0", "laravel/framework": "5.5.*", "laravel/tinker": "~1.0", + "misd/linkify": "^1.1", "parsedown/laravel": "~1.0" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 231987b..c766e56 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "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": "8fd656953b9909fbcbecf476db92f15c", + "content-hash": "49697b9f7b0f02fe37b2bff14bddf200", "packages": [ { "name": "dnoegel/php-xdg-base-dir", @@ -623,6 +623,51 @@ ], "time": "2017-08-06T17:41:04+00:00" }, + { + "name": "misd/linkify", + "version": "v1.1.4", + "source": { + "type": "git", + "url": "https://github.com/misd-service-development/php-linkify.git", + "reference": "3481b148806a23b4001712de645247a1a4dcc10a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/misd-service-development/php-linkify/zipball/3481b148806a23b4001712de645247a1a4dcc10a", + "reference": "3481b148806a23b4001712de645247a1a4dcc10a", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Misd\\Linkify\\": "src/Misd/Linkify" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Converts URLs and email addresses in text into HTML links", + "homepage": "https://github.com/misd-service-development/php-linkify", + "keywords": [ + "convert", + "email address", + "link", + "url" + ], + "time": "2017-08-17T08:33:35+00:00" + }, { "name": "monolog/monolog", "version": "1.23.0", diff --git a/resources/views/layouts/base-old.blade.php b/resources/views/layouts/base-old.blade.php index 2865eae..6534525 100644 --- a/resources/views/layouts/base-old.blade.php +++ b/resources/views/layouts/base-old.blade.php @@ -20,7 +20,7 @@ @if (Auth::check()) @@ -45,7 +45,7 @@ diff --git a/resources/views/user/profile.blade.php b/resources/views/user/profile.blade.php index 121edef..51cbdd1 100644 --- a/resources/views/user/profile.blade.php +++ b/resources/views/user/profile.blade.php @@ -41,7 +41,7 @@ @if (!empty($ejaculation['note']))

- {{ $ejaculation['note'] }} + {!! Formatter::linkify(nl2br(e($ejaculation['note']))) !!}

@endif