Passed
Branch master (de5173)
by Cody
11:03
created
lib/gettext/gettext.php 3 patches
Indentation   +241 added lines, -241 removed lines patch added patch discarded remove patch
@@ -61,19 +61,19 @@  discard block
 block discarded – undo
61 61
    * @return Integer from the Stream
62 62
    */
63 63
   function readint() {
64
-      if ($this->BYTEORDER == 0) {
65
-        // low endian
66
-        $input=unpack('V', $this->STREAM->read(4));
67
-        return array_shift($input);
68
-      } else {
69
-        // big endian
70
-        $input=unpack('N', $this->STREAM->read(4));
71
-        return array_shift($input);
72
-      }
73
-    }
64
+	  if ($this->BYTEORDER == 0) {
65
+		// low endian
66
+		$input=unpack('V', $this->STREAM->read(4));
67
+		return array_shift($input);
68
+	  } else {
69
+		// big endian
70
+		$input=unpack('N', $this->STREAM->read(4));
71
+		return array_shift($input);
72
+	  }
73
+	}
74 74
 
75 75
   function read($bytes) {
76
-    return $this->STREAM->read($bytes);
76
+	return $this->STREAM->read($bytes);
77 77
   }
78 78
 
79 79
   /**
@@ -83,13 +83,13 @@  discard block
 block discarded – undo
83 83
    * @return Array of Integers
84 84
    */
85 85
   function readintarray($count) {
86
-    if ($this->BYTEORDER == 0) {
87
-        // low endian
88
-        return unpack('V'.$count, $this->STREAM->read(4 * $count));
89
-      } else {
90
-        // big endian
91
-        return unpack('N'.$count, $this->STREAM->read(4 * $count));
92
-      }
86
+	if ($this->BYTEORDER == 0) {
87
+		// low endian
88
+		return unpack('V'.$count, $this->STREAM->read(4 * $count));
89
+	  } else {
90
+		// big endian
91
+		return unpack('N'.$count, $this->STREAM->read(4 * $count));
92
+	  }
93 93
   }
94 94
 
95 95
   /**
@@ -99,35 +99,35 @@  discard block
 block discarded – undo
99 99
    * @param boolean enable_cache Enable or disable caching of strings (default on)
100 100
    */
101 101
   function __construct($Reader, $enable_cache = true) {
102
-    // If there isn't a StreamReader, turn on short circuit mode.
103
-    if (! $Reader || isset($Reader->error) ) {
104
-      $this->short_circuit = true;
105
-      return;
106
-    }
107
-
108
-    // Caching can be turned off
109
-    $this->enable_cache = $enable_cache;
110
-
111
-    $MAGIC1 = "\x95\x04\x12\xde";
112
-    $MAGIC2 = "\xde\x12\x04\x95";
113
-
114
-    $this->STREAM = $Reader;
115
-    $magic = $this->read(4);
116
-    if ($magic == $MAGIC1) {
117
-      $this->BYTEORDER = 1;
118
-    } elseif ($magic == $MAGIC2) {
119
-      $this->BYTEORDER = 0;
120
-    } else {
121
-      $this->error = 1; // not MO file
122
-      return false;
123
-    }
124
-
125
-    // FIXME: Do we care about revision? We should.
126
-    $revision = $this->readint();
127
-
128
-    $this->total = $this->readint();
129
-    $this->originals = $this->readint();
130
-    $this->translations = $this->readint();
102
+	// If there isn't a StreamReader, turn on short circuit mode.
103
+	if (! $Reader || isset($Reader->error) ) {
104
+	  $this->short_circuit = true;
105
+	  return;
106
+	}
107
+
108
+	// Caching can be turned off
109
+	$this->enable_cache = $enable_cache;
110
+
111
+	$MAGIC1 = "\x95\x04\x12\xde";
112
+	$MAGIC2 = "\xde\x12\x04\x95";
113
+
114
+	$this->STREAM = $Reader;
115
+	$magic = $this->read(4);
116
+	if ($magic == $MAGIC1) {
117
+	  $this->BYTEORDER = 1;
118
+	} elseif ($magic == $MAGIC2) {
119
+	  $this->BYTEORDER = 0;
120
+	} else {
121
+	  $this->error = 1; // not MO file
122
+	  return false;
123
+	}
124
+
125
+	// FIXME: Do we care about revision? We should.
126
+	$revision = $this->readint();
127
+
128
+	$this->total = $this->readint();
129
+	$this->originals = $this->readint();
130
+	$this->translations = $this->readint();
131 131
   }
132 132
 
133 133
   /**
@@ -138,32 +138,32 @@  discard block
 block discarded – undo
138 138
    * @access private
139 139
    */
