From 58a2dec2c61ba451d9c2e41f451d99c90185b5f8 Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 5 Oct 2010 07:18:50 +0000 Subject: [PATCH] Updated replacement handling -> use [n-m] instead of {0:3} git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19914 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-core/include/functions.inc | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/gosa-core/include/functions.inc b/gosa-core/include/functions.inc index 59725b1d1..338ab70da 100644 --- a/gosa-core/include/functions.inc +++ b/gosa-core/include/functions.inc @@ -3865,10 +3865,10 @@ function detectLdapSpecialCharHandling() * '%uid@gonicus.de' Replaces '%uid' with 'uid'. * '%uid{0}@gonicus.de' Replaces '%uid{0}' with the first char of 'uid'. * '%uid{2:4}@gonicus.de' Replaces '%uid{2:4}' with three chars from 'uid' starting from the second. - * + * * @param String The string to perform the action on. * @param Array An array of replacements. - * @return The resulting string. + * @return The resulting string. */ function fillReplacements($str, $attrs, $shellArg = FALSE, $default = "") { @@ -3876,7 +3876,7 @@ function fillReplacements($str, $attrs, $shellArg = FALSE, $default = "") // Get all matching parts of the given string and sort them by // length, to avoid replacing strings like '%uidNumber' with 'uid' // instead of 'uidNumber'; The longest tring at first. - preg_match_all('/(%([a-z0-9]+)(\{(([0-9]+)(:([0-9]+))?)\})?)/i', $str ,$matches, PREG_SET_ORDER); + preg_match_all('/(\{?%([a-z0-9]+)(\[(([0-9]+)(\-([0-9]+))?)\])?\}?)/i', $str ,$matches, PREG_SET_ORDER); $hits = array(); foreach($matches as $match){ $hits[strlen($match[2]).$match[0]] = $match; @@ -3887,12 +3887,17 @@ function fillReplacements($str, $attrs, $shellArg = FALSE, $default = "") foreach($hits as $match){ // Avoid errors about undefined index. + $name = $match[2]; if(!isset($attrs[$name])) $attrs[$name] = $default; - // Calculate the replacement - $name = $match[2]; + // Calculate the replacement $start = (isset($match[5])) ? $match[5] : 0; - $end = (isset($match[7])) ? $match[7] : strlen($attrs[$name]); + $end = strlen($attrs[$name]); + if(isset($match[5]) && !isset($match[7])){ + $end = 1; + }elseif(isset($match[5]) && isset($match[7])){ + $end = ($match[7]-$start+1); + } $value = substr($attrs[$name], $start, $end); // Use values which are valid for shell execution? @@ -3904,6 +3909,5 @@ function fillReplacements($str, $attrs, $shellArg = FALSE, $default = "") return($str); } - // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?> -- 2.30.2