From 8ad74b5dda9626f1237e1df96a1183f573d254d2 Mon Sep 17 00:00:00 2001 From: TJ Date: Sun, 9 Oct 2011 16:33:57 +0100 Subject: [PATCH 1/2] 4885: Message.printAbstract() should indicate when additional message parameters are not used --- include/classes/Message/Message.class.php | 34 ++++++++++++++++------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/include/classes/Message/Message.class.php b/include/classes/Message/Message.class.php index ad4f5acb..1f36ebf0 100644 --- a/include/classes/Message/Message.class.php +++ b/include/classes/Message/Message.class.php @@ -97,16 +97,30 @@ function printAbstract($type) { /* this is an array with terms to replace */ $first = array_shift($item); - $result = _AT($first); // lets translate the code - - if ($result == '') { // if the code is not in the db lets just print out the code for easier trackdown - $result = '[' . $first . ']'; + $format_specifier = _AT($first); // lets translate the code + + if ($format_specifier == '') { // if the code is not in the db lets just print out the code for easier trackdown + $format_specifier = '[' . $first . ']'; + } + + /* replace the format-specifier tokens in DB language_text.text field with the terms */ + $result = vsprintf($format_specifier, $item); + /* Improve code quality. Detect specifiers that are not used. + This will highlight language_text.term entries that are missing format-specifiers */ + $match_fs = array(); + $count_fs = preg_match_all('/[^\d]%[^%]|\s]/', $format_specifier, $match_fs); + $count_item = count($item); + if (strcmp($result, $format_specifier) == 0 || $count_item != $count_fs) { + // $item array has elements that appear to have been ignored so give a warning + trigger_error('ERROR: language_text term '.$first.' is missing one or more format specifiers. Expected ' + .$count_item.' but got '.$count_fs); + // now add the missed elements to the message + $idx = 0; + foreach($item as $element) { + if ($idx++ >= $count_fs) + $result .= ' ' . $element; + } } - - $terms = $item; - - /* replace the tokens with the terms */ - $result = vsprintf($result, $terms); } else { $result = _AT($item); @@ -469,4 +483,4 @@ function deleteHelp($code) { -?> \ No newline at end of file +?> From 1b2038327d3bac87c3d02e133ad47ab43752f71c Mon Sep 17 00:00:00 2001 From: TJ Date: Wed, 2 Nov 2011 23:43:10 +0000 Subject: [PATCH 2/2] 4885: Change sense of regular expression to match format-specifiers --- include/classes/Message/Message.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/classes/Message/Message.class.php b/include/classes/Message/Message.class.php index 1f36ebf0..f915969a 100644 --- a/include/classes/Message/Message.class.php +++ b/include/classes/Message/Message.class.php @@ -108,7 +108,7 @@ function printAbstract($type) { /* Improve code quality. Detect specifiers that are not used. This will highlight language_text.term entries that are missing format-specifiers */ $match_fs = array(); - $count_fs = preg_match_all('/[^\d]%[^%]|\s]/', $format_specifier, $match_fs); + $count_fs = preg_match_all('/(%.*?[a-zA-Z])/', $format_specifier, $match_fs); $count_item = count($item); if (strcmp($result, $format_specifier) == 0 || $count_item != $count_fs) { // $item array has elements that appear to have been ignored so give a warning