]> BookStack Code Mirror - bookstack/commitdiff
Integrated TinyMCE
authorDan Brown <redacted>
Tue, 14 Jul 2015 21:34:31 +0000 (22:34 +0100)
committerDan Brown <redacted>
Tue, 14 Jul 2015 21:34:31 +0000 (22:34 +0100)
.gitignore
app/Http/Controllers/ImageController.php
app/Http/routes.php
app/Image.php
resources/assets/sass/styles.scss
resources/views/pages/edit.blade.php

index 9a50d01726c4abe6b6e5c47105d6b5cd1d39250b..188291eb802c9a515d4899fa7ec1502abee00e92 100644 (file)
@@ -6,4 +6,5 @@ Homestead.yaml
 .idea
 /public/plugins
 /public/css
+/public/bower
 /storage/images
\ No newline at end of file
index 941f2ad39986c3062ae047306dabd957c542b066..2014b360487ae12e1ed2e7efc98e38b71f979839 100644 (file)
@@ -5,6 +5,8 @@ namespace Oxbow\Http\Controllers;
 use Illuminate\Filesystem\Filesystem as File;
 use Illuminate\Http\Request;
 
+use Intervention\Image\Facades\Image as ImageTool;
+use Illuminate\Support\Facades\DB;
 use Oxbow\Http\Requests;
 use Oxbow\Image;
 
@@ -61,6 +63,49 @@ class ImageController extends Controller
         abort(404);
     }
 
