Custom Stream Filter Script

That feature available only for PRO or higher editions

All the custom scripts must be stored in directory application/filters.

Creating Filter Script

Create a new file application/filters/example.php with code example:

<?php
namespace Filters;
 
use Core\Filter\AbstractFilter;
use Core\Locale\LocaleService;
use Component\StreamFilters\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->getSubId(1) == $value);
    }
}

You must reimplement these methods:

Method Description
getModes Return hash with available filter modes
getTemplate Template for filter settings. More about template syntax here angular.js.
isPass Method checks if click passes conditions or not. Return true if yes, false if no.

Methods of $filter

Method Description
$filter->getPayload() Filter values
$filter->getMode() Current filter mode