From 415016a4c2382faa209bdfd8bd50d82ff7e6769b Mon Sep 17 00:00:00 2001 From: Arno Kaimbacher Date: Tue, 2 Apr 2019 18:03:29 +0200 Subject: [PATCH] allowed mimetypes from database --- .../Controllers/Publish/IndexController.php | 4 +- .../Settings/MimetypeController.php | 60 ++++++---- app/Models/MimeType.php | 16 +++ app/Rules/RdrFiletypes.php | 31 ++---- composer.lock | 29 +++-- config/enums.php | 105 +----------------- public/datasetxml2oai-pmh.xslt | 12 +- .../views/settings/filetype/index.blade.php | 67 ++++++----- routes/web.php | 6 + 9 files changed, 128 insertions(+), 202 deletions(-) create mode 100644 app/Models/MimeType.php diff --git a/app/Http/Controllers/Publish/IndexController.php b/app/Http/Controllers/Publish/IndexController.php index 6308647..3d4cf5f 100644 --- a/app/Http/Controllers/Publish/IndexController.php +++ b/app/Http/Controllers/Publish/IndexController.php @@ -431,8 +431,8 @@ class IndexController extends Controller $user = Auth::user(); $dataset->user()->associate($user)->save(); - // $error = 'Always throw this error'; - // throw new \Exception($error); + $error = 'Always throw this error'; + throw new \Exception($error); // all good//commit everything DB::commit(); diff --git a/app/Http/Controllers/Settings/MimetypeController.php b/app/Http/Controllers/Settings/MimetypeController.php index e6e0ae2..cc86401 100644 --- a/app/Http/Controllers/Settings/MimetypeController.php +++ b/app/Http/Controllers/Settings/MimetypeController.php @@ -1,21 +1,15 @@ report->find($id); - // $file = File::findOrFail($id); - // $file_path = public_path('storage/' . $file->path_name); - // return response()->download($file_path, $file->label, ['Content-Type:' . $file->mime_type]); - // } public function __construct() { $this->middleware('auth'); @@ -23,15 +17,15 @@ class MimetypeController extends Controller public function index(): View { - //$direction = 'asc'; // or desc - $mimetypes = Config::get('enums.mime_types'); - //$checkeds = $document->licenses->pluck('id')->toArray(); - $checkeds = Config::get('enums.mimetypes_allowed'); + // $mimetypes = Config::get('enums.mime_types'); + // $checkeds = Config::get('enums.mimetypes_allowed'); + $direction = 'asc'; // or desc + $mimetypes = MimeType::orderBy('name', $direction)->get(); return view('settings.filetype.index', [ - 'options' => $mimetypes, - 'checkeds' => $checkeds - ]); + 'mimetypes' => $mimetypes, + // 'checkeds' => $checkeds + ]); } public function update(Request $request) @@ -40,11 +34,37 @@ class MimetypeController extends Controller Config::set('enums.mimetypes_allowed', $mimetypes); return redirect()->back()->with('success', 'Mimetypes are updated'); - - // session()->flash('flash_message', 'allowed mimtypes have been updated!'); // return redirect()->route('settings.document'); - + // throw new GeneralException(trans('exceptions.backend.dataset.update_error')); } + + /** + * deactivate mimetype + * + * @param int $id + * @return \Illuminate\Http\RedirectResponse + */ + public function down($id): RedirectResponse + { + $mimetype = MimeType::findOrFail($id); + $mimetype->update(['enabled' => 0]); + session()->flash('flash_message', 'mimetype has been deactivated!'); + return redirect()->route('settings.mimetype.index'); + } + + /** + * activate mimetype. + * + * @param int $id + * @return \Illuminate\Http\RedirectResponse + */ + public function up($id): RedirectResponse + { + $mimetype = MimeType::findOrFail($id); + $mimetype->update(['enabled' => 1]); + session()->flash('flash_message', 'mimetype has been activated!'); + return redirect()->route('settings.mimetype.index'); + } } diff --git a/app/Models/MimeType.php b/app/Models/MimeType.php new file mode 100644 index 0000000..d0f8fa0 --- /dev/null +++ b/app/Models/MimeType.php @@ -0,0 +1,16 @@ +all(); + //$project = Project::create($input); + protected $fillable = [ + 'name', 'file_extension', 'enabled', + ]; +} diff --git a/app/Rules/RdrFiletypes.php b/app/Rules/RdrFiletypes.php index 44a39db..b2946f3 100644 --- a/app/Rules/RdrFiletypes.php +++ b/app/Rules/RdrFiletypes.php @@ -3,7 +3,8 @@ namespace App\Rules; use Illuminate\Contracts\Validation\Rule; -use Illuminate\Support\Facades\Config; +//use Illuminate\Support\Facades\Config; +use App\Models\MimeType; class RdrFiletypes implements Rule { @@ -16,7 +17,10 @@ class RdrFiletypes implements Rule */ public function __construct() { - $this->mimetypes = Config::get('enums.mimetypes_allowed', ['application/pdf']); + //$this->mimetypes = Config::get('enums.mimetypes_allowed', ['application/pdf']); + $this->mimetypes = MimeType::where('enabled', 1) + ->pluck('name') + ->toArray(); // $this->maxFileSize = Config::get('enums.max_filesize'); } @@ -30,9 +34,9 @@ class RdrFiletypes implements Rule public function passes($attribute, $value) { //return Rule::in($this->filetypes); - $test = $value->getMimeType();//"application/pdf" + $mimeType = $value->getMimeType();//"application/pdf" return $value->getPath() != '' && - in_array($value->getMimeType(), $this->mimetypes); + in_array($mimeType, $this->mimetypes); // in_array($value->guessExtension(), $this->filetypes); //file extension @@ -49,23 +53,4 @@ class RdrFiletypes implements Rule { return 'attribute :attribute has not a valid mime type.'; } - - /** - * Get the size of an attribute. - * - * @param string $attribute - * @param mixed $value - * @return mixed - */ - private function getSize($attribute, $value) - { - if (is_numeric($value) && $hasNumeric) { - return array_get($this->data, $attribute); - } elseif (is_array($value)) { - return count($value); - } elseif ($value instanceof File) { - return $value->getSize() / 1024; - } - return mb_strlen($value); - } } diff --git a/composer.lock b/composer.lock index 5592349..7917f2e 100755 --- a/composer.lock +++ b/composer.lock @@ -281,25 +281,30 @@ }, { "name": "dragonmantank/cron-expression", - "version": "v2.2.0", + "version": "v2.3.0", "source": { "type": "git", "url": "https://github.com/dragonmantank/cron-expression.git", - "reference": "92a2c3768d50e21a1f26a53cb795ce72806266c5" + "reference": "72b6fbf76adb3cf5bc0db68559b33d41219aba27" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/dragonmantank/cron-expression/zipball/92a2c3768d50e21a1f26a53cb795ce72806266c5", - "reference": "92a2c3768d50e21a1f26a53cb795ce72806266c5", + "url": "https://api.github.com/repos/dragonmantank/cron-expression/zipball/72b6fbf76adb3cf5bc0db68559b33d41219aba27", + "reference": "72b6fbf76adb3cf5bc0db68559b33d41219aba27", "shasum": "" }, "require": { - "php": ">=7.0.0" + "php": "^7.0" }, "require-dev": { - "phpunit/phpunit": "~6.4" + "phpunit/phpunit": "^6.4|^7.0" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.3-dev" + } + }, "autoload": { "psr-4": { "Cron\\": "src/Cron/" @@ -326,7 +331,7 @@ "cron", "schedule" ], - "time": "2018-06-06T03:12:17+00:00" + "time": "2019-03-31T00:38:28+00:00" }, { "name": "egulias/email-validator", @@ -961,16 +966,16 @@ }, { "name": "league/flysystem", - "version": "1.0.50", + "version": "1.0.51", "source": { "type": "git", "url": "https://github.com/thephpleague/flysystem.git", - "reference": "dab4e7624efa543a943be978008f439c333f2249" + "reference": "755ba7bf3fb9031e6581d091db84d78275874396" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/dab4e7624efa543a943be978008f439c333f2249", - "reference": "dab4e7624efa543a943be978008f439c333f2249", + "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/755ba7bf3fb9031e6581d091db84d78275874396", + "reference": "755ba7bf3fb9031e6581d091db84d78275874396", "shasum": "" }, "require": { @@ -1041,7 +1046,7 @@ "sftp", "storage" ], - "time": "2019-02-01T08:50:36+00:00" + "time": "2019-03-30T13:22:34+00:00" }, { "name": "mcamara/laravel-localization", diff --git a/config/enums.php b/config/enums.php index 98f098b..1e17544 100644 --- a/config/enums.php +++ b/config/enums.php @@ -25,108 +25,5 @@ return [ "png" => "image/png", "jpg|jpeg|jpe" => "image/jpeg", ], - 'max_filesize' => 5120, - 'mime_types' => [ - // Image formats. - 'jpg|jpeg|jpe' => 'image/jpeg', - 'gif' => 'image/gif', - 'png' => 'image/png', - 'bmp' => 'image/bmp', - 'tiff|tif' => 'image/tiff', - 'ico' => 'image/x-icon', - // Video formats. - 'asf|asx' => 'video/x-ms-asf', - 'wmv' => 'video/x-ms-wmv', - 'wmx' => 'video/x-ms-wmx', - 'wm' => 'video/x-ms-wm', - 'avi' => 'video/avi', - 'divx' => 'video/divx', - 'flv' => 'video/x-flv', - 'mov|qt' => 'video/quicktime', - 'mpeg|mpg|mpe' => 'video/mpeg', - 'mp4|m4v' => 'video/mp4', - 'ogv' => 'video/ogg', - 'webm' => 'video/webm', - 'mkv' => 'video/x-matroska', - '3gp|3gpp' => 'video/3gpp', // Can also be audio - '3g2|3gp2' => 'video/3gpp2', // Can also be audio - // Text formats. - 'txt|asc|c|cc|h|srt' => 'text/plain', - 'csv' => 'text/csv', - 'tsv' => 'text/tab-separated-values', - 'ics' => 'text/calendar', - 'rtx' => 'text/richtext', - 'css' => 'text/css', - 'htm|html' => 'text/html', - 'vtt' => 'text/vtt', - 'dfxp' => 'application/ttaf+xml', - // Audio formats. - 'mp3|m4a|m4b' => 'audio/mpeg', - 'aac' => 'audio/aac', - 'ra|ram' => 'audio/x-realaudio', - 'wav' => 'audio/wav', - 'ogg|oga' => 'audio/ogg', - 'flac' => 'audio/flac', - 'mid|midi' => 'audio/midi', - 'wma' => 'audio/x-ms-wma', - 'wax' => 'audio/x-ms-wax', - 'mka' => 'audio/x-matroska', - // Misc application formats. - 'rtf' => 'application/rtf', - 'js' => 'application/javascript', - 'pdf' => 'application/pdf', - 'swf' => 'application/x-shockwave-flash', - 'class' => 'application/java', - 'tar' => 'application/x-tar', - 'zip' => 'application/zip', - 'gz|gzip' => 'application/x-gzip', - 'rar' => 'application/rar', - '7z' => 'application/x-7z-compressed', - 'exe' => 'application/x-msdownload', - 'psd' => 'application/octet-stream', - 'xcf' => 'application/octet-stream', - // MS Office formats. - 'doc' => 'application/msword', - 'pot|pps|ppt' => 'application/vnd.ms-powerpoint', - 'wri' => 'application/vnd.ms-write', - 'xla|xls|xlt|xlw' => 'application/vnd.ms-excel', - 'mdb' => 'application/vnd.ms-access', - 'mpp' => 'application/vnd.ms-project', - 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', - 'docm' => 'application/vnd.ms-word.document.macroEnabled.12', - 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', - 'dotm' => 'application/vnd.ms-word.template.macroEnabled.12', - 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - 'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12', - 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12', - 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', - 'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12', - 'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12', - 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', - 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12', - 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', - 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12', - 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', - 'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12', - 'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12', - 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide', - 'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12', - 'onetoc|onetoc2|onetmp|onepkg' => 'application/onenote', - 'oxps' => 'application/oxps', - 'xps' => 'application/vnd.ms-xpsdocument', - // OpenOffice formats. - 'odt' => 'application/vnd.oasis.opendocument.text', - 'odp' => 'application/vnd.oasis.opendocument.presentation', - 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', - 'odg' => 'application/vnd.oasis.opendocument.graphics', - 'odc' => 'application/vnd.oasis.opendocument.chart', - 'odb' => 'application/vnd.oasis.opendocument.database', - 'odf' => 'application/vnd.oasis.opendocument.formula', - // WordPerfect formats. - 'wp|wpd' => 'application/wordperfect', - // iWork formats. - 'key' => 'application/vnd.apple.keynote', - 'numbers' => 'application/vnd.apple.numbers', - 'pages' => 'application/vnd.apple.pages', - ] + 'max_filesize' => 5120 ]; diff --git a/public/datasetxml2oai-pmh.xslt b/public/datasetxml2oai-pmh.xslt index 932a754..228e163 100644 --- a/public/datasetxml2oai-pmh.xslt +++ b/public/datasetxml2oai-pmh.xslt @@ -368,26 +368,26 @@ - + - + - + - + - + - + diff --git a/resources/views/settings/filetype/index.blade.php b/resources/views/settings/filetype/index.blade.php index e733629..08b5d17 100644 --- a/resources/views/settings/filetype/index.blade.php +++ b/resources/views/settings/filetype/index.blade.php @@ -1,5 +1,4 @@ -@extends('settings.layouts.app') - +@extends('settings.layouts.app') @section('content')

