Passed
Push — master ( 678db7...164b32 )
by Cody
06:12 queued 03:06
created
register.php 1 patch
Indentation   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -1,97 +1,97 @@  discard block
 block discarded – undo
1 1
 <?php
2
-	// This file uses two additional include files:
3
-	//
4
-	// 1) templates/register_notice.txt - displayed above the registration form
5
-	// 2) register_expire_do.php - contains user expiration queries when necessary
2
+    // This file uses two additional include files:
3
+    //
4
+    // 1) templates/register_notice.txt - displayed above the registration form
5
+    // 2) register_expire_do.php - contains user expiration queries when necessary
6 6
 
7
-	set_include_path(dirname(__FILE__)."/include".PATH_SEPARATOR.
8
-		get_include_path());
7
+    set_include_path(dirname(__FILE__)."/include".PATH_SEPARATOR.
8
+        get_include_path());
9 9
 
10
-	require_once "autoload.php";
11
-	require_once "functions.php";
12
-	require_once "sessions.php";
13
-	require_once "sanity_check.php";
14
-	require_once "config.php";
15
-	require_once "db.php";
10
+    require_once "autoload.php";
11
+    require_once "functions.php";
12
+    require_once "sessions.php";
13
+    require_once "sanity_check.php";
14
+    require_once "config.php";
15
+    require_once "db.php";
16 16
 
17
-	startup_gettext();
17
+    startup_gettext();
18 18
 
19
-	$action = $_REQUEST["action"];
19
+    $action = $_REQUEST["action"];
20 20
 
21
-	if (!init_plugins()) {
22
-	    return;
23
-	}
21
+    if (!init_plugins()) {
22
+        return;
23
+    }
24 24
 
25
-	if ($_REQUEST["format"] == "feed") {
26
-		header("Content-Type: text/xml");
25
+    if ($_REQUEST["format"] == "feed") {
26
+        header("Content-Type: text/xml");
27 27
 
28
-		print '<?xml version="1.0" encoding="utf-8"?>';
29
-		print "<feed xmlns=\"http://www.w3.org/2005/Atom\">
28
+        print '<?xml version="1.0" encoding="utf-8"?>';
29
+        print "<feed xmlns=\"http://www.w3.org/2005/Atom\">
30 30
 			<id>".htmlspecialchars(SELF_URL_PATH."/register.php")."</id>
31 31
 			<title>Tiny Tiny RSS registration slots</title>
32 32
 			<link rel=\"self\" href=\"".htmlspecialchars(SELF_URL_PATH."/register.php?format=feed")."\"/>
33 33
 			<link rel=\"alternate\" href=\"".htmlspecialchars(SELF_URL_PATH)."\"/>";
34 34
 
35
-		if (ENABLE_REGISTRATION) {
36
-			$result = db_query("SELECT COUNT(*) AS cu FROM ttrss_users");
37
-			$num_users = db_fetch_result($result, 0, "cu");
38
-
39
-			$num_users = REG_MAX_USERS - $num_users;
40
-			if ($num_users < 0) {
41
-			    $num_users = 0;
42
-			}
43
-			$reg_suffix = "enabled";
44
-		} else {
45
-			$num_users = 0;
46
-			$reg_suffix = "disabled";
47
-		}
48
-
49
-		print "<entry>
35
+        if (ENABLE_REGISTRATION) {
36
+            $result = db_query("SELECT COUNT(*) AS cu FROM ttrss_users");
37
+            $num_users = db_fetch_result($result, 0, "cu");
38
+
39
+            $num_users = REG_MAX_USERS - $num_users;
40
+            if ($num_users < 0) {
41
+                $num_users = 0;
42
+            }
43
+            $reg_suffix = "enabled";
44
+        } else {
45
+            $num_users = 0;
46
+            $reg_suffix = "disabled";
47
+        }
48
+
49
+        print "<entry>
50 50
 			<id>".htmlspecialchars(SELF_URL_PATH)."/register.php?$num_users"."</id>
51 51
 			<link rel=\"alternate\" href=\"".htmlspecialchars(SELF_URL_PATH."/register.php")."\"/>";
52 52
 
53
-		print "<title>$num_users slots are currently available, registration $reg_suffix</title>";
54
-		print "<summary>$num_users slots are currently available, registration $reg_suffix</summary>";
53
+        print "<title>$num_users slots are currently available, registration $reg_suffix</title>";
54
+        print "<summary>$num_users slots are currently available, registration $reg_suffix</summary>";
55 55
 
56
-		print "</entry>";
56
+        print "</entry>";
57 57
 
58
-		print "</feed>";
58
+        print "</feed>";
59 59
 
60
-		return;
61
-	}
60
+        return;
61
+    }
62 62
 
63
-	/* Remove users which didn't login after receiving their registration information */
63
+    /* Remove users which didn't login after receiving their registration information */
64 64
 
