Skip to content

Commit

Permalink
add new option for last_modified time
Browse files Browse the repository at this point in the history
...
  • Loading branch information
ctf0 committed Sep 17, 2017
1 parent cd45162 commit 1a7a54b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ return [
* css farmework
*/
'framework' => env('MIX_MM_FRAMEWORK'),

/*
* display file last modification time as
*/
'last_modified_format' => 'toDateString',
];
```

Expand Down Expand Up @@ -171,4 +176,3 @@ new Vue({

* Add Support To Other Css Frameworks.
* Add Support For Editors usage "tinymce / Ckeditor/ etc..".
* Fix `sortBy:size` To Work Properly With (kb vs Mb).
43 changes: 22 additions & 21 deletions src/Controllers/MediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,33 @@

namespace ctf0\MediaManager\Controllers;

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

class MediaController extends Controller
{
private $fileSystem;
private $storageDisk;
private $ignoreFiles;
private $fileChars;
private $folderChars;
private $sanitizedText;
private $unallowed_mimes;
private $fw;
protected $fileSystem;
protected $storageDisk;
protected $ignoreFiles;
protected $fileChars;
protected $folderChars;
protected $sanitizedText;
protected $unallowed_mimes;
protected $LMF;
protected $fw;

public function __construct()
{
$this->fileSystem = config('mediaManager.storage_disk');
$this->storageDisk = Storage::disk($this->fileSystem);
$this->storageDisk = app('filesystem')->disk($this->fileSystem);
$this->ignoreFiles = config('mediaManager.ignore_files');
$this->fileChars = config('mediaManager.allowed_fileNames_chars');
$this->folderChars = config('mediaManager.allowed_folderNames_chars');
$this->sanitizedText = config('mediaManager.sanitized_text');
$this->unallowed_mimes = config('mediaManager.unallowed_mimes');
$this->LMF = config('mediaManager.last_modified_format');
$this->fw = config('mediaManager.framework');
}

Expand Down Expand Up @@ -71,8 +72,8 @@ public function upload(Request $request)

// check name
// because dropzone automatically sanitize the file name
if ($file_name == '.'.$one->getClientOriginalExtension()) {
$file_name = $this->sanitizedText.$file_name;
if ($file_name == '.' . $one->getClientOriginalExtension()) {
$file_name = $this->sanitizedText . $file_name;
}

$path = $one->storeAs($upload_path, $this->cleanName($file_name), $this->fileSystem);
Expand All @@ -86,7 +87,7 @@ public function upload(Request $request)
$result[] = [
'path' => '',
'success' => false,
'message' => "\"$file_name\" ".$e->getMessage(),
'message' => "\"$file_name\" " . $e->getMessage(),
];
}
}
Expand Down Expand Up @@ -229,7 +230,7 @@ public function move_file(Request $request)
$destination = "{$request->destination}/$file_name";
$file_name = "$folderLocation/$file_name";
$destination = strpos($destination, '../') == true
? '/'.dirname($folderLocation).'/'.str_replace('../', '', $destination)
? '/' . dirname($folderLocation) . '/' . str_replace('../', '', $destination)
: "$folderLocation/$destination";

try {
Expand All @@ -249,7 +250,7 @@ public function move_file(Request $request)
} catch (Exception $e) {
$result[] = [
'success' => false,
'message' => "\"$file_name\" ".$e->getMessage(),
'message' => "\"$file_name\" " . $e->getMessage(),
];
}
}
Expand Down Expand Up @@ -312,7 +313,7 @@ public function getFiles($dir)
'path' => $this->storageDisk->url($folder),
'size' => '',
'items' => count($this->storageDisk->allFiles($folder)) + count($this->storageDisk->allDirectories($folder)),
'last_modified' => Carbon::createFromTimestamp($this->storageDisk->lastModified($folder))->toDateString(),
'last_modified' => Carbon::createFromTimestamp($this->storageDisk->lastModified($folder))->{$this->LMF}(),
];
}
}
Expand All @@ -324,7 +325,7 @@ public function getFiles($dir)
'type' => $this->storageDisk->mimeType($file),
'path' => $this->storageDisk->url($file),
'size' => $this->storageDisk->size($file),
'last_modified' => Carbon::createFromTimestamp($this->storageDisk->lastModified($file))->toDateString(),
'last_modified' => Carbon::createFromTimestamp($this->storageDisk->lastModified($file))->{$this->LMF}(),
];
}
}
Expand All @@ -343,12 +344,12 @@ public function getFiles($dir)
protected function cleanName($text, $folder = null)
{
$pattern = [
'/(script.*?\/script)|[^('.$this->fileChars.')a-zA-Z0-9]+/ius',
'/(script.*?\/script)|[^(' . $this->fileChars . ')a-zA-Z0-9]+/ius',
];

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

Expand Down
9 changes: 9 additions & 0 deletions src/config/mediaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
return [
/*
* ignore files pattern
*
* ignore any file starts with "."
*/
'ignore_files' => '/^\..*/',

Expand Down Expand Up @@ -40,4 +42,11 @@
* MIX_MM_FRAMEWORK=bulma
*/
'framework' => env('MIX_MM_FRAMEWORK'),

/*
* display file last modification time as
*
* check "/vendor/nesbot/carbon/src/Carbon/Carbon.php"
*/
'last_modified_format' => 'toDateString',
];

0 comments on commit 1a7a54b

Please sign in to comment.