@@ -230,7 +230,7 @@ |
||
230 | 230 | * @param string $user persistent identifier of the user who triggered the action |
231 | 231 | * @param string $category type of modification, from the fixed vocabulary: "NEW", "OWN", "MOD", "DEL" |
232 | 232 | * @param string $message message to log into the audit log |
233 | - * @return boolean TRUE if successful. Will terminate script execution on failure. |
|
233 | + * @return boolean|null TRUE if successful. Will terminate script execution on failure. |
|
234 | 234 | */ |
235 | 235 | public static function writeAudit($user, $category, $message) { |
236 | 236 | switch ($category) { |
@@ -73,12 +73,12 @@ discard block |
||
73 | 73 | |
74 | 74 | |
75 | 75 | if (CAT::$RELEASE_VERSION) { |
76 | - $temp_version = "CAT-".CAT::$VERSION_MAJOR.".".CAT::$VERSION_MINOR; |
|
76 | + $temp_version = "CAT-" . CAT::$VERSION_MAJOR . "." . CAT::$VERSION_MINOR; |
|
77 | 77 | if (CAT::$VERSION_PATCH != 0) |
78 | - $temp_version .= ".".CAT::$VERSION_PATCH; |
|
78 | + $temp_version .= "." . CAT::$VERSION_PATCH; |
|
79 | 79 | if (CAT::$VERSION_EXTRA != "") |
80 | - $temp_version .= "-".CAT::$VERSION_EXTRA; |
|
81 | - CAT::$VERSION = sprintf(_("Release %s"), $temp_version ); |
|
80 | + $temp_version .= "-" . CAT::$VERSION_EXTRA; |
|
81 | + CAT::$VERSION = sprintf(_("Release %s"), $temp_version); |
|
82 | 82 | } |
83 | 83 | else |
84 | 84 | CAT::$VERSION = _("Unreleased SVN Revision"); |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | * gets the language setting in CAT |
192 | 192 | */ |
193 | 193 | static public function get_lang() { |
194 | - if(self::$LANG === '') |
|
194 | + if (self::$LANG === '') |
|
195 | 195 | list(self::$LANG, $xx) = self::set_lang(); |
196 | 196 | return self::$LANG; |
197 | 197 | } |
@@ -239,9 +239,9 @@ discard block |
||
239 | 239 | case "MOD": // modified existing object |
240 | 240 | case "DEL": // deleted an object |
241 | 241 | ob_start(); |
242 | - printf("%-015s",microtime(TRUE)); |
|
242 | + printf("%-015s", microtime(TRUE)); |
|
243 | 243 | print " ($category) "; |
244 | - print_r(" ".$user.": ".$message."\n"); |
|
244 | + print_r(" " . $user . ": " . $message . "\n"); |
|
245 | 245 | $output = ob_get_clean(); |
246 | 246 | if (Config::$PATHS['logdir']) { |
247 | 247 | $f = fopen(Config::$PATHS['logdir'] . "/audit-activity.log", "a"); |
@@ -268,8 +268,8 @@ discard block |
||
268 | 268 | $logtext1 = preg_replace("/[\n\r]/", "", $query); |
269 | 269 | $logtext = preg_replace("/ +/", " ", $logtext1); |
270 | 270 | ob_start(); |
271 | - printf("%-015s",microtime(TRUE)); |
|
272 | - print(" ".$logtext."\n"); |
|
271 | + printf("%-015s", microtime(TRUE)); |
|
272 | + print(" " . $logtext . "\n"); |
|
273 | 273 | $output = ob_get_clean(); |
274 | 274 | if (Config::$PATHS['logdir']) { |
275 | 275 | $f = fopen(Config::$PATHS['logdir'] . "/audit-SQL.log", "a"); |
@@ -87,6 +87,7 @@ discard block |
||
87 | 87 | /** |
88 | 88 | * executes a query and triggers logging to the SQL audit log if it's not a SELECT |
89 | 89 | * @param string $querystring the query to be executed |
90 | + * @param string $db |
|
90 | 91 | * @return mixed the query result as mysqli_result object; or TRUE on non-return-value statements |
91 | 92 | */ |
92 | 93 | public static function exec($db, $querystring) { |
@@ -134,6 +135,8 @@ discard block |
||
134 | 135 | /** |
135 | 136 | * Checks if a raw data pointer is public data (return value FALSE) or if |
136 | 137 | * yes who the authorised admins to view it are (return array of user IDs) |
138 | + * @param string $table |
|
139 | + * @param string $row |
|
137 | 140 | */ |
138 | 141 | public static function isDataRestricted($table, $row) { |
139 | 142 | if ($table != "institution_option" && $table != "profile_option" && $table != "federation_option") |
@@ -175,6 +178,7 @@ discard block |
||
175 | 178 | |
176 | 179 | /** |
177 | 180 | * Retrieves the last auto-id of an INSERT. Needs to be called immediately after the corresponding exec() call |
181 | + * @param string $db |
|
178 | 182 | * @return int the last autoincrement-ID |
179 | 183 | */ |
180 | 184 | public static function lastID($db) { |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * named the same as device_id. The second option takes precedence. |
173 | 173 | * |
174 | 174 | * @param string $source_name The source file name |
175 | - * @param string $output_name The destination file name |
|
175 | + * @param integer $output_name The destination file name |
|
176 | 176 | * |
177 | 177 | * @return bool result of the copy operation |
178 | 178 | * @final not to be redefined |
@@ -216,8 +216,7 @@ discard block |
||
216 | 216 | * named the same as device_id. The second option takes precedence. |
217 | 217 | * |
218 | 218 | * @param string $source_name The source file name |
219 | - * @param string $output_name The destination file name |
|
220 | - * @param int $use_win_cp Set Windows charset if non-zero |
|
219 | + * @param integer $output_name The destination file name |
|
221 | 220 | * |
222 | 221 | * @final not to be redefined |
223 | 222 | */ |
@@ -262,8 +261,6 @@ discard block |
||
262 | 261 | * The second optional parameter, if nonzero, should be the character set understood by iconv |
263 | 262 | * This is required by the Windows installer and is expected to go away in the future. |
264 | 263 | * |
265 | - * @param string $source_name The source file name |
|
266 | - * @param int $use_win_cp Set Windows charset if non-zero |
|
267 | 264 | * |
268 | 265 | * @final not to be redefined |
269 | 266 | */ |
@@ -63,9 +63,9 @@ discard block |
||
63 | 63 | */ |
64 | 64 | |
65 | 65 | public function __construct() { |
66 | - $this->supportedEapMethods = [EAP::$TLS, EAP::$PEAP_MSCHAP2, EAP::$TTLS_PAP]; |
|
67 | - debug(4,"This device supports the following EAP methods: "); |
|
68 | - debug(4,$this->supportedEapMethods); |
|
66 | + $this->supportedEapMethods = [EAP::$TLS, EAP::$PEAP_MSCHAP2, EAP::$TTLS_PAP]; |
|
67 | + debug(4, "This device supports the following EAP methods: "); |
|
68 | + debug(4, $this->supportedEapMethods); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | |
@@ -88,50 +88,50 @@ discard block |
||
88 | 88 | * @final not to be redefined |
89 | 89 | */ |
90 | 90 | final public function setup(Profile $profile) { |
91 | - debug(4,"module setup start\n"); |
|
92 | - if(! $profile instanceof Profile) { |
|
93 | - debug(2,"No profile has been set\n"); |
|
91 | + debug(4, "module setup start\n"); |
|
92 | + if (!$profile instanceof Profile) { |
|
93 | + debug(2, "No profile has been set\n"); |
|
94 | 94 | error("No profile has been set"); |
95 | 95 | exit; |
96 | 96 | } |
97 | 97 | $this->attributes = $this->getProfileAttributes($profile); |
98 | - if(! $this->selected_eap) { |
|
98 | + if (!$this->selected_eap) { |
|
99 | 99 | error("No EAP type specified."); |
100 | 100 | exit; |
101 | 101 | } |
102 | 102 | // create temporary directory, its full path will be saved in $this->FPATH; |
103 | 103 | $T = createTemporaryDirectory('installer'); |
104 | 104 | $this->FPATH = $T['dir']; |
105 | - mkdir($T['dir'].'/tmp'); |
|
106 | - chdir($T['dir'].'/tmp'); |
|
105 | + mkdir($T['dir'] . '/tmp'); |
|
106 | + chdir($T['dir'] . '/tmp'); |
|
107 | 107 | $CAs = []; |
108 | - if(isset($this->attributes['eap:ca_file'])) { |
|
108 | + if (isset($this->attributes['eap:ca_file'])) { |
|
109 | 109 | foreach ($this->attributes['eap:ca_file'] as $ca) { |
110 | - if($c = X509::processCertificate($ca)) |
|
110 | + if ($c = X509::processCertificate($ca)) |
|
111 | 111 | $CAs[] = $c; |
112 | 112 | } |
113 | - $this->attributes['internal:CAs'][0]=$CAs; |
|
113 | + $this->attributes['internal:CAs'][0] = $CAs; |
|
114 | 114 | } |
115 | - if(isset($this->attributes['support:info_file'])) { |
|
115 | + if (isset($this->attributes['support:info_file'])) { |
|
116 | 116 | $this->attributes['internal:info_file'][0] = |
117 | 117 | $this->saveInfoFile($this->attributes['support:info_file'][0]); |
118 | 118 | } |
119 | - if(isset($this->attributes['general:logo_file'])) |
|
119 | + if (isset($this->attributes['general:logo_file'])) |
|
120 | 120 | $this->attributes['internal:logo_file'] = |
121 | 121 | $this->saveLogoFile($this->attributes['general:logo_file']); |
122 | - $this->attributes['internal:SSID'] = $this->getSSIDs()['add'];; |
|
123 | - $this->attributes['internal:remove_SSID'] = $this->getSSIDs()['del'];; |
|
122 | + $this->attributes['internal:SSID'] = $this->getSSIDs()['add']; ; |
|
123 | + $this->attributes['internal:remove_SSID'] = $this->getSSIDs()['del']; ; |
|
124 | 124 | $this->attributes['internal:consortia'] = $this->getConsortia(); |
125 | 125 | $this->lang_index = CAT::get_lang(); |
126 | 126 | // phpMD says the below is not needed. Wow. |
127 | 127 | // $idp = new IdP($profile->institution); |
128 | 128 | $olddomain = CAT::set_locale("core"); |
129 | - $this->support_email_substitute = sprintf(_("your local %s support"),Config::$CONSORTIUM['name']); |
|
130 | - $this->support_url_substitute = sprintf(_("your local %s support page"),Config::$CONSORTIUM['name']); |
|
129 | + $this->support_email_substitute = sprintf(_("your local %s support"), Config::$CONSORTIUM['name']); |
|
130 | + $this->support_url_substitute = sprintf(_("your local %s support page"), Config::$CONSORTIUM['name']); |
|
131 | 131 | CAT::set_locale($olddomain); |
132 | 132 | |
133 | - if($this->signer && $this->options['sign']) |
|
134 | - $this->sign = CAT::$root . '/signer/'. $this->signer; |
|
133 | + if ($this->signer && $this->options['sign']) |
|
134 | + $this->sign = CAT::$root . '/signer/' . $this->signer; |
|
135 | 135 | $this->installerBasename = $this->getInstallerBasename(); |
136 | 136 | } |
137 | 137 | |
@@ -143,10 +143,10 @@ discard block |
||
143 | 143 | */ |
144 | 144 | public function getPreferredEapType($eap_array) { |
145 | 145 | foreach ($eap_array as $eap) { |
146 | - if(in_array($eap,$this->supportedEapMethods)) { |
|
146 | + if (in_array($eap, $this->supportedEapMethods)) { |
|
147 | 147 | $this->selected_eap = $eap; |
148 | - debug(4,"Selected EAP:"); |
|
149 | - debug(4,$eap); |
|
148 | + debug(4, "Selected EAP:"); |
|
149 | + debug(4, $eap); |
|
150 | 150 | return($eap); |
151 | 151 | } |
152 | 152 | } |
@@ -178,22 +178,22 @@ discard block |
||
178 | 178 | * @final not to be redefined |
179 | 179 | */ |
180 | 180 | final protected function copyFile($source_name, $output_name = 0) { |
181 | - if ( $output_name === 0) |
|
181 | + if ($output_name === 0) |
|
182 | 182 | $output_name = $source_name; |
183 | 183 | |
184 | - debug(4,"fileCopy($source_name, $output_name)\n"); |
|
185 | - if(is_file($this->module_path.'/Files/'.$this->device_id.'/'.$source_name)) |
|
186 | - $source = $this->module_path.'/Files/'.$this->device_id.'/'.$source_name; |
|
187 | - elseif(is_file($this->module_path.'/Files/'.$source_name)) |
|
188 | - $source = $this->module_path.'/Files/'.$source_name; |
|
184 | + debug(4, "fileCopy($source_name, $output_name)\n"); |
|
185 | + if (is_file($this->module_path . '/Files/' . $this->device_id . '/' . $source_name)) |
|
186 | + $source = $this->module_path . '/Files/' . $this->device_id . '/' . $source_name; |
|
187 | + elseif (is_file($this->module_path . '/Files/' . $source_name)) |
|
188 | + $source = $this->module_path . '/Files/' . $source_name; |
|
189 | 189 | else { |
190 | - debug(2,"fileCopy:reqested file $source_name does not exist\n"); |
|
190 | + debug(2, "fileCopy:reqested file $source_name does not exist\n"); |
|
191 | 191 | return(FALSE); |
192 | 192 | } |
193 | - debug(4,"Copying $source to $output_name\n"); |
|
194 | - $result = copy($source,"$output_name"); |
|
195 | - if(! $result ) |
|
196 | - debug(2,"fileCopy($source_name, $output_name) failed\n"); |
|
193 | + debug(4, "Copying $source to $output_name\n"); |
|
194 | + $result = copy($source, "$output_name"); |
|
195 | + if (!$result) |
|
196 | + debug(2, "fileCopy($source_name, $output_name) failed\n"); |
|
197 | 197 | return($result); |
198 | 198 | } |
199 | 199 | |
@@ -223,31 +223,31 @@ discard block |
||
223 | 223 | */ |
224 | 224 | |
225 | 225 | final protected function translateFile($source_name, $output_name = 0, $encoding = 0) { |
226 | - if(Config::$NSIS_VERSION >= 3) |
|
226 | + if (Config::$NSIS_VERSION >= 3) |
|
227 | 227 | $encoding = 0; |
228 | - if ( $output_name === 0) |
|
228 | + if ($output_name === 0) |
|
229 | 229 | $output_name = $source_name; |
230 | 230 | |
231 | - debug(4,"translateFile($source_name, $output_name, $encoding)\n"); |
|
231 | + debug(4, "translateFile($source_name, $output_name, $encoding)\n"); |
|
232 | 232 | ob_start(); |
233 | - debug(4,$this->module_path.'/Files/'.$this->device_id.'/'.$source_name."\n"); |
|
234 | - if(is_file($this->module_path.'/Files/'.$this->device_id.'/'.$source_name)) |
|
235 | - $source = $this->module_path.'/Files/'.$this->device_id.'/'.$source_name; |
|
236 | - elseif(is_file($this->module_path.'/Files/'.$source_name)) |
|
237 | - $source = $this->module_path.'/Files/'.$source_name; |
|
233 | + debug(4, $this->module_path . '/Files/' . $this->device_id . '/' . $source_name . "\n"); |
|
234 | + if (is_file($this->module_path . '/Files/' . $this->device_id . '/' . $source_name)) |
|
235 | + $source = $this->module_path . '/Files/' . $this->device_id . '/' . $source_name; |
|
236 | + elseif (is_file($this->module_path . '/Files/' . $source_name)) |
|
237 | + $source = $this->module_path . '/Files/' . $source_name; |
|
238 | 238 | include($source); |
239 | 239 | $output = ob_get_clean(); |
240 | - if($encoding) { |
|
241 | - $output_c = iconv('UTF-8',$encoding.'//TRANSLIT',$output); |
|
242 | - if($output_c) |
|
240 | + if ($encoding) { |
|
241 | + $output_c = iconv('UTF-8', $encoding . '//TRANSLIT', $output); |
|
242 | + if ($output_c) |
|
243 | 243 | $output = $output_c; |
244 | 244 | } |
245 | - $f = fopen("$output_name","w"); |
|
246 | - if(! $f) |
|
247 | - debug(2,"translateFile($source, $output_name, $encoding) failed\n"); |
|
248 | - fwrite($f,$output); |
|
245 | + $f = fopen("$output_name", "w"); |
|
246 | + if (!$f) |
|
247 | + debug(2, "translateFile($source, $output_name, $encoding) failed\n"); |
|
248 | + fwrite($f, $output); |
|
249 | 249 | fclose($f); |
250 | - debug(4,"translateFile($source, $output_name, $encoding) end\n"); |
|
250 | + debug(4, "translateFile($source, $output_name, $encoding) end\n"); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | |
@@ -268,17 +268,17 @@ discard block |
||
268 | 268 | * @final not to be redefined |
269 | 269 | */ |
270 | 270 | |
271 | - final protected function translateString($source_string,$encoding = 0) { |
|
272 | - if(Config::$NSIS_VERSION >= 3) |
|
271 | + final protected function translateString($source_string, $encoding = 0) { |
|
272 | + if (Config::$NSIS_VERSION >= 3) |
|
273 | 273 | $encoding = 0; |
274 | - if($encoding) |
|
275 | - $output_c = iconv('UTF-8',$encoding.'//TRANSLIT',$source_string); |
|
274 | + if ($encoding) |
|
275 | + $output_c = iconv('UTF-8', $encoding . '//TRANSLIT', $source_string); |
|
276 | 276 | else |
277 | 277 | $output_c = $source_string; |
278 | - if($output_c) |
|
279 | - $source_string = str_replace('"','$\\"',$output_c); |
|
278 | + if ($output_c) |
|
279 | + $source_string = str_replace('"', '$\\"', $output_c); |
|
280 | 280 | else |
281 | - debug(2,"Failed to convert string $source_string\n"); |
|
281 | + debug(2, "Failed to convert string $source_string\n"); |
|
282 | 282 | return $source_string; |
283 | 283 | } |
284 | 284 | |
@@ -295,19 +295,19 @@ discard block |
||
295 | 295 | * root is set to 1 for the CA roor certicicate and 0 otherwise |
296 | 296 | */ |
297 | 297 | final protected function saveCertificateFiles($format) { |
298 | - if($format == 'der' || $format == 'pam') { |
|
298 | + if ($format == 'der' || $format == 'pam') { |
|
299 | 299 | $i = 0; |
300 | 300 | $CA_files = []; |
301 | 301 | $ca_array = $this->attributes['internal:CAs'][0]; |
302 | - if(! $ca_array) |
|
302 | + if (!$ca_array) |
|
303 | 303 | return(FALSE); |
304 | 304 | foreach ($ca_array as $CA) { |
305 | - $f = fopen("cert-$i.crt","w"); |
|
306 | - if(! $f) die("problem opening the file\n"); |
|
307 | - if($format == "pem") |
|
308 | - fwrite($f,$CA['pem']); |
|
305 | + $f = fopen("cert-$i.crt", "w"); |
|
306 | + if (!$f) die("problem opening the file\n"); |
|
307 | + if ($format == "pem") |
|
308 | + fwrite($f, $CA['pem']); |
|
309 | 309 | else |
310 | - fwrite($f,$CA['der']); |
|
310 | + fwrite($f, $CA['der']); |
|
311 | 311 | fclose($f); |
312 | 312 | $C = []; |
313 | 313 | $C['file'] = "cert-$i.crt"; |
@@ -334,42 +334,42 @@ discard block |
||
334 | 334 | */ |
335 | 335 | private function getInstallerBasename() { |
336 | 336 | $replace_pattern = '/[ ()\/\'"]+/'; |
337 | - debug(4,"getInstallerBasename1:".$this->attributes['general:instname'][0]."\n"); |
|
337 | + debug(4, "getInstallerBasename1:" . $this->attributes['general:instname'][0] . "\n"); |
|
338 | 338 | $inst = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', $this->attributes['general:instname'][0])); |
339 | - debug(4,"getInstallerBasename2:$inst\n"); |
|
340 | - $Inst_a = explode('_',$inst); |
|
341 | - if(count($Inst_a) > 2) { |
|
339 | + debug(4, "getInstallerBasename2:$inst\n"); |
|
340 | + $Inst_a = explode('_', $inst); |
|
341 | + if (count($Inst_a) > 2) { |
|
342 | 342 | $inst = ''; |
343 | - foreach($Inst_a as $i) |
|
343 | + foreach ($Inst_a as $i) |
|
344 | 344 | $inst .= $i[0]; |
345 | 345 | } |
346 | 346 | $c_name = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', Config::$CONSORTIUM['name'])); |
347 | - if($this->attributes['internal:profile_count'][0] > 1) { |
|
348 | - if(!empty($this->attributes['profile:name']) && ! empty($this->attributes['profile:name'][0])) { |
|
347 | + if ($this->attributes['internal:profile_count'][0] > 1) { |
|
348 | + if (!empty($this->attributes['profile:name']) && !empty($this->attributes['profile:name'][0])) { |
|
349 | 349 | $prof = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', $this->attributes['profile:name'][0])); |
350 | - $prof = preg_replace('/_+$/','',$prof); |
|
351 | - return $c_name. '-'. $this->getDeviceId() . $inst .'-'. $prof; |
|
350 | + $prof = preg_replace('/_+$/', '', $prof); |
|
351 | + return $c_name . '-' . $this->getDeviceId() . $inst . '-' . $prof; |
|
352 | 352 | } |
353 | 353 | } |
354 | - return $c_name. '-'. $this->getDeviceId() . $inst; |
|
354 | + return $c_name . '-' . $this->getDeviceId() . $inst; |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | private function getDeviceId() { |
358 | 358 | $d_id = $this->device_id; |
359 | - if(isset($this->options['device_id'])) |
|
359 | + if (isset($this->options['device_id'])) |
|
360 | 360 | $d_id = $this->options['device_id']; |
361 | - if($d_id !== '') |
|
361 | + if ($d_id !== '') |
|
362 | 362 | $d_id .= '-'; |
363 | 363 | return $d_id; |
364 | 364 | } |
365 | 365 | |
366 | 366 | |
367 | 367 | private function getSSIDs() { |
368 | - $S['add']=[]; |
|
369 | - $S['del']=[]; |
|
368 | + $S['add'] = []; |
|
369 | + $S['del'] = []; |
|
370 | 370 | if (isset(Config::$CONSORTIUM['ssid'])) { |
371 | 371 | foreach (Config::$CONSORTIUM['ssid'] as $ssid) { |
372 | - if(isset(Config::$CONSORTIUM['tkipsupport']) && Config::$CONSORTIUM['tkipsupport'] == TRUE) |
|
372 | + if (isset(Config::$CONSORTIUM['tkipsupport']) && Config::$CONSORTIUM['tkipsupport'] == TRUE) |
|
373 | 373 | $S['add'][$ssid] = 'TKIP'; |
374 | 374 | else { |
375 | 375 | $S['add'][$ssid] = 'AES'; |
@@ -377,20 +377,20 @@ discard block |
||
377 | 377 | } |
378 | 378 | } |
379 | 379 | } |
380 | - if(isset($this->attributes['media:SSID'])) { |
|
380 | + if (isset($this->attributes['media:SSID'])) { |
|
381 | 381 | $SSID = $this->attributes['media:SSID']; |
382 | 382 | |
383 | - foreach($SSID as $ssid) |
|
383 | + foreach ($SSID as $ssid) |
|
384 | 384 | $S['add'][$ssid] = 'AES'; |
385 | 385 | } |
386 | - if(isset($this->attributes['media:SSID_with_legacy'])) { |
|
386 | + if (isset($this->attributes['media:SSID_with_legacy'])) { |
|
387 | 387 | $SSID = $this->attributes['media:SSID_with_legacy']; |
388 | - foreach($SSID as $ssid) |
|
388 | + foreach ($SSID as $ssid) |
|
389 | 389 | $S['add'][$ssid] = 'TKIP'; |
390 | 390 | } |
391 | - if(isset($this->attributes['media:remove_SSID'])) { |
|
391 | + if (isset($this->attributes['media:remove_SSID'])) { |
|
392 | 392 | $SSID = $this->attributes['media:remove_SSID']; |
393 | - foreach($SSID as $ssid) |
|
393 | + foreach ($SSID as $ssid) |
|
394 | 394 | $S['del'][$ssid] = 'DEL'; |
395 | 395 | } |
396 | 396 | return $S; |
@@ -416,25 +416,25 @@ discard block |
||
416 | 416 | ]; |
417 | 417 | |
418 | 418 | private function saveLogoFile($Logos) { |
419 | - $i=0; |
|
420 | - $returnarray= []; |
|
419 | + $i = 0; |
|
420 | + $returnarray = []; |
|
421 | 421 | foreach ($Logos as $blob) { |
422 | 422 | $finfo = new finfo(FILEINFO_MIME_TYPE); |
423 | 423 | $mime = $finfo->buffer($blob); |
424 | - if(preg_match('/^image\/(.*)/',$mime,$m)) |
|
424 | + if (preg_match('/^image\/(.*)/', $mime, $m)) |
|
425 | 425 | $ext = $m[1]; |
426 | 426 | else |
427 | 427 | $ext = 'unsupported'; |
428 | - debug(4,"saveLogoFile: $mime : $ext\n"); |
|
429 | - $f_name = 'logo-'.$i.'.'.$ext; |
|
430 | - $f = fopen($f_name,"w"); |
|
431 | - if(! $f) { |
|
432 | - debug(2,"saveLogoFile failed for: $f_name\n"); |
|
428 | + debug(4, "saveLogoFile: $mime : $ext\n"); |
|
429 | + $f_name = 'logo-' . $i . '.' . $ext; |
|
430 | + $f = fopen($f_name, "w"); |
|
431 | + if (!$f) { |
|
432 | + debug(2, "saveLogoFile failed for: $f_name\n"); |
|
433 | 433 | die("problem opening the file\n"); |
434 | 434 | } |
435 | - fwrite($f,$blob); |
|
435 | + fwrite($f, $blob); |
|
436 | 436 | fclose($f); |
437 | - $returnarray[]= ['name'=>$f_name,'mime'=>$ext]; |
|
437 | + $returnarray[] = ['name'=>$f_name, 'mime'=>$ext]; |
|
438 | 438 | $i++; |
439 | 439 | } |
440 | 440 | return($returnarray); |
@@ -445,17 +445,17 @@ discard block |
||
445 | 445 | $finfo = new finfo(FILEINFO_MIME_TYPE); |
446 | 446 | $mime = $finfo->buffer($blob); |
447 | 447 | $ext = isset($this->mime_extensions[$mime]) ? $this->mime_extensions[$mime] : 'usupported'; |
448 | - debug(4,"saveInfoFile: $mime : $ext\n"); |
|
449 | - $f = fopen('local-info.'.$ext,"w"); |
|
450 | - if(! $f) die("problem opening the file\n"); |
|
451 | - fwrite($f,$blob); |
|
448 | + debug(4, "saveInfoFile: $mime : $ext\n"); |
|
449 | + $f = fopen('local-info.' . $ext, "w"); |
|
450 | + if (!$f) die("problem opening the file\n"); |
|
451 | + fwrite($f, $blob); |
|
452 | 452 | fclose($f); |
453 | - return(['name'=>'local-info.'.$ext,'mime'=>$ext]); |
|
453 | + return(['name'=>'local-info.' . $ext, 'mime'=>$ext]); |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | private function getProfileAttributes(Profile $profile) { |
457 | 457 | $eaps = $profile->getEapMethodsinOrderOfPreference(1); |
458 | - if($eap = $this->getPreferredEapType($eaps)) { |
|
458 | + if ($eap = $this->getPreferredEapType($eaps)) { |
|
459 | 459 | $a = $profile->getCollapsedAttributes($eap); |
460 | 460 | $a['eap'] = $eap; |
461 | 461 | $a['all_eaps'] = $eaps; |
@@ -476,8 +476,8 @@ discard block |
||
476 | 476 | ob_start(); |
477 | 477 | print_r($this->attributes); |
478 | 478 | $output = ob_get_clean(); |
479 | - $f = fopen($file,"w"); |
|
480 | - fwrite($f,$output); |
|
479 | + $f = fopen($file, "w"); |
|
480 | + fwrite($f, $output); |
|
481 | 481 | fclose($f); |
482 | 482 | } |
483 | 483 | /** |
@@ -661,7 +661,7 @@ |
||
661 | 661 | * This function retrieves the federation attributes. If called with the optional parameter, only attribute values for the attribute |
662 | 662 | * name in $option_name are retrieved; otherwise, all attributes are retrieved. |
663 | 663 | * |
664 | - * @param string $option_name optionally, the name of the attribute that is to be retrieved |
|
664 | + * @param integer $option_name optionally, the name of the attribute that is to be retrieved |
|
665 | 665 | * @return array of arrays of attributes which were set for this IdP |
666 | 666 | */ |
667 | 667 | public function getAttributes($option_name = 0) { |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | |
75 | 75 | $retstring = ""; |
76 | 76 | if (!$astablerows) |
77 | - $retstring .= "<federation id='" . ( $federationid == NULL ? "ALL" : $federationid ) . "' ts='$timestamp'>\n"; |
|
77 | + $retstring .= "<federation id='" . ($federationid == NULL ? "ALL" : $federationid) . "' ts='$timestamp'>\n"; |
|
78 | 78 | |
79 | 79 | foreach (Devices::listDevices() as $index => $device_array) { |
80 | 80 | $query = "SELECT SUM(downloads_admin) AS admin, SUM(downloads_user) AS user FROM downloads, profile, institution WHERE device_id = '$index' AND downloads.profile_id = profile.profile_id AND profile.inst_id = institution.inst_id "; |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | if ($astablerows) |
88 | 88 | $retstring .= "<td>" . $device_array['display'] . "</td>"; |
89 | 89 | $retstring .= ($astablerows ? "<td>" : " <downloads group='admin'>"); |
90 | - $retstring .= ( $a->admin === NULL ? "0" : $a->admin); |
|
90 | + $retstring .= ($a->admin === NULL ? "0" : $a->admin); |
|
91 | 91 | $retstring .= ($astablerows ? "</td><td>" : "</downloads>\n <downloads group='user'>"); |
92 | - $retstring .= ( $a->user === NULL ? "0" : $a->user); |
|
92 | + $retstring .= ($a->user === NULL ? "0" : $a->user); |
|
93 | 93 | $retstring .= ($astablerows ? "</td>" : "</downloads>\n"); |
94 | 94 | $gross_admin = $gross_admin + $a->admin; |
95 | 95 | $gross_user = $gross_user + $a->user; |
@@ -32,6 +32,7 @@ discard block |
||
32 | 32 | /** |
33 | 33 | * write debug messages to the log |
34 | 34 | * |
35 | + * @param integer $level |
|
35 | 36 | */ |
36 | 37 | function debug($level, $t) { |
37 | 38 | if (Config::$DEBUG_LEVEL >= $level) { |
@@ -130,7 +131,7 @@ discard block |
||
130 | 131 | * generates a UUID |
131 | 132 | * |
132 | 133 | * @param string $prefix an extra prefix to set before the UUID |
133 | - * @return UUID (possibly prefixed) |
|
134 | + * @return string (possibly prefixed) |
|
134 | 135 | */ |
135 | 136 | function uuid($prefix = '', $deterministic_source = NULL) { |
136 | 137 | if ($deterministic_source === NULL) |
@@ -177,65 +177,65 @@ |
||
177 | 177 | * @param $fail (default true) decides if a creation failure should cause an error |
178 | 178 | * @return - the tupple full directory path, directory name |
179 | 179 | */ |
180 | -function createTemporaryDirectory($purpose = 'installer',$fail = 1) { |
|
181 | - $name = md5(time().rand()); |
|
182 | - switch($purpose) { |
|
180 | +function createTemporaryDirectory($purpose = 'installer', $fail = 1) { |
|
181 | + $name = md5(time() . rand()); |
|
182 | + switch ($purpose) { |
|
183 | 183 | case 'installer': |
184 | - $path = CAT::$root.'/var/installer_cache'; |
|
184 | + $path = CAT::$root . '/var/installer_cache'; |
|
185 | 185 | break; |
186 | 186 | case 'logo': |
187 | - $path = CAT::$root.'/web/downloads/logos'; |
|
187 | + $path = CAT::$root . '/web/downloads/logos'; |
|
188 | 188 | break; |
189 | 189 | case 'test': |
190 | - $path = CAT::$root.'/var/tmp'; |
|
190 | + $path = CAT::$root . '/var/tmp'; |
|
191 | 191 | break; |
192 | 192 | default: |
193 | 193 | error("unable to create temporary directory for unknown purpose: $purpose\n"); |
194 | 194 | exit; |
195 | 195 | } |
196 | - $tmp_dir = $path .'/'. $name; |
|
197 | - debug(4,"temp dir: $purpose : $tmp_dir\n"); |
|
198 | - if(! mkdir($tmp_dir,0700, true)) { |
|
199 | - if($fail) { |
|
196 | + $tmp_dir = $path . '/' . $name; |
|
197 | + debug(4, "temp dir: $purpose : $tmp_dir\n"); |
|
198 | + if (!mkdir($tmp_dir, 0700, true)) { |
|
199 | + if ($fail) { |
|
200 | 200 | error("unable to create temporary directory: $tmp_dir\n"); |
201 | 201 | exit; |
202 | - } else { |
|
202 | + } else { |
|
203 | 203 | debug(4, "Directory creation failed for $tmp_dir\n"); |
204 | - return ['base'=>$path,'dir'=>'',$name=>'']; |
|
204 | + return ['base'=>$path, 'dir'=>'', $name=>'']; |
|
205 | 205 | } |
206 | 206 | } else |
207 | 207 | debug(4, "Directory created: $tmp_dir\n"); |
208 | - return ['base'=>$path,'dir'=>$tmp_dir,'name'=>$name]; |
|
208 | + return ['base'=>$path, 'dir'=>$tmp_dir, 'name'=>$name]; |
|
209 | 209 | } |
210 | 210 | |
211 | -function png_inject_consortium_logo ($inputpngstring, $symbolsize = 12, $marginsymbols = 4) { |
|
211 | +function png_inject_consortium_logo($inputpngstring, $symbolsize = 12, $marginsymbols = 4) { |
|
212 | 212 | $inputgd = imagecreatefromstring($inputpngstring); |
213 | 213 | |
214 | - debug(4,"Consortium logo is at: ".CAT::$root."/web/resources/images/consortium_logo_large.png"); |
|
215 | - $logogd = imagecreatefrompng(CAT::$root."/web/resources/images/consortium_logo_large.png"); |
|
214 | + debug(4, "Consortium logo is at: " . CAT::$root . "/web/resources/images/consortium_logo_large.png"); |
|
215 | + $logogd = imagecreatefrompng(CAT::$root . "/web/resources/images/consortium_logo_large.png"); |
|
216 | 216 | |
217 | - $sizeinput = [imagesx($inputgd),imagesy($inputgd)]; |
|
218 | - $sizelogo = [imagesx($logogd),imagesy($logogd)]; |
|
217 | + $sizeinput = [imagesx($inputgd), imagesy($inputgd)]; |
|
218 | + $sizelogo = [imagesx($logogd), imagesy($logogd)]; |
|
219 | 219 | // Q level QR-codes can sustain 25% "damage" |
220 | 220 | // make our logo cover approx 15% of area to be sure; mind that there's a $symbolsize * $marginsymbols pixel white border around each edge |
221 | - $totalpixels = ($sizeinput[0] - $symbolsize*$marginsymbols) * ($sizeinput[1] - $symbolsize*$marginsymbols); |
|
221 | + $totalpixels = ($sizeinput[0] - $symbolsize * $marginsymbols) * ($sizeinput[1] - $symbolsize * $marginsymbols); |
|
222 | 222 | $totallogopixels = ($sizelogo[0]) * ($sizelogo[1]); |
223 | 223 | $maxoccupy = $totalpixels * 0.04; |
224 | 224 | // find out how much we have to scale down logo to reach 10% QR estate |
225 | 225 | $scale = sqrt($maxoccupy / $totallogopixels); |
226 | - debug(4,"Scaling info: $scale, $maxoccupy, $totallogopixels\n"); |
|
226 | + debug(4, "Scaling info: $scale, $maxoccupy, $totallogopixels\n"); |
|
227 | 227 | // determine final pixel size - round to multitude of $symbolsize to match exact symbol boundary |
228 | 228 | $targetwidth = $symbolsize * round($sizelogo[0] * $scale / $symbolsize); |
229 | 229 | $targetheight = $symbolsize * round($sizelogo[1] * $scale / $symbolsize); |
230 | 230 | // paint white below the logo, in case it has transparencies (looks bad) |
231 | 231 | // have one symbol in each direction extra white space |
232 | - $whiteimage = imagecreate($targetwidth+2*$symbolsize, $targetheight+2*$symbolsize); |
|
233 | - imagecolorallocate($whiteimage, 255,255,255); |
|
232 | + $whiteimage = imagecreate($targetwidth + 2 * $symbolsize, $targetheight + 2 * $symbolsize); |
|
233 | + imagecolorallocate($whiteimage, 255, 255, 255); |
|
234 | 234 | // also make sure the initial placement is a multitude of 12; otherwise "two half" symbols might be affected |
235 | - $targetplacementx = $symbolsize * round(($sizeinput[0] / 2 - ($targetwidth - $symbolsize) / 2)/$symbolsize); |
|
236 | - $targetplacementy = $symbolsize * round(($sizeinput[1] / 2 - ($targetheight - $symbolsize) / 2)/$symbolsize); |
|
237 | - imagecopyresized($inputgd, $whiteimage, $targetplacementx-$symbolsize, $targetplacementy-$symbolsize, 0, 0, $targetwidth+2*$symbolsize, $targetheight+2*$symbolsize, $targetwidth+2*$symbolsize, $targetheight+2*$symbolsize); |
|
238 | - imagecopyresized($inputgd, $logogd, $targetplacementx, $targetplacementy, 0, 0, $targetwidth , $targetheight , $sizelogo[0] , $sizelogo[1]); |
|
235 | + $targetplacementx = $symbolsize * round(($sizeinput[0] / 2 - ($targetwidth - $symbolsize) / 2) / $symbolsize); |
|
236 | + $targetplacementy = $symbolsize * round(($sizeinput[1] / 2 - ($targetheight - $symbolsize) / 2) / $symbolsize); |
|
237 | + imagecopyresized($inputgd, $whiteimage, $targetplacementx - $symbolsize, $targetplacementy - $symbolsize, 0, 0, $targetwidth + 2 * $symbolsize, $targetheight + 2 * $symbolsize, $targetwidth + 2 * $symbolsize, $targetheight + 2 * $symbolsize); |
|
238 | + imagecopyresized($inputgd, $logogd, $targetplacementx, $targetplacementy, 0, 0, $targetwidth, $targetheight, $sizelogo[0], $sizelogo[1]); |
|
239 | 239 | // imagecopyresized($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); |
240 | 240 | ob_start(); |
241 | 241 | imagepng($inputgd); |
@@ -68,6 +68,7 @@ discard block |
||
68 | 68 | * Cannot be used to define a new IdP in the database! This happens via Federation::newIdP() |
69 | 69 | * |
70 | 70 | * @param integer $i_id the database row identifier |
71 | + * @return string |
|
71 | 72 | */ |
72 | 73 | public function __construct($i_id) { |
73 | 74 | debug(3, "--- BEGIN Constructing new IdP object ... ---\n"); |
@@ -247,7 +248,7 @@ discard block |
||
247 | 248 | * This function retrieves the IdP-wide attributes. If called with the optional parameter, only attribute values for the attribute |
248 | 249 | * name in $option_name are retrieved; otherwise, all attributes are retrieved. |
249 | 250 | * |
250 | - * @param string $option_name optionally, the name of the attribute that is to be retrieved |
|
251 | + * @param integer $option_name optionally, the name of the attribute that is to be retrieved |
|
251 | 252 | * @return array of arrays of attributes which were set for this IdP |
252 | 253 | */ |
253 | 254 | public function getAttributes($option_name = 0) { |
@@ -318,7 +319,7 @@ discard block |
||
318 | 319 | * Adds a new profile to this IdP. |
319 | 320 | * Only creates the DB entry for the Profile. If you want to add attributes later, see Profile::addAttribute(). |
320 | 321 | * |
321 | - * @return object new Profile object if successful, or FALSE if an error occured |
|
322 | + * @return Profile|null new Profile object if successful, or FALSE if an error occured |
|
322 | 323 | */ |
323 | 324 | public function newProfile() { |
324 | 325 | DBConnection::exec(IdP::$DB_TYPE, "INSERT INTO profile (inst_id) VALUES($this->identifier)"); |
@@ -94,7 +94,7 @@ |
||
94 | 94 | * |
95 | 95 | * @assert ("user") == Array("user:email","user:fedadmin","user:realname") |
96 | 96 | * |
97 | - * @param string $class_name optionally specifies the class of options to be listed (class is the part of the option name before the : sign) |
|
97 | + * @param integer $class_name optionally specifies the class of options to be listed (class is the part of the option name before the : sign) |
|
98 | 98 | * @return array of options |
99 | 99 | */ |
100 | 100 | public function availableOptions($class_name = 0) { |
@@ -77,15 +77,15 @@ discard block |
||
77 | 77 | */ |
78 | 78 | private function __construct() { |
79 | 79 | $this->type_db = []; |
80 | - debug(3,"--- BEGIN constructing Options instance ---\n"); |
|
80 | + debug(3, "--- BEGIN constructing Options instance ---\n"); |
|
81 | 81 | $options = DBConnection::exec(Options::$DB_TYPE, "SELECT name,type,flag from profile_option_dict ORDER BY name"); |
82 | - while($a = mysqli_fetch_object($options)) |
|
83 | - $this->type_db[$a->name] = ["type" => $a->type, "flag" => $a->flag]; |
|
84 | - $this->type_db["general:logo_url"] = ["type" => "string", "flag" => NULL]; |
|
85 | - $this->type_db["eap:ca_url"] = ["type" => "string", "flag" => NULL]; |
|
86 | - $this->type_db["internal:country"] = ["type" => "string", "flag" => NULL]; |
|
82 | + while ($a = mysqli_fetch_object($options)) |
|
83 | + $this->type_db[$a->name] = ["type" => $a->type, "flag" => $a->flag]; |
|
84 | + $this->type_db["general:logo_url"] = ["type" => "string", "flag" => NULL]; |
|
85 | + $this->type_db["eap:ca_url"] = ["type" => "string", "flag" => NULL]; |
|
86 | + $this->type_db["internal:country"] = ["type" => "string", "flag" => NULL]; |
|
87 | 87 | |
88 | - debug(3,"--- END constructing Options instance ---\n"); |
|
88 | + debug(3, "--- END constructing Options instance ---\n"); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -99,13 +99,13 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public function availableOptions($class_name = 0) { |
101 | 101 | $temporary_array = []; |
102 | - debug(3,"CLASSNAME IS $class_name\n"); |
|
102 | + debug(3, "CLASSNAME IS $class_name\n"); |
|
103 | 103 | |
104 | 104 | foreach (array_keys($this->type_db) as $name) { |
105 | 105 | if ($class_name === 0) { |
106 | 106 | $temporary_array[] = $name; |
107 | 107 | } else { |
108 | - if ( preg_match('/^'.$class_name.':/', $name) > 0 ) { |
|
108 | + if (preg_match('/^' . $class_name . ':/', $name) > 0) { |
|
109 | 109 | $temporary_array[] = $name; |
110 | 110 | } |
111 | 111 | } |
@@ -96,6 +96,10 @@ discard block |
||
96 | 96 | define('QR_FORMAT_PNG', 1); |
97 | 97 | |
98 | 98 | class qrstr { |
99 | + |
|
100 | + /** |
|
101 | + * @param string $repl |
|
102 | + */ |
|
99 | 103 | public static function set(&$srctab, $x, $y, $repl, $replLen = false) { |
100 | 104 | $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl)); |
101 | 105 | } |
@@ -231,6 +235,11 @@ discard block |
||
231 | 235 | } |
232 | 236 | |
233 | 237 | //---------------------------------------------------------------------- |
238 | + |
|
239 | + /** |
|
240 | + * @param boolean $outfile |
|
241 | + * @param string $err |
|
242 | + */ |
|
234 | 243 | public static function log($outfile, $err) |
235 | 244 | { |
236 | 245 | if (QR_LOG_DIR !== false) { |
@@ -256,6 +265,10 @@ discard block |
||
256 | 265 | } |
257 | 266 | |
258 | 267 | //---------------------------------------------------------------------- |
268 | + |
|
269 | + /** |
|
270 | + * @param string $markerId |
|
271 | + */ |
|
259 | 272 | public static function markTime($markerId) |
260 | 273 | { |
261 | 274 | list($usec, $sec) = explode(" ", microtime()); |
@@ -410,18 +423,30 @@ discard block |
||
410 | 423 | } |
411 | 424 | |
412 | 425 | //---------------------------------------------------------------------- |
426 | + |
|
427 | + /** |
|
428 | + * @param integer $version |
|
429 | + */ |
|
413 | 430 | public static function getWidth($version) |
414 | 431 | { |
415 | 432 | return self::$capacity[$version][QRCAP_WIDTH]; |
416 | 433 | } |
417 | 434 | |
418 | 435 | //---------------------------------------------------------------------- |
436 | + |
|
437 | + /** |
|
438 | + * @param integer $version |
|
439 | + */ |
|
419 | 440 | public static function getRemainder($version) |
420 | 441 | { |
421 | 442 | return self::$capacity[$version][QRCAP_REMINDER]; |
422 | 443 | } |
423 | 444 | |
424 | 445 | //---------------------------------------------------------------------- |
446 | + |
|
447 | + /** |
|
448 | + * @param integer $size |
|
449 | + */ |
|
425 | 450 | public static function getMinimumVersion($size, $level) |
426 | 451 | { |
427 | 452 | |
@@ -535,6 +560,9 @@ discard block |
||
535 | 560 | //---------------------------------------------------------------------- |
536 | 561 | // CACHEABLE!!! |
537 | 562 | |
563 | + /** |
|
564 | + * @param integer $version |
|
565 | + */ |
|
538 | 566 | public static function getEccSpec($version, $level, array &$spec) |
539 | 567 | { |
540 | 568 | if (count($spec) < 5) { |
@@ -857,12 +885,20 @@ discard block |
||
857 | 885 | } |
858 | 886 | |
859 | 887 | //---------------------------------------------------------------------- |
888 | + |
|
889 | + /** |
|
890 | + * @param string $code |
|
891 | + */ |
|
860 | 892 | public static function unserial($code) |
861 | 893 | { |
862 | 894 | return explode("\n", gzuncompress($code)); |
863 | 895 | } |
864 | 896 | |
865 | 897 | //---------------------------------------------------------------------- |
898 | + |
|
899 | + /** |
|
900 | + * @param integer $version |
|
901 | + */ |
|
866 | 902 | public static function newFrame($version) |
867 | 903 | { |
868 | 904 | if($version < 1 || $version > QRSPEC_VERSION_MAX) |
@@ -1236,6 +1272,10 @@ discard block |
||
1236 | 1272 | } |
1237 | 1273 | |
1238 | 1274 | //---------------------------------------------------------------------- |
1275 | + |
|
1276 | + /** |
|
1277 | + * @param integer $version |
|
1278 | + */ |
|
1239 | 1279 | public function encodeBitStream($version) |
1240 | 1280 | { |
1241 | 1281 | try { |
@@ -1313,6 +1353,10 @@ discard block |
||
1313 | 1353 | } |
1314 | 1354 | |
1315 | 1355 | //---------------------------------------------------------------------- |
1356 | + |
|
1357 | + /** |
|
1358 | + * @param integer $version |
|
1359 | + */ |
|
1316 | 1360 | public function setVersion($version) |
1317 | 1361 | { |
1318 | 1362 | if($version < 0 || $version > QRSPEC_VERSION_MAX) { |
@@ -1351,6 +1395,12 @@ discard block |
||
1351 | 1395 | } |
1352 | 1396 | |
1353 | 1397 | //---------------------------------------------------------------------- |
1398 | + |
|
1399 | + /** |
|
1400 | + * @param QRinput $mode |
|
1401 | + * @param integer $size |
|
1402 | + * @param integer $data |
|
1403 | + */ |
|
1354 | 1404 | public function append($mode, $size, $data) |
1355 | 1405 | { |
1356 | 1406 | try { |
@@ -1446,6 +1496,10 @@ discard block |
||
1446 | 1496 | ]; |
1447 | 1497 | |
1448 | 1498 | //---------------------------------------------------------------------- |
1499 | + |
|
1500 | + /** |
|
1501 | + * @param integer $c |
|
1502 | + */ |
|
1449 | 1503 | public static function lookAnTable($c) |
1450 | 1504 | { |
1451 | 1505 | return (($c > 127)?-1:self::$anTable[$c]); |
@@ -1531,6 +1585,10 @@ discard block |
||
1531 | 1585 | |
1532 | 1586 | |
1533 | 1587 | //---------------------------------------------------------------------- |
1588 | + |
|
1589 | + /** |
|
1590 | + * @param integer $version |
|
1591 | + */ |
|
1534 | 1592 | public function estimateBitStreamSize($version) |
1535 | 1593 | { |
1536 | 1594 | $bits = 0; |
@@ -1648,6 +1706,10 @@ discard block |
||
1648 | 1706 | } |
1649 | 1707 | |
1650 | 1708 | //---------------------------------------------------------------------- |
1709 | + |
|
1710 | + /** |
|
1711 | + * @param QRbitstream $bstream |
|
1712 | + */ |
|
1651 | 1713 | public function appendPaddingBit(&$bstream) |
1652 | 1714 | { |
1653 | 1715 | $bits = $bstream->size(); |
@@ -1977,6 +2039,10 @@ discard block |
||
1977 | 2039 | public $modeHint; |
1978 | 2040 | |
1979 | 2041 | //---------------------------------------------------------------------- |
2042 | + |
|
2043 | + /** |
|
2044 | + * @param QRinput $input |
|
2045 | + */ |
|
1980 | 2046 | public function __construct($dataStr, $input, $modeHint) |
1981 | 2047 | { |
1982 | 2048 | $this->dataStr = $dataStr; |
@@ -1985,6 +2051,10 @@ discard block |
||
1985 | 2051 | } |
1986 | 2052 | |
1987 | 2053 | //---------------------------------------------------------------------- |
2054 | + |
|
2055 | + /** |
|
2056 | + * @param string $str |
|
2057 | + */ |
|
1988 | 2058 | public static function isdigitat($str, $pos) |
1989 | 2059 | { |
1990 | 2060 | if ($pos >= strlen($str)) |
@@ -1994,6 +2064,10 @@ discard block |
||
1994 | 2064 | } |
1995 | 2065 | |
1996 | 2066 | //---------------------------------------------------------------------- |
2067 | + |
|
2068 | + /** |
|
2069 | + * @param string $str |
|
2070 | + */ |
|
1997 | 2071 | public static function isalnumat($str, $pos) |
1998 | 2072 | { |
1999 | 2073 | if ($pos >= strlen($str)) |
@@ -2114,6 +2188,10 @@ discard block |
||
2114 | 2188 | } |
2115 | 2189 | |
2116 | 2190 | //---------------------------------------------------------------------- |
2191 | + |
|
2192 | + /** |
|
2193 | + * @return integer |
|
2194 | + */ |
|
2117 | 2195 | public function eatKanji() |
2118 | 2196 | { |
2119 | 2197 | $p = 0; |
@@ -2447,6 +2525,13 @@ discard block |
||
2447 | 2525 | public static $items = []; |
2448 | 2526 | |
2449 | 2527 | //---------------------------------------------------------------------- |
2528 | + |
|
2529 | + /** |
|
2530 | + * @param integer $symsize |
|
2531 | + * @param integer $gfpoly |
|
2532 | + * @param integer $fcr |
|
2533 | + * @param integer $prim |
|
2534 | + */ |
|
2450 | 2535 | public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) |
2451 | 2536 | { |
2452 | 2537 | foreach(self::$items as $rs) { |
@@ -2601,6 +2686,10 @@ discard block |
||
2601 | 2686 | } |
2602 | 2687 | |
2603 | 2688 | //---------------------------------------------------------------------- |
2689 | + |
|
2690 | + /** |
|
2691 | + * @param string $code |
|
2692 | + */ |
|
2604 | 2693 | public static function unserial($code) |
2605 | 2694 | { |
2606 | 2695 | $codeArr = []; |
@@ -2661,6 +2750,10 @@ discard block |
||
2661 | 2750 | } |
2662 | 2751 | |
2663 | 2752 | //---------------------------------------------------------------------- |
2753 | + |
|
2754 | + /** |
|
2755 | + * @param integer $length |
|
2756 | + */ |
|
2664 | 2757 | public function calcN1N3($length) |
2665 | 2758 | { |
2666 | 2759 | $demerit = 0; |
@@ -2971,6 +3064,10 @@ discard block |
||
2971 | 3064 | public $data; |
2972 | 3065 | |
2973 | 3066 | //---------------------------------------------------------------------- |
3067 | + |
|
3068 | + /** |
|
3069 | + * @param integer $mask |
|
3070 | + */ |
|
2974 | 3071 | public function encodeMask(QRinput $input, $mask) |
2975 | 3072 | { |
2976 | 3073 | if($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) { |
@@ -3052,6 +3149,11 @@ discard block |
||
3052 | 3149 | } |
3053 | 3150 | |
3054 | 3151 | //---------------------------------------------------------------------- |
3152 | + |
|
3153 | + /** |
|
3154 | + * @param integer $version |
|
3155 | + * @param integer $level |
|
3156 | + */ |
|
3055 | 3157 | public function encodeString8bit($string, $version, $level) |
3056 | 3158 | { |
3057 | 3159 | if(string == NULL) { |
@@ -3071,6 +3173,12 @@ discard block |
||
3071 | 3173 | } |
3072 | 3174 | |
3073 | 3175 | //---------------------------------------------------------------------- |
3176 | + |
|
3177 | + /** |
|
3178 | + * @param integer $version |
|
3179 | + * @param integer $level |
|
3180 | + * @param boolean $casesensitive |
|
3181 | + */ |
|
3074 | 3182 | public function encodeString($string, $version, $level, $hint, $casesensitive) |
3075 | 3183 | { |
3076 | 3184 |
@@ -93,11 +93,11 @@ discard block |
||
93 | 93 | // Supported output formats |
94 | 94 | |
95 | 95 | define('QR_FORMAT_TEXT', 0); |
96 | - define('QR_FORMAT_PNG', 1); |
|
96 | + define('QR_FORMAT_PNG', 1); |
|
97 | 97 | |
98 | 98 | class qrstr { |
99 | 99 | public static function set(&$srctab, $x, $y, $repl, $replLen = false) { |
100 | - $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl)); |
|
100 | + $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false) ? substr($repl, 0, $replLen) : $repl, $x, ($replLen !== false) ? $replLen : strlen($repl)); |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
@@ -114,15 +114,15 @@ discard block |
||
114 | 114 | * Config file, tuned-up for merged verion |
115 | 115 | */ |
116 | 116 | |
117 | - define('QR_CACHEABLE', false); // use cache - more disk reads but less CPU power, masks and format templates are stored there |
|
118 | - define('QR_CACHE_DIR', false); // used when QR_CACHEABLE === true |
|
119 | - define('QR_LOG_DIR', false); // default error logs dir |
|
117 | + define('QR_CACHEABLE', false); // use cache - more disk reads but less CPU power, masks and format templates are stored there |
|
118 | + define('QR_CACHE_DIR', false); // used when QR_CACHEABLE === true |
|
119 | + define('QR_LOG_DIR', false); // default error logs dir |
|
120 | 120 | |
121 | - define('QR_FIND_BEST_MASK', true); // if true, estimates best mask (spec. default, but extremally slow; set to false to significant performance boost but (propably) worst quality code |
|
122 | - define('QR_FIND_FROM_RANDOM', 2); // if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly |
|
123 | - define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false |
|
121 | + define('QR_FIND_BEST_MASK', true); // if true, estimates best mask (spec. default, but extremally slow; set to false to significant performance boost but (propably) worst quality code |
|
122 | + define('QR_FIND_FROM_RANDOM', 2); // if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly |
|
123 | + define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false |
|
124 | 124 | |
125 | - define('QR_PNG_MAXIMUM_SIZE', 1024); // maximum allowed png image width (in pixels), tune to make sure GD and PHP can handle such big images |
|
125 | + define('QR_PNG_MAXIMUM_SIZE', 1024); // maximum allowed png image width (in pixels), tune to make sure GD and PHP can handle such big images |
|
126 | 126 | |
127 | 127 | |
128 | 128 | |
@@ -163,8 +163,8 @@ discard block |
||
163 | 163 | $len = count($frame); |
164 | 164 | foreach ($frame as &$frameLine) { |
165 | 165 | |
166 | - for($i=0; $i<$len; $i++) { |
|
167 | - $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0'; |
|
166 | + for ($i = 0; $i < $len; $i++) { |
|
167 | + $frameLine[$i] = (ord($frameLine[$i]) & 1) ? '1' : '0'; |
|
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
@@ -194,8 +194,8 @@ discard block |
||
194 | 194 | |
195 | 195 | foreach ($qrTab as $line) { |
196 | 196 | $arrAdd = []; |
197 | - foreach(str_split($line) as $char) |
|
198 | - $arrAdd[] = ($char=='1')?1:0; |
|
197 | + foreach (str_split($line) as $char) |
|
198 | + $arrAdd[] = ($char == '1') ? 1 : 0; |
|
199 | 199 | $barcode_array['bcode'][] = $arrAdd; |
200 | 200 | } |
201 | 201 | |
@@ -214,16 +214,16 @@ discard block |
||
214 | 214 | QRtools::markTime('before_build_cache'); |
215 | 215 | |
216 | 216 | $mask = new QRmask(); |
217 | - for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) { |
|
217 | + for ($a = 1; $a <= QRSPEC_VERSION_MAX; $a++) { |
|
218 | 218 | $frame = QRspec::newFrame($a); |
219 | 219 | if (QR_IMAGE) { |
220 | - $fileName = QR_CACHE_DIR.'frame_'.$a.'.png'; |
|
220 | + $fileName = QR_CACHE_DIR . 'frame_' . $a . '.png'; |
|
221 | 221 | QRimage::png(self::binarize($frame), $fileName, 1, 0); |
222 | 222 | } |
223 | 223 | |
224 | 224 | $width = count($frame); |
225 | 225 | $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
226 | - for ($maskNo=0; $maskNo<8; $maskNo++) |
|
226 | + for ($maskNo = 0; $maskNo < 8; $maskNo++) |
|
227 | 227 | $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
228 | 228 | } |
229 | 229 | |
@@ -236,9 +236,9 @@ discard block |
||
236 | 236 | if (QR_LOG_DIR !== false) { |
237 | 237 | if ($err != '') { |
238 | 238 | if ($outfile !== false) { |
239 | - file_put_contents(QR_LOG_DIR.basename($outfile).'-errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND); |
|
239 | + file_put_contents(QR_LOG_DIR . basename($outfile) . '-errors.txt', date('Y-m-d H:i:s') . ': ' . $err, FILE_APPEND); |
|
240 | 240 | } else { |
241 | - file_put_contents(QR_LOG_DIR.'errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND); |
|
241 | + file_put_contents(QR_LOG_DIR . 'errors.txt', date('Y-m-d H:i:s') . ': ' . $err, FILE_APPEND); |
|
242 | 242 | } |
243 | 243 | } |
244 | 244 | } |
@@ -248,9 +248,9 @@ discard block |
||
248 | 248 | public static function dumpMask($frame) |
249 | 249 | { |
250 | 250 | $width = count($frame); |
251 | - for($y=0;$y<$width;$y++) { |
|
252 | - for($x=0;$x<$width;$x++) { |
|
253 | - echo ord($frame[$y][$x]).','; |
|
251 | + for ($y = 0; $y < $width; $y++) { |
|
252 | + for ($x = 0; $x < $width; $x++) { |
|
253 | + echo ord($frame[$y][$x]) . ','; |
|
254 | 254 | } |
255 | 255 | } |
256 | 256 | } |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | public static function markTime($markerId) |
260 | 260 | { |
261 | 261 | list($usec, $sec) = explode(" ", microtime()); |
262 | - $time = ((float)$usec + (float)$sec); |
|
262 | + $time = ((float) $usec + (float) $sec); |
|
263 | 263 | |
264 | 264 | if (!isset($GLOBALS['qr_time_bench'])) |
265 | 265 | $GLOBALS['qr_time_bench'] = []; |
@@ -280,9 +280,9 @@ discard block |
||
280 | 280 | <thead><tr style="border-bottom:1px solid silver"><td colspan="2" style="text-align:center">BENCHMARK</td></tr></thead> |
281 | 281 | <tbody>'; |
282 | 282 | |
283 | - foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) { |
|
283 | + foreach ($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) { |
|
284 | 284 | if ($p > 0) { |
285 | - echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>'; |
|
285 | + echo '<tr><th style="text-align:right">till ' . $markerId . ': </th><td>' . number_format($thisTime - $lastTime, 6) . 's</td></tr>'; |
|
286 | 286 | } else { |
287 | 287 | $startTime = $thisTime; |
288 | 288 | } |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | } |
293 | 293 | |
294 | 294 | echo '</tbody><tfoot> |
295 | - <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime-$startTime, 6).'s</td></tr> |
|
295 | + <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime - $startTime, 6) . 's</td></tr> |
|
296 | 296 | </tfoot> |
297 | 297 | </table>'; |
298 | 298 | } |
@@ -344,57 +344,57 @@ discard block |
||
344 | 344 | */ |
345 | 345 | |
346 | 346 | define('QRSPEC_VERSION_MAX', 40); |
347 | - define('QRSPEC_WIDTH_MAX', 177); |
|
347 | + define('QRSPEC_WIDTH_MAX', 177); |
|
348 | 348 | |
349 | - define('QRCAP_WIDTH', 0); |
|
350 | - define('QRCAP_WORDS', 1); |
|
351 | - define('QRCAP_REMINDER', 2); |
|
352 | - define('QRCAP_EC', 3); |
|
349 | + define('QRCAP_WIDTH', 0); |
|
350 | + define('QRCAP_WORDS', 1); |
|
351 | + define('QRCAP_REMINDER', 2); |
|
352 | + define('QRCAP_EC', 3); |
|
353 | 353 | |
354 | 354 | class QRspec { |
355 | 355 | |
356 | 356 | public static $capacity = [ |
357 | - [ 0, 0, 0, [ 0, 0, 0, 0]], |
|
358 | - [ 21, 26, 0, [ 7, 10, 13, 17]], // 1 |
|
359 | - [ 25, 44, 7, [ 10, 16, 22, 28]], |
|
360 | - [ 29, 70, 7, [ 15, 26, 36, 44]], |
|
361 | - [ 33, 100, 7, [ 20, 36, 52, 64]], |
|
362 | - [ 37, 134, 7, [ 26, 48, 72, 88]], // 5 |
|
363 | - [ 41, 172, 7, [ 36, 64, 96, 112]], |
|
364 | - [ 45, 196, 0, [ 40, 72, 108, 130]], |
|
365 | - [ 49, 242, 0, [ 48, 88, 132, 156]], |
|
366 | - [ 53, 292, 0, [ 60, 110, 160, 192]], |
|
367 | - [ 57, 346, 0, [ 72, 130, 192, 224]], //10 |
|
368 | - [ 61, 404, 0, [ 80, 150, 224, 264]], |
|
369 | - [ 65, 466, 0, [ 96, 176, 260, 308]], |
|
370 | - [ 69, 532, 0, [ 104, 198, 288, 352]], |
|
371 | - [ 73, 581, 3, [ 120, 216, 320, 384]], |
|
372 | - [ 77, 655, 3, [ 132, 240, 360, 432]], //15 |
|
373 | - [ 81, 733, 3, [ 144, 280, 408, 480]], |
|
374 | - [ 85, 815, 3, [ 168, 308, 448, 532]], |
|
375 | - [ 89, 901, 3, [ 180, 338, 504, 588]], |
|
376 | - [ 93, 991, 3, [ 196, 364, 546, 650]], |
|
377 | - [ 97, 1085, 3, [ 224, 416, 600, 700]], //20 |
|
378 | - [101, 1156, 4, [ 224, 442, 644, 750]], |
|
379 | - [105, 1258, 4, [ 252, 476, 690, 816]], |
|
380 | - [109, 1364, 4, [ 270, 504, 750, 900]], |
|
381 | - [113, 1474, 4, [ 300, 560, 810, 960]], |
|
382 | - [117, 1588, 4, [ 312, 588, 870, 1050]], //25 |
|
383 | - [121, 1706, 4, [ 336, 644, 952, 1110]], |
|
384 | - [125, 1828, 4, [ 360, 700, 1020, 1200]], |
|
385 | - [129, 1921, 3, [ 390, 728, 1050, 1260]], |
|
386 | - [133, 2051, 3, [ 420, 784, 1140, 1350]], |
|
387 | - [137, 2185, 3, [ 450, 812, 1200, 1440]], //30 |
|
388 | - [141, 2323, 3, [ 480, 868, 1290, 1530]], |
|
389 | - [145, 2465, 3, [ 510, 924, 1350, 1620]], |
|
390 | - [149, 2611, 3, [ 540, 980, 1440, 1710]], |
|
391 | - [153, 2761, 3, [ 570, 1036, 1530, 1800]], |
|
392 | - [157, 2876, 0, [ 570, 1064, 1590, 1890]], //35 |
|
393 | - [161, 3034, 0, [ 600, 1120, 1680, 1980]], |
|
394 | - [165, 3196, 0, [ 630, 1204, 1770, 2100]], |
|
395 | - [169, 3362, 0, [ 660, 1260, 1860, 2220]], |
|
396 | - [173, 3532, 0, [ 720, 1316, 1950, 2310]], |
|
397 | - [177, 3706, 0, [ 750, 1372, 2040, 2430]] //40 |
|
357 | + [0, 0, 0, [0, 0, 0, 0]], |
|
358 | + [21, 26, 0, [7, 10, 13, 17]], // 1 |
|
359 | + [25, 44, 7, [10, 16, 22, 28]], |
|
360 | + [29, 70, 7, [15, 26, 36, 44]], |
|
361 | + [33, 100, 7, [20, 36, 52, 64]], |
|
362 | + [37, 134, 7, [26, 48, 72, 88]], // 5 |
|
363 | + [41, 172, 7, [36, 64, 96, 112]], |
|
364 | + [45, 196, 0, [40, 72, 108, 130]], |
|
365 | + [49, 242, 0, [48, 88, 132, 156]], |
|
366 | + [53, 292, 0, [60, 110, 160, 192]], |
|
367 | + [57, 346, 0, [72, 130, 192, 224]], //10 |
|
368 | + [61, 404, 0, [80, 150, 224, 264]], |
|
369 | + [65, 466, 0, [96, 176, 260, 308]], |
|
370 | + [69, 532, 0, [104, 198, 288, 352]], |
|
371 | + [73, 581, 3, [120, 216, 320, 384]], |
|
372 | + [77, 655, 3, [132, 240, 360, 432]], //15 |
|
373 | + [81, 733, 3, [144, 280, 408, 480]], |
|
374 | + [85, 815, 3, [168, 308, 448, 532]], |
|
375 | + [89, 901, 3, [180, 338, 504, 588]], |
|
376 | + [93, 991, 3, [196, 364, 546, 650]], |
|
377 | + [97, 1085, 3, [224, 416, 600, 700]], //20 |
|
378 | + [101, 1156, 4, [224, 442, 644, 750]], |
|
379 | + [105, 1258, 4, [252, 476, 690, 816]], |
|
380 | + [109, 1364, 4, [270, 504, 750, 900]], |
|
381 | + [113, 1474, 4, [300, 560, 810, 960]], |
|
382 | + [117, 1588, 4, [312, 588, 870, 1050]], //25 |
|
383 | + [121, 1706, 4, [336, 644, 952, 1110]], |
|
384 | + [125, 1828, 4, [360, 700, 1020, 1200]], |
|
385 | + [129, 1921, 3, [390, 728, 1050, 1260]], |
|
386 | + [133, 2051, 3, [420, 784, 1140, 1350]], |
|
387 | + [137, 2185, 3, [450, 812, 1200, 1440]], //30 |
|
388 | + [141, 2323, 3, [480, 868, 1290, 1530]], |
|
389 | + [145, 2465, 3, [510, 924, 1350, 1620]], |
|
390 | + [149, 2611, 3, [540, 980, 1440, 1710]], |
|
391 | + [153, 2761, 3, [570, 1036, 1530, 1800]], |
|
392 | + [157, 2876, 0, [570, 1064, 1590, 1890]], //35 |
|
393 | + [161, 3034, 0, [600, 1120, 1680, 1980]], |
|
394 | + [165, 3196, 0, [630, 1204, 1770, 2100]], |
|
395 | + [169, 3362, 0, [660, 1260, 1860, 2220]], |
|
396 | + [173, 3532, 0, [720, 1316, 1950, 2310]], |
|
397 | + [177, 3706, 0, [750, 1372, 2040, 2430]] //40 |
|
398 | 398 | ]; |
399 | 399 | |
400 | 400 | //---------------------------------------------------------------------- |
@@ -425,9 +425,9 @@ discard block |
||
425 | 425 | public static function getMinimumVersion($size, $level) |
426 | 426 | { |
427 | 427 | |
428 | - for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) { |
|
429 | - $words = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level]; |
|
430 | - if($words >= $size) |
|
428 | + for ($i = 1; $i <= QRSPEC_VERSION_MAX; $i++) { |
|
429 | + $words = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level]; |
|
430 | + if ($words >= $size) |
|
431 | 431 | return $i; |
432 | 432 | } |
433 | 433 | |
@@ -438,9 +438,9 @@ discard block |
||
438 | 438 | |
439 | 439 | public static $lengthTableBits = [ |
440 | 440 | [10, 12, 14], |
441 | - [ 9, 11, 13], |
|
442 | - [ 8, 16, 16], |
|
443 | - [ 8, 10, 12] |
|
441 | + [9, 11, 13], |
|
442 | + [8, 16, 16], |
|
443 | + [8, 10, 12] |
|
444 | 444 | ]; |
445 | 445 | |
446 | 446 | //---------------------------------------------------------------------- |
@@ -463,12 +463,12 @@ discard block |
||
463 | 463 | //---------------------------------------------------------------------- |
464 | 464 | public static function maximumWords($mode, $version) |
465 | 465 | { |
466 | - if($mode == QR_MODE_STRUCTURE) |
|
466 | + if ($mode == QR_MODE_STRUCTURE) |
|
467 | 467 | return 3; |
468 | 468 | |
469 | - if($version <= 9) { |
|
469 | + if ($version <= 9) { |
|
470 | 470 | $l = 0; |
471 | - } else if($version <= 26) { |
|
471 | + } else if ($version <= 26) { |
|
472 | 472 | $l = 1; |
473 | 473 | } else { |
474 | 474 | $l = 2; |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | $bits = self::$lengthTableBits[$mode][$l]; |
478 | 478 | $words = (1 << $bits) - 1; |
479 | 479 | |
480 | - if($mode == QR_MODE_KANJI) { |
|
480 | + if ($mode == QR_MODE_KANJI) { |
|
481 | 481 | $words *= 2; // the number of bytes is required |
482 | 482 | } |
483 | 483 | |
@@ -489,47 +489,47 @@ discard block |
||
489 | 489 | // See Table 12-16 (pp.30-36), JIS X0510:2004. |
490 | 490 | |
491 | 491 | public static $eccTable = [ |
492 | - [[ 0, 0], [ 0, 0], [ 0, 0], [ 0, 0]], |
|
493 | - [[ 1, 0], [ 1, 0], [ 1, 0], [ 1, 0]], // 1 |
|
494 | - [[ 1, 0], [ 1, 0], [ 1, 0], [ 1, 0]], |
|
495 | - [[ 1, 0], [ 1, 0], [ 2, 0], [ 2, 0]], |
|
496 | - [[ 1, 0], [ 2, 0], [ 2, 0], [ 4, 0]], |
|
497 | - [[ 1, 0], [ 2, 0], [ 2, 2], [ 2, 2]], // 5 |
|
498 | - [[ 2, 0], [ 4, 0], [ 4, 0], [ 4, 0]], |
|
499 | - [[ 2, 0], [ 4, 0], [ 2, 4], [ 4, 1]], |
|
500 | - [[ 2, 0], [ 2, 2], [ 4, 2], [ 4, 2]], |
|
501 | - [[ 2, 0], [ 3, 2], [ 4, 4], [ 4, 4]], |
|
502 | - [[ 2, 2], [ 4, 1], [ 6, 2], [ 6, 2]], //10 |
|
503 | - [[ 4, 0], [ 1, 4], [ 4, 4], [ 3, 8]], |
|
504 | - [[ 2, 2], [ 6, 2], [ 4, 6], [ 7, 4]], |
|
505 | - [[ 4, 0], [ 8, 1], [ 8, 4], [12, 4]], |
|
506 | - [[ 3, 1], [ 4, 5], [11, 5], [11, 5]], |
|
507 | - [[ 5, 1], [ 5, 5], [ 5, 7], [11, 7]], //15 |
|
508 | - [[ 5, 1], [ 7, 3], [15, 2], [ 3, 13]], |
|
509 | - [[ 1, 5], [10, 1], [ 1, 15], [ 2, 17]], |
|
510 | - [[ 5, 1], [ 9, 4], [17, 1], [ 2, 19]], |
|
511 | - [[ 3, 4], [ 3, 11], [17, 4], [ 9, 16]], |
|
512 | - [[ 3, 5], [ 3, 13], [15, 5], [15, 10]], //20 |
|
513 | - [[ 4, 4], [17, 0], [17, 6], [19, 6]], |
|
514 | - [[ 2, 7], [17, 0], [ 7, 16], [34, 0]], |
|
515 | - [[ 4, 5], [ 4, 14], [11, 14], [16, 14]], |
|
516 | - [[ 6, 4], [ 6, 14], [11, 16], [30, 2]], |
|
517 | - [[ 8, 4], [ 8, 13], [ 7, 22], [22, 13]], //25 |
|
518 | - [[10, 2], [19, 4], [28, 6], [33, 4]], |
|
519 | - [[ 8, 4], [22, 3], [ 8, 26], [12, 28]], |
|
520 | - [[ 3, 10], [ 3, 23], [ 4, 31], [11, 31]], |
|
521 | - [[ 7, 7], [21, 7], [ 1, 37], [19, 26]], |
|
522 | - [[ 5, 10], [19, 10], [15, 25], [23, 25]], //30 |
|
523 | - [[13, 3], [ 2, 29], [42, 1], [23, 28]], |
|
524 | - [[17, 0], [10, 23], [10, 35], [19, 35]], |
|
525 | - [[17, 1], [14, 21], [29, 19], [11, 46]], |
|
526 | - [[13, 6], [14, 23], [44, 7], [59, 1]], |
|
527 | - [[12, 7], [12, 26], [39, 14], [22, 41]], //35 |
|
528 | - [[ 6, 14], [ 6, 34], [46, 10], [ 2, 64]], |
|
529 | - [[17, 4], [29, 14], [49, 10], [24, 46]], |
|
530 | - [[ 4, 18], [13, 32], [48, 14], [42, 32]], |
|
531 | - [[20, 4], [40, 7], [43, 22], [10, 67]], |
|
532 | - [[19, 6], [18, 31], [34, 34], [20, 61]],//40 |
|
492 | + [[0, 0], [0, 0], [0, 0], [0, 0]], |
|
493 | + [[1, 0], [1, 0], [1, 0], [1, 0]], // 1 |
|
494 | + [[1, 0], [1, 0], [1, 0], [1, 0]], |
|
495 | + [[1, 0], [1, 0], [2, 0], [2, 0]], |
|
496 | + [[1, 0], [2, 0], [2, 0], [4, 0]], |
|
497 | + [[1, 0], [2, 0], [2, 2], [2, 2]], // 5 |
|
498 | + [[2, 0], [4, 0], [4, 0], [4, 0]], |
|
499 | + [[2, 0], [4, 0], [2, 4], [4, 1]], |
|
500 | + [[2, 0], [2, 2], [4, 2], [4, 2]], |
|
501 | + [[2, 0], [3, 2], [4, 4], [4, 4]], |
|
502 | + [[2, 2], [4, 1], [6, 2], [6, 2]], //10 |
|
503 | + [[4, 0], [1, 4], [4, 4], [3, 8]], |
|
504 | + [[2, 2], [6, 2], [4, 6], [7, 4]], |
|
505 | + [[4, 0], [8, 1], [8, 4], [12, 4]], |
|
506 | + [[3, 1], [4, 5], [11, 5], [11, 5]], |
|
507 | + [[5, 1], [5, 5], [5, 7], [11, 7]], //15 |
|
508 | + [[5, 1], [7, 3], [15, 2], [3, 13]], |
|
509 | + [[1, 5], [10, 1], [1, 15], [2, 17]], |
|
510 | + [[5, 1], [9, 4], [17, 1], [2, 19]], |
|
511 | + [[3, 4], [3, 11], [17, 4], [9, 16]], |
|
512 | + [[3, 5], [3, 13], [15, 5], [15, 10]], //20 |
|
513 | + [[4, 4], [17, 0], [17, 6], [19, 6]], |
|
514 | + [[2, 7], [17, 0], [7, 16], [34, 0]], |
|
515 | + [[4, 5], [4, 14], [11, 14], [16, 14]], |
|
516 | + [[6, 4], [6, 14], [11, 16], [30, 2]], |
|
517 | + [[8, 4], [8, 13], [7, 22], [22, 13]], //25 |
|
518 | + [[10, 2], [19, 4], [28, 6], [33, 4]], |
|
519 | + [[8, 4], [22, 3], [8, 26], [12, 28]], |
|
520 | + [[3, 10], [3, 23], [4, 31], [11, 31]], |
|
521 | + [[7, 7], [21, 7], [1, 37], [19, 26]], |
|
522 | + [[5, 10], [19, 10], [15, 25], [23, 25]], //30 |
|
523 | + [[13, 3], [2, 29], [42, 1], [23, 28]], |
|
524 | + [[17, 0], [10, 23], [10, 35], [19, 35]], |
|
525 | + [[17, 1], [14, 21], [29, 19], [11, 46]], |
|
526 | + [[13, 6], [14, 23], [44, 7], [59, 1]], |
|
527 | + [[12, 7], [12, 26], [39, 14], [22, 41]], //35 |
|
528 | + [[6, 14], [6, 34], [46, 10], [2, 64]], |
|
529 | + [[17, 4], [29, 14], [49, 10], [24, 46]], |
|
530 | + [[4, 18], [13, 32], [48, 14], [42, 32]], |
|
531 | + [[20, 4], [40, 7], [43, 22], [10, 67]], |
|
532 | + [[19, 6], [18, 31], [34, 34], [20, 61]], //40 |
|
533 | 533 | ]; |
534 | 534 | |
535 | 535 | //---------------------------------------------------------------------- |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | public static function getEccSpec($version, $level, array &$spec) |
539 | 539 | { |
540 | 540 | if (count($spec) < 5) { |
541 | - $spec = [0,0,0,0,0]; |
|
541 | + $spec = [0, 0, 0, 0, 0]; |
|
542 | 542 | } |
543 | 543 | |
544 | 544 | $b1 = self::$eccTable[$version][$level][0]; |
@@ -546,16 +546,16 @@ discard block |
||
546 | 546 | $data = self::getDataLength($version, $level); |
547 | 547 | $ecc = self::getECCLength($version, $level); |
548 | 548 | |
549 | - if($b2 == 0) { |
|
549 | + if ($b2 == 0) { |
|
550 | 550 | $spec[0] = $b1; |
551 | - $spec[1] = (int)($data / $b1); |
|
552 | - $spec[2] = (int)($ecc / $b1); |
|
551 | + $spec[1] = (int) ($data / $b1); |
|
552 | + $spec[2] = (int) ($ecc / $b1); |
|
553 | 553 | $spec[3] = 0; |
554 | 554 | $spec[4] = 0; |
555 | 555 | } else { |
556 | 556 | $spec[0] = $b1; |
557 | - $spec[1] = (int)($data / ($b1 + $b2)); |
|
558 | - $spec[2] = (int)($ecc / ($b1 + $b2)); |
|
557 | + $spec[1] = (int) ($data / ($b1 + $b2)); |
|
558 | + $spec[2] = (int) ($ecc / ($b1 + $b2)); |
|
559 | 559 | $spec[3] = $b2; |
560 | 560 | $spec[4] = $spec[1] + 1; |
561 | 561 | } |
@@ -571,9 +571,9 @@ discard block |
||
571 | 571 | // See Table 1 in Appendix E (pp.71) of JIS X0510:2004. |
572 | 572 | |
573 | 573 | public static $alignmentPattern = [ |
574 | - [ 0, 0], |
|
575 | - [ 0, 0], [18, 0], [22, 0], [26, 0], [30, 0], // 1- 5 |
|
576 | - [34, 0], [22, 38], [24, 42], [26, 46], [28, 50], // 6-10 |
|
574 | + [0, 0], |
|
575 | + [0, 0], [18, 0], [22, 0], [26, 0], [30, 0], // 1- 5 |
|
576 | + [34, 0], [22, 38], [24, 42], [26, 46], [28, 50], // 6-10 |
|
577 | 577 | [30, 54], [32, 58], [34, 62], [26, 46], [26, 48], //11-15 |
578 | 578 | [26, 50], [30, 54], [30, 56], [30, 58], [34, 62], //16-20 |
579 | 579 | [28, 50], [26, 50], [30, 54], [28, 54], [32, 58], //21-25 |
@@ -599,28 +599,28 @@ discard block |
||
599 | 599 | "\xa1\xa1\xa1\xa1\xa1" |
600 | 600 | ]; |
601 | 601 | |
602 | - $yStart = $oy-2; |
|
603 | - $xStart = $ox-2; |
|
602 | + $yStart = $oy - 2; |
|
603 | + $xStart = $ox - 2; |
|
604 | 604 | |
605 | - for($y=0; $y<5; $y++) { |
|
606 | - QRstr::set($frame, $xStart, $yStart+$y, $finder[$y]); |
|
605 | + for ($y = 0; $y < 5; $y++) { |
|
606 | + QRstr::set($frame, $xStart, $yStart + $y, $finder[$y]); |
|
607 | 607 | } |
608 | 608 | } |
609 | 609 | |
610 | 610 | //---------------------------------------------------------------------- |
611 | 611 | public static function putAlignmentPattern($version, &$frame, $width) |
612 | 612 | { |
613 | - if($version < 2) |
|
613 | + if ($version < 2) |
|
614 | 614 | return; |
615 | 615 | |
616 | 616 | $d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0]; |
617 | - if($d < 0) { |
|
617 | + if ($d < 0) { |
|
618 | 618 | $w = 2; |
619 | 619 | } else { |
620 | - $w = (int)(($width - self::$alignmentPattern[$version][0]) / $d + 2); |
|
620 | + $w = (int) (($width - self::$alignmentPattern[$version][0]) / $d + 2); |
|
621 | 621 | } |
622 | 622 | |
623 | - if($w * $w - 3 == 1) { |
|
623 | + if ($w * $w - 3 == 1) { |
|
624 | 624 | $x = self::$alignmentPattern[$version][0]; |
625 | 625 | $y = self::$alignmentPattern[$version][0]; |
626 | 626 | self::putAlignmentMarker($frame, $x, $y); |
@@ -628,16 +628,16 @@ discard block |
||
628 | 628 | } |
629 | 629 | |
630 | 630 | $cx = self::$alignmentPattern[$version][0]; |
631 | - for($x=1; $x<$w - 1; $x++) { |
|
631 | + for ($x = 1; $x < $w - 1; $x++) { |
|
632 | 632 | self::putAlignmentMarker($frame, 6, $cx); |
633 | - self::putAlignmentMarker($frame, $cx, 6); |
|
633 | + self::putAlignmentMarker($frame, $cx, 6); |
|
634 | 634 | $cx += $d; |
635 | 635 | } |
636 | 636 | |
637 | 637 | $cy = self::$alignmentPattern[$version][0]; |
638 | - for($y=0; $y<$w-1; $y++) { |
|
638 | + for ($y = 0; $y < $w - 1; $y++) { |
|
639 | 639 | $cx = self::$alignmentPattern[$version][0]; |
640 | - for($x=0; $x<$w-1; $x++) { |
|
640 | + for ($x = 0; $x < $w - 1; $x++) { |
|
641 | 641 | self::putAlignmentMarker($frame, $cx, $cy); |
642 | 642 | $cx += $d; |
643 | 643 | } |
@@ -663,10 +663,10 @@ discard block |
||
663 | 663 | //---------------------------------------------------------------------- |
664 | 664 | public static function getVersionPattern($version) |
665 | 665 | { |
666 | - if($version < 7 || $version > QRSPEC_VERSION_MAX) |
|
666 | + if ($version < 7 || $version > QRSPEC_VERSION_MAX) |
|
667 | 667 | return 0; |
668 | 668 | |
669 | - return self::$versionPattern[$version -7]; |
|
669 | + return self::$versionPattern[$version - 7]; |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | // Format information -------------------------------------------------- |
@@ -681,10 +681,10 @@ discard block |
||
681 | 681 | |
682 | 682 | public static function getFormatInfo($mask, $level) |
683 | 683 | { |
684 | - if($mask < 0 || $mask > 7) |
|
684 | + if ($mask < 0 || $mask > 7) |
|
685 | 685 | return 0; |
686 | 686 | |
687 | - if($level < 0 || $level > 3) |
|
687 | + if ($level < 0 || $level > 3) |
|
688 | 688 | return 0; |
689 | 689 | |
690 | 690 | return self::$formatInfo[$level][$mask]; |
@@ -713,8 +713,8 @@ discard block |
||
713 | 713 | "\xc1\xc1\xc1\xc1\xc1\xc1\xc1" |
714 | 714 | ]; |
715 | 715 | |
716 | - for($y=0; $y<7; $y++) { |
|
717 | - QRstr::set($frame, $ox, $oy+$y, $finder[$y]); |
|
716 | + for ($y = 0; $y < 7; $y++) { |
|
717 | + QRstr::set($frame, $ox, $oy + $y, $finder[$y]); |
|
718 | 718 | } |
719 | 719 | } |
720 | 720 | |
@@ -722,7 +722,7 @@ discard block |
||
722 | 722 | public static function createFrame($version) |
723 | 723 | { |
724 | 724 | $width = self::$capacity[$version][QRCAP_WIDTH]; |
725 | - $frameLine = str_repeat ("\0", $width); |
|
725 | + $frameLine = str_repeat("\0", $width); |
|
726 | 726 | $frame = array_fill(0, $width, $frameLine); |
727 | 727 | |
728 | 728 | // Finder pattern |
@@ -733,7 +733,7 @@ discard block |
||
733 | 733 | // Separator |
734 | 734 | $yOffset = $width - 7; |
735 | 735 | |
736 | - for($y=0; $y<7; $y++) { |
|
736 | + for ($y = 0; $y < 7; $y++) { |
|
737 | 737 | $frame[$y][7] = "\xc0"; |
738 | 738 | $frame[$y][$width - 8] = "\xc0"; |
739 | 739 | $frame[$yOffset][7] = "\xc0"; |
@@ -743,7 +743,7 @@ discard block |
||
743 | 743 | $setPattern = str_repeat("\xc0", 8); |
744 | 744 | |
745 | 745 | QRstr::set($frame, 0, 7, $setPattern); |
746 | - QRstr::set($frame, $width-8, 7, $setPattern); |
|
746 | + QRstr::set($frame, $width - 8, 7, $setPattern); |
|
747 | 747 | QRstr::set($frame, 0, $width - 8, $setPattern); |
748 | 748 | |
749 | 749 | // Format info |
@@ -753,38 +753,38 @@ discard block |
||
753 | 753 | |
754 | 754 | $yOffset = $width - 8; |
755 | 755 | |
756 | - for($y=0; $y<8; $y++,$yOffset++) { |
|
756 | + for ($y = 0; $y < 8; $y++, $yOffset++) { |
|
757 | 757 | $frame[$y][8] = "\x84"; |
758 | 758 | $frame[$yOffset][8] = "\x84"; |
759 | 759 | } |
760 | 760 | |
761 | 761 | // Timing pattern |
762 | 762 | |
763 | - for($i=1; $i<$width-15; $i++) { |
|
764 | - $frame[6][7+$i] = chr(0x90 | ($i & 1)); |
|
765 | - $frame[7+$i][6] = chr(0x90 | ($i & 1)); |
|
763 | + for ($i = 1; $i < $width - 15; $i++) { |
|
764 | + $frame[6][7 + $i] = chr(0x90 | ($i & 1)); |
|
765 | + $frame[7 + $i][6] = chr(0x90 | ($i & 1)); |
|
766 | 766 | } |
767 | 767 | |
768 | 768 | // Alignment pattern |
769 | 769 | self::putAlignmentPattern($version, $frame, $width); |
770 | 770 | |
771 | 771 | // Version information |
772 | - if($version >= 7) { |
|
772 | + if ($version >= 7) { |
|
773 | 773 | $vinf = self::getVersionPattern($version); |
774 | 774 | |
775 | 775 | $v = $vinf; |
776 | 776 | |
777 | - for($x=0; $x<6; $x++) { |
|
778 | - for($y=0; $y<3; $y++) { |
|
779 | - $frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1)); |
|
777 | + for ($x = 0; $x < 6; $x++) { |
|
778 | + for ($y = 0; $y < 3; $y++) { |
|
779 | + $frame[($width - 11) + $y][$x] = chr(0x88 | ($v & 1)); |
|
780 | 780 | $v = $v >> 1; |
781 | 781 | } |
782 | 782 | } |
783 | 783 | |
784 | 784 | $v = $vinf; |
785 | - for($y=0; $y<6; $y++) { |
|
786 | - for($x=0; $x<3; $x++) { |
|
787 | - $frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1)); |
|
785 | + for ($y = 0; $y < 6; $y++) { |
|
786 | + for ($x = 0; $x < 3; $x++) { |
|
787 | + $frame[$y][$x + ($width - 11)] = chr(0x88 | ($v & 1)); |
|
788 | 788 | $v = $v >> 1; |
789 | 789 | } |
790 | 790 | } |
@@ -818,16 +818,16 @@ discard block |
||
818 | 818 | } else { |
819 | 819 | |
820 | 820 | foreach ($frame as &$frameLine) { |
821 | - $frameLine = join('<span class="m"> </span>', explode("\xc0", $frameLine)); |
|
821 | + $frameLine = join('<span class="m"> </span>', explode("\xc0", $frameLine)); |
|
822 | 822 | $frameLine = join('<span class="m">▒</span>', explode("\xc1", $frameLine)); |
823 | - $frameLine = join('<span class="p"> </span>', explode("\xa0", $frameLine)); |
|
823 | + $frameLine = join('<span class="p"> </span>', explode("\xa0", $frameLine)); |
|
824 | 824 | $frameLine = join('<span class="p">▒</span>', explode("\xa1", $frameLine)); |
825 | 825 | $frameLine = join('<span class="s">◇</span>', explode("\x84", $frameLine)); //format 0 |
826 | 826 | $frameLine = join('<span class="s">◆</span>', explode("\x85", $frameLine)); //format 1 |
827 | 827 | $frameLine = join('<span class="x">☢</span>', explode("\x81", $frameLine)); //special bit |
828 | - $frameLine = join('<span class="c"> </span>', explode("\x90", $frameLine)); //clock 0 |
|
828 | + $frameLine = join('<span class="c"> </span>', explode("\x90", $frameLine)); //clock 0 |
|
829 | 829 | $frameLine = join('<span class="c">◷</span>', explode("\x91", $frameLine)); //clock 1 |
830 | - $frameLine = join('<span class="f"> </span>', explode("\x88", $frameLine)); //version |
|
830 | + $frameLine = join('<span class="f"> </span>', explode("\x88", $frameLine)); //version |
|
831 | 831 | $frameLine = join('<span class="f">▒</span>', explode("\x89", $frameLine)); //version |
832 | 832 | $frameLine = join('♦', explode("\x01", $frameLine)); |
833 | 833 | $frameLine = join('⋅', explode("\0", $frameLine)); |
@@ -865,12 +865,12 @@ discard block |
||
865 | 865 | //---------------------------------------------------------------------- |
866 | 866 | public static function newFrame($version) |
867 | 867 | { |
868 | - if($version < 1 || $version > QRSPEC_VERSION_MAX) |
|
868 | + if ($version < 1 || $version > QRSPEC_VERSION_MAX) |
|
869 | 869 | return null; |
870 | 870 | |
871 | - if(!isset(self::$frames[$version])) { |
|
871 | + if (!isset(self::$frames[$version])) { |
|
872 | 872 | |
873 | - $fileName = QR_CACHE_DIR.'frame_'.$version.'.dat'; |
|
873 | + $fileName = QR_CACHE_DIR . 'frame_' . $version . '.dat'; |
|
874 | 874 | |
875 | 875 | if (QR_CACHEABLE) { |
876 | 876 | if (file_exists($fileName)) { |
@@ -884,22 +884,22 @@ discard block |
||
884 | 884 | } |
885 | 885 | } |
886 | 886 | |
887 | - if(is_null(self::$frames[$version])) |
|
887 | + if (is_null(self::$frames[$version])) |
|
888 | 888 | return null; |
889 | 889 | |
890 | 890 | return self::$frames[$version]; |
891 | 891 | } |
892 | 892 | |
893 | 893 | //---------------------------------------------------------------------- |
894 | - public static function rsBlockNum($spec) { return $spec[0] + $spec[3]; } |
|
895 | - public static function rsBlockNum1($spec) { return $spec[0]; } |
|
896 | - public static function rsDataCodes1($spec) { return $spec[1]; } |
|
897 | - public static function rsEccCodes1($spec) { return $spec[2]; } |
|
898 | - public static function rsBlockNum2($spec) { return $spec[3]; } |
|
899 | - public static function rsDataCodes2($spec) { return $spec[4]; } |
|
900 | - public static function rsEccCodes2($spec) { return $spec[2]; } |
|
901 | - public static function rsDataLength($spec) { return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]); } |
|
902 | - public static function rsEccLength($spec) { return ($spec[0] + $spec[3]) * $spec[2]; } |
|
894 | + public static function rsBlockNum($spec) { return $spec[0] + $spec[3]; } |
|
895 | + public static function rsBlockNum1($spec) { return $spec[0]; } |
|
896 | + public static function rsDataCodes1($spec) { return $spec[1]; } |
|
897 | + public static function rsEccCodes1($spec) { return $spec[2]; } |
|
898 | + public static function rsBlockNum2($spec) { return $spec[3]; } |
|
899 | + public static function rsDataCodes2($spec) { return $spec[4]; } |
|
900 | + public static function rsEccCodes2($spec) { return $spec[2]; } |
|
901 | + public static function rsDataLength($spec) { return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]); } |
|
902 | + public static function rsEccLength($spec) { return ($spec[0] + $spec[3]) * $spec[2]; } |
|
903 | 903 | |
904 | 904 | } |
905 | 905 | |
@@ -938,7 +938,7 @@ discard block |
||
938 | 938 | class QRimage { |
939 | 939 | |
940 | 940 | //---------------------------------------------------------------------- |
941 | - public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE) |
|
941 | + public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4, $saveandprint = FALSE) |
|
942 | 942 | { |
943 | 943 | $image = self::image($frame, $pixelPerPoint, $outerFrame); |
944 | 944 | |
@@ -949,11 +949,11 @@ discard block |
||
949 | 949 | $output = ob_get_clean(); |
950 | 950 | return $output; |
951 | 951 | } else { |
952 | - if($saveandprint===TRUE){ |
|
952 | + if ($saveandprint === TRUE) { |
|
953 | 953 | ImagePng($image, $filename); |
954 | 954 | header("Content-type: image/png"); |
955 | 955 | ImagePng($image); |
956 | - }else{ |
|
956 | + } else { |
|
957 | 957 | ImagePng($image, $filename); |
958 | 958 | } |
959 | 959 | } |
@@ -982,25 +982,25 @@ discard block |
||
982 | 982 | $h = count($frame); |
983 | 983 | $w = strlen($frame[0]); |
984 | 984 | |
985 | - $imgW = $w + 2*$outerFrame; |
|
986 | - $imgH = $h + 2*$outerFrame; |
|
985 | + $imgW = $w + 2 * $outerFrame; |
|
986 | + $imgH = $h + 2 * $outerFrame; |
|
987 | 987 | |
988 | - $base_image =ImageCreate($imgW, $imgH); |
|
988 | + $base_image = ImageCreate($imgW, $imgH); |
|
989 | 989 | |
990 | - $col[0] = ImageColorAllocate($base_image,255,255,255); |
|
991 | - $col[1] = ImageColorAllocate($base_image,0,0,0); |
|
990 | + $col[0] = ImageColorAllocate($base_image, 255, 255, 255); |
|
991 | + $col[1] = ImageColorAllocate($base_image, 0, 0, 0); |
|
992 | 992 | |
993 | 993 | imagefill($base_image, 0, 0, $col[0]); |
994 | 994 | |
995 | - for($y=0; $y<$h; $y++) { |
|
996 | - for($x=0; $x<$w; $x++) { |
|
995 | + for ($y = 0; $y < $h; $y++) { |
|
996 | + for ($x = 0; $x < $w; $x++) { |
|
997 | 997 | if ($frame[$y][$x] == '1') { |
998 | - ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); |
|
998 | + ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]); |
|
999 | 999 | } |
1000 | 1000 | } |
1001 | 1001 | } |
1002 | 1002 | |
1003 | - $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); |
|
1003 | + $target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); |
|
1004 | 1004 | ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH); |
1005 | 1005 | ImageDestroy($base_image); |
1006 | 1006 | |
@@ -1041,7 +1041,7 @@ discard block |
||
1041 | 1041 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
1042 | 1042 | */ |
1043 | 1043 | |
1044 | - define('STRUCTURE_HEADER_BITS', 20); |
|
1044 | + define('STRUCTURE_HEADER_BITS', 20); |
|
1045 | 1045 | define('MAX_STRUCTURED_SYMBOLS', 16); |
1046 | 1046 | |
1047 | 1047 | class QRinputItem { |
@@ -1056,11 +1056,11 @@ discard block |
||
1056 | 1056 | $setData = array_slice($data, 0, $size); |
1057 | 1057 | |
1058 | 1058 | if (count($setData) < $size) { |
1059 | - $setData = array_merge($setData, array_fill(0,$size-count($setData),0)); |
|
1059 | + $setData = array_merge($setData, array_fill(0, $size - count($setData), 0)); |
|
1060 | 1060 | } |
1061 | 1061 | |
1062 | - if(!QRinput::check($mode, $size, $setData)) { |
|
1063 | - throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',',$setData)); |
|
1062 | + if (!QRinput::check($mode, $size, $setData)) { |
|
1063 | + throw new Exception('Error m:' . $mode . ',s:' . $size . ',d:' . join(',', $setData)); |
|
1064 | 1064 | return null; |
1065 | 1065 | } |
1066 | 1066 | |
@@ -1075,26 +1075,26 @@ discard block |
||
1075 | 1075 | { |
1076 | 1076 | try { |
1077 | 1077 | |
1078 | - $words = (int)($this->size / 3); |
|
1078 | + $words = (int) ($this->size / 3); |
|
1079 | 1079 | $bs = new QRbitstream(); |
1080 | 1080 | |
1081 | 1081 | $val = 0x1; |
1082 | 1082 | $bs->appendNum(4, $val); |
1083 | 1083 | $bs->appendNum(QRspec::lengthIndicator(QR_MODE_NUM, $version), $this->size); |
1084 | 1084 | |
1085 | - for($i=0; $i<$words; $i++) { |
|
1086 | - $val = (ord($this->data[$i*3 ]) - ord('0')) * 100; |
|
1087 | - $val += (ord($this->data[$i*3+1]) - ord('0')) * 10; |
|
1088 | - $val += (ord($this->data[$i*3+2]) - ord('0')); |
|
1085 | + for ($i = 0; $i < $words; $i++) { |
|
1086 | + $val = (ord($this->data[$i * 3]) - ord('0')) * 100; |
|
1087 | + $val += (ord($this->data[$i * 3 + 1]) - ord('0')) * 10; |
|
1088 | + $val += (ord($this->data[$i * 3 + 2]) - ord('0')); |
|
1089 | 1089 | $bs->appendNum(10, $val); |
1090 | 1090 | } |
1091 | 1091 | |
1092 | - if($this->size - $words * 3 == 1) { |
|
1093 | - $val = ord($this->data[$words*3]) - ord('0'); |
|
1092 | + if ($this->size - $words * 3 == 1) { |
|
1093 | + $val = ord($this->data[$words * 3]) - ord('0'); |
|
1094 | 1094 | $bs->appendNum(4, $val); |
1095 | - } else if($this->size - $words * 3 == 2) { |
|
1096 | - $val = (ord($this->data[$words*3 ]) - ord('0')) * 10; |
|
1097 | - $val += (ord($this->data[$words*3+1]) - ord('0')); |
|
1095 | + } else if ($this->size - $words * 3 == 2) { |
|
1096 | + $val = (ord($this->data[$words * 3]) - ord('0')) * 10; |
|
1097 | + $val += (ord($this->data[$words * 3 + 1]) - ord('0')); |
|
1098 | 1098 | $bs->appendNum(7, $val); |
1099 | 1099 | } |
1100 | 1100 | |
@@ -1110,20 +1110,20 @@ discard block |
||
1110 | 1110 | public function encodeModeAn($version) |
1111 | 1111 | { |
1112 | 1112 | try { |
1113 | - $words = (int)($this->size / 2); |
|
1113 | + $words = (int) ($this->size / 2); |
|
1114 | 1114 | $bs = new QRbitstream(); |
1115 | 1115 | |
1116 | 1116 | $bs->appendNum(4, 0x02); |
1117 | 1117 | $bs->appendNum(QRspec::lengthIndicator(QR_MODE_AN, $version), $this->size); |
1118 | 1118 | |
1119 | - for($i=0; $i<$words; $i++) { |
|
1120 | - $val = (int)QRinput::lookAnTable(ord($this->data[$i*2 ])) * 45; |
|
1121 | - $val += (int)QRinput::lookAnTable(ord($this->data[$i*2+1])); |
|
1119 | + for ($i = 0; $i < $words; $i++) { |
|
1120 | + $val = (int) QRinput::lookAnTable(ord($this->data[$i * 2])) * 45; |
|
1121 | + $val += (int) QRinput::lookAnTable(ord($this->data[$i * 2 + 1])); |
|
1122 | 1122 | |
1123 | 1123 | $bs->appendNum(11, $val); |
1124 | 1124 | } |
1125 | 1125 | |
1126 | - if($this->size & 1) { |
|
1126 | + if ($this->size & 1) { |
|
1127 | 1127 | $val = QRinput::lookAnTable(ord($this->data[$words * 2])); |
1128 | 1128 | $bs->appendNum(6, $val); |
1129 | 1129 | } |
@@ -1145,7 +1145,7 @@ discard block |
||
1145 | 1145 | $bs->appendNum(4, 0x4); |
1146 | 1146 | $bs->appendNum(QRspec::lengthIndicator(QR_MODE_8, $version), $this->size); |
1147 | 1147 | |
1148 | - for($i=0; $i<$this->size; $i++) { |
|
1148 | + for ($i = 0; $i < $this->size; $i++) { |
|
1149 | 1149 | $bs->appendNum(8, ord($this->data[$i])); |
1150 | 1150 | } |
1151 | 1151 | |
@@ -1165,11 +1165,11 @@ discard block |
||
1165 | 1165 | $bs = new QRbitrtream(); |
1166 | 1166 | |
1167 | 1167 | $bs->appendNum(4, 0x8); |
1168 | - $bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int)($this->size / 2)); |
|
1168 | + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int) ($this->size / 2)); |
|
1169 | 1169 | |
1170 | - for($i=0; $i<$this->size; $i+=2) { |
|
1171 | - $val = (ord($this->data[$i]) << 8) | ord($this->data[$i+1]); |
|
1172 | - if($val <= 0x9ffc) { |
|
1170 | + for ($i = 0; $i < $this->size; $i += 2) { |
|
1171 | + $val = (ord($this->data[$i]) << 8) | ord($this->data[$i + 1]); |
|
1172 | + if ($val <= 0x9ffc) { |
|
1173 | 1173 | $val -= 0x8140; |
1174 | 1174 | } else { |
1175 | 1175 | $val -= 0xc140; |
@@ -1193,7 +1193,7 @@ discard block |
||
1193 | 1193 | public function encodeModeStructure() |
1194 | 1194 | { |
1195 | 1195 | try { |
1196 | - $bs = new QRbitstream(); |
|
1196 | + $bs = new QRbitstream(); |
|
1197 | 1197 | |
1198 | 1198 | $bs->appendNum(4, 0x03); |
1199 | 1199 | $bs->appendNum(4, ord($this->data[1]) - 1); |
@@ -1213,14 +1213,14 @@ discard block |
||
1213 | 1213 | { |
1214 | 1214 | $bits = 0; |
1215 | 1215 | |
1216 | - if($version == 0) |
|
1216 | + if ($version == 0) |
|
1217 | 1217 | $version = 1; |
1218 | 1218 | |
1219 | - switch($this->mode) { |
|
1220 | - case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; |
|
1221 | - case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break; |
|
1222 | - case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break; |
|
1223 | - case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size);break; |
|
1219 | + switch ($this->mode) { |
|
1220 | + case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; |
|
1221 | + case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break; |
|
1222 | + case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break; |
|
1223 | + case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size); break; |
|
1224 | 1224 | case QR_MODE_STRUCTURE: return STRUCTURE_HEADER_BITS; |
1225 | 1225 | default: |
1226 | 1226 | return 0; |
@@ -1228,7 +1228,7 @@ discard block |
||
1228 | 1228 | |
1229 | 1229 | $l = QRspec::lengthIndicator($this->mode, $version); |
1230 | 1230 | $m = 1 << $l; |
1231 | - $num = (int)(($this->size + $m - 1) / $m); |
|
1231 | + $num = (int) (($this->size + $m - 1) / $m); |
|
1232 | 1232 | |
1233 | 1233 | $bits += $num * (4 + $l); |
1234 | 1234 | |
@@ -1243,7 +1243,7 @@ discard block |
||
1243 | 1243 | unset($this->bstream); |
1244 | 1244 | $words = QRspec::maximumWords($this->mode, $version); |
1245 | 1245 | |
1246 | - if($this->size > $words) { |
|
1246 | + if ($this->size > $words) { |
|
1247 | 1247 | |
1248 | 1248 | $st1 = new QRinputItem($this->mode, $words, $this->data); |
1249 | 1249 | $st2 = new QRinputItem($this->mode, $this->size - $words, array_slice($this->data, $words)); |
@@ -1262,18 +1262,18 @@ discard block |
||
1262 | 1262 | |
1263 | 1263 | $ret = 0; |
1264 | 1264 | |
1265 | - switch($this->mode) { |
|
1266 | - case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break; |
|
1267 | - case QR_MODE_AN: $ret = $this->encodeModeAn($version); break; |
|
1268 | - case QR_MODE_8: $ret = $this->encodeMode8($version); break; |
|
1269 | - case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version);break; |
|
1270 | - case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break; |
|
1265 | + switch ($this->mode) { |
|
1266 | + case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break; |
|
1267 | + case QR_MODE_AN: $ret = $this->encodeModeAn($version); break; |
|
1268 | + case QR_MODE_8: $ret = $this->encodeMode8($version); break; |
|
1269 | + case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version); break; |
|
1270 | + case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break; |
|
1271 | 1271 | |
1272 | 1272 | default: |
1273 | 1273 | break; |
1274 | 1274 | } |
1275 | 1275 | |
1276 | - if($ret < 0) |
|
1276 | + if ($ret < 0) |
|
1277 | 1277 | return -1; |
1278 | 1278 | } |
1279 | 1279 | |
@@ -1315,7 +1315,7 @@ discard block |
||
1315 | 1315 | //---------------------------------------------------------------------- |
1316 | 1316 | public function setVersion($version) |
1317 | 1317 | { |
1318 | - if($version < 0 || $version > QRSPEC_VERSION_MAX) { |
|
1318 | + if ($version < 0 || $version > QRSPEC_VERSION_MAX) { |
|
1319 | 1319 | throw new Exception('Invalid version no'); |
1320 | 1320 | return -1; |
1321 | 1321 | } |
@@ -1334,7 +1334,7 @@ discard block |
||
1334 | 1334 | //---------------------------------------------------------------------- |
1335 | 1335 | public function setErrorCorrectionLevel($level) |
1336 | 1336 | { |
1337 | - if($level > QR_ECLEVEL_H) { |
|
1337 | + if ($level > QR_ECLEVEL_H) { |
|
1338 | 1338 | throw new Exception('Invalid ECLEVEL'); |
1339 | 1339 | return -1; |
1340 | 1340 | } |
@@ -1366,11 +1366,11 @@ discard block |
||
1366 | 1366 | |
1367 | 1367 | public function insertStructuredAppendHeader($size, $index, $parity) |
1368 | 1368 | { |
1369 | - if( $size > MAX_STRUCTURED_SYMBOLS ) { |
|
1369 | + if ($size > MAX_STRUCTURED_SYMBOLS) { |
|
1370 | 1370 | throw new Exception('insertStructuredAppendHeader wrong size'); |
1371 | 1371 | } |
1372 | 1372 | |
1373 | - if( $index <= 0 || $index > MAX_STRUCTURED_SYMBOLS ) { |
|
1373 | + if ($index <= 0 || $index > MAX_STRUCTURED_SYMBOLS) { |
|
1374 | 1374 | throw new Exception('insertStructuredAppendHeader wrong index'); |
1375 | 1375 | } |
1376 | 1376 | |
@@ -1390,9 +1390,9 @@ discard block |
||
1390 | 1390 | { |
1391 | 1391 | $parity = 0; |
1392 | 1392 | |
1393 | - foreach($this->items as $item) { |
|
1394 | - if($item->mode != QR_MODE_STRUCTURE) { |
|
1395 | - for($i=$item->size-1; $i>=0; $i--) { |
|
1393 | + foreach ($this->items as $item) { |
|
1394 | + if ($item->mode != QR_MODE_STRUCTURE) { |
|
1395 | + for ($i = $item->size - 1; $i >= 0; $i--) { |
|
1396 | 1396 | $parity ^= $item->data[$i]; |
1397 | 1397 | } |
1398 | 1398 | } |
@@ -1404,8 +1404,8 @@ discard block |
||
1404 | 1404 | //---------------------------------------------------------------------- |
1405 | 1405 | public static function checkModeNum($size, $data) |
1406 | 1406 | { |
1407 | - for($i=0; $i<$size; $i++) { |
|
1408 | - if((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))){ |
|
1407 | + for ($i = 0; $i < $size; $i++) { |
|
1408 | + if ((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))) { |
|
1409 | 1409 | return false; |
1410 | 1410 | } |
1411 | 1411 | } |
@@ -1416,10 +1416,10 @@ discard block |
||
1416 | 1416 | //---------------------------------------------------------------------- |
1417 | 1417 | public static function estimateBitsModeNum($size) |
1418 | 1418 | { |
1419 | - $w = (int)$size / 3; |
|
1419 | + $w = (int) $size / 3; |
|
1420 | 1420 | $bits = $w * 10; |
1421 | 1421 | |
1422 | - switch($size - $w * 3) { |
|
1422 | + switch ($size - $w * 3) { |
|
1423 | 1423 | case 1: |
1424 | 1424 | $bits += 4; |
1425 | 1425 | break; |
@@ -1438,7 +1438,7 @@ discard block |
||
1438 | 1438 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
1439 | 1439 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
1440 | 1440 | 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, |
1441 | - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
|
1441 | + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
|
1442 | 1442 | -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
1443 | 1443 | 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, |
1444 | 1444 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
@@ -1448,13 +1448,13 @@ discard block |
||
1448 | 1448 | //---------------------------------------------------------------------- |
1449 | 1449 | public static function lookAnTable($c) |
1450 | 1450 | { |
1451 | - return (($c > 127)?-1:self::$anTable[$c]); |
|
1451 | + return (($c > 127) ?-1 : self::$anTable[$c]); |
|
1452 | 1452 | } |
1453 | 1453 | |
1454 | 1454 | //---------------------------------------------------------------------- |
1455 | 1455 | public static function checkModeAn($size, $data) |
1456 | 1456 | { |
1457 | - for($i=0; $i<$size; $i++) { |
|
1457 | + for ($i = 0; $i < $size; $i++) { |
|
1458 | 1458 | if (self::lookAnTable(ord($data[$i])) == -1) { |
1459 | 1459 | return false; |
1460 | 1460 | } |
@@ -1466,10 +1466,10 @@ discard block |
||
1466 | 1466 | //---------------------------------------------------------------------- |
1467 | 1467 | public static function estimateBitsModeAn($size) |
1468 | 1468 | { |
1469 | - $w = (int)($size / 2); |
|
1469 | + $w = (int) ($size / 2); |
|
1470 | 1470 | $bits = $w * 11; |
1471 | 1471 | |
1472 | - if($size & 1) { |
|
1472 | + if ($size & 1) { |
|
1473 | 1473 | $bits += 6; |
1474 | 1474 | } |
1475 | 1475 | |
@@ -1485,18 +1485,18 @@ discard block |
||
1485 | 1485 | //---------------------------------------------------------------------- |
1486 | 1486 | public function estimateBitsModeKanji($size) |
1487 | 1487 | { |
1488 | - return (int)(($size / 2) * 13); |
|
1488 | + return (int) (($size / 2) * 13); |
|
1489 | 1489 | } |
1490 | 1490 | |
1491 | 1491 | //---------------------------------------------------------------------- |
1492 | 1492 | public static function checkModeKanji($size, $data) |
1493 | 1493 | { |
1494 | - if($size & 1) |
|
1494 | + if ($size & 1) |
|
1495 | 1495 | return false; |
1496 | 1496 | |
1497 | - for($i=0; $i<$size; $i+=2) { |
|
1498 | - $val = (ord($data[$i]) << 8) | ord($data[$i+1]); |
|
1499 | - if( $val < 0x8140 |
|
1497 | + for ($i = 0; $i < $size; $i += 2) { |
|
1498 | + $val = (ord($data[$i]) << 8) | ord($data[$i + 1]); |
|
1499 | + if ($val < 0x8140 |
|
1500 | 1500 | || ($val > 0x9ffc && $val < 0xe040) |
1501 | 1501 | || $val > 0xebbf) { |
1502 | 1502 | return false; |
@@ -1512,12 +1512,12 @@ discard block |
||
1512 | 1512 | |
1513 | 1513 | public static function check($mode, $size, $data) |
1514 | 1514 | { |
1515 | - if($size <= 0) |
|
1515 | + if ($size <= 0) |
|
1516 | 1516 | return false; |
1517 | 1517 | |
1518 | - switch($mode) { |
|
1519 | - case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
|
1520 | - case QR_MODE_AN: return self::checkModeAn($size, $data); break; |
|
1518 | + switch ($mode) { |
|
1519 | + case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
|
1520 | + case QR_MODE_AN: return self::checkModeAn($size, $data); break; |
|
1521 | 1521 | case QR_MODE_KANJI: return self::checkModeKanji($size, $data); break; |
1522 | 1522 | case QR_MODE_8: return true; break; |
1523 | 1523 | case QR_MODE_STRUCTURE: return true; break; |
@@ -1535,7 +1535,7 @@ discard block |
||
1535 | 1535 | { |
1536 | 1536 | $bits = 0; |
1537 | 1537 | |
1538 | - foreach($this->items as $item) { |
|
1538 | + foreach ($this->items as $item) { |
|
1539 | 1539 | $bits += $item->estimateBitStreamSizeOfEntry($version); |
1540 | 1540 | } |
1541 | 1541 | |
@@ -1550,7 +1550,7 @@ discard block |
||
1550 | 1550 | do { |
1551 | 1551 | $prev = $version; |
1552 | 1552 | $bits = $this->estimateBitStreamSize($prev); |
1553 | - $version = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
|
1553 | + $version = QRspec::getMinimumVersion((int) (($bits + 7) / 8), $this->level); |
|
1554 | 1554 | if ($version < 0) { |
1555 | 1555 | return -1; |
1556 | 1556 | } |
@@ -1563,32 +1563,32 @@ discard block |
||
1563 | 1563 | public static function lengthOfCode($mode, $version, $bits) |
1564 | 1564 | { |
1565 | 1565 | $payload = $bits - 4 - QRspec::lengthIndicator($mode, $version); |
1566 | - switch($mode) { |
|
1566 | + switch ($mode) { |
|
1567 | 1567 | case QR_MODE_NUM: |
1568 | - $chunks = (int)($payload / 10); |
|
1568 | + $chunks = (int) ($payload / 10); |
|
1569 | 1569 | $remain = $payload - $chunks * 10; |
1570 | 1570 | $size = $chunks * 3; |
1571 | - if($remain >= 7) { |
|
1571 | + if ($remain >= 7) { |
|
1572 | 1572 | $size += 2; |
1573 | - } else if($remain >= 4) { |
|
1573 | + } else if ($remain >= 4) { |
|
1574 | 1574 | $size += 1; |
1575 | 1575 | } |
1576 | 1576 | break; |
1577 | 1577 | case QR_MODE_AN: |
1578 | - $chunks = (int)($payload / 11); |
|
1578 | + $chunks = (int) ($payload / 11); |
|
1579 | 1579 | $remain = $payload - $chunks * 11; |
1580 | 1580 | $size = $chunks * 2; |
1581 | - if($remain >= 6) |
|
1581 | + if ($remain >= 6) |
|
1582 | 1582 | $size++; |
1583 | 1583 | break; |
1584 | 1584 | case QR_MODE_8: |
1585 | - $size = (int)($payload / 8); |
|
1585 | + $size = (int) ($payload / 8); |
|
1586 | 1586 | break; |
1587 | 1587 | case QR_MODE_KANJI: |
1588 | - $size = (int)(($payload / 13) * 2); |
|
1588 | + $size = (int) (($payload / 13) * 2); |
|
1589 | 1589 | break; |
1590 | 1590 | case QR_MODE_STRUCTURE: |
1591 | - $size = (int)($payload / 8); |
|
1591 | + $size = (int) ($payload / 8); |
|
1592 | 1592 | break; |
1593 | 1593 | default: |
1594 | 1594 | $size = 0; |
@@ -1596,8 +1596,8 @@ discard block |
||
1596 | 1596 | } |
1597 | 1597 | |
1598 | 1598 | $maxsize = QRspec::maximumWords($mode, $version); |
1599 | - if($size < 0) $size = 0; |
|
1600 | - if($size > $maxsize) $size = $maxsize; |
|
1599 | + if ($size < 0) $size = 0; |
|
1600 | + if ($size > $maxsize) $size = $maxsize; |
|
1601 | 1601 | |
1602 | 1602 | return $size; |
1603 | 1603 | } |
@@ -1607,10 +1607,10 @@ discard block |
||
1607 | 1607 | { |
1608 | 1608 | $total = 0; |
1609 | 1609 | |
1610 | - foreach($this->items as $item) { |
|
1610 | + foreach ($this->items as $item) { |
|
1611 | 1611 | $bits = $item->encodeBitStream($this->version); |
1612 | 1612 | |
1613 | - if($bits < 0) |
|
1613 | + if ($bits < 0) |
|
1614 | 1614 | return -1; |
1615 | 1615 | |
1616 | 1616 | $total += $bits; |
@@ -1623,21 +1623,21 @@ discard block |
||
1623 | 1623 | public function convertData() |
1624 | 1624 | { |
1625 | 1625 | $ver = $this->estimateVersion(); |
1626 | - if($ver > $this->getVersion()) { |
|
1626 | + if ($ver > $this->getVersion()) { |
|
1627 | 1627 | $this->setVersion($ver); |
1628 | 1628 | } |
1629 | 1629 | |
1630 | - for(;;) { |
|
1630 | + for (;;) { |
|
1631 | 1631 | $bits = $this->createBitStream(); |
1632 | 1632 | |
1633 | - if($bits < 0) |
|
1633 | + if ($bits < 0) |
|
1634 | 1634 | return -1; |
1635 | 1635 | |
1636 | - $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
|
1637 | - if($ver < 0) { |
|
1636 | + $ver = QRspec::getMinimumVersion((int) (($bits + 7) / 8), $this->level); |
|
1637 | + if ($ver < 0) { |
|
1638 | 1638 | throw new Exception('WRONG VERSION'); |
1639 | 1639 | return -1; |
1640 | - } else if($ver > $this->getVersion()) { |
|
1640 | + } else if ($ver > $this->getVersion()) { |
|
1641 | 1641 | $this->setVersion($ver); |
1642 | 1642 | } else { |
1643 | 1643 | break; |
@@ -1663,26 +1663,26 @@ discard block |
||
1663 | 1663 | } |
1664 | 1664 | |
1665 | 1665 | $bits += 4; |
1666 | - $words = (int)(($bits + 7) / 8); |
|
1666 | + $words = (int) (($bits + 7) / 8); |
|
1667 | 1667 | |
1668 | 1668 | $padding = new QRbitstream(); |
1669 | 1669 | $ret = $padding->appendNum($words * 8 - $bits + 4, 0); |
1670 | 1670 | |
1671 | - if($ret < 0) |
|
1671 | + if ($ret < 0) |
|
1672 | 1672 | return $ret; |
1673 | 1673 | |
1674 | 1674 | $padlen = $maxwords - $words; |
1675 | 1675 | |
1676 | - if($padlen > 0) { |
|
1676 | + if ($padlen > 0) { |
|
1677 | 1677 | |
1678 | 1678 | $padbuf = []; |
1679 | - for($i=0; $i<$padlen; $i++) { |
|
1680 | - $padbuf[$i] = ($i&1)?0x11:0xec; |
|
1679 | + for ($i = 0; $i < $padlen; $i++) { |
|
1680 | + $padbuf[$i] = ($i & 1) ? 0x11 : 0xec; |
|
1681 | 1681 | } |
1682 | 1682 | |
1683 | 1683 | $ret = $padding->appendBytes($padlen, $padbuf); |
1684 | 1684 | |
1685 | - if($ret < 0) |
|
1685 | + if ($ret < 0) |
|
1686 | 1686 | return $ret; |
1687 | 1687 | |
1688 | 1688 | } |
@@ -1695,15 +1695,15 @@ discard block |
||
1695 | 1695 | //---------------------------------------------------------------------- |
1696 | 1696 | public function mergeBitStream() |
1697 | 1697 | { |
1698 | - if($this->convertData() < 0) { |
|
1698 | + if ($this->convertData() < 0) { |
|
1699 | 1699 | return null; |
1700 | 1700 | } |
1701 | 1701 | |
1702 | 1702 | $bstream = new QRbitstream(); |
1703 | 1703 | |
1704 | - foreach($this->items as $item) { |
|
1704 | + foreach ($this->items as $item) { |
|
1705 | 1705 | $ret = $bstream->append($item->bstream); |
1706 | - if($ret < 0) { |
|
1706 | + if ($ret < 0) { |
|
1707 | 1707 | return null; |
1708 | 1708 | } |
1709 | 1709 | } |
@@ -1717,12 +1717,12 @@ discard block |
||
1717 | 1717 | |
1718 | 1718 | $bstream = $this->mergeBitStream(); |
1719 | 1719 | |
1720 | - if($bstream == null) { |
|
1720 | + if ($bstream == null) { |
|
1721 | 1721 | return null; |
1722 | 1722 | } |
1723 | 1723 | |
1724 | 1724 | $ret = $this->appendPaddingBit($bstream); |
1725 | - if($ret < 0) { |
|
1725 | + if ($ret < 0) { |
|
1726 | 1726 | return null; |
1727 | 1727 | } |
1728 | 1728 | |
@@ -1733,7 +1733,7 @@ discard block |
||
1733 | 1733 | public function getByteStream() |
1734 | 1734 | { |
1735 | 1735 | $bstream = $this->getBitStream(); |
1736 | - if($bstream == null) { |
|
1736 | + if ($bstream == null) { |
|
1737 | 1737 | return null; |
1738 | 1738 | } |
1739 | 1739 | |
@@ -1801,8 +1801,8 @@ discard block |
||
1801 | 1801 | $bstream->allocate($bits); |
1802 | 1802 | |
1803 | 1803 | $mask = 1 << ($bits - 1); |
1804 | - for($i=0; $i<$bits; $i++) { |
|
1805 | - if($num & $mask) { |
|
1804 | + for ($i = 0; $i < $bits; $i++) { |
|
1805 | + if ($num & $mask) { |
|
1806 | 1806 | $bstream->data[$i] = 1; |
1807 | 1807 | } else { |
1808 | 1808 | $bstream->data[$i] = 0; |
@@ -1818,12 +1818,12 @@ discard block |
||
1818 | 1818 | { |
1819 | 1819 | $bstream = new QRbitstream(); |
1820 | 1820 | $bstream->allocate($size * 8); |
1821 | - $p=0; |
|
1821 | + $p = 0; |
|
1822 | 1822 | |
1823 | - for($i=0; $i<$size; $i++) { |
|
1823 | + for ($i = 0; $i < $size; $i++) { |
|
1824 | 1824 | $mask = 0x80; |
1825 | - for($j=0; $j<8; $j++) { |
|
1826 | - if($data[$i] & $mask) { |
|
1825 | + for ($j = 0; $j < 8; $j++) { |
|
1826 | + if ($data[$i] & $mask) { |
|
1827 | 1827 | $bstream->data[$p] = 1; |
1828 | 1828 | } else { |
1829 | 1829 | $bstream->data[$p] = 0; |
@@ -1843,11 +1843,11 @@ discard block |
||
1843 | 1843 | return -1; |
1844 | 1844 | } |
1845 | 1845 | |
1846 | - if($arg->size() == 0) { |
|
1846 | + if ($arg->size() == 0) { |
|
1847 | 1847 | return 0; |
1848 | 1848 | } |
1849 | 1849 | |
1850 | - if($this->size() == 0) { |
|
1850 | + if ($this->size() == 0) { |
|
1851 | 1851 | $this->data = $arg->data; |
1852 | 1852 | return 0; |
1853 | 1853 | } |
@@ -1865,7 +1865,7 @@ discard block |
||
1865 | 1865 | |
1866 | 1866 | $b = QRbitstream::newFromNum($bits, $num); |
1867 | 1867 | |
1868 | - if(is_null($b)) |
|
1868 | + if (is_null($b)) |
|
1869 | 1869 | return -1; |
1870 | 1870 | |
1871 | 1871 | $ret = $this->append($b); |
@@ -1882,7 +1882,7 @@ discard block |
||
1882 | 1882 | |
1883 | 1883 | $b = QRbitstream::newFromBytes($size, $data); |
1884 | 1884 | |
1885 | - if(is_null($b)) |
|
1885 | + if (is_null($b)) |
|
1886 | 1886 | return -1; |
1887 | 1887 | |
1888 | 1888 | $ret = $this->append($b); |
@@ -1897,18 +1897,18 @@ discard block |
||
1897 | 1897 | |
1898 | 1898 | $size = $this->size(); |
1899 | 1899 | |
1900 | - if($size == 0) { |
|
1900 | + if ($size == 0) { |
|
1901 | 1901 | return []; |
1902 | 1902 | } |
1903 | 1903 | |
1904 | - $data = array_fill(0, (int)(($size + 7) / 8), 0); |
|
1905 | - $bytes = (int)($size / 8); |
|
1904 | + $data = array_fill(0, (int) (($size + 7) / 8), 0); |
|
1905 | + $bytes = (int) ($size / 8); |
|
1906 | 1906 | |
1907 | 1907 | $p = 0; |
1908 | 1908 | |
1909 | - for($i=0; $i<$bytes; $i++) { |
|
1909 | + for ($i = 0; $i < $bytes; $i++) { |
|
1910 | 1910 | $v = 0; |
1911 | - for($j=0; $j<8; $j++) { |
|
1911 | + for ($j = 0; $j < 8; $j++) { |
|
1912 | 1912 | $v = $v << 1; |
1913 | 1913 | $v |= $this->data[$p]; |
1914 | 1914 | $p++; |
@@ -1916,9 +1916,9 @@ discard block |
||
1916 | 1916 | $data[$i] = $v; |
1917 | 1917 | } |
1918 | 1918 | |
1919 | - if($size & 7) { |
|
1919 | + if ($size & 7) { |
|
1920 | 1920 | $v = 0; |
1921 | - for($j=0; $j<($size & 7); $j++) { |
|
1921 | + for ($j = 0; $j < ($size & 7); $j++) { |
|
1922 | 1922 | $v = $v << 1; |
1923 | 1923 | $v |= $this->data[$p]; |
1924 | 1924 | $p++; |
@@ -1990,7 +1990,7 @@ discard block |
||
1990 | 1990 | if ($pos >= strlen($str)) |
1991 | 1991 | return false; |
1992 | 1992 | |
1993 | - return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9'))); |
|
1993 | + return ((ord($str[$pos]) >= ord('0')) && (ord($str[$pos]) <= ord('9'))); |
|
1994 | 1994 | } |
1995 | 1995 | |
1996 | 1996 | //---------------------------------------------------------------------- |
@@ -2010,17 +2010,17 @@ discard block |
||
2010 | 2010 | |
2011 | 2011 | $c = $this->dataStr[$pos]; |
2012 | 2012 | |
2013 | - if(self::isdigitat($this->dataStr, $pos)) { |
|
2013 | + if (self::isdigitat($this->dataStr, $pos)) { |
|
2014 | 2014 | return QR_MODE_NUM; |
2015 | - } else if(self::isalnumat($this->dataStr, $pos)) { |
|
2015 | + } else if (self::isalnumat($this->dataStr, $pos)) { |
|
2016 | 2016 | return QR_MODE_AN; |
2017 | - } else if($this->modeHint == QR_MODE_KANJI) { |
|
2017 | + } else if ($this->modeHint == QR_MODE_KANJI) { |
|
2018 | 2018 | |
2019 | - if ($pos+1 < strlen($this->dataStr)) |
|
2019 | + if ($pos + 1 < strlen($this->dataStr)) |
|
2020 | 2020 | { |
2021 | - $d = $this->dataStr[$pos+1]; |
|
2021 | + $d = $this->dataStr[$pos + 1]; |
|
2022 | 2022 | $word = (ord($c) << 8) | ord($d); |
2023 | - if(($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) { |
|
2023 | + if (($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) { |
|
2024 | 2024 | return QR_MODE_KANJI; |
2025 | 2025 | } |
2026 | 2026 | } |
@@ -2035,32 +2035,32 @@ discard block |
||
2035 | 2035 | $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); |
2036 | 2036 | |
2037 | 2037 | $p = 0; |
2038 | - while(self::isdigitat($this->dataStr, $p)) { |
|
2038 | + while (self::isdigitat($this->dataStr, $p)) { |
|
2039 | 2039 | $p++; |
2040 | 2040 | } |
2041 | 2041 | |
2042 | 2042 | $run = $p; |
2043 | 2043 | $mode = $this->identifyMode($p); |
2044 | 2044 | |
2045 | - if($mode == QR_MODE_8) { |
|
2045 | + if ($mode == QR_MODE_8) { |
|
2046 | 2046 | $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln |
2047 | 2047 | + QRinput::estimateBitsMode8(1) // + 4 + l8 |
2048 | 2048 | - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 |
2049 | - if($dif > 0) { |
|
2049 | + if ($dif > 0) { |
|
2050 | 2050 | return $this->eat8(); |
2051 | 2051 | } |
2052 | 2052 | } |
2053 | - if($mode == QR_MODE_AN) { |
|
2053 | + if ($mode == QR_MODE_AN) { |
|
2054 | 2054 | $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln |
2055 | 2055 | + QRinput::estimateBitsModeAn(1) // + 4 + la |
2056 | - - QRinput::estimateBitsModeAn($run + 1);// - 4 - la |
|
2057 | - if($dif > 0) { |
|
2056 | + - QRinput::estimateBitsModeAn($run + 1); // - 4 - la |
|
2057 | + if ($dif > 0) { |
|
2058 | 2058 | return $this->eatAn(); |
2059 | 2059 | } |
2060 | 2060 | } |
2061 | 2061 | |
2062 | 2062 | $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr)); |
2063 | - if($ret < 0) |
|
2063 | + if ($ret < 0) |
|
2064 | 2064 | return -1; |
2065 | 2065 | |
2066 | 2066 | return $run; |
@@ -2069,15 +2069,15 @@ discard block |
||
2069 | 2069 | //---------------------------------------------------------------------- |
2070 | 2070 | public function eatAn() |
2071 | 2071 | { |
2072 | - $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); |
|
2072 | + $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); |
|
2073 | 2073 | $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); |
2074 | 2074 | |
2075 | 2075 | $p = 0; |
2076 | 2076 | |
2077 | - while(self::isalnumat($this->dataStr, $p)) { |
|
2078 | - if(self::isdigitat($this->dataStr, $p)) { |
|
2077 | + while (self::isalnumat($this->dataStr, $p)) { |
|
2078 | + if (self::isdigitat($this->dataStr, $p)) { |
|
2079 | 2079 | $q = $p; |
2080 | - while(self::isdigitat($this->dataStr, $q)) { |
|
2080 | + while (self::isdigitat($this->dataStr, $q)) { |
|
2081 | 2081 | $q++; |
2082 | 2082 | } |
2083 | 2083 | |
@@ -2085,7 +2085,7 @@ discard block |
||
2085 | 2085 | + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln |
2086 | 2086 | - QRinput::estimateBitsModeAn($q); // - 4 - la |
2087 | 2087 | |
2088 | - if($dif < 0) { |
|
2088 | + if ($dif < 0) { |
|
2089 | 2089 | break; |
2090 | 2090 | } else { |
2091 | 2091 | $p = $q; |
@@ -2097,17 +2097,17 @@ discard block |
||
2097 | 2097 | |
2098 | 2098 | $run = $p; |
2099 | 2099 | |
2100 | - if(!self::isalnumat($this->dataStr, $p)) { |
|
2100 | + if (!self::isalnumat($this->dataStr, $p)) { |
|
2101 | 2101 | $dif = QRinput::estimateBitsModeAn($run) + 4 + $la |
2102 | 2102 | + QRinput::estimateBitsMode8(1) // + 4 + l8 |
2103 | 2103 | - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 |
2104 | - if($dif > 0) { |
|
2104 | + if ($dif > 0) { |
|
2105 | 2105 | return $this->eat8(); |
2106 | 2106 | } |
2107 | 2107 | } |
2108 | 2108 | |
2109 | 2109 | $ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr)); |
2110 | - if($ret < 0) |
|
2110 | + if ($ret < 0) |
|
2111 | 2111 | return -1; |
2112 | 2112 | |
2113 | 2113 | return $run; |
@@ -2118,12 +2118,12 @@ discard block |
||
2118 | 2118 | { |
2119 | 2119 | $p = 0; |
2120 | 2120 | |
2121 | - while($this->identifyMode($p) == QR_MODE_KANJI) { |
|
2121 | + while ($this->identifyMode($p) == QR_MODE_KANJI) { |
|
2122 | 2122 | $p += 2; |
2123 | 2123 | } |
2124 | 2124 | |
2125 | 2125 | $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr)); |
2126 | - if($ret < 0) |
|
2126 | + if ($ret < 0) |
|
2127 | 2127 | return -1; |
2128 | 2128 | |
2129 | 2129 | return $run; |
@@ -2138,34 +2138,34 @@ discard block |
||
2138 | 2138 | $p = 1; |
2139 | 2139 | $dataStrLen = strlen($this->dataStr); |
2140 | 2140 | |
2141 | - while($p < $dataStrLen) { |
|
2141 | + while ($p < $dataStrLen) { |
|
2142 | 2142 | |
2143 | 2143 | $mode = $this->identifyMode($p); |
2144 | - if($mode == QR_MODE_KANJI) { |
|
2144 | + if ($mode == QR_MODE_KANJI) { |
|
2145 | 2145 | break; |
2146 | 2146 | } |
2147 | - if($mode == QR_MODE_NUM) { |
|
2147 | + if ($mode == QR_MODE_NUM) { |
|
2148 | 2148 | $q = $p; |
2149 | - while(self::isdigitat($this->dataStr, $q)) { |
|
2149 | + while (self::isdigitat($this->dataStr, $q)) { |
|
2150 | 2150 | $q++; |
2151 | 2151 | } |
2152 | 2152 | $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 |
2153 | 2153 | + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln |
2154 | 2154 | - QRinput::estimateBitsMode8($q); // - 4 - l8 |
2155 | - if($dif < 0) { |
|
2155 | + if ($dif < 0) { |
|
2156 | 2156 | break; |
2157 | 2157 | } else { |
2158 | 2158 | $p = $q; |
2159 | 2159 | } |
2160 | - } else if($mode == QR_MODE_AN) { |
|
2160 | + } else if ($mode == QR_MODE_AN) { |
|
2161 | 2161 | $q = $p; |
2162 | - while(self::isalnumat($this->dataStr, $q)) { |
|
2162 | + while (self::isalnumat($this->dataStr, $q)) { |
|
2163 | 2163 | $q++; |
2164 | 2164 | } |
2165 | 2165 | $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 |
2166 | 2166 | + QRinput::estimateBitsModeAn($q - $p) + 4 + $la |
2167 | 2167 | - QRinput::estimateBitsMode8($q); // - 4 - l8 |
2168 | - if($dif < 0) { |
|
2168 | + if ($dif < 0) { |
|
2169 | 2169 | break; |
2170 | 2170 | } else { |
2171 | 2171 | $p = $q; |
@@ -2178,7 +2178,7 @@ discard block |
||
2178 | 2178 | $run = $p; |
2179 | 2179 | $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr)); |
2180 | 2180 | |
2181 | - if($ret < 0) |
|
2181 | + if ($ret < 0) |
|
2182 | 2182 | return -1; |
2183 | 2183 | |
2184 | 2184 | return $run; |
@@ -2189,7 +2189,7 @@ discard block |
||
2189 | 2189 | { |
2190 | 2190 | while (strlen($this->dataStr) > 0) |
2191 | 2191 | { |
2192 | - if($this->dataStr == '') |
|
2192 | + if ($this->dataStr == '') |
|
2193 | 2193 | return 0; |
2194 | 2194 | |
2195 | 2195 | $mode = $this->identifyMode(0); |
@@ -2206,8 +2206,8 @@ discard block |
||
2206 | 2206 | |
2207 | 2207 | } |
2208 | 2208 | |
2209 | - if($length == 0) return 0; |
|
2210 | - if($length < 0) return -1; |
|
2209 | + if ($length == 0) return 0; |
|
2210 | + if ($length < 0) return -1; |
|
2211 | 2211 | |
2212 | 2212 | $this->dataStr = substr($this->dataStr, $length); |
2213 | 2213 | } |
@@ -2219,9 +2219,9 @@ discard block |
||
2219 | 2219 | $stringLen = strlen($this->dataStr); |
2220 | 2220 | $p = 0; |
2221 | 2221 | |
2222 | - while ($p<$stringLen) { |
|
2222 | + while ($p < $stringLen) { |
|
2223 | 2223 | $mode = self::identifyMode(substr($this->dataStr, $p), $this->modeHint); |
2224 | - if($mode == QR_MODE_KANJI) { |
|
2224 | + if ($mode == QR_MODE_KANJI) { |
|
2225 | 2225 | $p += 2; |
2226 | 2226 | } else { |
2227 | 2227 | if (ord($this->dataStr[$p]) >= ord('a') && ord($this->dataStr[$p]) <= ord('z')) { |
@@ -2237,13 +2237,13 @@ discard block |
||
2237 | 2237 | //---------------------------------------------------------------------- |
2238 | 2238 | public static function splitStringToQRinput($string, QRinput $input, $modeHint, $casesensitive = true) |
2239 | 2239 | { |
2240 | - if(is_null($string) || $string == '\0' || $string == '') { |
|
2240 | + if (is_null($string) || $string == '\0' || $string == '') { |
|
2241 | 2241 | throw new Exception('empty string!!!'); |
2242 | 2242 | } |
2243 | 2243 | |
2244 | 2244 | $split = new QRsplit($string, $input, $modeHint); |
2245 | 2245 | |
2246 | - if(!$casesensitive) |
|
2246 | + if (!$casesensitive) |
|
2247 | 2247 | $split->toUpper(); |
2248 | 2248 | |
2249 | 2249 | return $split->splitString(); |
@@ -2288,16 +2288,16 @@ discard block |
||
2288 | 2288 | |
2289 | 2289 | class QRrsItem { |
2290 | 2290 | |
2291 | - public $mm; // Bits per symbol |
|
2292 | - public $nn; // Symbols per block (= (1<<mm)-1) |
|
2293 | - public $alpha_to = []; // log lookup table |
|
2294 | - public $index_of = []; // Antilog lookup table |
|
2295 | - public $genpoly = []; // Generator polynomial |
|
2296 | - public $nroots; // Number of generator roots = number of parity symbols |
|
2297 | - public $fcr; // First consecutive root, index form |
|
2298 | - public $prim; // Primitive element, index form |
|
2299 | - public $iprim; // prim-th root of 1, index form |
|
2300 | - public $pad; // Padding bytes in shortened block |
|
2291 | + public $mm; // Bits per symbol |
|
2292 | + public $nn; // Symbols per block (= (1<<mm)-1) |
|
2293 | + public $alpha_to = []; // log lookup table |
|
2294 | + public $index_of = []; // Antilog lookup table |
|
2295 | + public $genpoly = []; // Generator polynomial |
|
2296 | + public $nroots; // Number of generator roots = number of parity symbols |
|
2297 | + public $fcr; // First consecutive root, index form |
|
2298 | + public $prim; // Primitive element, index form |
|
2299 | + public $iprim; // prim-th root of 1, index form |
|
2300 | + public $pad; // Padding bytes in shortened block |
|
2301 | 2301 | public $gfpoly; |
2302 | 2302 | |
2303 | 2303 | //---------------------------------------------------------------------- |
@@ -2321,47 +2321,47 @@ discard block |
||
2321 | 2321 | $rs = null; |
2322 | 2322 | |
2323 | 2323 | // Check parameter ranges |
2324 | - if($symsize < 0 || $symsize > 8) return $rs; |
|
2325 | - if($fcr < 0 || $fcr >= (1<<$symsize)) return $rs; |
|
2326 | - if($prim <= 0 || $prim >= (1<<$symsize)) return $rs; |
|
2327 | - if($nroots < 0 || $nroots >= (1<<$symsize)) return $rs; // Can't have more roots than symbol values! |
|
2328 | - if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding |
|
2324 | + if ($symsize < 0 || $symsize > 8) return $rs; |
|
2325 | + if ($fcr < 0 || $fcr >= (1 << $symsize)) return $rs; |
|
2326 | + if ($prim <= 0 || $prim >= (1 << $symsize)) return $rs; |
|
2327 | + if ($nroots < 0 || $nroots >= (1 << $symsize)) return $rs; // Can't have more roots than symbol values! |
|
2328 | + if ($pad < 0 || $pad >= ((1 << $symsize) - 1 - $nroots)) return $rs; // Too much padding |
|
2329 | 2329 | |
2330 | 2330 | $rs = new QRrsItem(); |
2331 | 2331 | $rs->mm = $symsize; |
2332 | - $rs->nn = (1<<$symsize)-1; |
|
2332 | + $rs->nn = (1 << $symsize) - 1; |
|
2333 | 2333 | $rs->pad = $pad; |
2334 | 2334 | |
2335 | - $rs->alpha_to = array_fill(0, $rs->nn+1, 0); |
|
2336 | - $rs->index_of = array_fill(0, $rs->nn+1, 0); |
|
2335 | + $rs->alpha_to = array_fill(0, $rs->nn + 1, 0); |
|
2336 | + $rs->index_of = array_fill(0, $rs->nn + 1, 0); |
|
2337 | 2337 | |
2338 | 2338 | // PHP style macro replacement ;) |
2339 | - $NN =& $rs->nn; |
|
2340 | - $A0 =& $NN; |
|
2339 | + $NN = & $rs->nn; |
|
2340 | + $A0 = & $NN; |
|
2341 | 2341 | |
2342 | 2342 | // Generate Galois field lookup tables |
2343 | 2343 | $rs->index_of[0] = $A0; // log(zero) = -inf |
2344 | 2344 | $rs->alpha_to[$A0] = 0; // alpha**-inf = 0 |
2345 | 2345 | $sr = 1; |
2346 | 2346 | |
2347 | - for($i=0; $i<$rs->nn; $i++) { |
|
2347 | + for ($i = 0; $i < $rs->nn; $i++) { |
|
2348 | 2348 | $rs->index_of[$sr] = $i; |
2349 | 2349 | $rs->alpha_to[$i] = $sr; |
2350 | 2350 | $sr <<= 1; |
2351 | - if($sr & (1<<$symsize)) { |
|
2351 | + if ($sr & (1 << $symsize)) { |
|
2352 | 2352 | $sr ^= $gfpoly; |
2353 | 2353 | } |
2354 | 2354 | $sr &= $rs->nn; |
2355 | 2355 | } |
2356 | 2356 | |
2357 | - if($sr != 1){ |
|
2357 | + if ($sr != 1) { |
|
2358 | 2358 | // field generator polynomial is not primitive! |
2359 | 2359 | $rs = NULL; |
2360 | 2360 | return $rs; |
2361 | 2361 | } |
2362 | 2362 | |
2363 | 2363 | /* Form RS code generator polynomial from its roots */ |
2364 | - $rs->genpoly = array_fill(0, $nroots+1, 0); |
|
2364 | + $rs->genpoly = array_fill(0, $nroots + 1, 0); |
|
2365 | 2365 | |
2366 | 2366 | $rs->fcr = $fcr; |
2367 | 2367 | $rs->prim = $prim; |
@@ -2369,21 +2369,21 @@ discard block |
||
2369 | 2369 | $rs->gfpoly = $gfpoly; |
2370 | 2370 | |
2371 | 2371 | /* Find prim-th root of 1, used in decoding */ |
2372 | - for($iprim=1;($iprim % $prim) != 0;$iprim += $rs->nn) |
|
2372 | + for ($iprim = 1; ($iprim % $prim) != 0; $iprim += $rs->nn) |
|
2373 | 2373 | ; // intentional empty-body loop! |
2374 | 2374 | |
2375 | - $rs->iprim = (int)($iprim / $prim); |
|
2375 | + $rs->iprim = (int) ($iprim / $prim); |
|
2376 | 2376 | $rs->genpoly[0] = 1; |
2377 | 2377 | |
2378 | - for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) { |
|
2379 | - $rs->genpoly[$i+1] = 1; |
|
2378 | + for ($i = 0, $root = $fcr * $prim; $i < $nroots; $i++, $root += $prim) { |
|
2379 | + $rs->genpoly[$i + 1] = 1; |
|
2380 | 2380 | |
2381 | 2381 | // Multiply rs->genpoly[] by @**(root + x) |
2382 | 2382 | for ($j = $i; $j > 0; $j--) { |
2383 | 2383 | if ($rs->genpoly[$j] != 0) { |
2384 | - $rs->genpoly[$j] = $rs->genpoly[$j-1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)]; |
|
2384 | + $rs->genpoly[$j] = $rs->genpoly[$j - 1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)]; |
|
2385 | 2385 | } else { |
2386 | - $rs->genpoly[$j] = $rs->genpoly[$j-1]; |
|
2386 | + $rs->genpoly[$j] = $rs->genpoly[$j - 1]; |
|
2387 | 2387 | } |
2388 | 2388 | } |
2389 | 2389 | // rs->genpoly[0] can never be zero |
@@ -2400,38 +2400,38 @@ discard block |
||
2400 | 2400 | //---------------------------------------------------------------------- |
2401 | 2401 | public function encode_rs_char($data, &$parity) |
2402 | 2402 | { |
2403 | - $MM =& $this->mm; |
|
2404 | - $NN =& $this->nn; |
|
2405 | - $ALPHA_TO =& $this->alpha_to; |
|
2406 | - $INDEX_OF =& $this->index_of; |
|
2407 | - $GENPOLY =& $this->genpoly; |
|
2408 | - $NROOTS =& $this->nroots; |
|
2409 | - $FCR =& $this->fcr; |
|
2410 | - $PRIM =& $this->prim; |
|
2411 | - $IPRIM =& $this->iprim; |
|
2412 | - $PAD =& $this->pad; |
|
2413 | - $A0 =& $NN; |
|
2403 | + $MM = & $this->mm; |
|
2404 | + $NN = & $this->nn; |
|
2405 | + $ALPHA_TO = & $this->alpha_to; |
|
2406 | + $INDEX_OF = & $this->index_of; |
|
2407 | + $GENPOLY = & $this->genpoly; |
|
2408 | + $NROOTS = & $this->nroots; |
|
2409 | + $FCR = & $this->fcr; |
|
2410 | + $PRIM = & $this->prim; |
|
2411 | + $IPRIM = & $this->iprim; |
|
2412 | + $PAD = & $this->pad; |
|
2413 | + $A0 = & $NN; |
|
2414 | 2414 | |
2415 | 2415 | $parity = array_fill(0, $NROOTS, 0); |
2416 | 2416 | |
2417 | - for($i=0; $i< ($NN-$NROOTS-$PAD); $i++) { |
|
2417 | + for ($i = 0; $i < ($NN - $NROOTS - $PAD); $i++) { |
|
2418 | 2418 | |
2419 | 2419 | $feedback = $INDEX_OF[$data[$i] ^ $parity[0]]; |
2420 | - if($feedback != $A0) { |
|
2420 | + if ($feedback != $A0) { |
|
2421 | 2421 | // feedback term is non-zero |
2422 | 2422 | |
2423 | 2423 | // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must |
2424 | 2424 | // always be for the polynomials constructed by init_rs() |
2425 | 2425 | $feedback = $this->modnn($NN - $GENPOLY[$NROOTS] + $feedback); |
2426 | 2426 | |
2427 | - for($j=1;$j<$NROOTS;$j++) { |
|
2428 | - $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS-$j])]; |
|
2427 | + for ($j = 1; $j < $NROOTS; $j++) { |
|
2428 | + $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS - $j])]; |
|
2429 | 2429 | } |
2430 | 2430 | } |
2431 | 2431 | |
2432 | 2432 | // Shift |
2433 | 2433 | array_shift($parity); |
2434 | - if($feedback != $A0) { |
|
2434 | + if ($feedback != $A0) { |
|
2435 | 2435 | array_push($parity, $ALPHA_TO[$this->modnn($feedback + $GENPOLY[0])]); |
2436 | 2436 | } else { |
2437 | 2437 | array_push($parity, 0); |
@@ -2449,13 +2449,13 @@ discard block |
||
2449 | 2449 | //---------------------------------------------------------------------- |
2450 | 2450 | public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) |
2451 | 2451 | { |
2452 | - foreach(self::$items as $rs) { |
|
2453 | - if($rs->pad != $pad) continue; |
|
2454 | - if($rs->nroots != $nroots) continue; |
|
2455 | - if($rs->mm != $symsize) continue; |
|
2456 | - if($rs->gfpoly != $gfpoly) continue; |
|
2457 | - if($rs->fcr != $fcr) continue; |
|
2458 | - if($rs->prim != $prim) continue; |
|
2452 | + foreach (self::$items as $rs) { |
|
2453 | + if ($rs->pad != $pad) continue; |
|
2454 | + if ($rs->nroots != $nroots) continue; |
|
2455 | + if ($rs->mm != $symsize) continue; |
|
2456 | + if ($rs->gfpoly != $gfpoly) continue; |
|
2457 | + if ($rs->fcr != $fcr) continue; |
|
2458 | + if ($rs->prim != $prim) continue; |
|
2459 | 2459 | |
2460 | 2460 | return $rs; |
2461 | 2461 | } |
@@ -2519,10 +2519,10 @@ discard block |
||
2519 | 2519 | public function writeFormatInformation($width, &$frame, $mask, $level) |
2520 | 2520 | { |
2521 | 2521 | $blacks = 0; |
2522 | - $format = QRspec::getFormatInfo($mask, $level); |
|
2522 | + $format = QRspec::getFormatInfo($mask, $level); |
|
2523 | 2523 | |
2524 | - for($i=0; $i<8; $i++) { |
|
2525 | - if($format & 1) { |
|
2524 | + for ($i = 0; $i < 8; $i++) { |
|
2525 | + if ($format & 1) { |
|
2526 | 2526 | $blacks += 2; |
2527 | 2527 | $v = 0x85; |
2528 | 2528 | } else { |
@@ -2530,7 +2530,7 @@ discard block |
||
2530 | 2530 | } |
2531 | 2531 | |
2532 | 2532 | $frame[8][$width - 1 - $i] = chr($v); |
2533 | - if($i < 6) { |
|
2533 | + if ($i < 6) { |
|
2534 | 2534 | $frame[$i][8] = chr($v); |
2535 | 2535 | } else { |
2536 | 2536 | $frame[$i + 1][8] = chr($v); |
@@ -2538,8 +2538,8 @@ discard block |
||
2538 | 2538 | $format = $format >> 1; |
2539 | 2539 | } |
2540 | 2540 | |
2541 | - for($i=0; $i<7; $i++) { |
|
2542 | - if($format & 1) { |
|
2541 | + for ($i = 0; $i < 7; $i++) { |
|
2542 | + if ($format & 1) { |
|
2543 | 2543 | $blacks += 2; |
2544 | 2544 | $v = 0x85; |
2545 | 2545 | } else { |
@@ -2547,7 +2547,7 @@ discard block |
||
2547 | 2547 | } |
2548 | 2548 | |
2549 | 2549 | $frame[$width - 7 + $i][8] = chr($v); |
2550 | - if($i == 0) { |
|
2550 | + if ($i == 0) { |
|
2551 | 2551 | $frame[8][7] = chr($v); |
2552 | 2552 | } else { |
2553 | 2553 | $frame[8][6 - $i] = chr($v); |
@@ -2560,27 +2560,27 @@ discard block |
||
2560 | 2560 | } |
2561 | 2561 | |
2562 | 2562 | //---------------------------------------------------------------------- |
2563 | - public function mask0($x, $y) { return ($x+$y)&1; } |
|
2564 | - public function mask1($x, $y) { return ($y&1); } |
|
2565 | - public function mask2($x, $y) { return ($x%3); } |
|
2566 | - public function mask3($x, $y) { return ($x+$y)%3; } |
|
2567 | - public function mask4($x, $y) { return (((int)($y/2))+((int)($x/3)))&1; } |
|
2568 | - public function mask5($x, $y) { return (($x*$y)&1)+($x*$y)%3; } |
|
2569 | - public function mask6($x, $y) { return ((($x*$y)&1)+($x*$y)%3)&1; } |
|
2570 | - public function mask7($x, $y) { return ((($x*$y)%3)+(($x+$y)&1))&1; } |
|
2563 | + public function mask0($x, $y) { return ($x + $y) & 1; } |
|
2564 | + public function mask1($x, $y) { return ($y & 1); } |
|
2565 | + public function mask2($x, $y) { return ($x % 3); } |
|
2566 | + public function mask3($x, $y) { return ($x + $y) % 3; } |
|
2567 | + public function mask4($x, $y) { return (((int) ($y / 2)) + ((int) ($x / 3))) & 1; } |
|
2568 | + public function mask5($x, $y) { return (($x * $y) & 1) + ($x * $y) % 3; } |
|
2569 | + public function mask6($x, $y) { return ((($x * $y) & 1) + ($x * $y) % 3) & 1; } |
|
2570 | + public function mask7($x, $y) { return ((($x * $y) % 3) + (($x + $y) & 1)) & 1; } |
|
2571 | 2571 | |
2572 | 2572 | //---------------------------------------------------------------------- |
2573 | 2573 | private function generateMaskNo($maskNo, $width, $frame) |
2574 | 2574 | { |
2575 | 2575 | $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
2576 | 2576 | |
2577 | - for($y=0; $y<$width; $y++) { |
|
2578 | - for($x=0; $x<$width; $x++) { |
|
2579 | - if(ord($frame[$y][$x]) & 0x80) { |
|
2577 | + for ($y = 0; $y < $width; $y++) { |
|
2578 | + for ($x = 0; $x < $width; $x++) { |
|
2579 | + if (ord($frame[$y][$x]) & 0x80) { |
|
2580 | 2580 | $bitMask[$y][$x] = 0; |
2581 | 2581 | } else { |
2582 | - $maskFunc = call_user_func([$this, 'mask'.$maskNo], $x, $y); |
|
2583 | - $bitMask[$y][$x] = ($maskFunc == 0)?1:0; |
|
2582 | + $maskFunc = call_user_func([$this, 'mask' . $maskNo], $x, $y); |
|
2583 | + $bitMask[$y][$x] = ($maskFunc == 0) ? 1 : 0; |
|
2584 | 2584 | } |
2585 | 2585 | |
2586 | 2586 | } |
@@ -2618,15 +2618,15 @@ discard block |
||
2618 | 2618 | $b = 0; |
2619 | 2619 | $bitMask = []; |
2620 | 2620 | |
2621 | - $fileName = QR_CACHE_DIR.'mask_'.$maskNo.DIRECTORY_SEPARATOR.'mask_'.$width.'_'.$maskNo.'.dat'; |
|
2621 | + $fileName = QR_CACHE_DIR . 'mask_' . $maskNo . DIRECTORY_SEPARATOR . 'mask_' . $width . '_' . $maskNo . '.dat'; |
|
2622 | 2622 | |
2623 | 2623 | if (QR_CACHEABLE) { |
2624 | 2624 | if (file_exists($fileName)) { |
2625 | 2625 | $bitMask = self::unserial(file_get_contents($fileName)); |
2626 | 2626 | } else { |
2627 | 2627 | $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d); |
2628 | - if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo)) |
|
2629 | - mkdir(QR_CACHE_DIR.'mask_'.$maskNo); |
|
2628 | + if (!file_exists(QR_CACHE_DIR . 'mask_' . $maskNo)) |
|
2629 | + mkdir(QR_CACHE_DIR . 'mask_' . $maskNo); |
|
2630 | 2630 | file_put_contents($fileName, self::serial($bitMask)); |
2631 | 2631 | } |
2632 | 2632 | } else { |
@@ -2638,12 +2638,12 @@ discard block |
||
2638 | 2638 | |
2639 | 2639 | $d = $s; |
2640 | 2640 | |
2641 | - for($y=0; $y<$width; $y++) { |
|
2642 | - for($x=0; $x<$width; $x++) { |
|
2643 | - if($bitMask[$y][$x] == 1) { |
|
2644 | - $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]); |
|
2641 | + for ($y = 0; $y < $width; $y++) { |
|
2642 | + for ($x = 0; $x < $width; $x++) { |
|
2643 | + if ($bitMask[$y][$x] == 1) { |
|
2644 | + $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int) $bitMask[$y][$x]); |
|
2645 | 2645 | } |
2646 | - $b += (int)(ord($d[$y][$x]) & 1); |
|
2646 | + $b += (int) (ord($d[$y][$x]) & 1); |
|
2647 | 2647 | } |
2648 | 2648 | } |
2649 | 2649 | |
@@ -2665,21 +2665,21 @@ discard block |
||
2665 | 2665 | { |
2666 | 2666 | $demerit = 0; |
2667 | 2667 | |
2668 | - for($i=0; $i<$length; $i++) { |
|
2668 | + for ($i = 0; $i < $length; $i++) { |
|
2669 | 2669 | |
2670 | - if($this->runLength[$i] >= 5) { |
|
2670 | + if ($this->runLength[$i] >= 5) { |
|
2671 | 2671 | $demerit += (N1 + ($this->runLength[$i] - 5)); |
2672 | 2672 | } |
2673 | - if($i & 1) { |
|
2674 | - if(($i >= 3) && ($i < ($length-2)) && ($this->runLength[$i] % 3 == 0)) { |
|
2675 | - $fact = (int)($this->runLength[$i] / 3); |
|
2676 | - if(($this->runLength[$i-2] == $fact) && |
|
2677 | - ($this->runLength[$i-1] == $fact) && |
|
2678 | - ($this->runLength[$i+1] == $fact) && |
|
2679 | - ($this->runLength[$i+2] == $fact)) { |
|
2680 | - if(($this->runLength[$i-3] < 0) || ($this->runLength[$i-3] >= (4 * $fact))) { |
|
2673 | + if ($i & 1) { |
|
2674 | + if (($i >= 3) && ($i < ($length - 2)) && ($this->runLength[$i] % 3 == 0)) { |
|
2675 | + $fact = (int) ($this->runLength[$i] / 3); |
|
2676 | + if (($this->runLength[$i - 2] == $fact) && |
|
2677 | + ($this->runLength[$i - 1] == $fact) && |
|
2678 | + ($this->runLength[$i + 1] == $fact) && |
|
2679 | + ($this->runLength[$i + 2] == $fact)) { |
|
2680 | + if (($this->runLength[$i - 3] < 0) || ($this->runLength[$i - 3] >= (4 * $fact))) { |
|
2681 | 2681 | $demerit += N3; |
2682 | - } else if((($i+3) >= $length) || ($this->runLength[$i+3] >= (4 * $fact))) { |
|
2682 | + } else if ((($i + 3) >= $length) || ($this->runLength[$i + 3] >= (4 * $fact))) { |
|
2683 | 2683 | $demerit += N3; |
2684 | 2684 | } |
2685 | 2685 | } |
@@ -2695,30 +2695,30 @@ discard block |
||
2695 | 2695 | $head = 0; |
2696 | 2696 | $demerit = 0; |
2697 | 2697 | |
2698 | - for($y=0; $y<$width; $y++) { |
|
2698 | + for ($y = 0; $y < $width; $y++) { |
|
2699 | 2699 | $head = 0; |
2700 | 2700 | $this->runLength[0] = 1; |
2701 | 2701 | |
2702 | 2702 | $frameY = $frame[$y]; |
2703 | 2703 | |
2704 | - if ($y>0) |
|
2705 | - $frameYM = $frame[$y-1]; |
|
2704 | + if ($y > 0) |
|
2705 | + $frameYM = $frame[$y - 1]; |
|
2706 | 2706 | |
2707 | - for($x=0; $x<$width; $x++) { |
|
2708 | - if(($x > 0) && ($y > 0)) { |
|
2709 | - $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]); |
|
2710 | - $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]); |
|
2707 | + for ($x = 0; $x < $width; $x++) { |
|
2708 | + if (($x > 0) && ($y > 0)) { |
|
2709 | + $b22 = ord($frameY[$x]) & ord($frameY[$x - 1]) & ord($frameYM[$x]) & ord($frameYM[$x - 1]); |
|
2710 | + $w22 = ord($frameY[$x]) | ord($frameY[$x - 1]) | ord($frameYM[$x]) | ord($frameYM[$x - 1]); |
|
2711 | 2711 | |
2712 | - if(($b22 | ($w22 ^ 1))&1) { |
|
2712 | + if (($b22 | ($w22 ^ 1)) & 1) { |
|
2713 | 2713 | $demerit += N2; |
2714 | 2714 | } |
2715 | 2715 | } |
2716 | - if(($x == 0) && (ord($frameY[$x]) & 1)) { |
|
2716 | + if (($x == 0) && (ord($frameY[$x]) & 1)) { |
|
2717 | 2717 | $this->runLength[0] = -1; |
2718 | 2718 | $head = 1; |
2719 | 2719 | $this->runLength[$head] = 1; |
2720 | - } else if($x > 0) { |
|
2721 | - if((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) { |
|
2720 | + } else if ($x > 0) { |
|
2721 | + if ((ord($frameY[$x]) ^ ord($frameY[$x - 1])) & 1) { |
|
2722 | 2722 | $head++; |
2723 | 2723 | $this->runLength[$head] = 1; |
2724 | 2724 | } else { |
@@ -2727,20 +2727,20 @@ discard block |
||
2727 | 2727 | } |
2728 | 2728 | } |
2729 | 2729 | |
2730 | - $demerit += $this->calcN1N3($head+1); |
|
2730 | + $demerit += $this->calcN1N3($head + 1); |
|
2731 | 2731 | } |
2732 | 2732 | |
2733 | - for($x=0; $x<$width; $x++) { |
|
2733 | + for ($x = 0; $x < $width; $x++) { |
|
2734 | 2734 | $head = 0; |
2735 | 2735 | $this->runLength[0] = 1; |
2736 | 2736 | |
2737 | - for($y=0; $y<$width; $y++) { |
|
2738 | - if($y == 0 && (ord($frame[$y][$x]) & 1)) { |
|
2737 | + for ($y = 0; $y < $width; $y++) { |
|
2738 | + if ($y == 0 && (ord($frame[$y][$x]) & 1)) { |
|
2739 | 2739 | $this->runLength[0] = -1; |
2740 | 2740 | $head = 1; |
2741 | 2741 | $this->runLength[$head] = 1; |
2742 | - } else if($y > 0) { |
|
2743 | - if((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) { |
|
2742 | + } else if ($y > 0) { |
|
2743 | + if ((ord($frame[$y][$x]) ^ ord($frame[$y - 1][$x])) & 1) { |
|
2744 | 2744 | $head++; |
2745 | 2745 | $this->runLength[$head] = 1; |
2746 | 2746 | } else { |
@@ -2749,7 +2749,7 @@ discard block |
||
2749 | 2749 | } |
2750 | 2750 | } |
2751 | 2751 | |
2752 | - $demerit += $this->calcN1N3($head+1); |
|
2752 | + $demerit += $this->calcN1N3($head + 1); |
|
2753 | 2753 | } |
2754 | 2754 | |
2755 | 2755 | return $demerit; |
@@ -2763,13 +2763,13 @@ discard block |
||
2763 | 2763 | $bestMaskNum = 0; |
2764 | 2764 | $bestMask = []; |
2765 | 2765 | |
2766 | - $checked_masks = [0,1,2,3,4,5,6,7]; |
|
2766 | + $checked_masks = [0, 1, 2, 3, 4, 5, 6, 7]; |
|
2767 | 2767 | |
2768 | 2768 | if (QR_FIND_FROM_RANDOM !== false) { |
2769 | 2769 | |
2770 | - $howManuOut = 8-(QR_FIND_FROM_RANDOM % 9); |
|
2771 | - for ($i = 0; $i < $howManuOut; $i++) { |
|
2772 | - $remPos = rand (0, count($checked_masks)-1); |
|
2770 | + $howManuOut = 8 - (QR_FIND_FROM_RANDOM % 9); |
|
2771 | + for ($i = 0; $i < $howManuOut; $i++) { |
|
2772 | + $remPos = rand(0, count($checked_masks) - 1); |
|
2773 | 2773 | unset($checked_masks[$remPos]); |
2774 | 2774 | $checked_masks = array_values($checked_masks); |
2775 | 2775 | } |
@@ -2778,18 +2778,18 @@ discard block |
||
2778 | 2778 | |
2779 | 2779 | $bestMask = $frame; |
2780 | 2780 | |
2781 | - foreach($checked_masks as $i) { |
|
2781 | + foreach ($checked_masks as $i) { |
|
2782 | 2782 | $mask = array_fill(0, $width, str_repeat("\0", $width)); |
2783 | 2783 | |
2784 | 2784 | $demerit = 0; |
2785 | 2785 | $blacks = 0; |
2786 | 2786 | $blacks = $this->makeMaskNo($i, $width, $frame, $mask); |
2787 | 2787 | $blacks += $this->writeFormatInformation($width, $mask, $i, $level); |
2788 | - $blacks = (int)(100 * $blacks / ($width * $width)); |
|
2789 | - $demerit = (int)((int)(abs($blacks - 50) / 5) * N4); |
|
2788 | + $blacks = (int) (100 * $blacks / ($width * $width)); |
|
2789 | + $demerit = (int) ((int) (abs($blacks - 50) / 5) * N4); |
|
2790 | 2790 | $demerit += $this->evaluateSymbol($width, $mask); |
2791 | 2791 | |
2792 | - if($demerit < $minDemerit) { |
|
2792 | + if ($demerit < $minDemerit) { |
|
2793 | 2793 | $minDemerit = $demerit; |
2794 | 2794 | $bestMask = $mask; |
2795 | 2795 | $bestMaskNum = $i; |
@@ -2869,10 +2869,10 @@ discard block |
||
2869 | 2869 | //---------------------------------------------------------------------- |
2870 | 2870 | public function __construct(QRinput $input) |
2871 | 2871 | { |
2872 | - $spec = [0,0,0,0,0]; |
|
2872 | + $spec = [0, 0, 0, 0, 0]; |
|
2873 | 2873 | |
2874 | 2874 | $this->datacode = $input->getByteStream(); |
2875 | - if(is_null($this->datacode)) { |
|
2875 | + if (is_null($this->datacode)) { |
|
2876 | 2876 | throw new Exception('null imput string'); |
2877 | 2877 | } |
2878 | 2878 | |
@@ -2886,7 +2886,7 @@ discard block |
||
2886 | 2886 | $this->blocks = QRspec::rsBlockNum($spec); |
2887 | 2887 | |
2888 | 2888 | $ret = $this->init($spec); |
2889 | - if($ret < 0) { |
|
2889 | + if ($ret < 0) { |
|
2890 | 2890 | throw new Exception('block alloc error'); |
2891 | 2891 | return null; |
2892 | 2892 | } |
@@ -2905,29 +2905,29 @@ discard block |
||
2905 | 2905 | $blockNo = 0; |
2906 | 2906 | $dataPos = 0; |
2907 | 2907 | $eccPos = 0; |
2908 | - for($i=0; $i<QRspec::rsBlockNum1($spec); $i++) { |
|
2909 | - $ecc = array_slice($this->ecccode,$eccPos); |
|
2910 | - $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); |
|
2911 | - $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); |
|
2908 | + for ($i = 0; $i < QRspec::rsBlockNum1($spec); $i++) { |
|
2909 | + $ecc = array_slice($this->ecccode, $eccPos); |
|
2910 | + $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); |
|
2911 | + $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc); |
|
2912 | 2912 | |
2913 | 2913 | $dataPos += $dl; |
2914 | 2914 | $eccPos += $el; |
2915 | 2915 | $blockNo++; |
2916 | 2916 | } |
2917 | 2917 | |
2918 | - if(QRspec::rsBlockNum2($spec) == 0) |
|
2918 | + if (QRspec::rsBlockNum2($spec) == 0) |
|
2919 | 2919 | return 0; |
2920 | 2920 | |
2921 | 2921 | $dl = QRspec::rsDataCodes2($spec); |
2922 | 2922 | $el = QRspec::rsEccCodes2($spec); |
2923 | 2923 | $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); |
2924 | 2924 | |
2925 | - if($rs == NULL) return -1; |
|
2925 | + if ($rs == NULL) return -1; |
|
2926 | 2926 | |
2927 | - for($i=0; $i<QRspec::rsBlockNum2($spec); $i++) { |
|
2928 | - $ecc = array_slice($this->ecccode,$eccPos); |
|
2927 | + for ($i = 0; $i < QRspec::rsBlockNum2($spec); $i++) { |
|
2928 | + $ecc = array_slice($this->ecccode, $eccPos); |
|
2929 | 2929 | $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); |
2930 | - $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); |
|
2930 | + $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc); |
|
2931 | 2931 | |
2932 | 2932 | $dataPos += $dl; |
2933 | 2933 | $eccPos += $el; |
@@ -2942,14 +2942,14 @@ discard block |
||
2942 | 2942 | { |
2943 | 2943 | $ret; |
2944 | 2944 | |
2945 | - if($this->count < $this->dataLength) { |
|
2945 | + if ($this->count < $this->dataLength) { |
|
2946 | 2946 | $row = $this->count % $this->blocks; |
2947 | 2947 | $col = $this->count / $this->blocks; |
2948 | - if($col >= $this->rsblocks[0]->dataLength) { |
|
2948 | + if ($col >= $this->rsblocks[0]->dataLength) { |
|
2949 | 2949 | $row += $this->b1; |
2950 | 2950 | } |
2951 | 2951 | $ret = $this->rsblocks[$row]->data[$col]; |
2952 | - } else if($this->count < $this->dataLength + $this->eccLength) { |
|
2952 | + } else if ($this->count < $this->dataLength + $this->eccLength) { |
|
2953 | 2953 | $row = ($this->count - $this->dataLength) % $this->blocks; |
2954 | 2954 | $col = ($this->count - $this->dataLength) / $this->blocks; |
2955 | 2955 | $ret = $this->rsblocks[$row]->ecc[$col]; |
@@ -2973,10 +2973,10 @@ discard block |
||
2973 | 2973 | //---------------------------------------------------------------------- |
2974 | 2974 | public function encodeMask(QRinput $input, $mask) |
2975 | 2975 | { |
2976 | - if($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) { |
|
2976 | + if ($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) { |
|
2977 | 2977 | throw new Exception('wrong version'); |
2978 | 2978 | } |
2979 | - if($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) { |
|
2979 | + if ($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) { |
|
2980 | 2980 | throw new Exception('wrong level'); |
2981 | 2981 | } |
2982 | 2982 | |
@@ -2989,15 +2989,15 @@ discard block |
||
2989 | 2989 | $frame = QRspec::newFrame($version); |
2990 | 2990 | |
2991 | 2991 | $filler = new FrameFiller($width, $frame); |
2992 | - if(is_null($filler)) { |
|
2992 | + if (is_null($filler)) { |
|
2993 | 2993 | return NULL; |
2994 | 2994 | } |
2995 | 2995 | |
2996 | 2996 | // inteleaved data and ecc codes |
2997 | - for($i=0; $i<$raw->dataLength + $raw->eccLength; $i++) { |
|
2997 | + for ($i = 0; $i < $raw->dataLength + $raw->eccLength; $i++) { |
|
2998 | 2998 | $code = $raw->getCode(); |
2999 | 2999 | $bit = 0x80; |
3000 | - for($j=0; $j<8; $j++) { |
|
3000 | + for ($j = 0; $j < 8; $j++) { |
|
3001 | 3001 | $addr = $filler->next(); |
3002 | 3002 | $filler->setFrameAt($addr, 0x02 | (($bit & $code) != 0)); |
3003 | 3003 | $bit = $bit >> 1; |
@@ -3010,7 +3010,7 @@ discard block |
||
3010 | 3010 | |
3011 | 3011 | // remainder bits |
3012 | 3012 | $j = QRspec::getRemainder($version); |
3013 | - for($i=0; $i<$j; $i++) { |
|
3013 | + for ($i = 0; $i < $j; $i++) { |
|
3014 | 3014 | $addr = $filler->next(); |
3015 | 3015 | $filler->setFrameAt($addr, 0x02); |
3016 | 3016 | } |
@@ -3021,7 +3021,7 @@ discard block |
||
3021 | 3021 | |
3022 | 3022 | // masking |
3023 | 3023 | $maskObj = new QRmask(); |
3024 | - if($mask < 0) { |
|
3024 | + if ($mask < 0) { |
|
3025 | 3025 | |
3026 | 3026 | if (QR_FIND_BEST_MASK) { |
3027 | 3027 | $masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel()); |
@@ -3032,7 +3032,7 @@ discard block |
||
3032 | 3032 | $masked = $maskObj->makeMask($width, $frame, $mask, $input->getErrorCorrectionLevel()); |
3033 | 3033 | } |
3034 | 3034 | |
3035 | - if($masked == NULL) { |
|
3035 | + if ($masked == NULL) { |
|
3036 | 3036 | return NULL; |
3037 | 3037 | } |
3038 | 3038 | |
@@ -3054,16 +3054,16 @@ discard block |
||
3054 | 3054 | //---------------------------------------------------------------------- |
3055 | 3055 | public function encodeString8bit($string, $version, $level) |
3056 | 3056 | { |
3057 | - if(string == NULL) { |
|
3057 | + if (string == NULL) { |
|
3058 | 3058 | throw new Exception('empty string!'); |
3059 | 3059 | return NULL; |
3060 | 3060 | } |
3061 | 3061 | |
3062 | 3062 | $input = new QRinput($version, $level); |
3063 | - if($input == NULL) return NULL; |
|
3063 | + if ($input == NULL) return NULL; |
|
3064 | 3064 | |
3065 | 3065 | $ret = $input->append($input, QR_MODE_8, strlen($string), str_split($string)); |
3066 | - if($ret < 0) { |
|
3066 | + if ($ret < 0) { |
|
3067 | 3067 | unset($input); |
3068 | 3068 | return NULL; |
3069 | 3069 | } |
@@ -3074,16 +3074,16 @@ discard block |
||
3074 | 3074 | public function encodeString($string, $version, $level, $hint, $casesensitive) |
3075 | 3075 | { |
3076 | 3076 | |
3077 | - if($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) { |
|
3077 | + if ($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) { |
|
3078 | 3078 | throw new Exception('bad hint'); |
3079 | 3079 | return NULL; |
3080 | 3080 | } |
3081 | 3081 | |
3082 | 3082 | $input = new QRinput($version, $level); |
3083 | - if($input == NULL) return NULL; |
|
3083 | + if ($input == NULL) return NULL; |
|
3084 | 3084 | |
3085 | 3085 | $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive); |
3086 | - if($ret < 0) { |
|
3086 | + if ($ret < 0) { |
|
3087 | 3087 | return NULL; |
3088 | 3088 | } |
3089 | 3089 | |
@@ -3091,10 +3091,10 @@ discard block |
||
3091 | 3091 | } |
3092 | 3092 | |
3093 | 3093 | //---------------------------------------------------------------------- |
3094 | - public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false) |
|
3094 | + public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint = false) |
|
3095 | 3095 | { |
3096 | 3096 | $enc = QRencode::factory($level, $size, $margin); |
3097 | - return $enc->encodePNG($text, $outfile, $saveandprint=false); |
|
3097 | + return $enc->encodePNG($text, $outfile, $saveandprint = false); |
|
3098 | 3098 | } |
3099 | 3099 | |
3100 | 3100 | //---------------------------------------------------------------------- |
@@ -3151,7 +3151,7 @@ discard block |
||
3151 | 3151 | { |
3152 | 3152 | do { |
3153 | 3153 | |
3154 | - if($this->bit == -1) { |
|
3154 | + if ($this->bit == -1) { |
|
3155 | 3155 | $this->bit = 0; |
3156 | 3156 | return ['x'=>$this->x, 'y'=>$this->y]; |
3157 | 3157 | } |
@@ -3160,7 +3160,7 @@ discard block |
||
3160 | 3160 | $y = $this->y; |
3161 | 3161 | $w = $this->width; |
3162 | 3162 | |
3163 | - if($this->bit == 0) { |
|
3163 | + if ($this->bit == 0) { |
|
3164 | 3164 | $x--; |
3165 | 3165 | $this->bit++; |
3166 | 3166 | } else { |
@@ -3169,33 +3169,33 @@ discard block |
||
3169 | 3169 | $this->bit--; |
3170 | 3170 | } |
3171 | 3171 | |
3172 | - if($this->dir < 0) { |
|
3173 | - if($y < 0) { |
|
3172 | + if ($this->dir < 0) { |
|
3173 | + if ($y < 0) { |
|
3174 | 3174 | $y = 0; |
3175 | 3175 | $x -= 2; |
3176 | 3176 | $this->dir = 1; |
3177 | - if($x == 6) { |
|
3177 | + if ($x == 6) { |
|
3178 | 3178 | $x--; |
3179 | 3179 | $y = 9; |
3180 | 3180 | } |
3181 | 3181 | } |
3182 | 3182 | } else { |
3183 | - if($y == $w) { |
|
3183 | + if ($y == $w) { |
|
3184 | 3184 | $y = $w - 1; |
3185 | 3185 | $x -= 2; |
3186 | 3186 | $this->dir = -1; |
3187 | - if($x == 6) { |
|
3187 | + if ($x == 6) { |
|
3188 | 3188 | $x--; |
3189 | 3189 | $y -= 8; |
3190 | 3190 | } |
3191 | 3191 | } |
3192 | 3192 | } |
3193 | - if($x < 0 || $y < 0) return null; |
|
3193 | + if ($x < 0 || $y < 0) return null; |
|
3194 | 3194 | |
3195 | 3195 | $this->x = $x; |
3196 | 3196 | $this->y = $y; |
3197 | 3197 | |
3198 | - } while(ord($this->frame[$y][$x]) & 0x80); |
|
3198 | + } while (ord($this->frame[$y][$x]) & 0x80); |
|
3199 | 3199 | |
3200 | 3200 | return ['x'=>$x, 'y'=>$y]; |
3201 | 3201 | } |
@@ -3225,7 +3225,7 @@ discard block |
||
3225 | 3225 | $enc->size = $size; |
3226 | 3226 | $enc->margin = $margin; |
3227 | 3227 | |
3228 | - switch ($level.'') { |
|
3228 | + switch ($level . '') { |
|
3229 | 3229 | case '0': |
3230 | 3230 | case '1': |
3231 | 3231 | case '2': |
@@ -3258,7 +3258,7 @@ discard block |
||
3258 | 3258 | { |
3259 | 3259 | $code = new QRcode(); |
3260 | 3260 | |
3261 | - if($this->eightbit) { |
|
3261 | + if ($this->eightbit) { |
|
3262 | 3262 | $code->encodeString8bit($intext, $this->version, $this->level); |
3263 | 3263 | } else { |
3264 | 3264 | $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive); |
@@ -3272,7 +3272,7 @@ discard block |
||
3272 | 3272 | { |
3273 | 3273 | $code = new QRcode(); |
3274 | 3274 | |
3275 | - if($this->eightbit) { |
|
3275 | + if ($this->eightbit) { |
|
3276 | 3276 | $code->encodeString8bit($intext, $this->version, $this->level); |
3277 | 3277 | } else { |
3278 | 3278 | $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive); |
@@ -3280,7 +3280,7 @@ discard block |
||
3280 | 3280 | |
3281 | 3281 | QRtools::markTime('after_encode'); |
3282 | 3282 | |
3283 | - if ($outfile!== false) { |
|
3283 | + if ($outfile !== false) { |
|
3284 | 3284 | file_put_contents($outfile, join("\n", QRtools::binarize($code->data))); |
3285 | 3285 | } else { |
3286 | 3286 | return QRtools::binarize($code->data); |
@@ -3288,7 +3288,7 @@ discard block |
||
3288 | 3288 | } |
3289 | 3289 | |
3290 | 3290 | //---------------------------------------------------------------------- |
3291 | - public function encodePNG($intext, $outfile = false,$saveandprint=false) |
|
3291 | + public function encodePNG($intext, $outfile = false, $saveandprint = false) |
|
3292 | 3292 | { |
3293 | 3293 | try { |
3294 | 3294 | |
@@ -3300,9 +3300,9 @@ discard block |
||
3300 | 3300 | if ($err != '') |
3301 | 3301 | QRtools::log($outfile, $err); |
3302 | 3302 | |
3303 | - $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin)); |
|
3303 | + $maxSize = (int) (QR_PNG_MAXIMUM_SIZE / (count($tab) + 2 * $this->margin)); |
|
3304 | 3304 | |
3305 | - return QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin,$saveandprint); |
|
3305 | + return QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin, $saveandprint); |
|
3306 | 3306 | |
3307 | 3307 | } catch (Exception $e) { |
3308 | 3308 |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * supported EAP types from the DB and stores them in the priv_ arrays. |
74 | 74 | * |
75 | 75 | * @param int $p_id identifier of the profile in the DB |
76 | - * @param IdP $idp_object optionally, the institution to which this Profile belongs. Saves the construction of the IdP instance. If omitted, an extra query and instantiation is executed to find out. |
|
76 | + * @param integer $idp_object optionally, the institution to which this Profile belongs. Saves the construction of the IdP instance. If omitted, an extra query and instantiation is executed to find out. |
|
77 | 77 | */ |
78 | 78 | public function __construct($p_id, $idp_object = 0) { |
79 | 79 | debug(3, "--- BEGIN Constructing new Profile object ... ---\n"); |
@@ -372,6 +372,8 @@ discard block |
||
372 | 372 | * |
373 | 373 | * @param string device the device identifier string |
374 | 374 | * @param string path the path where the new installer can be found |
375 | + * @param string $device |
|
376 | + * @param string $path |
|
375 | 377 | */ |
376 | 378 | public function updateCache($device, $path,$mime) { |
377 | 379 | $device = DBConnection::escape_value(Profile::$DB_TYPE, $device); |
@@ -384,9 +386,9 @@ discard block |
||
384 | 386 | /** |
385 | 387 | * Log a new download for our stats |
386 | 388 | * |
387 | - * @param device the device id string |
|
388 | - * @param area either admin or user |
|
389 | - * @return TRUE if incrementing worked, FALSE if not |
|
389 | + * @param device string device id string |
|
390 | + * @param area string admin or user |
|
391 | + * @return boolean if incrementing worked, FALSE if not |
|
390 | 392 | */ |
391 | 393 | public function incrementDownloadStats($device, $area) { |
392 | 394 | $device = DBConnection::escape_value(Profile::$DB_TYPE, $device); |
@@ -399,7 +401,7 @@ discard block |
||
399 | 401 | |
400 | 402 | /** |
401 | 403 | * Retrieve current download stats from database, either for one specific device or for all devices |
402 | - * @param string $device the device id string |
|
404 | + * @param integer $device the device id string |
|
403 | 405 | * @return mixed user downloads of this profile; if device is given, returns the counter as int, otherwise an array with devicename => counter |
404 | 406 | */ |
405 | 407 | public function getUserDownloadStats($device = 0) { |
@@ -464,7 +466,7 @@ discard block |
||
464 | 466 | * @param string $attr_name name of the attribute to set |
465 | 467 | * @param string $attr_value value of the attribute to set |
466 | 468 | * @param int $eap_type identifier of the EAP type in the database. 0 if the attribute is valid for all EAP types. |
467 | - * @param string $device identifier of the device in the databse. Omit the argument if attribute is valid for all devices. |
|
469 | + * @param integer $device identifier of the device in the databse. Omit the argument if attribute is valid for all devices. |
|
468 | 470 | */ |
469 | 471 | public function addAttribute($attr_name, $attr_value, $eap_type, $device = 0) { |
470 | 472 | $attr_name = DBConnection::escape_value(Profile::$DB_TYPE, $attr_name); |
@@ -574,7 +576,7 @@ discard block |
||
574 | 576 | /** Returns an array of the profile's attributes. |
575 | 577 | * |
576 | 578 | * @param string option_name the name of a specific option. If set, only returns option values for this option name |
577 | - * @param eapmethod the EAP type, in array ("OUTER/INNER") notation. If set, returns only attributes which are specific to that EAP type |
|
579 | + * @param eapmethod integer EAP type, in array ("OUTER/INNER") notation. If set, returns only attributes which are specific to that EAP type |
|
578 | 580 | * @param string device the device ID string. If set, returns only attributes which are specific to that device |
579 | 581 | * @return array attributes of the profile |
580 | 582 | */ |
@@ -658,7 +660,7 @@ discard block |
||
658 | 660 | /** |
659 | 661 | * list all devices marking their availabiblity and possible redirects |
660 | 662 | * |
661 | - * @param string $locale for text-based attributes, either returns values for the default value, or if specified here, in the locale specified |
|
663 | + * @param integer $locale for text-based attributes, either returns values for the default value, or if specified here, in the locale specified |
|
662 | 664 | * @return array of device ids display names and their status |
663 | 665 | */ |
664 | 666 | public function listDevices($locale = 0) { |
@@ -713,7 +715,7 @@ discard block |
||
713 | 715 | * as wel as the chosen language. |
714 | 716 | * can be called with an optional $eap argument |
715 | 717 | * |
716 | - * @param array $eap if specified, retrieves attributes specific to the given EAP type |
|
718 | + * @param integer $eap if specified, retrieves attributes specific to the given EAP type |
|
717 | 719 | * @return array list of attributes in collapsed style (index is the attrib name, value is an array of different values) |
718 | 720 | */ |
719 | 721 | public function getCollapsedAttributes($eap = 0) { |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | $temparray[] = [ |
121 | 121 | "name" => $a->option_name, |
122 | 122 | "value" => $a->option_value, |
123 | - "level" => ($a->device_id == NULL && $a->method == 0 ? "Profile" : "Method" ), |
|
123 | + "level" => ($a->device_id == NULL && $a->method == 0 ? "Profile" : "Method"), |
|
124 | 124 | "row" => $a->row, |
125 | 125 | "device" => $a->device_id, |
126 | 126 | "flag" => $optinfo['flag'], |
@@ -141,8 +141,8 @@ discard block |
||
141 | 141 | |
142 | 142 | $temparray[] = [ |
143 | 143 | "name" => $a->option_name, |
144 | - "value" => ( $lang == "" ? $content : serialize(['lang' => $lang, 'content' => $content])), |
|
145 | - "level" => ($a->device_id == NULL && $a->method == 0 ? "Profile" : "Method" ), |
|
144 | + "value" => ($lang == "" ? $content : serialize(['lang' => $lang, 'content' => $content])), |
|
145 | + "level" => ($a->device_id == NULL && $a->method == 0 ? "Profile" : "Method"), |
|
146 | 146 | "row" => $a->row, |
147 | 147 | "flag" => $optinfo['flag'], |
148 | 148 | "device" => $a->device_id, |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | if ($lc = mysqli_fetch_object($exec_update)->last_change) { |
356 | 356 | if ($lc < $cache->tm) { |
357 | 357 | debug(4, "Installer cached:$cache->download_path\n"); |
358 | - return(['cache'=>$cache->download_path,'mime'=>$cache->mime]); |
|
358 | + return(['cache'=>$cache->download_path, 'mime'=>$cache->mime]); |
|
359 | 359 | } |
360 | 360 | else |
361 | 361 | return NULL; |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | * @param string device the device identifier string |
374 | 374 | * @param string path the path where the new installer can be found |
375 | 375 | */ |
376 | - public function updateCache($device, $path,$mime) { |
|
376 | + public function updateCache($device, $path, $mime) { |
|
377 | 377 | $device = DBConnection::escape_value(Profile::$DB_TYPE, $device); |
378 | 378 | $path = DBConnection::escape_value(Profile::$DB_TYPE, $path); |
379 | 379 | DBConnection::exec(Profile::$DB_TYPE, "INSERT INTO downloads (profile_id,device_id,download_path,mime,lang,installer_time) |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | $attr_value = DBConnection::escape_value(Profile::$DB_TYPE, $attr_value); |
472 | 472 | |
473 | 473 | DBConnection::exec(Profile::$DB_TYPE, "INSERT INTO profile_option (profile_id, option_name, option_value, eap_method_id" . ($device !== 0 ? ",device_id" : "") . ") |
474 | - VALUES(". $this->identifier . ", '$attr_name', '$attr_value', $eap_type" . ($device !== 0 ? ",'". DBConnection::escape_value(Profile::$DB_TYPE, $device) . "'" : "" ) . ")"); |
|
474 | + VALUES(". $this->identifier . ", '$attr_name', '$attr_value', $eap_type" . ($device !== 0 ? ",'" . DBConnection::escape_value(Profile::$DB_TYPE, $device) . "'" : "") . ")"); |
|
475 | 475 | $this->updateFreshness(); |
476 | 476 | } |
477 | 477 | |
@@ -524,20 +524,20 @@ discard block |
||
524 | 524 | * @param string $localpart the username |
525 | 525 | * |
526 | 526 | */ |
527 | - public function setRealmCheckUser($shallwe,$localpart = NULL) { |
|
527 | + public function setRealmCheckUser($shallwe, $localpart = NULL) { |
|
528 | 528 | DBConnection::exec(Profile::$DB_TYPE, |
529 | 529 | "UPDATE profile SET checkuser_outer = " . ($shallwe == true ? "1" : "0") . |
530 | - ( $localpart !== NULL ? ", checkuser_value = '$localpart' " : "") . |
|
530 | + ($localpart !== NULL ? ", checkuser_value = '$localpart' " : "") . |
|
531 | 531 | " WHERE profile_id = $this->identifier"); |
532 | 532 | } |
533 | 533 | |
534 | 534 | /** should username be verified or even prefilled? |
535 | 535 | * |
536 | 536 | */ |
537 | - public function setInputVerificationPreference($verify,$hint) { |
|
537 | + public function setInputVerificationPreference($verify, $hint) { |
|
538 | 538 | DBConnection::exec(Profile::$DB_TYPE, |
539 | 539 | "UPDATE profile SET verify_userinput_suffix = " . ($verify == true ? "1" : "0") . |
540 | - ", hint_userinput_suffix = ". ($hint == true ? "1" : "0") . |
|
540 | + ", hint_userinput_suffix = " . ($hint == true ? "1" : "0") . |
|
541 | 541 | " WHERE profile_id = $this->identifier"); |
542 | 542 | } |
543 | 543 | |
@@ -679,15 +679,15 @@ discard block |
||
679 | 679 | $dev = $factory->device; |
680 | 680 | $redirect_url = getLocalisedValue($this->getAttributes("device-specific:redirect", 0, $d), $locale); |
681 | 681 | $dev_status = AVAILABLE; |
682 | - if(isset($D['options']) && isset($D['options']['message']) && $D['options']['message']) |
|
682 | + if (isset($D['options']) && isset($D['options']['message']) && $D['options']['message']) |
|
683 | 683 | $message = $D['options']['message']; |
684 | 684 | else |
685 | 685 | $message = 0; |
686 | 686 | |
687 | 687 | if ($redirect_url === 0) { |
688 | - if(isset($D['options']) && isset($D['options']['redirect']) && $D['options']['redirect']) { |
|
688 | + if (isset($D['options']) && isset($D['options']['redirect']) && $D['options']['redirect']) { |
|
689 | 689 | $dev_status = HIDDEN; |
690 | - } else { |
|
690 | + } else { |
|
691 | 691 | $eap = $dev->getPreferredEapType($preferred_eap); |
692 | 692 | if ($eap) { |
693 | 693 | if (isset($EAP_options["eap-specific:customtext"][serialize($eap)])) |