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 */ static public function getPatternQuoted($pattern) { return '/' . str_replace('/', '\/', $pattern) . '/'; } /** * Performs case insensitive match * * @param string $pattern * @param string $patternQuoted * @param string $string * @param bool $invertedMatch * @return int */ static public function match($pattern, $patternQuoted, $string, $invertedMatch) { return @preg_match($patternQuoted . "i", $string) == 1 ^ $invertedMatch; } /** * @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->patternToSearch, $this->patternToSearchQuoted, $value, $this->invertedMatch)) { $table->deleteRow($key); } } } }