AnonSec Shell
Server IP : 213.186.33.4  /  Your IP : 216.73.216.193
Web Server : Apache
System : Linux webm006.cluster103.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64
User : awebpaca ( 35430)
PHP Version : 8.5.0
Disable Function : _dyuweyrj4,_dyuweyrj4r,dl
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/awebpaca/piwik/core/DataTable/Filter/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/awebpaca/piwik/core/DataTable/Filter/Pattern.php
<?php
/**
 * Matomo - free/libre analytics platform
 *
 * @link https://matomo.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 *
 */
namespace Piwik\DataTable\Filter;

use Piwik\DataTable;
use Piwik\DataTable\BaseFilter;

/**
 * Deletes every row for which a specific column does not match a supplied regex pattern.
 *
 * **Example**
 *
 *     // filter out all rows whose labels doesn't start with piwik
 *     $dataTable->filter('Pattern', array('label', '^piwik'));
 *
 * @api
 */
class Pattern extends BaseFilter
{
    /**
     * @var string|array
     */
    private $columnToFilter;
    private $patternToSearch;
    private $patternToSearchQuoted;
    private $invertedMatch;

    /**
     * Constructor.
     *
     * @param DataTable $table The table to eventually filter.
     * @param string $columnToFilter The column to match with the `$patternToSearch` pattern.
     * @param string $patternToSearch The regex pattern to use.
     * @param bool $invertedMatch Whether to invert the pattern or not. If true, will remove
     *                            rows if they match the pattern.
     */
    public function __construct($table, $columnToFilter, $patternToSearch, $invertedMatch = false)
    {
        parent::__construct($table);
        $this->patternToSearch = $patternToSearch;
        $this->patternToSearchQuoted = self::getPatternQuoted($patternToSearch);
        $this->columnToFilter = $columnToFilter;
        $this->invertedMatch = $invertedMatch;
    }

    /**
     * Helper method to return the given pattern quoted
     *
     * @param string $pattern
     * @return string
     * @ignore
     */
    public static function getPatternQuoted($pattern)
    {
        return '/' . str_replace('/', '\/', $pattern) . '/';
    }

    /**
     * Performs case insensitive match
     *
     * @param string $patternQuoted
     * @param string $string
     * @param bool $invertedMatch
     * @return int
     * @ignore
     */
    public static function match($patternQuoted, $string, $invertedMatch = false)
    {
        return preg_match($patternQuoted . "i", $string) == 1 ^ $invertedMatch;
    }

    /**
     * See {@link Pattern}.
     *
     * @param DataTable $table
     */
    public function filter($table)
    {
        foreach ($table->getRows() as $key => $row) {
            //instead search must handle
            // - negative search with -piwik
            // - exact match with ""
            // see (?!pattern) 	A subexpression that performs a negative lookahead search, which matches the search string at any point where a string not matching pattern begins.
            $value = $row->getColumn($this->columnToFilter);
            if ($value === false) {
                $value = $row->getMetadata($this->columnToFilter);
            }
            if (!self::match($this->patternToSearchQuoted, $value, $this->invertedMatch)) {
                $table->deleteRow($key);
            }
        }
    }

    /**
     * See {@link Pattern}.
     *
     * @param array $array
     * @return array
     */
    public function filterArray($array)
    {
        $newArray = array();

        foreach ($array as $key => $row) {
            foreach ($this->columnToFilter as $column) {
                if (!array_key_exists($column, $row)) {
                    continue;
                }

                if (self::match($this->patternToSearchQuoted, $row[$column], $this->invertedMatch)) {
                    $newArray[$key] = $row;
                    continue 2;
                }
            }
        }

        return $newArray;
    }
}

Anon7 - 2022
AnonSec Team