INIT: initial commit
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user