updated-packages

This commit is contained in:
RafficMohammed
2023-01-08 00:13:22 +05:30
parent 3ff7df7487
commit da241bacb6
12659 changed files with 563377 additions and 510538 deletions

View File

@@ -0,0 +1,12 @@
<?php
namespace UniSharp\LaravelFilemanager\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
abstract class Controller extends BaseController
{
use DispatchesJobs, ValidatesRequests;
}

View File

@@ -0,0 +1,69 @@
<?php
namespace UniSharp\LaravelFilemanager\Controllers;
use Intervention\Image\Facades\Image;
use UniSharp\LaravelFilemanager\Events\ImageIsCropping;
use UniSharp\LaravelFilemanager\Events\ImageWasCropped;
/**
* Class CropController.
*/
class CropController extends LfmController
{
/**
* Show crop page.
*
* @return mixed
*/
public function getCrop()
{
$working_dir = request('working_dir');
$img = parent::objectPresenter(parent::getCurrentPath(request('img')));
return view('laravel-filemanager::crop')
->with(compact('working_dir', 'img'));
}
/**
* Crop the image (called via ajax).
*/
public function getCropimage($overWrite = true)
{
$dataX = request('dataX');
$dataY = request('dataY');
$dataHeight = request('dataHeight');
$dataWidth = request('dataWidth');
$image_path = parent::getCurrentPath(request('img'));
$crop_path = $image_path;
if (! $overWrite) {
$fileParts = explode('.', request('img'));
$fileParts[count($fileParts) - 2] = $fileParts[count($fileParts) - 2] . '_cropped_' . time();
$crop_path = parent::getCurrentPath(implode('.', $fileParts));
}
event(new ImageIsCropping($image_path));
// crop image
Image::make($image_path)
->crop($dataWidth, $dataHeight, $dataX, $dataY)
->save($crop_path);
if (config('lfm.should_create_thumbnails', true)) {
// create thumb folder
parent::createFolderByPath(parent::getThumbPath());
// make new thumbnail
Image::make($crop_path)
->fit(config('lfm.thumb_img_width', 200), config('lfm.thumb_img_height', 200))
->save(parent::getThumbPath(parent::getName($crop_path)));
}
event(new ImageWasCropped($image_path));
}
public function getNewCropimage()
{
$this->getCropimage(false);
}
}

View File

