add priority on filters for replacement order

master
Jean-Christian Paul Denis 2021-10-31 23:50:38 +01:00
parent 6a6f810d78
commit 6b36cac180
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
4 changed files with 21 additions and 9 deletions

View File

@ -1,7 +1,6 @@
dev dev
- [ ] add priority on filters for replacement order
- [ ] add priority on lists of filters for replacement order
- [ ] add auto-find post title in content - [ ] add auto-find post title in content
- add priority on filters for replacement order
- split filters into modules - split filters into modules
- add autosubmit onadmin menu - add autosubmit onadmin menu
- move sort options from blog pref to user pref - move sort options from blog pref to user pref

View File

@ -19,6 +19,7 @@ abstract class epcFilter
private $records = null; private $records = null;
private $properties = [ private $properties = [
'priority' => 500,
'name' => 'undefined', 'name' => 'undefined',
'help' => 'undefined', 'help' => 'undefined',
'has_list' => false, 'has_list' => false,

View File

@ -16,12 +16,13 @@ class epcFilterTag extends epcFilter
protected function init(): string protected function init(): string
{ {
$this->setProperties([ $this->setProperties([
'name' => __('Tag'), 'priority' => 900,
'help' => __('Highlight tags of your blog.'), 'name' => __('Tag'),
'htmltag' => 'a', 'help' => __('Highlight tags of your blog.'),
'class' => ['a.epc-tag'], 'htmltag' => 'a',
'replace' => '<a class="epc-tag" href="%s" title="' . __('Tag') . '">%s</a>', 'class' => ['a.epc-tag'],
'widget' => '<a href="%s" title="' . __('Tag') . '">%s</a>' 'replace' => '<a class="epc-tag" href="%s" title="' . __('Tag') . '">%s</a>',
'widget' => '<a href="%s" title="' . __('Tag') . '">%s</a>'
]); ]);
$this->setSettings([ $this->setSettings([
@ -80,6 +81,7 @@ class epcFilterSearch extends epcFilter
protected function init(): string protected function init(): string
{ {
$this->setProperties([ $this->setProperties([
'priority' => 100,
'name' => __('Search'), 'name' => __('Search'),
'help' => __('Highlight searched words.'), 'help' => __('Highlight searched words.'),
'htmltag' => '', 'htmltag' => '',
@ -125,6 +127,7 @@ class epcFilterAcronym extends epcFilter
protected function init(): string protected function init(): string
{ {
$this->setProperties([ $this->setProperties([
'priority' => 700,
'name' => __('Acronym'), 'name' => __('Acronym'),
'help' => __('Explain some acronyms. First term of the list is the acornym and second term the explanation.'), 'help' => __('Explain some acronyms. First term of the list is the acornym and second term the explanation.'),
'has_list' => true, 'has_list' => true,
@ -178,6 +181,7 @@ class epcFilterAbbreviation extends epcFilter
protected function init(): string protected function init(): string
{ {
$this->setProperties([ $this->setProperties([
'priority' => 400,
'name' => __('Abbreviation'), 'name' => __('Abbreviation'),
'help' => __('Explain some abbreviation. First term of the list is the abbreviation and second term the explanation.'), 'help' => __('Explain some abbreviation. First term of the list is the abbreviation and second term the explanation.'),
'has_list' => true, 'has_list' => true,
@ -231,6 +235,7 @@ class epcFilterDefinition extends epcFilter
protected function init(): string protected function init(): string
{ {
$this->setProperties([ $this->setProperties([
'priority' => 800,
'name' => __('Definition'), 'name' => __('Definition'),
'help' => __('Explain some definition. First term of the list is the sample to define and second term the explanation.'), 'help' => __('Explain some definition. First term of the list is the sample to define and second term the explanation.'),
'has_list' => true, 'has_list' => true,
@ -284,6 +289,7 @@ class epcFilterCitation extends epcFilter
protected function init(): string protected function init(): string
{ {
$this->setProperties([ $this->setProperties([
'priority' => 600,
'name' => __('Citation'), 'name' => __('Citation'),
'help' => __('Highlight citation of people. First term of the list is the citation and second term the author.'), 'help' => __('Highlight citation of people. First term of the list is the citation and second term the author.'),
'has_list' => true, 'has_list' => true,
@ -338,6 +344,7 @@ class epcFilterLink extends epcFilter
protected function init(): string protected function init(): string
{ {
$this->setProperties([ $this->setProperties([
'priority' => 500,
'name' => __('Link'), 'name' => __('Link'),
'help' => __('Link some words. First term of the list is the term to link and second term the link.'), 'help' => __('Link some words. First term of the list is the term to link and second term the link.'),
'has_list' => true, 'has_list' => true,
@ -391,6 +398,7 @@ class epcFilterReplace extends epcFilter
protected function init(): string protected function init(): string
{ {
$this->setProperties([ $this->setProperties([
'priority' => 200,
'name' => __('Replace'), 'name' => __('Replace'),
'help' => __('Replace some text. First term of the list is the text to replace and second term the replacement.'), 'help' => __('Replace some text. First term of the list is the text to replace and second term the replacement.'),
'has_list' => true, 'has_list' => true,
@ -431,6 +439,7 @@ class epcFilterUpdate extends epcFilter
protected function init(): string protected function init(): string
{ {
$this->setProperties([ $this->setProperties([
'priority' => 300,
'name' => __('Update'), 'name' => __('Update'),
'help' => __('Update and show terms. First term of the list is the term to update and second term the new term.'), 'help' => __('Update and show terms. First term of the list is the term to update and second term the new term.'),
'has_list' => true, 'has_list' => true,
@ -471,6 +480,7 @@ class epcFilterTwitter extends epcFilter
protected function init(): string protected function init(): string
{ {
$this->setProperties([ $this->setProperties([
'priority' => 1000,
'name' => __('Twitter'), 'name' => __('Twitter'),
'help' => __('Add link to twitter user page. Every word started with "@" will be considered as twitter user.'), 'help' => __('Add link to twitter user page. Every word started with "@" will be considered as twitter user.'),
'htmltag' => 'a', 'htmltag' => 'a',

View File

@ -103,7 +103,7 @@ class libEPC
global $core; global $core;
if (self::$default_filters === null) { if (self::$default_filters === null) {
$final = []; $final = $sort = [];
$filters = new arrayObject(); $filters = new arrayObject();
try { try {
@ -111,12 +111,14 @@ class libEPC
foreach($filters as $filter) { foreach($filters as $filter) {
if ($filter instanceOf epcFilter && !isset($final[$filter->id()])) { if ($filter instanceOf epcFilter && !isset($final[$filter->id()])) {
$sort[$filter->id()] = $filter->priority;
$final[$filter->id()] = $filter; $final[$filter->id()] = $filter;
} }
} }
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
array_multisort($sort, $final);
self::$default_filters = $final; self::$default_filters = $final;
} }