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',
];
if (null != $request->file('files')) {
$files = count($request->file('files')) - 1;
$files = count($request->file('files')) -1;
foreach (range(0, $files) as $index) {
// $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);

View File

@ -1,18 +1,18 @@
<?php
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\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
{
@ -21,7 +21,7 @@ class DatasetController extends Controller
$this->middleware('auth');
}
public function index(Request $request) : View
public function index(Request $request): View
{
$searchType = $request->input('searchtype');
$builder = Dataset::query();
@ -32,16 +32,16 @@ class DatasetController extends Controller
if (null !== ($request->input('state'))) {
$state = $request->input('state');
} else {
$state = "published";
$state = "published";
}
$data = $request->all();
$data = $request->all();
if ($searchType == "simple") {
if (strlen($filter) > 0) {
//$builder->where('field1', '=', $criteria1);
$builder->whereHas('titles', function ($query) use ($filter) {
$closure = function ($query) use ($filter) {
$query->where('value', 'LIKE', '%' . $filter . '%');
});
};
$builder->whereHas('titles', $closure);
// ::with(['titles' => function ($query) use($filter) {
// $query->where('value', 'LIKE', '%' . $filter . '%');
// }])
@ -49,10 +49,9 @@ class DatasetController extends Controller
}
$builder->where('server_state', $state);
//$perPage = $request->get('perPage', 20);
$documents = $builder
->paginate(8);
->paginate(8);
return view('settings.document.document', compact('documents', 'state', 'filter'));
}
@ -107,7 +106,7 @@ class DatasetController extends Controller
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id) : View
public function edit($id): View
{
$document = Dataset::findOrFail($id);
$document->load('licenses', 'titles', 'abstracts', 'files');
@ -151,7 +150,7 @@ class DatasetController extends Controller
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(DocumentRequest $request, $id) : RedirectResponse
public function update(DocumentRequest $request, $id): RedirectResponse
{
$dataset = Dataset::findOrFail($id);
//$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();
$dataset->setUpdatedAt($time);
}
@ -204,14 +203,13 @@ class DatasetController extends Controller
throw new GeneralException(trans('exceptions.backend.dataset.update_error'));
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id) : RedirectResponse
public function destroy($id): RedirectResponse
{
// $document = Document::findOrFail($id);
// $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

@ -93,7 +93,7 @@ class DatasetObserver
$service = new SolariumAdapter("solr", config('solarium'));
$service->addDatasetsToIndex($dataset);
} 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) {
Log::warning(__METHOD__ . ': ' . $e->getMessage());
}

View File

@ -16,7 +16,7 @@ class RdrFiletypes implements Rule
*/
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');
}
@ -30,8 +30,13 @@ class RdrFiletypes implements Rule
public function passes($attribute, $value)
{
//return Rule::in($this->filetypes);
$test = $value->getMimeType();//"application/pdf"
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;
}

View File

@ -25,7 +25,7 @@
"require-dev": {
"fzaninotto/faker": "^1.8",
"phpunit/phpunit": "^7.0",
"squizlabs/php_codesniffer": "^3.3"
"squizlabs/php_codesniffer": "^3.4"
},
"autoload": {
"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",
"This file is @generated automatically"
],
"content-hash": "cfd99ddd9c6460b54b15771a05d2e1d7",
"content-hash": "35e771d8a4e73ec0c3768490092f9391",
"packages": [
{
"name": "davejamesmiller/laravel-breadcrumbs",

View File

@ -18,8 +18,115 @@ return [
'temporary' => 'temporary',
'created' => 'created',
],
'filetypes_allowed' => [
"pdf", "txt", "html", "htm", "png", "jpeg",
'mimetypes_allowed' => [
"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,
'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">
<h3 class="header-title">
<i class="fa fa-file"></i>
<span> File Extensions</span>
<span> Mime-Types</span>
</h3>
</div>
<div class="pure-g box-content">
<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>
<span>Create New File Extension</span>
</a>
<br><br>
</a> --}}
@if ($message = Session::get('success'))
<div class="alert summary-success">
@ -23,26 +22,31 @@
</div>
@endif
<table class="pure-table users">
<thead>
<tr>
<th>File Extensions</th>
<th width="280px">Action</th>
</tr>
</thead>
<tbody>
@foreach ($fileextensions as $key => $fileextension)
<tr>
<td>{{ $fileextension }}</td>
<td>
{{-- <a class="edit" href="{{ route('access.user.edit', $user->id) }}">&nbsp;Edit</a>
<span>&nbsp;</span>
<a class="delete" href="{{ route('access.user.destroy', $user->id) }}"><span>&nbsp;Delete</span></a> --}}
</td>
</tr>
@endforeach
</tbody>
</table>
{!! Form::open(array('route' => 'settings.mimetype.update','method' => 'PATCH', 'class'=>'pure-form')) !!}
<div class="pure-control-group checkboxlist">
@foreach ($options as $key => $value)
<label for={{"mimetype". $key }} class="pure-checkbox">
{{-- <input name="mimetypes[]" value={{ $value }} {{ (in_array($value, $checkeds)) ? 'checked=checked' : '' }} type="checkbox" class="form-check-input"> --}}
{!! Form::checkbox( 'mimetypes['. $key .']',
$value,
in_array($value, $checkeds),
['class' => 'md-check', 'id' => $key]
) !!}
{{ $value }}
</label>
@endforeach
</div>
{{-- <div class="pure-controls">
<button type="submit" class="pure-button button-small">
<i class="fa fa-save"></i>
<span>Update allowed mimetypes</span>
</button>
</div> --}}
{!! Form::close() !!}
</div>

View File

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

View File

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