65
-	if (DB_TYPE == "pgsql") {
66
-		db_query("DELETE FROM ttrss_users WHERE last_login IS NULL
65
+    if (DB_TYPE == "pgsql") {
66
+        db_query("DELETE FROM ttrss_users WHERE last_login IS NULL
67 67
 				AND created < NOW() - INTERVAL '1 day' AND access_level = 0");
68
-	} else {
69
-		db_query("DELETE FROM ttrss_users WHERE last_login IS NULL
68
+    } else {
69
+        db_query("DELETE FROM ttrss_users WHERE last_login IS NULL
70 70
 				AND created < DATE_SUB(NOW(), INTERVAL 1 DAY) AND access_level = 0");
71
-	}
71
+    }
72 72
 
73
-	if (file_exists("register_expire_do.php")) {
74
-		require_once "register_expire_do.php";
75
-	}
73
+    if (file_exists("register_expire_do.php")) {
74
+        require_once "register_expire_do.php";
75
+    }
76 76
 
77
-	if ($action == "check") {
78
-		header("Content-Type: application/xml");
77
+    if ($action == "check") {
78
+        header("Content-Type: application/xml");
79 79
 
80
-		$login = trim(db_escape_string($_REQUEST['login']));
80
+        $login = trim(db_escape_string($_REQUEST['login']));
81 81
 
82
-		$result = db_query("SELECT id FROM ttrss_users WHERE
82
+        $result = db_query("SELECT id FROM ttrss_users WHERE
83 83
 			LOWER(login) = LOWER('$login')");
84 84
 
85
-		$is_registered = db_num_rows($result) > 0;
85
+        $is_registered = db_num_rows($result) > 0;
86 86
 
87
-		print "<result>";
87
+        print "<result>";
88 88
 
89
-		printf("%d", $is_registered);
89
+        printf("%d", $is_registered);
90 90
 
91
-		print "</result>";
91
+        print "</result>";
92 92
 
93
-		return;
94
-	}
93
+        return;
94
+    }
95 95
 ?>
96 96
 <!DOCTYPE html>
97 97
 <html>
@@ -189,20 +189,20 @@  discard block
 block discarded – undo
189 189
 <div class="content">
190 190
 
191 191
 <?php
192
-		if (!ENABLE_REGISTRATION) {
193
-			print_error(__("New user registrations are administratively disabled."));
192
+        if (!ENABLE_REGISTRATION) {
193
+            print_error(__("New user registrations are administratively disabled."));
194 194
 
195
-			print "<p><form method=\"GET\" action=\"backend.php\">
195
+            print "<p><form method=\"GET\" action=\"backend.php\">
196 196
 				<input type=\"hidden\" name=\"op\" value=\"logout\">
197 197
 				<input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
198 198
 				</form>";
199
-			return;
200
-		}
199
+            return;
200
+        }
201 201
 ?>
202 202
 
203 203
 <?php if (REG_MAX_USERS > 0) {
204
-		$result = db_query("SELECT COUNT(*) AS cu FROM ttrss_users");
205
-		$num_users = db_fetch_result($result, 0, "cu");
204
+        $result = db_query("SELECT COUNT(*) AS cu FROM ttrss_users");
205
+        $num_users = db_fetch_result($result, 0, "cu");
206 206
 } ?>
207 207
 
208 208
 <?php if (!REG_MAX_USERS || $num_users < REG_MAX_USERS) { ?>
@@ -210,8 +210,8 @@  discard block
 block discarded – undo
210 210
 	<!-- If you have any rules or ToS you'd like to display, enter them here -->
211 211
 
212 212
 	<?php	if (file_exists("templates/register_notice.txt")) {
213
-			require_once "templates/register_notice.txt";
214
-	} ?>
213
+            require_once "templates/register_notice.txt";
214
+    } ?>
215 215
 
216 216
 	<?php if (!$action) { ?>
217 217
 
@@ -245,114 +245,114 @@  discard block
 block discarded – undo
245 245
 	<?php } else if ($action == "do_register") { ?>
246 246
 
247 247
 	<?php
248
-		$login = mb_strtolower(trim(db_escape_string($_REQUEST["login"])));
249
-		$email = trim(db_escape_string($_REQUEST["email"]));
250
-		$test = trim(db_escape_string($_REQUEST["turing_test"]));
248
+        $login = mb_strtolower(trim(db_escape_string($_REQUEST["login"])));
249
+        $email = trim(db_escape_string($_REQUEST["email"]));
250
+        $test = trim(db_escape_string($_REQUEST["turing_test"]));
251 251
 
252
-		if (!$login || !$email || !$test) {
253
-			print_error(__("Your registration information is incomplete."));
254
-			print "<p><form method=\"GET\" action=\"index.php\">
252
+        if (!$login || !$email || !$test) {
253
+            print_error(__("Your registration information is incomplete."));
254
+            print "<p><form method=\"GET\" action=\"index.php\">
255 255
 				<input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
256 256
 				</form>";
257
-			return;
258
-		}
257
+            return;
258
+        }
259 259
 
260
-		if ($test == "four" || $test == "4") {
260
+        if ($test == "four" || $test == "4") {
261 261
 
262
-			$result = db_query("SELECT id FROM ttrss_users WHERE
262
+            $result = db_query("SELECT id FROM ttrss_users WHERE
263 263
 				login = '$login'");
264 264
 
265
-			$is_registered = db_num_rows($result) > 0;
265
+            $is_registered = db_num_rows($result) > 0;
266 266
 
267
-			if ($is_registered) {
268
-				print_error(__('Sorry, this username is already taken.'));
269
-				print "<p><form method=\"GET\" action=\"index.php\">
267
+            if ($is_registered) {
268
+                print_error(__('Sorry, this username is already taken.'));
269
+                print "<p><form method=\"GET\" action=\"index.php\">
270 270
 				<input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
271 271
 				</form>";
272
-			} else {
272
+            } else {
273 273
 
274
-				$password = make_password();
274
+                $password = make_password();
275 275
 
276
-				$salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
277
-				$pwd_hash = encrypt_password($password, $salt, true);
276
+                $salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
277
+                $pwd_hash = encrypt_password($password, $salt, true);
278 278
 
279
-				db_query("INSERT INTO ttrss_users
279
+                db_query("INSERT INTO ttrss_users
280 280
 					(login,pwd_hash,access_level,last_login, email, created, salt)
281 281
 					VALUES ('$login', '$pwd_hash', 0, null, '$email', NOW(), '$salt')");
282 282
 
283
-				$result = db_query("SELECT id FROM ttrss_users WHERE
283
+                $result = db_query("SELECT id FROM ttrss_users WHERE
284 284
 					login = '$login' AND pwd_hash = '$pwd_hash'");
285 285
 
286
-				if (db_num_rows($result) != 1) {
287
-					print_error(__('Registration failed.'));
288
-					print "<p><form method=\"GET\" action=\"index.php\">
286
+                if (db_num_rows($result) != 1) {
287
+                    print_error(__('Registration failed.'));
288
+                    print "<p><form method=\"GET\" action=\"index.php\">
289 289
 					<input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
290 290
 					</form>";
291
-				} else {
292
-
293
-					$new_uid = db_fetch_result($result, 0, "id");
294
-
295
-					initialize_user($new_uid);
296
-
297
-					$reg_text = "Hi!\n".
298
-						"\n".
299
-						"You are receiving this message, because you (or somebody else) have opened\n".
300
-						"an account at Tiny Tiny RSS.\n".
301
-						"\n".
302
-						"Your login information is as follows:\n".
303
-						"\n".
304
-						"Login: $login\n".
305
-						"Password: $password\n".
306
-						"\n".
307
-						"Don't forget to login at least once to your new account, otherwise\n".
308
-						"it will be deleted in 24 hours.\n".
309
-						"\n".
310
-						"If that wasn't you, just ignore this message. Thanks.";
311
-
312
-					$mailer = new Mailer();
313
-					$rc = $mailer->mail(["to_address" => $email,
314
-						"subject" => "Registration information for Tiny Tiny RSS",
315
-						"message" => $reg_text]);
316
-
317
-					if (!$rc) {
318
-					    print_error($mailer->error());
319
-					}
320
-
321
-					$reg_text = "Hi!\n".
322
-						"\n".
323
-						"New user had registered at your Tiny Tiny RSS installation.\n".
324
-						"\n".
325
-						"Login: $login\n".
326
-						"Email: $email\n";
327
-
328
-					$mailer = new Mailer();
329
-					$rc = $mailer->mail(["to_address" => REG_NOTIFY_ADDRESS,
330
-						"subject" => "Registration notice for Tiny Tiny RSS",
331
-						"message" => $reg_text]);
332
-
333
-					if (!$rc) {
334
-					    print_error($mailer->error());
335
-					}
336
-
337
-					print_notice(__("Account created successfully."));
338
-
339
-					print "<p><form method=\"GET\" action=\"index.php\">
291
+                } else {
292
+
293
+                    $new_uid = db_fetch_result($result, 0, "id");
294
+
295
+                    initialize_user($new_uid);
296
+
297
+                    $reg_text = "Hi!\n".
298
+                        "\n".
299
+                        "You are receiving this message, because you (or somebody else) have opened\n".
300
+                        "an account at Tiny Tiny RSS.\n".
301
+                        "\n".
302
+                        "Your login information is as follows:\n".
303
+                        "\n".
304
+                        "Login: $login\n".
305
+                        "Password: $password\n".
306
+                        "\n".
307
+                        "Don't forget to login at least once to your new account, otherwise\n".
308
+                        "it will be deleted in 24 hours.\n".
309
+                        "\n".
310
+                        "If that wasn't you, just ignore this message. Thanks.";
311
+
312
+                    $mailer = new Mailer();
313
+                    $rc = $mailer->mail(["to_address" => $email,
314
+                        "subject" => "Registration information for Tiny Tiny RSS",
315
+                        "message" => $reg_text]);
316
+
317
+                    if (!$rc) {
318
+                        print_error($mailer->error());
319
+                    }
320
+
321
+                    $reg_text = "Hi!\n".
322
+                        "\n".
323
+                        "New user had registered at your Tiny Tiny RSS installation.\n".
324
+                        "\n".
325
+                        "Login: $login\n".
326
+                        "Email: $email\n";
327
+
328
+                    $mailer = new Mailer();
329
+                    $rc = $mailer->mail(["to_address" => REG_NOTIFY_ADDRESS,
330
+                        "subject" => "Registration notice for Tiny Tiny RSS",
331
+                        "message" => $reg_text]);
332
+
333
+                    if (!$rc) {
334
+                        print_error($mailer->error());
335
+                    }
336
+
337
+                    print_notice(__("Account created successfully."));
338
+
339
+                    print "<p><form method=\"GET\" action=\"index.php\">
340 340
 					<input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
341 341
 					</form>";
342 342
 
343
-				}
343
+                }
344 344
 
345
-			}
345
+            }
346 346
 
347
-			} else {
348
-				print_error('Plese check the form again, you have failed the robot test.');
349
-				print "<p><form method=\"GET\" action=\"index.php\">
347
+            } else {
348
+                print_error('Plese check the form again, you have failed the robot test.');
349
+                print "<p><form method=\"GET\" action=\"index.php\">
350 350
 				<input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
351 351
 				</form>";
352 352
 
353
-			}
354
-		}
355
-	?>
353
+            }
354
+        }
355
+    ?>
356 356
 
357 357
 <?php } else { ?>
358 358
 
Please login to merge, or discard this patch.
lib/accept-to-gettext.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -72,41 +72,41 @@  discard block
 block discarded – undo
72 72
 function find_match($curlscore, $curcscore, $curgtlang, $langval, $charval,
73 73
                     $gtlang)
74 74
 {
75
-  if ($curlscore < $langval) {
75
+    if ($curlscore < $langval) {
76 76
     $curlscore = $langval;
77 77
     $curcscore = $charval;
78 78
     $curgtlang = $gtlang;
79
-  } else if ($curlscore == $langval) {
79
+    } else if ($curlscore == $langval) {
80 80
     if ($curcscore < $charval) {
81
-      $curcscore = $charval;
82
-      $curgtlang = $gtlang;
81
+        $curcscore = $charval;
82
+        $curgtlang = $gtlang;
83 83
     }
84
-  }
85
-  return array($curlscore, $curcscore, $curgtlang);
84
+    }
85
+    return array($curlscore, $curcscore, $curgtlang);
86 86
 }
87 87
 
88 88
 function al2gt($gettextlangs, $mime) {
89
-  /* default to "everything is acceptable", as RFC2616 specifies */
90
-  $acceptLang = (($_SERVER["HTTP_ACCEPT_LANGUAGE"] == '') ? '*' : $_SERVER["HTTP_ACCEPT_LANGUAGE"]);
91
-  $acceptChar = (($_SERVER["HTTP_ACCEPT_CHARSET"] == '') ? '*' : $_SERVER["HTTP_ACCEPT_CHARSET"]);
92
-  $alparts = @preg_split("/,/", $acceptLang);
93
-  $acparts = @preg_split("/,/", $acceptChar);
89
+    /* default to "everything is acceptable", as RFC2616 specifies */
90
+    $acceptLang = (($_SERVER["HTTP_ACCEPT_LANGUAGE"] == '') ? '*' : $_SERVER["HTTP_ACCEPT_LANGUAGE"]);
91
+    $acceptChar = (($_SERVER["HTTP_ACCEPT_CHARSET"] == '') ? '*' : $_SERVER["HTTP_ACCEPT_CHARSET"]);
92
+    $alparts = @preg_split("/,/", $acceptLang);
93
+    $acparts = @preg_split("/,/", $acceptChar);
94 94
   
95
-  /* Parse the contents of the Accept-Language header.*/
96
-  foreach ($alparts as $part) {
95
+    /* Parse the contents of the Accept-Language header.*/
96
+    foreach ($alparts as $part) {
97 97
     $part = trim($part);
98 98
     if (preg_match("/;/", $part)) {
99
-      $lang = @preg_split("/;/", $part);
100
-      $score = @preg_split("/=/", $lang[1]);
101
-      $alscores[$lang[0]] = $score[1];
99
+        $lang = @preg_split("/;/", $part);
100
+        $score = @preg_split("/=/", $lang[1]);
101
+        $alscores[$lang[0]] = $score[1];
102 102
     } else {
103
-      $alscores[$part] = 1;
103
+        $alscores[$part] = 1;
104
+    }
104 105
     }
105
-  }
106 106
 
107
-  /* Do the same for the Accept-Charset header. */
107
+    /* Do the same for the Accept-Charset header. */
108 108
 
109
-  /* RFC2616: ``If no "*" is present in an Accept-Charset field, then
109
+    /* RFC2616: ``If no "*" is present in an Accept-Charset field, then
110 110
    * all character sets not explicitly mentioned get a quality value of
111 111
    * 0, except for ISO-8859-1, which gets a quality value of 1 if not
112 112
    * explicitly mentioned.''
@@ -114,31 +114,31 @@  discard block
 block discarded – undo
114 114
    * Making it 2 for the time being, so that we
115 115
    * can distinguish between "not specified" and "specified as 1" later
116 116
    * on. */
117
-  $acscores["ISO-8859-1"] = 2;
117
+    $acscores["ISO-8859-1"] = 2;
118 118
 
119
-  foreach ($acparts as $part) {
119
+    foreach ($acparts as $part) {
120 120
     $part = trim($part);
121 121
     if (preg_match("/;/", $part)) {
122
-      $cs = @preg_split("/;/", $part);
123
-      $score = @preg_split("/=/", $cs[1]);
124
-      $acscores[strtoupper($cs[0])] = $score[1];
122
+        $cs = @preg_split("/;/", $part);
123
+        $score = @preg_split("/=/", $cs[1]);
124
+        $acscores[strtoupper($cs[0])] = $score[1];
125 125
     } else {
126
-      $acscores[strtoupper($part)] = 1;
126
+        $acscores[strtoupper($part)] = 1;
127
+    }
127 128
     }
128
-  }
129
-  if ($acscores["ISO-8859-1"] == 2) {
129
+    if ($acscores["ISO-8859-1"] == 2) {
130 130
     $acscores["ISO-8859-1"] = (isset($acscores["*"]) ? $acscores["*"] : 1);
131
-  }
131
+    }
132 132
 
133
-  /* 
133
+    /* 
134 134
    * Loop through the available languages/encodings, and pick the one
135 135
    * with the highest score, excluding the ones with a charset the user
136 136
    * did not include.
137 137
    */
138
-  $curlscore = 0;
139
-  $curcscore = 0;
140
-  $curgtlang = null;
141
-  foreach ($gettextlangs as $gtlang) {
138
+    $curlscore = 0;
139
+    $curcscore = 0;
140
+    $curgtlang = null;
141
+    foreach ($gettextlangs as $gtlang) {
142 142
 
143 143
     $tmp1 = preg_replace("/\_/", "-", $gtlang);
144 144
     $tmp2 = @preg_split("/\./", $tmp1);
@@ -147,38 +147,38 @@  discard block
 block discarded – undo
147 147
     $noct = @preg_split("/-/", $allang);
148 148
 
149 149
     $testvals = array(
150
-         array(@$alscores[$allang], @$acscores[$gtcs]),
151
-     array(@$alscores[$noct[0]], @$acscores[$gtcs]),
152
-     array(@$alscores[$allang], @$acscores["*"]),
153
-     array(@$alscores[$noct[0]], @$acscores["*"]),
154
-     array(@$alscores["*"], @$acscores[$gtcs]),
155
-     array(@$alscores["*"], @$acscores["*"]));
150
+            array(@$alscores[$allang], @$acscores[$gtcs]),
151
+        array(@$alscores[$noct[0]], @$acscores[$gtcs]),
152
+        array(@$alscores[$allang], @$acscores["*"]),
153
+        array(@$alscores[$noct[0]], @$acscores["*"]),
154
+        array(@$alscores["*"], @$acscores[$gtcs]),
155
+        array(@$alscores["*"], @$acscores["*"]));
156 156
 
157 157
     $found = false;
158 158
     foreach ($testvals as $tval) {
159
-      if (!$found && isset($tval[0]) && isset($tval[1])) {
159
+        if (!$found && isset($tval[0]) && isset($tval[1])) {
160 160
         $arr = find_match($curlscore, $curcscore, $curgtlang, $tval[0],
161
-              $tval[1], $gtlang);
161
+                $tval[1], $gtlang);
162 162
         $curlscore = $arr[0];
163 163
         $curcscore = $arr[1];
164 164
         $curgtlang = $arr[2];
165 165
     $found = true;
166
-      }
166
+        }
167
+    }
167 168
     }
168
-  }
169 169
 
170
-  /* We must re-parse the gettext-string now, since we may have found it
170
+    /* We must re-parse the gettext-string now, since we may have found it
171 171
    * through a "*" qualifier.*/
172 172
   
173
-  $gtparts = @preg_split("/\./", $curgtlang);
174
-  $tmp = strtolower($gtparts[0]);
175
-  $lang = preg_replace("/\_/", "-", $tmp);
176
-  $charset = $gtparts[1];
173
+    $gtparts = @preg_split("/\./", $curgtlang);
174
+    $tmp = strtolower($gtparts[0]);
175
+    $lang = preg_replace("/\_/", "-", $tmp);
176
+    $charset = $gtparts[1];
177 177
 
178
-  header("Content-Language: $lang");
179
-  header("Content-Type: $mime; charset=$charset");
178
+    header("Content-Language: $lang");
179
+    header("Content-Type: $mime; charset=$charset");
180 180
 
181
-  return $curgtlang;
181
+    return $curgtlang;
182 182
 }
183 183
 
184 184
 ?>
Please login to merge, or discard this patch.
lib/jimIcon.php 2 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -127,16 +127,16 @@  discard block
 block discarded – undo
127 127
                 $bitmapinfo = unpack("Vsize", $data);
128 128
                 if ($bitmapinfo["size"] == 40) {
129 129
                         $info = unpack("Vsize/".
130
-                                       "Vwidth/".
131
-                                       "Vheight/".
132
-                                       "vplanes/".
133
-                                       "vbpp/".
134
-                                       "Vcompress/".
135
-                                       "Vsize/".
136
-                                       "Vxres/".
137
-                                       "Vyres/".
138
-                                       "Vpalcolors/".
139
-                                       "Vimpcolors/", $data);
130
+                                        "Vwidth/".
131
+                                        "Vheight/".
132
+                                        "vplanes/".
133
+                                        "vbpp/".
134
+                                        "Vcompress/".
135
+                                        "Vsize/".
136
+                                        "Vxres/".
137
+                                        "Vyres/".
138
+                                        "Vpalcolors/".
139
+                                        "Vimpcolors/", $data);
140 140
                         if ($e["bpp"] == 0) {
141 141
                                 $e["bpp"] = $info["bpp"];
142 142
                         }
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
                         for ($y = 0; $y < $height; $y++) {
245 245
                                 for ($x = 0; $x < $width; $x++) {
246 246
                                         imagesetpixel($img, $x, $y,
247
-                                                      $XOR[$y][$x]);
247
+                                                        $XOR[$y][$x]);
248 248
                                 }
249 249
                         }
250 250
                         return $img;
@@ -255,10 +255,10 @@  discard block
 block discarded – undo
255 255
                         $x = 0;
256 256
                         while ($x < $width) {
257 257
                                 for ($b = 0x80;
258
-                                     $b > 0 && $x < $width; $b >>= 1) {
258
+                                        $b > 0 && $x < $width; $b >>= 1) {
259 259
                                         if (!(ord($data[$offset]) & $b)) {
260 260
                                                 imagesetpixel($img, $x, $y,
261
-                                                              $XOR[$y][$x]);
261
+                                                                $XOR[$y][$x]);
262 262
                                         }
263 263
                                         $x++;
264 264
                                 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -67,8 +67,9 @@
 block discarded – undo
67 67
                 $most_pixels = 0;
68 68
                 for ($i = 0; $i < $h["num"]; $i++) {
69 69
                         $entry = substr($ico, 6 + 16 * $i, 16);
70
-                        if (!$entry || strlen($entry) < 16)
71
-                                continue;
70
+                        if (!$entry || strlen($entry) < 16) {
71
+                                                        continue;
72
+                        }
72 73
                         $e = unpack("Cwidth/".
73 74
                                     "Cheight/".
74 75
                                     "Ccolors/".
Please login to merge, or discard this patch.
lib/MiniTemplator.class.php 3 patches
Indentation   +405 added lines, -405 removed lines patch added patch discarded remove patch
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 * @access public
162 162
 */
163 163
 function __construct() {
164
-   $this->templateValid = false; }
164
+    $this->templateValid = false; }
165 165
 
166 166
 //--- template string handling --------------------------------------------------------------------------------------
167 167
 
@@ -172,13 +172,13 @@  discard block
 block discarded – undo
172 172
 * @access public
173 173
 */
174 174
 function readTemplateFromFile($fileName) {
175
-   if (!$this->readFileIntoString($fileName, $s)) {
176
-      $this->triggerError("Error while reading template file ".$fileName.".");
177
-      return false; }
178
-   if (!$this->setTemplateString($s)) {
179
-       return false;
180
-   }
181
-   return true; }
175
+    if (!$this->readFileIntoString($fileName, $s)) {
176
+        $this->triggerError("Error while reading template file ".$fileName.".");
177
+        return false; }
178
+    if (!$this->setTemplateString($s)) {
179
+        return false;
180
+    }
181
+    return true; }
182 182
 
183 183
 /**
184 184
 * Assigns a new template string.
@@ -187,14 +187,14 @@  discard block
 block discarded – undo
187 187
 * @access public
188 188
 */
189 189
 function setTemplateString($templateString) {
190
-   $this->templateValid = false;
191
-   $this->template = $templateString;
192
-   if (!$this->parseTemplate()) {
193
-       return false;
194
-   }
195
-   $this->reset();
196
-   $this->templateValid = true;
197
-   return true; }
190
+    $this->templateValid = false;
191
+    $this->template = $templateString;
192
+    if (!$this->parseTemplate()) {
193
+        return false;
194
+    }
195
+    $this->reset();
196
+    $this->templateValid = true;
197
+    return true; }
198 198
 
199 199
 /**
200 200
 * Loads the template string for a subtemplate (used for the $Include command).
@@ -202,11 +202,11 @@  discard block
 block discarded – undo
202 202
 * @access private
203 203
 */
204 204
 function loadSubtemplate($subtemplateName, &$s) {
205
-   $subtemplateFileName = $this->combineFileSystemPath($this->subtemplateBasePath, $subtemplateName);
206
-   if (!$this->readFileIntoString($subtemplateFileName, $s)) {
207
-      $this->triggerError("Error while reading subtemplate file ".$subtemplateFileName.".");
208
-      return false; }
209
-   return true; }
205
+    $subtemplateFileName = $this->combineFileSystemPath($this->subtemplateBasePath, $subtemplateName);
206
+    if (!$this->readFileIntoString($subtemplateFileName, $s)) {
207
+        $this->triggerError("Error while reading subtemplate file ".$subtemplateFileName.".");
208
+        return false; }
209
+    return true; }
210 210
 
211 211
 //--- template parsing ----------------------------------------------------------------------------------------------
212 212
 
@@ -216,34 +216,34 @@  discard block
 block discarded – undo
216 216
 * @access private
217 217
 */
218 218
 function parseTemplate() {
219
-   $this->initParsing();
220
-   $this->beginMainBlock();
221
-   if (!$this->parseTemplateCommands()) {
222
-       return false;
223
-   }
224
-   $this->endMainBlock();
225
-   if (!$this->checkBlockDefinitionsComplete()) {
226
-       return false;
227
-   }
228
-   if (!$this->parseTemplateVariables()) {
229
-       return false;
230
-   }
231
-   $this->associateVariablesWithBlocks();
232
-   return true; }
219
+    $this->initParsing();
220
+    $this->beginMainBlock();
221
+    if (!$this->parseTemplateCommands()) {
222
+        return false;
223
+    }
224
+    $this->endMainBlock();
225
+    if (!$this->checkBlockDefinitionsComplete()) {
226
+        return false;
227
+    }
228
+    if (!$this->parseTemplateVariables()) {
229
+        return false;
230
+    }
231
+    $this->associateVariablesWithBlocks();
232
+    return true; }
233 233
 
234 234
 /**
235 235
 * @access private
236 236
 */
237 237
 function initParsing() {
238
-   $this->varTab = array();
239
-   $this->varTabCnt = 0;
240
-   $this->varNameToNoMap = array();
241
-   $this->varRefTab = array();
242
-   $this->varRefTabCnt = 0;
243
-   $this->blockTab = array();
244
-   $this->blockTabCnt = 0;
245
-   $this->blockNameToNoMap = array();
246
-   $this->openBlocksTab = array(); }
238
+    $this->varTab = array();
239
+    $this->varTabCnt = 0;
240
+    $this->varNameToNoMap = array();
241
+    $this->varRefTab = array();
242
+    $this->varRefTabCnt = 0;
243
+    $this->blockTab = array();
244
+    $this->blockTabCnt = 0;
245
+    $this->blockNameToNoMap = array();
246
+    $this->openBlocksTab = array(); }
247 247
 
248 248
 /**
249 249
 * Registers the main block.
@@ -251,27 +251,27 @@  discard block
 block discarded – undo
251 251
 * @access private
252 252
 */
253 253
 function beginMainBlock() {
254
-   $blockNo = 0;
255
-   $this->registerBlock('@@InternalMainBlock@@', $blockNo);
256
-   $bte = & $this->blockTab[$blockNo];
257
-   $bte['tPosBegin'] = 0;
258
-   $bte['tPosContentsBegin'] = 0;
259
-   $bte['nestingLevel'] = 0;
260
-   $bte['parentBlockNo'] = -1;
261
-   $bte['definitionIsOpen'] = true;
262
-   $this->openBlocksTab[0] = $blockNo;
263
-   $this->currentNestingLevel = 1; }
254
+    $blockNo = 0;
255
+    $this->registerBlock('@@InternalMainBlock@@', $blockNo);
256
+    $bte = & $this->blockTab[$blockNo];
257
+    $bte['tPosBegin'] = 0;
258
+    $bte['tPosContentsBegin'] = 0;
259
+    $bte['nestingLevel'] = 0;
260
+    $bte['parentBlockNo'] = -1;
261
+    $bte['definitionIsOpen'] = true;
262
+    $this->openBlocksTab[0] = $blockNo;
263
+    $this->currentNestingLevel = 1; }
264 264
 
265 265
 /**
266 266
 * Completes the main block registration.
267 267
 * @access private
268 268
 */
269 269
 function endMainBlock() {
270
-   $bte = & $this->blockTab[0];
271
-   $bte['tPosContentsEnd'] = strlen($this->template);
272
-   $bte['tPosEnd'] = strlen($this->template);
273
-   $bte['definitionIsOpen'] = false;
274
-   $this->currentNestingLevel -= 1; }
270
+    $bte = & $this->blockTab[0];
271
+    $bte['tPosContentsEnd'] = strlen($this->template);
272
+    $bte['tPosEnd'] = strlen($this->template);
273
+    $bte['definitionIsOpen'] = false;
274
+    $this->currentNestingLevel -= 1; }
275 275
 
276 276
 /**
277 277
 * Parses commands within the template in the format "<!-- $command parameters -->".
@@ -279,46 +279,46 @@  discard block
 block discarded – undo
279 279
 * @access private
280 280
 */
281 281
 function parseTemplateCommands() {
282
-   $p = 0;
283
-   while (true) {
284
-      $p0 = strpos($this->template, '<!--', $p);
285
-      if ($p0 === false) break;
286
-      $p = strpos($this->template, '-->', $p0);
287
-      if ($p === false) {
288
-         $this->triggerError("Invalid HTML comment in template at offset $p0.");
289
-         return false; }
290
-      $p += 3;
291
-      $cmdL = substr($this->template, $p0 + 4, $p - $p0 - 7);
292
-      if (!$this->processTemplateCommand($cmdL, $p0, $p, $resumeFromStart))
293
-         return false;
294
-      if ($resumeFromStart) $p = $p0; }
295
-   return true; }
282
+    $p = 0;
283
+    while (true) {
284
+        $p0 = strpos($this->template, '<!--', $p);
285
+        if ($p0 === false) break;
286
+        $p = strpos($this->template, '-->', $p0);
287
+        if ($p === false) {
288
+            $this->triggerError("Invalid HTML comment in template at offset $p0.");
289
+            return false; }
290
+        $p += 3;
291
+        $cmdL = substr($this->template, $p0 + 4, $p - $p0 - 7);
292
+        if (!$this->processTemplateCommand($cmdL, $p0, $p, $resumeFromStart))
293
+            return false;
294
+        if ($resumeFromStart) $p = $p0; }
295
+    return true; }
296 296
 
297 297
 /**
298 298
 * @return boolean  true on success, false on error.
299 299
 * @access private
300 300
 */
301 301
 function processTemplateCommand($cmdL, $cmdTPosBegin, $cmdTPosEnd, &$resumeFromStart) {
302
-   $resumeFromStart = false;
303
-   $p = 0;
304
-   $cmd = '';
305
-   if (!$this->parseWord($cmdL, $p, $cmd)) return true;
306
-   $parms = substr($cmdL, $p);
307
-   switch (strtoupper($cmd)) {
308
-      case '$BEGINBLOCK':
302
+    $resumeFromStart = false;
303
+    $p = 0;
304
+    $cmd = '';
305
+    if (!$this->parseWord($cmdL, $p, $cmd)) return true;
306
+    $parms = substr($cmdL, $p);
307
+    switch (strtoupper($cmd)) {
308
+        case '$BEGINBLOCK':
309 309
          if (!$this->processBeginBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd))
310 310
             return false;
311
-         break;
312
-      case '$ENDBLOCK':
311
+            break;
312
+        case '$ENDBLOCK':
313 313
          if (!$this->processEndBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd))
314 314
             return false;
315
-         break;
316
-      case '$INCLUDE':
315
+            break;
316
+        case '$INCLUDE':
317 317
          if (!$this->processincludeCmd($parms, $cmdTPosBegin, $cmdTPosEnd))
318 318
             return false;
319
-         $resumeFromStart = true;
320
-         break;
321
-      default:
319
+            $resumeFromStart = true;
320
+            break;
321
+        default:
322 322
          if ($cmd{0} == '$' && !(strlen($cmd) >= 2 && $cmd{1} == '{')) {
323 323
             $this->triggerError("Unknown command \"$cmd\" in template at offset $cmdTPosBegin.");
324 324
             return false; }}
@@ -330,25 +330,25 @@  discard block
 block discarded – undo
330 330
 * @access private
331 331
 */
332 332
 function processBeginBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd) {
333
-   $p = 0;
334
-   if (!$this->parseWord($parms, $p, $blockName)) {
335
-      $this->triggerError("Missing block name in \$BeginBlock command in template at offset $cmdTPosBegin.");
336
-      return false; }
337
-   if (trim(substr($parms, $p)) != '') {
338
-      $this->triggerError("Extra parameter in \$BeginBlock command in template at offset $cmdTPosBegin.");
339
-      return false; }
340
-   $this->registerBlock($blockName, $blockNo);
341
-   $btr = & $this->blockTab[$blockNo];
342
-   $btr['tPosBegin'] = $cmdTPosBegin;
343
-   $btr['tPosContentsBegin'] = $cmdTPosEnd;
344
-   $btr['nestingLevel'] = $this->currentNestingLevel;
345
-   $btr['parentBlockNo'] = $this->openBlocksTab[$this->currentNestingLevel - 1];
346
-   $this->openBlocksTab[$this->currentNestingLevel] = $blockNo;
347
-   $this->currentNestingLevel += 1;
348
-   if ($this->currentNestingLevel > $this->maxNestingLevel) {
349
-      $this->triggerError("Block nesting overflow in template at offset $cmdTPosBegin.");
350
-      return false; }
351
-   return true; }
333
+    $p = 0;
334
+    if (!$this->parseWord($parms, $p, $blockName)) {
335
+        $this->triggerError("Missing block name in \$BeginBlock command in template at offset $cmdTPosBegin.");
336
+        return false; }
337
+    if (trim(substr($parms, $p)) != '') {
338
+        $this->triggerError("Extra parameter in \$BeginBlock command in template at offset $cmdTPosBegin.");
339
+        return false; }
340
+    $this->registerBlock($blockName, $blockNo);
341
+    $btr = & $this->blockTab[$blockNo];
342
+    $btr['tPosBegin'] = $cmdTPosBegin;
343
+    $btr['tPosContentsBegin'] = $cmdTPosEnd;
344
+    $btr['nestingLevel'] = $this->currentNestingLevel;
345
+    $btr['parentBlockNo'] = $this->openBlocksTab[$this->currentNestingLevel - 1];
346
+    $this->openBlocksTab[$this->currentNestingLevel] = $blockNo;
347
+    $this->currentNestingLevel += 1;
348
+    if ($this->currentNestingLevel > $this->maxNestingLevel) {
349
+        $this->triggerError("Block nesting overflow in template at offset $cmdTPosBegin.");
350
+        return false; }
351
+    return true; }
352 352
 