@@ -10,44 +9,42 @@
-
- {{-- +
+ {{-- - Create New File Extension - --}} + ADD NEW MimeType + +

--}} - @if ($message = Session::get('success')) -
-

{{ $message }}

-
- @endif + + + + + + + + + - {!! Form::open(array('route' => 'settings.mimetype.update','method' => 'PATCH', 'class'=>'pure-form')) !!} - -
- @foreach ($options as $key => $value) - - @endforeach -
+ + @foreach($mimetypes as $mimetype) + - {{--
- -
--}} + + + + + + @endforeach + - {!! Form::close() !!} - +
NameFile ExtensionStatus
{{ $mimetype->name }}{{ $mimetype->file_extension }} + @if($mimetype->enabled == 1) Active @else Inactive @endif + + @if($mimetype->enabled == 1) + Deactivate @else + Activate @endif +
diff --git a/routes/web.php b/routes/web.php index 822fa3a..0e8b75a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -187,6 +187,12 @@ Route::group(['middleware' => ['permission:settings']], function () { // Route::get('settings/collection/delete/{id}', [ // 'as' => 'settings.collection.delete', 'uses' => 'Settings\CollectionController@delete', // ]); + Route::get('settings/mimetype/down/{id}', [ + 'as' => 'settings.mimetype.down', 'uses' => 'Settings\MimetypeController@down', + ]); + Route::get('settings/mimetype/up/{id}', [ + 'as' => 'settings.mimetype.up', 'uses' => 'Settings\MimetypeController@up', + ]); //=================================================setting collection============================================= Route::get('/settings/collection', [