From 1fc1601e6840323431b627891f6bb871b01b96c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Thu, 14 Sep 2017 11:36:05 +0200 Subject: [PATCH] INIT: initial commit --- Config/config.php | 12 ++ Database/Migrations/.gitkeep | 0 ..._14_082308_create_content_filter_table.php | 32 ++++++ Entities/ContentFilter.php | 18 +++ Handlers/ContentFilterHandler.php | 32 ++++++ Http/Controllers/Admin/ContentFilter.php | 106 ++++++++++++++++++ Http/Requests/CreateContentFilter.php | 13 +++ Http/Requests/UpdateContentFilter.php | 13 +++ Http/routes.php | 10 ++ Pipelines/Display/Filter.php | 46 ++++++++ Providers/ContentFilterServiceProvider.php | 40 +++++++ Repositories/ContentFilterRepository.php | 24 ++++ Resources/lang/cs/contentfilter.php | 13 +++ Resources/lang/cs/fields.php | 7 ++ Resources/views/admin/create.blade.php | 17 +++ Resources/views/admin/edit.blade.php | 17 +++ Resources/views/admin/form.blade.php | 36 ++++++ Resources/views/admin/index.blade.php | 52 +++++++++ 18 files changed, 488 insertions(+) create mode 100644 Config/config.php create mode 100644 Database/Migrations/.gitkeep create mode 100644 Database/Migrations/2017_09_14_082308_create_content_filter_table.php create mode 100644 Entities/ContentFilter.php create mode 100644 Handlers/ContentFilterHandler.php create mode 100644 Http/Controllers/Admin/ContentFilter.php create mode 100644 Http/Requests/CreateContentFilter.php create mode 100644 Http/Requests/UpdateContentFilter.php create mode 100644 Http/routes.php create mode 100644 Pipelines/Display/Filter.php create mode 100644 Providers/ContentFilterServiceProvider.php create mode 100644 Repositories/ContentFilterRepository.php create mode 100644 Resources/lang/cs/contentfilter.php create mode 100644 Resources/lang/cs/fields.php create mode 100644 Resources/views/admin/create.blade.php create mode 100644 Resources/views/admin/edit.blade.php create mode 100644 Resources/views/admin/form.blade.php create mode 100644 Resources/views/admin/index.blade.php diff --git a/Config/config.php b/Config/config.php new file mode 100644 index 0000000..5707f33 --- /dev/null +++ b/Config/config.php @@ -0,0 +1,12 @@ + 'ContentFilter', + 'translatedName' => 'contentfilter::contentfilter.name', + 'translatedDescription' => 'contentfilter::contentfilter.description', + 'alias' => 'contentfilter', + 'handler' => \Modules\ContentFilter\Handlers\ContentFilterHandler::class, + 'providers' => [\Modules\ContentFilter\Providers\ContentFilterServiceProvider::class], + 'files' => ['Http/routes.php'], + 'order' => 0, +]; \ No newline at end of file diff --git a/Database/Migrations/.gitkeep b/Database/Migrations/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Database/Migrations/2017_09_14_082308_create_content_filter_table.php b/Database/Migrations/2017_09_14_082308_create_content_filter_table.php new file mode 100644 index 0000000..f772282 --- /dev/null +++ b/Database/Migrations/2017_09_14_082308_create_content_filter_table.php @@ -0,0 +1,32 @@ +increments('id'); + $table->timestamps(); + $table->boolean('active') + ->default(true); + $table->string('name'); + $table->string('search'); + $table->string('replace'); + }); + } + + /** + * Rollback migration + */ + public function down() + { + Schema::drop('content_filters'); + } +} \ No newline at end of file diff --git a/Entities/ContentFilter.php b/Entities/ContentFilter.php new file mode 100644 index 0000000..ba24d67 --- /dev/null +++ b/Entities/ContentFilter.php @@ -0,0 +1,18 @@ + 'boolean' + ]; +} \ No newline at end of file diff --git a/Handlers/ContentFilterHandler.php b/Handlers/ContentFilterHandler.php new file mode 100644 index 0000000..53203ff --- /dev/null +++ b/Handlers/ContentFilterHandler.php @@ -0,0 +1,32 @@ +whereTitle(trans('admin/mainMenu.system')); + $system->route('contentfilter.index', trans('contentfilter::contentfilter.overview'), [], 20, ['icon' => 'fa fa-fw fa-filter']); + } + + /** + * Does this module support categories? + * @return boolean + */ + public static function supportCategories() + { + return false; + } +} \ No newline at end of file diff --git a/Http/Controllers/Admin/ContentFilter.php b/Http/Controllers/Admin/ContentFilter.php new file mode 100644 index 0000000..82dfcfa --- /dev/null +++ b/Http/Controllers/Admin/ContentFilter.php @@ -0,0 +1,106 @@ +contentfilterRepository = $contentfilterRepository; + } + + /** + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + */ + public function index() + { + $filters = ContentFilterEntity::paginate(); + + return view('contentfilter::admin/index', compact('filters')); + } + + /** + * Display form for updating filter + * + * @param ContentFilterEntity $contentfilter + * + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + */ + public function edit(ContentFilterEntity $contentfilter) + { + $filter = $contentfilter; + + return view('contentfilter::admin.edit', compact('filter')); + } + + /** + * Update existing filter + * + * @param UpdateContentFilter $request + * @param ContentFilterEntity $contentfilter + * + * @return \Illuminate\Http\RedirectResponse + */ + public function update(UpdateContentFilter $request, ContentFilterEntity $contentfilter) + { + $this->contentfilterRepository->update($contentfilter, $request->all()); + + return redirect() + ->route('contentfilter.index') + ->with('success', trans('contentfilter::contentfilter.successfullyUpdated')); + } + + /** + * Display form for creating new filter + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + */ + public function create() + { + $filter = new ContentFilterEntity(); + + return view('contentfilter::admin.create', compact('filter')); + } + + /** + * Create new instance of filter + * + * @param CreateContentFilter $request + * + * @return \Illuminate\Http\RedirectResponse + */ + public function store(CreateContentFilter $request) + { + $this->contentfilterRepository->create($request->all()); + + return redirect() + ->route('contentfilter.index') + ->with('success', trans('contentfilter::contentfilter.successfullyUpdated')); + } + + /** + * Delete filter + * + * @param ContentFilterEntity $contentfilter + * + * @return \Illuminate\Http\RedirectResponse + */ + public function destroy(ContentFilterEntity $contentfilter) + { + $contentfilter->delete(); + + return redirect() + ->route('contentfilter.index') + ->with('success', trans('contentfilter::contentfilter.successfullyDeleted')); + } +} \ No newline at end of file diff --git a/Http/Requests/CreateContentFilter.php b/Http/Requests/CreateContentFilter.php new file mode 100644 index 0000000..614bcac --- /dev/null +++ b/Http/Requests/CreateContentFilter.php @@ -0,0 +1,13 @@ + 'required', 'search' => 'required', 'replace' => 'required']; + } +} \ No newline at end of file diff --git a/Http/Requests/UpdateContentFilter.php b/Http/Requests/UpdateContentFilter.php new file mode 100644 index 0000000..3261c94 --- /dev/null +++ b/Http/Requests/UpdateContentFilter.php @@ -0,0 +1,13 @@ + 'required', 'search' => 'required', 'replace' => 'required']; + } +} \ No newline at end of file diff --git a/Http/routes.php b/Http/routes.php new file mode 100644 index 0000000..d35ceef --- /dev/null +++ b/Http/routes.php @@ -0,0 +1,10 @@ + \LaravelLocalization::setLocale() . '/admin', + 'middleware' => ['admin', 'bindings'], + 'namespace' => 'Modules\ContentFilter\Http\Controllers\Admin' + ], function () { + + Route::resource('contentfilter', 'ContentFilter'); +}); \ No newline at end of file diff --git a/Pipelines/Display/Filter.php b/Pipelines/Display/Filter.php new file mode 100644 index 0000000..bfeb467 --- /dev/null +++ b/Pipelines/Display/Filter.php @@ -0,0 +1,46 @@ +filters = collect(); + } + + /** + * Process and modify given page + * + * @param Content $page + * + * @return void + */ + function handle(Content & $page) + { + $this->initFilters(); + + $page->pageContent = $this->applyFilters($page->pageContent); + } + + protected function applyFilters($content) + { + foreach ($this->filters as $filter) { + $content = str_replace($filter->search, $filter->replace, $content); + } + + return $content; + } + + protected function initFilters() + { + $this->filters = ContentFilter::where('active', true) + ->get(); + } +} \ No newline at end of file diff --git a/Providers/ContentFilterServiceProvider.php b/Providers/ContentFilterServiceProvider.php new file mode 100644 index 0000000..77b0f82 --- /dev/null +++ b/Providers/ContentFilterServiceProvider.php @@ -0,0 +1,40 @@ +alias = 'contentfilter'; + } + + /** + * Set path to module + */ + protected function setModulePath() + { + $this->path = __DIR__; + } + + public function boot() { + parent::boot(); + + $registrator = $this->app->make('displayPipeline'); + + $registrator->add(Filter::class); + } +} \ No newline at end of file diff --git a/Repositories/ContentFilterRepository.php b/Repositories/ContentFilterRepository.php new file mode 100644 index 0000000..058e103 --- /dev/null +++ b/Repositories/ContentFilterRepository.php @@ -0,0 +1,24 @@ +update($data); + } +} \ No newline at end of file diff --git a/Resources/lang/cs/contentfilter.php b/Resources/lang/cs/contentfilter.php new file mode 100644 index 0000000..b03ca71 --- /dev/null +++ b/Resources/lang/cs/contentfilter.php @@ -0,0 +1,13 @@ + 'Filtr obsahu', + 'new' => 'Vytvořit nový filtr', + 'description' => 'Modul pro správu filtrů obsahu.', + 'successfullyUpdated' => 'Úspěšně upraveno.', + 'successfullyCreated' => 'Úspěšně vytvořeno.', + 'successfullyDeleted' => 'Úspěšně smazáno.', + 'overview' => 'Filtry obsahu', + 'noItems' => 'Žádná data.', + 'save' => 'Uložit' +]; \ No newline at end of file diff --git a/Resources/lang/cs/fields.php b/Resources/lang/cs/fields.php new file mode 100644 index 0000000..e360792 --- /dev/null +++ b/Resources/lang/cs/fields.php @@ -0,0 +1,7 @@ + 'Jméno', + 'search' => 'Vyhledat co', + 'replace' => 'Nahradit za' +]; \ No newline at end of file diff --git a/Resources/views/admin/create.blade.php b/Resources/views/admin/create.blade.php new file mode 100644 index 0000000..fa2a331 --- /dev/null +++ b/Resources/views/admin/create.blade.php @@ -0,0 +1,17 @@ +@extends('admin.layoutWithNavigation') + +@section('pageHeading', @trans('contentfilter::contentfilter.name')) + +@section('headerButtons') + + + +@endsection + +@section('content') +
+
+ @include('contentfilter::admin.form', ['action' => route('contentfilter.store'), 'method' => 'post']) +
+
+@endsection \ No newline at end of file diff --git a/Resources/views/admin/edit.blade.php b/Resources/views/admin/edit.blade.php new file mode 100644 index 0000000..249ea98 --- /dev/null +++ b/Resources/views/admin/edit.blade.php @@ -0,0 +1,17 @@ +@extends('admin.layoutWithNavigation') + +@section('pageHeading', @trans('contentfilter::contentfilter.name')) + +@section('headerButtons') + + + +@endsection + +@section('content') +
+
+ @include('contentfilter::admin.form', ['action' => route('contentfilter.update', ['contentfilter' => $filter]), 'method' => 'put']) +
+
+@endsection \ No newline at end of file diff --git a/Resources/views/admin/form.blade.php b/Resources/views/admin/form.blade.php new file mode 100644 index 0000000..2c177e4 --- /dev/null +++ b/Resources/views/admin/form.blade.php @@ -0,0 +1,36 @@ +
+ {!! csrf_field() !!} + {!! method_field($method) !!} + + + + + + +
+
+ + + + @include('admin.snippets.hasError', ['field' => 'search']) +
+
+ + + + + @include('admin.snippets.hasError', ['field' => 'replace']) +
+
+ + +
\ No newline at end of file diff --git a/Resources/views/admin/index.blade.php b/Resources/views/admin/index.blade.php new file mode 100644 index 0000000..3737304 --- /dev/null +++ b/Resources/views/admin/index.blade.php @@ -0,0 +1,52 @@ +@extends('admin.layoutWithNavigation') + +@section('pageHeading', @trans('contentfilter::contentfilter.overview')) + +@section('headerButtons') + + + +@endsection + +@section('content') + @if (!$filters->isEmpty()) +
+
+ + + + + + + + + + + @foreach($filters as $filter) + + + + + + + @endforeach + +
@lang('contentfilter::fields.name')@lang('contentfilter::fields.search')@lang('contentfilter::fields.replace')
{{$filter->name}}{{$filter->search}}{{$filter->replace}} + + + + + @include('admin/snippets.buttons.delete', ['action' => route('contentfilter.destroy', ['contentfilter' => $filter])]) +
+ + @else +
+ @lang('contentfilter::contentfilter.noItems') +
+ @endif + +
+@endsection \ No newline at end of file