Skip to content

Commit

Permalink
v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ctf0 committed Sep 21, 2017
1 parent 7a08bf0 commit fe1779d
Show file tree
Hide file tree
Showing 28 changed files with 1,359 additions and 1,120 deletions.
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,15 @@

- events

| event-name | description |
|------------|-----------------------------------|
| modal-show | do something when modal is showen |
| modal-hide | do something when modal is hidden |
| event-name | description |
|--------------------|------------------------------|
| modal-show | when modal is showen |
| modal-hide | when modal is hidden |
| no-files-show | when no files msg is showen |
| no-files-hide | when no files msg is hidden |
| loading-files-show | when loading files is hidden |
| loading-files-hide | when loading files is hidden |
| ajax-error-show | when ajax call fails |

## Config
**config/mediaManager.php**
Expand Down Expand Up @@ -134,6 +139,11 @@ return [
* display file last modification time as
*/
'last_modified_format' => 'toDateString',

/**
* hide file extension in files list
*/
'hide_ext' => true
];
```

Expand All @@ -149,9 +159,9 @@ return [
- install dependencies

```bash
yarn add vue dropzone keycode vue-tippy vue2-filters vue-lightbox vuemit
yarn add vue dropzone keycode vue-tippy vue2-filters vuemit
# or
npm install vue dropzone keycode vue-tippy vue2-filters vue-lightbox vuemit
npm install vue dropzone keycode vue-tippy vue2-filters vuemit
```

- for styling we use ***bulma***
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"require": {
"php" : "~7.0",
"illuminate/support": "^5.4",
"tightenco/ziggy": "^0.4",
"ctf0/package-changelog": "^1.0"
},
"autoload": {
Expand Down
4 changes: 0 additions & 4 deletions logs/v1.2.3.txt

This file was deleted.

16 changes: 16 additions & 0 deletions logs/v1.3.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- remove ziggy
- remove vue-lightbox
- remove bs-modal
- add new option to config
- add events
- add new animation for ajax call fail
- add new key into lang for “ajax_error”
- optimize bm animation
- show folder content size instead of NaN
- auto-scroll to first item when adding new folder
- fix rename issue with folder vs file
- fix file size conversion
- update folder size on file move
- update assets
- update view
- update rdme
174 changes: 50 additions & 124 deletions src/Controllers/MediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
namespace ctf0\MediaManager\Controllers;

use Exception;
use Carbon\Carbon;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class MediaController extends Controller
{
use OpsTrait;

protected $fileSystem;
protected $storageDisk;
protected $ignoreFiles;
Expand Down Expand Up @@ -42,6 +43,45 @@ public function index()
return view("MediaManager::{$this->fw}.media");
}

/**
* [files description].
*
* @param Request $request [description]
*
* @return [type] [description]
*/
public function get_files(Request $request)
{
$folder = $request->folder !== '/'
? $request->folder
: '';

return response()->json([
'path' => $folder,
'items' => $this->getData($folder),
]);
}

/**
* [get_all_dirs description].
*
* @param Request $request [description]
*
* @return [type] [description]
*/
public function get_dirs(Request $request)
{
$folderLocation = $request->folder_location;

if (is_array($folderLocation)) {
$folderLocation = rtrim(implode('/', $folderLocation), '/');
}

return response()->json(
str_replace($folderLocation, '', $this->storageDisk->allDirectories($folderLocation))
);
}

/**
* [upload description].
*
Expand Down Expand Up @@ -95,27 +135,6 @@ public function upload(Request $request)
return response()->json(['data'=>$result]);
}

/**
* [files description].
*
* @param Request $request [description]
*
* @return [type] [description]
*/
public function files(Request $request)
{
$folder = $request->folder;

if ($folder == '/') {
$folder = '';
}

return response()->json([
'path' => $folder,
'items' => $this->getFiles($folder),
]);
}

/**
* [new_folder description].
*
Expand All @@ -139,17 +158,17 @@ public function new_folder(Request $request)
$message = trans('MediaManager::messages.error_creating_dir');
}

return compact('success', 'message', 'new_folder');
return compact('success', 'message', 'new_folder_name', 'full_path');
}

/**
* [delete_file_folder description].
* [delete_file description].
*
* @param Request $request [description]
*
* @return [type] [description]
*/
public function delete_file_folder(Request $request)
public function delete_file(Request $request)
{
$folderLocation = $request->folder_location;
$result = [];
Expand Down Expand Up @@ -188,26 +207,6 @@ public function delete_file_folder(Request $request)
return response()->json(['data'=>$result]);
}

/**
* [get_all_dirs description].
*
* @param Request $request [description]
*
* @return [type] [description]
*/
public function get_all_dirs(Request $request)
{
$folderLocation = $request->folder_location;

if (is_array($folderLocation)) {
$folderLocation = rtrim(implode('/', $folderLocation), '/');
}

return response()->json(
str_replace($folderLocation, '', $this->storageDisk->allDirectories($folderLocation))
);
}

/**
* [move_file description].
*
Expand All @@ -225,13 +224,15 @@ public function move_file(Request $request)
}

foreach ($request->moved_files as $one) {
$file_type =$one['type'];
$file_type = $one['type'];
$file_name = $one['name'];
$file_size = $one['size'];

$destination = "{$request->destination}/$file_name";
$file_name = "$folderLocation/$file_name";
$destination = strpos($destination, '../') == true
? '/' . dirname($folderLocation) . '/' . str_replace('../', '', $destination)
: "$folderLocation/$destination";
? '/' . dirname($folderLocation) . '/' . str_replace('../', '', $destination)
: "$folderLocation/$destination";

try {
if (!file_exists($destination)) {
Expand All @@ -240,6 +241,7 @@ public function move_file(Request $request)
'success' => true,
'name' => $one['name'],
'type' => $file_type,
'size' => $file_size,
];
} else {
throw new Exception(trans('MediaManager::messages.error_moving'));
Expand Down Expand Up @@ -289,80 +291,4 @@ public function rename_file(Request $request)

return compact('success', 'message', 'new_filename');
}

/**
* [getFiles description].
*
* @param [type] $dir [description]
*
* @return [type] [description]
*/
public function getFiles($dir)
{
$files = [];
$storageFiles = $this->storageDisk->files($dir);
$storageFolders = $this->storageDisk->directories($dir);

$pattern = $this->ignoreFiles;

foreach ($storageFolders as $folder) {
if (!preg_grep($pattern, [$folder])) {
$time = $this->storageDisk->lastModified($folder);
$files[] = [
'name' => strpos($folder, '/') > 1 ? str_replace('/', '', strrchr($folder, '/')) : $folder,
'type' => 'folder',
'path' => $this->storageDisk->url($folder),
'size' => '',
'items' => count($this->storageDisk->allFiles($folder)) + count($this->storageDisk->allDirectories($folder)),
'last_modified' => $time,
'last_modified_formated' => Carbon::createFromTimestamp($time)->{$this->LMF}(),
];
}
}

foreach ($storageFiles as $file) {
if (!preg_grep($pattern, [$file])) {
$time = $this->storageDisk->lastModified($file);
$files[] = [
'name' => strpos($file, '/') > 1 ? str_replace('/', '', strrchr($file, '/')) : $file,
'type' => $this->storageDisk->mimeType($file),
'path' => $this->storageDisk->url($file),
'size' => $this->storageDisk->size($file),
'last_modified' => $time,
'last_modified_formated' => Carbon::createFromTimestamp($time)->{$this->LMF}(),
];
}
}

return $files;
}

/**
* sanitize input.
*
* @param [type] $text [description]
* @param null|mixed $folder
*
* @return [type] [description]
*/
protected function cleanName($text, $folder = null)
{
$pattern = [
'/(script.*?\/script)|[^(' . $this->fileChars . ')a-zA-Z0-9]+/ius',
];

if ($folder) {
$pattern = [
'/(script.*?\/script)|[^(' . $this->folderChars . ')a-zA-Z0-9]+/ius',
];
}

$text = preg_replace($pattern, '', $text);

if ($text == '') {
$text = $this->sanitizedText;
}

return $text;
}
}
Loading

0 comments on commit fe1779d

Please sign in to comment.