# Custom filter

All custom scripts must be stored in directory /var/www/keitaro/application/filters.

# How to create new filter

Create a new file /var/www/keitaro/application/filters/example.php with content:

<?php
namespace Filters;
 
use Core\Filter\AbstractFilter;
use Core\Locale\LocaleService;
use Traffic\Model\StreamFilter;
use Traffic\RawClick;
 
class example extends AbstractFilter
{
    public function getModes()
    {
        return [
            StreamFilter::ACCEPT => LocaleService::t('filters.binary_options.' . StreamFilter::ACCEPT),
            StreamFilter::REJECT => LocaleService::t('filters.binary_options.' . StreamFilter::REJECT),
        ];
    }
    /**
     * Filter settings template
     */
    public function getTemplate()
    {
        return '<input class="form-control" ng-model="filter.payload" />';
    }
 
    /**
     * Check if $rawClick passes the filter (true - passed, false - failed)
     */
    public function isPass(StreamFilter $filter, RawClick $rawClick)
    {
        $value = $filter->getPayload();
        return ($filter->getMode() == StreamFilter::ACCEPT && $rawClick->getSubIdN(1) == $value)
            || ($filter->getMode() == StreamFilter::REJECT && $rawClick->getSubIdN(1) == $value);
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

You must implement these methods:

Method Description
getModes Return key-value list of available modes
getTemplate HTML template for filter settings. Use ng-model="filter.payload" in the input.
isPass Method checks if click passes conditions or not. Return true if yes, false if no.

# See also