Index: trunk/extensions/SemanticForms/includes/SF_ParserFunctions.php |
— | — | @@ -103,8 +103,13 @@ |
104 | 104 | function sfgRegisterParser( &$parser ) { |
105 | 105 | $parser->setFunctionHook('forminput', 'sfRenderFormInput'); |
106 | 106 | $parser->setFunctionHook('formlink', 'sfRenderFormLink'); |
107 | | - $parser->setFunctionHook('arraymap', 'sfRenderArrayMap'); |
108 | | - $parser->setFunctionHook('arraymaptemplate', 'sfRenderArrayMapTemplate'); |
| 107 | + if( defined( get_class( $parser ) . '::SFH_OBJECT_ARGS' ) ) { |
| 108 | + $parser->setFunctionHook('arraymap', 'sfRenderArrayMapObj', SFH_OBJECT_ARGS); |
| 109 | + $parser->setFunctionHook('arraymaptemplate', 'sfRenderArrayMapTemplateObj', SFH_OBJECT_ARGS); |
| 110 | + } else { |
| 111 | + $parser->setFunctionHook('arraymap', 'sfRenderArrayMap'); |
| 112 | + $parser->setFunctionHook('arraymaptemplate', 'sfRenderArrayMapTemplate'); |
| 113 | + } |
109 | 114 | return true; |
110 | 115 | } |
111 | 116 | |
— | — | @@ -174,7 +179,7 @@ |
175 | 180 | /** |
176 | 181 | * {{#arraymap:value|delimiter|var|new_value|new_delimiter}} |
177 | 182 | */ |
178 | | -function sfRenderArrayMap ( &$parser, $value = '', $delimiter = ',', $var = 'x', $new_value = '', $new_delimiter = ', ' ) { |
| 183 | +function sfRenderArrayMap( &$parser, $value = '', $delimiter = ',', $var = 'x', $new_value = 'x', $new_delimiter = ', ' ) { |
179 | 184 | $values_array = explode($parser->mStripState->unstripNoWiki($delimiter), $value); |
180 | 185 | $results = array(); |
181 | 186 | foreach ($values_array as $cur_value) { |
— | — | @@ -189,9 +194,41 @@ |
190 | 195 | } |
191 | 196 | |
192 | 197 | /** |
193 | | - * {{#arraymaptemplate:blue;red;yellow|Beautify|;|;}} |
| 198 | + * SFH_OBJ_ARGS |
| 199 | + * {{#arraymap:value|delimiter|var|new_value|new_delimiter}} |
194 | 200 | */ |
195 | | -function sfRenderArrayMapTemplate ( &$parser, $value = '', $template = '', $delimiter = ',', $new_delimiter = ', ' ) { |
| 201 | +function sfRenderArrayMapObj( &$parser, $frame, $args ) { |
| 202 | + # Set variables |
| 203 | + $value = isset($args[0]) ? $args[0] : ''; |
| 204 | + $delimiter = isset($args[1]) ? $args[1] : ','; |
| 205 | + $var = isset($args[2]) ? $args[2] : 'x'; |
| 206 | + $new_value = isset($args[3]) ? $args[3] : 'x'; |
| 207 | + $new_delimiter = isset($args[4]) ? $args[4] : ', '; |
| 208 | + # Expand some |
| 209 | + $value = trim($frame->expand($value)); |
| 210 | + $delimiter = trim($frame->expand($delimiter)); |
| 211 | + $var = trim($frame->expand($var, PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES)); |
| 212 | + $new_delimiter = trim($frame->expand($new_delimiter)); |
| 213 | + # Unstrip some |
| 214 | + $delimiter = $parser->mStripState->unstripNoWiki($delimiter); |
| 215 | + |
| 216 | + $values_array = explode($delimiter, $value); |
| 217 | + $results_array = array(); |
| 218 | + foreach( $values_array as $old_value ) { |
| 219 | + $old_value = trim($old_value); |
| 220 | + if( $old_value == '' ) continue; |
| 221 | + $result_value = $frame->expand($new_value, PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES); |
| 222 | + $result_value = str_replace($var, $old_value, $result_value); |
| 223 | + $result_value = $parser->preprocessToDom($result_value, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0); |
| 224 | + $results_array[] = trim($frame->expand($result_value)); |
| 225 | + } |
| 226 | + return implode($new_delimiter, $results_array); |
| 227 | +} |
| 228 | + |
| 229 | +/** |
| 230 | + * {{#arraymaptemplate:value|template|delimiter|new_delimiter}} |
| 231 | + */ |
| 232 | +function sfRenderArrayMapTemplate( &$parser, $value = '', $template = '', $delimiter = ',', $new_delimiter = ', ' ) { |
196 | 233 | $values_array = explode($parser->mStripState->unstripNoWiki($delimiter), $value); |
197 | 234 | $results = array(); |
198 | 235 | $template = trim($template); |
— | — | @@ -205,3 +242,28 @@ |
206 | 243 | } |
207 | 244 | return array(implode($new_delimiter, $results), 'noparse' => false, 'isHTML' => false); |
208 | 245 | } |
| 246 | + |
| 247 | +/** |
| 248 | + * SFH_OBJ_ARGS |
| 249 | + * {{#arraymaptemplate:value|template|delimiter|new_delimiter}} |
| 250 | + */ |
| 251 | +function sfRenderArrayMapTemplateObj( &$parser, $frame, $args ) { |
| 252 | + # Set variables |
| 253 | + $value = isset($args[0]) ? trim($frame->expand($args[0])) : ''; |
| 254 | + $template = isset($args[1]) ? trim($frame->expand($args[1])) : ''; |
| 255 | + $delimiter = isset($args[2]) ? trim($frame->expand($args[2])) : ','; |
| 256 | + $new_delimiter = isset($args[3]) ? trim($frame->expand($args[3])) : ', '; |
| 257 | + # Unstrip some |
| 258 | + $delimiter = $parser->mStripState->unstripNoWiki($delimiter); |
| 259 | + |
| 260 | + $values_array = explode($delimiter, $value); |
| 261 | + $results_array = array(); |
| 262 | + foreach( $values_array as $old_value ) { |
| 263 | + $old_value = trim($old_value); |
| 264 | + if( $old_value == '' ) continue; |
| 265 | + $results_array[] = $parser->replaceVariables( |
| 266 | + implode('', $frame->virtualBracketedImplode( '{{', '|', '}}', |
| 267 | + $template, '1='.$old_value )), $frame); |
| 268 | + } |
| 269 | + return implode($new_delimiter, $results_array); |
| 270 | +} |