353 353
 /**
354 354
 * Processes the $EndBlock command.
@@ -356,47 +356,47 @@  discard block
 block discarded – undo
356 356
 * @access private
357 357
 */
358 358
 function processEndBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd) {
359
-   $p = 0;
360
-   if (!$this->parseWord($parms, $p, $blockName)) {
361
-      $this->triggerError("Missing block name in \$EndBlock command in template at offset $cmdTPosBegin.");
362
-      return false; }
363
-   if (trim(substr($parms, $p)) != '') {
364
-      $this->triggerError("Extra parameter in \$EndBlock command in template at offset $cmdTPosBegin.");
365
-      return false; }
366
-   if (!$this->lookupBlockName($blockName, $blockNo)) {
367
-      $this->triggerError("Undefined block name \"$blockName\" in \$EndBlock command in template at offset $cmdTPosBegin.");
368
-      return false; }
369
-   $this->currentNestingLevel -= 1;
370
-   $btr = & $this->blockTab[$blockNo];
371
-   if (!$btr['definitionIsOpen']) {
372
-      $this->triggerError("Multiple \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin.");
373
-      return false; }
374
-   if ($btr['nestingLevel'] != $this->currentNestingLevel) {
375
-      $this->triggerError("Block nesting level mismatch at \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin.");
376
-      return false; }
377
-   $btr['tPosContentsEnd'] = $cmdTPosBegin;
378
-   $btr['tPosEnd'] = $cmdTPosEnd;
379
-   $btr['definitionIsOpen'] = false;
380
-   return true; }
359
+    $p = 0;
360
+    if (!$this->parseWord($parms, $p, $blockName)) {
361
+        $this->triggerError("Missing block name in \$EndBlock command in template at offset $cmdTPosBegin.");
362
+        return false; }
363
+    if (trim(substr($parms, $p)) != '') {
364
+        $this->triggerError("Extra parameter in \$EndBlock command in template at offset $cmdTPosBegin.");
365
+        return false; }
366
+    if (!$this->lookupBlockName($blockName, $blockNo)) {
367
+        $this->triggerError("Undefined block name \"$blockName\" in \$EndBlock command in template at offset $cmdTPosBegin.");
368
+        return false; }
369
+    $this->currentNestingLevel -= 1;
370
+    $btr = & $this->blockTab[$blockNo];
371
+    if (!$btr['definitionIsOpen']) {
372
+        $this->triggerError("Multiple \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin.");
373
+        return false; }
374
+    if ($btr['nestingLevel'] != $this->currentNestingLevel) {
375
+        $this->triggerError("Block nesting level mismatch at \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin.");
376
+        return false; }
377
+    $btr['tPosContentsEnd'] = $cmdTPosBegin;
378
+    $btr['tPosEnd'] = $cmdTPosEnd;
379
+    $btr['definitionIsOpen'] = false;
380
+    return true; }
381 381
 
382 382
 /**
383 383
 * @access private
384 384
 */
385 385
 function registerBlock($blockName, &$blockNo) {
386
-   $blockNo = $this->blockTabCnt++;
387
-   $btr = & $this->blockTab[$blockNo];
388
-   $btr = array();
389
-   $btr['blockName'] = $blockName;
390
-   if (!$this->lookupBlockName($blockName, $btr['nextWithSameName']))
391
-      $btr['nextWithSameName'] = -1;
392
-   $btr['definitionIsOpen'] = true;
393
-   $btr['instances'] = 0;
394
-   $btr['firstBlockInstNo'] = -1;
395
-   $btr['lastBlockInstNo'] = -1;
396
-   $btr['blockVarCnt'] = 0;
397
-   $btr['firstVarRefNo'] = -1;
398
-   $btr['blockVarNoToVarNoMap'] = array();
399
-   $this->blockNameToNoMap[strtoupper($blockName)] = $blockNo; }
386
+    $blockNo = $this->blockTabCnt++;
387
+    $btr = & $this->blockTab[$blockNo];
388
+    $btr = array();
389
+    $btr['blockName'] = $blockName;
390
+    if (!$this->lookupBlockName($blockName, $btr['nextWithSameName']))
391
+        $btr['nextWithSameName'] = -1;
392
+    $btr['definitionIsOpen'] = true;
393
+    $btr['instances'] = 0;
394
+    $btr['firstBlockInstNo'] = -1;
395
+    $btr['lastBlockInstNo'] = -1;
396
+    $btr['blockVarCnt'] = 0;
397
+    $btr['firstVarRefNo'] = -1;
398
+    $btr['blockVarNoToVarNoMap'] = array();
399
+    $this->blockNameToNoMap[strtoupper($blockName)] = $blockNo; }
400 400
 
401 401
 /**
402 402
 * Checks that all block definitions are closed.
@@ -404,15 +404,15 @@  discard block
 block discarded – undo
404 404
 * @access private
405 405
 */
406 406
 function checkBlockDefinitionsComplete() {
407
-   for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) {
408
-      $btr = & $this->blockTab[$blockNo];
409
-      if ($btr['definitionIsOpen']) {
410
-         $this->triggerError("Missing \$EndBlock command in template for block ".$btr['blockName'].".");
411
-         return false; }}
412
-   if ($this->currentNestingLevel != 0) {
413
-      $this->triggerError("Block nesting level error at end of template.");
414
-      return false; }
415
-   return true; }
407
+    for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) {
408
+        $btr = & $this->blockTab[$blockNo];
409
+        if ($btr['definitionIsOpen']) {
410
+            $this->triggerError("Missing \$EndBlock command in template for block ".$btr['blockName'].".");
411
+            return false; }}
412
+    if ($this->currentNestingLevel != 0) {
413
+        $this->triggerError("Block nesting level error at end of template.");
414
+        return false; }
415
+    return true; }
416 416
 
417 417
 /**
418 418
 * Processes the $Include command.
@@ -420,14 +420,14 @@  discard block
 block discarded – undo
420 420
 * @access private
421 421
 */
422 422
 function processIncludeCmd($parms, $cmdTPosBegin, $cmdTPosEnd) {
423
-   $p = 0;
424
-   if (!$this->parseWordOrQuotedString($parms, $p, $subtemplateName)) {
425
-      $this->triggerError("Missing or invalid subtemplate name in \$Include command in template at offset $cmdTPosBegin.");
426
-      return false; }
427
-   if (trim(substr($parms, $p)) != '') {
428
-      $this->triggerError("Extra parameter in \$include command in template at offset $cmdTPosBegin.");
429
-      return false; }
430
-   return $this->insertSubtemplate($subtemplateName, $cmdTPosBegin, $cmdTPosEnd); }
423
+    $p = 0;
424
+    if (!$this->parseWordOrQuotedString($parms, $p, $subtemplateName)) {
425
+        $this->triggerError("Missing or invalid subtemplate name in \$Include command in template at offset $cmdTPosBegin.");
426
+        return false; }
427
+    if (trim(substr($parms, $p)) != '') {
428
+        $this->triggerError("Extra parameter in \$include command in template at offset $cmdTPosBegin.");
429
+        return false; }
430
+    return $this->insertSubtemplate($subtemplateName, $cmdTPosBegin, $cmdTPosEnd); }
431 431
 
432 432
 /**
433 433
 * Processes the $Include command.
@@ -435,14 +435,14 @@  discard block
 block discarded – undo
435 435
 * @access private
436 436
 */
437 437
 function insertSubtemplate($subtemplateName, $tPos1, $tPos2) {
438
-   if (strlen($this->template) > $this->maxInclTemplateSize) {
439
-      $this->triggerError("Subtemplate include aborted because the internal template string is longer than $this->maxInclTemplateSize characters.");
440
-      return false; }
441
-   if (!$this->loadSubtemplate($subtemplateName, $subtemplate)) return false;
442
-   // (Copying the template to insert a subtemplate is a bit slow. In a future implementation of MiniTemplator,
443
-   // a table could be used that contains references to the string fragments.)
444
-   $this->template = substr($this->template, 0, $tPos1).$subtemplate.substr($this->template, $tPos2);
445
-   return true; }
438
+    if (strlen($this->template) > $this->maxInclTemplateSize) {
439
+        $this->triggerError("Subtemplate include aborted because the internal template string is longer than $this->maxInclTemplateSize characters.");
440
+        return false; }
441
+    if (!$this->loadSubtemplate($subtemplateName, $subtemplate)) return false;
442
+    // (Copying the template to insert a subtemplate is a bit slow. In a future implementation of MiniTemplator,
443
+    // a table could be used that contains references to the string fragments.)
444
+    $this->template = substr($this->template, 0, $tPos1).$subtemplate.substr($this->template, $tPos2);
445
+    return true; }
446 446
 
447 447
 /**
448 448
 * Parses variable references within the template in the format "${VarName}".
@@ -450,79 +450,79 @@  discard block
 block discarded – undo
450 450
 * @access private
451 451
 */
452 452
 function parseTemplateVariables() {
453
-   $p = 0;
454
-   while (true) {
455
-      $p = strpos($this->template, '${', $p);
456
-      if ($p === false) {
457
-          break;
458
-      }
459
-      $p0 = $p;
460
-      $p = strpos($this->template, '}', $p);
461
-      if ($p === false) {
462
-         $this->triggerError("Invalid variable reference in template at offset $p0.");
463
-         return false; }
464
-      $p += 1;
465
-      $varName = trim(substr($this->template, $p0 + 2, $p - $p0 - 3));
466
-      if (strlen($varName) == 0) {
467
-         $this->triggerError("Empty variable name in template at offset $p0.");
468
-         return false; }
469
-      $this->registerVariableReference($varName, $p0, $p); }
470
-   return true; }
453
+    $p = 0;
454
+    while (true) {
455
+        $p = strpos($this->template, '${', $p);
456
+        if ($p === false) {
457
+            break;
458
+        }
459
+        $p0 = $p;
460
+        $p = strpos($this->template, '}', $p);
461
+        if ($p === false) {
462
+            $this->triggerError("Invalid variable reference in template at offset $p0.");
463
+            return false; }
464
+        $p += 1;
465
+        $varName = trim(substr($this->template, $p0 + 2, $p - $p0 - 3));
466
+        if (strlen($varName) == 0) {
467
+            $this->triggerError("Empty variable name in template at offset $p0.");
468
+            return false; }
469
+        $this->registerVariableReference($varName, $p0, $p); }
470
+    return true; }
471 471
 
472 472
 /**
473 473
 * @access private
474 474
 */
475 475
 function registerVariableReference($varName, $tPosBegin, $tPosEnd) {
476
-   if (!$this->lookupVariableName($varName, $varNo))
477
-      $this->registerVariable($varName, $varNo);
478
-   $varRefNo = $this->varRefTabCnt++;
479
-   $vrtr = & $this->varRefTab[$varRefNo];
480
-   $vrtr = array();
481
-   $vrtr['tPosBegin'] = $tPosBegin;
482
-   $vrtr['tPosEnd'] = $tPosEnd;
483
-   $vrtr['varNo'] = $varNo; }
476
+    if (!$this->lookupVariableName($varName, $varNo))
477
+        $this->registerVariable($varName, $varNo);
478
+    $varRefNo = $this->varRefTabCnt++;
479
+    $vrtr = & $this->varRefTab[$varRefNo];
480
+    $vrtr = array();
481
+    $vrtr['tPosBegin'] = $tPosBegin;
482
+    $vrtr['tPosEnd'] = $tPosEnd;
483
+    $vrtr['varNo'] = $varNo; }
484 484
 
485 485
 /**
486 486
 * @access private
487 487
 */
488 488
 function registerVariable($varName, &$varNo) {
489
-   $varNo = $this->varTabCnt++;
490
-   $vtr = & $this->varTab[$varNo];
491
-   $vtr = array();
492
-   $vtr['varName'] = $varName;
493
-   $vtr['varValue'] = '';
494
-   $this->varNameToNoMap[strtoupper($varName)] = $varNo; }
489
+    $varNo = $this->varTabCnt++;
490
+    $vtr = & $this->varTab[$varNo];
491
+    $vtr = array();
492
+    $vtr['varName'] = $varName;
493
+    $vtr['varValue'] = '';
494
+    $this->varNameToNoMap[strtoupper($varName)] = $varNo; }
495 495
 
496 496
 /**
497 497
 * Associates variable references with blocks.
498 498
 * @access private
499 499
 */
500 500
 function associateVariablesWithBlocks() {
501
-   $varRefNo = 0;
502
-   $activeBlockNo = 0;
503
-   $nextBlockNo = 1;
504
-   while ($varRefNo < $this->varRefTabCnt) {
505
-      $vrtr = & $this->varRefTab[$varRefNo];
506
-      $varRefTPos = $vrtr['tPosBegin'];
507
-      $varNo = $vrtr['varNo'];
508
-      if ($varRefTPos >= $this->blockTab[$activeBlockNo]['tPosEnd']) {
509
-         $activeBlockNo = $this->blockTab[$activeBlockNo]['parentBlockNo'];
510
-         continue; }
511
-      if ($nextBlockNo < $this->blockTabCnt) {
512
-         if ($varRefTPos >= $this->blockTab[$nextBlockNo]['tPosBegin']) {
501
+    $varRefNo = 0;
502
+    $activeBlockNo = 0;
503
+    $nextBlockNo = 1;
504
+    while ($varRefNo < $this->varRefTabCnt) {
505
+        $vrtr = & $this->varRefTab[$varRefNo];
506
+        $varRefTPos = $vrtr['tPosBegin'];
507
+        $varNo = $vrtr['varNo'];
508
+        if ($varRefTPos >= $this->blockTab[$activeBlockNo]['tPosEnd']) {
509
+            $activeBlockNo = $this->blockTab[$activeBlockNo]['parentBlockNo'];
510
+            continue; }
511
+        if ($nextBlockNo < $this->blockTabCnt) {
512
+            if ($varRefTPos >= $this->blockTab[$nextBlockNo]['tPosBegin']) {
513 513
             $activeBlockNo = $nextBlockNo;
514 514
             $nextBlockNo += 1;
515 515
             continue; }}
516
-      $btr = & $this->blockTab[$activeBlockNo];
517
-      if ($varRefTPos < $btr['tPosBegin'])
518
-         $this->programLogicError(1);
519
-      $blockVarNo = $btr['blockVarCnt']++;
520
-      $btr['blockVarNoToVarNoMap'][$blockVarNo] = $varNo;
521
-      if ($btr['firstVarRefNo'] == -1)
522
-         $btr['firstVarRefNo'] = $varRefNo;
523
-      $vrtr['blockNo'] = $activeBlockNo;
524
-      $vrtr['blockVarNo'] = $blockVarNo;
525
-      $varRefNo += 1; }}
516
+        $btr = & $this->blockTab[$activeBlockNo];
517
+        if ($varRefTPos < $btr['tPosBegin'])
518
+            $this->programLogicError(1);
519
+        $blockVarNo = $btr['blockVarCnt']++;
520
+        $btr['blockVarNoToVarNoMap'][$blockVarNo] = $varNo;
521
+        if ($btr['firstVarRefNo'] == -1)
522
+            $btr['firstVarRefNo'] = $varRefNo;
523
+        $vrtr['blockNo'] = $activeBlockNo;
524
+        $vrtr['blockVarNo'] = $blockVarNo;
525
+        $varRefNo += 1; }}
526 526
 
527 527
 //--- build up (template variables and blocks) ----------------------------------------------------------------------
528 528
 
@@ -535,15 +535,15 @@  discard block
 block discarded – undo
535 535
 * @access public
536 536
 */
537 537
 function reset() {
538
-   for ($varNo = 0; $varNo < $this->varTabCnt; $varNo++)
539
-      $this->varTab[$varNo]['varValue'] = '';
540
-   for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) {
541
-      $btr = & $this->blockTab[$blockNo];
542
-      $btr['instances'] = 0;
543
-      $btr['firstBlockInstNo'] = -1;
544
-      $btr['lastBlockInstNo'] = -1; }
545
-   $this->blockInstTab = array();
546
-   $this->blockInstTabCnt = 0; }
538
+    for ($varNo = 0; $varNo < $this->varTabCnt; $varNo++)
539
+        $this->varTab[$varNo]['varValue'] = '';
540
+    for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) {
541
+        $btr = & $this->blockTab[$blockNo];
542
+        $btr['instances'] = 0;
543
+        $btr['firstBlockInstNo'] = -1;
544
+        $btr['lastBlockInstNo'] = -1; }
545
+    $this->blockInstTab = array();
546
+    $this->blockInstTabCnt = 0; }
547 547
 
548 548
 /**
549 549
 * Sets a template variable.
@@ -561,13 +561,13 @@  discard block
 block discarded – undo
561 561
 * @access public
562 562
 */