140 140
   function load_tables() {
141
-    if (is_array($this->cache_translations) &&
142
-      is_array($this->table_originals) &&
143
-      is_array($this->table_translations))
144
-      return;
145
-
146
-    /* get original and translations tables */
147
-    if (!is_array($this->table_originals)) {
148
-      $this->STREAM->seekto($this->originals);
149
-      $this->table_originals = $this->readintarray($this->total * 2);
150
-    }
151
-    if (!is_array($this->table_translations)) {
152
-      $this->STREAM->seekto($this->translations);
153
-      $this->table_translations = $this->readintarray($this->total * 2);
154
-    }
155
-
156
-    if ($this->enable_cache) {
157
-      $this->cache_translations = array ();
158
-      /* read all strings in the cache */
159
-      for ($i = 0; $i < $this->total; $i++) {
160
-        $this->STREAM->seekto($this->table_originals[$i * 2 + 2]);
161
-        $original = $this->STREAM->read($this->table_originals[$i * 2 + 1]);
162
-        $this->STREAM->seekto($this->table_translations[$i * 2 + 2]);
163
-        $translation = $this->STREAM->read($this->table_translations[$i * 2 + 1]);
164
-        $this->cache_translations[$original] = $translation;
165
-      }
166
-    }
141
+	if (is_array($this->cache_translations) &&
142
+	  is_array($this->table_originals) &&
143
+	  is_array($this->table_translations))
144
+	  return;
145
+
146
+	/* get original and translations tables */
147
+	if (!is_array($this->table_originals)) {
148
+	  $this->STREAM->seekto($this->originals);
149
+	  $this->table_originals = $this->readintarray($this->total * 2);
150
+	}
151
+	if (!is_array($this->table_translations)) {
152
+	  $this->STREAM->seekto($this->translations);
153
+	  $this->table_translations = $this->readintarray($this->total * 2);
154
+	}
155
+
156
+	if ($this->enable_cache) {
157
+	  $this->cache_translations = array ();
158
+	  /* read all strings in the cache */
159
+	  for ($i = 0; $i < $this->total; $i++) {
160
+		$this->STREAM->seekto($this->table_originals[$i * 2 + 2]);
161
+		$original = $this->STREAM->read($this->table_originals[$i * 2 + 1]);
162
+		$this->STREAM->seekto($this->table_translations[$i * 2 + 2]);
163
+		$translation = $this->STREAM->read($this->table_translations[$i * 2 + 1]);
164
+		$this->cache_translations[$original] = $translation;
165
+	  }
166
+	}
167 167
   }
168 168
 
169 169
   /**
@@ -174,13 +174,13 @@  discard block
 block discarded – undo
174 174
    * @return string Requested string if found, otherwise ''
175 175
    */
176 176
   function get_original_string($num) {
177
-    $length = $this->table_originals[$num * 2 + 1];
178
-    $offset = $this->table_originals[$num * 2 + 2];
179
-    if (! $length)
180
-      return '';
181
-    $this->STREAM->seekto($offset);
182
-    $data = $this->STREAM->read($length);
183
-    return (string)$data;
177
+	$length = $this->table_originals[$num * 2 + 1];
178
+	$offset = $this->table_originals[$num * 2 + 2];
179
+	if (! $length)
180
+	  return '';
181
+	$this->STREAM->seekto($offset);
182
+	$data = $this->STREAM->read($length);
183
+	return (string)$data;
184 184
   }
185 185
 
186 186
   /**
@@ -191,13 +191,13 @@  discard block
 block discarded – undo
191 191
    * @return string Requested string if found, otherwise ''
192 192
    */
193 193
   function get_translation_string($num) {
194
-    $length = $this->table_translations[$num * 2 + 1];
195
-    $offset = $this->table_translations[$num * 2 + 2];
196
-    if (! $length)
197
-      return '';
198
-    $this->STREAM->seekto($offset);
199
-    $data = $this->STREAM->read($length);
200
-    return (string)$data;
194
+	$length = $this->table_translations[$num * 2 + 1];
195
+	$offset = $this->table_translations[$num * 2 + 2];
196
+	if (! $length)
197
+	  return '';
198
+	$this->STREAM->seekto($offset);
199
+	$data = $this->STREAM->read($length);
200
+	return (string)$data;
201 201
   }
202 202
 
203 203
   /**
@@ -210,35 +210,35 @@  discard block
 block discarded – undo
210 210
    * @return int string number (offset in originals table)
211 211
    */
