mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-26 16:48:49 +01:00
use raw custom-field data for yaml files, no user-preference specific formatting, all to use regular expressions in yaml files to modify content of placeholders, eg. commas with linebreaks: "{{name/, */\n}}"
This commit is contained in:
parent
d02ca8ecb5
commit
5449825beb
@ -263,7 +263,10 @@ abstract class bo_merge
|
|||||||
foreach($this->contacts->customfields as $name => $field)
|
foreach($this->contacts->customfields as $name => $field)
|
||||||
{
|
{
|
||||||
$name = '#'.$name;
|
$name = '#'.$name;
|
||||||
$replacements['$$'.($prefix ? $prefix.'/':'').$name.'$$'] = egw_customfields::format($field, (string)$contact[$name]);
|
$replacements['$$'.($prefix ? $prefix.'/':'').$name.'$$'] =
|
||||||
|
// use raw data for yaml, no user-preference specific formatting
|
||||||
|
$this->mimetype == 'application/x-yaml' ? (string)$contact[$name] :
|
||||||
|
egw_customfields::format($field, (string)$contact[$name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add in extra cat field
|
// Add in extra cat field
|
||||||
@ -1089,13 +1092,25 @@ abstract class bo_merge
|
|||||||
}
|
}
|
||||||
if ($mimetype == 'application/x-yaml')
|
if ($mimetype == 'application/x-yaml')
|
||||||
{
|
{
|
||||||
$content = preg_replace_callback('/^( +)(\$\$[^$]+\$\$)/m', function($matches) use ($replacements)
|
$content = preg_replace_callback('/^( +)([^$\n]*)(\$\$.+?\$\$)/m', function($matches) use ($replacements)
|
||||||
{
|
{
|
||||||
$replacement = $replacements[$matches[2]];
|
// allow with {{name/replace/with}} syntax to replace eg. commas with linebreaks: "{{name/, */\n}}"
|
||||||
// replacement with multiple lines --> add same number of space as before placeholder
|
$parts = null;
|
||||||
if (isset($replacement) && strpos($replacement, "\n") !== false)
|
if (preg_match('|^\$\$([^/]+)/([^/]+)/([^$]*)\$\$$|', $matches[3], $parts) && isset($replacements['$$'.$parts[1].'$$']))
|
||||||
{
|
{
|
||||||
return $matches[1].implode("\n".$matches[1], preg_split("/\r?\n/", $replacement));
|
$replacement =& $replacements['$$'.$parts[1].'$$'];
|
||||||
|
$replacement = preg_replace('/'.$parts[2].'/', strtr($parts[3], array(
|
||||||
|
'\\n' => "\n", '\\r' => "\r", '\\t' => "\t", '\\v' => "\v", '\\\\' => '\\', '\\f' => "\f",
|
||||||
|
)), $replacement);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$replacement =& $replacements[$matches[3]];
|
||||||
|
}
|
||||||
|
// replacement with multiple lines --> add same number of space as before placeholder
|
||||||
|
if (isset($replacement))
|
||||||
|
{
|
||||||
|
return $matches[1].$matches[2].implode("\n".$matches[1], preg_split("/\r?\n/", $replacement));
|
||||||
}
|
}
|
||||||
return $matches[0]; // regular replacement below
|
return $matches[0]; // regular replacement below
|
||||||
}, $content);
|
}, $content);
|
||||||
|
Loading…
Reference in New Issue
Block a user