563 563
 function setVariable($variableName, $variableValue, $isOptional = false) {
564
-   if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; }
565
-   if (!$this->lookupVariableName($variableName, $varNo)) {
566
-      if ($isOptional) return true;
567
-      $this->triggerError("Variable \"$variableName\" not defined in template.");
568
-      return false; }
569
-   $this->varTab[$varNo]['varValue'] = $variableValue;
570
-   return true; }
564
+    if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; }
565
+    if (!$this->lookupVariableName($variableName, $varNo)) {
566
+        if ($isOptional) return true;
567
+        $this->triggerError("Variable \"$variableName\" not defined in template.");
568
+        return false; }
569
+    $this->varTab[$varNo]['varValue'] = $variableValue;
570
+    return true; }
571 571
 
572 572
 /**
573 573
 * Sets a template variable to an escaped string.
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
 * @access public
589 589
 */
590 590
 function setVariableEsc($variableName, $variableValue, $isOptional = false) {
591
-   return $this->setVariable($variableName, htmlspecialchars($variableValue, ENT_QUOTES), $isOptional); }
591
+    return $this->setVariable($variableName, htmlspecialchars($variableValue, ENT_QUOTES), $isOptional); }
592 592
 
593 593
 /**
594 594
 * Checks whether a variable with the specified name exists within the template.
@@ -598,8 +598,8 @@  discard block
 block discarded – undo
598 598
 * @access public
599 599
 */
600 600
 function variableExists($variableName) {
601
-   if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; }
602
-   return $this->lookupVariableName($variableName, $varNo); }
601
+    if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; }
602
+    return $this->lookupVariableName($variableName, $varNo); }
603 603
 
604 604
 /**
605 605
 * Adds an instance of a template block.
@@ -615,48 +615,48 @@  discard block
 block discarded – undo
615 615
 * @access public
616 616
 */
617 617
 function addBlock($blockName) {
618
-   if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; }
619
-   if (!$this->lookupBlockName($blockName, $blockNo)) {
620
-      $this->triggerError("Block \"$blockName\" not defined in template.");
621
-      return false; }
622
-   while ($blockNo != -1) {
623
-      $this->addBlockByNo($blockNo);
624
-      $blockNo = $this->blockTab[$blockNo]['nextWithSameName']; }
625
-   return true; }
618
+    if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; }
619
+    if (!$this->lookupBlockName($blockName, $blockNo)) {
620
+        $this->triggerError("Block \"$blockName\" not defined in template.");
621
+        return false; }
622
+    while ($blockNo != -1) {
623
+        $this->addBlockByNo($blockNo);
624
+        $blockNo = $this->blockTab[$blockNo]['nextWithSameName']; }
625
+    return true; }
626 626
 
627 627
 /**
628 628
 * @access private
629 629
 */
630 630
 function addBlockByNo($blockNo) {
631
-   $btr = & $this->blockTab[$blockNo];
632
-   $this->registerBlockInstance($blockInstNo);
633
-   $bitr = & $this->blockInstTab[$blockInstNo];
634
-   if ($btr['firstBlockInstNo'] == -1)
635
-      $btr['firstBlockInstNo'] = $blockInstNo;
636
-   if ($btr['lastBlockInstNo'] != -1)
637
-      $this->blockInstTab[$btr['lastBlockInstNo']]['nextBlockInstNo'] = $blockInstNo;
638
-         // set forward pointer of chain
639
-   $btr['lastBlockInstNo'] = $blockInstNo;
640
-   $parentBlockNo = $btr['parentBlockNo'];
641
-   $blockVarCnt = $btr['blockVarCnt'];
642
-   $bitr['blockNo'] = $blockNo;
643
-   $bitr['instanceLevel'] = $btr['instances']++;
644
-   if ($parentBlockNo == -1)
645
-      $bitr['parentInstLevel'] = -1;
631
+    $btr = & $this->blockTab[$blockNo];
632
+    $this->registerBlockInstance($blockInstNo);
633
+    $bitr = & $this->blockInstTab[$blockInstNo];
634
+    if ($btr['firstBlockInstNo'] == -1)
635
+        $btr['firstBlockInstNo'] = $blockInstNo;
636
+    if ($btr['lastBlockInstNo'] != -1)
637
+        $this->blockInstTab[$btr['lastBlockInstNo']]['nextBlockInstNo'] = $blockInstNo;
638
+            // set forward pointer of chain
639
+    $btr['lastBlockInstNo'] = $blockInstNo;
640
+    $parentBlockNo = $btr['parentBlockNo'];
641
+    $blockVarCnt = $btr['blockVarCnt'];
642
+    $bitr['blockNo'] = $blockNo;
643
+    $bitr['instanceLevel'] = $btr['instances']++;
644
+    if ($parentBlockNo == -1)
645
+        $bitr['parentInstLevel'] = -1;
646 646
     else
647
-      $bitr['parentInstLevel'] = $this->blockTab[$parentBlockNo]['instances'];
648
-   $bitr['nextBlockInstNo'] = -1;
649
-   $bitr['blockVarTab'] = array();
650
-   // copy instance variables for this block
651
-   for ($blockVarNo = 0; $blockVarNo < $blockVarCnt; $blockVarNo++) {
652
-      $varNo = $btr['blockVarNoToVarNoMap'][$blockVarNo];
653
-      $bitr['blockVarTab'][$blockVarNo] = $this->varTab[$varNo]['varValue']; }}
647
+        $bitr['parentInstLevel'] = $this->blockTab[$parentBlockNo]['instances'];
648
+    $bitr['nextBlockInstNo'] = -1;
649
+    $bitr['blockVarTab'] = array();
650
+    // copy instance variables for this block
651
+    for ($blockVarNo = 0; $blockVarNo < $blockVarCnt; $blockVarNo++) {
652
+        $varNo = $btr['blockVarNoToVarNoMap'][$blockVarNo];
653
+        $bitr['blockVarTab'][$blockVarNo] = $this->varTab[$varNo]['varValue']; }}
654 654
 
655 655
 /**
656 656
 * @access private
657 657
 */
658 658
 function registerBlockInstance(&$blockInstNo) {
659
-   $blockInstNo = $this->blockInstTabCnt++; }
659
+    $blockInstNo = $this->blockInstTabCnt++; }
660 660
 
661 661
 /**
662 662
 * Checks whether a block with the specified name exists within the template.
@@ -666,8 +666,8 @@  discard block
 block discarded – undo
666 666
 * @access public
667 667
 */
668 668
 function blockExists($blockName) {
669
-   if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; }
670
-   return $this->lookupBlockName($blockName, $blockNo); }
669
+    if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; }
670
+    return $this->lookupBlockName($blockName, $blockNo); }
671 671
 
672 672
 //--- output generation ---------------------------------------------------------------------------------------------
673 673
 
@@ -677,11 +677,11 @@  discard block
 block discarded – undo
677 677
 * @access public
678 678
 */
679 679
 function generateOutput() {
680
-   $this->outputMode = 0;
681
-   if (!$this->generateOutputPage()) {
682
-       return false;
683
-   }
684
-   return true; }
680
+    $this->outputMode = 0;
681
+    if (!$this->generateOutputPage()) {
682
+        return false;
683
+    }
684
+    return true; }
685 685
 
686 686
 /**
687 687
 * Generates the HTML page and writes it to a file.
@@ -690,13 +690,13 @@  discard block
 block discarded – undo
690 690
 * @access public
691 691
 */
692 692
 function generateOutputToFile($fileName) {
693
-   $fh = fopen($fileName, "wb");
694
-   if ($fh === false) return false;
695
-   $this->outputMode = 1;
696
-   $this->outputFileHandle = $fh;
697
-   $ok = $this->generateOutputPage();
698
-   fclose($fh);
699
-   return $ok; }
693
+    $fh = fopen($fileName, "wb");
694
+    if ($fh === false) return false;
695
+    $this->outputMode = 1;
696
+    $this->outputFileHandle = $fh;
697
+    $ok = $this->generateOutputPage();
698
+    fclose($fh);
699
+    return $ok; }
700 700
 
701 701
 /**
702 702
 * Generates the HTML page and writes it to a string.
@@ -706,30 +706,30 @@  discard block
 block discarded – undo
706 706
 * @access public
707 707
 */
708 708
 function generateOutputToString(&$outputString) {
709
-   $outputString = "Error";
710
-   $this->outputMode = 2;
711
-   $this->outputString = "";
712
-   if (!$this->generateOutputPage()) {
713
-       return false;
714
-   }
715
-   $outputString = $this->outputString;
716
-   return true; }
709
+    $outputString = "Error";
710
+    $this->outputMode = 2;
711
+    $this->outputString = "";
712
+    if (!$this->generateOutputPage()) {
713
+        return false;
714
+    }
715
+    $outputString = $this->outputString;
716
+    return true; }
717 717
 
718 718
 /**
719 719
 * @access private
720 720
 * @return boolean  true on success, false on error.
721 721
 */
722 722
 function generateOutputPage() {
723
-   if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; }
724
-   if ($this->blockTab[0]['instances'] == 0)
725
-      $this->addBlockByNo(0); // add main block
726
-   for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) {
727
-       $btr = & $this->blockTab[$blockNo];
728
-       $btr['currBlockInstNo'] = $btr['firstBlockInstNo']; }
729
-   $this->outputError = false;
730
-   $this->writeBlockInstances(0, -1);
731
-   if ($this->outputError) return false;
732
-   return true; }
723
+    if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; }
724
+    if ($this->blockTab[0]['instances'] == 0)
725
+        $this->addBlockByNo(0); // add main block
726
+    for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) {
727
+        $btr = & $this->blockTab[$blockNo];
728
+        $btr['currBlockInstNo'] = $btr['firstBlockInstNo']; }
729
+    $this->outputError = false;
730
+    $this->writeBlockInstances(0, -1);
731
+    if ($this->outputError) return false;
732
+    return true; }
733 733
 
734 734
 /**
735 735
 * Writes all instances of a block that are contained within a specific
@@ -738,64 +738,64 @@  discard block
 block discarded – undo
738 738
 * @access private
739 739
 */
740 740
 function writeBlockInstances($blockNo, $parentInstLevel) {
741
-   $btr = & $this->blockTab[$blockNo];
742
-   while (!$this->outputError) {
743
-      $blockInstNo = $btr['currBlockInstNo'];
744
-      if ($blockInstNo == -1) break;
745
-      $bitr = & $this->blockInstTab[$blockInstNo];
746
-      if ($bitr['parentInstLevel'] < $parentInstLevel)
747
-         $this->programLogicError(2);
748
-      if ($bitr['parentInstLevel'] > $parentInstLevel) break;
749
-      $this->writeBlockInstance($blockInstNo);
750
-      $btr['currBlockInstNo'] = $bitr['nextBlockInstNo']; }}
741
+    $btr = & $this->blockTab[$blockNo];
742
+    while (!$this->outputError) {
743
+        $blockInstNo = $btr['currBlockInstNo'];
744
+        if ($blockInstNo == -1) break;
745
+        $bitr = & $this->blockInstTab[$blockInstNo];
746
+        if ($bitr['parentInstLevel'] < $parentInstLevel)
747
+            $this->programLogicError(2);
748
+        if ($bitr['parentInstLevel'] > $parentInstLevel) break;
749
+        $this->writeBlockInstance($blockInstNo);
750
+        $btr['currBlockInstNo'] = $bitr['nextBlockInstNo']; }}
751 751
 
752 752
 /**
753 753
 * @access private
754 754
 */
755 755
 function writeBlockInstance($blockInstNo) {
756
-   $bitr = & $this->blockInstTab[$blockInstNo];
757
-   $blockNo = $bitr['blockNo'];
758
-   $btr = & $this->blockTab[$blockNo];
759
-   $tPos = $btr['tPosContentsBegin'];
760
-   $subBlockNo = $blockNo + 1;
761
-   $varRefNo = $btr['firstVarRefNo'];
762
-   while (!$this->outputError) {
763
-      $tPos2 = $btr['tPosContentsEnd'];
764
-      $kind = 0; // assume end-of-block
765
-      if ($varRefNo != -1 && $varRefNo < $this->varRefTabCnt) {  // check for variable reference
766
-         $vrtr = & $this->varRefTab[$varRefNo];
767
-         if ($vrtr['tPosBegin'] < $tPos) {
756
+    $bitr = & $this->blockInstTab[$blockInstNo];
757
+    $blockNo = $bitr['blockNo'];
758
+    $btr = & $this->blockTab[$blockNo];
759
+    $tPos = $btr['tPosContentsBegin'];
760
+    $subBlockNo = $blockNo + 1;
761
+    $varRefNo = $btr['firstVarRefNo'];
762
+    while (!$this->outputError) {
763
+        $tPos2 = $btr['tPosContentsEnd'];
764
+        $kind = 0; // assume end-of-block
765
+        if ($varRefNo != -1 && $varRefNo < $this->varRefTabCnt) {  // check for variable reference
766
+            $vrtr = & $this->varRefTab[$varRefNo];
767
+            if ($vrtr['tPosBegin'] < $tPos) {
768 768
             $varRefNo += 1;
769 769
             continue; }
770
-         if ($vrtr['tPosBegin'] < $tPos2) {
770
+            if ($vrtr['tPosBegin'] < $tPos2) {
771 771
             $tPos2 = $vrtr['tPosBegin'];
772 772
             $kind = 1; }}
773
-      if ($subBlockNo < $this->blockTabCnt) {   // check for subblock
774
-         $subBtr = & $this->blockTab[$subBlockNo];
775
-         if ($subBtr['tPosBegin'] < $tPos) {
773
+        if ($subBlockNo < $this->blockTabCnt) {   // check for subblock
774
+            $subBtr = & $this->blockTab[$subBlockNo];
775
+            if ($subBtr['tPosBegin'] < $tPos) {
776 776
             $subBlockNo += 1;
777 777
             continue; }
778
-         if ($subBtr['tPosBegin'] < $tPos2) {
778
+            if ($subBtr['tPosBegin'] < $tPos2) {
779 779
             $tPos2 = $subBtr['tPosBegin'];
780 780
             $kind = 2; }}
781
-      if ($tPos2 > $tPos)
782
-         $this->writeString(substr($this->template, $tPos, $tPos2 - $tPos));
783
-      switch ($kind) {
784
-         case 0:         // end of block
781
+        if ($tPos2 > $tPos)
782
+            $this->writeString(substr($this->template, $tPos, $tPos2 - $tPos));
783
+        switch ($kind) {
784
+            case 0:         // end of block
785 785
             return;
786
-         case 1:         // variable
786
+            case 1:         // variable
787 787
             $vrtr = & $this->varRefTab[$varRefNo];
788 788
             if ($vrtr['blockNo'] != $blockNo)
789
-               $this->programLogicError(4);
789
+                $this->programLogicError(4);
790 790
             $variableValue = $bitr['blockVarTab'][$vrtr['blockVarNo']];
791 791
             $this->writeString($variableValue);
792 792
             $tPos = $vrtr['tPosEnd'];
793 793
             $varRefNo += 1;
794 794
             break;
795
-         case 2:         // sub block
795
+            case 2:         // sub block
796 796
             $subBtr = & $this->blockTab[$subBlockNo];
797 797
             if ($subBtr['parentBlockNo'] != $blockNo)
798
-               $this->programLogicError(3);
798
+                $this->programLogicError(3);
799 799
             $this->writeBlockInstances($subBlockNo, $bitr['instanceLevel']); // recursive call
800 800
             $tPos = $subBtr['tPosEnd'];
801 801
             $subBlockNo += 1;
@@ -805,19 +805,19 @@  discard block
 block discarded – undo
805 805
 * @access private
806 806
 */
807 807
 function writeString($s) {
808
-   if ($this->outputError) return;
809
-   switch ($this->outputMode) {
810
-      case 0:            // output to PHP output stream
808
+    if ($this->outputError) return;
809
+    switch ($this->outputMode) {
810
+        case 0:            // output to PHP output stream
811 811
          if (!print($s))
812 812
             $this->outputError = true;
813
-         break;
814
-      case 1:            // output to file
813
+            break;
814
+        case 1:            // output to file
815 815
          $rc = fwrite($this->outputFileHandle, $s);
816
-         if ($rc === false) $this->outputError = true;
817
-         break;
818
-      case 2:            // output to string
816
+            if ($rc === false) $this->outputError = true;
817
+            break;
818
+        case 2:            // output to string
819 819
          $this->outputString .= $s;
820
-         break; }}
820
+            break; }}
821 821
 
822 822
 //--- name lookup routines ------------------------------------------------------------------------------------------
823 823
 
@@ -827,10 +827,10 @@  discard block
 block discarded – undo
827 827
 * @access private
828 828
 */
829 829
 function lookupVariableName($varName, &$varNo) {
830
-   $x = & $this->varNameToNoMap[strtoupper($varName)];
831
-   if (!isset($x)) return false;
832
-   $varNo = $x;
833
-   return true; }
830
+    $x = & $this->varNameToNoMap[strtoupper($varName)];
831
+    if (!isset($x)) return false;
832
+    $varNo = $x;
833
+    return true; }
834 834
 
835 835
 /**
836 836
 * Maps block name to block number.
@@ -840,10 +840,10 @@  discard block
 block discarded – undo
840 840
 * @access private
841 841
 */
842 842
 function lookupBlockName($blockName, &$blockNo) {
843
-   $x = & $this->blockNameToNoMap[strtoupper($blockName)];
844
-   if (!isset($x)) return false;
845
-   $blockNo = $x;
846
-   return true; }
843
+    $x = & $this->blockNameToNoMap[strtoupper($blockName)];
844
+    if (!isset($x)) return false;
845
+    $blockNo = $x;
846
+    return true; }
847 847
 
848 848
 //--- general utility routines -----------------------------------------------------------------------------------------
849 849
 
@@ -853,92 +853,92 @@  discard block
 block discarded – undo
853 853
 * @access private
854 854
 */
855 855
 function readFileIntoString($fileName, &$s) {
856
-   if (function_exists('version_compare') && version_compare(phpversion(), "4.3.0", ">=")) {
857
-      $s = file_get_contents($fileName);
858
-      if ($s === false) return false;
859
-      return true; }
860
-   $fh = fopen($fileName, "rb");
861
-   if ($fh === false) return false;
862
-   $fileSize = filesize($fileName);
863
-   if ($fileSize === false) {fclose($fh); return false; }
864
-   $s = fread($fh, $fileSize);
865
-   fclose($fh);
866
-   if (strlen($s) != $fileSize) return false;
867
-   return true; }
856
+    if (function_exists('version_compare') && version_compare(phpversion(), "4.3.0", ">=")) {
857
+        $s = file_get_contents($fileName);
858
+        if ($s === false) return false;
859
+        return true; }
860
+    $fh = fopen($fileName, "rb");
861
+    if ($fh === false) return false;
862
+    $fileSize = filesize($fileName);
863
+    if ($fileSize === false) {fclose($fh); return false; }
864
+    $s = fread($fh, $fileSize);
865
+    fclose($fh);
866
+    if (strlen($s) != $fileSize) return false;
867
+    return true; }
868 868
 
869 869
 /**
870 870
 * @access private
871 871
 * @return boolean  true on success, false when the end of the string is reached.
872 872
 */
873 873
 function parseWord($s, &$p, &$w) {
874
-   $sLen = strlen($s);
875
-   while ($p < $sLen && ord($s{$p}) <= 32) {
876
-       $p++;
877
-   }
878
-   if ($p >= $sLen) {
879
-       return false;
880
-   }
881
-   $p0 = $p;
882
-   while ($p < $sLen && ord($s{$p}) > 32) {
883
-       $p++;
884
-   }
885
-   $w = substr($s, $p0, $p - $p0);
886
-   return true; }
874
+    $sLen = strlen($s);
875
+    while ($p < $sLen && ord($s{$p}) <= 32) {
876
+        $p++;
877
+    }
878
+    if ($p >= $sLen) {
879
+        return false;
880
+    }
881
+    $p0 = $p;
882
+    while ($p < $sLen && ord($s{$p}) > 32) {
883
+        $p++;
884
+    }
885
+    $w = substr($s, $p0, $p - $p0);
886
+    return true; }
887 887
 
888 888
 /**
889 889
 * @access private
890 890
 * @return boolean  true on success, false on error.
891 891
 */
892 892
 function parseQuotedString($s, &$p, &$w) {
893
-   $sLen = strlen($s);
894
-   while ($p < $sLen && ord($s{$p}) <= 32) $p++;
895
-   if ($p >= $sLen) return false;
896
-   if (substr($s, $p, 1) != '"') return false;
897
-   $p++; $p0 = $p;
898
-   while ($p < $sLen && $s{$p} != '"') $p++;
899
-   if ($p >= $sLen) return false;
900
-   $w = substr($s, $p0, $p - $p0);
901
-   $p++;
902
-   return true; }
893
+    $sLen = strlen($s);
894
+    while ($p < $sLen && ord($s{$p}) <= 32) $p++;
895
+    if ($p >= $sLen) return false;
896
+    if (substr($s, $p, 1) != '"') return false;
897
+    $p++; $p0 = $p;
898
+    while ($p < $sLen && $s{$p} != '"') $p++;
899
+    if ($p >= $sLen) return false;
900
+    $w = substr($s, $p0, $p - $p0);
901
+    $p++;
902
+    return true; }
903 903
 
904 904
 /**
905 905
 * @access private
906 906
 * @return boolean  true on success, false on error.
907 907
 */
908 908
 function parseWordOrQuotedString($s, &$p, &$w) {
909
-   $sLen = strlen($s);
910
-   while ($p < $sLen && ord($s{$p}) <= 32) $p++;
911
-   if ($p >= $sLen) return false;
912
-   if (substr($s, $p, 1) == '"')
913
-      return $this->parseQuotedString($s, $p, $w);
909
+    $sLen = strlen($s);
910
+    while ($p < $sLen && ord($s{$p}) <= 32) $p++;
911
+    if ($p >= $sLen) return false;
912
+    if (substr($s, $p, 1) == '"')
913
+        return $this->parseQuotedString($s, $p, $w);
914 914
     else
915
-      return $this->parseWord($s, $p, $w); }
915
+        return $this->parseWord($s, $p, $w); }
916 916
 
917 917
 /**
918 918
 * Combine two file system paths.
919 919
 * @access private
920 920
 */
921 921
 function combineFileSystemPath($path1, $path2) {
922
-   if ($path1 == '' || $path2 == '') return $path2;
923
-   $s = $path1;
924
-   if (substr($s, -1) != '\\' && substr($s, -1) != '/') $s = $s."/";
925
-   if (substr($path2, 0, 1) == '\\' || substr($path2, 0, 1) == '/')
926
-      $s = $s.substr($path2, 1);
922
+    if ($path1 == '' || $path2 == '') return $path2;
923
+    $s = $path1;
924
+    if (substr($s, -1) != '\\' && substr($s, -1) != '/') $s = $s."/";
925
+    if (substr($path2, 0, 1) == '\\' || substr($path2, 0, 1) == '/')
926
+        $s = $s.substr($path2, 1);
927 927
     else
928
-      $s = $s.$path2;
929
-   return $s; }
928
+        $s = $s.$path2;
929
+    return $s; }
930 930
 
931 931
 /**
932 932
 * @access private
933 933
 */
934 934
 function triggerError($msg) {
935
-   trigger_error("MiniTemplator error: $msg", E_USER_ERROR); }
935
+    trigger_error("MiniTemplator error: $msg", E_USER_ERROR); }
936 936
 
937 937
 /**
938 938
 * @access private
939 939
 */
940 940
 function programLogicError($errorId) {
941
-   die ("MiniTemplator: Program logic error $errorId.\n"); }
941
+    die ("MiniTemplator: Program logic error $errorId.\n"); }
942 942
 
943 943
 }