+    /**
+     * Get all images, Paginated
+     * @param int $page
+     * @return \Illuminate\Http\JsonResponse
+     */
+    public function getAll($page = 0)
+    {
+        $pageSize = 25;
+        $images = DB::table('images')->orderBy('created_at', 'desc')
+            ->skip($page*$pageSize)->take($pageSize)->get();
+        foreach($images as $image) {
+            $image->thumbnail = $this->getThumbnail($image, 150, 150);
+        }
+        return response()->json($images);
+    }
+
+    /**
+     * Get the thumbnail for an image.
+     * @param $image
+     * @param int $width
+     * @param int $height
+     * @return string
+     */
+    public function getThumbnail($image, $width = 220, $height = 220)
+    {
+        $explodedPath = explode('/', $image->url);
+        array_splice($explodedPath, 3, 0, ['thumbs-' . $width . '-' . $height]);
+        $thumbPath = implode('/', $explodedPath);
+        $thumbFilePath = storage_path() . $thumbPath;
+        if(file_exists($thumbFilePath)) {
+            return $thumbPath;
+        }
+
+        //dd($thumbFilePath);
+        $thumb = ImageTool::make(storage_path() . $image->url);
+        $thumb->fit($width, $height);
+        if(!file_exists(dirname($thumbFilePath))) {
+            mkdir(dirname($thumbFilePath), 0775, true);
+        }
+        $thumb->save($thumbFilePath);
+        return $thumbFilePath;
+    }
+
     /**
      * Handles image uploads for use on pages.
      * @param Request $request
@@ -69,7 +114,7 @@ class ImageController extends Controller
     public function upload(Request $request)
     {
         $imageUpload = $request->file('file');
-        $name = $imageUpload->getClientOriginalName();
+        $name = str_replace(' ', '-', $imageUpload->getClientOriginalName());
         $imagePath = '/images/' . Date('Y-m-M') . '/';
         $storagePath = storage_path(). $imagePath;
         $fullPath = $storagePath . $name;
@@ -82,7 +127,7 @@ class ImageController extends Controller
         $this->image->name = $name;
         $this->image->url = $imagePath . $name;
         $this->image->save();
-        return response()->json(['link' => $this->image->url]);
+        return response()->json($this->image);
     }
 
 
index 8840a62d5ef768cce8530bf633cbf8a84344feee..be5d7c487f280eeaea5a96866e4b29575f42ad49 100644 (file)
@@ -31,6 +31,8 @@ Route::group(['prefix' => 'books'], function() {
 
 Route::post('/upload/image', 'ImageController@upload');
 
+Route::get('/images/all', 'ImageController@getAll');
+Route::get('/images/all/{page}', 'ImageController@getAll');
 Route::get('/images/{any}', 'ImageController@getImage')->where('any', '.*');
 
 Route::get('/', function () {
index 4600e5b1bcb2028258ccd38f328411f2a09b15a6..a51c18f75a5e101ea2cb3498d69288d321f06154 100644 (file)
@@ -6,5 +6,8 @@ use Illuminate\Database\Eloquent\Model;
 
 class Image extends Model
 {
-    //
+    public function getFilePath()
+    {
+        return storage_path() . $this->url;
+    }
 }
index 22d043de9e2f687b7fd11bd808de51bb2a4c9ee3..9f4eda5a983df0c94d454e605e13b24d7207a3b8 100644 (file)
@@ -25,4 +25,70 @@ header .menu {
   display: block;
   width: 100%;
   font-size: 1.4em;
+}
+
+.overlay {
+  background-color: rgba(0, 0, 0, 0.2);
+  position: fixed;
+  display: block;
+  z-index: 95536;
+  width: 100%;
+  height: 100%;
+  min-width: 100%;
+  min-height: 100%;
+  top: 0;
+  left: 0;
+  right: 0;
+  bottom: 0;
+}
+#image-manager {
+  background-color: #EEE;
+  max-width: 90%;
+  max-height: 90%;
+  width: 90%;
+  height: 90%;
+  margin: 2% 5%;
+  //border: 2px solid $primary;
+  border-radius: 4px;
+  box-shadow: 0 0 15px 0 rgba(0, 0, 0, 0.3);
+  overflow: hidden;
+  .image-manager-display img {
+    width: 150px;
+    height: 150px;
+    display: inline-block;
+    margin: $-s 0 0 $-s;
+    cursor: pointer;
+  }
+}
+.image-manager-left {
+  background-color: #FFF;
+  height: 100%;
+  width: 100%;
+  text-align: left;
+  .image-manager-display {
+    height: 75%;
+    width: 100%;
+    text-align: left;
+    overflow-y: scroll;
+  }
+}
+
+.image-manager-title {
+  font-size: 2em;
+  text-align: left;
+  margin: 0 $-m;
+  padding: $-xl $-m;
+  color: #666;
+  border-bottom: 1px solid #DDD;
+}
+
+.image-manager-dropzone {
+  background-color: lighten($primary, 40%);
+  height: 25%;
+  text-align: center;
+  font-size: 2em;
+  line-height: 2em;
+  padding-top: $-xl*1.2;
+  color: #666;
+  border-top: 2px solid $primary;
 }
\ No newline at end of file
index 832d3f8ad8ca12c34b3b7403167ce303cc83ba04..85502c2aabfeaae4538231f7148c53adb890d8cd 100644 (file)
@@ -1,9 +1,9 @@
 @extends('base')
 
 @section('head')
-    <link rel="stylesheet" href="/plugins/css/froala_editor.min.css">
-    <link rel="stylesheet" href="/plugins/css/froala_style.min.css">
-    <script src="/plugins/js/froala_editor.min.js"></script>
+    <script src="/bower/tinymce-dist/tinymce.jquery.min.js"></script>
+    <script src="/bower/dropzone/dist/min/dropzone.min.js"></script>
+    <script src="/js/image-manager.js"></script>
 @stop
 
 @section('content')
         @include('pages/form', ['model' => $page])
     </form>
 
+    <section class="overlay" style="display:none;">
+        <div id="image-manager">
+            <div class="image-manager-left">
+                <div class="image-manager-header">
+                    <button type="button" class="button neg float right" data-action="close">Close</button>
+                    <div class="image-manager-title">Image Library</div>
+                </div>
+                <div class="image-manager-display">
+                </div>
+                <form action="/upload/image" class="image-manager-dropzone">
+                    {{ csrf_field() }}
+                    Drag images or click here to upload
+                </form>
+            </div>
+            {{--<div class="sidebar">--}}
+
+            {{--</div>--}}
+        </div>
+    </section>
+
     <script>
         $(function() {
-            $('#html').editable({
-                inlineMode: false,
-                imageUploadURL: '/upload/image',
-                imageUploadParams: {
-                    '_token': '{{ csrf_token() }}'
+            //ImageManager.show('#image-manager');
+
+            tinymce.init({
+                selector: '.edit-area textarea',
+                content_css: '/css/app.css',
+                body_class: 'container',
+                plugins: "autoresize image table textcolor paste link imagetools",
+                content_style: "body {padding-left: 15px !important; padding-right: 15px !important;}",
+                file_browser_callback: function(field_name, url, type, win) {
+                    ImageManager.show('#image-manager', function(image) {
+                        win.document.getElementById(field_name).value = image.url;
+                        if ("createEvent" in document) {
+                            var evt = document.createEvent("HTMLEvents");
+                            evt.initEvent("change", false, true);
+                            win.document.getElementById(field_name).dispatchEvent(evt);
+                        } else {
+                            win.document.getElementById(field_name).fireEvent("onchange");
+                        }
+                    });
                 }
             });
+
+
+
         });
     </script>
 @stop
\ No newline at end of file