diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 98d18c5..2a606a5 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -118,6 +118,11 @@ class HomeController extends Controller } } + /** + * @param TagDetectorService $tag_detector + * @return mixed + * @throws \Exception + */ public function store(TagDetectorService $tag_detector) { $user_id = Auth::user()->getAuthIdentifier(); diff --git a/app/Http/Controllers/ImageController.php b/app/Http/Controllers/ImageController.php new file mode 100644 index 0000000..57e0daf --- /dev/null +++ b/app/Http/Controllers/ImageController.php @@ -0,0 +1,82 @@ +getAuthIdentifier() !== (int)$post->user_id) { + throw new UnauthorizedHttpException('Cette image ne vous appartient pas.'); + } + + $path = sprintf('%s/%s/%s', storage_path('app'), Auth::user()->getFolder(), $image); + if (!is_readable($path)) { + throw new NotFoundHttpException(); + } + + + $img = Image::make($path); + + if ('o:full' !== $options) { + $options = explode('!', $options); + $width = null; + $height = null; + foreach ($options as $option) { + $current_option = explode(':', $option); + foreach ($current_option as $current_option_name => $current_option_value) { + switch ($current_option_name) { + case 'w': + $width = $current_option_value; + break; + case 'h': + $height = $current_option_value; + break; + } + } + } + //http://image.intervention.io/getting_started/ + $img->resize($width, $height, static function (Constraint $constraint) { + $constraint->aspectRatio(); + }); + } + + return $img->response(File::extension($path)); + } + + /** + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + */ + public function gallery() + { + $posts_with_image = Post::where('user_id', Auth::user()->getAuthIdentifier()) + ->where('image', '!=', 'null') + ->orderBy('created_at', 'desc') + ->paginate(30); + + return view('gallery.my', [ + 'posts' => $posts_with_image, + ]); + } +} diff --git a/app/User.php b/app/User.php index 8d34633..b7c1510 100644 --- a/app/User.php +++ b/app/User.php @@ -42,20 +42,4 @@ class User extends Authenticatable $arrayHash = str_split(strtolower(md5($this->id))); return sprintf('%s/%s', $arrayHash[0], $arrayHash[1]); } - - public function getImageData(Post $post) - { - if (empty($post->image)) { - return ''; - } - - $path = sprintf('%s/%s/%s', storage_path('app'), $this->getFolder(), $post->image); - - if (!is_readable($path)) { - return ''; - } - $type = pathinfo($path, PATHINFO_EXTENSION); - $data = file_get_contents($path); - return sprintf('data:image/%s;base64,%s', $type, base64_encode($data)); - } } diff --git a/composer.json b/composer.json index 0d3f00d..4de1904 100644 --- a/composer.json +++ b/composer.json @@ -10,8 +10,10 @@ "require": { "php": "^7.2", "fideloper/proxy": "^4.0", + "intervention/image": "^2.5", "laravel/framework": "^6.0", - "laravel/tinker": "^1.0" + "laravel/tinker": "^1.0", + "lavary/laravel-menu": "^1.7" }, "require-dev": { "facade/ignition": "^1.4", diff --git a/composer.lock b/composer.lock index d8da420..a25d7a0 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3f43a645b4cb3d85ae04049046b0845a", + "content-hash": "a8999b4d9f518e7a9608ff59c6ba40e9", "packages": [ { "name": "dnoegel/php-xdg-base-dir", @@ -380,6 +380,147 @@ ], "time": "2019-09-03T16:45:42+00:00" }, + { + "name": "guzzlehttp/psr7", + "version": "1.6.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "239400de7a173fe9901b9ac7c06497751f00727a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/239400de7a173fe9901b9ac7c06497751f00727a", + "reference": "239400de7a173fe9901b9ac7c06497751f00727a", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "psr/http-message": "~1.0", + "ralouphie/getallheaders": "^2.0.5 || ^3.0.0" + }, + "provide": { + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "ext-zlib": "*", + "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8" + }, + "suggest": { + "zendframework/zend-httphandlerrunner": "Emit PSR-7 responses" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.6-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Schultze", + "homepage": "https://github.com/Tobion" + } + ], + "description": "PSR-7 message implementation that also provides common utility methods", + "keywords": [ + "http", + "message", + "psr-7", + "request", + "response", + "stream", + "uri", + "url" + ], + "time": "2019-07-01T23:21:34+00:00" + }, + { + "name": "intervention/image", + "version": "2.5.1", + "source": { + "type": "git", + "url": "https://github.com/Intervention/image.git", + "reference": "abbf18d5ab8367f96b3205ca3c89fb2fa598c69e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Intervention/image/zipball/abbf18d5ab8367f96b3205ca3c89fb2fa598c69e", + "reference": "abbf18d5ab8367f96b3205ca3c89fb2fa598c69e", + "shasum": "" + }, + "require": { + "ext-fileinfo": "*", + "guzzlehttp/psr7": "~1.1", + "php": ">=5.4.0" + }, + "require-dev": { + "mockery/mockery": "~0.9.2", + "phpunit/phpunit": "^4.8 || ^5.7" + }, + "suggest": { + "ext-gd": "to use GD library based image processing.", + "ext-imagick": "to use Imagick based image processing.", + "intervention/imagecache": "Caching extension for the Intervention Image library" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.4-dev" + }, + "laravel": { + "providers": [ + "Intervention\\Image\\ImageServiceProvider" + ], + "aliases": { + "Image": "Intervention\\Image\\Facades\\Image" + } + } + }, + "autoload": { + "psr-4": { + "Intervention\\Image\\": "src/Intervention/Image" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Oliver Vogel", + "email": "oliver@olivervogel.com", + "homepage": "http://olivervogel.com/" + } + ], + "description": "Image handling and manipulation library with support for Laravel integration", + "homepage": "http://image.intervention.io/", + "keywords": [ + "gd", + "image", + "imagick", + "laravel", + "thumbnail", + "watermark" + ], + "time": "2019-11-02T09:15:47+00:00" + }, { "name": "jakub-onderka/php-console-color", "version": "v0.2", @@ -676,6 +817,58 @@ ], "time": "2019-08-07T15:10:45+00:00" }, + { + "name": "lavary/laravel-menu", + "version": "v1.7.7", + "source": { + "type": "git", + "url": "https://github.com/lavary/laravel-menu.git", + "reference": "5592778b3193ae561614ecb107467469b694ab11" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/lavary/laravel-menu/zipball/5592778b3193ae561614ecb107467469b694ab11", + "reference": "5592778b3193ae561614ecb107467469b694ab11", + "shasum": "" + }, + "require": { + "illuminate/support": ">=5.0", + "illuminate/view": ">=5.0", + "php": ">=5.4.0" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Lavary\\Menu\\ServiceProvider" + ], + "aliases": { + "Menu": "Lavary\\Menu\\Facade" + } + } + }, + "autoload": { + "psr-0": { + "Lavary\\Menu\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Lavary", + "email": "mrl.8081@gmail.com" + } + ], + "description": "A quick way to create menus in Laravel 5", + "homepage": "https://github.com/lavary/laravel-menu", + "keywords": [ + "laravel" + ], + "time": "2019-09-06T16:28:16+00:00" + }, { "name": "league/flysystem", "version": "1.0.55", @@ -1164,6 +1357,56 @@ ], "time": "2017-02-14T16:28:37+00:00" }, + { + "name": "psr/http-message", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "time": "2016-08-06T14:39:51+00:00" + }, { "name": "psr/log", "version": "1.1.0", @@ -1333,6 +1576,46 @@ ], "time": "2018-10-13T15:16:03+00:00" }, + { + "name": "ralouphie/getallheaders", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "A polyfill for getallheaders.", + "time": "2019-03-08T08:55:37+00:00" + }, { "name": "ramsey/uuid", "version": "3.8.0", diff --git a/config/app.php b/config/app.php index e0a4459..54da053 100644 --- a/config/app.php +++ b/config/app.php @@ -176,7 +176,7 @@ return [ App\Providers\RouteServiceProvider::class, \App\Providers\TagDetectorProvider::class, - + Intervention\Image\ImageServiceProvider::class, ], /* @@ -209,6 +209,7 @@ return [ 'File' => Illuminate\Support\Facades\File::class, 'Gate' => Illuminate\Support\Facades\Gate::class, 'Hash' => Illuminate\Support\Facades\Hash::class, + 'Image' => Intervention\Image\Facades\Image::class, 'Lang' => Illuminate\Support\Facades\Lang::class, 'Log' => Illuminate\Support\Facades\Log::class, 'Mail' => Illuminate\Support\Facades\Mail::class, diff --git a/config/image.php b/config/image.php new file mode 100644 index 0000000..2b1d2c3 --- /dev/null +++ b/config/image.php @@ -0,0 +1,20 @@ + 'gd' + +]; diff --git a/resources/views/gallery/my.blade.php b/resources/views/gallery/my.blade.php new file mode 100644 index 0000000..5f0fca1 --- /dev/null +++ b/resources/views/gallery/my.blade.php @@ -0,0 +1,33 @@ +@extends('layouts.connected') + +@section('content') +
+ +
+ @foreach($posts as $post) +
+
+
+
+

{{ ucfirst(\Carbon\Carbon::instance($post->date_post)->diffForHumans()) }}

+
+ +
+
+
+

+ + + +

+
+
+
+ @endforeach +
+
+@endsection diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index 19e6c9d..fa00d1e 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -133,7 +133,7 @@
- @if($post->image != '')

@endif + @if($post->image != '')

@endif {!! $tag_detector->linkTagFrom($post->content) !!}