944 944
 ?>
Please login to merge, or discard this patch.
Switch Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -305,23 +305,23 @@  discard block
 block discarded – undo
305 305
    if (!$this->parseWord($cmdL, $p, $cmd)) return true;
306 306
    $parms = substr($cmdL, $p);
307 307
    switch (strtoupper($cmd)) {
308
-      case '$BEGINBLOCK':
309
-         if (!$this->processBeginBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd))
310
-            return false;
311
-         break;
312
-      case '$ENDBLOCK':
313
-         if (!$this->processEndBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd))
314
-            return false;
315
-         break;
316
-      case '$INCLUDE':
317
-         if (!$this->processincludeCmd($parms, $cmdTPosBegin, $cmdTPosEnd))
318
-            return false;
319
-         $resumeFromStart = true;
320
-         break;
321
-      default:
322
-         if ($cmd{0} == '$' && !(strlen($cmd) >= 2 && $cmd{1} == '{')) {
323
-            $this->triggerError("Unknown command \"$cmd\" in template at offset $cmdTPosBegin.");
324
-            return false; }}
308
+   case '$BEGINBLOCK':
309
+      if (!$this->processBeginBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd))
310
+         return false;
311
+      break;
312
+   case '$ENDBLOCK':
313
+      if (!$this->processEndBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd))
314
+         return false;
315
+      break;
316
+   case '$INCLUDE':
317
+      if (!$this->processincludeCmd($parms, $cmdTPosBegin, $cmdTPosEnd))
318
+         return false;
319
+      $resumeFromStart = true;
320
+      break;
321
+   default:
322
+      if ($cmd{0} == '$' && !(strlen($cmd) >= 2 && $cmd{1} == '{')) {
323
+         $this->triggerError("Unknown command \"$cmd\" in template at offset $cmdTPosBegin.");
324
+         return false; }}
325 325
     return true; }
326 326
 
327 327
 /**
@@ -781,25 +781,25 @@  discard block
 block discarded – undo
781 781
       if ($tPos2 > $tPos)
782 782
          $this->writeString(substr($this->template, $tPos, $tPos2 - $tPos));
783 783
       switch ($kind) {
784
-         case 0:         // end of block
785
-            return;
786
-         case 1:         // variable
787
-            $vrtr = & $this->varRefTab[$varRefNo];
788
-            if ($vrtr['blockNo'] != $blockNo)
789
-               $this->programLogicError(4);
790
-            $variableValue = $bitr['blockVarTab'][$vrtr['blockVarNo']];
791
-            $this->writeString($variableValue);
792
-            $tPos = $vrtr['tPosEnd'];
793
-            $varRefNo += 1;
794
-            break;
795
-         case 2:         // sub block
796
-            $subBtr = & $this->blockTab[$subBlockNo];
797
-            if ($subBtr['parentBlockNo'] != $blockNo)
798
-               $this->programLogicError(3);
799
-            $this->writeBlockInstances($subBlockNo, $bitr['instanceLevel']); // recursive call
800
-            $tPos = $subBtr['tPosEnd'];
801
-            $subBlockNo += 1;
802
-            break; }}}
784
+      case 0:         // end of block
785
+         return;
786
+      case 1:         // variable
787
+         $vrtr = & $this->varRefTab[$varRefNo];
788
+         if ($vrtr['blockNo'] != $blockNo)
789
+            $this->programLogicError(4);
790
+         $variableValue = $bitr['blockVarTab'][$vrtr['blockVarNo']];
791
+         $this->writeString($variableValue);
792
+         $tPos = $vrtr['tPosEnd'];
793
+         $varRefNo += 1;
794
+         break;
795
+      case 2:         // sub block
796
+         $subBtr = & $this->blockTab[$subBlockNo];
797
+         if ($subBtr['parentBlockNo'] != $blockNo)
798
+            $this->programLogicError(3);
799
+         $this->writeBlockInstances($subBlockNo, $bitr['instanceLevel']); // recursive call
800
+         $tPos = $subBtr['tPosEnd'];
801
+         $subBlockNo += 1;
802
+         break; }}}
803 803
 
804 804
 /**
805 805
 * @access private
@@ -807,17 +807,17 @@  discard block
 block discarded – undo
807 807
 function writeString($s) {
808 808
    if ($this->outputError) return;
809 809
    switch ($this->outputMode) {
810
-      case 0:            // output to PHP output stream
811
-         if (!print($s))
812
-            $this->outputError = true;
813
-         break;
814
-      case 1:            // output to file
815
-         $rc = fwrite($this->outputFileHandle, $s);
816
-         if ($rc === false) $this->outputError = true;
817
-         break;
818
-      case 2:            // output to string
819
-         $this->outputString .= $s;
820
-         break; }}
810
+   case 0:            // output to PHP output stream
811
+      if (!print($s))
812
+         $this->outputError = true;
813
+      break;
814
+   case 1:            // output to file
815
+      $rc = fwrite($this->outputFileHandle, $s);
816
+      if ($rc === false) $this->outputError = true;
817
+      break;
818
+   case 2:            // output to string
819
+      $this->outputString .= $s;
820
+      break; }}
821 821
 
822 822
 //--- name lookup routines ------------------------------------------------------------------------------------------
823 823
 
Please login to merge, or discard this patch.
Braces   +144 added lines, -71 removed lines patch added patch discarded remove patch
@@ -282,16 +282,22 @@  discard block
 block discarded – undo
282 282
    $p = 0;
283 283
    while (true) {
284 284
       $p0 = strpos($this->template, '<!--', $p);
285
-      if ($p0 === false) break;
285
+      if ($p0 === false) {
286
+          break;
287
+      }
286 288
       $p = strpos($this->template, '-->', $p0);
287 289
       if ($p === false) {
288 290
          $this->triggerError("Invalid HTML comment in template at offset $p0.");
289 291
          return false; }
290 292
       $p += 3;
291 293
       $cmdL = substr($this->template, $p0 + 4, $p - $p0 - 7);
292
-      if (!$this->processTemplateCommand($cmdL, $p0, $p, $resumeFromStart))
293
-         return false;
294
-      if ($resumeFromStart) $p = $p0; }
294
+      if (!$this->processTemplateCommand($cmdL, $p0, $p, $resumeFromStart)) {
295
+               return false;
296
+      }
297
+      if ($resumeFromStart) {
298
+          $p = $p0;
299
+      }
300
+      }
295 301
    return true; }
296 302
 
297 303
 /**
@@ -302,20 +308,25 @@  discard block
 block discarded – undo
302 308
    $resumeFromStart = false;
303 309
    $p = 0;
304 310
    $cmd = '';
305
-   if (!$this->parseWord($cmdL, $p, $cmd)) return true;
311
+   if (!$this->parseWord($cmdL, $p, $cmd)) {
312
+       return true;
313
+   }
306 314
    $parms = substr($cmdL, $p);
307 315
    switch (strtoupper($cmd)) {
308 316
       case '$BEGINBLOCK':
309
-         if (!$this->processBeginBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd))
310
-            return false;
317
+         if (!$this->processBeginBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd)) {
318
+                     return false;
319
+         }
311 320
          break;
312 321
       case '$ENDBLOCK':
313
-         if (!$this->processEndBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd))
314
-            return false;
322
+         if (!$this->processEndBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd)) {
323
+                     return false;
324
+         }
315 325
          break;
316 326
       case '$INCLUDE':
317
-         if (!$this->processincludeCmd($parms, $cmdTPosBegin, $cmdTPosEnd))
318
-            return false;
327
+         if (!$this->processincludeCmd($parms, $cmdTPosBegin, $cmdTPosEnd)) {
328
+                     return false;
329
+         }
319 330
          $resumeFromStart = true;
320 331
          break;
321 332
       default:
@@ -387,8 +398,9 @@  discard block
 block discarded – undo
387 398
    $btr = & $this->blockTab[$blockNo];
388 399
    $btr = array();
389 400
    $btr['blockName'] = $blockName;
390
-   if (!$this->lookupBlockName($blockName, $btr['nextWithSameName']))
391
-      $btr['nextWithSameName'] = -1;
401
+   if (!$this->lookupBlockName($blockName, $btr['nextWithSameName'])) {
402
+         $btr['nextWithSameName'] = -1;
403
+   }
392 404
    $btr['definitionIsOpen'] = true;
393 405
    $btr['instances'] = 0;
394 406
    $btr['firstBlockInstNo'] = -1;
@@ -438,7 +450,9 @@  discard block
 block discarded – undo
438 450
    if (strlen($this->template) > $this->maxInclTemplateSize) {
439 451
       $this->triggerError("Subtemplate include aborted because the internal template string is longer than $this->maxInclTemplateSize characters.");
440 452
       return false; }
441
-   if (!$this->loadSubtemplate($subtemplateName, $subtemplate)) return false;
453
+   if (!$this->loadSubtemplate($subtemplateName, $subtemplate)) {
454
+       return false;
455
+   }
442 456
    // (Copying the template to insert a subtemplate is a bit slow. In a future implementation of MiniTemplator,
443 457
    // a table could be used that contains references to the string fragments.)
444 458
    $this->template = substr($this->template, 0, $tPos1).$subtemplate.substr($this->template, $tPos2);
@@ -473,8 +487,9 @@  discard block
 block discarded – undo
473 487
 * @access private
474 488
 */
475 489
 function registerVariableReference($varName, $tPosBegin, $tPosEnd) {
476
-   if (!$this->lookupVariableName($varName, $varNo))
477
-      $this->registerVariable($varName, $varNo);
490
+   if (!$this->lookupVariableName($varName, $varNo)) {
491
+         $this->registerVariable($varName, $varNo);
492
+   }
478 493
    $varRefNo = $this->varRefTabCnt++;
479 494
    $vrtr = & $this->varRefTab[$varRefNo];
480 495
    $vrtr = array();
@@ -514,12 +529,14 @@  discard block
 block discarded – undo
514 529
             $nextBlockNo += 1;
515 530
             continue; }}
516 531
       $btr = & $this->blockTab[$activeBlockNo];
517
-      if ($varRefTPos < $btr['tPosBegin'])
518
-         $this->programLogicError(1);
532
+      if ($varRefTPos < $btr['tPosBegin']) {
533
+               $this->programLogicError(1);
534
+      }
519 535
       $blockVarNo = $btr['blockVarCnt']++;
520 536
       $btr['blockVarNoToVarNoMap'][$blockVarNo] = $varNo;
521
-      if ($btr['firstVarRefNo'] == -1)
522
-         $btr['firstVarRefNo'] = $varRefNo;
537
+      if ($btr['firstVarRefNo'] == -1) {
538
+               $btr['firstVarRefNo'] = $varRefNo;
539
+      }
523 540
       $vrtr['blockNo'] = $activeBlockNo;
524 541
       $vrtr['blockVarNo'] = $blockVarNo;
525 542
       $varRefNo += 1; }}
@@ -535,8 +552,9 @@  discard block
 block discarded – undo
535 552
 * @access public
536 553
 */
537 554
 function reset() {
538
-   for ($varNo = 0; $varNo < $this->varTabCnt; $varNo++)
539
-      $this->varTab[$varNo]['varValue'] = '';
555
+   for ($varNo = 0; $varNo < $this->varTabCnt; $varNo++) {
556
+         $this->varTab[$varNo]['varValue'] = '';
557
+   }
540 558
    for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) {
541 559
       $btr = & $this->blockTab[$blockNo];
542 560
       $btr['instances'] = 0;
@@ -563,7 +581,9 @@  discard block
 block discarded – undo
563 581
 function setVariable($variableName, $variableValue, $isOptional = false) {
564 582
    if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; }
565 583
    if (!$this->lookupVariableName($variableName, $varNo)) {
566
-      if ($isOptional) return true;
584
+      if ($isOptional) {
585
+          return true;
586
+      }
567 587
       $this->triggerError("Variable \"$variableName\" not defined in template.");
568 588
       return false; }
569 589
    $this->varTab[$varNo]['varValue'] = $variableValue;
@@ -631,20 +651,23 @@  discard block
 block discarded – undo
631 651
    $btr = & $this->blockTab[$blockNo];
632 652
    $this->registerBlockInstance($blockInstNo);
633 653
    $bitr = & $this->blockInstTab[$blockInstNo];
634
-   if ($btr['firstBlockInstNo'] == -1)
635
-      $btr['firstBlockInstNo'] = $blockInstNo;
636
-   if ($btr['lastBlockInstNo'] != -1)
637
-      $this->blockInstTab[$btr['lastBlockInstNo']]['nextBlockInstNo'] = $blockInstNo;
654
+   if ($btr['firstBlockInstNo'] == -1) {
655
+         $btr['firstBlockInstNo'] = $blockInstNo;
656
+   }
657
+   if ($btr['lastBlockInstNo'] != -1) {
658
+         $this->blockInstTab[$btr['lastBlockInstNo']]['nextBlockInstNo'] = $blockInstNo;
659
+   }
638 660
          // set forward pointer of chain
639 661
    $btr['lastBlockInstNo'] = $blockInstNo;
640 662
    $parentBlockNo = $btr['parentBlockNo'];
641 663
    $blockVarCnt = $btr['blockVarCnt'];
642 664
    $bitr['blockNo'] = $blockNo;
643 665
    $bitr['instanceLevel'] = $btr['instances']++;
644
-   if ($parentBlockNo == -1)
645
-      $bitr['parentInstLevel'] = -1;
646
-    else
647
-      $bitr['parentInstLevel'] = $this->blockTab[$parentBlockNo]['instances'];
666
+   if ($parentBlockNo == -1) {
667
+         $bitr['parentInstLevel'] = -1;
668
+   } else {
669
+          $bitr['parentInstLevel'] = $this->blockTab[$parentBlockNo]['instances'];
670
+    }
648 671
    $bitr['nextBlockInstNo'] = -1;
649 672
    $bitr['blockVarTab'] = array();
650 673
    // copy instance variables for this block
@@ -691,7 +714,9 @@  discard block
 block discarded – undo
691 714
 */
692 715
 function generateOutputToFile($fileName) {
693 716
    $fh = fopen($fileName, "wb");
694
-   if ($fh === false) return false;
717
+   if ($fh === false) {
718
+       return false;
719
+   }
695 720
    $this->outputMode = 1;
696 721
    $this->outputFileHandle = $fh;
697 722
    $ok = $this->generateOutputPage();
@@ -721,14 +746,18 @@  discard block
 block discarded – undo
721 746
 */
722 747
 function generateOutputPage() {
723 748
    if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; }
724
-   if ($this->blockTab[0]['instances'] == 0)
725
-      $this->addBlockByNo(0); // add main block
749
+   if ($this->blockTab[0]['instances'] == 0) {
750
+         $this->addBlockByNo(0);
751
+   }
752
+   // add main block
726 753
    for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) {
727 754
        $btr = & $this->blockTab[$blockNo];
728 755
        $btr['currBlockInstNo'] = $btr['firstBlockInstNo']; }
729 756
    $this->outputError = false;
730 757
    $this->writeBlockInstances(0, -1);
731
-   if ($this->outputError) return false;
758
+   if ($this->outputError) {
759
+       return false;
760
+   }
732 761
    return true; }
