-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Adrián Pardellas Blunier
committed
May 4, 2016
1 parent
c7bcd37
commit 94c1f87
Showing
8 changed files
with
158 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.img-preview { | ||
cursor: pointer; | ||
} | ||
|
||
.img-preview img { | ||
width: 200px; | ||
height: 200px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,97 @@ | ||
<?php | ||
namespace Anavel\Foundation\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
|
||
class DefaultController extends Controller | ||
{ | ||
public function index() | ||
{ | ||
return view(config('anavel.dashboard_view')); | ||
} | ||
|
||
public function ckeditorFileUploader() | ||
/** | ||
* 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; | ||
} else if (! 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]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@extends('anavel::layouts.master') | ||
|
||
@section('header')@stop | ||
|
||
@section('sidebar')@stop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
@extends('anavel::layouts.simple') | ||
|
||
@section('body-classes') | ||
sidebar-collapse | ||
@stop | ||
|
||
@section('content') | ||
<div class="box box-default"> | ||
<div class="box-header"> | ||
<h3><i class="fa fa-file"></i>{{ trans('anavel::messages.file_browser_title') }}</h3> | ||
</div> | ||
<div class="box-body"> | ||
<div class="row"> | ||
@foreach ($files as $file) | ||
<div class="col-sm-4 col-md-2 img-preview" data-url="{{ $file['url'] }}" onclick="returnFileUrl(this)"> | ||
<img src="{{ $file['url'] }}" alt=""> | ||
</div> | ||
@endforeach | ||
</div> | ||
</div> | ||
</div> | ||
@stop | ||
|
||
@section('footer-scripts') | ||
@parent | ||
|
||
<script> | ||
// Helper function to get parameters from the query string. | ||
function getUrlParam( paramName ) { | ||
var reParam = new RegExp( '(?:[\?&]|&)' + paramName + '=([^&]+)', 'i' ); | ||
var match = window.location.search.match( reParam ); | ||
return ( match && match.length > 1 ) ? match[1] : null; | ||
} | ||
// Simulate user action of selecting a file to be returned to CKEditor. | ||
function returnFileUrl(element) { | ||
var funcNum = getUrlParam( 'CKEditorFuncNum' ); | ||
var fileUrl = $(element).data('url'); | ||
window.opener.CKEDITOR.tools.callFunction( funcNum, fileUrl ); | ||
window.close(); | ||
} | ||
</script> | ||
@stop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
</head> | ||
<body> | ||
<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction({{ $funcNum }}, '{{ $url }}', '{{ $message }}');</script> | ||
</body> | ||
</html> |