Skip to content

Commit

Permalink
removed ckeditor upload function. anavel/uploads module responsibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrián Pardellas Blunier committed Sep 15, 2016
1 parent b306242 commit bc51655
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 156 deletions.
8 changes: 0 additions & 8 deletions config/anavel.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,6 @@

],

/*
|--------------------------------------------------------------------------
| CKeditor uploads path
|--------------------------------------------------------------------------
|
*/
'ckeditor_uploads_path' => 'uploads/ckeditor',

/*
|--------------------------------------------------------------------------
| Modules
Expand Down
6 changes: 3 additions & 3 deletions public/dist/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
}

.img-preview img {
width: 200px;
height: 200px;
}
width: 133px;
height: 133px;
}
11 changes: 7 additions & 4 deletions public/plugins/ckeditor/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ CKEDITOR.editorConfig = function( config ) {
{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
{ name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ] },
{ name: 'styles' },
{ name: 'colors' },
{ name: 'about' }
{ name: 'colors' }
];

// Remove some buttons provided by the standard plugins, which are
Expand All @@ -36,6 +35,10 @@ CKEDITOR.editorConfig = function( config ) {
// Simplify the dialog windows.
config.removeDialogTabs = 'image:advanced;link:advanced';

config.filebrowserBrowseUrl = $('body').data('ckeditor-file-browser-url');
config.filebrowserUploadUrl = $('body').data('ckeditor-file-uploader-url');
var customConfig = $('body').data('ckeditor');

config.removePlugins = customConfig.removePlugins;

config.filebrowserBrowseUrl = customConfig.fileBrowserUrl;
config.filebrowserUploadUrl = customConfig.fileUploaderUrl;
};
2 changes: 2 additions & 0 deletions src/Contracts/Anavel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ public function register($provider);
public function modules();

public function activeModule();

public function hasModule($moduleProvider);
}
13 changes: 13 additions & 0 deletions src/Core/Anavel.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,17 @@ public function activeModule()

return null;
}

public function hasModule($moduleProvider)
{
$hasModule = false;

foreach ($this->moduleProviders as $module) {
if ($module instanceof $moduleProvider) {
$hasModule = true;
}
}

return $hasModule;
}
}
85 changes: 0 additions & 85 deletions src/Http/Controllers/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,89 +9,4 @@ public function index()
{
return view(config('anavel.dashboard_view'));
}

/**
* Store the files uploaded by ckeditor
*
* @param Request $request
* @return Response
*/
public function ckeditorFileUploader(Request $request)
{
$url = '';
$message = '';

if ($request->hasFile('upload')) {
$fileName = uniqid() . '-' . $request->file('upload')->getClientOriginalName();

$request->file('upload')->move(
base_path(DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . config('anavel.ckeditor_uploads_path')),
$fileName
);

$url = url(config('anavel.ckeditor_uploads_path')) . DIRECTORY_SEPARATOR . $fileName;
} elseif (! empty($request->file('upload')) && ! $request->file('upload')->isValid()) {
$message = $request->file('upload')->getErrorMessage();
}

return view('anavel::pages.ckeditor.uploader', [
'funcNum' => $request->get('CKEditorFuncNum'),
'url' => $url,
'message' => $message
]);
}

public function ckeditorFileBrowser()
{
$base = public_path(config('anavel.ckeditor_uploads_path'));

if (!is_dir($base) && ! @mkdir($base, 0700, true)) {
throw new Exception(__('Folder %s not exists and can not be created', config('anavel.ckeditor_uploads_path')));
}

if (!is_dir($base)) {
throw new Exception(__('Folder %s not exists', config('anavel.ckeditor_uploads_path')));
} elseif (!is_writable($base)) {
throw new Exception(__('Folder %s has not write permissions', config('anavel.ckeditor_uploads_path')));
}

$dir = null;

list($files, $directories) = $this->getFilesDirectories($base, $dir, config('anavel.ckeditor_uploads_path'));

return view('anavel::pages.ckeditor.browser', [
'directories' => $directories,
'files' => $files
]);
}

