Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Improved 'cleaning' of optional data parameter in get_string() to inc…

…lude objects
  • Loading branch information...
commit 1a08f75e5031acad7363e3fee001fdcf559f368f 1 parent 9ef1ef1
authored June 21, 2005

Showing 1 changed file with 25 additions and 1 deletion. Show diff stats Hide diff stats

  1. 26  lib/moodlelib.php
26  lib/moodlelib.php
@@ -4243,6 +4243,30 @@ function print_string($identifier, $module='', $a=NULL) {
4243 4243
 }
4244 4244
 
4245 4245
 /**
  4246
+ * fix up the optional data in get_string()/print_string() etc
  4247
+ * ensure possible sprintf() format characters are escaped correctly
  4248
+ * needs to handle arbitrary strings and objects
  4249
+ * @param mixed $a An object, string or number that can be used
  4250
+ * @return mixed the supplied parameter 'cleaned'
  4251
+ */
  4252
+function clean_a( $a ) {
  4253
+    if (is_string($a)) {
  4254
+        return str_replace( '%','%%',$a );
  4255
+    }
  4256
+    elseif (is_object($a)) {
  4257
+        $a_vars = get_object_vars( $a );
  4258
+        $new_a_vars = array();
  4259
+        foreach ($a_vars as $fname => $a_var) {
  4260
+            $new_a_vars[$fname] = clean_a( $a_var );
  4261
+        }
  4262
+        return (object)$new_a_vars;
  4263
+    } 
  4264
+    else {
  4265
+        return $a;
  4266
+    }
  4267
+}
  4268
+
  4269
+/**
4246 4270
  * Returns a localized string.
4247 4271
  *
4248 4272
  * Returns the translated string specified by $identifier as
@@ -4312,7 +4336,7 @@ function get_string($identifier, $module='', $a=NULL) {
4312 4336
     }
4313 4337
 
4314 4338
     // if $a happens to have % in it, double it so sprintf() doesn't break
4315  
-    $a = str_replace( '%','%%',$a );
  4339
+    $a = clean_a( $a );
4316 4340
 
4317 4341
 /// Define the two or three major locations of language strings for this module
4318 4342
 

0 notes on commit 1a08f75

Please sign in to comment.
Something went wrong with that request. Please try again.