212 212
   function find_string($string, $start = -1, $end = -1) {
213
-    if (($start == -1) or ($end == -1)) {
214
-      // find_string is called with only one parameter, set start end end
215
-      $start = 0;
216
-      $end = $this->total;
217
-    }
218
-    if (abs($start - $end) <= 1) {
219
-      // We're done, now we either found the string, or it doesn't exist
220
-      $txt = $this->get_original_string($start);
221
-      if ($string == $txt)
222
-        return $start;
223
-      else
224
-        return -1;
225
-    } else if ($start > $end) {
226
-      // start > end -> turn around and start over
227
-      return $this->find_string($string, $end, $start);
228
-    } else {
229
-      // Divide table in two parts
230
-      $half = (int)(($start + $end) / 2);
231
-      $cmp = strcmp($string, $this->get_original_string($half));
232
-      if ($cmp == 0)
233
-        // string is exactly in the middle => return it
234
-        return $half;
235
-      else if ($cmp < 0)
236
-        // The string is in the upper half
237
-        return $this->find_string($string, $start, $half);
238
-      else
239
-        // The string is in the lower half
240
-        return $this->find_string($string, $half, $end);
241
-    }
213
+	if (($start == -1) or ($end == -1)) {
214
+	  // find_string is called with only one parameter, set start end end
215
+	  $start = 0;
216
+	  $end = $this->total;
217
+	}
218
+	if (abs($start - $end) <= 1) {
219
+	  // We're done, now we either found the string, or it doesn't exist
220
+	  $txt = $this->get_original_string($start);
221
+	  if ($string == $txt)
222
+		return $start;
223
+	  else
224
+		return -1;
225
+	} else if ($start > $end) {
226
+	  // start > end -> turn around and start over
227
+	  return $this->find_string($string, $end, $start);
228
+	} else {
229
+	  // Divide table in two parts
230
+	  $half = (int)(($start + $end) / 2);
231
+	  $cmp = strcmp($string, $this->get_original_string($half));
232
+	  if ($cmp == 0)
233
+		// string is exactly in the middle => return it
234
+		return $half;
235
+	  else if ($cmp < 0)
236
+		// The string is in the upper half
237
+		return $this->find_string($string, $start, $half);
238
+	  else
239
+		// The string is in the lower half
240
+		return $this->find_string($string, $half, $end);
241
+	}
242 242
   }
243 243
 
244 244
   /**
@@ -249,24 +249,24 @@  discard block
 block discarded – undo
249 249
    * @return string translated string (or original, if not found)
250 250
    */
251 251
   function translate($string) {
252
-    if ($this->short_circuit)
253
-      return $string;
254
-    $this->load_tables();
255
-
256
-    if ($this->enable_cache) {
257
-      // Caching enabled, get translated string from cache
258
-      if (array_key_exists($string, $this->cache_translations))
259
-        return $this->cache_translations[$string];
260
-      else
261
-        return $string;
262
-    } else {
263
-      // Caching not enabled, try to find string
264
-      $num = $this->find_string($string);
265
-      if ($num == -1)
266
-        return $string;
267
-      else
268
-        return $this->get_translation_string($num);
269
-    }
252
+	if ($this->short_circuit)
253
+	  return $string;
254
+	$this->load_tables();
255
+
256
+	if ($this->enable_cache) {
257
+	  // Caching enabled, get translated string from cache
258
+	  if (array_key_exists($string, $this->cache_translations))
259
+		return $this->cache_translations[$string];
260
+	  else
261
+		return $string;
262
+	} else {
263
+	  // Caching not enabled, try to find string
264
+	  $num = $this->find_string($string);
265
+	  if ($num == -1)
266
+		return $string;
267
+	  else
268
+		return $this->get_translation_string($num);
269
+	}
270 270
   }
271 271
 
272 272
   /**
@@ -276,32 +276,32 @@  discard block
 block discarded – undo
276 276
    * @return string sanitized plural form expression
277 277
    */
278 278
   function sanitize_plural_expression($expr) {
279
-    // Get rid of disallowed characters.
280
-    $expr = preg_replace('@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@', '', $expr);
281
-
282
-    // Add parenthesis for tertiary '?' operator.
283
-    $expr .= ';';
284
-    $res = '';
285
-    $p = 0;
286
-    for ($i = 0; $i < strlen($expr); $i++) {
287
-      $ch = $expr[$i];
288
-      switch ($ch) {
289
-      case '?':
290
-        $res .= ' ? (';
291
-        $p++;
292
-        break;
293
-      case ':':
294
-        $res .= ') : (';
295
-        break;
296
-      case ';':
297
-        $res .= str_repeat( ')', $p) . ';';
298
-        $p = 0;
299
-        break;
300
-      default:
301
-        $res .= $ch;
302
-      }
303
-    }
304
-    return $res;
279
+	// Get rid of disallowed characters.
280
+	$expr = preg_replace('@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@', '', $expr);
281
+
282
+	// Add parenthesis for tertiary '?' operator.
283
+	$expr .= ';';
284
+	$res = '';
285
+	$p = 0;
286
+	for ($i = 0; $i < strlen($expr); $i++) {
287
+	  $ch = $expr[$i];
288
+	  switch ($ch) {
289
+	  case '?':
290
+		$res .= ' ? (';
291
+		$p++;
292
+		break;
293
+	  case ':':
294
+		$res .= ') : (';
295
+		break;
296
+	  case ';':
297
+		$res .= str_repeat( ')', $p) . ';';
298
+		$p = 0;
299
+		break;
300
+	  default:
301
+		$res .= $ch;
302
+	  }
303
+	}
304
+	return $res;
305 305
   }
