Showing
6 changed files
with
165 additions
and
11 deletions
| ... | @@ -5,6 +5,8 @@ namespace Oxbow\Http\Controllers; | ... | @@ -5,6 +5,8 @@ namespace Oxbow\Http\Controllers; |
| 5 | use Illuminate\Filesystem\Filesystem as File; | 5 | use Illuminate\Filesystem\Filesystem as File; |
| 6 | use Illuminate\Http\Request; | 6 | use Illuminate\Http\Request; |
| 7 | 7 | ||
| 8 | +use Intervention\Image\Facades\Image as ImageTool; | ||
| 9 | +use Illuminate\Support\Facades\DB; | ||
| 8 | use Oxbow\Http\Requests; | 10 | use Oxbow\Http\Requests; |
| 9 | use Oxbow\Image; | 11 | use Oxbow\Image; |
| 10 | 12 | ||
| ... | @@ -62,6 +64,49 @@ class ImageController extends Controller | ... | @@ -62,6 +64,49 @@ class ImageController extends Controller |
| 62 | } | 64 | } |
| 63 | 65 | ||
| 64 | /** | 66 | /** |
| 67 | + * Get all images, Paginated | ||
| 68 | + * @param int $page | ||
| 69 | + * @return \Illuminate\Http\JsonResponse | ||
| 70 | + */ | ||
| 71 | + public function getAll($page = 0) | ||
| 72 | + { | ||
| 73 | + $pageSize = 25; | ||
| 74 | + $images = DB::table('images')->orderBy('created_at', 'desc') | ||
| 75 | + ->skip($page*$pageSize)->take($pageSize)->get(); | ||
| 76 | + foreach($images as $image) { | ||
| 77 | + $image->thumbnail = $this->getThumbnail($image, 150, 150); | ||
| 78 | + } | ||
| 79 | + return response()->json($images); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + /** | ||
| 83 | + * Get the thumbnail for an image. | ||
| 84 | + * @param $image | ||
| 85 | + * @param int $width | ||
| 86 | + * @param int $height | ||
| 87 | + * @return string | ||
| 88 | + */ | ||
| 89 | + public function getThumbnail($image, $width = 220, $height = 220) | ||
| 90 | + { | ||
| 91 | + $explodedPath = explode('/', $image->url); | ||
| 92 | + array_splice($explodedPath, 3, 0, ['thumbs-' . $width . '-' . $height]); | ||
| 93 | + $thumbPath = implode('/', $explodedPath); | ||
| 94 | + $thumbFilePath = storage_path() . $thumbPath; | ||
| 95 | + if(file_exists($thumbFilePath)) { | ||
| 96 | + return $thumbPath; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + //dd($thumbFilePath); | ||
| 100 | + $thumb = ImageTool::make(storage_path() . $image->url); | ||
| 101 | + $thumb->fit($width, $height); | ||
| 102 | + if(!file_exists(dirname($thumbFilePath))) { | ||
| 103 | + mkdir(dirname($thumbFilePath), 0775, true); | ||
| 104 | + } | ||
| 105 | + $thumb->save($thumbFilePath); | ||
| 106 | + return $thumbFilePath; | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + /** | ||
| 65 | * Handles image uploads for use on pages. | 110 | * Handles image uploads for use on pages. |
| 66 | * @param Request $request | 111 | * @param Request $request |
| 67 | * @return \Illuminate\Http\JsonResponse | 112 | * @return \Illuminate\Http\JsonResponse |
| ... | @@ -69,7 +114,7 @@ class ImageController extends Controller | ... | @@ -69,7 +114,7 @@ class ImageController extends Controller |
| 69 | public function upload(Request $request) | 114 | public function upload(Request $request) |
| 70 | { | 115 | { |
| 71 | $imageUpload = $request->file('file'); | 116 | $imageUpload = $request->file('file'); |
| 72 | - $name = $imageUpload->getClientOriginalName(); | 117 | + $name = str_replace(' ', '-', $imageUpload->getClientOriginalName()); |
| 73 | $imagePath = '/images/' . Date('Y-m-M') . '/'; | 118 | $imagePath = '/images/' . Date('Y-m-M') . '/'; |
| 74 | $storagePath = storage_path(). $imagePath; | 119 | $storagePath = storage_path(). $imagePath; |
| 75 | $fullPath = $storagePath . $name; | 120 | $fullPath = $storagePath . $name; |
| ... | @@ -82,7 +127,7 @@ class ImageController extends Controller | ... | @@ -82,7 +127,7 @@ class ImageController extends Controller |
| 82 | $this->image->name = $name; | 127 | $this->image->name = $name; |
| 83 | $this->image->url = $imagePath . $name; | 128 | $this->image->url = $imagePath . $name; |
| 84 | $this->image->save(); | 129 | $this->image->save(); |
| 85 | - return response()->json(['link' => $this->image->url]); | 130 | + return response()->json($this->image); |
| 86 | } | 131 | } |
| 87 | 132 | ||
| 88 | 133 | ... | ... |
| ... | @@ -31,6 +31,8 @@ Route::group(['prefix' => 'books'], function() { | ... | @@ -31,6 +31,8 @@ Route::group(['prefix' => 'books'], function() { |
| 31 | 31 | ||
| 32 | Route::post('/upload/image', 'ImageController@upload'); | 32 | Route::post('/upload/image', 'ImageController@upload'); |
| 33 | 33 | ||
| 34 | +Route::get('/images/all', 'ImageController@getAll'); | ||
| 35 | +Route::get('/images/all/{page}', 'ImageController@getAll'); | ||
| 34 | Route::get('/images/{any}', 'ImageController@getImage')->where('any', '.*'); | 36 | Route::get('/images/{any}', 'ImageController@getImage')->where('any', '.*'); |
| 35 | 37 | ||
| 36 | Route::get('/', function () { | 38 | Route::get('/', function () { | ... | ... |
| ... | @@ -25,4 +25,70 @@ header .menu { | ... | @@ -25,4 +25,70 @@ header .menu { |
| 25 | display: block; | 25 | display: block; |
| 26 | width: 100%; | 26 | width: 100%; |
| 27 | font-size: 1.4em; | 27 | font-size: 1.4em; |
| 28 | +} | ||
| 29 | + | ||
| 30 | +.overlay { | ||
| 31 | + background-color: rgba(0, 0, 0, 0.2); | ||
| 32 | + position: fixed; | ||
| 33 | + display: block; | ||
| 34 | + z-index: 95536; | ||
| 35 | + width: 100%; | ||
| 36 | + height: 100%; | ||
| 37 | + min-width: 100%; | ||
| 38 | + min-height: 100%; | ||
| 39 | + top: 0; | ||
| 40 | + left: 0; | ||
| 41 | + right: 0; | ||
| 42 | + bottom: 0; | ||
| 43 | +} | ||
| 44 | +#image-manager { | ||
| 45 | + background-color: #EEE; | ||
| 46 | + max-width: 90%; | ||
| 47 | + max-height: 90%; | ||
| 48 | + width: 90%; | ||
| 49 | + height: 90%; | ||
| 50 | + margin: 2% 5%; | ||
| 51 | + //border: 2px solid $primary; | ||
| 52 | + border-radius: 4px; | ||
| 53 | + box-shadow: 0 0 15px 0 rgba(0, 0, 0, 0.3); | ||
| 54 | + overflow: hidden; | ||
| 55 | + .image-manager-display img { | ||
| 56 | + width: 150px; | ||
| 57 | + height: 150px; | ||
| 58 | + display: inline-block; | ||
| 59 | + margin: $-s 0 0 $-s; | ||
| 60 | + cursor: pointer; | ||
| 61 | + } | ||
| 62 | +} | ||
| 63 | +.image-manager-left { | ||
| 64 | + background-color: #FFF; | ||
| 65 | + height: 100%; | ||
| 66 | + width: 100%; | ||
| 67 | + text-align: left; | ||
| 68 | + .image-manager-display { | ||
| 69 | + height: 75%; | ||
| 70 | + width: 100%; | ||
| 71 | + text-align: left; | ||
| 72 | + overflow-y: scroll; | ||
| 73 | + } | ||
| 74 | +} | ||
| 75 | + | ||
| 76 | +.image-manager-title { | ||
| 77 | + font-size: 2em; | ||
| 78 | + text-align: left; | ||
| 79 | + margin: 0 $-m; | ||
| 80 | + padding: $-xl $-m; | ||
| 81 | + color: #666; | ||
| 82 | + border-bottom: 1px solid #DDD; | ||
| 83 | +} | ||
| 84 | + | ||
| 85 | +.image-manager-dropzone { | ||
| 86 | + background-color: lighten($primary, 40%); | ||
| 87 | + height: 25%; | ||
| 88 | + text-align: center; | ||
| 89 | + font-size: 2em; | ||
| 90 | + line-height: 2em; | ||
| 91 | + padding-top: $-xl*1.2; | ||
| 92 | + color: #666; | ||
| 93 | + border-top: 2px solid $primary; | ||
| 28 | } | 94 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| 1 | @extends('base') | 1 | @extends('base') |
| 2 | 2 | ||
| 3 | @section('head') | 3 | @section('head') |
| 4 | - <link rel="stylesheet" href="/plugins/css/froala_editor.min.css"> | 4 | + <script src="/bower/tinymce-dist/tinymce.jquery.min.js"></script> |
| 5 | - <link rel="stylesheet" href="/plugins/css/froala_style.min.css"> | 5 | + <script src="/bower/dropzone/dist/min/dropzone.min.js"></script> |
| 6 | - <script src="/plugins/js/froala_editor.min.js"></script> | 6 | + <script src="/js/image-manager.js"></script> |
| 7 | @stop | 7 | @stop |
| 8 | 8 | ||
| 9 | @section('content') | 9 | @section('content') |
| ... | @@ -12,15 +12,52 @@ | ... | @@ -12,15 +12,52 @@ |
| 12 | @include('pages/form', ['model' => $page]) | 12 | @include('pages/form', ['model' => $page]) |
| 13 | </form> | 13 | </form> |
| 14 | 14 | ||
| 15 | + <section class="overlay" style="display:none;"> | ||
| 16 | + <div id="image-manager"> | ||
| 17 | + <div class="image-manager-left"> | ||
| 18 | + <div class="image-manager-header"> | ||
| 19 | + <button type="button" class="button neg float right" data-action="close">Close</button> | ||
| 20 | + <div class="image-manager-title">Image Library</div> | ||
| 21 | + </div> | ||
| 22 | + <div class="image-manager-display"> | ||
| 23 | + </div> | ||
| 24 | + <form action="/upload/image" class="image-manager-dropzone"> | ||
| 25 | + {{ csrf_field() }} | ||
| 26 | + Drag images or click here to upload | ||
| 27 | + </form> | ||
| 28 | + </div> | ||
| 29 | + {{--<div class="sidebar">--}} | ||
| 30 | + | ||
| 31 | + {{--</div>--}} | ||
| 32 | + </div> | ||
| 33 | + </section> | ||
| 34 | + | ||
| 15 | <script> | 35 | <script> |
| 16 | $(function() { | 36 | $(function() { |
| 17 | - $('#html').editable({ | 37 | + //ImageManager.show('#image-manager'); |
| 18 | - inlineMode: false, | 38 | + |
| 19 | - imageUploadURL: '/upload/image', | 39 | + tinymce.init({ |
| 20 | - imageUploadParams: { | 40 | + selector: '.edit-area textarea', |
| 21 | - '_token': '{{ csrf_token() }}' | 41 | + content_css: '/css/app.css', |
| 42 | + body_class: 'container', | ||
| 43 | + plugins: "autoresize image table textcolor paste link imagetools", | ||
| 44 | + content_style: "body {padding-left: 15px !important; padding-right: 15px !important;}", | ||
| 45 | + file_browser_callback: function(field_name, url, type, win) { | ||
| 46 | + ImageManager.show('#image-manager', function(image) { | ||
| 47 | + win.document.getElementById(field_name).value = image.url; | ||
| 48 | + if ("createEvent" in document) { | ||
| 49 | + var evt = document.createEvent("HTMLEvents"); | ||
| 50 | + evt.initEvent("change", false, true); | ||
| 51 | + win.document.getElementById(field_name).dispatchEvent(evt); | ||
| 52 | + } else { | ||
| 53 | + win.document.getElementById(field_name).fireEvent("onchange"); | ||
| 54 | + } | ||
| 55 | + }); | ||
| 22 | } | 56 | } |
| 23 | }); | 57 | }); |
| 58 | + | ||
| 59 | + | ||
| 60 | + | ||
| 24 | }); | 61 | }); |
| 25 | </script> | 62 | </script> |
| 26 | @stop | 63 | @stop |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or sign in to post a comment