733 762
 
734 763
 /**
@@ -741,11 +770,16 @@  discard block
 block discarded – undo
741 770
    $btr = & $this->blockTab[$blockNo];
742 771
    while (!$this->outputError) {
743 772
       $blockInstNo = $btr['currBlockInstNo'];
744
-      if ($blockInstNo == -1) break;
773
+      if ($blockInstNo == -1) {
774
+          break;
775
+      }
745 776
       $bitr = & $this->blockInstTab[$blockInstNo];
746
-      if ($bitr['parentInstLevel'] < $parentInstLevel)
747
-         $this->programLogicError(2);
748
-      if ($bitr['parentInstLevel'] > $parentInstLevel) break;
777
+      if ($bitr['parentInstLevel'] < $parentInstLevel) {
778
+               $this->programLogicError(2);
779
+      }
780
+      if ($bitr['parentInstLevel'] > $parentInstLevel) {
781
+          break;
782
+      }
749 783
       $this->writeBlockInstance($blockInstNo);
750 784
       $btr['currBlockInstNo'] = $bitr['nextBlockInstNo']; }}
751 785
 
@@ -778,15 +812,17 @@  discard block
 block discarded – undo
778 812
          if ($subBtr['tPosBegin'] < $tPos2) {
779 813
             $tPos2 = $subBtr['tPosBegin'];
780 814
             $kind = 2; }}
781
-      if ($tPos2 > $tPos)
782
-         $this->writeString(substr($this->template, $tPos, $tPos2 - $tPos));
815
+      if ($tPos2 > $tPos) {
816
+               $this->writeString(substr($this->template, $tPos, $tPos2 - $tPos));
817
+      }
783 818
       switch ($kind) {
784 819
          case 0:         // end of block
785 820
             return;
786 821
          case 1:         // variable
787 822
             $vrtr = & $this->varRefTab[$varRefNo];
788
-            if ($vrtr['blockNo'] != $blockNo)
789
-               $this->programLogicError(4);
823
+            if ($vrtr['blockNo'] != $blockNo) {
824
+                           $this->programLogicError(4);
825
+            }
790 826
             $variableValue = $bitr['blockVarTab'][$vrtr['blockVarNo']];
791 827
             $this->writeString($variableValue);
792 828
             $tPos = $vrtr['tPosEnd'];
@@ -794,8 +830,9 @@  discard block
 block discarded – undo
794 830
             break;
795 831
          case 2:         // sub block
796 832
             $subBtr = & $this->blockTab[$subBlockNo];
797
-            if ($subBtr['parentBlockNo'] != $blockNo)
798
-               $this->programLogicError(3);
833
+            if ($subBtr['parentBlockNo'] != $blockNo) {
834
+                           $this->programLogicError(3);
835
+            }
799 836
             $this->writeBlockInstances($subBlockNo, $bitr['instanceLevel']); // recursive call
800 837
             $tPos = $subBtr['tPosEnd'];
801 838
             $subBlockNo += 1;
@@ -805,15 +842,20 @@  discard block
 block discarded – undo
805 842
 * @access private
806 843
 */
807 844
 function writeString($s) {
808
-   if ($this->outputError) return;
845
+   if ($this->outputError) {
846
+       return;
847
+   }
809 848
    switch ($this->outputMode) {
810 849
       case 0:            // output to PHP output stream
811
-         if (!print($s))
812
-            $this->outputError = true;
850
+         if (!print($s)) {
851
+                     $this->outputError = true;
852
+         }
813 853
          break;
814 854
       case 1:            // output to file
815 855
          $rc = fwrite($this->outputFileHandle, $s);
816
-         if ($rc === false) $this->outputError = true;
856
+         if ($rc === false) {
857
+             $this->outputError = true;
858
+         }
817 859
          break;
818 860
       case 2:            // output to string
819 861
          $this->outputString .= $s;
@@ -828,7 +870,9 @@  discard block
 block discarded – undo
828 870
 */
829 871
 function lookupVariableName($varName, &$varNo) {
830 872
    $x = & $this->varNameToNoMap[strtoupper($varName)];
831
-   if (!isset($x)) return false;
873
+   if (!isset($x)) {
874
+       return false;
875
+   }
832 876
    $varNo = $x;
833 877
    return true; }
834 878
 
@@ -841,7 +885,9 @@  discard block
 block discarded – undo
841 885
 */
842 886
 function lookupBlockName($blockName, &$blockNo) {
843 887
    $x = & $this->blockNameToNoMap[strtoupper($blockName)];
844
-   if (!isset($x)) return false;
888
+   if (!isset($x)) {
889
+       return false;
890
+   }
845 891
    $blockNo = $x;
846 892
    return true; }
847 893
 
@@ -855,15 +901,21 @@  discard block
 block discarded – undo
855 901
 function readFileIntoString($fileName, &$s) {
856 902
    if (function_exists('version_compare') && version_compare(phpversion(), "4.3.0", ">=")) {
857 903
       $s = file_get_contents($fileName);
858
-      if ($s === false) return false;
904
+      if ($s === false) {
905
+          return false;
906
+      }
859 907
       return true; }
860 908
    $fh = fopen($fileName, "rb");
861
-   if ($fh === false) return false;
909
+   if ($fh === false) {
910
+       return false;
911
+   }
862 912
    $fileSize = filesize($fileName);
863 913
    if ($fileSize === false) {fclose($fh); return false; }
864 914
    $s = fread($fh, $fileSize);
865 915
    fclose($fh);
866
-   if (strlen($s) != $fileSize) return false;
916
+   if (strlen($s) != $fileSize) {
917
+       return false;
918
+   }
867 919
    return true; }
868 920
 
869 921
 /**
@@ -891,12 +943,22 @@  discard block
 block discarded – undo
891 943
 */
892 944
 function parseQuotedString($s, &$p, &$w) {
893 945
    $sLen = strlen($s);
894
-   while ($p < $sLen && ord($s{$p}) <= 32) $p++;
895
-   if ($p >= $sLen) return false;
896
-   if (substr($s, $p, 1) != '"') return false;
946
+   while ($p < $sLen && ord($s{$p}) <= 32) {
947
+       $p++;
948
+   }
949
+   if ($p >= $sLen) {
950
+       return false;
951
+   }
952
+   if (substr($s, $p, 1) != '"') {
953
+       return false;
954
+   }
897 955
    $p++; $p0 = $p;
898
-   while ($p < $sLen && $s{$p} != '"') $p++;
899
-   if ($p >= $sLen) return false;
956
+   while ($p < $sLen && $s{$p} != '"') {
957
+       $p++;
958
+   }
959
+   if ($p >= $sLen) {
960
+       return false;
961
+   }
900 962
    $w = substr($s, $p0, $p - $p0);
901 963
    $p++;
902 964
    return true; }
@@ -907,25 +969,36 @@  discard block
 block discarded – undo
907 969
 */
908 970
 function parseWordOrQuotedString($s, &$p, &$w) {
909 971
    $sLen = strlen($s);
910
-   while ($p < $sLen && ord($s{$p}) <= 32) $p++;
911
-   if ($p >= $sLen) return false;
912
-   if (substr($s, $p, 1) == '"')
913
-      return $this->parseQuotedString($s, $p, $w);
914
-    else
915
-      return $this->parseWord($s, $p, $w); }
972
+   while ($p < $sLen && ord($s{$p}) <= 32) {
973
+       $p++;
974
+   }
975
+   if ($p >= $sLen) {
976
+       return false;
977
+   }
978
+   if (substr($s, $p, 1) == '"') {
979
+         return $this->parseQuotedString($s, $p, $w);
980
+   } else {
981
+          return $this->parseWord($s, $p, $w);
982
+    }
983
+    }
916 984
 
917 985
 /**
918 986
 * Combine two file system paths.
919 987
 * @access private
920 988
 */
921 989
 function combineFileSystemPath($path1, $path2) {
922
-   if ($path1 == '' || $path2 == '') return $path2;
990
+   if ($path1 == '' || $path2 == '') {
991
+       return $path2;
992
+   }
923 993
    $s = $path1;
924
-   if (substr($s, -1) != '\\' && substr($s, -1) != '/') $s = $s."/";
925
-   if (substr($path2, 0, 1) == '\\' || substr($path2, 0, 1) == '/')
926
-      $s = $s.substr($path2, 1);
927
-    else
928
-      $s = $s.$path2;
994
+   if (substr($s, -1) != '\\' && substr($s, -1) != '/') {
995
+       $s = $s."/";
996
+   }
997
+   if (substr($path2, 0, 1) == '\\' || substr($path2, 0, 1) == '/') {
998
+         $s = $s.substr($path2, 1);
999
+   } else {
1000
+          $s = $s.$path2;
1001
+    }
929 1002
    return $s; }
930 1003
 
931 1004
 /**
Please login to merge, or discard this patch.
lib/gettext/streams.php 2 patches
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -21,148 +21,148 @@
 block discarded – undo
21 21
 */
22 22
 
23 23
 
24
-  // Simple class to wrap file streams, string streams, etc.
25
-  // seek is essential, and it should be byte stream
24
+    // Simple class to wrap file streams, string streams, etc.
25
+    // seek is essential, and it should be byte stream
26 26
 class StreamReader {
27
-  // should return a string [FIXME: perhaps return array of bytes?]
28
-  function read($bytes) {
27
+    // should return a string [FIXME: perhaps return array of bytes?]
28
+    function read($bytes) {
29 29
     return false;
30
-  }
30
+    }
31 31
 
32
-  // should return new position
33
-  function seekto($position) {
32
+    // should return new position
33
+    function seekto($position) {
34 34
     return false;
35
-  }
35
+    }
36 36
 
37
-  // returns current position
38
-  function currentpos() {
37
+    // returns current position
38
+    function currentpos() {
39 39
     return false;
40
-  }
40
+    }
41 41
 
42
-  // returns length of entire stream (limit for seekto()s)
43
-  function length() {
42
+    // returns length of entire stream (limit for seekto()s)
43
+    function length() {
44 44
     return false;
45
-  }
45
+    }
46 46
 };
47 47
 
48 48
 class StringReader {
49
-  var $_pos;
50
-  var $_str;
49
+    var $_pos;
50
+    var $_str;
51 51
 
52
-  function StringReader($str = '') {
52
+    function StringReader($str = '') {
53 53
     $this->_str = $str;
54 54
     $this->_pos = 0;
55
-  }
55
+    }
56 56
 
57
-  function read($bytes) {
57
+    function read($bytes) {
58 58
     $data = substr($this->_str, $this->_pos, $bytes);
59 59
     $this->_pos += $bytes;
60 60
     if (strlen($this->_str) < $this->_pos)
61
-      $this->_pos = strlen($this->_str);
61
+        $this->_pos = strlen($this->_str);
62 62
 
63 63
     return $data;
64
-  }
64
+    }
65 65
 
66
-  function seekto($pos) {
66
+    function seekto($pos) {
67 67
     $this->_pos = $pos;
68 68
     if (strlen($this->_str) < $this->_pos)
69
-      $this->_pos = strlen($this->_str);
69
+        $this->_pos = strlen($this->_str);
70 70
     return $this->_pos;
71
-  }
71
+    }
72 72
 
73
-  function currentpos() {
73
+    function currentpos() {
74 74
     return $this->_pos;
75
-  }
75
+    }
76 76
 
77
-  function length() {
77
+    function length() {
78 78
     return strlen($this->_str);
79
-  }
79
+    }
80 80
 
81 81
 };
82 82
 
83 83
 
84 84
 class FileReader {
85
-  var $_pos;
86
-  var $_fd;
87
-  var $_length;
85
+    var $_pos;
86
+    var $_fd;
87
+    var $_length;
88 88
 
89
-  function FileReader($filename) {
89
+    function FileReader($filename) {
90 90
     if (file_exists($filename)) {
91 91
 
92
-      $this->_length = filesize($filename);
93
-      $this->_pos = 0;
94
-      $this->_fd = fopen($filename, 'rb');
95
-      if (!$this->_fd) {
92
+        $this->_length = filesize($filename);
93
+        $this->_pos = 0;
94
+        $this->_fd = fopen($filename, 'rb');
95
+        if (!$this->_fd) {
96 96
         $this->error = 3; // Cannot read file, probably permissions
97 97
         return false;
98
-      }
98
+        }
99 99
     } else {
100
-      $this->error = 2; // File doesn't exist
101
-      return false;
100
+        $this->error = 2; // File doesn't exist
101
+        return false;
102
+    }
102 103
     }
103
-  }
104 104
 
105
-  function read($bytes) {
105
+    function read($bytes) {
106 106
     if ($bytes) {
107
-      fseek($this->_fd, $this->_pos);
107
+        fseek($this->_fd, $this->_pos);
108 108
 
109
-      // PHP 5.1.1 does not read more than 8192 bytes in one fread()
110
-      // the discussions at PHP Bugs suggest it's the intended behaviour
111
-      $data = '';
112
-      while ($bytes > 0) {
109
+        // PHP 5.1.1 does not read more than 8192 bytes in one fread()
110
+        // the discussions at PHP Bugs suggest it's the intended behaviour
111
+        $data = '';
112
+        while ($bytes > 0) {
113 113
         $chunk  = fread($this->_fd, $bytes);
114 114
         $data  .= $chunk;
115 115
         $bytes -= strlen($chunk);
116
-      }
117
-      $this->_pos = ftell($this->_fd);
116
+        }
117
+        $this->_pos = ftell($this->_fd);
118 118
 
119
-      return $data;
119
+        return $data;
120 120
     } else {
121 121
         return '';
122 122
     }
123
-  }
123
+    }
124 124
 
125
-  function seekto($pos) {
125
+    function seekto($pos) {
126 126
     fseek($this->_fd, $pos);
127 127
     $this->_pos = ftell($this->_fd);
128 128
     return $this->_pos;
129
-  }
129
+    }
130 130
 
131
-  function currentpos() {
131
+    function currentpos() {
132 132
     return $this->_pos;
133
-  }
133
+    }
134 134
 
135
-  function length() {
135
+    function length() {
136 136
     return $this->_length;
137
-  }
137
+    }
138 138
 
139
-  function close() {
139
+    function close() {
140 140
     fclose($this->_fd);
141
-  }
141
+    }
142 142
 
143 143
 };
144 144
 
145 145
 // Preloads entire file in memory first, then creates a StringReader
146 146
 // over it (it assumes knowledge of StringReader internals)
147 147
 class CachedFileReader extends StringReader {
148
-  function CachedFileReader($filename) {
148
+    function CachedFileReader($filename) {
149 149
     if (file_exists($filename)) {
150 150
 
151
-      $length = filesize($filename);
152
-      $fd = fopen($filename, 'rb');
151
+        $length = filesize($filename);
152
+        $fd = fopen($filename, 'rb');
153 153
 
154
-      if (!$fd) {
154
+        if (!$fd) {
155 155
         $this->error = 3; // Cannot read file, probably permissions
156 156
         return false;
157
-      }
158
-      $this->_str = fread($fd, $length);
159
-      fclose($fd);
157
+        }
158
+        $this->_str = fread($fd, $length);
159
+        fclose($fd);
160 160
 
161 161
     } else {
162
-      $this->error = 2; // File doesn't exist
163
-      return false;
162
+        $this->error = 2; // File doesn't exist
163
+        return false;
164
+    }
164 165
     }
165
-  }
166 166
 };
167 167
 
168 168
 
Please login to merge, or discard this patch.
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -57,16 +57,18 @@
 block discarded – undo
57 57
   function read($bytes) {
58 58
     $data = substr($this->_str, $this->_pos, $bytes);
59 59
     $this->_pos += $bytes;
60
-    if (strlen($this->_str) < $this->_pos)
61
-      $this->_pos = strlen($this->_str);
60
+    if (strlen($this->_str) < $this->_pos) {
61
+          $this->_pos = strlen($this->_str);
62
+    }
62 63
 
63 64
     return $data;
64 65
   }
65 66
 
66 67
   function seekto($pos) {
67 68
     $this->_pos = $pos;
68
-    if (strlen($this->_str) < $this->_pos)
69
-      $this->_pos = strlen($this->_str);
69
+    if (strlen($this->_str) < $this->_pos) {
70
+          $this->_pos = strlen($this->_str);
71
+    }
70 72
     return $this->_pos;
71 73
   }
72 74
 
Please login to merge, or discard this patch.
lib/gettext/gettext.php 2 patches
Indentation   +244 added lines, -244 removed lines patch added patch discarded remove patch
@@ -34,75 +34,75 @@  discard block
 block discarded – undo
34 34
  * that you don't want to keep in memory)
35 35
  */
36 36
 class gettext_reader {
37
-  //public:
38
-   var $error = 0; // public variable that holds error code (0 if no error)
39
-
40
-   //private:
41
-  var $BYTEORDER = 0; // 0: low endian, 1: big endian
42
-  var $STREAM = null;
43
-  var $short_circuit = false;
44
-  var $enable_cache = false;
45
-  var $originals = null; // offset of original table
46
-  var $translations = null; // offset of translation table
47
-  var $pluralheader = null; // cache header field for plural forms
48
-  var $total = 0; // total string count
49
-  var $table_originals = null; // table for original strings (offsets)
50
-  var $table_translations = null; // table for translated strings (offsets)
51
-  var $cache_translations = null; // original -> translation mapping
52
-
53
-
54
-  /* Methods */
55
-
56
-
57
-  /**
58
-   * Reads a 32bit Integer from the Stream
59
-   *
60
-   * @access private
61
-   * @return Integer from the Stream
62
-   */
63
-  function readint() {
64
-      if ($this->BYTEORDER == 0) {
37
+    //public:
38
+    var $error = 0; // public variable that holds error code (0 if no error)
39
+
40
+    //private:
41
+    var $BYTEORDER = 0; // 0: low endian, 1: big endian
42
+    var $STREAM = null;
43
+    var $short_circuit = false;
44
+    var $enable_cache = false;
45
+    var $originals = null; // offset of original table
46
+    var $translations = null; // offset of translation table
47
+    var $pluralheader = null; // cache header field for plural forms
48
+    var $total = 0; // total string count
49
+    var $table_originals = null; // table for original strings (offsets)
50
+    var $table_translations = null; // table for translated strings (offsets)
51
+    var $cache_translations = null; // original -> translation mapping
52
+
53
+
54
+    /* Methods */
55
+
56
+
57
+    /**
58
+     * Reads a 32bit Integer from the Stream
59
+     *
60
+     * @access private
61
+     * @return Integer from the Stream
62
+     */
63
+    function readint() {
64
+        if ($this->BYTEORDER == 0) {
65 65
         // low endian
66 66
         $input = unpack('V', $this->STREAM->read(4));
67 67
         return array_shift($input);
68
-      } else {
68
+        } else {
69 69
         // big endian
70 70
         $input = unpack('N', $this->STREAM->read(4));
71 71
         return array_shift($input);
72
-      }
72
+        }
73 73
     }
74 74
 
75
-  function read($bytes) {
75
+    function read($bytes) {
76 76
     return $this->STREAM->read($bytes);
77
-  }
78
-
79
-  /**
80
-   * Reads an array of Integers from the Stream
81
-   *
82
-   * @param int count How many elements should be read
83
-   * @return Array of Integers
84
-   */
85
-  function readintarray($count) {
77
+    }
78
+
79
+    /**
80
+     * Reads an array of Integers from the Stream
81
+     *
82
+     * @param int count How many elements should be read
83
+     * @return Array of Integers
84
+     */
85
+    function readintarray($count) {
86 86
     if ($this->BYTEORDER == 0) {
87 87
         // low endian
88 88
         return unpack('V'.$count, $this->STREAM->read(4 * $count));
89
-      } else {
89
+        } else {
90 90
         // big endian
91 91
         return unpack('N'.$count, $this->STREAM->read(4 * $count));
92
-      }
93
-  }
94
-
95
-  /**
96
-   * Constructor
97
-   *
98
-   * @param object Reader the StreamReader object
99
-   * @param boolean enable_cache Enable or disable caching of strings (default on)
100
-   */
101
-  function __construct($Reader, $enable_cache = true) {
92
+        }
93
+    }
94
+
95
+    /**
96
+     * Constructor
97
+     *
98
+     * @param object Reader the StreamReader object
99
+     * @param boolean enable_cache Enable or disable caching of strings (default on)
100
+     */
101
+    function __construct($Reader, $enable_cache = true) {
102 102
     // If there isn't a StreamReader, turn on short circuit mode.
103 103
     if (!$Reader || isset($Reader->error)) {
104
-      $this->short_circuit = true;
105
-      return;
104
+        $this->short_circuit = true;
105
+        return;
106 106
     }
107 107
 
108 108
     // Caching can be turned off
@@ -114,12 +114,12 @@  discard block
 block discarded – undo
114 114
     $this->STREAM = $Reader;
115 115
     $magic = $this->read(4);
116 116
     if ($magic == $MAGIC1) {
117
-      $this->BYTEORDER = 1;
117
+        $this->BYTEORDER = 1;
118 118
     } elseif ($magic == $MAGIC2) {
119
-      $this->BYTEORDER = 0;
119
+        $this->BYTEORDER = 0;
120 120
     } else {
121
-      $this->error = 1; // not MO file
122
-      return false;
121
+        $this->error = 1; // not MO file
122
+        return false;
123 123
     }
124 124
 
125 125
     // FIXME: Do we care about revision? We should.
@@ -128,162 +128,162 @@  discard block
 block discarded – undo
128 128
     $this->total = $this->readint();
129 129
     $this->originals = $this->readint();
130 130
     $this->translations = $this->readint();
131
-  }
132
-
133
-  /**
134
-   * Loads the translation tables from the MO file into the cache
135
-   * If caching is enabled, also loads all strings into a cache
136
-   * to speed up translation lookups
137
-   *
138
-   * @access private
139
-   */
140
-  function load_tables() {
131
+    }
132
+
133
+    /**
134
+     * Loads the translation tables from the MO file into the cache
135
+     * If caching is enabled, also loads all strings into a cache
136
+     * to speed up translation lookups
137
+     *
138
+     * @access private
139
+     */
140
+    function load_tables() {
141 141
     if (is_array($this->cache_translations) &&
142 142
       is_array($this->table_originals) &&
143 143
       is_array($this->table_translations)) {
144
-          return;
144
+            return;
145 145
     }
146 146
 
147 147
     /* get original and translations tables */
148 148
     if (!is_array($this->table_originals)) {
149
-      $this->STREAM->seekto($this->originals);
150
-      $this->table_originals = $this->readintarray($this->total * 2);
149
+        $this->STREAM->seekto($this->originals);
150
+        $this->table_originals = $this->readintarray($this->total * 2);
151 151
     }
152 152
     if (!is_array($this->table_translations)) {
153
-      $this->STREAM->seekto($this->translations);
154
-      $this->table_translations = $this->readintarray($this->total * 2);
153
+        $this->STREAM->seekto($this->translations);
154
+        $this->table_translations = $this->readintarray($this->total * 2);
155 155
     }
156 156
 
157 157
     if ($this->enable_cache) {
158
-      $this->cache_translations = array();
159
-      /* read all strings in the cache */
160
-      for ($i = 0; $i < $this->total; $i++) {
158
+        $this->cache_translations = array();
159
+        /* read all strings in the cache */
160
+        for ($i = 0; $i < $this->total; $i++) {
161 161
         $this->STREAM->seekto($this->table_originals[$i * 2 + 2]);
162 162
         $original = $this->STREAM->read($this->table_originals[$i * 2 + 1]);
163 163
         $this->STREAM->seekto($this->table_translations[$i * 2 + 2]);
164 164
         $translation = $this->STREAM->read($this->table_translations[$i * 2 + 1]);
165 165
         $this->cache_translations[$original] = $translation;
166
-      }
167
-    }
168
-  }
169
-
170
-  /**
171
-   * Returns a string from the "originals" table
172
-   *
173
-   * @access private
174
-   * @param int num Offset number of original string
175
-   * @return string Requested string if found, otherwise ''
176
-   */
177
-  function get_original_string($num) {
166
+        }
167
+    }
168
+    }
169
+
170
+    /**
171
+     * Returns a string from the "originals" table
172
+     *
173
+     * @access private
174
+     * @param int num Offset number of original string
175
+     * @return string Requested string if found, otherwise ''
176
+     */
177
+    function get_original_string($num) {
178 178
     $length = $this->table_originals[$num * 2 + 1];
179 179
     $offset = $this->table_originals[$num * 2 + 2];
180 180
     if (! $length) {
181
-          return '';
181
+            return '';
182 182
     }
183 183
     $this->STREAM->seekto($offset);
184 184
     $data = $this->STREAM->read($length);
185 185
     return (string)$data;
186
-  }
187
-
188
-  /**
189
-   * Returns a string from the "translations" table
190
-   *
191
-   * @access private
192
-   * @param int num Offset number of original string
193
-   * @return string Requested string if found, otherwise ''
194
-   */
195
-  function get_translation_string($num) {
186
+    }
187
+
188
+    /**
189
+     * Returns a string from the "translations" table
190
+     *
191
+     * @access private
192
+     * @param int num Offset number of original string
193
+     * @return string Requested string if found, otherwise ''
194
+     */
195
+    function get_translation_string($num) {
196 196
     $length = $this->table_translations[$num * 2 + 1];
197 197
     $offset = $this->table_translations[$num * 2 + 2];
198 198
     if (! $length) {
199
-          return '';
199
+            return '';
200 200
     }
201 201
     $this->STREAM->seekto($offset);
202 202
     $data = $this->STREAM->read($length);
203 203
     return (string)$data;
204
-  }
205
-
206
-  /**
207
-   * Binary search for string
208
-   *
209
-   * @access private
210
-   * @param string string
211
-   * @param int start (internally used in recursive function)
212
-   * @param int end (internally used in recursive function)
213
-   * @return int string number (offset in originals table)
214
-   */
215
-  function find_string($string, $start = -1, $end = -1) {
204
+    }
205
+
206
+    /**
207
+     * Binary search for string
208
+     *
209
+     * @access private
210
+     * @param string string
211
+     * @param int start (internally used in recursive function)
212
+     * @param int end (internally used in recursive function)
213
+     * @return int string number (offset in originals table)
214
+     */
215
+    function find_string($string, $start = -1, $end = -1) {
216 216
     if (($start == -1) or ($end == -1)) {
217
-      // find_string is called with only one parameter, set start end end
218
-      $start = 0;
219
-      $end = $this->total;
217
+        // find_string is called with only one parameter, set start end end
218
+        $start = 0;
219
+        $end = $this->total;
220 220
     }
221 221
     if (abs($start - $end) <= 1) {
222
-      // We're done, now we either found the string, or it doesn't exist
223
-      $txt = $this->get_original_string($start);
224
-      if ($string == $txt) {
225
-              return $start;
226
-      } else {
227
-              return -1;
228
-      }
222
+        // We're done, now we either found the string, or it doesn't exist
223
+        $txt = $this->get_original_string($start);
224
+        if ($string == $txt) {
225
+                return $start;
226
+        } else {
227
+                return -1;
228
+        }
229 229
     } else if ($start > $end) {
230
-      // start > end -> turn around and start over
231
-      return $this->find_string($string, $end, $start);
230
+        // start > end -> turn around and start over
231
+        return $this->find_string($string, $end, $start);
232 232
     } else {
233
-      // Divide table in two parts
234
-      $half = (int) (($start + $end) / 2);
235
-      $cmp = strcmp($string, $this->get_original_string($half));
236
-      if ($cmp == 0) {
237
-              // string is exactly in the middle => return it
233
+        // Divide table in two parts
234
+        $half = (int) (($start + $end) / 2);
235
+        $cmp = strcmp($string, $this->get_original_string($half));
236
+        if ($cmp == 0) {
237
+                // string is exactly in the middle => return it
238 238
         return $half;
239
-      } else if ($cmp < 0) {
240
-              // The string is in the upper half
239
+        } else if ($cmp < 0) {
240
+                // The string is in the upper half
241 241
         return $this->find_string($string, $start, $half);
242
-      } else {
243
-              // The string is in the lower half
242
+        } else {
243
+                // The string is in the lower half
244 244
         return $this->find_string($string, $half, $end);
245
-      }
246
-    }
247
-  }
248
-
249
-  /**
250
-   * Translates a string
251
-   *
252
-   * @access public
253
-   * @param string string to be translated
254
-   * @return string translated string (or original, if not found)
255
-   */
256
-  function translate($string) {
245
+        }
246
+    }
247
+    }
248
+
249
+    /**
250
+     * Translates a string
251
+     *
252
+     * @access public
253
+     * @param string string to be translated
254
+     * @return string translated string (or original, if not found)
255
+     */
256
+    function translate($string) {
257 257
     if ($this->short_circuit) {
258
-          return $string;
258
+            return $string;
259 259
     }
260 260
     $this->load_tables();
261 261
 
262 262
     if ($this->enable_cache) {
263
-      // Caching enabled, get translated string from cache
264
-      if (array_key_exists($string, $this->cache_translations)) {
265
-              return $this->cache_translations[$string];
266
-      } else {
267
-              return $string;
268
-      }
263
+        // Caching enabled, get translated string from cache
264
+        if (array_key_exists($string, $this->cache_translations)) {
265
+                return $this->cache_translations[$string];
266
+        } else {
267
+                return $string;
268
+        }
269 269
     } else {
270
-      // Caching not enabled, try to find string
271
-      $num = $this->find_string($string);
272
-      if ($num == -1) {
273
-              return $string;
274
-      } else {
275
-              return $this->get_translation_string($num);
276
-      }
277
-    }
278
-  }
279
-
280
-  /**
281
-   * Sanitize plural form expression for use in PHP eval call.
282
-   *
283
-   * @access private
284
-   * @return string sanitized plural form expression
285
-   */
286
-  function sanitize_plural_expression($expr) {
270
+        // Caching not enabled, try to find string
271
+        $num = $this->find_string($string);
272
+        if ($num == -1) {
273
+                return $string;
274
+        } else {
275
+                return $this->get_translation_string($num);
276
+        }
277
+    }
278
+    }
279
+
280
+    /**
281
+     * Sanitize plural form expression for use in PHP eval call.
282
+     *
283
+     * @access private
284
+     * @return string sanitized plural form expression
285
+     */
286
+    function sanitize_plural_expression($expr) {
287 287
     // Get rid of disallowed characters.
288 288
     $expr = preg_replace('@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@', '', $expr);
289 289
 
@@ -292,75 +292,75 @@  discard block
 block discarded – undo
292 292
     $res = '';
293 293
     $p = 0;
294 294
     for ($i = 0; $i < strlen($expr); $i++) {
295
-      $ch = $expr[$i];
296
-      switch ($ch) {
297
-      case '?':
295
+        $ch = $expr[$i];
296
+        switch ($ch) {
297
+        case '?':
298 298
         $res .= ' ? (';
299 299
         $p++;
300 300
         break;
301
-      case ':':
301
+        case ':':
302 302
         $res .= ') : (';
303 303
         break;
304
-      case ';':
304
+        case ';':
305 305
         $res .= str_repeat(')', $p).';';
306 306
         $p = 0;
307 307
         break;
308
-      default:
308
+        default:
309 309
         $res .= $ch;
310
-      }
310
+        }
311 311
     }
312 312
     return $res;
313
-  }
314
-
315
-  /**
316
-   * Parse full PO header and extract only plural forms line.
317
-   *
318
-   * @access private
319
-   * @return string verbatim plural form header field
320
-   */
321
-  function extract_plural_forms_header_from_po_header($header) {
313
+    }
314
+
315
+    /**
316
+     * Parse full PO header and extract only plural forms line.
317
+     *
318
+     * @access private
319
+     * @return string verbatim plural form header field
320
+     */
321
+    function extract_plural_forms_header_from_po_header($header) {
322 322
     if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs)) {
323
-          $expr = $regs[2];
323
+            $expr = $regs[2];
324 324
     } else {
325
-          $expr = "nplurals=2; plural=n == 1 ? 0 : 1;";
325
+            $expr = "nplurals=2; plural=n == 1 ? 0 : 1;";
326 326
     }