306 306
 
307 307
   /**
@@ -311,11 +311,11 @@  discard block
 block discarded – undo
311 311
    * @return string verbatim plural form header field
312 312
    */
313 313
   function extract_plural_forms_header_from_po_header($header) {
314
-    if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs))
315
-      $expr = $regs[2];
316
-    else
317
-      $expr = "nplurals=2; plural=n == 1 ? 0 : 1;";
318
-    return $expr;
314
+	if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs))
315
+	  $expr = $regs[2];
316
+	else
317
+	  $expr = "nplurals=2; plural=n == 1 ? 0 : 1;";
318
+	return $expr;
319 319
   }
320 320
 
321 321
   /**
@@ -325,21 +325,21 @@  discard block
 block discarded – undo
325 325
    * @return string plural form header
326 326
    */
327 327
   function get_plural_forms() {
328
-    // lets assume message number 0 is header
329
-    // this is true, right?
330
-    $this->load_tables();
331
-
332
-    // cache header field for plural forms
333
-    if (! is_string($this->pluralheader)) {
334
-      if ($this->enable_cache) {
335
-        $header = $this->cache_translations[""];
336
-      } else {
337
-        $header = $this->get_translation_string(0);
338
-      }
339
-      $expr = $this->extract_plural_forms_header_from_po_header($header);
340
-      $this->pluralheader = $this->sanitize_plural_expression($expr);
341
-    }
342
-    return $this->pluralheader;
328
+	// lets assume message number 0 is header
329
+	// this is true, right?
330
+	$this->load_tables();
331
+
332
+	// cache header field for plural forms
333
+	if (! is_string($this->pluralheader)) {
334
+	  if ($this->enable_cache) {
335
+		$header = $this->cache_translations[""];
336
+	  } else {
337
+		$header = $this->get_translation_string(0);
338
+	  }
339
+	  $expr = $this->extract_plural_forms_header_from_po_header($header);
340
+	  $this->pluralheader = $this->sanitize_plural_expression($expr);
341
+	}
342
+	return $this->pluralheader;
343 343
   }
344 344
 
345 345
   /**
@@ -350,21 +350,21 @@  discard block
 block discarded – undo
350 350
    * @return int array index of the right plural form
351 351
    */
352 352
   function select_string($n) {
353
-    if (!is_int($n)) {
354
-      throw new InvalidArgumentException(
355
-        "Select_string only accepts integers: " . $n);
356
-    }
357
-    $string = $this->get_plural_forms();
358
-    $string = str_replace('nplurals',"\$total",$string);
359
-    $string = str_replace("n",$n,$string);
360
-    $string = str_replace('plural',"\$plural",$string);
361
-
362
-    $total = 0;
363
-    $plural = 0;
364
-
365
-    eval("$string");
366
-    if ($plural >= $total) $plural = $total - 1;
367
-    return $plural;
353
+	if (!is_int($n)) {
354
+	  throw new InvalidArgumentException(
355
+		"Select_string only accepts integers: " . $n);
356
+	}
357
+	$string = $this->get_plural_forms();
358
+	$string = str_replace('nplurals',"\$total",$string);
359
+	$string = str_replace("n",$n,$string);
360
+	$string = str_replace('plural',"\$plural",$string);
361
+
362
+	$total = 0;
363
+	$plural = 0;
364
+
365
+	eval("$string");
366
+	if ($plural >= $total) $plural = $total - 1;
367
+	return $plural;
368 368
   }
369 369
 
370 370
   /**
@@ -377,58 +377,58 @@  discard block
 block discarded – undo
377 377
    * @return translated plural form
378 378
    */
