MimetypesController

This commit is contained in:
Arno Kaimbacher 2019-02-22 18:07:00 +01:00
parent c86c9fe9f4
commit f3f17d9371
13 changed files with 235 additions and 99 deletions

View File

@ -473,10 +473,10 @@ class IndexController extends Controller
'abstract_main.language' => 'required', 'abstract_main.language' => 'required',
]; ];
if (null != $request->file('files')) { if (null != $request->file('files')) {
$files = count($request->file('files')) - 1; $files = count($request->file('files')) -1;
foreach (range(0, $files) as $index) { foreach (range(0, $files) as $index) {
// $rules['files.' . $index] = 'image|max:2048'; // $rules['files.' . $index] = 'image|max:2048';
$rules['files.' . $index . '.file'] = ['required', 'file', new RdrFiletypes(), new RdrFilesize()]; $rules['files.' . $index . '.file'] = ['required', 'file', new RdrFiletypes(), new RdrFilesize($index)];
} }
} }
$validator = Validator::make($request->all(), $rules); $validator = Validator::make($request->all(), $rules);

View File

@ -1,18 +1,18 @@
<?php <?php
namespace App\Http\Controllers\Settings; namespace App\Http\Controllers\Settings;
use App\Http\Controllers\Controller;
use App\Models\Dataset;
use App\Models\Project;
use App\Models\License;
use App\Models\Title;
use App\Models\Description;
use App\Http\Requests\DocumentRequest;
use Illuminate\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use App\Exceptions\GeneralException; use App\Exceptions\GeneralException;
use App\Http\Controllers\Controller;
use App\Http\Requests\DocumentRequest;
use App\Models\Dataset;
use App\Models\Description;
use App\Models\License;
use App\Models\Project;
use App\Models\Title;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\View\View;
class DatasetController extends Controller class DatasetController extends Controller
{ {
@ -21,38 +21,37 @@ class DatasetController extends Controller
$this->middleware('auth'); $this->middleware('auth');
} }
public function index(Request $request) : View public function index(Request $request): View
{ {
$searchType = $request->input('searchtype'); $searchType = $request->input('searchtype');
$builder = Dataset::query(); $builder = Dataset::query();
//$registers = array(); //$registers = array();
$filter = $request->input('filter'); $filter = $request->input('filter');
if (null !== ($request->input('state'))) { if (null !== ($request->input('state'))) {
$state = $request->input('state'); $state = $request->input('state');
} else { } else {
$state = "published"; $state = "published";
} }
$data = $request->all(); $data = $request->all();
if ($searchType == "simple") { if ($searchType == "simple") {
if (strlen($filter) > 0) { if (strlen($filter) > 0) {
//$builder->where('field1', '=', $criteria1); $closure = function ($query) use ($filter) {
$builder->whereHas('titles', function ($query) use ($filter) {
$query->where('value', 'LIKE', '%' . $filter . '%'); $query->where('value', 'LIKE', '%' . $filter . '%');
}); };
$builder->whereHas('titles', $closure);
// ::with(['titles' => function ($query) use($filter) { // ::with(['titles' => function ($query) use($filter) {
// $query->where('value', 'LIKE', '%' . $filter . '%'); // $query->where('value', 'LIKE', '%' . $filter . '%');
// }]) // }])
} }
} }
$builder->where('server_state', $state); $builder->where('server_state', $state);
//$perPage = $request->get('perPage', 20); //$perPage = $request->get('perPage', 20);
$documents = $builder $documents = $builder
->paginate(8); ->paginate(8);
return view('settings.document.document', compact('documents', 'state', 'filter')); return view('settings.document.document', compact('documents', 'state', 'filter'));
} }
@ -107,20 +106,20 @@ class DatasetController extends Controller
* @param int $id * @param int $id
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function edit($id) : View public function edit($id): View
{ {
$document = Dataset::findOrFail($id); $document = Dataset::findOrFail($id);
$document->load('licenses', 'titles', 'abstracts', 'files'); $document->load('licenses', 'titles', 'abstracts', 'files');
$projects = Project::pluck('label', 'id'); $projects = Project::pluck('label', 'id');
$datum = date('Y-m-d'); $datum = date('Y-m-d');
$nowYear = substr($datum, 0, 4); $nowYear = substr($datum, 0, 4);
$years = array(); $years = array();
for ($jahr = 1990; $jahr <= $nowYear; $jahr++) { for ($jahr = 1990; $jahr <= $nowYear; $jahr++) {
$years[$jahr] = $jahr; $years[$jahr] = $jahr;
} }
$languages = DB::table('languages') $languages = DB::table('languages')
->where('active', true) ->where('active', true)
->pluck('part1', 'part1'); ->pluck('part1', 'part1');
@ -151,7 +150,7 @@ class DatasetController extends Controller
* @param int $id * @param int $id
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function update(DocumentRequest $request, $id) : RedirectResponse public function update(DocumentRequest $request, $id): RedirectResponse
{ {
$dataset = Dataset::findOrFail($id); $dataset = Dataset::findOrFail($id);
//$input = $request->all(); //$input = $request->all();
@ -191,7 +190,7 @@ class DatasetController extends Controller
} }
} }
if (! $dataset->isDirty(dataset::UPDATED_AT)) { if (!$dataset->isDirty(dataset::UPDATED_AT)) {
$time = new \Illuminate\Support\Carbon(); $time = new \Illuminate\Support\Carbon();
$dataset->setUpdatedAt($time); $dataset->setUpdatedAt($time);
} }
@ -204,14 +203,13 @@ class DatasetController extends Controller
throw new GeneralException(trans('exceptions.backend.dataset.update_error')); throw new GeneralException(trans('exceptions.backend.dataset.update_error'));
} }
/** /**
* Remove the specified resource from storage. * Remove the specified resource from storage.
* *
* @param int $id * @param int $id
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function destroy($id) : RedirectResponse public function destroy($id): RedirectResponse
{ {
// $document = Document::findOrFail($id); // $document = Document::findOrFail($id);
// $document->delete(); // $document->delete();

View File

@ -1,28 +0,0 @@
<?php
namespace App\Http\Controllers\Settings;
use App\Http\Controllers\Controller;
use Illuminate\View\View;
use Illuminate\Support\Facades\Config;
class FiletypeController extends Controller
{
// public function download($id)
// {
// //$report = $this->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');
}
public function index(): View
{
$direction = 'asc'; // or desc
$fileextensions = Config::get('enums.filetypes_allowed');
return view('settings.filetype.index', compact('fileextensions'));
}
}

View File

@ -0,0 +1,50 @@
<?php
namespace App\Http\Controllers\Settings;
use App\Exceptions\GeneralException;
use App\Http\Controllers\Controller;
use Illuminate\View\View;
use Illuminate\Support\Facades\Config;
use Illuminate\Http\Request;
class MimetypeController extends Controller
{
// public function download($id)
// {
// //$report = $this->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');
}
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');
return view('settings.filetype.index', [
'options' => $mimetypes,
'checkeds' => $checkeds
]);
}
public function update(Request $request)
{
$mimetypes = $request->input('mimetypes');
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'));
}
}

View File

@ -68,7 +68,7 @@ class WorkflowController extends Controller
session()->flash('flash_message', 'You have puplished 1 dataset!'); session()->flash('flash_message', 'You have puplished 1 dataset!');
} }
$dataset->save(); $dataset->save();
return redirect()->back(); return redirect()->back();
//return redirect()->route('settings.review.index'); //return redirect()->route('settings.review.index');
} catch (Exception $e) { } catch (Exception $e) {
//return $this->_redirectTo('index', array('failure' => $e->getMessage()), 'documents', 'admin'); //return $this->_redirectTo('index', array('failure' => $e->getMessage()), 'documents', 'admin');

View File

@ -93,7 +93,7 @@ class DatasetObserver
$service = new SolariumAdapter("solr", config('solarium')); $service = new SolariumAdapter("solr", config('solarium'));
$service->addDatasetsToIndex($dataset); $service->addDatasetsToIndex($dataset);
} catch (Opus_Search_Exception $e) { } catch (Opus_Search_Exception $e) {
Log::debug(__METHOD__ . ': ' . 'Indexing document ' . $documentId . ' failed: ' . $e->getMessage()); Log::debug(__METHOD__ . ': ' . 'Indexing document ' . $datasetId . ' failed: ' . $e->getMessage());
} catch (InvalidArgumentException $e) { } catch (InvalidArgumentException $e) {
Log::warning(__METHOD__ . ': ' . $e->getMessage()); Log::warning(__METHOD__ . ': ' . $e->getMessage());
} }

View File

@ -16,7 +16,7 @@ class RdrFiletypes implements Rule
*/ */
public function __construct() public function __construct()
{ {
$this->filetypes = Config::get('enums.filetypes_allowed', ['pdf']); $this->mimetypes = Config::get('enums.mimetypes_allowed', ['application/pdf']);
// $this->maxFileSize = Config::get('enums.max_filesize'); // $this->maxFileSize = Config::get('enums.max_filesize');
} }
@ -30,8 +30,13 @@ class RdrFiletypes implements Rule
public function passes($attribute, $value) public function passes($attribute, $value)
{ {
//return Rule::in($this->filetypes); //return Rule::in($this->filetypes);
$test = $value->getMimeType();//"application/pdf"
return $value->getPath() != '' && return $value->getPath() != '' &&
in_array($value->guessExtension(), $this->filetypes); // && in_array($value->getMimeType(), $this->mimetypes);
// in_array($value->guessExtension(), $this->filetypes); //file extension
// &&
// $this->getSize($attribute, $value) <= $this->maxFileSize; // $this->getSize($attribute, $value) <= $this->maxFileSize;
} }