@@ -0,0 +1,56 @@
<?php
namespace UniSharp\LaravelFilemanager\Controllers;
use Illuminate\Support\Facades\File;
use UniSharp\LaravelFilemanager\Events\ImageIsDeleting;
use UniSharp\LaravelFilemanager\Events\ImageWasDeleted;
/**
* Class CropController.
*/
class DeleteController extends LfmController
{
/**
* Delete image and associated thumbnail.
*
* @return mixed
*/
public function getDelete()
{
$name_to_delete = request('items');
$file_to_delete = parent::getCurrentPath($name_to_delete);
$thumb_to_delete = parent::getThumbPath($name_to_delete);
event(new ImageIsDeleting($file_to_delete));
if (is_null($name_to_delete)) {
return parent::error('folder-name');
}
if (! File::exists($file_to_delete)) {
return parent::error('folder-not-found', ['folder' => $file_to_delete]);
}
if (File::isDirectory($file_to_delete)) {
if (! parent::directoryIsEmpty($file_to_delete)) {
return parent::error('delete-folder');
}
File::deleteDirectory($file_to_delete);
return parent::$success_response;
}
if (parent::fileIsImage($file_to_delete)) {
File::delete($thumb_to_delete);
}
File::delete($file_to_delete);
event(new ImageWasDeleted($file_to_delete));
return parent::$success_response;
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace UniSharp\LaravelFilemanager\Controllers;
/**
* Class DownloadController.
*/
class DownloadController extends LfmController
{
/**
* Download a file.
*
* @return mixed
*/
public function getDownload()
{
return response()->download(parent::getCurrentPath(request('file')));
}
}

View File

@@ -0,0 +1,75 @@
<?php
namespace UniSharp\LaravelFilemanager\Controllers;
use Illuminate\Support\Facades\File;
/**
* Class FolderController.
*/
class FolderController extends LfmController
{
/**
* Get list of folders as json to populate treeview.
*
* @return mixed
*/
public function getFolders()
{
$folder_types = [];
$root_folders = [];
if (parent::allowMultiUser()) {
$folder_types['user'] = 'root';
}
if (parent::allowShareFolder()) {
$folder_types['share'] = 'shares';
}
foreach ($folder_types as $folder_type => $lang_key) {
$root_folder_path = parent::getRootFolderPath($folder_type);
$children = parent::getDirectories($root_folder_path);
usort($children, function ($a, $b) {
return strcmp($a->name, $b->name);
});
array_push($root_folders, (object) [
'name' => trans('laravel-filemanager::lfm.title-' . $lang_key),
'path' => parent::getInternalPath($root_folder_path),
'children' => $children,
'has_next' => ! ($lang_key == end($folder_types)),
]);
}
return view('laravel-filemanager::tree')
->with(compact('root_folders'));
}
/**
* Add a new folder.
*
* @return mixed
*/
public function getAddfolder()
{
$folder_name = parent::translateFromUtf8(trim(request('name')));
$path = parent::getCurrentPath($folder_name);
if (empty($folder_name)) {
return parent::error('folder-name');
}
if (File::exists($path)) {
return parent::error('folder-exist');
}
if (config('lfm.alphanumeric_directory') && preg_match('/[^\w-]/i', $folder_name)) {
return parent::error('folder-alnum');
}
parent::createFolderByPath($path);
return parent::$success_response;
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace UniSharp\LaravelFilemanager\Controllers;
/**
* Class ItemsController.
*/
class ItemsController extends LfmController
{
/**
* Get the images to load for a selected folder.
*
* @return mixed
*/
public function getItems()
{
$path = parent::getCurrentPath();
$sort_type = request('sort_type');
$files = parent::sortFilesAndDirectories(parent::getFilesWithInfo($path), $sort_type);
$directories = parent::sortFilesAndDirectories(parent::getDirectories($path), $sort_type);
return [
'html' => (string) view($this->getView())->with([
'files' => $files,
'directories' => $directories,
'items' => array_merge($directories, $files),
]),
'working_dir' => parent::getInternalPath($path),
];
}
private function getView()
{
$view_type = request('show_list');
if (null === $view_type) {
return $this->composeViewName($this->getStartupViewFromConfig());
}
$view_mapping = [
'0' => 'grid',
'1' => 'list'
];
return $this->composeViewName($view_mapping[$view_type]);
}
private function composeViewName($view_type = 'grid')
{
return "laravel-filemanager::$view_type-view";
}
private function getStartupViewFromConfig($default = 'grid')
{
$type_key = parent::currentLfmType();
$startup_view = config('lfm.' . $type_key . 's_startup_view', $default);
return $startup_view;
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace UniSharp\LaravelFilemanager\Controllers;
use UniSharp\LaravelFilemanager\Traits\LfmHelpers;
/**
* Class LfmController.
*/
class LfmController extends Controller
{
use LfmHelpers;
protected static $success_response = 'OK';
public function __construct()
{
$this->applyIniOverrides();
}
/**
* Show the filemanager.
*
* @return mixed
*/
public function show()
{
return view('laravel-filemanager::index');
}
public function getErrors()
{
$arr_errors = [];
if (! extension_loaded('gd') && ! extension_loaded('imagick')) {
array_push($arr_errors, trans('laravel-filemanager::lfm.message-extension_not_found'));
}
$type_key = $this->currentLfmType();
$mine_config = 'lfm.valid_' . $type_key . '_mimetypes';
$config_error = null;
if (! is_array(config($mine_config))) {
array_push($arr_errors, 'Config : ' . $mine_config . ' is not a valid array.');
}
return $arr_errors;
}
}

View File

@@ -0,0 +1,88 @@
<?php
namespace UniSharp\LaravelFilemanager\Controllers;
use Illuminate\Support\Facades\File;
use UniSharp\LaravelFilemanager\Events\ImageIsRenaming;
use UniSharp\LaravelFilemanager\Events\ImageWasRenamed;
use UniSharp\LaravelFilemanager\Events\FolderIsRenaming;
use UniSharp\LaravelFilemanager\Events\FolderWasRenamed;
/**
* Class RenameController.
*/
class RenameController extends LfmController
{
/**
* @return string
*/
public function getRename()
{
$old_name = parent::translateFromUtf8(request('file'));
$new_name = parent::translateFromUtf8(trim(request('new_name')));
$old_file = parent::getCurrentPath($old_name);
if (File::isDirectory($old_file)) {
return $this->renameDirectory($old_name, $new_name);
} else {
return $this->renameFile($old_name, $new_name);
}
}
protected function renameDirectory($old_name, $new_name)
{
if (empty($new_name)) {
return parent::error('folder-name');
}
$old_file = parent::getCurrentPath($old_name);
$new_file = parent::getCurrentPath($new_name);
event(new FolderIsRenaming($old_file, $new_file));
if (config('lfm.alphanumeric_directory') && preg_match('/[^\w-]/i', $new_name)) {
return parent::error('folder-alnum');
}
if (File::exists($new_file)) {
return parent::error('rename');
}
File::move($old_file, $new_file);
event(new FolderWasRenamed($old_file, $new_file));
return parent::$success_response;
}
protected function renameFile($old_name, $new_name)
{
if (empty($new_name)) {
return parent::error('file-name');
}
$old_file = parent::getCurrentPath($old_name);
$extension = File::extension($old_file);
$new_file = parent::getCurrentPath(basename($new_name, ".$extension") . ".$extension");
if (config('lfm.alphanumeric_filename') && preg_match('/[^\w-.]/i', $new_name)) {
return parent::error('file-alnum');
}
// TODO Should be "FileIsRenaming"
event(new ImageIsRenaming($old_file, $new_file));
if (File::exists($new_file)) {
return parent::error('rename');
}
if (parent::fileIsImage($old_file) && File::exists(parent::getThumbPath($old_name))) {
File::move(parent::getThumbPath($old_name), parent::getThumbPath($new_name));
}
File::move($old_file, $new_file);
// TODO Should be "FileWasRenamed"
event(new ImageWasRenamed($old_file, $new_file));
return parent::$success_response;
}
}

View File

@@ -0,0 +1,72 @@
<?php
namespace UniSharp\LaravelFilemanager\Controllers;
use Intervention\Image\Facades\Image;
use UniSharp\LaravelFilemanager\Events\ImageIsResizing;
use UniSharp\LaravelFilemanager\Events\ImageWasResized;
/**
* Class ResizeController.
*/
class ResizeController extends LfmController
{
/**
* Dipsplay image for resizing.
*
* @return mixed
*/
public function getResize()
{
$ratio = 1.0;
$image = request('img');
$original_image = Image::make(parent::getCurrentPath($image));
$original_width = $original_image->width();
$original_height = $original_image->height();
$scaled = false;
// FIXME size should be configurable
if ($original_width > 600) {
$ratio = 600 / $original_width;
$width = $original_width * $ratio;
$height = $original_height * $ratio;
$scaled = true;
} else {
$width = $original_width;
$height = $original_height;
}
if ($height > 400) {
$ratio = 400 / $original_height;
$width = $original_width * $ratio;
$height = $original_height * $ratio;
$scaled = true;
}
return view('laravel-filemanager::resize')
->with('img', parent::objectPresenter(parent::getCurrentPath($image)))
->with('height', number_format($height, 0))
->with('width', $width)
->with('original_height', $original_height)
->with('original_width', $original_width)
->with('scaled', $scaled)
->with('ratio', $ratio);
}
public function performResize()
{
$dataX = request('dataX');
$dataY = request('dataY');
$height = request('dataHeight');
$width = request('dataWidth');
$image_path = parent::getCurrentPath(request('img'));
event(new ImageIsResizing($image_path));
Image::make($image_path)->resize($width, $height)->save();
event(new ImageWasResized($image_path));
return parent::$success_response;
}
}

View File

@@ -0,0 +1,236 @@
<?php
namespace UniSharp\LaravelFilemanager\Controllers;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Log;
use Intervention\Image\Facades\Image;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use UniSharp\LaravelFilemanager\Events\ImageIsUploading;
use UniSharp\LaravelFilemanager\Events\ImageWasUploaded;
/**
* Class UploadController.
*/
class UploadController extends LfmController
{
protected $errors;
public function __construct()
{
parent::__construct();
$this->errors = [];
}
/**
* Upload files
*
* @param void
* @return string
*/
public function upload()
{
$files = request()->file('upload');
// single file
if (!is_array($files)) {
$file = $files;
if (!$this->fileIsValid($file)) {
return $this->errors;
}
$filename = $this->proceedSingleUpload($file);
if ($filename === false) {
return $this->errors;
}
// upload via ckeditor 'Upload' tab
return $this->useFile($filename);
}
// Multiple files
foreach ($files as $file) {
if (!$this->fileIsValid($file)) {
continue;
}
$this->proceedSingleUpload($file);
}
return count($this->errors) > 0 ? $this->errors : parent::$success_response;
}
private function proceedSingleUpload($file)
{
$new_filename = $this->getNewName($file);
$new_file_path = parent::getCurrentPath($new_filename);
event(new ImageIsUploading($new_file_path));
try {
if (parent::fileIsImage($file) && !in_array($file->getMimeType(), ['image/gif', 'image/svg+xml'])) {
// Handle image rotation
Image::make($file->getRealPath())
->orientate() //Apply orientation from exif data
->save($new_file_path);
// Generate a thumbnail
if (parent::imageShouldHaveThumb($file)) {
$this->makeThumb($new_filename);
}
} else {
// Create (move) the file
File::move($file->getRealPath(), $new_file_path);
}
if (config('lfm.should_change_file_mode', true)) {
chmod($new_file_path, config('lfm.create_file_mode', 0644));
}
} catch (\Exception $e) {
array_push($this->errors, parent::error('invalid'));
Log::error($e->getMessage(), [
'file' => $e->getFile(),
'line' => $e->getLine(),
'trace' => $e->getTraceAsString()
]);
return false;
}
// TODO should be "FileWasUploaded"
event(new ImageWasUploaded(realpath($new_file_path)));
return $new_filename;
}
private function fileIsValid($file)
{
if (empty($file)) {
array_push($this->errors, parent::error('file-empty'));
return false;
}
if (! $file instanceof UploadedFile) {
array_push($this->errors, parent::error('instance'));
return false;
}
if ($file->getError() == UPLOAD_ERR_INI_SIZE) {
$max_size = ini_get('upload_max_filesize');
array_push($this->errors, parent::error('file-size', ['max' => $max_size]));
return false;
}
if ($file->getError() != UPLOAD_ERR_OK) {
$msg = 'File failed to upload. Error code: ' . $file->getError();
array_push($this->errors, $msg);
return false;
}
$new_filename = $this->getNewName($file);
if (File::exists(parent::getCurrentPath($new_filename))) {
array_push($this->errors, parent::error('file-exist'));
return false;
}
$mimetype = $file->getMimeType();
// Bytes to KB
$file_size = $file->getSize() / 1024;
$type_key = parent::currentLfmType();
if (config('lfm.should_validate_mime', false)) {
$mine_config = 'lfm.valid_' . $type_key . '_mimetypes';
$valid_mimetypes = config($mine_config, []);
if (false === in_array($mimetype, $valid_mimetypes)) {
array_push($this->errors, parent::error('mime') . $mimetype);
return false;
}
}
if (config('lfm.should_validate_size', false)) {
$max_size = config('lfm.max_' . $type_key . '_size', 0);
if ($file_size > $max_size) {
array_push($this->errors, parent::error('size'));
return false;
}
}
return true;
}
protected function replaceInsecureSuffix($name)
{
return preg_replace("/\.php$/i", '', $name);
}
private function getNewName($file)
{
$new_filename = parent::translateFromUtf8(trim($this->pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME)));
if (config('lfm.rename_file') === true) {
$new_filename = uniqid();
} elseif (config('lfm.alphanumeric_filename') === true) {
$new_filename = preg_replace('/[^A-Za-z0-9\-\']/', '_', $new_filename);
}
return $new_filename . $this->replaceInsecureSuffix('.' . $file->getClientOriginalExtension());
}
private function makeThumb($new_filename)
{
// create thumb folder
parent::createFolderByPath(parent::getThumbPath());
// create thumb image
Image::make(parent::getCurrentPath($new_filename))
->fit(config('lfm.thumb_img_width', 200), config('lfm.thumb_img_height', 200))
->save(parent::getThumbPath($new_filename));
}
private function useFile($new_filename)
{
$file = parent::getFileUrl($new_filename);
$responseType = request()->input('responseType');
if ($responseType && $responseType == 'json') {
return [
"uploaded" => 1,
"fileName" => $new_filename,
"url" => $file,
];
}
return "<script type='text/javascript'>
function getUrlParam(paramName) {
var reParam = new RegExp('(?:[\?&]|&)' + paramName + '=([^&]+)', 'i');
var match = window.location.search.match(reParam);
return ( match && match.length > 1 ) ? match[1] : null;
}
var funcNum = getUrlParam('CKEditorFuncNum');
var par = window.parent,
op = window.opener,
o = (par && par.CKEDITOR) ? par : ((op && op.CKEDITOR) ? op : false);
if (op) window.close();
if (o !== false) o.CKEDITOR.tools.callFunction(funcNum, '$file');
</script>";
}
private function pathinfo($path, $options = null)
{
$path = urlencode($path);
$parts = is_null($options) ? pathinfo($path) : pathinfo($path, $options);
if (is_array($parts)) {
foreach ($parts as $field => $value) {
$parts[$field] = urldecode($value);
}
} else {
$parts = urldecode($parts);
}
return $parts;
}
}