379 379
   function ngettext($single, $plural, $number) {
380
-    if ($this->short_circuit) {
381
-      if ($number != 1)
382
-        return $plural;
383
-      else
384
-        return $single;
385
-    }
386
-
387
-    // find out the appropriate form
388
-    $select = $this->select_string($number);
389
-
390
-    // this should contains all strings separated by NULLs
391
-    $key = $single . chr(0) . $plural;
392
-
393
-
394
-    if ($this->enable_cache) {
395
-      if (! array_key_exists($key, $this->cache_translations)) {
396
-        return ($number != 1) ? $plural : $single;
397
-      } else {
398
-        $result = $this->cache_translations[$key];
399
-        $list = explode(chr(0), $result);
400
-        return $list[$select];
401
-      }
402
-    } else {
403
-      $num = $this->find_string($key);
404
-      if ($num == -1) {
405
-        return ($number != 1) ? $plural : $single;
406
-      } else {
407
-        $result = $this->get_translation_string($num);
408
-        $list = explode(chr(0), $result);
409
-        return $list[$select];
410
-      }
411
-    }
380
+	if ($this->short_circuit) {
381
+	  if ($number != 1)
382
+		return $plural;
383
+	  else
384
+		return $single;
385
+	}
386
+
387
+	// find out the appropriate form
388
+	$select = $this->select_string($number);
389
+
390
+	// this should contains all strings separated by NULLs
391
+	$key = $single . chr(0) . $plural;
392
+
393
+
394
+	if ($this->enable_cache) {
395
+	  if (! array_key_exists($key, $this->cache_translations)) {
396
+		return ($number != 1) ? $plural : $single;
397
+	  } else {
398
+		$result = $this->cache_translations[$key];
399
+		$list = explode(chr(0), $result);
400
+		return $list[$select];
401
+	  }
402
+	} else {
403
+	  $num = $this->find_string($key);
404
+	  if ($num == -1) {
405
+		return ($number != 1) ? $plural : $single;
406
+	  } else {
407
+		$result = $this->get_translation_string($num);
408
+		$list = explode(chr(0), $result);
409
+		return $list[$select];
410
+	  }
411
+	}
412 412
   }
413 413
 
414 414
   function pgettext($context, $msgid) {
415
-    $key = $context . chr(4) . $msgid;
416
-    $ret = $this->translate($key);
417
-    if (strpos($ret, "\004") !== FALSE) {
418
-      return $msgid;
419
-    } else {
420
-      return $ret;
421
-    }
415
+	$key = $context . chr(4) . $msgid;
416
+	$ret = $this->translate($key);
417
+	if (strpos($ret, "\004") !== FALSE) {
418
+	  return $msgid;
419
+	} else {
420
+	  return $ret;
421
+	}
422 422
   }
423 423
 
424 424
   function npgettext($context, $singular, $plural, $number) {
425
-    $key = $context . chr(4) . $singular;
426
-    $ret = $this->ngettext($key, $plural, $number);
427
-    if (strpos($ret, "\004") !== FALSE) {
428
-      return $singular;
429
-    } else {
430
-      return $ret;
431
-    }
425
+	$key = $context . chr(4) . $singular;
426
+	$ret = $this->ngettext($key, $plural, $number);
427
+	if (strpos($ret, "\004") !== FALSE) {
428
+	  return $singular;
429
+	} else {
430
+	  return $ret;
431
+	}
432 432
 
433 433
   }
434 434
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -38,17 +38,17 @@  discard block
 block discarded – undo
38 38
    var $error = 0; // public variable that holds error code (0 if no error)
39 39
 
40 40
    //private:
41
-  var $BYTEORDER = 0;        // 0: low endian, 1: big endian
41
+  var $BYTEORDER = 0; // 0: low endian, 1: big endian
42 42
   var $STREAM = NULL;
43 43
   var $short_circuit = false;
44 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
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 52
 
53 53
 
54 54
   /* Methods */
@@ -63,11 +63,11 @@  discard block
 block discarded – undo
63 63
   function readint() {
64 64
       if ($this->BYTEORDER == 0) {
65 65
         // low endian
66
-        $input=unpack('V', $this->STREAM->read(4));
66
+        $input = unpack('V', $this->STREAM->read(4));
67 67
         return array_shift($input);
68 68
       } else {
69 69
         // big endian
70
-        $input=unpack('N', $this->STREAM->read(4));
70
+        $input = unpack('N', $this->STREAM->read(4));
71 71
         return array_shift($input);
72 72
       }
73 73
     }
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
    */