View File

@ -25,7 +25,7 @@
"require-dev": { "require-dev": {
"fzaninotto/faker": "^1.8", "fzaninotto/faker": "^1.8",
"phpunit/phpunit": "^7.0", "phpunit/phpunit": "^7.0",
"squizlabs/php_codesniffer": "^3.3" "squizlabs/php_codesniffer": "^3.4"
}, },
"autoload": { "autoload": {
"files": [ "files": [

2
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "cfd99ddd9c6460b54b15771a05d2e1d7", "content-hash": "35e771d8a4e73ec0c3768490092f9391",
"packages": [ "packages": [
{ {
"name": "davejamesmiller/laravel-breadcrumbs", "name": "davejamesmiller/laravel-breadcrumbs",

View File

@ -18,8 +18,115 @@ return [
'temporary' => 'temporary', 'temporary' => 'temporary',
'created' => 'created', 'created' => 'created',
], ],
'filetypes_allowed' => [ 'mimetypes_allowed' => [
"pdf", "txt", "html", "htm", "png", "jpeg", "pdf" => "application/pdf",
"txt|asc|c|cc|h|srt" => "text/plain",
"htm|html" => "text/html",
"png" => "image/png",
"jpg|jpeg|jpe" => "image/jpeg",
], ],
'max_filesize' => 5120, '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',
]
]; ];

View File

@ -4,18 +4,17 @@
<div class="header"> <div class="header">
<h3 class="header-title"> <h3 class="header-title">
<i class="fa fa-file"></i> <i class="fa fa-file"></i>
<span> File Extensions</span> <span> Mime-Types</span>
</h3> </h3>
</div> </div>
<div class="pure-g box-content"> <div class="pure-g box-content">
<div class="pure-u-1 pure-u-md-2-3"> <div class="pure-u-1 pure-u-md-2-3">
<a class="pure-button button-small is-primary" href="{{ route('access.user.create') }}"> {{-- <a class="pure-button button-small is-primary" href="{{ route('access.user.create') }}">
<i class="fa fa-plus-circle"></i> <i class="fa fa-plus-circle"></i>
<span>Create New File Extension</span> <span>Create New File Extension</span>
</a> </a> --}}
<br><br>
@if ($message = Session::get('success')) @if ($message = Session::get('success'))
<div class="alert summary-success"> <div class="alert summary-success">
@ -23,27 +22,32 @@
</div> </div>
@endif @endif
<table class="pure-table users"> {!! Form::open(array('route' => 'settings.mimetype.update','method' => 'PATCH', 'class'=>'pure-form')) !!}
<thead>
<tr> <div class="pure-control-group checkboxlist">
<th>File Extensions</th> @foreach ($options as $key => $value)
<th width="280px">Action</th> <label for={{"mimetype". $key }} class="pure-checkbox">
</tr> {{-- <input name="mimetypes[]" value={{ $value }} {{ (in_array($value, $checkeds)) ? 'checked=checked' : '' }} type="checkbox" class="form-check-input"> --}}
</thead>
<tbody> {!! Form::checkbox( 'mimetypes['. $key .']',
@foreach ($fileextensions as $key => $fileextension) $value,
<tr> in_array($value, $checkeds),
<td>{{ $fileextension }}</td> ['class' => 'md-check', 'id' => $key]
<td> ) !!}
{{-- <a class="edit" href="{{ route('access.user.edit', $user->id) }}">&nbsp;Edit</a> {{ $value }}
<span>&nbsp;</span> </label>
<a class="delete" href="{{ route('access.user.destroy', $user->id) }}"><span>&nbsp;Delete</span></a> --}} @endforeach
</td> </div>
</tr>
@endforeach {{-- <div class="pure-controls">
</tbody> <button type="submit" class="pure-button button-small">
</table> <i class="fa fa-save"></i>
<span>Update allowed mimetypes</span>
</button>
</div> --}}
{!! Form::close() !!}
</div> </div>
</div> </div>

View File

@ -71,8 +71,8 @@
<a class="pure-menu-link" href="{{ route('settings.project') }}"><i class="fa fa-tasks"></i> Projects</a> <a class="pure-menu-link" href="{{ route('settings.project') }}"><i class="fa fa-tasks"></i> Projects</a>
</li> </li>
<li class="pure-menu-item {{ Route::is('settings.filetype') ? 'active' : '' }}"> <li class="pure-menu-item {{ Route::is('settings.mimetype') ? 'active' : '' }}">
<a class="pure-menu-link" href="{{ route('settings.filetype.index') }}"><i class="fa fa-archive"></i> Filetypes</a> <a class="pure-menu-link" href="{{ route('settings.mimetype.index') }}"><i class="fa fa-archive"></i> Mimetypes</a>
</li> </li>
@permission('page') @permission('page')

View File

@ -163,9 +163,9 @@ Route::group(['middleware' => ['permission:settings']], function () {
'as' => 'settings.file.download', 'uses' => 'Settings\FileController@download', 'as' => 'settings.file.download', 'uses' => 'Settings\FileController@download',
]); ]);
//=================================================setting filetype============================================= //=================================================setting mimetype=============================================
Route::get('/settings/filetype', [ Route::get('/settings/mimetype', [
'as' => 'settings.filetype.index', 'uses' => 'Settings\FiletypeController@index', 'as' => 'settings.mimetype.index', 'uses' => 'Settings\MimetypeController@index',
]); ]);
// Route::get('/settings/collection/create', [ // Route::get('/settings/collection/create', [
@ -178,9 +178,9 @@ Route::group(['middleware' => ['permission:settings']], function () {
// Route::get('settings/collection/edit/{id}', [ // Route::get('settings/collection/edit/{id}', [
// 'as' => 'settings.collection.edit', 'uses' => 'Settings\CollectionController@edit', // 'as' => 'settings.collection.edit', 'uses' => 'Settings\CollectionController@edit',
// ]); // ]);
// Route::patch('settings/collection/edit/{id}', [ Route::patch('settings/mimetype/update', [
// 'as' => 'settings.collection.update', 'uses' => 'Settings\CollectionController@update', 'as' => 'settings.mimetype.update', 'uses' => 'Settings\MimetypeController@update',
// ]); ]);
// Route::get('settings/collection/show/{collection}', [ // Route::get('settings/collection/show/{collection}', [
// 'as' => 'settings.collection.show', 'uses' => 'Settings\CollectionController@show', // 'as' => 'settings.collection.show', 'uses' => 'Settings\CollectionController@show',
// ]); // ]);