327 327
     return $expr;
328
-  }
329
-
330
-  /**
331
-   * Get possible plural forms from MO header
332
-   *
333
-   * @access private
334
-   * @return string plural form header
335
-   */
336
-  function get_plural_forms() {
328
+    }
329
+
330
+    /**
331
+     * Get possible plural forms from MO header
332
+     *
333
+     * @access private
334
+     * @return string plural form header
335
+     */
336
+    function get_plural_forms() {
337 337
     // lets assume message number 0 is header
338 338
     // this is true, right?
339 339
     $this->load_tables();
340 340
 
341 341
     // cache header field for plural forms
342 342
     if (!is_string($this->pluralheader)) {
343
-      if ($this->enable_cache) {
343
+        if ($this->enable_cache) {
344 344
         $header = $this->cache_translations[""];
345
-      } else {
345
+        } else {
346 346
         $header = $this->get_translation_string(0);
347
-      }
348
-      $expr = $this->extract_plural_forms_header_from_po_header($header);
349
-      $this->pluralheader = $this->sanitize_plural_expression($expr);
347
+        }
348
+        $expr = $this->extract_plural_forms_header_from_po_header($header);
349
+        $this->pluralheader = $this->sanitize_plural_expression($expr);
350 350
     }
351 351
     return $this->pluralheader;
352
-  }
353
-
354
-  /**
355
-   * Detects which plural form to take
356
-   *
357
-   * @access private
358
-   * @param n count
359
-   * @return int array index of the right plural form
360
-   */
361
-  function select_string($n) {
352
+    }
353
+
354
+    /**
355
+     * Detects which plural form to take
356
+     *
357
+     * @access private
358
+     * @param n count
359
+     * @return int array index of the right plural form
360
+     */
361
+    function select_string($n) {
362 362
     if (!is_int($n)) {
363
-      throw new InvalidArgumentException(
363
+        throw new InvalidArgumentException(
364 364
         "Select_string only accepts integers: ".$n);
365 365
     }
366 366
     $string = $this->get_plural_forms();
@@ -376,24 +376,24 @@  discard block
 block discarded – undo
376 376
         $plural = $total - 1;
377 377
     }
378 378
     return $plural;
379
-  }
380
-
381
-  /**
382
-   * Plural version of gettext
383
-   *
384
-   * @access public
385
-   * @param string single
386
-   * @param string plural
387
-   * @param string number
388
-   * @return translated plural form
389
-   */
390
-  function ngettext($single, $plural, $number) {
379
+    }
380
+
381
+    /**
382
+     * Plural version of gettext
383
+     *
384
+     * @access public
385
+     * @param string single
386
+     * @param string plural
387
+     * @param string number
388
+     * @return translated plural form
389
+     */
390
+    function ngettext($single, $plural, $number) {
391 391
     if ($this->short_circuit) {
392
-      if ($number != 1) {
393
-              return $plural;
394
-      } else {
395
-              return $single;
396
-      }
392
+        if ($number != 1) {
393
+                return $plural;
394
+        } else {
395
+                return $single;
396
+        }
397 397
     }
398 398
 
399 399
     // find out the appropriate form
@@ -404,45 +404,45 @@  discard block
 block discarded – undo
404 404
 
405 405
 
406 406
     if ($this->enable_cache) {
407
-      if (!array_key_exists($key, $this->cache_translations)) {
407
+        if (!array_key_exists($key, $this->cache_translations)) {
408 408
         return ($number != 1) ? $plural : $single;
409
-      } else {
409
+        } else {
410 410
         $result = $this->cache_translations[$key];
411 411
         $list = explode(chr(0), $result);
412 412
         return $list[$select];
413
-      }
413
+        }
414 414
     } else {
415
-      $num = $this->find_string($key);
416
-      if ($num == -1) {
415
+        $num = $this->find_string($key);
416
+        if ($num == -1) {
417 417
         return ($number != 1) ? $plural : $single;
418
-      } else {
418
+        } else {
419 419
         $result = $this->get_translation_string($num);
420 420
         $list = explode(chr(0), $result);
421 421
         return $list[$select];
422
-      }
422
+        }
423
+    }
423 424
     }
424
-  }
425 425
 
426
-  function pgettext($context, $msgid) {
426
+    function pgettext($context, $msgid) {
427 427
     $key = $context.chr(4).$msgid;
428 428
     $ret = $this->translate($key);
429 429
     if (strpos($ret, "\004") !== false) {
430
-      return $msgid;
430
+        return $msgid;
431 431
     } else {
432
-      return $ret;
432
+        return $ret;
433
+    }
433 434
     }
434
-  }
435 435
 
436
-  function npgettext($context, $singular, $plural, $number) {
436
+    function npgettext($context, $singular, $plural, $number) {
437 437
     $key = $context.chr(4).$singular;
438 438
     $ret = $this->ngettext($key, $plural, $number);
439 439
     if (strpos($ret, "\004") !== false) {
440
-      return $singular;
440
+        return $singular;
441 441
     } else {
442
-      return $ret;
442
+        return $ret;
443 443
     }
444 444
 
445
-  }
445
+    }
446 446
 }
447 447
 