101 101
   function __construct($Reader, $enable_cache = true) {
102 102
     // If there isn't a StreamReader, turn on short circuit mode.
103
-    if (! $Reader || isset($Reader->error) ) {
103
+    if (!$Reader || isset($Reader->error)) {
104 104
       $this->short_circuit = true;
105 105
       return;
106 106
     }
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
     }
155 155
 
156 156
     if ($this->enable_cache) {
157
-      $this->cache_translations = array ();
157
+      $this->cache_translations = array();
158 158
       /* read all strings in the cache */
159 159
       for ($i = 0; $i < $this->total; $i++) {
160 160
         $this->STREAM->seekto($this->table_originals[$i * 2 + 2]);
@@ -176,11 +176,11 @@  discard block
 block discarded – undo
176 176
   function get_original_string($num) {
177 177
     $length = $this->table_originals[$num * 2 + 1];
178 178
     $offset = $this->table_originals[$num * 2 + 2];
179
-    if (! $length)
179
+    if (!$length)
180 180
       return '';
181 181
     $this->STREAM->seekto($offset);
182 182
     $data = $this->STREAM->read($length);
183
-    return (string)$data;
183
+    return (string) $data;
184 184
   }
185 185
 
186 186
   /**
@@ -193,11 +193,11 @@  discard block
 block discarded – undo
193 193
   function get_translation_string($num) {
194 194
     $length = $this->table_translations[$num * 2 + 1];
195 195
     $offset = $this->table_translations[$num * 2 + 2];
196
-    if (! $length)
196
+    if (!$length)
197 197
       return '';
198 198
     $this->STREAM->seekto($offset);
199 199
     $data = $this->STREAM->read($length);
200
-    return (string)$data;
200
+    return (string) $data;
201 201
   }
202 202
 
203 203
   /**
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
       return $this->find_string($string, $end, $start);
228 228
     } else {
229 229
       // Divide table in two parts
230
-      $half = (int)(($start + $end) / 2);
230
+      $half = (int) (($start + $end) / 2);
231 231
       $cmp = strcmp($string, $this->get_original_string($half));
232 232
       if ($cmp == 0)
233 233
         // string is exactly in the middle => return it
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
         $res .= ') : (';
295 295
         break;
296 296
       case ';':
297
-        $res .= str_repeat( ')', $p) . ';';
297
+        $res .= str_repeat(')', $p).';';
298 298
         $p = 0;
299 299
         break;
300 300
       default:
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
     $this->load_tables();
331 331
 
332 332
     // cache header field for plural forms
333
-    if (! is_string($this->pluralheader)) {
333
+    if (!is_string($this->pluralheader)) {
334 334
       if ($this->enable_cache) {
335 335
         $header = $this->cache_translations[""];
336 336
       } else {
@@ -352,12 +352,12 @@  discard block
 block discarded – undo
352 352
   function select_string($n) {
353 353
     if (!is_int($n)) {
354 354
       throw new InvalidArgumentException(
355
-        "Select_string only accepts integers: " . $n);
355
+        "Select_string only accepts integers: ".$n);
356 356
     }
357 357
     $string = $this->get_plural_forms();
358
-    $string = str_replace('nplurals',"\$total",$string);
359
-    $string = str_replace("n",$n,$string);
360
-    $string = str_replace('plural',"\$plural",$string);
358
+    $string = str_replace('nplurals', "\$total", $string);
359
+    $string = str_replace("n", $n, $string);
360
+    $string = str_replace('plural', "\$plural", $string);
361 361
 
362 362
     $total = 0;
363 363
     $plural = 0;
@@ -388,11 +388,11 @@  discard block
 block discarded – undo
388 388
     $select = $this->select_string($number);
389 389
 
390 390
     // this should contains all strings separated by NULLs
391
-    $key = $single . chr(0) . $plural;
391
+    $key = $single.chr(0).$plural;
392 392
 
393 393
 
394 394
     if ($this->enable_cache) {
395
-      if (! array_key_exists($key, $this->cache_translations)) {
395
+      if (!array_key_exists($key, $this->cache_translations)) {
396 396
         return ($number != 1) ? $plural : $single;
397 397
       } else {
398 398
         $result = $this->cache_translations[$key];
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
   }
413 413
 
414 414
   function pgettext($context, $msgid) {
415
-    $key = $context . chr(4) . $msgid;
415
+    $key = $context.chr(4).$msgid;
416 416
     $ret = $this->translate($key);
417 417
     if (strpos($ret, "\004") !== FALSE) {
418 418
       return $msgid;
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
   }
423 423
 
424 424
   function npgettext($context, $singular, $plural, $number) {
425
-    $key = $context . chr(4) . $singular;
425
+    $key = $context.chr(4).$singular;
426 426
     $ret = $this->ngettext($key, $plural, $number);
427 427
     if (strpos($ret, "\004") !== FALSE) {
428 428
       return $singular;
Please login to merge, or discard this patch.
Braces   +47 added lines, -35 removed lines patch added patch discarded remove patch
@@ -140,8 +140,9 @@  discard block
 block discarded – undo
140 140
   function load_tables() {
141 141
     if (is_array($this->cache_translations) &&
142 142
       is_array($this->table_originals) &&
143
-      is_array($this->table_translations))
144
-      return;
143
+      is_array($this->table_translations)) {
144
+          return;
145
+    }
145 146
 
146 147
     /* get original and translations tables */
147 148
     if (!is_array($this->table_originals)) {
@@ -176,8 +177,9 @@  discard block
 block discarded – undo
176 177
   function get_original_string($num) {
177 178
     $length = $this->table_originals[$num * 2 + 1];
178 179
     $offset = $this->table_originals[$num * 2 + 2];
179
-    if (! $length)
180
-      return '';
180
+    if (! $length) {
181
+          return '';
182
+    }
181 183
     $this->STREAM->seekto($offset);
182 184
     $data = $this->STREAM->read($length);
183 185
     return (string)$data;
@@ -193,8 +195,9 @@  discard block
 block discarded – undo
193 195
   function get_translation_string($num) {
194 196
     $length = $this->table_translations[$num * 2 + 1];
195 197
     $offset = $this->table_translations[$num * 2 + 2];
196
-    if (! $length)
197
-      return '';
198
+    if (! $length) {
199
+          return '';
200
+    }
198 201
     $this->STREAM->seekto($offset);
199 202
     $data = $this->STREAM->read($length);
200 203
     return (string)$data;
@@ -218,10 +221,11 @@  discard block
 block discarded – undo
218 221
     if (abs($start - $end) <= 1) {
219 222
       // We're done, now we either found the string, or it doesn't exist
220 223
       $txt = $this->get_original_string($start);
221
-      if ($string == $txt)
222
-        return $start;
223
-      else
224
-        return -1;
224
+      if ($string == $txt) {
225
+              return $start;
226
+      } else {
227
+              return -1;
228
+      }
225 229
     } else if ($start > $end) {
226 230
       // start > end -> turn around and start over
227 231
       return $this->find_string($string, $end, $start);
@@ -229,15 +233,16 @@  discard block
 block discarded – undo
229 233
       // Divide table in two parts
230 234
       $half = (int)(($start + $end) / 2);
231 235
       $cmp = strcmp($string, $this->get_original_string($half));
232
-      if ($cmp == 0)
233
-        // string is exactly in the middle => return it
236
+      if ($cmp == 0) {
237
+              // string is exactly in the middle => return it
234 238
         return $half;
235
-      else if ($cmp < 0)
236
-        // The string is in the upper half
239
+      } else if ($cmp < 0) {
240
+              // The string is in the upper half
237 241
         return $this->find_string($string, $start, $half);
238
-      else
239
-        // The string is in the lower half
242
+      } else {
243
+              // The string is in the lower half
240 244
         return $this->find_string($string, $half, $end);
245
+      }
241 246
     }
242 247
   }
243 248
 
@@ -249,23 +254,26 @@  discard block
 block discarded – undo
249 254
    * @return string translated string (or original, if not found)
250 255
    */
251 256
   function translate($string) {
252
-    if ($this->short_circuit)
253
-      return $string;
257
+    if ($this->short_circuit) {
258
+          return $string;
259
+    }
254 260
     $this->load_tables();
255 261
 
256 262
     if ($this->enable_cache) {
257 263
       // Caching enabled, get translated string from cache
258
-      if (array_key_exists($string, $this->cache_translations))
259
-        return $this->cache_translations[$string];
260
-      else
261
-        return $string;
264
+      if (array_key_exists($string, $this->cache_translations)) {
265
+              return $this->cache_translations[$string];
266
+      } else {
267
+              return $string;
268
+      }
262 269
     } else {
263 270
       // Caching not enabled, try to find string
264 271
       $num = $this->find_string($string);
265
-      if ($num == -1)
266
-        return $string;
267
-      else
268
-        return $this->get_translation_string($num);
272
+      if ($num == -1) {
273
+              return $string;
274
+      } else {
275
+              return $this->get_translation_string($num);
276
+      }
269 277
     }
270 278
   }
271 279
 
@@ -311,10 +319,11 @@  discard block
 block discarded – undo
311 319
    * @return string verbatim plural form header field
312 320
    */
313 321
   function extract_plural_forms_header_from_po_header($header) {
314
-    if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs))
315
-      $expr = $regs[2];
316
-    else
317
-      $expr = "nplurals=2; plural=n == 1 ? 0 : 1;";
322
+    if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs)) {
323
+          $expr = $regs[2];
324
+    } else {
325
+          $expr = "nplurals=2; plural=n == 1 ? 0 : 1;";
326
+    }
318 327
     return $expr;
319 328
   }
320 329
 
@@ -363,7 +372,9 @@  discard block
 block discarded – undo
363 372
     $plural = 0;
364 373
 
365 374
     eval("$string");
366
-    if ($plural >= $total) $plural = $total - 1;
375
+    if ($plural >= $total) {
376
+    	$plural = $total - 1;
377
+    }
367 378
     return $plural;
368 379
   }
