summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b63628e)
raw | patch | inline | side by side (parent: b63628e)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 5 Oct 2010 06:11:43 +0000 (06:11 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 5 Oct 2010 06:11:43 +0000 (06:11 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19913 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-core/include/functions.inc | patch | blob | history |
index ae3624984a2c54fda029661d09cb10b6d9d5a9d0..59725b1d18216c6952338ff1b3456ade722b06e0 100644 (file)
* @param Array An array of replacements.
* @return The resulting string.
*/
-function fillReplacements($str, $attrs, $shellArg = FALSE)
+function fillReplacements($str, $attrs, $shellArg = FALSE, $default = "")
{
// Search for '%...{...}
// Get all matching parts of the given string and sort them by
// Replace the placeholder in the given string now.
foreach($hits as $match){
+
+ // Avoid errors about undefined index.
+ if(!isset($attrs[$name])) $attrs[$name] = $default;
+
+ // Calculate the replacement
$name = $match[2];
$start = (isset($match[5])) ? $match[5] : 0;
$end = (isset($match[7])) ? $match[7] : strlen($attrs[$name]);
$value = substr($attrs[$name], $start, $end);
+
+ // Use values which are valid for shell execution?
if($shellArg) $value = escapeshellarg($value);
+
+ // Replace the placeholder within the string.
$str = preg_replace("/".preg_quote($match[0],'/')."/", $value, $str);
}
return($str);