448 448
 ?>
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -177,12 +177,12 @@  discard block
 block discarded – undo
177 177
   function get_original_string($num) {
178 178
     $length = $this->table_originals[$num * 2 + 1];
179 179
     $offset = $this->table_originals[$num * 2 + 2];
180
-    if (! $length) {
180
+    if (!$length) {
181 181
           return '';
182 182
     }
183 183
     $this->STREAM->seekto($offset);
184 184
     $data = $this->STREAM->read($length);
185
-    return (string)$data;
185
+    return (string) $data;
186 186
   }
187 187
 
188 188
   /**
@@ -195,12 +195,12 @@  discard block
 block discarded – undo
195 195
   function get_translation_string($num) {
196 196
     $length = $this->table_translations[$num * 2 + 1];
197 197
     $offset = $this->table_translations[$num * 2 + 2];
198
-    if (! $length) {
198
+    if (!$length) {
199 199
           return '';
200 200
     }
201 201
     $this->STREAM->seekto($offset);
202 202
     $data = $this->STREAM->read($length);
203
-    return (string)$data;
203
+    return (string) $data;
204 204
   }
205 205
 
206 206
   /**
Please login to merge, or discard this patch.
lib/gettext/gettext.inc 2 patches
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 // LC_MESSAGES is not available if php-gettext is not loaded
36 36
 // while the other constants are already available from session extension.
37 37
 if (!defined('LC_MESSAGES')) {
38
-  define('LC_MESSAGES', 5);
38
+    define('LC_MESSAGES', 5);
39 39
 }
40 40
 
41 41
 require('streams.php');
@@ -53,9 +53,9 @@  discard block
 block discarded – undo
53 53
 
54 54
 /* Class to hold a single domain included in $text_domains. */
55 55
 class domain {
56
-  var $l10n;
57
-  var $path;
58
-  var $codeset;
56
+    var $l10n;
57
+    var $path;
58
+    var $codeset;
59 59
 }
60 60
 
61 61
 // Utility functions
@@ -64,63 +64,63 @@  discard block
 block discarded – undo
64 64
  * Return a list of locales to try for any POSIX-style locale specification.
65 65
  */
66 66
 function get_list_of_locales($locale) {
67
-  /* Figure out all possible locale names and start with the most
67
+    /* Figure out all possible locale names and start with the most
68 68
    * specific ones.  I.e. for sr_CS.UTF-8@latin, look through all of
69 69
    * sr_CS.UTF-8@latin, sr_CS@latin, sr@latin, sr_CS.UTF-8, sr_CS, sr.
70 70
    */
71
-  $locale_names = array();
72
-  $lang = null;
73
-  $country = null;
74
-  $charset = null;
75
-  $modifier = null;
76
-  if ($locale) {
71
+    $locale_names = array();
72
+    $lang = null;
73
+    $country = null;
74
+    $charset = null;
75
+    $modifier = null;
76
+    if ($locale) {
77 77
     if (preg_match("/^(?P<lang>[a-z]{2,3})"              // language code
78
-                   ."(?:_(?P<country>[A-Z]{2}))?"           // country code
79
-                   ."(?:\.(?P<charset>[-A-Za-z0-9_]+))?"    // charset
80
-                   ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/", // @ modifier
81
-                   $locale, $matches)) {
82
-
83
-      if (isset($matches["lang"])) {
84
-          $lang = $matches["lang"];
85
-      }
86
-      if (isset($matches["country"])) {
87
-          $country = $matches["country"];
88
-      }
89
-      if (isset($matches["charset"])) {
90
-          $charset = $matches["charset"];
91
-      }
92
-      if (isset($matches["modifier"])) {
93
-          $modifier = $matches["modifier"];
94
-      }
95
-
96
-      if ($modifier) {
78
+                    ."(?:_(?P<country>[A-Z]{2}))?"           // country code
79
+                    ."(?:\.(?P<charset>[-A-Za-z0-9_]+))?"    // charset
80
+                    ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/", // @ modifier
81
+                    $locale, $matches)) {
82
+
83
+        if (isset($matches["lang"])) {
84
+            $lang = $matches["lang"];
85
+        }
86
+        if (isset($matches["country"])) {
87
+            $country = $matches["country"];
88
+        }
89
+        if (isset($matches["charset"])) {
90
+            $charset = $matches["charset"];
91
+        }
92
+        if (isset($matches["modifier"])) {
93
+            $modifier = $matches["modifier"];
94
+        }
95
+
96
+        if ($modifier) {
97 97
         if ($country) {
98
-          if ($charset) {
99
-                      array_push($locale_names, "${lang}_$country.$charset@$modifier");
100
-          }
101
-          array_push($locale_names, "${lang}_$country@$modifier");
98
+            if ($charset) {
99
+                        array_push($locale_names, "${lang}_$country.$charset@$modifier");
100
+            }
101
+            array_push($locale_names, "${lang}_$country@$modifier");
102 102
         } elseif ($charset) {
103 103
                     array_push($locale_names, "${lang}.$charset@$modifier");
104 104
         }
105 105
         array_push($locale_names, "$lang@$modifier");
106
-      }
107
-      if ($country) {
106
+        }
107
+        if ($country) {
108 108
         if ($charset) {
109
-                  array_push($locale_names, "${lang}_$country.$charset");
109
+                    array_push($locale_names, "${lang}_$country.$charset");
110 110
         }
111 111
         array_push($locale_names, "${lang}_$country");
112
-      } elseif ($charset) {
112
+        } elseif ($charset) {
113 113
                 array_push($locale_names, "${lang}.$charset");
114
-      }
115
-      array_push($locale_names, $lang);
114
+        }
115
+        array_push($locale_names, $lang);
116 116
     }
117 117
 
118 118
     // If the locale name doesn't match POSIX style, just include it as-is.
119 119
     if (!in_array($locale, $locale_names)) {
120
-          array_push($locale_names, $locale);
120
+            array_push($locale_names, $locale);
121 121
     }
122
-  }
123
-  return $locale_names;
122
+    }
123
+    return $locale_names;
124 124
 }
125 125
 
126 126
 /**
@@ -141,19 +141,19 @@  discard block
 block discarded – undo
141 141
         $locale_names = get_list_of_locales($locale);
142 142
         $input = null;
143 143
         foreach ($locale_names as $locale) {
144
-          $full_path = $bound_path.$locale."/".$subpath;
145
-          if (file_exists($full_path)) {
144
+            $full_path = $bound_path.$locale."/".$subpath;
145
+            if (file_exists($full_path)) {
146 146
             $input = new FileReader($full_path);
147 147
             break;
148
-          }
148
+            }
149 149
         }
150 150
 
151 151
         if (!array_key_exists($domain, $text_domains)) {
152
-          // Initialize an empty domain object.
153
-          $text_domains[$domain] = new domain();
152
+            // Initialize an empty domain object.
153
+            $text_domains[$domain] = new domain();
154 154
         }
155 155
         $text_domains[$domain]->l10n = new gettext_reader($input,
156
-                                                          $enable_cache);
156
+                                                            $enable_cache);
157 157
     }
158 158
     return $text_domains[$domain]->l10n;
159 159
 }
@@ -190,14 +190,14 @@  discard block
 block discarded – undo
190 190
  * Convert the given string to the encoding set by bind_textdomain_codeset.
191 191
  */
192 192
 function _encode($text) {
193
-  $target_encoding = _get_codeset();
194
-  if (function_exists("mb_detect_encoding")) {
193
+    $target_encoding = _get_codeset();
194
+    if (function_exists("mb_detect_encoding")) {
195 195
     $source_encoding = mb_detect_encoding($text);
196 196
     if ($source_encoding != $target_encoding) {
197
-          $text = mb_convert_encoding($text, $target_encoding, $source_encoding);
197
+            $text = mb_convert_encoding($text, $target_encoding, $source_encoding);
198
+    }
198 199
     }
199
-  }
200
-  return $text;
200
+    return $text;
201 201
 }
202 202
 
203 203
 
@@ -207,13 +207,13 @@  discard block
 block discarded – undo
207 207
  * Returns passed in $locale, or environment variable $LANG if $locale == ''.
208 208
  */
209 209
 function _get_default_locale($locale) {
210
-  if ($locale == '') {
211
-      // emulate variable support
210
+    if ($locale == '') {
211
+        // emulate variable support
212 212
     return getenv('LANG');
213
-  } else {
214
-      return $locale;
215
-  }
216
-  }
213
+    } else {
214
+        return $locale;
215
+    }
216
+    }
217 217
 
218 218
 /**
219 219
  * Sets a requested locale, if needed emulates it.
@@ -230,20 +230,20 @@  discard block
 block discarded – undo
230 230
         }
231 231
     } else {
232 232
         if (function_exists('setlocale')) {
233
-          $ret = setlocale($category, $locale);
234
-          if (($locale == '' and !$ret) or // failed setting it by env
233
+            $ret = setlocale($category, $locale);
234
+            if (($locale == '' and !$ret) or // failed setting it by env
235 235
               ($locale != '' and $ret != $locale)) { // failed setting it
236 236
             // Failed setting it according to environment.
237 237
             $CURRENTLOCALE = _get_default_locale($locale);
238 238
             $EMULATEGETTEXT = 1;
239
-          } else {
239
+            } else {
240 240
             $CURRENTLOCALE = $ret;
241 241
             $EMULATEGETTEXT = 0;
242
-          }
242
+            }
243 243
         } else {
244
-          // No function setlocale(), emulate it all.
245
-          $CURRENTLOCALE = _get_default_locale($locale);
246
-          $EMULATEGETTEXT = 1;
244
+            // No function setlocale(), emulate it all.
245
+            $CURRENTLOCALE = _get_default_locale($locale);
246
+            $EMULATEGETTEXT = 1;
247 247
         }
248 248
         // Allow locale to be changed on the go for one translation domain.
249 249
         global $text_domains, $default_domain;
@@ -261,15 +261,15 @@  discard block
 block discarded – undo
261 261
     global $text_domains;
262 262
     // ensure $path ends with a slash ('/' should work for both, but lets still play nice)
263 263
     if (substr(php_uname(), 0, 7) == "Windows") {
264
-      if ($path[strlen($path) - 1] != '\\' and $path[strlen($path) - 1] != '/')
264
+        if ($path[strlen($path) - 1] != '\\' and $path[strlen($path) - 1] != '/')
265 265
         $path .= '\\';
266 266
     } else {
267
-      if ($path[strlen($path) - 1] != '/')
267
+        if ($path[strlen($path) - 1] != '/')
268 268
         $path .= '/';
269 269
     }
270 270
     if (!array_key_exists($domain, $text_domains)) {
271
-      // Initialize an empty domain object.
272
-      $text_domains[$domain] = new domain();
271
+        // Initialize an empty domain object.
272
+        $text_domains[$domain] = new domain();
273 273
     }
274 274
     $text_domains[$domain]->path = $path;
275 275
 }
@@ -468,35 +468,35 @@  discard block
 block discarded – undo
468 468
     }
469 469
 function T_dcngettext($domain, $singular, $plural, $number, $category) {
470 470
     if (_check_locale_and_function()) {
471
-          return dcngettext($domain, $singular, $plural, $number, $category);
471
+            return dcngettext($domain, $singular, $plural, $number, $category);
472 472
     } else {
473 473
         return _dcngettext($domain, $singular, $plural, $number, $category);
474 474
     }
475 475
     }
476 476
 
477 477
 function T_pgettext($context, $msgid) {
478
-  if (_check_locale_and_function('pgettext')) {
478
+    if (_check_locale_and_function('pgettext')) {
479 479
         return pgettext($context, $msgid);
480
-  } else {
480
+    } else {
481 481
         return _pgettext($context, $msgid);
482
-  }
483
-  }
482
+    }
483
+    }
484 484
 
485 485
 function T_dpgettext($domain, $context, $msgid) {
486
-  if (_check_locale_and_function('dpgettext')) {
486
+    if (_check_locale_and_function('dpgettext')) {
487 487
         return dpgettext($domain, $context, $msgid);
488
-  } else {
488
+    } else {
489 489
         return _dpgettext($domain, $context, $msgid);
490
-  }
491
-  }
490
+    }
491
+    }
492 492
 
493 493
 function T_dcpgettext($domain, $context, $msgid, $category) {
494
-  if (_check_locale_and_function('dcpgettext')) {
494
+    if (_check_locale_and_function('dcpgettext')) {
495 495
         return dcpgettext($domain, $context, $msgid, $category);
496
-  } else {
496
+    } else {
497 497
         return _dcpgettext($domain, $context, $msgid, $category);
498
-  }
499
-  }
498
+    }
499
+    }
500 500
 
501 501
 function T_npgettext($context, $singular, $plural, $number) {
502 502
     if (_check_locale_and_function('npgettext')) {
@@ -507,18 +507,18 @@  discard block
 block discarded – undo
507 507
     }
508 508
 
509 509
 function T_dnpgettext($domain, $context, $singular, $plural, $number) {
510
-  if (_check_locale_and_function('dnpgettext')) {
510
+    if (_check_locale_and_function('dnpgettext')) {
511 511
         return dnpgettext($domain, $context, $singular, $plural, $number);
512
-  } else {
512
+    } else {
513 513
         return _dnpgettext($domain, $context, $singular, $plural, $number);
514
-  }
515
-  }
514
+    }
515
+    }
516 516
 
517 517
 function T_dcnpgettext($domain, $context, $singular, $plural,
518
-                       $number, $category) {
518
+                        $number, $category) {
519 519
     if (_check_locale_and_function('dcnpgettext')) {
520 520
             return dcnpgettext($domain, $context, $singular,
521
-                           $plural, $number, $category);
521
+                            $plural, $number, $category);
522 522
     } else {
523 523
             return _dcnpgettext($domain, $context, $singular,
524 524
                             $plural, $number, $category);
@@ -576,9 +576,9 @@  discard block
 block discarded – undo
576 576
         return _dcpgettext($domain, $context, $msgid, $category);
577 577
     }
578 578
     function dcnpgettext($domain, $context, $singular, $plural,
579
-                         $number, $category) {
580
-      return _dcnpgettext($domain, $context, $singular, $plural,
581
-                          $number, $category);
579
+                            $number, $category) {
580
+        return _dcnpgettext($domain, $context, $singular, $plural,
581
+                            $number, $category);
582 582
     }
583 583
 }
584 584
 
Please login to merge, or discard this patch.
Braces   +9 added lines, -5 removed lines patch added patch discarded remove patch
@@ -182,7 +182,9 @@  discard block
 block discarded – undo
182 182
  */
183 183
 function _get_codeset($domain = null) {
184 184
     global $text_domains, $default_domain, $LC_CATEGORIES;
185
-    if (!isset($domain)) $domain = $default_domain;
185
+    if (!isset($domain)) {
186
+        $domain = $default_domain;
187
+    }
186 188
     return (isset($text_domains[$domain]->codeset)) ? $text_domains[$domain]->codeset : ini_get('mbstring.internal_encoding');
187 189
 }
188 190
 
@@ -261,11 +263,13 @@  discard block
 block discarded – undo
261 263
     global $text_domains;
262 264
     // ensure $path ends with a slash ('/' should work for both, but lets still play nice)
263 265
     if (substr(php_uname(), 0, 7) == "Windows") {
264
-      if ($path[strlen($path) - 1] != '\\' and $path[strlen($path) - 1] != '/')
265
-        $path .= '\\';
266
+      if ($path[strlen($path) - 1] != '\\' and $path[strlen($path) - 1] != '/') {
267
+              $path .= '\\';
268
+      }
266 269
     } else {
267
-      if ($path[strlen($path) - 1] != '/')
268
-        $path .= '/';
270
+      if ($path[strlen($path) - 1] != '/') {
271
+              $path .= '/';
272
+      }
269 273
     }
270 274
     if (!array_key_exists($domain, $text_domains)) {
271 275
       // Initialize an empty domain object.
Please login to merge, or discard this patch.
lib/phpqrcode/qrimage.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -35,11 +35,11 @@
 block discarded – undo
35 35
                 Header("Content-type: image/png");
36 36
                 ImagePng($image);
37 37
             } else {
38
-                if($saveandprint===true){
38
+                if ($saveandprint === true) {
39 39
                     ImagePng($image, $filename);
40 40
                     header("Content-type: image/png");
41 41
                     ImagePng($image);
42
-                } else{
42
+                } else {
43 43
                     ImagePng($image, $filename);
44 44
                 }
45 45
             }
Please login to merge, or discard this patch.
lib/phpqrcode/qrtools.php 2 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -79,9 +79,9 @@  discard block
 block discarded – undo
79 79
         //----------------------------------------------------------------------
80 80
         public static function buildCache()
81 81
         {
82
-			QRtools::markTime('before_build_cache');
82
+            QRtools::markTime('before_build_cache');
83 83
 			
84
-			$mask = new QRmask();
84
+            $mask = new QRmask();
85 85
             for ($a = 1; $a <= QRSPEC_VERSION_MAX; $a++) {
86 86
                 $frame = QRspec::newFrame($a);
87 87
                 if (QR_IMAGE) {
@@ -89,13 +89,13 @@  discard block
 block discarded – undo
89 89
                     QRimage::png(self::binarize($frame), $fileName, 1, 0);
90 90
                 }
91 91
 				
92
-				$width = count($frame);
93
-				$bitMask = array_fill(0, $width, array_fill(0, $width, 0));
94
-				for ($maskNo = 0; $maskNo < 8; $maskNo++)
95
-					$mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
92
+                $width = count($frame);
93
+                $bitMask = array_fill(0, $width, array_fill(0, $width, 0));
94
+                for ($maskNo = 0; $maskNo < 8; $maskNo++)
95
+                    $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
96 96
             }
97 97
 			
98
-			QRtools::markTime('after_build_cache');
98
+            QRtools::markTime('after_build_cache');
99 99
         }
100 100
 
101 101
         //----------------------------------------------------------------------
Please login to merge, or discard this patch.
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -62,8 +62,9 @@  discard block
 block discarded – undo
62 62
                 
63 63
             foreach ($qrTab as $line) {
64 64
                 $arrAdd = array();
65
-                foreach (str_split($line) as $char)
66
-                    $arrAdd[] = ($char == '1') ? 1 : 0;
65
+                foreach (str_split($line) as $char) {
66
+                                    $arrAdd[] = ($char == '1') ? 1 : 0;
67
+                }
67 68
                 $barcode_array['bcode'][] = $arrAdd;
68 69
             }
69 70
                     
@@ -91,8 +92,9 @@  discard block
 block discarded – undo
91 92
 				
92 93
 				$width = count($frame);
93 94
 				$bitMask = array_fill(0, $width, array_fill(0, $width, 0));
94
-				for ($maskNo = 0; $maskNo < 8; $maskNo++)
95
-					$mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
95
+				for ($maskNo = 0; $maskNo < 8; $maskNo++) {
96
+									$mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
97
+				}
96 98
             }
97 99
 			
98 100
 			QRtools::markTime('after_build_cache');
Please login to merge, or discard this patch.