369 380
 
@@ -378,10 +389,11 @@  discard block
 block discarded – undo
378 389
    */
379 390
   function ngettext($single, $plural, $number) {
380 391
     if ($this->short_circuit) {
381
-      if ($number != 1)
382
-        return $plural;
383
-      else
384
-        return $single;
392
+      if ($number != 1) {
393
+              return $plural;
394
+      } else {
395
+              return $single;
396
+      }
385 397
     }
386 398
 
387 399
     // find out the appropriate form
Please login to merge, or discard this patch.
index.php 3 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -93,9 +93,9 @@  discard block
 block discarded – undo
93 93
 	<?php
94 94
 		foreach (PluginHost::getInstance()->get_plugins() as $n => $p) {
95 95
 			if (method_exists($p, "get_js")) {
96
-			    $script = $p->get_js();
96
+				$script = $p->get_js();
97 97
 
98
-			    if ($script) {
98
+				if ($script) {
99 99
 					echo "try {
100 100
 					    $script
101 101
 					} catch (e) {
@@ -146,10 +146,10 @@  discard block
 block discarded – undo
146 146
             <img src='images/indicator_tiny.gif'/>
147 147
             <?php echo  __("Loading, please wait..."); ?></div>
148 148
         <?php
149
-          foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_TREE) as $p) {
150
-            echo $p->hook_feed_tree();
151
-          }
152
-        ?>
149
+		  foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_TREE) as $p) {
150
+			echo $p->hook_feed_tree();
151
+		  }
152
+		?>
153 153
         <div id="feedTree"></div>
154 154
     </div>
155 155
 
@@ -167,10 +167,10 @@  discard block
 block discarded – undo
167 167
                title="<?php echo __('Updates are available from Git.') ?>">new_releases</i>
168 168
 
169 169
             <?php
170
-            foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_MAIN_TOOLBAR_BUTTON) as $p) {
171
-                echo $p->hook_main_toolbar_button();
172
-            }
173
-            ?>
170
+			foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_MAIN_TOOLBAR_BUTTON) as $p) {
171
+				echo $p->hook_main_toolbar_button();
172
+			}
173
+			?>
174 174
 
