From fc60bccf201f022be9a66778262e9136078e10e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be> Date: Tue, 13 Jun 2017 16:19:44 +0200 Subject: [PATCH] Fixes #5602 Added array modifiers --- include/class_templateHandling.inc | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/include/class_templateHandling.inc b/include/class_templateHandling.inc index c40bb6053..6752459c4 100644 --- a/include/class_templateHandling.inc +++ b/include/class_templateHandling.inc @@ -379,15 +379,15 @@ class templateHandling { mb_internal_encoding('UTF-8'); mb_regex_encoding('UTF-8'); - if (is_array($str) && (strtolower($m) == $m)) { + if (is_array($str) && (!is_numeric($m)) && (strtolower($m) == $m)) { /* $str is an array and $m is lowercase, so it's a string modifier */ - $str = $str[0]; + $str = reset($str); } $result = array($str); switch ($m) { case 'F': // First - $result = array($str[0]); + $result = array(reset($str)); break; case 'L': // Last @@ -405,6 +405,22 @@ class templateHandling // Count $result = array(count($str)); break; + case 'M': + // Match + if (count($args) < 1) { + trigger_error('Missing "M" match modifier parameter'); + $args[] = '/.*/'; + } + $result = array(array_filter($str, function ($s) use ($args) { return preg_match($args[0], $s); })); + break; + case '4': + // IPv4 + $result = array(array_filter($str, 'tests::is_ipv4')); + break; + case '6': + // IPv6 + $result = array(array_filter($str, 'tests::is_ipv6')); + break; case 'c': // comment $result = array(''); -- GitLab