private function getFilesDirectories($base, $dir, $public)
{
if (substr($base, -1) !== DIRECTORY_SEPARATOR) {
$base = $base.DIRECTORY_SEPARATOR;
}

if (substr($public, -1) !== DIRECTORY_SEPARATOR) {
$public = $public.DIRECTORY_SEPARATOR;
}

$directories = $files = [];
foreach (glob($base.'*', GLOB_MARK) as $each) {
$each = str_replace($base, '', $each);
if (substr($each, -1) === '/') {
$directories[] = [
'dir' => base64_encode($dir.$each),
'slug' => base64_encode($each),
'name' => $each,
];
} else {
$files[] = [
'slug' => base64_encode($each),
'url' => asset($public.$each),
'name' => $each,
];
}
}
return [$files, $directories];
}
}
3 changes: 0 additions & 3 deletions src/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,5 @@ function () {
return redirect()->route(config('anavel.profile_edit_route'), [config('anavel.profile_model_slug'), $id]);
}
]);

Route::post('/ckeditor/file/uploader', ['as' => 'anavel.ckeditor.file-uploader', 'uses' => 'DefaultController@ckeditorFileUploader']);
Route::get('/ckeditor/file/browser', ['as' => 'anavel.ckeditor.file-browser', 'uses' => 'DefaultController@ckeditorFileBrowser']);
}
);
1 change: 1 addition & 0 deletions src/Providers/ViewComposersServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function boot()
*/
public function register()
{
$this->app->view->composer('anavel::layouts.master', 'Anavel\Foundation\View\Composers\MasterLayoutComposer');
$this->app->view->composer('anavel::molecules.header.default', 'Anavel\Foundation\View\Composers\HeaderComposer');
$this->app->view->composer('anavel::molecules.sidebar.default', 'Anavel\Foundation\View\Composers\SidebarComposer');
}
Expand Down
35 changes: 35 additions & 0 deletions src/View/Composers/MasterLayoutComposer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace Anavel\Foundation\View\Composers;

use Anavel\Foundation\Contracts\Anavel;

class MasterLayoutComposer
{
protected $anavel;

public function __construct(Anavel $anavel)
{
$this->anavel = $anavel;
}

public function compose($view)
{
$uploadsModuleIsInstalled = $this->anavel->hasModule('Anavel\Uploads\UploadsModuleProvider');

$ckEditorData = [
'removePlugins' => 'image',
'fileBrowserUrl' => '',
'fileUploaderUrl' => '',
];

if ($uploadsModuleIsInstalled) {
$ckEditorData['removePlugins'] = '';
$ckEditorData['fileBrowserUrl'] = route('anavel-uploads.ckeditor.file-browser');
$ckEditorData['fileUploaderUrl'] = route('anavel-uploads.ckeditor.file-uploader', ['_token' => csrf_token()]);
}

$view->with([
'ckEditorData' => json_encode($ckEditorData)
]);
}
}
2 changes: 1 addition & 1 deletion views/layouts/master.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</head>

@section('body')
<body class="{{ config('anavel.layout_options') }} {{ config('anavel.skin') }} @section('body-classes')@show" data-ckeditor-file-browser-url="{{ route('anavel.ckeditor.file-browser') }}" data-ckeditor-file-uploader-url="{{ route('anavel.ckeditor.file-uploader', ['_token' => csrf_token()]) }}">
<body class="{{ config('anavel.layout_options') }} {{ config('anavel.skin') }} @section('body-classes')@show" data-ckeditor="{{ $ckEditorData }}">
<div class="wrapper">
@section('header')
@include('anavel::molecules.header.default')
Expand Down
43 changes: 0 additions & 43 deletions views/pages/ckeditor/browser.blade.php

This file was deleted.

9 changes: 0 additions & 9 deletions views/pages/ckeditor/uploader.blade.php

This file was deleted.

0 comments on commit bc51655

Please sign in to comment.