175 175
             <form id="toolbar-headlines" action="" style="order : 10" onsubmit='return false'>
176 176
 
@@ -220,10 +220,10 @@  discard block
 block discarded – undo
220 220
             <div class="action-chooser" style="order : 30">
221 221
 
222 222
                 <?php
223
-                    foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_TOOLBAR_BUTTON) as $p) {
224
-                         echo $p->hook_toolbar_button();
225
-                    }
226
-                ?>
223
+					foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_TOOLBAR_BUTTON) as $p) {
224
+						 echo $p->hook_toolbar_button();
225
+					}
226
+				?>
227 227
 
228 228
                 <div dojoType="fox.form.DropDownButton" class="action-button" title="<?php echo __('Actions...') ?>">
229 229
 					<span><i class="material-icons">menu</i></span>
@@ -242,10 +242,10 @@  discard block
 block discarded – undo
242 242
                         <div dojoType="dijit.MenuItem" onclick="App.onActionSelected('qmcHKhelp')"><?php echo __('Keyboard shortcuts help') ?></div>
243 243
 
244 244
                         <?php
245
-                            foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ACTION_ITEM) as $p) {
246
-                             echo $p->hook_action_item();
247
-                            }
248
-                        ?>
245
+							foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ACTION_ITEM) as $p) {
246
+							 echo $p->hook_action_item();
247
+							}
248
+						?>
249 249
 
250 250
                         <?php if (!$_SESSION["hide_logout"]) { ?>
251 251
                             <div dojoType="dijit.MenuItem" onclick="App.onActionSelected('qmcLogout')"><?php echo __('Logout') ?></div>
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -12,11 +12,11 @@
 block discarded – undo
12 12
 	// we need a separate check here because functions.php might get parsed
13 13
 	// incorrectly before 5.3 because of :: syntax.
14 14
 	if (version_compare(PHP_VERSION, '5.6.0', '<')) {
15
-		print "<b>Fatal Error</b>: PHP version 5.6.0 or newer required. You're using " . PHP_VERSION . ".\n";
15
+		print "<b>Fatal Error</b>: PHP version 5.6.0 or newer required. You're using ".PHP_VERSION.".\n";
16 16
 		exit;
17 17
 	}
18 18
 
19
-	set_include_path(dirname(__FILE__) ."/include" . PATH_SEPARATOR .
19
+	set_include_path(dirname(__FILE__)."/include".PATH_SEPARATOR.
20 20
 		get_include_path());
21 21
 
22 22
 	require_once "autoload.php";
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,7 +26,9 @@
 block discarded – undo
26 26
 	require_once "config.php";
27 27
 	require_once "db-prefs.php";
28 28
 
29
-	if (!init_plugins()) return;
29
+	if (!init_plugins()) {
30
+		return;
31
+	}
30 32
 
31 33
 	login_sequence();
32 34
 
Please login to merge, or discard this patch.