INIT: initial commit
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'name' => '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,
|
||||
];
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateContentFilterTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run migration
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('content_filters', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ContentFilter\Entities;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ContentFilter extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'active',
|
||||
'name',
|
||||
'search',
|
||||
'replace'
|
||||
];
|
||||
protected $casts = [
|
||||
'active' => 'boolean'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ContentFilter\Handlers;
|
||||
|
||||
use App\CMS\Handlers\BaseHandler;
|
||||
use App\Models\User;
|
||||
|
||||
class ContentFilterHandler extends BaseHandler
|
||||
{
|
||||
/**
|
||||
* Register admin menu
|
||||
*
|
||||
* @param User $user
|
||||
*/
|
||||
public static function registerAdminMenu(User $user)
|
||||
{
|
||||
// register links in admin menu
|
||||
$menu = \Menu::instance('mainMenu');
|
||||
|
||||
$system = $menu->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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ContentFilter\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Admin\Controller;
|
||||
use Modules\ContentFilter\Entities\ContentFilter as ContentFilterEntity;
|
||||
use Modules\ContentFilter\Http\Requests\CreateContentFilter;
|
||||
use Modules\ContentFilter\Http\Requests\UpdateContentFilter;
|
||||
use Modules\ContentFilter\Repositories\ContentFilterRepository;
|
||||
|
||||
class ContentFilter extends Controller
|
||||
{
|
||||
/**
|
||||
* @var ContentFilterRepository
|
||||
*/
|
||||
private $contentfilterRepository;
|
||||
|
||||
public function __construct(ContentFilterRepository $contentfilterRepository)
|
||||
{
|
||||
$this->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'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ContentFilter\Http\Requests;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
|
||||
class CreateContentFilter extends Request
|
||||
{
|
||||
public function rules()
|
||||
{
|
||||
return ['name' => 'required', 'search' => 'required', 'replace' => 'required'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ContentFilter\Http\Requests;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
|
||||
class UpdateContentFilter extends Request
|
||||
{
|
||||
public function rules()
|
||||
{
|
||||
return ['name' => 'required', 'search' => 'required', 'replace' => 'required'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
\Route::group([
|
||||
'prefix' => \LaravelLocalization::setLocale() . '/admin',
|
||||
'middleware' => ['admin', 'bindings'],
|
||||
'namespace' => 'Modules\ContentFilter\Http\Controllers\Admin'
|
||||
], function () {
|
||||
|
||||
Route::resource('contentfilter', 'ContentFilter');
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ContentFilter\Pipelines\Display;
|
||||
|
||||
use App\CMS\Contracts\Content\DisplayPipeline\Process;
|
||||
use App\Models\Content\Content;
|
||||
use Modules\ContentFilter\Entities\ContentFilter;
|
||||
|
||||
class Filter implements Process
|
||||
{
|
||||
protected $filters;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ContentFilter\Providers;
|
||||
|
||||
use App\CMS\Modules\ServiceProviders\ServiceProvider;
|
||||
use Modules\ContentFilter\Pipelines\Display\Filter;
|
||||
|
||||
/**
|
||||
* Class ContentFilterServiceProvider
|
||||
*
|
||||
* Service provider for module ContentFilter
|
||||
*
|
||||
* @package Modules\ContentFilter\Providers
|
||||
*/
|
||||
class ContentFilterServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Set module Alias
|
||||
*/
|
||||
protected function setModuleAlias()
|
||||
{
|
||||
$this->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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace Modules\ContentFilter\Repositories;
|
||||
|
||||
use \Modules\ContentFilter\Entities\ContentFilter as ContentFilterEntity;
|
||||
|
||||
class ContentFilterRepository {
|
||||
/**
|
||||
* Create new instance of entity
|
||||
*
|
||||
* @param $data
|
||||
*/
|
||||
public function create($data) {
|
||||
ContentFilterEntity::create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update entity
|
||||
*
|
||||
* @param ContentFilterEntity $entity
|
||||
*/
|
||||
public function update(ContentFilterEntity $entity, $data) {
|
||||
$entity->update($data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'name' => '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'
|
||||
];
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'name' => 'Jméno',
|
||||
'search' => 'Vyhledat co',
|
||||
'replace' => 'Nahradit za'
|
||||
];
|
||||
@@ -0,0 +1,17 @@
|
||||
@extends('admin.layoutWithNavigation')
|
||||
|
||||
@section('pageHeading', @trans('contentfilter::contentfilter.name'))
|
||||
|
||||
@section('headerButtons')
|
||||
<a class="btn btn-secondary btn-sm rounded" href="{{route('contentfilter.index')}}">
|
||||
<i class="fa fa-list"></i>
|
||||
</a>
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div class="card items">
|
||||
<div class="card-block">
|
||||
@include('contentfilter::admin.form', ['action' => route('contentfilter.store'), 'method' => 'post'])
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@@ -0,0 +1,17 @@
|
||||
@extends('admin.layoutWithNavigation')
|
||||
|
||||
@section('pageHeading', @trans('contentfilter::contentfilter.name'))
|
||||
|
||||
@section('headerButtons')
|
||||
<a class="btn btn-secondary btn-sm rounded" href="{{route('contentfilter.index')}}">
|
||||
<i class="fa fa-list"></i>
|
||||
</a>
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div class="card items">
|
||||
<div class="card-block">
|
||||
@include('contentfilter::admin.form', ['action' => route('contentfilter.update', ['contentfilter' => $filter]), 'method' => 'put'])
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@@ -0,0 +1,36 @@
|
||||
<form action="{{$action}}" method="post">
|
||||
{!! csrf_field() !!}
|
||||
{!! method_field($method) !!}
|
||||
|
||||
|
||||
<label class="label-control">
|
||||
@lang('contentfilter::fields.name')
|
||||
</label>
|
||||
<input class="form-control" type="text" name="name" placeholder="@lang('contentfilter::fields.name')"
|
||||
value="{{old('name', $filter->name)}}" />
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6"><label class="label-control">
|
||||
@lang('contentfilter::fields.search')
|
||||
</label>
|
||||
|
||||
<input class="form-control" type="text" name="search" placeholder="@lang('contentfilter::fields.search')"
|
||||
value="{{old('search', $filter->search)}}" />
|
||||
|
||||
@include('admin.snippets.hasError', ['field' => 'search'])
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="label-control">
|
||||
@lang('contentfilter::fields.replace')
|
||||
</label>
|
||||
|
||||
<input class="form-control" type="text" name="replace" placeholder="@lang('contentfilter::fields.replace')"
|
||||
value="{{old('replace', $filter->replace)}}" />
|
||||
|
||||
@include('admin.snippets.hasError', ['field' => 'replace'])
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input type="submit" class="btn btn-primary" value="@lang('contentfilter::contentfilter.save')">
|
||||
</form>
|
||||
@@ -0,0 +1,52 @@
|
||||
@extends('admin.layoutWithNavigation')
|
||||
|
||||
@section('pageHeading', @trans('contentfilter::contentfilter.overview'))
|
||||
|
||||
@section('headerButtons')
|
||||
<a class="btn btn-secondary btn-sm rounded" href="{{route('contentfilter.create')}}">
|
||||
<i class="fa fa-plus"></i>
|
||||
</a>
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
@if (!$filters->isEmpty())
|
||||
<div class="card items">
|
||||
<div class="card-block">
|
||||
<table class="table full-width">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>@lang('contentfilter::fields.name')</th>
|
||||
<th>@lang('contentfilter::fields.search')</th>
|
||||
<th>@lang('contentfilter::fields.replace')</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($filters as $filter)
|
||||
<tr>
|
||||
<td>{{$filter->name}}</td>
|
||||
<td>{{$filter->search}}</td>
|
||||
<td>{{$filter->replace}}</td>
|
||||
<td class="text-right">
|
||||
<a class="btn btn-secondary btn-sm rounded"
|
||||
href="{{route('contentfilter.edit', ['contentfilter' => $filter])}}">
|
||||
<i class="fa fa-pencil"></i>
|
||||
</a>
|
||||
|
||||
@include('admin/snippets.buttons.delete', ['action' => route('contentfilter.destroy', ['contentfilter' => $filter])])
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="card-footer">
|
||||
{!! $filters->render() !!}
|
||||
</div>
|
||||
@else
|
||||
<div class="alert alert-info">
|
||||
<em>@lang('contentfilter::contentfilter.noItems')</em>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
</div>
|
||||
@endsection
|
||||
Reference in New Issue
Block a user