44# Copyright (c) 2012 - 2014 MantisBT Team - [email protected] 55# Licensed under the MIT license
66
7+ define ( 'PLACEHOLDER_USER ' , '{user} ' );
8+ define ( 'PLACEHOLDER_REPORTER ' , '{reporter} ' );
9+ define ( 'PLACEHOLDER_HANDLER ' , '{handler} ' );
10+ define ( 'PLACEHOLDER_PROJECT ' , '{project} ' );
11+
712function xmlhttprequest_plugin_snippets_text () {
813 plugin_push_current ("Snippets " );
914
@@ -185,7 +190,7 @@ public static function clean($dirty, $target="view", $pattern=false) {
185190 * @return array Updated snippet objects
186191 */
187192 public static function patterns ($ snippets , $ bug_id ) {
188- $ handler = ' %h ' ;
193+ $ handler = PLACEHOLDER_HANDLER ;
189194
190195 $ current_user = auth_get_current_user_id ();
191196
@@ -209,7 +214,7 @@ public static function patterns($snippets, $bug_id) {
209214
210215 foreach ($ snippets as $ snippet ) {
211216 $ snippet ->value = str_replace (
212- array (' %u ' , ' %r ' , ' %h ' , ' %p ' ),
217+ array (PLACEHOLDER_USER , PLACEHOLDER_REPORTER , PLACEHOLDER_HANDLER , PLACEHOLDER_PROJECT ),
213218 array ($ username , $ reporter , $ handler , $ project ),
214219 $ snippet ->value );
215220 }
@@ -334,7 +339,11 @@ public static function delete_by_user_id($user_id) {
334339 private static function from_db_result ($ result ) {
335340 $ snippets = array ();
336341 while ($ row = db_fetch_array ($ result )) {
337- $ snippet = new Snippet ($ row ["type " ], $ row ["name " ], $ row ["value " ], $ row ["user_id " ]);
342+ $ snippet = new Snippet (
343+ $ row ['type ' ],
344+ $ row ['name ' ],
345+ Snippet::replace_legacy_placeholders ($ row ['value ' ]),
346+ $ row ['user_id ' ]);
338347 $ snippet ->id = $ row ["id " ];
339348
340349 $ snippets [$ row ["id " ]] = $ snippet ;
@@ -343,6 +352,21 @@ private static function from_db_result($result) {
343352 return $ snippets ;
344353 }
345354
355+ /**
356+ * Replace legacy placeholders (e.g. %u) with modern ones (e.g. {user}).
357+ *
358+ * @param string $p_value The snippet to process.
359+ * @return string The processed snippet.
360+ */
361+ private static function replace_legacy_placeholders ($ p_value ) {
362+ $ t_value = $ p_value ;
363+ $ t_value = str_replace ('%u ' , PLACEHOLDER_USER , $ t_value );
364+ $ t_value = str_replace ('%r ' , PLACEHOLDER_REPORTER , $ t_value );
365+ $ t_value = str_replace ('%h ' , PLACEHOLDER_HANDLER , $ t_value );
366+ $ t_value = str_replace ('%p ' , PLACEHOLDER_PROJECT , $ t_value );
367+ return $ t_value ;
368+ }
369+
346370 public static function global_url ($ p_is_global = true ) {
347371 if ($ p_is_global ) {
348372 return '&global=true ' ;
0 commit comments