@@ -14,7 +14,7 @@ |
||
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | public function get_js() { |
| 17 | - return file_get_contents(__DIR__ . "/init.js"); |
|
| 17 | + return file_get_contents(__DIR__."/init.js"); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | public function api_version() { |
@@ -1,24 +1,24 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | class No_URL_Hashes extends Plugin { |
| 3 | - private $host; |
|
| 3 | + private $host; |
|
| 4 | 4 | |
| 5 | - public function about() { |
|
| 6 | - return array(1.0, |
|
| 7 | - "Disable URL hash usage (e.g. #f=10, etc)", |
|
| 8 | - "fox"); |
|
| 9 | - } |
|
| 5 | + public function about() { |
|
| 6 | + return array(1.0, |
|
| 7 | + "Disable URL hash usage (e.g. #f=10, etc)", |
|
| 8 | + "fox"); |
|
| 9 | + } |
|
| 10 | 10 | |
| 11 | - public function init($host) { |
|
| 12 | - $this->host = $host; |
|
| 11 | + public function init($host) { |
|
| 12 | + $this->host = $host; |
|
| 13 | 13 | |
| 14 | - } |
|
| 14 | + } |
|
| 15 | 15 | |
| 16 | - public function get_js() { |
|
| 17 | - return file_get_contents(__DIR__ . "/init.js"); |
|
| 18 | - } |
|
| 16 | + public function get_js() { |
|
| 17 | + return file_get_contents(__DIR__ . "/init.js"); |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - public function api_version() { |
|
| 21 | - return 2; |
|
| 22 | - } |
|
| 20 | + public function api_version() { |
|
| 21 | + return 2; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | 24 | } |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | public function get_js() { |
| 17 | - return file_get_contents(__DIR__ . "/init.js"); |
|
| 17 | + return file_get_contents(__DIR__."/init.js"); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | public function api_version() { |
@@ -1,23 +1,23 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | class Af_Zz_NoAutoPlay extends Plugin { |
| 3 | - private $host; |
|
| 3 | + private $host; |
|
| 4 | 4 | |
| 5 | - public function about() { |
|
| 6 | - return array(1.0, |
|
| 7 | - "Don't autoplay HTML5 videos", |
|
| 8 | - "fox"); |
|
| 9 | - } |
|
| 5 | + public function about() { |
|
| 6 | + return array(1.0, |
|
| 7 | + "Don't autoplay HTML5 videos", |
|
| 8 | + "fox"); |
|
| 9 | + } |
|
| 10 | 10 | |
| 11 | - public function init($host) { |
|
| 12 | - $this->host = $host; |
|
| 13 | - } |
|
| 11 | + public function init($host) { |
|
| 12 | + $this->host = $host; |
|
| 13 | + } |
|
| 14 | 14 | |
| 15 | - public function get_js() { |
|
| 16 | - return file_get_contents(__DIR__ . "/init.js"); |
|
| 17 | - } |
|
| 15 | + public function get_js() { |
|
| 16 | + return file_get_contents(__DIR__ . "/init.js"); |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - public function api_version() { |
|
| 20 | - return 2; |
|
| 21 | - } |
|
| 19 | + public function api_version() { |
|
| 20 | + return 2; |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | 23 | } |
@@ -140,8 +140,9 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
@@ -34,75 +34,75 @@ discard block |
||
| 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 |
||
| 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,154 +128,154 @@ discard block |
||
| 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 | /* get original and translations tables */ |
| 147 | 147 | if (!is_array($this->table_originals)) { |
| 148 | - $this->STREAM->seekto($this->originals); |
|
| 149 | - $this->table_originals = $this->readintarray($this->total * 2); |
|
| 148 | + $this->STREAM->seekto($this->originals); |
|
| 149 | + $this->table_originals = $this->readintarray($this->total * 2); |
|
| 150 | 150 | } |
| 151 | 151 | if (!is_array($this->table_translations)) { |
| 152 | - $this->STREAM->seekto($this->translations); |
|
| 153 | - $this->table_translations = $this->readintarray($this->total * 2); |
|
| 152 | + $this->STREAM->seekto($this->translations); |
|
| 153 | + $this->table_translations = $this->readintarray($this->total * 2); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 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++) { |
|
| 157 | + $this->cache_translations = array (); |
|
| 158 | + /* read all strings in the cache */ |
|
| 159 | + for ($i = 0; $i < $this->total; $i++) { |
|
| 160 | 160 | $this->STREAM->seekto($this->table_originals[$i * 2 + 2]); |
| 161 | 161 | $original = $this->STREAM->read($this->table_originals[$i * 2 + 1]); |
| 162 | 162 | $this->STREAM->seekto($this->table_translations[$i * 2 + 2]); |
| 163 | 163 | $translation = $this->STREAM->read($this->table_translations[$i * 2 + 1]); |
| 164 | 164 | $this->cache_translations[$original] = $translation; |
| 165 | - } |
|
| 165 | + } |
|
| 166 | + } |
|
| 166 | 167 | } |
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Returns a string from the "originals" table |
|
| 171 | - * |
|
| 172 | - * @access private |
|
| 173 | - * @param int num Offset number of original string |
|
| 174 | - * @return string Requested string if found, otherwise '' |
|
| 175 | - */ |
|
| 176 | - function get_original_string($num) { |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Returns a string from the "originals" table |
|
| 171 | + * |
|
| 172 | + * @access private |
|
| 173 | + * @param int num Offset number of original string |
|
| 174 | + * @return string Requested string if found, otherwise '' |
|
| 175 | + */ |
|
| 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 | 179 | if (! $length) |
| 180 | - return ''; |
|
| 180 | + return ''; |
|
| 181 | 181 | $this->STREAM->seekto($offset); |
| 182 | 182 | $data = $this->STREAM->read($length); |
| 183 | 183 | return (string)$data; |
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * Returns a string from the "translations" table |
|
| 188 | - * |
|
| 189 | - * @access private |
|
| 190 | - * @param int num Offset number of original string |
|
| 191 | - * @return string Requested string if found, otherwise '' |
|
| 192 | - */ |
|
| 193 | - function get_translation_string($num) { |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * Returns a string from the "translations" table |
|
| 188 | + * |
|
| 189 | + * @access private |
|
| 190 | + * @param int num Offset number of original string |
|
| 191 | + * @return string Requested string if found, otherwise '' |
|
| 192 | + */ |
|
| 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 | 196 | if (! $length) |
| 197 | - return ''; |
|
| 197 | + return ''; |
|
| 198 | 198 | $this->STREAM->seekto($offset); |
| 199 | 199 | $data = $this->STREAM->read($length); |
| 200 | 200 | return (string)$data; |
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Binary search for string |
|
| 205 | - * |
|
| 206 | - * @access private |
|
| 207 | - * @param string string |
|
| 208 | - * @param int start (internally used in recursive function) |
|
| 209 | - * @param int end (internally used in recursive function) |
|
| 210 | - * @return int string number (offset in originals table) |
|
| 211 | - */ |
|
| 212 | - function find_string($string, $start = -1, $end = -1) { |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Binary search for string |
|
| 205 | + * |
|
| 206 | + * @access private |
|
| 207 | + * @param string string |
|
| 208 | + * @param int start (internally used in recursive function) |
|
| 209 | + * @param int end (internally used in recursive function) |
|
| 210 | + * @return int string number (offset in originals table) |
|
| 211 | + */ |
|
| 212 | + function find_string($string, $start = -1, $end = -1) { |
|
| 213 | 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; |
|
| 214 | + // find_string is called with only one parameter, set start end end |
|
| 215 | + $start = 0; |
|
| 216 | + $end = $this->total; |
|
| 217 | 217 | } |
| 218 | 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) |
|
| 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 | 222 | return $start; |
| 223 | - else |
|
| 223 | + else |
|
| 224 | 224 | return -1; |
| 225 | 225 | } else if ($start > $end) { |
| 226 | - // start > end -> turn around and start over |
|
| 227 | - return $this->find_string($string, $end, $start); |
|
| 226 | + // start > end -> turn around and start over |
|
| 227 | + return $this->find_string($string, $end, $start); |
|
| 228 | 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) |
|
| 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 | 233 | // string is exactly in the middle => return it |
| 234 | 234 | return $half; |
| 235 | - else if ($cmp < 0) |
|
| 235 | + else if ($cmp < 0) |
|
| 236 | 236 | // The string is in the upper half |
| 237 | 237 | return $this->find_string($string, $start, $half); |
| 238 | - else |
|
| 238 | + else |
|
| 239 | 239 | // The string is in the lower half |
| 240 | 240 | return $this->find_string($string, $half, $end); |
| 241 | 241 | } |
| 242 | - } |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * Translates a string |
|
| 246 | - * |
|
| 247 | - * @access public |
|
| 248 | - * @param string string to be translated |
|
| 249 | - * @return string translated string (or original, if not found) |
|
| 250 | - */ |
|
| 251 | - function translate($string) { |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * Translates a string |
|
| 246 | + * |
|
| 247 | + * @access public |
|
| 248 | + * @param string string to be translated |
|
| 249 | + * @return string translated string (or original, if not found) |
|
| 250 | + */ |
|
| 251 | + function translate($string) { |
|
| 252 | 252 | if ($this->short_circuit) |
| 253 | - return $string; |
|
| 253 | + return $string; |
|
| 254 | 254 | $this->load_tables(); |
| 255 | 255 | |
| 256 | 256 | if ($this->enable_cache) { |
| 257 | - // Caching enabled, get translated string from cache |
|
| 258 | - if (array_key_exists($string, $this->cache_translations)) |
|
| 257 | + // Caching enabled, get translated string from cache |
|
| 258 | + if (array_key_exists($string, $this->cache_translations)) |
|
| 259 | 259 | return $this->cache_translations[$string]; |
| 260 | - else |
|
| 260 | + else |
|
| 261 | 261 | return $string; |
| 262 | 262 | } else { |
| 263 | - // Caching not enabled, try to find string |
|
| 264 | - $num = $this->find_string($string); |
|
| 265 | - if ($num == -1) |
|
| 263 | + // Caching not enabled, try to find string |
|
| 264 | + $num = $this->find_string($string); |
|
| 265 | + if ($num == -1) |
|
| 266 | 266 | return $string; |
| 267 | - else |
|
| 267 | + else |
|
| 268 | 268 | return $this->get_translation_string($num); |
| 269 | 269 | } |
| 270 | - } |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * Sanitize plural form expression for use in PHP eval call. |
|
| 274 | - * |
|
| 275 | - * @access private |
|
| 276 | - * @return string sanitized plural form expression |
|
| 277 | - */ |
|
| 278 | - function sanitize_plural_expression($expr) { |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * Sanitize plural form expression for use in PHP eval call. |
|
| 274 | + * |
|
| 275 | + * @access private |
|
| 276 | + * @return string sanitized plural form expression |
|
| 277 | + */ |
|
| 278 | + function sanitize_plural_expression($expr) { |
|
| 279 | 279 | // Get rid of disallowed characters. |
| 280 | 280 | $expr = preg_replace('@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@', '', $expr); |
| 281 | 281 | |
@@ -284,74 +284,74 @@ discard block |
||
| 284 | 284 | $res = ''; |
| 285 | 285 | $p = 0; |
| 286 | 286 | for ($i = 0; $i < strlen($expr); $i++) { |
| 287 | - $ch = $expr[$i]; |
|
| 288 | - switch ($ch) { |
|
| 289 | - case '?': |
|
| 287 | + $ch = $expr[$i]; |
|
| 288 | + switch ($ch) { |
|
| 289 | + case '?': |
|
| 290 | 290 | $res .= ' ? ('; |
| 291 | 291 | $p++; |
| 292 | 292 | break; |
| 293 | - case ':': |
|
| 293 | + case ':': |
|
| 294 | 294 | $res .= ') : ('; |
| 295 | 295 | break; |
| 296 | - case ';': |
|
| 296 | + case ';': |
|
| 297 | 297 | $res .= str_repeat( ')', $p) . ';'; |
| 298 | 298 | $p = 0; |
| 299 | 299 | break; |
| 300 | - default: |
|
| 300 | + default: |
|
| 301 | 301 | $res .= $ch; |
| 302 | - } |
|
| 302 | + } |
|
| 303 | 303 | } |
| 304 | 304 | return $res; |
| 305 | - } |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * Parse full PO header and extract only plural forms line. |
|
| 309 | - * |
|
| 310 | - * @access private |
|
| 311 | - * @return string verbatim plural form header field |
|
| 312 | - */ |
|
| 313 | - function extract_plural_forms_header_from_po_header($header) { |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * Parse full PO header and extract only plural forms line. |
|
| 309 | + * |
|
| 310 | + * @access private |
|
| 311 | + * @return string verbatim plural form header field |
|
| 312 | + */ |
|
| 313 | + function extract_plural_forms_header_from_po_header($header) { |
|
| 314 | 314 | if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs)) |
| 315 | - $expr = $regs[2]; |
|
| 315 | + $expr = $regs[2]; |
|
| 316 | 316 | else |
| 317 | - $expr = "nplurals=2; plural=n == 1 ? 0 : 1;"; |
|
| 317 | + $expr = "nplurals=2; plural=n == 1 ? 0 : 1;"; |
|
| 318 | 318 | return $expr; |
| 319 | - } |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * Get possible plural forms from MO header |
|
| 323 | - * |
|
| 324 | - * @access private |
|
| 325 | - * @return string plural form header |
|
| 326 | - */ |
|
| 327 | - function get_plural_forms() { |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * Get possible plural forms from MO header |
|
| 323 | + * |
|
| 324 | + * @access private |
|
| 325 | + * @return string plural form header |
|
| 326 | + */ |
|
| 327 | + function get_plural_forms() { |
|
| 328 | 328 | // lets assume message number 0 is header |
| 329 | 329 | // this is true, right? |
| 330 | 330 | $this->load_tables(); |
| 331 | 331 | |
| 332 | 332 | // cache header field for plural forms |
| 333 | 333 | if (! is_string($this->pluralheader)) { |
| 334 | - if ($this->enable_cache) { |
|
| 334 | + if ($this->enable_cache) { |
|
| 335 | 335 | $header = $this->cache_translations[""]; |
| 336 | - } else { |
|
| 336 | + } else { |
|
| 337 | 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); |
|
| 338 | + } |
|
| 339 | + $expr = $this->extract_plural_forms_header_from_po_header($header); |
|
| 340 | + $this->pluralheader = $this->sanitize_plural_expression($expr); |
|
| 341 | 341 | } |
| 342 | 342 | return $this->pluralheader; |
| 343 | - } |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * Detects which plural form to take |
|
| 347 | - * |
|
| 348 | - * @access private |
|
| 349 | - * @param n count |
|
| 350 | - * @return int array index of the right plural form |
|
| 351 | - */ |
|
| 352 | - function select_string($n) { |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * Detects which plural form to take |
|
| 347 | + * |
|
| 348 | + * @access private |
|
| 349 | + * @param n count |
|
| 350 | + * @return int array index of the right plural form |
|
| 351 | + */ |
|
| 352 | + function select_string($n) { |
|
| 353 | 353 | if (!is_int($n)) { |
| 354 | - throw new InvalidArgumentException( |
|
| 354 | + throw new InvalidArgumentException( |
|
| 355 | 355 | "Select_string only accepts integers: " . $n); |
| 356 | 356 | } |
| 357 | 357 | $string = $this->get_plural_forms(); |
@@ -365,22 +365,22 @@ discard block |
||
| 365 | 365 | eval("$string"); |
| 366 | 366 | if ($plural >= $total) $plural = $total - 1; |
| 367 | 367 | return $plural; |
| 368 | - } |
|
| 369 | - |
|
| 370 | - /** |
|
| 371 | - * Plural version of gettext |
|
| 372 | - * |
|
| 373 | - * @access public |
|
| 374 | - * @param string single |
|
| 375 | - * @param string plural |
|
| 376 | - * @param string number |
|
| 377 | - * @return translated plural form |
|
| 378 | - */ |
|
| 379 | - function ngettext($single, $plural, $number) { |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + /** |
|
| 371 | + * Plural version of gettext |
|
| 372 | + * |
|
| 373 | + * @access public |
|
| 374 | + * @param string single |
|
| 375 | + * @param string plural |
|
| 376 | + * @param string number |
|
| 377 | + * @return translated plural form |
|
| 378 | + */ |
|
| 379 | + function ngettext($single, $plural, $number) { |
|
| 380 | 380 | if ($this->short_circuit) { |
| 381 | - if ($number != 1) |
|
| 381 | + if ($number != 1) |
|
| 382 | 382 | return $plural; |
| 383 | - else |
|
| 383 | + else |
|
| 384 | 384 | return $single; |
| 385 | 385 | } |
| 386 | 386 | |
@@ -392,45 +392,45 @@ discard block |
||
| 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 | - } else { |
|
| 397 | + } else { |
|
| 398 | 398 | $result = $this->cache_translations[$key]; |
| 399 | 399 | $list = explode(chr(0), $result); |
| 400 | 400 | return $list[$select]; |
| 401 | - } |
|
| 401 | + } |
|
| 402 | 402 | } else { |
| 403 | - $num = $this->find_string($key); |
|
| 404 | - if ($num == -1) { |
|
| 403 | + $num = $this->find_string($key); |
|
| 404 | + if ($num == -1) { |
|
| 405 | 405 | return ($number != 1) ? $plural : $single; |
| 406 | - } else { |
|
| 406 | + } else { |
|
| 407 | 407 | $result = $this->get_translation_string($num); |
| 408 | 408 | $list = explode(chr(0), $result); |
| 409 | 409 | return $list[$select]; |
| 410 | - } |
|
| 410 | + } |
|
| 411 | + } |
|
| 411 | 412 | } |
| 412 | - } |
|
| 413 | 413 | |
| 414 | - function pgettext($context, $msgid) { |
|
| 414 | + function pgettext($context, $msgid) { |
|
| 415 | 415 | $key = $context . chr(4) . $msgid; |
| 416 | 416 | $ret = $this->translate($key); |
| 417 | 417 | if (strpos($ret, "\004") !== false) { |
| 418 | - return $msgid; |
|
| 418 | + return $msgid; |
|
| 419 | 419 | } else { |
| 420 | - return $ret; |
|
| 420 | + return $ret; |
|
| 421 | + } |
|
| 421 | 422 | } |
| 422 | - } |
|
| 423 | 423 | |
| 424 | - function npgettext($context, $singular, $plural, $number) { |
|
| 424 | + function npgettext($context, $singular, $plural, $number) { |
|
| 425 | 425 | $key = $context . chr(4) . $singular; |
| 426 | 426 | $ret = $this->ngettext($key, $plural, $number); |
| 427 | 427 | if (strpos($ret, "\004") !== false) { |
| 428 | - return $singular; |
|
| 428 | + return $singular; |
|
| 429 | 429 | } else { |
| 430 | - return $ret; |
|
| 430 | + return $ret; |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | - } |
|
| 433 | + } |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | ?> |
@@ -38,17 +38,17 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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; |
@@ -25,19 +25,19 @@ |
||
| 25 | 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 26 | 26 | */ |
| 27 | 27 | |
| 28 | - $QR_BASEDIR = dirname(__FILE__).DIRECTORY_SEPARATOR; |
|
| 28 | + $QR_BASEDIR = dirname(__FILE__).DIRECTORY_SEPARATOR; |
|
| 29 | 29 | |
| 30 | - // Required libs |
|
| 30 | + // Required libs |
|
| 31 | 31 | |
| 32 | - include $QR_BASEDIR."qrconst.php"; |
|
| 33 | - include $QR_BASEDIR."qrconfig.php"; |
|
| 34 | - include $QR_BASEDIR."qrtools.php"; |
|
| 35 | - include $QR_BASEDIR."qrspec.php"; |
|
| 36 | - include $QR_BASEDIR."qrimage.php"; |
|
| 37 | - include $QR_BASEDIR."qrinput.php"; |
|
| 38 | - include $QR_BASEDIR."qrbitstream.php"; |
|
| 39 | - include $QR_BASEDIR."qrsplit.php"; |
|
| 40 | - include $QR_BASEDIR."qrrscode.php"; |
|
| 41 | - include $QR_BASEDIR."qrmask.php"; |
|
| 42 | - include $QR_BASEDIR."qrencode.php"; |
|
| 32 | + include $QR_BASEDIR."qrconst.php"; |
|
| 33 | + include $QR_BASEDIR."qrconfig.php"; |
|
| 34 | + include $QR_BASEDIR."qrtools.php"; |
|
| 35 | + include $QR_BASEDIR."qrspec.php"; |
|
| 36 | + include $QR_BASEDIR."qrimage.php"; |
|
| 37 | + include $QR_BASEDIR."qrinput.php"; |
|
| 38 | + include $QR_BASEDIR."qrbitstream.php"; |
|
| 39 | + include $QR_BASEDIR."qrsplit.php"; |
|
| 40 | + include $QR_BASEDIR."qrrscode.php"; |
|
| 41 | + include $QR_BASEDIR."qrmask.php"; |
|
| 42 | + include $QR_BASEDIR."qrencode.php"; |
|
| 43 | 43 | |
@@ -33,4 +33,4 @@ |
||
| 33 | 33 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 34 | 34 | */ |
| 35 | 35 | |
| 36 | - |
|
| 37 | 36 | \ No newline at end of file |
| 37 | + |
|
| 38 | 38 | \ No newline at end of file |
@@ -63,11 +63,23 @@ discard block |
||
| 63 | 63 | $rs = null; |
| 64 | 64 | |
| 65 | 65 | // Check parameter ranges |
| 66 | - if($symsize < 0 || $symsize > 8) return $rs; |
|
| 67 | - if($fcr < 0 || $fcr >= (1<<$symsize)) return $rs; |
|
| 68 | - if($prim <= 0 || $prim >= (1<<$symsize)) return $rs; |
|
| 69 | - if($nroots < 0 || $nroots >= (1<<$symsize)) return $rs; // Can't have more roots than symbol values! |
|
| 70 | - if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding |
|
| 66 | + if($symsize < 0 || $symsize > 8) { |
|
| 67 | + return $rs; |
|
| 68 | + } |
|
| 69 | + if($fcr < 0 || $fcr >= (1<<$symsize)) { |
|
| 70 | + return $rs; |
|
| 71 | + } |
|
| 72 | + if($prim <= 0 || $prim >= (1<<$symsize)) { |
|
| 73 | + return $rs; |
|
| 74 | + } |
|
| 75 | + if($nroots < 0 || $nroots >= (1<<$symsize)) { |
|
| 76 | + return $rs; |
|
| 77 | + } |
|
| 78 | + // Can't have more roots than symbol values! |
|
| 79 | + if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) { |
|
| 80 | + return $rs; |
|
| 81 | + } |
|
| 82 | + // Too much padding |
|
| 71 | 83 | |
| 72 | 84 | $rs = new QRrsItem(); |
| 73 | 85 | $rs->mm = $symsize; |
@@ -133,8 +145,9 @@ discard block |
||
| 133 | 145 | } |
| 134 | 146 | |
| 135 | 147 | // convert rs->genpoly[] to index form for quicker encoding |
| 136 | - for ($i = 0; $i <= $nroots; $i++) |
|
| 137 | - $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]]; |
|
| 148 | + for ($i = 0; $i <= $nroots; $i++) { |
|
| 149 | + $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]]; |
|
| 150 | + } |
|
| 138 | 151 | |
| 139 | 152 | return $rs; |
| 140 | 153 | } |
@@ -192,12 +205,24 @@ discard block |
||
| 192 | 205 | public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) |
| 193 | 206 | {
|
| 194 | 207 | foreach(self::$items as $rs) {
|
| 195 | - if($rs->pad != $pad) continue; |
|
| 196 | - if($rs->nroots != $nroots) continue; |
|
| 197 | - if($rs->mm != $symsize) continue; |
|
| 198 | - if($rs->gfpoly != $gfpoly) continue; |
|
| 199 | - if($rs->fcr != $fcr) continue; |
|
| 200 | - if($rs->prim != $prim) continue; |
|
| 208 | + if($rs->pad != $pad) { |
|
| 209 | + continue; |
|
| 210 | + } |
|
| 211 | + if($rs->nroots != $nroots) { |
|
| 212 | + continue; |
|
| 213 | + } |
|
| 214 | + if($rs->mm != $symsize) { |
|
| 215 | + continue; |
|
| 216 | + } |
|
| 217 | + if($rs->gfpoly != $gfpoly) { |
|
| 218 | + continue; |
|
| 219 | + } |
|
| 220 | + if($rs->fcr != $fcr) { |
|
| 221 | + continue; |
|
| 222 | + } |
|
| 223 | + if($rs->prim != $prim) { |
|
| 224 | + continue; |
|
| 225 | + } |
|
| 201 | 226 | |
| 202 | 227 | return $rs; |
| 203 | 228 | } |
@@ -30,16 +30,16 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | class QRrsItem {
|
| 32 | 32 | |
| 33 | - public $mm; // Bits per symbol |
|
| 34 | - public $nn; // Symbols per block (= (1<<mm)-1) |
|
| 35 | - public $alpha_to = array(); // log lookup table |
|
| 36 | - public $index_of = array(); // Antilog lookup table |
|
| 37 | - public $genpoly = array(); // Generator polynomial |
|
| 38 | - public $nroots; // Number of generator roots = number of parity symbols |
|
| 39 | - public $fcr; // First consecutive root, index form |
|
| 40 | - public $prim; // Primitive element, index form |
|
| 41 | - public $iprim; // prim-th root of 1, index form |
|
| 42 | - public $pad; // Padding bytes in shortened block |
|
| 33 | + public $mm; // Bits per symbol |
|
| 34 | + public $nn; // Symbols per block (= (1<<mm)-1) |
|
| 35 | + public $alpha_to = array(); // log lookup table |
|
| 36 | + public $index_of = array(); // Antilog lookup table |
|
| 37 | + public $genpoly = array(); // Generator polynomial |
|
| 38 | + public $nroots; // Number of generator roots = number of parity symbols |
|
| 39 | + public $fcr; // First consecutive root, index form |
|
| 40 | + public $prim; // Primitive element, index form |
|
| 41 | + public $iprim; // prim-th root of 1, index form |
|
| 42 | + public $pad; // Padding bytes in shortened block |
|
| 43 | 43 | public $gfpoly; |
| 44 | 44 | |
| 45 | 45 | //---------------------------------------------------------------------- |
@@ -63,47 +63,47 @@ discard block |
||
| 63 | 63 | $rs = null; |
| 64 | 64 | |
| 65 | 65 | // Check parameter ranges |
| 66 | - if($symsize < 0 || $symsize > 8) return $rs; |
|
| 67 | - if($fcr < 0 || $fcr >= (1<<$symsize)) return $rs; |
|
| 68 | - if($prim <= 0 || $prim >= (1<<$symsize)) return $rs; |
|
| 69 | - if($nroots < 0 || $nroots >= (1<<$symsize)) return $rs; // Can't have more roots than symbol values! |
|
| 70 | - if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding |
|
| 66 | + if ($symsize < 0 || $symsize > 8) return $rs; |
|
| 67 | + if ($fcr < 0 || $fcr >= (1 << $symsize)) return $rs; |
|
| 68 | + if ($prim <= 0 || $prim >= (1 << $symsize)) return $rs; |
|
| 69 | + if ($nroots < 0 || $nroots >= (1 << $symsize)) return $rs; // Can't have more roots than symbol values! |
|
| 70 | + if ($pad < 0 || $pad >= ((1 << $symsize) - 1 - $nroots)) return $rs; // Too much padding |
|
| 71 | 71 | |
| 72 | 72 | $rs = new QRrsItem(); |
| 73 | 73 | $rs->mm = $symsize; |
| 74 | - $rs->nn = (1<<$symsize)-1; |
|
| 74 | + $rs->nn = (1 << $symsize) - 1; |
|
| 75 | 75 | $rs->pad = $pad; |
| 76 | 76 | |
| 77 | - $rs->alpha_to = array_fill(0, $rs->nn+1, 0); |
|
| 78 | - $rs->index_of = array_fill(0, $rs->nn+1, 0); |
|
| 77 | + $rs->alpha_to = array_fill(0, $rs->nn + 1, 0); |
|
| 78 | + $rs->index_of = array_fill(0, $rs->nn + 1, 0); |
|
| 79 | 79 | |
| 80 | 80 | // PHP style macro replacement ;) |
| 81 | - $NN =& $rs->nn; |
|
| 82 | - $A0 =& $NN; |
|
| 81 | + $NN = & $rs->nn; |
|
| 82 | + $A0 = & $NN; |
|
| 83 | 83 | |
| 84 | 84 | // Generate Galois field lookup tables |
| 85 | 85 | $rs->index_of[0] = $A0; // log(zero) = -inf |
| 86 | 86 | $rs->alpha_to[$A0] = 0; // alpha**-inf = 0 |
| 87 | 87 | $sr = 1; |
| 88 | 88 | |
| 89 | - for($i=0; $i<$rs->nn; $i++) {
|
|
| 89 | + for ($i = 0; $i < $rs->nn; $i++) {
|
|
| 90 | 90 | $rs->index_of[$sr] = $i; |
| 91 | 91 | $rs->alpha_to[$i] = $sr; |
| 92 | 92 | $sr <<= 1; |
| 93 | - if($sr & (1<<$symsize)) {
|
|
| 93 | + if ($sr & (1 << $symsize)) {
|
|
| 94 | 94 | $sr ^= $gfpoly; |
| 95 | 95 | } |
| 96 | 96 | $sr &= $rs->nn; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - if($sr != 1){
|
|
| 99 | + if ($sr != 1) {
|
|
| 100 | 100 | // field generator polynomial is not primitive! |
| 101 | 101 | $rs = null; |
| 102 | 102 | return $rs; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /* Form RS code generator polynomial from its roots */ |
| 106 | - $rs->genpoly = array_fill(0, $nroots+1, 0); |
|
| 106 | + $rs->genpoly = array_fill(0, $nroots + 1, 0); |
|
| 107 | 107 | |
| 108 | 108 | $rs->fcr = $fcr; |
| 109 | 109 | $rs->prim = $prim; |
@@ -111,21 +111,21 @@ discard block |
||
| 111 | 111 | $rs->gfpoly = $gfpoly; |
| 112 | 112 | |
| 113 | 113 | /* Find prim-th root of 1, used in decoding */ |
| 114 | - for($iprim=1;($iprim % $prim) != 0;$iprim += $rs->nn) |
|
| 114 | + for ($iprim = 1; ($iprim % $prim) != 0; $iprim += $rs->nn) |
|
| 115 | 115 | ; // intentional empty-body loop! |
| 116 | 116 | |
| 117 | - $rs->iprim = (int)($iprim / $prim); |
|
| 117 | + $rs->iprim = (int) ($iprim / $prim); |
|
| 118 | 118 | $rs->genpoly[0] = 1; |
| 119 | 119 | |
| 120 | - for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) {
|
|
| 121 | - $rs->genpoly[$i+1] = 1; |
|
| 120 | + for ($i = 0, $root = $fcr * $prim; $i < $nroots; $i++, $root += $prim) {
|
|
| 121 | + $rs->genpoly[$i + 1] = 1; |
|
| 122 | 122 | |
| 123 | 123 | // Multiply rs->genpoly[] by @**(root + x) |
| 124 | 124 | for ($j = $i; $j > 0; $j--) {
|
| 125 | 125 | if ($rs->genpoly[$j] != 0) {
|
| 126 | - $rs->genpoly[$j] = $rs->genpoly[$j-1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)]; |
|
| 126 | + $rs->genpoly[$j] = $rs->genpoly[$j - 1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)]; |
|
| 127 | 127 | } else {
|
| 128 | - $rs->genpoly[$j] = $rs->genpoly[$j-1]; |
|
| 128 | + $rs->genpoly[$j] = $rs->genpoly[$j - 1]; |
|
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | 131 | // rs->genpoly[0] can never be zero |
@@ -142,38 +142,38 @@ discard block |
||
| 142 | 142 | //---------------------------------------------------------------------- |
| 143 | 143 | public function encode_rs_char($data, &$parity) |
| 144 | 144 | {
|
| 145 | - $MM =& $this->mm; |
|
| 146 | - $NN =& $this->nn; |
|
| 147 | - $ALPHA_TO =& $this->alpha_to; |
|
| 148 | - $INDEX_OF =& $this->index_of; |
|
| 149 | - $GENPOLY =& $this->genpoly; |
|
| 150 | - $NROOTS =& $this->nroots; |
|
| 151 | - $FCR =& $this->fcr; |
|
| 152 | - $PRIM =& $this->prim; |
|
| 153 | - $IPRIM =& $this->iprim; |
|
| 154 | - $PAD =& $this->pad; |
|
| 155 | - $A0 =& $NN; |
|
| 145 | + $MM = & $this->mm; |
|
| 146 | + $NN = & $this->nn; |
|
| 147 | + $ALPHA_TO = & $this->alpha_to; |
|
| 148 | + $INDEX_OF = & $this->index_of; |
|
| 149 | + $GENPOLY = & $this->genpoly; |
|
| 150 | + $NROOTS = & $this->nroots; |
|
| 151 | + $FCR = & $this->fcr; |
|
| 152 | + $PRIM = & $this->prim; |
|
| 153 | + $IPRIM = & $this->iprim; |
|
| 154 | + $PAD = & $this->pad; |
|
| 155 | + $A0 = & $NN; |
|
| 156 | 156 | |
| 157 | 157 | $parity = array_fill(0, $NROOTS, 0); |
| 158 | 158 | |
| 159 | - for($i=0; $i< ($NN-$NROOTS-$PAD); $i++) {
|
|
| 159 | + for ($i = 0; $i < ($NN - $NROOTS - $PAD); $i++) {
|
|
| 160 | 160 | |
| 161 | 161 | $feedback = $INDEX_OF[$data[$i] ^ $parity[0]]; |
| 162 | - if($feedback != $A0) {
|
|
| 162 | + if ($feedback != $A0) {
|
|
| 163 | 163 | // feedback term is non-zero |
| 164 | 164 | |
| 165 | 165 | // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must |
| 166 | 166 | // always be for the polynomials constructed by init_rs() |
| 167 | 167 | $feedback = $this->modnn($NN - $GENPOLY[$NROOTS] + $feedback); |
| 168 | 168 | |
| 169 | - for($j=1;$j<$NROOTS;$j++) {
|
|
| 170 | - $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS-$j])]; |
|
| 169 | + for ($j = 1; $j < $NROOTS; $j++) {
|
|
| 170 | + $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS - $j])]; |
|
| 171 | 171 | } |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | // Shift |
| 175 | 175 | array_shift($parity); |
| 176 | - if($feedback != $A0) {
|
|
| 176 | + if ($feedback != $A0) {
|
|
| 177 | 177 | array_push($parity, $ALPHA_TO[$this->modnn($feedback + $GENPOLY[0])]); |
| 178 | 178 | } else {
|
| 179 | 179 | array_push($parity, 0); |
@@ -191,13 +191,13 @@ discard block |
||
| 191 | 191 | //---------------------------------------------------------------------- |
| 192 | 192 | public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) |
| 193 | 193 | {
|
| 194 | - foreach(self::$items as $rs) {
|
|
| 195 | - if($rs->pad != $pad) continue; |
|
| 196 | - if($rs->nroots != $nroots) continue; |
|
| 197 | - if($rs->mm != $symsize) continue; |
|
| 198 | - if($rs->gfpoly != $gfpoly) continue; |
|
| 199 | - if($rs->fcr != $fcr) continue; |
|
| 200 | - if($rs->prim != $prim) continue; |
|
| 194 | + foreach (self::$items as $rs) {
|
|
| 195 | + if ($rs->pad != $pad) continue; |
|
| 196 | + if ($rs->nroots != $nroots) continue; |
|
| 197 | + if ($rs->mm != $symsize) continue; |
|
| 198 | + if ($rs->gfpoly != $gfpoly) continue; |
|
| 199 | + if ($rs->fcr != $fcr) continue; |
|
| 200 | + if ($rs->prim != $prim) continue; |
|
| 201 | 201 | |
| 202 | 202 | return $rs; |
| 203 | 203 | } |
@@ -1,16 +1,16 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | abstract class FeedItem { |
| 3 | - abstract function get_id(); |
|
| 4 | - abstract function get_date(); |
|
| 5 | - abstract function get_link(); |
|
| 6 | - abstract function get_title(); |
|
| 7 | - abstract function get_description(); |
|
| 8 | - abstract function get_content(); |
|
| 9 | - abstract function get_comments_url(); |
|
| 10 | - abstract function get_comments_count(); |
|
| 11 | - abstract function get_categories(); |
|
| 12 | - abstract function get_enclosures(); |
|
| 13 | - abstract function get_author(); |
|
| 14 | - abstract function get_language(); |
|
| 3 | + abstract function get_id(); |
|
| 4 | + abstract function get_date(); |
|
| 5 | + abstract function get_link(); |
|
| 6 | + abstract function get_title(); |
|
| 7 | + abstract function get_description(); |
|
| 8 | + abstract function get_content(); |
|
| 9 | + abstract function get_comments_url(); |
|
| 10 | + abstract function get_comments_count(); |
|
| 11 | + abstract function get_categories(); |
|
| 12 | + abstract function get_enclosures(); |
|
| 13 | + abstract function get_author(); |
|
| 14 | + abstract function get_language(); |
|
| 15 | 15 | } |
| 16 | 16 | |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | interface IHandler { |
| 3 | - public function csrf_ignore($method); |
|
| 4 | - public function before($method); |
|
| 5 | - public function after(); |
|
| 3 | + public function csrf_ignore($method); |
|
| 4 | + public function before($method); |
|
| 5 | + public function after(); |
|
| 6 | 6 | } |
@@ -2,59 +2,59 @@ |
||
| 2 | 2 | |
| 3 | 3 | abstract class Plugin { |
| 4 | 4 | |
| 5 | - const API_VERSION_COMPAT = 1; |
|
| 5 | + const API_VERSION_COMPAT = 1; |
|
| 6 | 6 | |
| 7 | - /** |
|
| 8 | - * @var PDO |
|
| 9 | - */ |
|
| 10 | - protected $pdo; |
|
| 7 | + /** |
|
| 8 | + * @var PDO |
|
| 9 | + */ |
|
| 10 | + protected $pdo; |
|
| 11 | 11 | |
| 12 | - abstract function init(PluginHost $host); |
|
| 12 | + abstract function init(PluginHost $host); |
|
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @return array(version, name, description, author, false) |
|
| 16 | - */ |
|
| 17 | - abstract function about(); |
|
| 14 | + /** |
|
| 15 | + * @return array(version, name, description, author, false) |
|
| 16 | + */ |
|
| 17 | + abstract function about(); |
|
| 18 | 18 | |
| 19 | - public function __construct() { |
|
| 20 | - $this->pdo = Db::pdo(); |
|
| 21 | - } |
|
| 19 | + public function __construct() { |
|
| 20 | + $this->pdo = Db::pdo(); |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - public function flags() { |
|
| 24 | - /* associative array, possible keys: |
|
| 23 | + public function flags() { |
|
| 24 | + /* associative array, possible keys: |
|
| 25 | 25 | needs_curl = boolean |
| 26 | 26 | */ |
| 27 | - return array(); |
|
| 28 | - } |
|
| 27 | + return array(); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - public function is_public_method() { |
|
| 31 | - return false; |
|
| 32 | - } |
|
| 30 | + public function is_public_method() { |
|
| 31 | + return false; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - public function get_js() { |
|
| 35 | - return ""; |
|
| 36 | - } |
|
| 34 | + public function get_js() { |
|
| 35 | + return ""; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - public function get_prefs_js() { |
|
| 39 | - return ""; |
|
| 40 | - } |
|
| 38 | + public function get_prefs_js() { |
|
| 39 | + return ""; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - public function api_version() { |
|
| 43 | - return Plugin::API_VERSION_COMPAT; |
|
| 44 | - } |
|
| 42 | + public function api_version() { |
|
| 43 | + return Plugin::API_VERSION_COMPAT; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - public function __($msgid) { |
|
| 47 | - return _dgettext(PluginHost::object_to_domain($this), $msgid); |
|
| 48 | - } |
|
| 46 | + public function __($msgid) { |
|
| 47 | + return _dgettext(PluginHost::object_to_domain($this), $msgid); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - public function _ngettext($singular, $plural, $number) { |
|
| 51 | - return _dngettext(PluginHost::object_to_domain($this), $singular, $plural, $number); |
|
| 52 | - } |
|
| 50 | + public function _ngettext($singular, $plural, $number) { |
|
| 51 | + return _dngettext(PluginHost::object_to_domain($this), $singular, $plural, $number); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - public function T_sprintf() { |
|
| 55 | - $args = func_get_args(); |
|
| 56 | - $msgid = array_shift($args); |
|
| 54 | + public function T_sprintf() { |
|
| 55 | + $args = func_get_args(); |
|
| 56 | + $msgid = array_shift($args); |
|
| 57 | 57 | |
| 58 | - return vsprintf($this->__($msgid), $args); |
|
| 59 | - } |
|
| 58 | + return vsprintf($this->__($msgid), $args); |
|
| 59 | + } |
|
| 60 | 60 | } |