From 240b8eac317ed91f6ac293889f12c7f5efa938f5 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 27 Aug 2007 13:00:45 +0000 Subject: [PATCH] some new features for the infolog-widget to improve form printting: 1) fetching contact fields from linked infolog entries, 2) formatting content with preg_replace --- infolog/inc/class.infolog_widget.inc.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/infolog/inc/class.infolog_widget.inc.php b/infolog/inc/class.infolog_widget.inc.php index 9d68c1fe0d..80f0dd3a98 100644 --- a/infolog/inc/class.infolog_widget.inc.php +++ b/infolog/inc/class.infolog_widget.inc.php @@ -99,7 +99,7 @@ class infolog_widget $value = ''; break; } - list($type,$compare,$alternatives) = explode(',',$cell['size']); + list($type,$compare,$alternatives,$contactfield,$regex,$replace) = explode(',',$cell['size'],6); $value = $this->info[$type]; $cell['size'] = ''; $cell['no_lang'] = 1; @@ -109,7 +109,7 @@ class infolog_widget { case '': // Sum of the alternatives $cell['type'] = 'float'; - $cell['size'] = ',,,2'; + $cell['size'] = ',,,%0.2lf'; $value = 0.0; foreach(explode(':',$alternatives) as $name) { @@ -174,6 +174,23 @@ class infolog_widget $value = $value == $compare ? 'X' : ''; $cell['type'] = 'label'; } + // modify the value with a regular expression + if (!empty($regex)) + { + $parts = explode('/',$regex); + if (strchr(array_pop($parts),'e') === false) // dont allow e modifier, which would execute arbitrary php code + { + $value = preg_replace($regex,$replace,$value); + } + $cell['type'] = 'label'; + $cell['size'] = ''; + } + // use a contact widget to render the value, eg. to fetch contact data from an linked infolog + if (!empty($contactfield)) + { + $cell['type'] = 'contact-value'; + $cell['size'] = $contactfield; + } break; } return True; // extra label ok