A filter is an implementation of the command pattern.
You can download the filter sandbox in order to have a skeleton to develop your plug-in but you'll see
how simple it is!
As software developer we like to start with some code:
require_once(FILTERPATH.'/filtercommand.php');
require_once(FILTERPATH.'/articlefilterremote.php');
class ProofFilter implements FilterCommand {
function execute($string){
return $string." filter executed";
}
}
$filter= new ProofFilter();
$articleRemote = ArticleFilterRemote::getInstance();
$articleRemote->addFiltersGetTitle($filter);
This is just a little example, this filter add the string " filter executed" to every Article
title. It is not really useful but is good to give you an idea.
After you understand this you can try to do someting more interesting, maybe with some table
of words to filter saved in a database.
Ad the start of the script we include the filtercommand interface and the articlefilterremote singleton.
If you are curious about this script just check the files filtercommand.php and articlefilterremote.php in the
admin/filters directory in your EasyMagazine installation.
Then we create the class ProofFilter that implements the interface FilterCommand.
This means that we must create a method execute($string). This method will be executed
every time the trigger is pulled.
Be careful a filter needs an input and an output so you must implement a String parameter and you
must return a String output.
That's it, the filter is ready! :-)
Now we need to decide to what of database fileds the filter has to be connected.
We decide to let it execute everytime the Title of an
Article is showed in the magazine!
So we create an instance of the filter ProofFilter, we get the instance of the ArticleFilterRemote singleton and we add the $filter instance to the filter array calling $remote->addFiltersGetTitle.
Now we finished, the filter will be executed as we desire, every time the Article title is showed in the website.
Now a list of what Entity you can attach a filter to:
Article:
(you need to include articlefilterremote.php)
Comment:
(you need to include commentfilterremote.php)
Number:
(you need to include numberfilterremote.php)
Page:
(you need to include pagefilterremote.php)