@@ -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"); |
@@ -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"; |
@@ -335,42 +335,42 @@ discard block |
||
335 | 335 | private function getInstallerBasename() { |
336 | 336 | $replace_pattern = '/[ ()\/\'"]+/'; |
337 | 337 | $lang_pointer = Config::$LANGUAGES[$this->lang_index]['latin_based'] == TRUE ? 0 : 1; |
338 | - debug(4,"getInstallerBasename1:".$this->attributes['general:instname'][$lang_pointer]."\n"); |
|
338 | + debug(4, "getInstallerBasename1:" . $this->attributes['general:instname'][$lang_pointer] . "\n"); |
|
339 | 339 | $inst = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', $this->attributes['general:instname'][$lang_pointer])); |
340 | - debug(4,"getInstallerBasename2:$inst\n"); |
|
341 | - $Inst_a = explode('_',$inst); |
|
342 | - if(count($Inst_a) > 2) { |
|
340 | + debug(4, "getInstallerBasename2:$inst\n"); |
|
341 | + $Inst_a = explode('_', $inst); |
|
342 | + if (count($Inst_a) > 2) { |
|
343 | 343 | $inst = ''; |
344 | - foreach($Inst_a as $i) |
|
344 | + foreach ($Inst_a as $i) |
|
345 | 345 | $inst .= $i[0]; |
346 | 346 | } |
347 | 347 | $c_name = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', Config::$CONSORTIUM['name'])); |
348 | - if($this->attributes['internal:profile_count'][0] > 1) { |
|
349 | - if(!empty($this->attributes['profile:name']) && ! empty($this->attributes['profile:name'][$lang_pointer])) { |
|
348 | + if ($this->attributes['internal:profile_count'][0] > 1) { |
|
349 | + if (!empty($this->attributes['profile:name']) && !empty($this->attributes['profile:name'][$lang_pointer])) { |
|
350 | 350 | $prof = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', $this->attributes['profile:name'][$lang_pointer])); |
351 | - $prof = preg_replace('/_+$/','',$prof); |
|
352 | - return $c_name. '-'. $this->getDeviceId() . $inst .'-'. $prof; |
|
351 | + $prof = preg_replace('/_+$/', '', $prof); |
|
352 | + return $c_name . '-' . $this->getDeviceId() . $inst . '-' . $prof; |
|
353 | 353 | } |
354 | 354 | } |
355 | - return $c_name. '-'. $this->getDeviceId() . $inst; |
|
355 | + return $c_name . '-' . $this->getDeviceId() . $inst; |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | private function getDeviceId() { |
359 | 359 | $d_id = $this->device_id; |
360 | - if(isset($this->options['device_id'])) |
|
360 | + if (isset($this->options['device_id'])) |
|
361 | 361 | $d_id = $this->options['device_id']; |
362 | - if($d_id !== '') |
|
362 | + if ($d_id !== '') |
|
363 | 363 | $d_id .= '-'; |
364 | 364 | return $d_id; |
365 | 365 | } |
366 | 366 | |
367 | 367 | |
368 | 368 | private function getSSIDs() { |
369 | - $S['add']=[]; |
|
370 | - $S['del']=[]; |
|
369 | + $S['add'] = []; |
|
370 | + $S['del'] = []; |
|
371 | 371 | if (isset(Config::$CONSORTIUM['ssid'])) { |
372 | 372 | foreach (Config::$CONSORTIUM['ssid'] as $ssid) { |
373 | - if(isset(Config::$CONSORTIUM['tkipsupport']) && Config::$CONSORTIUM['tkipsupport'] == TRUE) |
|
373 | + if (isset(Config::$CONSORTIUM['tkipsupport']) && Config::$CONSORTIUM['tkipsupport'] == TRUE) |
|
374 | 374 | $S['add'][$ssid] = 'TKIP'; |
375 | 375 | else { |
376 | 376 | $S['add'][$ssid] = 'AES'; |
@@ -378,20 +378,20 @@ discard block |
||
378 | 378 | } |
379 | 379 | } |
380 | 380 | } |
381 | - if(isset($this->attributes['media:SSID'])) { |
|
381 | + if (isset($this->attributes['media:SSID'])) { |
|
382 | 382 | $SSID = $this->attributes['media:SSID']; |
383 | 383 | |
384 | - foreach($SSID as $ssid) |
|
384 | + foreach ($SSID as $ssid) |
|
385 | 385 | $S['add'][$ssid] = 'AES'; |
386 | 386 | } |
387 | - if(isset($this->attributes['media:SSID_with_legacy'])) { |
|
387 | + if (isset($this->attributes['media:SSID_with_legacy'])) { |
|
388 | 388 | $SSID = $this->attributes['media:SSID_with_legacy']; |
389 | - foreach($SSID as $ssid) |
|
389 | + foreach ($SSID as $ssid) |
|
390 | 390 | $S['add'][$ssid] = 'TKIP'; |
391 | 391 | } |
392 | - if(isset($this->attributes['media:remove_SSID'])) { |
|
392 | + if (isset($this->attributes['media:remove_SSID'])) { |
|
393 | 393 | $SSID = $this->attributes['media:remove_SSID']; |
394 | - foreach($SSID as $ssid) |
|
394 | + foreach ($SSID as $ssid) |
|
395 | 395 | $S['del'][$ssid] = 'DEL'; |
396 | 396 | } |
397 | 397 | return $S; |
@@ -417,25 +417,25 @@ discard block |
||
417 | 417 | ]; |
418 | 418 | |
419 | 419 | private function saveLogoFile($Logos) { |
420 | - $i=0; |
|
421 | - $returnarray= []; |
|
420 | + $i = 0; |
|
421 | + $returnarray = []; |
|
422 | 422 | foreach ($Logos as $blob) { |
423 | 423 | $finfo = new finfo(FILEINFO_MIME_TYPE); |
424 | 424 | $mime = $finfo->buffer($blob); |
425 | - if(preg_match('/^image\/(.*)/',$mime,$m)) |
|
425 | + if (preg_match('/^image\/(.*)/', $mime, $m)) |
|
426 | 426 | $ext = $m[1]; |
427 | 427 | else |
428 | 428 | $ext = 'unsupported'; |
429 | - debug(4,"saveLogoFile: $mime : $ext\n"); |
|
430 | - $f_name = 'logo-'.$i.'.'.$ext; |
|
431 | - $f = fopen($f_name,"w"); |
|
432 | - if(! $f) { |
|
433 | - debug(2,"saveLogoFile failed for: $f_name\n"); |
|
429 | + debug(4, "saveLogoFile: $mime : $ext\n"); |
|
430 | + $f_name = 'logo-' . $i . '.' . $ext; |
|
431 | + $f = fopen($f_name, "w"); |
|
432 | + if (!$f) { |
|
433 | + debug(2, "saveLogoFile failed for: $f_name\n"); |
|
434 | 434 | die("problem opening the file\n"); |
435 | 435 | } |
436 | - fwrite($f,$blob); |
|
436 | + fwrite($f, $blob); |
|
437 | 437 | fclose($f); |
438 | - $returnarray[]= ['name'=>$f_name,'mime'=>$ext]; |
|
438 | + $returnarray[] = ['name'=>$f_name, 'mime'=>$ext]; |
|
439 | 439 | $i++; |
440 | 440 | } |
441 | 441 | return($returnarray); |
@@ -446,17 +446,17 @@ discard block |
||
446 | 446 | $finfo = new finfo(FILEINFO_MIME_TYPE); |
447 | 447 | $mime = $finfo->buffer($blob); |
448 | 448 | $ext = isset($this->mime_extensions[$mime]) ? $this->mime_extensions[$mime] : 'usupported'; |
449 | - debug(4,"saveInfoFile: $mime : $ext\n"); |
|
450 | - $f = fopen('local-info.'.$ext,"w"); |
|
451 | - if(! $f) die("problem opening the file\n"); |
|
452 | - fwrite($f,$blob); |
|
449 | + debug(4, "saveInfoFile: $mime : $ext\n"); |
|
450 | + $f = fopen('local-info.' . $ext, "w"); |
|
451 | + if (!$f) die("problem opening the file\n"); |
|
452 | + fwrite($f, $blob); |
|
453 | 453 | fclose($f); |
454 | - return(['name'=>'local-info.'.$ext,'mime'=>$ext]); |
|
454 | + return(['name'=>'local-info.' . $ext, 'mime'=>$ext]); |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | private function getProfileAttributes(Profile $profile) { |
458 | 458 | $eaps = $profile->getEapMethodsinOrderOfPreference(1); |
459 | - if($eap = $this->getPreferredEapType($eaps)) { |
|
459 | + if ($eap = $this->getPreferredEapType($eaps)) { |
|
460 | 460 | $a = $profile->getCollapsedAttributes($eap); |
461 | 461 | $a['eap'] = $eap; |
462 | 462 | $a['all_eaps'] = $eaps; |
@@ -477,8 +477,8 @@ discard block |
||
477 | 477 | ob_start(); |
478 | 478 | print_r($this->attributes); |
479 | 479 | $output = ob_get_clean(); |
480 | - $f = fopen($file,"w"); |
|
481 | - fwrite($f,$output); |
|
480 | + $f = fopen($file, "w"); |
|
481 | + fwrite($f, $output); |
|
482 | 482 | fclose($f); |
483 | 483 | } |
484 | 484 | /** |
@@ -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); |
@@ -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 |
@@ -957,6 +957,11 @@ discard block |
||
957 | 957 | return $anon_id; |
958 | 958 | } |
959 | 959 | |
960 | + /** |
|
961 | + * @param string $inner_user |
|
962 | + * @param string $password |
|
963 | + * @param string $clientcertdata |
|
964 | + */ |
|
960 | 965 | public function UDP_login($probeindex, $eaptype, $inner_user, $password, $outer_user = '', $opname_check = TRUE, $frag = TRUE, $clientcertdata = NULL) { |
961 | 966 | if (!isset(Config::$RADIUSTESTS['UDP-hosts'][$probeindex])) { |
962 | 967 | $this->UDP_reachability_executed = RETVAL_NOTCONFIGURED; |
@@ -1478,10 +1483,8 @@ discard block |
||
1478 | 1483 | /** |
1479 | 1484 | * This function executes openssl s_client command |
1480 | 1485 | * |
1481 | - * @param string $key points NAPTR_hostname_records |
|
1482 | - * @param string $bracketaddr IP address |
|
1483 | - * @param int $port |
|
1484 | - * @param string $arg arguments to add to the openssl command |
|
1486 | + * @param string $arg arguments to add to the openssl command |
|
1487 | + * @param string $host |
|
1485 | 1488 | * @return string result of oenssl s_client ... |
1486 | 1489 | */ |
1487 | 1490 | function openssl_s_client($host, $arg, &$testresults) { |
@@ -138,6 +138,9 @@ |
||
138 | 138 | $this->test_result['global'] = max($this->test_result['global'],$level); |
139 | 139 | } |
140 | 140 | |
141 | + /** |
|
142 | + * @param string $s |
|
143 | + */ |
|
141 | 144 | private function get_exec_path($s) { |
142 | 145 | $the_path = ""; |
143 | 146 | $exec_is = "UNDEFINED"; |
@@ -75,12 +75,12 @@ discard block |
||
75 | 75 | * @param string $test the test name |
76 | 76 | */ |
77 | 77 | public function test($test) { |
78 | - $this->out[$test] =[]; |
|
78 | + $this->out[$test] = []; |
|
79 | 79 | $this->name = $test; |
80 | - $m_name = $test.'_test'; |
|
80 | + $m_name = $test . '_test'; |
|
81 | 81 | $this->test_result[$test] = 0; |
82 | - if(! method_exists($this,$m_name)) { |
|
83 | - $this->test_return($test,L_ERROR,"Configuration error, no test configured for <strong>$test</strong>."); |
|
82 | + if (!method_exists($this, $m_name)) { |
|
83 | + $this->test_return($test, L_ERROR, "Configuration error, no test configured for <strong>$test</strong>."); |
|
84 | 84 | return; |
85 | 85 | } |
86 | 86 | $this->$m_name(); |
@@ -97,10 +97,10 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function run_tests($Tests) { |
99 | 99 | foreach ($Tests as $t) { |
100 | - if(preg_match('/(.+)=>(.+)/',$t,$m)) { |
|
100 | + if (preg_match('/(.+)=>(.+)/', $t, $m)) { |
|
101 | 101 | $tst = $m[1]; |
102 | - $subtst=$m[2]; |
|
103 | - if($this->test_result[$tst] < L_ERROR) |
|
102 | + $subtst = $m[2]; |
|
103 | + if ($this->test_result[$tst] < L_ERROR) |
|
104 | 104 | $this->test($subtst); |
105 | 105 | } |
106 | 106 | else |
@@ -111,8 +111,8 @@ discard block |
||
111 | 111 | public function get_test_names() { |
112 | 112 | $T = get_class_methods($this); |
113 | 113 | $out = []; |
114 | - foreach($T as $t) { |
|
115 | - if(preg_match('/^(.*)_test$/',$t,$m)) { |
|
114 | + foreach ($T as $t) { |
|
115 | + if (preg_match('/^(.*)_test$/', $t, $m)) { |
|
116 | 116 | $out[] = $m[1]; |
117 | 117 | } |
118 | 118 | } |
@@ -132,17 +132,17 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public $test_result; |
134 | 134 | |
135 | - private function test_return($level,$message) { |
|
135 | + private function test_return($level, $message) { |
|
136 | 136 | $this->out[$this->name][] = ['level'=>$level, 'message'=>$message]; |
137 | - $this->test_result[$this->name] = max($this->test_result[$this->name],$level); |
|
138 | - $this->test_result['global'] = max($this->test_result['global'],$level); |
|
137 | + $this->test_result[$this->name] = max($this->test_result[$this->name], $level); |
|
138 | + $this->test_result['global'] = max($this->test_result['global'], $level); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | private function get_exec_path($s) { |
142 | 142 | $the_path = ""; |
143 | 143 | $exec_is = "UNDEFINED"; |
144 | 144 | if (!empty(Config::$PATHS[$s])) { |
145 | - preg_match('/([^ ]+) ?/',Config::$PATHS[$s],$m); |
|
145 | + preg_match('/([^ ]+) ?/', Config::$PATHS[$s], $m); |
|
146 | 146 | $exe = $m[1]; |
147 | 147 | $the_path = exec("which " . Config::$PATHS[$s]); |
148 | 148 | if ($the_path == $exe) |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | else |
151 | 151 | $exec_is = "IMPLICIT"; |
152 | 152 | } |
153 | - return(['exec'=>$the_path,'exec_is'=>$exec_is]); |
|
153 | + return(['exec'=>$the_path, 'exec_is'=>$exec_is]); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -158,9 +158,9 @@ discard block |
||
158 | 158 | */ |
159 | 159 | private function php_test() { |
160 | 160 | if (version_compare(phpversion(), $this->php_needversion, '>=')) |
161 | - $this->test_return(L_OK,"<strong>PHP</strong> is sufficiently recent. You are running " . phpversion() . "."); |
|
161 | + $this->test_return(L_OK, "<strong>PHP</strong> is sufficiently recent. You are running " . phpversion() . "."); |
|
162 | 162 | else |
163 | - $this->test_return(L_ERROR,"<strong>PHP</strong> is too old. We need at least $this->php_needversion, but you only have ".phpversion(). "."); |
|
163 | + $this->test_return(L_ERROR, "<strong>PHP</strong> is too old. We need at least $this->php_needversion, but you only have " . phpversion() . "."); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -168,9 +168,9 @@ discard block |
||
168 | 168 | */ |
169 | 169 | private function ssp_test() { |
170 | 170 | if (!is_file(CONFIG::$AUTHENTICATION['ssp-path-to-autoloader'])) |
171 | - $this->test_return(L_ERROR,"<strong>simpleSAMLphp</strong> not found!"); |
|
171 | + $this->test_return(L_ERROR, "<strong>simpleSAMLphp</strong> not found!"); |
|
172 | 172 | else |
173 | - $this->test_return(L_OK,"<strong>simpleSAMLphp</strong> autoloader found."); |
|
173 | + $this->test_return(L_OK, "<strong>simpleSAMLphp</strong> autoloader found."); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | */ |
179 | 179 | private function security_test() { |
180 | 180 | if (in_array("I do not care about security!", Config::$SUPERADMINS)) |
181 | - $this->test_return(L_WARN,"You do not care about security. This page should be made accessible to the CAT admin only! See config.php 'Superadmins'!"); |
|
181 | + $this->test_return(L_WARN, "You do not care about security. This page should be made accessible to the CAT admin only! See config.php 'Superadmins'!"); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -186,9 +186,9 @@ discard block |
||
186 | 186 | */ |
187 | 187 | private function zip_test() { |
188 | 188 | if (exec("which zip") != "") |
189 | - $this->test_return(L_OK,"<strong>zip</strong> binary found."); |
|
189 | + $this->test_return(L_OK, "<strong>zip</strong> binary found."); |
|
190 | 190 | else |
191 | - $this->test_return(L_ERROR,"<strong>zip</strong> not found in your \$PATH!"); |
|
191 | + $this->test_return(L_ERROR, "<strong>zip</strong> not found in your \$PATH!"); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -196,15 +196,15 @@ discard block |
||
196 | 196 | */ |
197 | 197 | private function eapol_test_test() { |
198 | 198 | exec(Config::$PATHS['eapol_test'], $out, $retval); |
199 | - if($retval == 255 ) { |
|
200 | - $o = preg_grep('/-o<server cert/',$out); |
|
201 | - if(count($o) > 0) |
|
202 | - $this->test_return(L_OK,"<strong>eapol_test</strong> script found."); |
|
199 | + if ($retval == 255) { |
|
200 | + $o = preg_grep('/-o<server cert/', $out); |
|
201 | + if (count($o) > 0) |
|
202 | + $this->test_return(L_OK, "<strong>eapol_test</strong> script found."); |
|
203 | 203 | else |
204 | - $this->test_return(L_ERROR,"<strong>eapol_test</strong> found, but is too old!"); |
|
204 | + $this->test_return(L_ERROR, "<strong>eapol_test</strong> found, but is too old!"); |
|
205 | 205 | } |
206 | 206 | else |
207 | - $this->test_return(L_ERROR,"<strong>eapol_test</strong> not found!"); |
|
207 | + $this->test_return(L_ERROR, "<strong>eapol_test</strong> not found!"); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -212,9 +212,9 @@ discard block |
||
212 | 212 | */ |
213 | 213 | private function logdir_test() { |
214 | 214 | if (fopen(Config::$PATHS['logdir'] . "/debug.log", "a") == FALSE) |
215 | - $this->test_return(L_WARN,"Log files in <strong>" . Config::$PATHS['logdir'] . "</strong> are not writable!"); |
|
215 | + $this->test_return(L_WARN, "Log files in <strong>" . Config::$PATHS['logdir'] . "</strong> are not writable!"); |
|
216 | 216 | else |
217 | - $this->test_return(L_OK,"Log directory is writable."); |
|
217 | + $this->test_return(L_OK, "Log directory is writable."); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -222,34 +222,34 @@ discard block |
||
222 | 222 | */ |
223 | 223 | private function phpModules_test() { |
224 | 224 | if (function_exists('idn_to_ascii')) |
225 | - $this->test_return(L_OK,"PHP can handle internationalisation."); |
|
225 | + $this->test_return(L_OK, "PHP can handle internationalisation."); |
|
226 | 226 | else |
227 | - $this->test_return(L_ERROR,"PHP can <strongNOT</strong> handle internationalisation (idn_to_ascii() from php5-intl)."); |
|
227 | + $this->test_return(L_ERROR, "PHP can <strongNOT</strong> handle internationalisation (idn_to_ascii() from php5-intl)."); |
|
228 | 228 | |
229 | 229 | if (function_exists('gettext')) |
230 | - $this->test_return(L_OK,"PHP extension <strong>GNU Gettext</strong> is installed."); |
|
230 | + $this->test_return(L_OK, "PHP extension <strong>GNU Gettext</strong> is installed."); |
|
231 | 231 | else |
232 | - $this->test_return(L_ERROR,"PHP extension <strong>GNU Gettext</strong> not found!"); |
|
232 | + $this->test_return(L_ERROR, "PHP extension <strong>GNU Gettext</strong> not found!"); |
|
233 | 233 | |
234 | 234 | if (function_exists('openssl_sign')) |
235 | - $this->test_return(L_OK,"PHP extension <strong>OpenSSL</strong> is installed."); |
|
235 | + $this->test_return(L_OK, "PHP extension <strong>OpenSSL</strong> is installed."); |
|
236 | 236 | else |
237 | - $this->test_return(L_ERROR,"PHP extension <strong>OpenSSL</strong> not found!"); |
|
237 | + $this->test_return(L_ERROR, "PHP extension <strong>OpenSSL</strong> not found!"); |
|
238 | 238 | |
239 | 239 | if (class_exists('Imagick')) |
240 | - $this->test_return(L_OK,"PHP extension <strong>Imagick</strong> is installed."); |
|
240 | + $this->test_return(L_OK, "PHP extension <strong>Imagick</strong> is installed."); |
|
241 | 241 | else |
242 | - $this->test_return(L_ERROR,"PHP extension <strong>Imagick</strong> not found! Get it from your distribution or <a href='http://pecl.php.net/package/imagick'>here</a>."); |
|
242 | + $this->test_return(L_ERROR, "PHP extension <strong>Imagick</strong> not found! Get it from your distribution or <a href='http://pecl.php.net/package/imagick'>here</a>."); |
|
243 | 243 | |
244 | 244 | if (function_exists('ImageCreate')) |
245 | - $this->test_return(L_OK,"PHP extension <strong>GD</strong> is installed."); |
|
245 | + $this->test_return(L_OK, "PHP extension <strong>GD</strong> is installed."); |
|
246 | 246 | else |
247 | - $this->test_return(L_ERROR,"PHP extension <strong>GD</strong> not found!</a>."); |
|
247 | + $this->test_return(L_ERROR, "PHP extension <strong>GD</strong> not found!</a>."); |
|
248 | 248 | |
249 | 249 | if (function_exists('mysqli_connect')) |
250 | - $this->test_return(L_OK,"PHP extension <strong>MySQL</strong> is installed."); |
|
250 | + $this->test_return(L_OK, "PHP extension <strong>MySQL</strong> is installed."); |
|
251 | 251 | else |
252 | - $this->test_return(L_ERROR,"PHP extension <strong>MySQL</strong> not found!"); |
|
252 | + $this->test_return(L_ERROR, "PHP extension <strong>MySQL</strong> not found!"); |
|
253 | 253 | /* |
254 | 254 | if (function_exists('geoip_record_by_name')) { |
255 | 255 | $host = '158.75.1.10'; |
@@ -275,31 +275,31 @@ discard block |
||
275 | 275 | $host_6 = '2001:610:188:444::50'; |
276 | 276 | switch (Config::$GEOIP['version']) { |
277 | 277 | case 0: |
278 | - $this->test_return(L_REMARK,"As set in the config, no geolocation service will be used"); |
|
278 | + $this->test_return(L_REMARK, "As set in the config, no geolocation service will be used"); |
|
279 | 279 | break; |
280 | 280 | case 1: |
281 | 281 | if (!function_exists('geoip_record_by_name')) { |
282 | - $this->test_return(L_ERROR,"PHP extension <strong>GeoIP</strong> (legacy) not found! Get it from your distribution or <a href='http://pecl.php.net/package/geoip'>here</a> or better install GeoIP2 from <a href='https://github.com/maxmind/GeoIP2-php'>here</a>."); |
|
282 | + $this->test_return(L_ERROR, "PHP extension <strong>GeoIP</strong> (legacy) not found! Get it from your distribution or <a href='http://pecl.php.net/package/geoip'>here</a> or better install GeoIP2 from <a href='https://github.com/maxmind/GeoIP2-php'>here</a>."); |
|
283 | 283 | return; |
284 | 284 | } |
285 | 285 | $record = geoip_record_by_name($host_4); |
286 | - if(! $record) { |
|
287 | - $this->test_return(L_ERROR,"PHP extension <strong>GeoIP</strong> (legacy) found but not working properly, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
286 | + if (!$record) { |
|
287 | + $this->test_return(L_ERROR, "PHP extension <strong>GeoIP</strong> (legacy) found but not working properly, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
288 | 288 | return; |
289 | 289 | } |
290 | - if($record['city'] != 'Utrecht') { |
|
291 | - $this->test_return(L_ERROR,"PHP extension <strong>GeoIP</strong> (legacy) found but not working properly, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
290 | + if ($record['city'] != 'Utrecht') { |
|
291 | + $this->test_return(L_ERROR, "PHP extension <strong>GeoIP</strong> (legacy) found but not working properly, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
292 | 292 | return; |
293 | 293 | } |
294 | - $this->test_return(L_REMARK,"PHP extension <strong>GeoIP</strong> (legacy) is installed and working. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly. We stronly advise to replace the legacy GeoIP with GeoIP2 from <a href='https://github.com/maxmind/GeoIP2-php'>here</a>."); |
|
294 | + $this->test_return(L_REMARK, "PHP extension <strong>GeoIP</strong> (legacy) is installed and working. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly. We stronly advise to replace the legacy GeoIP with GeoIP2 from <a href='https://github.com/maxmind/GeoIP2-php'>here</a>."); |
|
295 | 295 | break; |
296 | 296 | case 2: |
297 | - if(! is_file(Config::$GEOIP['geoip2-path-to-autoloader'])) { |
|
298 | - $this->test_return(L_ERROR,"PHP extension <strong>GeoIP2</strong> not found! Get it from <a href='https://github.com/maxmind/GeoIP2-php'>here</a>."); |
|
297 | + if (!is_file(Config::$GEOIP['geoip2-path-to-autoloader'])) { |
|
298 | + $this->test_return(L_ERROR, "PHP extension <strong>GeoIP2</strong> not found! Get it from <a href='https://github.com/maxmind/GeoIP2-php'>here</a>."); |
|
299 | 299 | return; |
300 | 300 | } |
301 | - if(! is_file(Config::$GEOIP['geoip2-path-to-db'])) { |
|
302 | - $this->test_return(L_ERROR,"<strong>GeoIP2 database</strong> not found! See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
301 | + if (!is_file(Config::$GEOIP['geoip2-path-to-db'])) { |
|
302 | + $this->test_return(L_ERROR, "<strong>GeoIP2 database</strong> not found! See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
303 | 303 | return; |
304 | 304 | } |
305 | 305 | require_once Config::$GEOIP['geoip2-path-to-autoloader']; |
@@ -307,27 +307,27 @@ discard block |
||
307 | 307 | try { |
308 | 308 | $record = $reader->city($host_4); |
309 | 309 | } catch (Exception $e) { |
310 | - $this->test_return(L_ERROR,"PHP extension <strong>GeoIP2</strong> found but not working properly, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
310 | + $this->test_return(L_ERROR, "PHP extension <strong>GeoIP2</strong> found but not working properly, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
311 | 311 | return; |
312 | 312 | } |
313 | - if( $record->city->name != 'Utrecht') { |
|
314 | - $this->test_return(L_ERROR,"PHP extension <strong>GeoIP2</strong> found but not working properly, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
313 | + if ($record->city->name != 'Utrecht') { |
|
314 | + $this->test_return(L_ERROR, "PHP extension <strong>GeoIP2</strong> found but not working properly, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
315 | 315 | return; |
316 | 316 | } |
317 | 317 | try { |
318 | 318 | $record = $reader->city($host_6); |
319 | 319 | } catch (Exception $e) { |
320 | - $this->test_return(L_ERROR,"PHP extension <strong>GeoIP2</strong> found but not working properly with IPv6, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
320 | + $this->test_return(L_ERROR, "PHP extension <strong>GeoIP2</strong> found but not working properly with IPv6, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
321 | 321 | return; |
322 | 322 | } |
323 | - if( $record->city->name != 'Utrecht') { |
|
324 | - $this->test_return(L_ERROR,"PHP extension <strong>GeoIP2</strong> found but not working properly with IPv6, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
323 | + if ($record->city->name != 'Utrecht') { |
|
324 | + $this->test_return(L_ERROR, "PHP extension <strong>GeoIP2</strong> found but not working properly with IPv6, perhaps you need to download the databases. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
325 | 325 | return; |
326 | 326 | } |
327 | - $this->test_return(L_OK,"PHP extension <strong>GeoIP2</strong> is installed and working. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
327 | + $this->test_return(L_OK, "PHP extension <strong>GeoIP2</strong> is installed and working. See utils/GeoIP-update.sh in the CAT distribution and use it tu update the GeoIP database regularly."); |
|
328 | 328 | break; |
329 | 329 | default: |
330 | - $this->test_return(L_ERROR,'Check Config::$GEOIP[\'version\'], it must be set to either 1 or 2'); |
|
330 | + $this->test_return(L_ERROR, 'Check Config::$GEOIP[\'version\'], it must be set to either 1 or 2'); |
|
331 | 331 | break; |
332 | 332 | } |
333 | 333 | } |
@@ -337,88 +337,88 @@ discard block |
||
337 | 337 | */ |
338 | 338 | private function openssl_test() { |
339 | 339 | $A = $this->get_exec_path('openssl'); |
340 | - if($A['exec'] != "") { |
|
340 | + if ($A['exec'] != "") { |
|
341 | 341 | $t = exec($A['exec'] . ' version'); |
342 | - if($A['exec_is'] == "EXPLICIT") |
|
343 | - $this->test_return(L_OK,"<strong>$t</strong> was found and is configured explicitly in your config."); |
|
342 | + if ($A['exec_is'] == "EXPLICIT") |
|
343 | + $this->test_return(L_OK, "<strong>$t</strong> was found and is configured explicitly in your config."); |
|
344 | 344 | else |
345 | - $this->test_return(L_WARN,"<strong>$t</strong> was found, but is not configured with an absolute path in your config."); |
|
345 | + $this->test_return(L_WARN, "<strong>$t</strong> was found, but is not configured with an absolute path in your config."); |
|
346 | 346 | } else |
347 | - $this->test_return(L_ERROR,"<strong>openssl</strong> was not found on your system!"); |
|
347 | + $this->test_return(L_ERROR, "<strong>openssl</strong> was not found on your system!"); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | /** |
351 | 351 | * test if makensis is available |
352 | 352 | */ |
353 | 353 | private function makensis_test() { |
354 | - if(! is_numeric(Config::$NSIS_VERSION)) { |
|
355 | - $this->test_return(L_ERROR,"NSIS_VERSION needs to be numeric!"); |
|
354 | + if (!is_numeric(Config::$NSIS_VERSION)) { |
|
355 | + $this->test_return(L_ERROR, "NSIS_VERSION needs to be numeric!"); |
|
356 | 356 | return; |
357 | 357 | } |
358 | - if(Config::$NSIS_VERSION < 2) { |
|
359 | - $this->test_return(L_ERROR,"NSIS_VERSION needs to be at least 2!"); |
|
358 | + if (Config::$NSIS_VERSION < 2) { |
|
359 | + $this->test_return(L_ERROR, "NSIS_VERSION needs to be at least 2!"); |
|
360 | 360 | return; |
361 | 361 | } |
362 | 362 | $A = $this->get_exec_path('makensis'); |
363 | - if($A['exec'] != "") { |
|
363 | + if ($A['exec'] != "") { |
|
364 | 364 | $t = exec($A['exec'] . ' -VERSION'); |
365 | - if($A['exec_is'] == "EXPLICIT") |
|
366 | - $this->test_return(L_OK,"<strong>makensis $t</strong> was found and is configured explicitly in your config."); |
|
365 | + if ($A['exec_is'] == "EXPLICIT") |
|
366 | + $this->test_return(L_OK, "<strong>makensis $t</strong> was found and is configured explicitly in your config."); |
|
367 | 367 | else |
368 | - $this->test_return(L_WARN,"<strong>makensis $t</strong> was found, but is not configured with an absolute path in your config."); |
|
369 | - exec($A['exec'] . ' -HELP',$t); |
|
370 | - $t1 = count(preg_grep('/INPUTCHARSET/',$t)); |
|
371 | - if($t1 == 1 && Config::$NSIS_VERSION == 2) |
|
372 | - $this->test_return(L_ERROR,"Declared NSIS_VERSION does not seem to match the file pointed to by PATHS['makensis']!"); |
|
373 | - if($t1 == 0 && Config::$NSIS_VERSION >= 3) |
|
374 | - $this->test_return(L_ERROR,"Declared NSIS_VERSION does not seem to match the file pointed to by PATHS['makensis']!"); |
|
368 | + $this->test_return(L_WARN, "<strong>makensis $t</strong> was found, but is not configured with an absolute path in your config."); |
|
369 | + exec($A['exec'] . ' -HELP', $t); |
|
370 | + $t1 = count(preg_grep('/INPUTCHARSET/', $t)); |
|
371 | + if ($t1 == 1 && Config::$NSIS_VERSION == 2) |
|
372 | + $this->test_return(L_ERROR, "Declared NSIS_VERSION does not seem to match the file pointed to by PATHS['makensis']!"); |
|
373 | + if ($t1 == 0 && Config::$NSIS_VERSION >= 3) |
|
374 | + $this->test_return(L_ERROR, "Declared NSIS_VERSION does not seem to match the file pointed to by PATHS['makensis']!"); |
|
375 | 375 | } else |
376 | - $this->test_return(L_ERROR,"<strong>makensis</strong> was not found on your system!"); |
|
376 | + $this->test_return(L_ERROR, "<strong>makensis</strong> was not found on your system!"); |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | /** |
380 | 380 | * test if all required NSIS modules are available |
381 | 381 | */ |
382 | 382 | private function NSISmodules_test() { |
383 | - $tmp_dir = createTemporaryDirectory('installer',0)['dir']; |
|
384 | - if(!chdir($tmp_dir)) { |
|
383 | + $tmp_dir = createTemporaryDirectory('installer', 0)['dir']; |
|
384 | + if (!chdir($tmp_dir)) { |
|
385 | 385 | debug(2, "Cannot chdir to $tmp_dir\n"); |
386 | - $this->test_return(L_ERROR,"NSIS modules test - problem with temporary directory permissions, cannot continue"); |
|
386 | + $this->test_return(L_ERROR, "NSIS modules test - problem with temporary directory permissions, cannot continue"); |
|
387 | 387 | return; |
388 | 388 | } |
389 | - $exe= 'tt.exe'; |
|
389 | + $exe = 'tt.exe'; |
|
390 | 390 | $NSIS_Module_status = []; |
391 | 391 | foreach ($this->NSIS_Modules as $module) { |
392 | 392 | unset($out); |
393 | - exec(Config::$PATHS['makensis']." -V1 '-X!include $module' '-XOutFile $exe' '-XSection X' '-XSectionEnd'", $out, $retval); |
|
394 | - if($retval > 0) |
|
393 | + exec(Config::$PATHS['makensis'] . " -V1 '-X!include $module' '-XOutFile $exe' '-XSection X' '-XSectionEnd'", $out, $retval); |
|
394 | + if ($retval > 0) |
|
395 | 395 | $NSIS_Module_status[$module] = 0; |
396 | 396 | else |
397 | 397 | $NSIS_Module_status[$module] = 1; |
398 | 398 | } |
399 | - if(is_file($exe)) |
|
399 | + if (is_file($exe)) |
|
400 | 400 | unlink($exe); |
401 | 401 | foreach ($NSIS_Module_status as $module => $status) { |
402 | - if($status == 1) |
|
403 | - $this->test_return(L_OK,"NSIS module <strong>$module</strong> was found."); |
|
402 | + if ($status == 1) |
|
403 | + $this->test_return(L_OK, "NSIS module <strong>$module</strong> was found."); |
|
404 | 404 | else |
405 | - $this->test_return(L_ERROR,"NSIS module <strong>$module</strong> was not found or is not working correctly."); |
|
405 | + $this->test_return(L_ERROR, "NSIS module <strong>$module</strong> was not found or is not working correctly."); |
|
406 | 406 | } |
407 | 407 | } |
408 | 408 | private function NSIS_GetVersion_test() { |
409 | - $tmp_dir = createTemporaryDirectory('installer',0)['dir']; |
|
410 | - if(!chdir($tmp_dir)) { |
|
409 | + $tmp_dir = createTemporaryDirectory('installer', 0)['dir']; |
|
410 | + if (!chdir($tmp_dir)) { |
|
411 | 411 | debug(2, "Cannot chdir to $tmp_dir\n"); |
412 | - $this->test_return(L_ERROR,"NSIS module <strong>GetVersion</strong> - problem with temporary directory permissions, cannot continue"); |
|
412 | + $this->test_return(L_ERROR, "NSIS module <strong>GetVersion</strong> - problem with temporary directory permissions, cannot continue"); |
|
413 | 413 | return; |
414 | 414 | } |
415 | - $exe= 'tt.exe'; |
|
416 | - exec(Config::$PATHS['makensis']." -V1 '-XOutFile $exe' '-XSection X' '-XGetVersion::WindowsName' '-XSectionEnd'", $out, $retval); |
|
417 | - if($retval > 0) |
|
418 | - $this->test_return(L_ERROR,"NSIS module <strong>GetVersion</strong> was not found or is not working correctly."); |
|
415 | + $exe = 'tt.exe'; |
|
416 | + exec(Config::$PATHS['makensis'] . " -V1 '-XOutFile $exe' '-XSection X' '-XGetVersion::WindowsName' '-XSectionEnd'", $out, $retval); |
|
417 | + if ($retval > 0) |
|
418 | + $this->test_return(L_ERROR, "NSIS module <strong>GetVersion</strong> was not found or is not working correctly."); |
|
419 | 419 | else |
420 | - $this->test_return(L_OK,"NSIS module <strong>GetVersion</strong> was found."); |
|
421 | - if(is_file($exe)) |
|
420 | + $this->test_return(L_OK, "NSIS module <strong>GetVersion</strong> was found."); |
|
421 | + if (is_file($exe)) |
|
422 | 422 | unlink($exe); |
423 | 423 | } |
424 | 424 | |
@@ -426,32 +426,32 @@ discard block |
||
426 | 426 | * test access to dowloads directories |
427 | 427 | */ |
428 | 428 | private function directories_test() { |
429 | - $Dir = createTemporaryDirectory('installer',0); |
|
429 | + $Dir = createTemporaryDirectory('installer', 0); |
|
430 | 430 | $dir = $Dir['dir']; |
431 | 431 | $base = $Dir['base']; |
432 | - if($dir) { |
|
433 | - $this->test_return(L_OK,"Installer cache directory is writable."); |
|
432 | + if ($dir) { |
|
433 | + $this->test_return(L_OK, "Installer cache directory is writable."); |
|
434 | 434 | rrmdir($dir); |
435 | 435 | } else { |
436 | - $this->test_return(L_ERROR,"Installer cache directory $base does not exist or is not writable!"); |
|
436 | + $this->test_return(L_ERROR, "Installer cache directory $base does not exist or is not writable!"); |
|
437 | 437 | } |
438 | - $Dir = createTemporaryDirectory('test',0); |
|
438 | + $Dir = createTemporaryDirectory('test', 0); |
|
439 | 439 | $dir = $Dir['dir']; |
440 | 440 | $base = $Dir['base']; |
441 | - if($dir) { |
|
442 | - $this->test_return(L_OK,"Test directory is writable."); |
|
441 | + if ($dir) { |
|
442 | + $this->test_return(L_OK, "Test directory is writable."); |
|
443 | 443 | rrmdir($dir); |
444 | 444 | } else { |
445 | - $this->test_return(L_ERROR,"Test directory $base does not exist or is not writable!"); |
|
445 | + $this->test_return(L_ERROR, "Test directory $base does not exist or is not writable!"); |
|
446 | 446 | } |
447 | - $Dir = createTemporaryDirectory('logo',0); |
|
447 | + $Dir = createTemporaryDirectory('logo', 0); |
|
448 | 448 | $dir = $Dir['dir']; |
449 | 449 | $base = $Dir['base']; |
450 | - if($dir) { |
|
451 | - $this->test_return(L_OK,"Logos cache directory is writable."); |
|
450 | + if ($dir) { |
|
451 | + $this->test_return(L_OK, "Logos cache directory is writable."); |
|
452 | 452 | rrmdir($dir); |
453 | 453 | } else { |
454 | - $this->test_return(L_ERROR,"Logos cache directory $base does not exist or is not writable!"); |
|
454 | + $this->test_return(L_ERROR, "Logos cache directory $base does not exist or is not writable!"); |
|
455 | 455 | } |
456 | 456 | } |
457 | 457 | |
@@ -466,16 +466,16 @@ discard block |
||
466 | 466 | $allthere .= $onelanguage['locale'] . " "; |
467 | 467 | |
468 | 468 | if ($allthere == "") |
469 | - $this->test_return(L_OK,"All of your configured locales are available on your system."); |
|
469 | + $this->test_return(L_OK, "All of your configured locales are available on your system."); |
|
470 | 470 | else |
471 | - $this->test_return(L_WARN,"Some of your configured locales (<strong>$allthere</strong>) are not installed and will not be displayed correctly!"); |
|
471 | + $this->test_return(L_WARN, "Some of your configured locales (<strong>$allthere</strong>) are not installed and will not be displayed correctly!"); |
|
472 | 472 | } |
473 | 473 | |
474 | - private function check_config_default($type,$key,$value) { |
|
474 | + private function check_config_default($type, $key, $value) { |
|
475 | 475 | if (empty(Config::$type[$key])) |
476 | - $missingvalues .="type/webcert_OCSP "; |
|
476 | + $missingvalues .= "type/webcert_OCSP "; |
|
477 | 477 | elseif (Config::$type['webcert_OCSP'] == $value) |
478 | - $defaultvalues .="type/$key "; |
|
478 | + $defaultvalues .= "type/$key "; |
|
479 | 479 | } |
480 | 480 | |
481 | 481 | |
@@ -486,31 +486,31 @@ discard block |
||
486 | 486 | $defaultvalues = ""; |
487 | 487 | $missingvalues = ""; |
488 | 488 | if (Config::$APPEARANCE['from-mail'] == "[email protected]") |
489 | - $defaultvalues .="APPEARANCE/from-mail "; |
|
489 | + $defaultvalues .= "APPEARANCE/from-mail "; |
|
490 | 490 | if (Config::$APPEARANCE['support-contact']['url'] == "[email protected]?body=Only%20English%20language%20please!") |
491 | - $defaultvalues .="APPEARANCE/support-contact/url "; |
|
491 | + $defaultvalues .= "APPEARANCE/support-contact/url "; |
|
492 | 492 | if (Config::$APPEARANCE['support-contact']['display'] == "[email protected]") |
493 | - $defaultvalues .="APPEARANCE/support-contact/display "; |
|
493 | + $defaultvalues .= "APPEARANCE/support-contact/display "; |
|
494 | 494 | if (Config::$APPEARANCE['support-contact']['developer-mail'] == "[email protected]") |
495 | - $defaultvalues .="APPEARANCE/support-contact/mail "; |
|
495 | + $defaultvalues .= "APPEARANCE/support-contact/mail "; |
|
496 | 496 | if (Config::$APPEARANCE['abuse-mail'] == "[email protected]") |
497 | - $defaultvalues .="APPEARANCE/abuse-mail "; |
|
497 | + $defaultvalues .= "APPEARANCE/abuse-mail "; |
|
498 | 498 | if (Config::$APPEARANCE['MOTD'] == "Release Candidate. All bugs to be shot on sight!") |
499 | - $defaultvalues .="APPEARANCE/MOTD "; |
|
499 | + $defaultvalues .= "APPEARANCE/MOTD "; |
|
500 | 500 | if (Config::$APPEARANCE['webcert_CRLDP'] == ['list', 'of', 'CRL', 'pointers']) |
501 | - $defaultvalues .="APPEARANCE/webcert_CRLDP "; |
|
501 | + $defaultvalues .= "APPEARANCE/webcert_CRLDP "; |
|
502 | 502 | if (empty(Config::$APPEARANCE['webcert_OCSP'])) |
503 | - $missingvalues .="APPEARANCE/webcert_OCSP "; |
|
503 | + $missingvalues .= "APPEARANCE/webcert_OCSP "; |
|
504 | 504 | elseif (Config::$APPEARANCE['webcert_OCSP'] == ['list', 'of', 'OCSP', 'pointers']) |
505 | - $defaultvalues .="APPEARANCE/webcert_OCSP "; |
|
505 | + $defaultvalues .= "APPEARANCE/webcert_OCSP "; |
|
506 | 506 | if (isset(Config::$RADIUSTESTS['UDP-hosts'][0]) && Config::$RADIUSTESTS['UDP-hosts'][0]['ip'] == "192.0.2.1") |
507 | - $defaultvalues .="RADIUSTESTS/UDP-hosts "; |
|
507 | + $defaultvalues .= "RADIUSTESTS/UDP-hosts "; |
|
508 | 508 | if (Config::$DB['INST']['host'] == "db.host.example") |
509 | - $defaultvalues .="DB/INST "; |
|
509 | + $defaultvalues .= "DB/INST "; |
|
510 | 510 | if (Config::$DB['INST']['host'] == "db.host.example") |
511 | - $defaultvalues .="DB/USER "; |
|
512 | - if(!empty(Config::$DB['EXTERNAL']) && Config::$DB['EXTERNAL']['host'] == "customerdb.otherhost.example") |
|
513 | - $defaultvalues .="DB/EXTERNAL "; |
|
511 | + $defaultvalues .= "DB/USER "; |
|
512 | + if (!empty(Config::$DB['EXTERNAL']) && Config::$DB['EXTERNAL']['host'] == "customerdb.otherhost.example") |
|
513 | + $defaultvalues .= "DB/EXTERNAL "; |
|
514 | 514 | $files = []; |
515 | 515 | foreach (Config::$RADIUSTESTS['TLS-clientcerts'] as $cadata) { |
516 | 516 | foreach ($cadata['certificates'] as $cert_files) { |
@@ -522,14 +522,14 @@ discard block |
||
522 | 522 | foreach ($files as $file) { |
523 | 523 | $handle = fopen(CAT::$root . "/config/cli-certs/" . $file, 'r'); |
524 | 524 | if (!$handle) |
525 | - $defaultvalues .="CERTIFICATE/$file "; |
|
525 | + $defaultvalues .= "CERTIFICATE/$file "; |
|
526 | 526 | else |
527 | 527 | fclose($handle); |
528 | 528 | } |
529 | 529 | if ($defaultvalues != "") |
530 | - $this->test_return(L_WARN,"Your configuration in config/config.php contains unchanged default values or links to inexistent files: <strong>$defaultvalues</strong>!"); |
|
530 | + $this->test_return(L_WARN, "Your configuration in config/config.php contains unchanged default values or links to inexistent files: <strong>$defaultvalues</strong>!"); |
|
531 | 531 | else |
532 | - $this->test_return(L_OK,"Your configuration does not contain any unchanged defaults, which is a good sign."); |
|
532 | + $this->test_return(L_OK, "Your configuration does not contain any unchanged defaults, which is a good sign."); |
|
533 | 533 | } |
534 | 534 | |
535 | 535 | /** |
@@ -538,37 +538,37 @@ discard block |
||
538 | 538 | private function databases_test() { |
539 | 539 | $DB = 'INST'; |
540 | 540 | $db = mysqli_connect(Config::$DB[$DB]['host'], Config::$DB[$DB]['user'], Config::$DB[$DB]['pass'], Config::$DB[$DB]['db']); |
541 | - if(! $db) { |
|
542 | - $this->test_return(L_ERROR,"Connection to the $DB database failed"); |
|
541 | + if (!$db) { |
|
542 | + $this->test_return(L_ERROR, "Connection to the $DB database failed"); |
|
543 | 543 | } else { |
544 | - $r = mysqli_query($db,'select * from profile_option_dict'); |
|
545 | - if($r->num_rows == $this->profile_option_ct) |
|
546 | - $this->test_return(L_OK,"The $DB database appears to be OK."); |
|
544 | + $r = mysqli_query($db, 'select * from profile_option_dict'); |
|
545 | + if ($r->num_rows == $this->profile_option_ct) |
|
546 | + $this->test_return(L_OK, "The $DB database appears to be OK."); |
|
547 | 547 | else |
548 | - $this->test_return(L_ERROR,"The $DB database is reacheable but probably not updated to this version of CAT."); |
|
548 | + $this->test_return(L_ERROR, "The $DB database is reacheable but probably not updated to this version of CAT."); |
|
549 | 549 | } |
550 | 550 | $DB = 'USER'; |
551 | 551 | $db = mysqli_connect(Config::$DB[$DB]['host'], Config::$DB[$DB]['user'], Config::$DB[$DB]['pass'], Config::$DB[$DB]['db']); |
552 | - if(! $db) { |
|
553 | - $this->test_return(L_ERROR,"Connection to the $DB database failed"); |
|
552 | + if (!$db) { |
|
553 | + $this->test_return(L_ERROR, "Connection to the $DB database failed"); |
|
554 | 554 | } else { |
555 | - $r = mysqli_query($db,'desc view_admin'); |
|
556 | - if($r->num_rows == $this->view_admin_ct) |
|
557 | - $this->test_return(L_OK,"The $DB database appears to be OK."); |
|
555 | + $r = mysqli_query($db, 'desc view_admin'); |
|
556 | + if ($r->num_rows == $this->view_admin_ct) |
|
557 | + $this->test_return(L_OK, "The $DB database appears to be OK."); |
|
558 | 558 | else |
559 | - $this->test_return(L_ERROR,"The $DB is reacheable but there is something wrong with the schema"); |
|
559 | + $this->test_return(L_ERROR, "The $DB is reacheable but there is something wrong with the schema"); |
|
560 | 560 | } |
561 | 561 | $DB = 'EXTERNAL'; |
562 | - if(! empty(Config::$DB[$DB])) { |
|
562 | + if (!empty(Config::$DB[$DB])) { |
|
563 | 563 | $db = mysqli_connect(Config::$DB[$DB]['host'], Config::$DB[$DB]['user'], Config::$DB[$DB]['pass'], Config::$DB[$DB]['db']); |
564 | - if(! $db) { |
|
565 | - $this->test_return(L_ERROR,"Connection to the $DB database failed"); |
|
564 | + if (!$db) { |
|
565 | + $this->test_return(L_ERROR, "Connection to the $DB database failed"); |
|
566 | 566 | } else { |
567 | - $r = mysqli_query($db,'desc view_admin'); |
|
568 | - if($r->num_rows == $this->view_admin_ct) |
|
569 | - $this->test_return(L_OK,"The $DB database appears to be OK."); |
|
567 | + $r = mysqli_query($db, 'desc view_admin'); |
|
568 | + if ($r->num_rows == $this->view_admin_ct) |
|
569 | + $this->test_return(L_OK, "The $DB database appears to be OK."); |
|
570 | 570 | else |
571 | - $this->test_return(L_ERROR,"The $DB is reacheable but there is something wrong with the schema"); |
|
571 | + $this->test_return(L_ERROR, "The $DB is reacheable but there is something wrong with the schema"); |
|
572 | 572 | } |
573 | 573 | } |
574 | 574 | } |
@@ -578,37 +578,37 @@ discard block |
||
578 | 578 | * test devices.php for the no_cache option |
579 | 579 | */ |
580 | 580 | private function device_cache_test() { |
581 | - if((! empty(Devices::$Options['no_cache'])) && Devices::$Options['no_cache']) |
|
581 | + if ((!empty(Devices::$Options['no_cache'])) && Devices::$Options['no_cache']) |
|
582 | 582 | $global_no_cache = 1; |
583 | 583 | else |
584 | 584 | $global_no_cache = 0; |
585 | 585 | |
586 | - if($global_no_cache == 1) |
|
587 | - $this->test_return(L_WARN,"Devices no_cache global option is set, this is not a good idea in a production setting\n"); |
|
586 | + if ($global_no_cache == 1) |
|
587 | + $this->test_return(L_WARN, "Devices no_cache global option is set, this is not a good idea in a production setting\n"); |
|
588 | 588 | $Devs = Devices::listDevices(); |
589 | 589 | $no_cache_dev = ''; |
590 | 590 | $no_cache_dev_count = 0; |
591 | - if($global_no_cache) { |
|
591 | + if ($global_no_cache) { |
|
592 | 592 | foreach ($Devs as $dev=>$D) { |
593 | - if(empty($D['options']['no_cache']) || $D['options']['no_cache'] != 0) { |
|
594 | - $no_cache_dev .= $dev." "; |
|
593 | + if (empty($D['options']['no_cache']) || $D['options']['no_cache'] != 0) { |
|
594 | + $no_cache_dev .= $dev . " "; |
|
595 | 595 | $no_cache_dev_count++; |
596 | 596 | } |
597 | 597 | } |
598 | 598 | } else { |
599 | 599 | foreach ($Devs as $dev=>$D) { |
600 | - if(!empty($D['options']['no_cache']) && $D['options']['no_cache'] != 0) { |
|
601 | - $no_cache_dev .= $dev." "; |
|
600 | + if (!empty($D['options']['no_cache']) && $D['options']['no_cache'] != 0) { |
|
601 | + $no_cache_dev .= $dev . " "; |
|
602 | 602 | $no_cache_dev_count++; |
603 | 603 | } |
604 | 604 | } |
605 | 605 | } |
606 | 606 | |
607 | 607 | |
608 | - if($no_cache_dev_count > 1 ) |
|
609 | - $this->test_return(L_WARN,"The following devices will not be cached: $no_cache_dev"); |
|
610 | - if($no_cache_dev_count == 1 ) |
|
611 | - $this->test_return(L_WARN,"The following device will not be cached: $no_cache_dev"); |
|
608 | + if ($no_cache_dev_count > 1) |
|
609 | + $this->test_return(L_WARN, "The following devices will not be cached: $no_cache_dev"); |
|
610 | + if ($no_cache_dev_count == 1) |
|
611 | + $this->test_return(L_WARN, "The following device will not be cached: $no_cache_dev"); |
|
612 | 612 | |
613 | 613 | } |
614 | 614 | |
@@ -617,7 +617,7 @@ discard block |
||
617 | 617 | */ |
618 | 618 | private function mailer_test() { |
619 | 619 | if (empty(Config::$APPEARANCE['abuse-mail']) || Config::$APPEARANCE['abuse-mail'] == "[email protected]") { |
620 | - $this->test_return(L_ERROR,"Your abuse-mail has not been set, cannot continue with mailer tests."); |
|
620 | + $this->test_return(L_ERROR, "Your abuse-mail has not been set, cannot continue with mailer tests."); |
|
621 | 621 | return; |
622 | 622 | } |
623 | 623 | $mail = new PHPMailer(); |
@@ -637,10 +637,10 @@ discard block |
||
637 | 637 | $mail->Subject = "testing CAT configuration mail"; |
638 | 638 | $mail->Body = "Testing CAT mailing\n"; |
639 | 639 | $sent = $mail->send(); |
640 | - if($sent) |
|
641 | - $this->test_return(L_OK,"mailer settings appear to be working, check ".Config::$APPEARANCE['abuse-mail']." mailbox if the message was receiced."); |
|
640 | + if ($sent) |
|
641 | + $this->test_return(L_OK, "mailer settings appear to be working, check " . Config::$APPEARANCE['abuse-mail'] . " mailbox if the message was receiced."); |
|
642 | 642 | else |
643 | - $this->test_return(L_ERROR,"mailer settings failed, check the Config::MAILSETTINGS"); |
|
643 | + $this->test_return(L_ERROR, "mailer settings failed, check the Config::MAILSETTINGS"); |
|
644 | 644 | |
645 | 645 | } |
646 | 646 |
@@ -260,7 +260,6 @@ discard block |
||
260 | 260 | /** |
261 | 261 | * Return the list of IdPs in a given country |
262 | 262 | * |
263 | - * @param int $idp_id the IdP identifier |
|
264 | 263 | * @return string JSON encoded data |
265 | 264 | */ |
266 | 265 | |
@@ -301,7 +300,6 @@ discard block |
||
301 | 300 | /** |
302 | 301 | * Return the list of IdPs in a given country ordered with respect to the user location |
303 | 302 | * |
304 | - * @param int $idp_id the IdP identifier |
|
305 | 303 | * @return string JSON encoded data |
306 | 304 | */ |
307 | 305 |
@@ -52,21 +52,21 @@ discard block |
||
52 | 52 | * link - the path name of the resulting installer |
53 | 53 | * mime - the mimetype of the installer |
54 | 54 | */ |
55 | - public function generateInstaller($device,$prof_id, $generated_for = "user") { |
|
55 | + public function generateInstaller($device, $prof_id, $generated_for = "user") { |
|
56 | 56 | $this->set_locale("devices"); |
57 | 57 | $Dev = Devices::listDevices(); |
58 | 58 | $Config = $Dev[$device]; |
59 | - debug(4,"installer:$device:$prof_id\n"); |
|
59 | + debug(4, "installer:$device:$prof_id\n"); |
|
60 | 60 | $profile = new Profile($prof_id); |
61 | 61 | $attribs = $profile->getCollapsedAttributes(); |
62 | 62 | // test if the profile is production-ready and if not if the authenticated user is an owner |
63 | 63 | if (!isset($attribs['profile:production']) || (isset($attribs['profile:production']) && $attribs['profile:production'][0] != "on")) { |
64 | - debug(4,"Attempt to download a non-production ready installer fir profile: $prof_id\n"); |
|
64 | + debug(4, "Attempt to download a non-production ready installer fir profile: $prof_id\n"); |
|
65 | 65 | require_once(Config::$AUTHENTICATION['ssp-path-to-autoloader']); |
66 | 66 | $as = new SimpleSAML_Auth_Simple(Config::$AUTHENTICATION['ssp-authsource']); |
67 | - if($as->isAuthenticated()) { |
|
67 | + if ($as->isAuthenticated()) { |
|
68 | 68 | $user_object = new User($_SESSION['user']); |
69 | - if($user_object->isIdPOwner($profile->institution)) { |
|
69 | + if ($user_object->isIdPOwner($profile->institution)) { |
|
70 | 70 | debug(4, "User is the owner - allowing access\n"); |
71 | 71 | } else { |
72 | 72 | debug(2, "User not an owner of a non-production profile - access forbidden\n"); |
@@ -82,38 +82,38 @@ discard block |
||
82 | 82 | $a = []; |
83 | 83 | $a['profile'] = $prof_id; |
84 | 84 | $a['device'] = $device; |
85 | - if( (isset(Devices::$Options['no_cache']) && Devices::$Options['no_cache'] ) || ( isset($Config['options']['no_cache']) && $Config['options']['no_cache'] )) |
|
85 | + if ((isset(Devices::$Options['no_cache']) && Devices::$Options['no_cache']) || (isset($Config['options']['no_cache']) && $Config['options']['no_cache'])) |
|
86 | 86 | $this->i_path = FALSE; |
87 | 87 | else { |
88 | 88 | $cache = $profile->testCache($device); |
89 | 89 | $this->i_path = $cache['cache']; |
90 | 90 | } |
91 | - if($this->i_path && is_file($this->i_path)) { |
|
92 | - debug(4,"Using cached installer for: $device\n"); |
|
93 | - $a['link'] = "API.php?api_version=$version&action=downloadInstaller&lang=".CAT::get_lang()."&profile=$prof_id&device=$device&generatedfor=$generated_for"; |
|
91 | + if ($this->i_path && is_file($this->i_path)) { |
|
92 | + debug(4, "Using cached installer for: $device\n"); |
|
93 | + $a['link'] = "API.php?api_version=$version&action=downloadInstaller&lang=" . CAT::get_lang() . "&profile=$prof_id&device=$device&generatedfor=$generated_for"; |
|
94 | 94 | $a['mime'] = $cache['mime']; |
95 | 95 | } else { |
96 | 96 | $factory = new DeviceFactory($device); |
97 | 97 | $dev = $factory->device; |
98 | - if(isset($dev)) { |
|
98 | + if (isset($dev)) { |
|
99 | 99 | $dev->setup($profile); |
100 | 100 | $installer = $dev->writeInstaller(); |
101 | - $i_path = $dev->FPATH.'/tmp/'.$installer; |
|
102 | - if($i_path && is_file($i_path)) { |
|
103 | - if(isset($dev->options['mime'])) |
|
101 | + $i_path = $dev->FPATH . '/tmp/' . $installer; |
|
102 | + if ($i_path && is_file($i_path)) { |
|
103 | + if (isset($dev->options['mime'])) |
|
104 | 104 | $a['mime'] = $dev->options['mime']; |
105 | 105 | else { |
106 | 106 | $info = new finfo(); |
107 | 107 | $a['mime'] = $info->file($i_path, FILEINFO_MIME_TYPE); |
108 | 108 | } |
109 | - $this->i_path = $dev->FPATH.'/'.$installer; |
|
109 | + $this->i_path = $dev->FPATH . '/' . $installer; |
|
110 | 110 | rename($i_path, $this->i_path); |
111 | - $profile->updateCache($device,$this->i_path,$a['mime']); |
|
111 | + $profile->updateCache($device, $this->i_path, $a['mime']); |
|
112 | 112 | // rrmdir($dev->FPATH.'/tmp'); |
113 | - debug(4,"Generated installer: ".$this->i_path.": for: $device\n"); |
|
114 | - $a['link'] = "API.php?api_version=$version&action=downloadInstaller&lang=".CAT::get_lang()."&profile=$prof_id&device=$device&generatedfor=$generated_for"; |
|
113 | + debug(4, "Generated installer: " . $this->i_path . ": for: $device\n"); |
|
114 | + $a['link'] = "API.php?api_version=$version&action=downloadInstaller&lang=" . CAT::get_lang() . "&profile=$prof_id&device=$device&generatedfor=$generated_for"; |
|
115 | 115 | } else { |
116 | - debug(2,"Installer generation failed for: $prof_id:$device:".CAT::get_lang()."\n"); |
|
116 | + debug(2, "Installer generation failed for: $prof_id:$device:" . CAT::get_lang() . "\n"); |
|
117 | 117 | $a['link'] = 0; |
118 | 118 | } |
119 | 119 | } |
@@ -129,31 +129,31 @@ discard block |
||
129 | 129 | $Dev = Devices::listDevices(); |
130 | 130 | $R = []; |
131 | 131 | $ct = 0; |
132 | - if($show_hidden !== 0 && $show_hidden != 1) |
|
132 | + if ($show_hidden !== 0 && $show_hidden != 1) |
|
133 | 133 | return; |
134 | 134 | foreach ($Dev as $device => $D) { |
135 | - if(isset($D['options']['hidden']) && $D['options']['hidden'] && $show_hidden == 0) |
|
135 | + if (isset($D['options']['hidden']) && $D['options']['hidden'] && $show_hidden == 0) |
|
136 | 136 | continue; |
137 | - $ct ++; |
|
138 | - if($this->version == 1) |
|
137 | + $ct++; |
|
138 | + if ($this->version == 1) |
|
139 | 139 | $D['device'] = $device; |
140 | 140 | else |
141 | 141 | $D['device'] = $device; |
142 | 142 | $group = isset($D['group']) ? $D['group'] : 'other'; |
143 | - if (! isset($R[$group])) |
|
143 | + if (!isset($R[$group])) |
|
144 | 144 | $R[$group] = []; |
145 | 145 | $R[$group][$device] = $D; |
146 | 146 | } |
147 | 147 | return $R; |
148 | 148 | } |
149 | 149 | |
150 | - public function deviceInfo($device,$prof_id) { |
|
150 | + public function deviceInfo($device, $prof_id) { |
|
151 | 151 | $this->set_locale("devices"); |
152 | 152 | $out = 0; |
153 | 153 | $profile = new Profile($prof_id); |
154 | 154 | $factory = new DeviceFactory($device); |
155 | 155 | $dev = $factory->device; |
156 | - if(isset($dev)) { |
|
156 | + if (isset($dev)) { |
|
157 | 157 | // $dev->setup($profile); |
158 | 158 | $out = $dev->writeDeviceInfo(); |
159 | 159 | } |
@@ -178,13 +178,13 @@ discard block |
||
178 | 178 | $profile = new Profile($prof_id); |
179 | 179 | $attr = $profile->getCollapsedAttributes(); |
180 | 180 | $a = []; |
181 | - if(isset($attr['support:email'])) |
|
181 | + if (isset($attr['support:email'])) |
|
182 | 182 | $a['local_email'] = $attr['support:email'][0]; |
183 | - if(isset($attr['support:phone'])) |
|
183 | + if (isset($attr['support:phone'])) |
|
184 | 184 | $a['local_phone'] = $attr['support:phone'][0]; |
185 | - if(isset($attr['support:url'])) |
|
185 | + if (isset($attr['support:url'])) |
|
186 | 186 | $a['local_url'] = $attr['support:url'][0]; |
187 | - if(isset($attr['profile:description'])) |
|
187 | + if (isset($attr['profile:description'])) |
|
188 | 188 | $a['description'] = $attr['profile:description'][0]; |
189 | 189 | $a['devices'] = $profile->listDevices(); |
190 | 190 | $this->set_locale("web_user"); |
@@ -196,30 +196,30 @@ discard block |
||
196 | 196 | cicumstances |
197 | 197 | */ |
198 | 198 | private function GetRootURL() { |
199 | - $backtrace = debug_backtrace(); |
|
199 | + $backtrace = debug_backtrace(); |
|
200 | 200 | $F = array_pop($backtrace); |
201 | - $file= $F['file']; |
|
202 | - $file = substr($file,strlen(dirname(__DIR__))); |
|
203 | - while(substr($file,0,1) == '/') |
|
204 | - $file = substr($file,1); |
|
205 | - $n = count(explode('/',$file)); |
|
201 | + $file = $F['file']; |
|
202 | + $file = substr($file, strlen(dirname(__DIR__))); |
|
203 | + while (substr($file, 0, 1) == '/') |
|
204 | + $file = substr($file, 1); |
|
205 | + $n = count(explode('/', $file)); |
|
206 | 206 | $out = $_SERVER['SCRIPT_NAME']; |
207 | - for ($i= 0; $i < $n; $i++) |
|
207 | + for ($i = 0; $i < $n; $i++) |
|
208 | 208 | $out = dirname($out); |
209 | 209 | if ($out == '/') |
210 | 210 | $out = ''; |
211 | 211 | $s = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 'https' : 'http'; |
212 | - $s .= '://'.$_SERVER['HTTP_HOST'] . $out; |
|
212 | + $s .= '://' . $_SERVER['HTTP_HOST'] . $out; |
|
213 | 213 | return $s; |
214 | 214 | } |
215 | 215 | |
216 | 216 | /* JSON functions */ |
217 | 217 | |
218 | - public function return_json($data,$status=1) { |
|
218 | + public function return_json($data, $status = 1) { |
|
219 | 219 | $return_array = []; |
220 | 220 | $return_array['status'] = $status; |
221 | 221 | $return_array['data'] = $data; |
222 | - $return_array['tou'] = "Please consult Terms of Use at: ".$this->GetRootURL()."/tou.php"; |
|
222 | + $return_array['tou'] = "Please consult Terms of Use at: " . $this->GetRootURL() . "/tou.php"; |
|
223 | 223 | return(json_encode($return_array)); |
224 | 224 | } |
225 | 225 | |
@@ -230,11 +230,11 @@ discard block |
||
230 | 230 | */ |
231 | 231 | public function JSON_listLanguages() { |
232 | 232 | $return_array = []; |
233 | - foreach(Config::$LANGUAGES as $id => $val){ |
|
234 | - if($this->version == 1) |
|
235 | - $return_array[] = ['id'=>$id,'display'=>$val['display'],'locale'=>$val['locale']]; |
|
233 | + foreach (Config::$LANGUAGES as $id => $val) { |
|
234 | + if ($this->version == 1) |
|
235 | + $return_array[] = ['id'=>$id, 'display'=>$val['display'], 'locale'=>$val['locale']]; |
|
236 | 236 | else |
237 | - $return_array[] = ['lang'=>$id,'display'=>$val['display'],'locale'=>$val['locale']]; |
|
237 | + $return_array[] = ['lang'=>$id, 'display'=>$val['display'], 'locale'=>$val['locale']]; |
|
238 | 238 | } |
239 | 239 | echo $this->return_json($return_array); |
240 | 240 | } |
@@ -249,10 +249,10 @@ discard block |
||
249 | 249 | $FED = $this->printCountryList(1); |
250 | 250 | $return_array = []; |
251 | 251 | foreach ($FED as $id => $val) { |
252 | - if($this->version == 1) |
|
253 | - $return_array[] = ['id'=>$id,'display'=>$val]; |
|
252 | + if ($this->version == 1) |
|
253 | + $return_array[] = ['id'=>$id, 'display'=>$val]; |
|
254 | 254 | else |
255 | - $return_array[] = ['federation'=>$id,'display'=>$val]; |
|
255 | + $return_array[] = ['federation'=>$id, 'display'=>$val]; |
|
256 | 256 | } |
257 | 257 | echo $this->return_json($return_array); |
258 | 258 | } |
@@ -265,13 +265,13 @@ discard block |
||
265 | 265 | */ |
266 | 266 | |
267 | 267 | public function JSON_listIdentityProviders($country) { |
268 | - $idps = Federation::listAllIdentityProviders(1,$country); |
|
268 | + $idps = Federation::listAllIdentityProviders(1, $country); |
|
269 | 269 | $return_array = []; |
270 | 270 | foreach ($idps as $idp) { |
271 | - if($this->version == 1) |
|
272 | - $return_array[] = ['id'=>$idp['entityID'],'display'=>$idp['title']]; |
|
271 | + if ($this->version == 1) |
|
272 | + $return_array[] = ['id'=>$idp['entityID'], 'display'=>$idp['title']]; |
|
273 | 273 | else |
274 | - $return_array[] = ['idp'=>$idp['entityID'],'display'=>$idp['title']]; |
|
274 | + $return_array[] = ['idp'=>$idp['entityID'], 'display'=>$idp['title']]; |
|
275 | 275 | } |
276 | 276 | echo $this->return_json($return_array); |
277 | 277 | } |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | $idps = Federation::listAllIdentityProviders(1); |
288 | 288 | $return_array = []; |
289 | 289 | foreach ($idps as $idp) { |
290 | - if($this->version == 1) |
|
290 | + if ($this->version == 1) |
|
291 | 291 | $idp['id'] = $idp['entityID']; |
292 | 292 | else |
293 | 293 | $idp['idp'] = $idp['entityID']; |
@@ -306,14 +306,14 @@ discard block |
||
306 | 306 | */ |
307 | 307 | |
308 | 308 | |
309 | - public function JSON_orderIdentityProviders($country,$L=NULL) { |
|
310 | - $idps = $this->orderIdentityProviders($country,$L); |
|
309 | + public function JSON_orderIdentityProviders($country, $L = NULL) { |
|
310 | + $idps = $this->orderIdentityProviders($country, $L); |
|
311 | 311 | $return_array = []; |
312 | 312 | foreach ($idps as $idp) { |
313 | - if($this->version == 1) |
|
314 | - $return_array[] = ['id'=>$idp['id'],'display'=>$idp['title']]; |
|
313 | + if ($this->version == 1) |
|
314 | + $return_array[] = ['id'=>$idp['id'], 'display'=>$idp['title']]; |
|
315 | 315 | else |
316 | - $return_array[] = ['idp'=>$idp['id'],'display'=>$idp['title']]; |
|
316 | + $return_array[] = ['idp'=>$idp['id'], 'display'=>$idp['title']]; |
|
317 | 317 | } |
318 | 318 | echo $this->return_json($return_array); |
319 | 319 | } |
@@ -324,28 +324,28 @@ discard block |
||
324 | 324 | * @param int $idp_id the IdP identifier |
325 | 325 | * @return string JSON encoded data |
326 | 326 | */ |
327 | - public function JSON_listProfiles($idp_id,$sort = 0) { |
|
327 | + public function JSON_listProfiles($idp_id, $sort = 0) { |
|
328 | 328 | $this->set_locale("web_user"); |
329 | 329 | $return_array = []; |
330 | 330 | try { |
331 | 331 | $idp = new IdP($idp_id); |
332 | 332 | } |
333 | 333 | catch (Exception $fail) { |
334 | - echo $this->return_json($return_array,0); |
|
334 | + echo $this->return_json($return_array, 0); |
|
335 | 335 | return; |
336 | 336 | } |
337 | 337 | $l = 0; |
338 | 338 | $logo = $idp->getAttributes('general:logo_file'); |
339 | - if($logo) |
|
339 | + if ($logo) |
|
340 | 340 | $l = 1; |
341 | 341 | $profiles = $idp->listProfiles(1); |
342 | - if($sort == 1) |
|
343 | - usort($profiles,"profile_sort"); |
|
342 | + if ($sort == 1) |
|
343 | + usort($profiles, "profile_sort"); |
|
344 | 344 | foreach ($profiles as $P) { |
345 | - if($this->version == 1) |
|
346 | - $return_array[] = ['id'=>$P->identifier,'display'=>$P->name, 'idp_name'=>$P->inst_name,'logo'=>$l]; |
|
345 | + if ($this->version == 1) |
|
346 | + $return_array[] = ['id'=>$P->identifier, 'display'=>$P->name, 'idp_name'=>$P->inst_name, 'logo'=>$l]; |
|
347 | 347 | else |
348 | - $return_array[] = ['profile'=>$P->identifier,'display'=>$P->name, 'idp_name'=>$P->inst_name,'logo'=>$l]; |
|
348 | + $return_array[] = ['profile'=>$P->identifier, 'display'=>$P->name, 'idp_name'=>$P->inst_name, 'logo'=>$l]; |
|
349 | 349 | } |
350 | 350 | echo $this->return_json($return_array); |
351 | 351 | } |
@@ -361,20 +361,20 @@ discard block |
||
361 | 361 | $return_array = []; |
362 | 362 | $a = $this->profileAttributes($profile_id); |
363 | 363 | $thedevices = $a['devices']; |
364 | - if(!isset($profile_redirect) || ! $profile_redirect) { |
|
364 | + if (!isset($profile_redirect) || !$profile_redirect) { |
|
365 | 365 | $profile_redirect = 0; |
366 | 366 | foreach ($thedevices as $D) { |
367 | - if(isset($D['options']) && isset($D['options']['hidden']) && $D['options']['hidden']) |
|
367 | + if (isset($D['options']) && isset($D['options']['hidden']) && $D['options']['hidden']) |
|
368 | 368 | continue; |
369 | 369 | $disp = $D['display']; |
370 | - if($this->version == 1) { |
|
371 | - if($D['id'] === '0') { |
|
370 | + if ($this->version == 1) { |
|
371 | + if ($D['id'] === '0') { |
|
372 | 372 | $profile_redirect = 1; |
373 | 373 | $disp = $c; |
374 | 374 | } |
375 | 375 | $return_array[] = ['id'=>$D['id'], 'display'=>$disp, 'status'=>$D['status'], 'redirect'=>$D['redirect']]; |
376 | 376 | } else { |
377 | - if($D['device'] === '0') { |
|
377 | + if ($D['device'] === '0') { |
|
378 | 378 | $profile_redirect = 1; |
379 | 379 | $disp = $c; |
380 | 380 | } |
@@ -393,12 +393,12 @@ discard block |
||
393 | 393 | * @param int $prof_id profile identifier |
394 | 394 | * @return string JSON encoded data |
395 | 395 | */ |
396 | - public function JSON_generateInstaller($device,$prof_id) { |
|
397 | - debug(4,"JSON::generateInstaller arguments: $device,$prof_id\n"); |
|
398 | - $o = $this->generateInstaller($device,$prof_id); |
|
399 | - debug(4,"output from GUI::generateInstaller:"); |
|
400 | - debug(4,$o); |
|
401 | - debug(4,json_encode($o)); |
|
396 | + public function JSON_generateInstaller($device, $prof_id) { |
|
397 | + debug(4, "JSON::generateInstaller arguments: $device,$prof_id\n"); |
|
398 | + $o = $this->generateInstaller($device, $prof_id); |
|
399 | + debug(4, "output from GUI::generateInstaller:"); |
|
400 | + debug(4, $o); |
|
401 | + debug(4, json_encode($o)); |
|
402 | 402 | // header('Content-type: application/json; utf-8'); |
403 | 403 | echo $this->return_json($o); |
404 | 404 | } |
@@ -411,12 +411,12 @@ discard block |
||
411 | 411 | * @return binary installerFile |
412 | 412 | */ |
413 | 413 | |
414 | - public function downloadInstaller($device,$prof_id,$generated_for='user') { |
|
415 | - debug(4,"downloadInstaller arguments: $device,$prof_id,$generated_for\n"); |
|
416 | - $o = $this->generateInstaller($device,$prof_id); |
|
417 | - debug(4,"output from GUI::generateInstaller:"); |
|
418 | - debug(4,$o); |
|
419 | - if(! $o['link']) { |
|
414 | + public function downloadInstaller($device, $prof_id, $generated_for = 'user') { |
|
415 | + debug(4, "downloadInstaller arguments: $device,$prof_id,$generated_for\n"); |
|
416 | + $o = $this->generateInstaller($device, $prof_id); |
|
417 | + debug(4, "output from GUI::generateInstaller:"); |
|
418 | + debug(4, $o); |
|
419 | + if (!$o['link']) { |
|
420 | 420 | header("HTTP/1.0 404 Not Found"); |
421 | 421 | return; |
422 | 422 | } |
@@ -424,9 +424,9 @@ discard block |
||
424 | 424 | $profile->incrementDownloadStats($device, $generated_for); |
425 | 425 | $file = $this->i_path; |
426 | 426 | $filetype = $o['mime']; |
427 | - debug(4,"installer MIME type:$filetype\n"); |
|
428 | - header("Content-type: ".$filetype); |
|
429 | - header('Content-Disposition: inline; filename="'.basename($file).'"'); |
|
427 | + debug(4, "installer MIME type:$filetype\n"); |
|
428 | + header("Content-type: " . $filetype); |
|
429 | + header('Content-Disposition: inline; filename="' . basename($file) . '"'); |
|
430 | 430 | header('Content-Length: ' . filesize($file)); |
431 | 431 | ob_clean(); |
432 | 432 | flush(); |
@@ -444,67 +444,67 @@ discard block |
||
444 | 444 | * |
445 | 445 | */ |
446 | 446 | |
447 | - public function sendLogo($idp_id, $disco=FALSE, $width=0, $height=0) { |
|
447 | + public function sendLogo($idp_id, $disco = FALSE, $width = 0, $height = 0) { |
|
448 | 448 | $ExpStr = ''; |
449 | 449 | $resize = 0; |
450 | - if(($width || $height) && is_numeric($width) && is_numeric($height)) { |
|
450 | + if (($width || $height) && is_numeric($width) && is_numeric($height)) { |
|
451 | 451 | $resize = 1; |
452 | - if($height == 0) |
|
452 | + if ($height == 0) |
|
453 | 453 | $height = 10000; |
454 | - if($width == 0) |
|
454 | + if ($width == 0) |
|
455 | 455 | $width = 10000; |
456 | - $logo_file = CAT::$root.'/web/downloads/logos/'.$idp_id.'_'.$width.'_'.$height.'.png'; |
|
457 | - } elseif($disco == 1) { |
|
456 | + $logo_file = CAT::$root . '/web/downloads/logos/' . $idp_id . '_' . $width . '_' . $height . '.png'; |
|
457 | + } elseif ($disco == 1) { |
|
458 | 458 | $width = 120; |
459 | 459 | $height = 40; |
460 | 460 | $resize = 1; |
461 | - $logo_file = CAT::$root.'/web/downloads/logos/'.$idp_id.'_'.$width.'_'.$height.'.png'; |
|
461 | + $logo_file = CAT::$root . '/web/downloads/logos/' . $idp_id . '_' . $width . '_' . $height . '.png'; |
|
462 | 462 | } |
463 | 463 | |
464 | - if($resize && is_file($logo_file)){ |
|
465 | - debug(4,"Using cached logo $logo_file for: $idp_id\n"); |
|
464 | + if ($resize && is_file($logo_file)) { |
|
465 | + debug(4, "Using cached logo $logo_file for: $idp_id\n"); |
|
466 | 466 | $blob = file_get_contents($logo_file); |
467 | 467 | $filetype = 'image/png'; |
468 | 468 | } |
469 | 469 | else { |
470 | 470 | $idp = new IdP($idp_id); |
471 | 471 | $at = $idp->getAttributes('general:logo_file'); |
472 | - $blob = $at[0]['value']; |
|
472 | + $blob = $at[0]['value']; |
|
473 | 473 | $info = new finfo(); |
474 | 474 | $filetype = $info->buffer($blob, FILEINFO_MIME_TYPE); |
475 | 475 | $offset = 60 * 60 * 24 * 30; |
476 | - $ExpStr = "Expires: " . gmdate( "D, d M Y H:i:s", time() + $offset ) . " GMT"; |
|
477 | - if($resize) { |
|
476 | + $ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT"; |
|
477 | + if ($resize) { |
|
478 | 478 | $filetype = 'image/png'; |
479 | 479 | $image = new Imagick(); |
480 | 480 | $image->readImageBlob($blob); |
481 | - if( $image->setImageFormat('PNG')) { |
|
482 | - $image->thumbnailImage($width,$height,1); |
|
481 | + if ($image->setImageFormat('PNG')) { |
|
482 | + $image->thumbnailImage($width, $height, 1); |
|
483 | 483 | $blob = $image->getImageBlob(); |
484 | - debug(4,"Writing cached logo $logo_file for: $idp_id\n"); |
|
485 | - file_put_contents($logo_file,$blob); |
|
484 | + debug(4, "Writing cached logo $logo_file for: $idp_id\n"); |
|
485 | + file_put_contents($logo_file, $blob); |
|
486 | 486 | } |
487 | 487 | else |
488 | 488 | $blob = "XXXXXX"; |
489 | 489 | } |
490 | 490 | } |
491 | - header( "Content-type: ".$filetype ); |
|
492 | - header( "Cache-Control:max-age=36000, must-revalidate" ); |
|
493 | - header( $ExpStr ); |
|
491 | + header("Content-type: " . $filetype); |
|
492 | + header("Cache-Control:max-age=36000, must-revalidate"); |
|
493 | + header($ExpStr); |
|
494 | 494 | echo $blob; |
495 | 495 | } |
496 | 496 | |
497 | 497 | public function locateUser() { |
498 | 498 | $host = $_SERVER['REMOTE_ADDR']; |
499 | 499 | $record = geoip_record_by_name($host); |
500 | - if($record) { |
|
500 | + if ($record) { |
|
501 | 501 | $result = ['status' => 'ok']; |
502 | 502 | $result['country'] = $record['country_code']; |
503 | 503 | // the two lines below are a dirty hack to take of the error in naming the UK federation |
504 | - if($result['country'] == 'GB') |
|
504 | + if ($result['country'] == 'GB') |
|
505 | 505 | $result['country'] = 'UK'; |
506 | 506 | $result['region'] = $record['region']; |
507 | - $result['geo'] = ['lat' => (float)$record['latitude'] , 'lon' => (float)$record['longitude']]; |
|
507 | + $result['geo'] = ['lat' => (float) $record['latitude'], 'lon' => (float) $record['longitude']]; |
|
508 | 508 | } else { |
509 | 509 | $result = ['status' => 'error', 'error' =>'Problem listing countries']; |
510 | 510 | } |
@@ -525,22 +525,22 @@ discard block |
||
525 | 525 | $result = ['status' => 'ok']; |
526 | 526 | $result['country'] = $record->country->isoCode; |
527 | 527 | // the two lines below are a dirty hack to take of the error in naming the UK federation |
528 | - if($result['country'] == 'GB') |
|
528 | + if ($result['country'] == 'GB') |
|
529 | 529 | $result['country'] = 'UK'; |
530 | 530 | $result['region'] = $record->continent->name; |
531 | 531 | |
532 | - $result['geo'] = ['lat' => (float)$record->location->latitude , 'lon' => (float)$record->location->longitude]; |
|
532 | + $result['geo'] = ['lat' => (float) $record->location->latitude, 'lon' => (float) $record->location->longitude]; |
|
533 | 533 | return($result); |
534 | 534 | } |
535 | 535 | |
536 | 536 | public function JSON_locateUser() { |
537 | 537 | header('Content-type: application/json; utf-8'); |
538 | 538 | |
539 | - if(empty(Config::$GEOIP['version']) || Config::$GEOIP['version'] == 0) |
|
539 | + if (empty(Config::$GEOIP['version']) || Config::$GEOIP['version'] == 0) |
|
540 | 540 | echo json_encode(['status' => 'error', 'error' =>'Geolocation not supported']); |
541 | - if(Config::$GEOIP['version'] == 1) |
|
541 | + if (Config::$GEOIP['version'] == 1) |
|
542 | 542 | echo json_encode($this->locateUser()); |
543 | - if(Config::$GEOIP['version'] == 2) |
|
543 | + if (Config::$GEOIP['version'] == 2) |
|
544 | 544 | echo json_encode($this->locateUser2()); |
545 | 545 | } |
546 | 546 | |
@@ -560,11 +560,11 @@ discard block |
||
560 | 560 | * @param array $P2 - second point as an 'lat', 'lon' array |
561 | 561 | * @return float distance in km |
562 | 562 | */ |
563 | -private function geoDistance($P1,$P2) { |
|
563 | +private function geoDistance($P1, $P2) { |
|
564 | 564 | |
565 | 565 | $dist = sin(deg2rad($P1['lat'])) * sin(deg2rad($P2['lat'])) + |
566 | 566 | cos(deg2rad($P1['lat'])) * cos(deg2rad($P2['lat'])) * cos(deg2rad($P1['lon'] - $P2['lon'])); |
567 | - $dist = rad2deg(acos($dist)) * 60 * 1.1852 ; |
|
567 | + $dist = rad2deg(acos($dist)) * 60 * 1.1852; |
|
568 | 568 | return(round($dist)); |
569 | 569 | } |
570 | 570 | |
@@ -574,44 +574,44 @@ discard block |
||
574 | 574 | * @return array $IdPs - list of arrays ('id', 'name'); |
575 | 575 | */ |
576 | 576 | |
577 | -public function orderIdentityProviders($country,$L=NULL) { |
|
578 | - $idps = Federation::listAllIdentityProviders(1,$country); |
|
577 | +public function orderIdentityProviders($country, $L = NULL) { |
|
578 | + $idps = Federation::listAllIdentityProviders(1, $country); |
|
579 | 579 | |
580 | - if(is_null($L)) { |
|
580 | + if (is_null($L)) { |
|
581 | 581 | $U = $this->locateUser(); |
582 | - if($U['status'] == 'ok') { |
|
582 | + if ($U['status'] == 'ok') { |
|
583 | 583 | $L = $U['geo']; |
584 | 584 | } else { |
585 | - $L = ['lat'=>"90",'lon'=>"0"]; |
|
585 | + $L = ['lat'=>"90", 'lon'=>"0"]; |
|
586 | 586 | } |
587 | 587 | } |
588 | - $T=[]; |
|
589 | - $R=[]; |
|
588 | + $T = []; |
|
589 | + $R = []; |
|
590 | 590 | foreach ($idps as $idp) { |
591 | 591 | $T[$idp['entityID']] = $idp['title']; |
592 | 592 | $dist = 10000; |
593 | - if(isset($idp['geo'])) { |
|
594 | - $G=$idp['geo']; |
|
595 | - if(isset($G['lon'])) { |
|
596 | - $d1 = $this->geoDistance($L,$G); |
|
597 | - if( $d1 < $dist) |
|
593 | + if (isset($idp['geo'])) { |
|
594 | + $G = $idp['geo']; |
|
595 | + if (isset($G['lon'])) { |
|
596 | + $d1 = $this->geoDistance($L, $G); |
|
597 | + if ($d1 < $dist) |
|
598 | 598 | $dist = $d1; |
599 | 599 | } else { |
600 | 600 | foreach ($G as $g) { |
601 | - $d1 = $this->geoDistance($L,$g); |
|
602 | - if( $d1 < $dist) |
|
601 | + $d1 = $this->geoDistance($L, $g); |
|
602 | + if ($d1 < $dist) |
|
603 | 603 | $dist = $d1; |
604 | 604 | } |
605 | 605 | } |
606 | 606 | } |
607 | - if($dist > 100) |
|
608 | - $dist=10000; |
|
609 | - $d = sprintf("%06d",$dist); |
|
610 | - $R[$idp['entityID']] = $d." ".$idp['title']; |
|
607 | + if ($dist > 100) |
|
608 | + $dist = 10000; |
|
609 | + $d = sprintf("%06d", $dist); |
|
610 | + $R[$idp['entityID']] = $d . " " . $idp['title']; |
|
611 | 611 | } |
612 | 612 | asort($R); |
613 | 613 | foreach (array_keys($R) as $r) { |
614 | - if($this->version == 1) |
|
614 | + if ($this->version == 1) |
|
615 | 615 | $outarray[] = ['id'=>$r, 'title'=>$T[$r]]; |
616 | 616 | else |
617 | 617 | $outarray[] = ['idp'=>$r, 'title'=>$T[$r]]; |
@@ -629,44 +629,44 @@ discard block |
||
629 | 629 | |
630 | 630 | public function detectOS() { |
631 | 631 | $Dev = Devices::listDevices(); |
632 | - if( isset($_REQUEST['device']) && isset($Dev[$_REQUEST['device']]) && (!isset($device['options']['hidden']) || $device['options']['hidden'] == 0)) { |
|
632 | + if (isset($_REQUEST['device']) && isset($Dev[$_REQUEST['device']]) && (!isset($device['options']['hidden']) || $device['options']['hidden'] == 0)) { |
|
633 | 633 | $dev_id = $_REQUEST['device']; |
634 | 634 | $device = $Dev[$dev_id]; |
635 | - if($this->version == 1) |
|
636 | - return(['id'=>$dev_id,'display'=>$device['display'], 'group'=>$device['group']]); |
|
635 | + if ($this->version == 1) |
|
636 | + return(['id'=>$dev_id, 'display'=>$device['display'], 'group'=>$device['group']]); |
|
637 | 637 | else |
638 | - return(['device'=>$dev_id,'display'=>$device['display'], 'group'=>$device['group']]); |
|
638 | + return(['device'=>$dev_id, 'display'=>$device['display'], 'group'=>$device['group']]); |
|
639 | 639 | } |
640 | 640 | $browser = $_SERVER['HTTP_USER_AGENT']; |
641 | - debug(4,"HTTP_USER_AGENT=$browser\n"); |
|
641 | + debug(4, "HTTP_USER_AGENT=$browser\n"); |
|
642 | 642 | foreach ($Dev as $dev_id => $device) { |
643 | - if(!isset($device['match'])) |
|
643 | + if (!isset($device['match'])) |
|
644 | 644 | continue; |
645 | - if(preg_match('/'.$device['match'].'/',$browser)) { |
|
646 | - if(!isset($device['options']['hidden']) || $device['options']['hidden'] == 0) { |
|
647 | - debug(4,"Browser_id: $dev_id\n"); |
|
648 | - if($this->version == 1) |
|
649 | - return(['id'=>$dev_id,'display'=>$device['display'], 'group'=>$device['group']]); |
|
645 | + if (preg_match('/' . $device['match'] . '/', $browser)) { |
|
646 | + if (!isset($device['options']['hidden']) || $device['options']['hidden'] == 0) { |
|
647 | + debug(4, "Browser_id: $dev_id\n"); |
|
648 | + if ($this->version == 1) |
|
649 | + return(['id'=>$dev_id, 'display'=>$device['display'], 'group'=>$device['group']]); |
|
650 | 650 | else |
651 | - return(['device'=>$dev_id,'display'=>$device['display'], 'group'=>$device['group']]); |
|
651 | + return(['device'=>$dev_id, 'display'=>$device['display'], 'group'=>$device['group']]); |
|
652 | 652 | } |
653 | 653 | else { |
654 | - debug(2, "Unrecognised system: ".$_SERVER['HTTP_USER_AGENT']."\n"); |
|
654 | + debug(2, "Unrecognised system: " . $_SERVER['HTTP_USER_AGENT'] . "\n"); |
|
655 | 655 | return(false); |
656 | 656 | } |
657 | 657 | } |
658 | 658 | } |
659 | - debug(2, "Unrecognised system: ".$_SERVER['HTTP_USER_AGENT']."\n"); |
|
659 | + debug(2, "Unrecognised system: " . $_SERVER['HTTP_USER_AGENT'] . "\n"); |
|
660 | 660 | return(false); |
661 | 661 | } |
662 | 662 | |
663 | 663 | public function JSON_detectOS() { |
664 | - $return_array=$this->detectOS(); |
|
665 | - if($return_array) |
|
664 | + $return_array = $this->detectOS(); |
|
665 | + if ($return_array) |
|
666 | 666 | $status = 1; |
667 | 667 | else |
668 | 668 | $status = 0; |
669 | - echo $this->return_json($return_array,$status); |
|
669 | + echo $this->return_json($return_array, $status); |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | |
@@ -675,6 +675,6 @@ discard block |
||
675 | 675 | private $i_path; |
676 | 676 | |
677 | 677 | } |
678 | -function profile_sort($P1,$P2) { |
|
678 | +function profile_sort($P1, $P2) { |
|
679 | 679 | return strcasecmp($P1->name, $P2->name); |
680 | 680 | } |
681 | 681 | \ No newline at end of file |
@@ -78,9 +78,6 @@ |
||
78 | 78 | * It is CRUTCIAL that the constructor sets $this->supportedEapMethods to an array of methods |
79 | 79 | * available for the particular device. |
80 | 80 | * {@source} |
81 | - * @param string $device a pointer to a device module, which must |
|
82 | - * be an index of one of the devices defined in the {@link Devices} |
|
83 | - * array in {@link devices.php}. |
|
84 | 81 | * @final not to be redefined |
85 | 82 | */ |
86 | 83 | final public function __construct() { |
@@ -170,13 +170,13 @@ |
||
170 | 170 | // define CA certificates |
171 | 171 | foreach ($this->attributes['internal:CAs'][0] as $ca) { |
172 | 172 | // strip -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- |
173 | - debug(2,$ca['pem']); |
|
173 | + debug(2, $ca['pem']); |
|
174 | 174 | $caSanitized = substr($ca['pem'], 27, strlen($ca['pem']) - 27 - 25 - 1); |
175 | - debug(2,$caSanitized."\n"); |
|
175 | + debug(2, $caSanitized . "\n"); |
|
176 | 176 | // remove \n |
177 | 177 | $caSanitized = str_replace("\n", "", $caSanitized); |
178 | 178 | $jsonArray["Certificates"][] = ["GUID" => "{" . $ca['uuid'] . "}", "Type" => "Authority", "X509" => $caSanitized]; |
179 | - debug(2,$caSanitized."\n"); |
|
179 | + debug(2, $caSanitized . "\n"); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | $outputJson = json_encode($jsonArray, JSON_PRETTY_PRINT); |
@@ -308,6 +308,9 @@ |
||
308 | 308 | |
309 | 309 | /** |
310 | 310 | * produce PEAP, TLS and TTLS configuration files for Windows 8 |
311 | + * @param string $auth |
|
312 | + * @param string $encryption |
|
313 | + * @param integer $i |
|
311 | 314 | */ |
312 | 315 | private function writeWLANprofile($wlan_profile_name,$ssid,$auth,$encryption,$eap_config,$i) { |
313 | 316 | $profile_file_contents = '<?xml version="1.0"?> |
@@ -28,8 +28,8 @@ discard block |
||
28 | 28 | final public function __construct() { |
29 | 29 | $this->supportedEapMethods = [EAP::$TLS, EAP::$PEAP_MSCHAP2, EAP::$TTLS_PAP, EAP::$TTLS_MSCHAP2, EAP::$PWD]; |
30 | 30 | # $this->supportedEapMethods = array(EAP::$TLS, EAP::$PEAP_MSCHAP2, EAP::$TTLS_PAP, EAP::$PWD); |
31 | - debug(4,"This device supports the following EAP methods: "); |
|
32 | - debug(4,$this->supportedEapMethods); |
|
31 | + debug(4, "This device supports the following EAP methods: "); |
|
32 | + debug(4, $this->supportedEapMethods); |
|
33 | 33 | $this->specialities['anon_id'][serialize(EAP::$PEAP_MSCHAP2)] = _("Anonymous identities do not use the realm as specified in the profile - it is derived from the suffix of the user's username input instead."); |
34 | 34 | } |
35 | 35 | |
@@ -46,42 +46,42 @@ discard block |
||
46 | 46 | // create a list of profiles to be deleted after installation |
47 | 47 | $delProfiles = []; |
48 | 48 | foreach ($delSSIDs as $ssid => $cipher) { |
49 | - if($cipher == 'DEL') |
|
49 | + if ($cipher == 'DEL') |
|
50 | 50 | $delProfiles[] = $ssid; |
51 | - if($cipher == 'TKIP') |
|
52 | - $delProfiles[] = $ssid.' (TKIP)'; |
|
51 | + if ($cipher == 'TKIP') |
|
52 | + $delProfiles[] = $ssid . ' (TKIP)'; |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | |
56 | - if ($this->selected_eap == EAP::$TLS || $this->selected_eap == EAP::$PEAP_MSCHAP2 || $this->selected_eap == EAP::$TTLS_PAP || $this->selected_eap == EAP::$TTLS_MSCHAP2 || $this->selected_eap == EAP::$PWD) { |
|
56 | + if ($this->selected_eap == EAP::$TLS || $this->selected_eap == EAP::$PEAP_MSCHAP2 || $this->selected_eap == EAP::$TTLS_PAP || $this->selected_eap == EAP::$TTLS_MSCHAP2 || $this->selected_eap == EAP::$PWD) { |
|
57 | 57 | $WindowsProfile = []; |
58 | 58 | $eap_config = $this->prepareEapConfig($this->attributes); |
59 | 59 | $i = 0; |
60 | 60 | foreach ($SSIDs as $ssid => $cipher) { |
61 | - if($cipher == 'TKIP') { |
|
62 | - $WindowsProfile[$i] = $this->writeWLANprofile ($ssid.' (TKIP)',$ssid,'WPA','TKIP',$eap_config,$i); |
|
61 | + if ($cipher == 'TKIP') { |
|
62 | + $WindowsProfile[$i] = $this->writeWLANprofile($ssid . ' (TKIP)', $ssid, 'WPA', 'TKIP', $eap_config, $i); |
|
63 | 63 | $i++; |
64 | 64 | } |
65 | - $WindowsProfile[$i] = $this->writeWLANprofile ($ssid,$ssid,'WPA2','AES',$eap_config,$i); |
|
65 | + $WindowsProfile[$i] = $this->writeWLANprofile($ssid, $ssid, 'WPA2', 'AES', $eap_config, $i); |
|
66 | 66 | $i++; |
67 | 67 | } |
68 | - if($set_wired) { |
|
68 | + if ($set_wired) { |
|
69 | 69 | $this->writeLANprofile($eap_config); |
70 | 70 | } |
71 | 71 | } else { |
72 | 72 | error(" this EAP type is not handled yet"); |
73 | 73 | return; |
74 | 74 | } |
75 | - debug(4,"WindowsProfile"); debug(4,$WindowsProfile); |
|
75 | + debug(4, "WindowsProfile"); debug(4, $WindowsProfile); |
|
76 | 76 | |
77 | - $this->writeProfilesNSH($WindowsProfile, $CA_files,$set_wired); |
|
77 | + $this->writeProfilesNSH($WindowsProfile, $CA_files, $set_wired); |
|
78 | 78 | $this->writeAdditionalDeletes($delProfiles); |
79 | - if(isset($additional_deletes) && count($additional_deletes)) |
|
79 | + if (isset($additional_deletes) && count($additional_deletes)) |
|
80 | 80 | $this->writeAdditionalDeletes($additional_deletes); |
81 | 81 | $this->copyFiles($this->selected_eap); |
82 | - if(isset($this->attributes['internal:logo_file'])) |
|
82 | + if (isset($this->attributes['internal:logo_file'])) |
|
83 | 83 | $this->combineLogo($this->attributes['internal:logo_file']); |
84 | - $this->writeMainNSH($this->selected_eap,$this->attributes); |
|
84 | + $this->writeMainNSH($this->selected_eap, $this->attributes); |
|
85 | 85 | $this->compileNSIS(); |
86 | 86 | $installer_path = $this->signInstaller($this->attributes); |
87 | 87 | |
@@ -90,19 +90,19 @@ discard block |
||
90 | 90 | } |
91 | 91 | |
92 | 92 | public function writeDeviceInfo() { |
93 | - $ssid_ct=count($this->attributes['internal:SSID']); |
|
93 | + $ssid_ct = count($this->attributes['internal:SSID']); |
|
94 | 94 | $out = "<p>"; |
95 | - $out .= sprintf(_("%s installer will be in the form of an EXE file. It will configure %s on your device, by creating wireless network profiles.<p>When you click the download button, the installer will be saved by your browser. Copy it to the machine you want to configure and execute."),Config::$CONSORTIUM['name'],Config::$CONSORTIUM['name']); |
|
95 | + $out .= sprintf(_("%s installer will be in the form of an EXE file. It will configure %s on your device, by creating wireless network profiles.<p>When you click the download button, the installer will be saved by your browser. Copy it to the machine you want to configure and execute."), Config::$CONSORTIUM['name'], Config::$CONSORTIUM['name']); |
|
96 | 96 | $out .= "<p>"; |
97 | - if($ssid_ct > 1) { |
|
98 | - if($ssid_ct > 2) { |
|
99 | - $out .= sprintf(_("In addition to <strong>%s</strong> the installer will also configure access to the following networks:"),implode(', ',Config::$CONSORTIUM['ssid']))." "; |
|
97 | + if ($ssid_ct > 1) { |
|
98 | + if ($ssid_ct > 2) { |
|
99 | + $out .= sprintf(_("In addition to <strong>%s</strong> the installer will also configure access to the following networks:"), implode(', ', Config::$CONSORTIUM['ssid'])) . " "; |
|
100 | 100 | } else |
101 | - $out .= sprintf(_("In addition to <strong>%s</strong> the installer will also configure access to:"),implode(', ',Config::$CONSORTIUM['ssid']))." "; |
|
101 | + $out .= sprintf(_("In addition to <strong>%s</strong> the installer will also configure access to:"), implode(', ', Config::$CONSORTIUM['ssid'])) . " "; |
|
102 | 102 | $i = 0; |
103 | 103 | foreach ($this->attributes['internal:SSID'] as $ssid=>$v) { |
104 | - if(! in_array($ssid, Config::$CONSORTIUM['ssid'])) { |
|
105 | - if($i > 0) |
|
104 | + if (!in_array($ssid, Config::$CONSORTIUM['ssid'])) { |
|
105 | + if ($i > 0) |
|
106 | 106 | $out .= ", "; |
107 | 107 | $i++; |
108 | 108 | $out .= "<strong>$ssid</strong>"; |
@@ -111,18 +111,18 @@ discard block |
||
111 | 111 | $out .= "<p>"; |
112 | 112 | } |
113 | 113 | |
114 | -if($this->eap == EAP::$TLS) |
|
114 | +if ($this->eap == EAP::$TLS) |
|
115 | 115 | $out .= _("In order to connect to the network you will need an a personal certificate in the form of a p12 file. You should obtain this certificate from your home institution. Consult the support page to find out how this certificate can be obtained. Such certificate files are password protected. You should have both the file and the password available during the installation process."); |
116 | 116 | else { |
117 | 117 | $out .= _("In order to connect to the network you will need an account from your home institution. You should consult the support page to find out how this account can be obtained. It is very likely that your account is already activated."); |
118 | 118 | $out .= "<p>"; |
119 | 119 | $out .= _("When you are connecting to the network for the first time, Windows will pop up a login box, where you should enter your user name and password. This information will be saved so that you will reconnect to the network automatically each time you are in the range."); |
120 | - if($ssid_ct > 1) { |
|
120 | + if ($ssid_ct > 1) { |
|
121 | 121 | $out .= "<p>"; |
122 | - $out .= _("You will be required to enter the same credentials for each of the configured notworks:")." "; |
|
122 | + $out .= _("You will be required to enter the same credentials for each of the configured notworks:") . " "; |
|
123 | 123 | $i = 0; |
124 | 124 | foreach ($this->attributes['internal:SSID'] as $ssid=>$v) { |
125 | - if($i > 0) |
|
125 | + if ($i > 0) |
|
126 | 126 | $out .= ", "; |
127 | 127 | $i++; |
128 | 128 | $out .= "<strong>$ssid</strong>"; |
@@ -141,10 +141,10 @@ discard block |
||
141 | 141 | $use_anon = $attr['internal:use_anon_outer'] [0]; |
142 | 142 | if ($use_anon) { |
143 | 143 | $outer_user = $attr['internal:anon_local_value'][0]; |
144 | - $outer_id = $outer_user.'@'.$attr['internal:realm'][0]; |
|
144 | + $outer_id = $outer_user . '@' . $attr['internal:realm'][0]; |
|
145 | 145 | } |
146 | 146 | // $servers = preg_quote(implode(';',$attr['eap:server_name'])); |
147 | - $servers = implode(';',$attr['eap:server_name']); |
|
147 | + $servers = implode(';', $attr['eap:server_name']); |
|
148 | 148 | |
149 | 149 | $ca_array = $attr['internal:CAs'][0]; |
150 | 150 | |
@@ -153,12 +153,12 @@ discard block |
||
153 | 153 | <EapMethod> |
154 | 154 | '; |
155 | 155 | |
156 | -$profile_file_contents .= '<Type xmlns="http://www.microsoft.com/provisioning/EapCommon">'. |
|
157 | - $this->selected_eap["OUTER"].'</Type> |
|
156 | +$profile_file_contents .= '<Type xmlns="http://www.microsoft.com/provisioning/EapCommon">' . |
|
157 | + $this->selected_eap["OUTER"] . '</Type> |
|
158 | 158 | <VendorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorId> |
159 | 159 | <VendorType xmlns="http://www.microsoft.com/provisioning/EapCommon">0</VendorType> |
160 | 160 | '; |
161 | -if( $eap == EAP::$TLS) { |
|
161 | +if ($eap == EAP::$TLS) { |
|
162 | 162 | $profile_file_contents .= '<AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</AuthorId> |
163 | 163 | </EapMethod> |
164 | 164 | '; |
@@ -174,15 +174,15 @@ discard block |
||
174 | 174 | </eapTls:CredentialsSource> |
175 | 175 | <eapTls:ServerValidation> |
176 | 176 | <eapTls:DisableUserPromptForServerValidation>true</eapTls:DisableUserPromptForServerValidation> |
177 | -<eapTls:ServerNames>'.$servers.'</eapTls:ServerNames>'; |
|
178 | -if($ca_array) { |
|
177 | +<eapTls:ServerNames>'.$servers . '</eapTls:ServerNames>'; |
|
178 | +if ($ca_array) { |
|
179 | 179 | foreach ($ca_array as $CA) |
180 | - if($CA['root']) |
|
181 | - $profile_file_contents .= "<eapTls:TrustedRootCA>".$CA['sha1']."</eapTls:TrustedRootCA>\n"; |
|
180 | + if ($CA['root']) |
|
181 | + $profile_file_contents .= "<eapTls:TrustedRootCA>" . $CA['sha1'] . "</eapTls:TrustedRootCA>\n"; |
|
182 | 182 | } |
183 | 183 | $profile_file_contents .= '</eapTls:ServerValidation> |
184 | 184 | '; |
185 | -if(isset($attr['eap-specific:tls_use_other_id']) && $attr['eap-specific:tls_use_other_id'][0] == 'on') |
|
185 | +if (isset($attr['eap-specific:tls_use_other_id']) && $attr['eap-specific:tls_use_other_id'][0] == 'on') |
|
186 | 186 | $profile_file_contents .= '<eapTls:DifferentUsername>true</eapTls:DifferentUsername>'; |
187 | 187 | else |
188 | 188 | $profile_file_contents .= '<eapTls:DifferentUsername>false</eapTls:DifferentUsername>'; |
@@ -191,8 +191,8 @@ discard block |
||
191 | 191 | </baseEap:Eap> |
192 | 192 | </Config> |
193 | 193 | '; |
194 | -} elseif ( $eap == EAP::$PEAP_MSCHAP2) { |
|
195 | -if(isset($attr['eap:enable_nea']) && $attr['eap:enable_nea'][0] == 'on') |
|
194 | +} elseif ($eap == EAP::$PEAP_MSCHAP2) { |
|
195 | +if (isset($attr['eap:enable_nea']) && $attr['eap:enable_nea'][0] == 'on') |
|
196 | 196 | $nea = 'true'; |
197 | 197 | else |
198 | 198 | $nea = 'false'; |
@@ -205,11 +205,11 @@ discard block |
||
205 | 205 | <EapType xmlns="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV1"> |
206 | 206 | <ServerValidation> |
207 | 207 | <DisableUserPromptForServerValidation>true</DisableUserPromptForServerValidation> |
208 | -<ServerNames>'.$servers.'</ServerNames>'; |
|
209 | -if($ca_array) { |
|
208 | +<ServerNames>'.$servers . '</ServerNames>'; |
|
209 | +if ($ca_array) { |
|
210 | 210 | foreach ($ca_array as $CA) |
211 | - if($CA['root']) |
|
212 | - $w8_ext .= "<TrustedRootCA>".$CA['sha1']."</TrustedRootCA>\n"; |
|
211 | + if ($CA['root']) |
|
212 | + $w8_ext .= "<TrustedRootCA>" . $CA['sha1'] . "</TrustedRootCA>\n"; |
|
213 | 213 | } |
214 | 214 | $w8_ext .= '</ServerValidation> |
215 | 215 | <FastReconnect>true</FastReconnect> |
@@ -220,50 +220,50 @@ discard block |
||
220 | 220 | <UseWinLogonCredentials>false</UseWinLogonCredentials> |
221 | 221 | </EapType> |
222 | 222 | </Eap> |
223 | -<EnableQuarantineChecks>'.$nea.'</EnableQuarantineChecks> |
|
223 | +<EnableQuarantineChecks>'.$nea . '</EnableQuarantineChecks> |
|
224 | 224 | <RequireCryptoBinding>false</RequireCryptoBinding> |
225 | 225 | '; |
226 | -if($use_anon == 1) { |
|
227 | -$w8_ext .='<PeapExtensions> |
|
226 | +if ($use_anon == 1) { |
|
227 | +$w8_ext .= '<PeapExtensions> |
|
228 | 228 | <IdentityPrivacy xmlns="http://www.microsoft.com/provisioning/MsPeapConnectionPropertiesV2"> |
229 | 229 | <EnableIdentityPrivacy>true</EnableIdentityPrivacy> |
230 | 230 | '; |
231 | -if(isset($outer_user) && $outer_user) |
|
232 | -$w8_ext .='<AnonymousUserName>'.$outer_user.'</AnonymousUserName> |
|
231 | +if (isset($outer_user) && $outer_user) |
|
232 | +$w8_ext .= '<AnonymousUserName>' . $outer_user . '</AnonymousUserName> |
|
233 | 233 | '; |
234 | 234 | else |
235 | -$w8_ext .='<AnonymousUserName/> |
|
235 | +$w8_ext .= '<AnonymousUserName/> |
|
236 | 236 | '; |
237 | -$w8_ext .='</IdentityPrivacy> |
|
237 | +$w8_ext .= '</IdentityPrivacy> |
|
238 | 238 | </PeapExtensions> |
239 | 239 | '; |
240 | 240 | } |
241 | -$w8_ext .='</EapType> |
|
241 | +$w8_ext .= '</EapType> |
|
242 | 242 | </Eap> |
243 | 243 | </Config> |
244 | 244 | '; |
245 | -} elseif ( $eap == EAP::$TTLS_PAP || $eap == EAP::$TTLS_MSCHAP2) { |
|
245 | +} elseif ($eap == EAP::$TTLS_PAP || $eap == EAP::$TTLS_MSCHAP2) { |
|
246 | 246 | $profile_file_contents .= '<AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">311</AuthorId> |
247 | 247 | </EapMethod> |
248 | 248 | '; |
249 | 249 | $w8_ext = '<Config xmlns="http://www.microsoft.com/provisioning/EapHostConfig"> |
250 | 250 | <EapTtls xmlns="http://www.microsoft.com/provisioning/EapTtlsConnectionPropertiesV1"> |
251 | 251 | <ServerValidation> |
252 | -<ServerNames>'.$servers.'</ServerNames> '; |
|
253 | -if($ca_array) { |
|
252 | +<ServerNames>'.$servers . '</ServerNames> '; |
|
253 | +if ($ca_array) { |
|
254 | 254 | foreach ($ca_array as $CA) |
255 | - if($CA['root']) |
|
256 | - $w8_ext .= "<TrustedRootCAHash>".chunk_split($CA['sha1'],2,' ')."</TrustedRootCAHash>\n"; |
|
255 | + if ($CA['root']) |
|
256 | + $w8_ext .= "<TrustedRootCAHash>" . chunk_split($CA['sha1'], 2, ' ') . "</TrustedRootCAHash>\n"; |
|
257 | 257 | } |
258 | -$w8_ext .='<DisablePrompt>true</DisablePrompt> |
|
258 | +$w8_ext .= '<DisablePrompt>true</DisablePrompt> |
|
259 | 259 | </ServerValidation> |
260 | 260 | <Phase2Authentication> |
261 | 261 | '; |
262 | -if ( $eap == EAP::$TTLS_PAP) { |
|
263 | - $w8_ext .='<PAPAuthentication /> '; |
|
262 | +if ($eap == EAP::$TTLS_PAP) { |
|
263 | + $w8_ext .= '<PAPAuthentication /> '; |
|
264 | 264 | } |
265 | -if ( $eap == EAP::$TTLS_MSCHAP2) { |
|
266 | - $w8_ext .='<MSCHAPv2Authentication> |
|
265 | +if ($eap == EAP::$TTLS_MSCHAP2) { |
|
266 | + $w8_ext .= '<MSCHAPv2Authentication> |
|
267 | 267 | <UseWinlogonCredentials>false</UseWinlogonCredentials> |
268 | 268 | </MSCHAPv2Authentication> |
269 | 269 | '; |
@@ -271,24 +271,24 @@ discard block |
||
271 | 271 | $w8_ext .= '</Phase2Authentication> |
272 | 272 | <Phase1Identity> |
273 | 273 | '; |
274 | -if($use_anon == 1) { |
|
274 | +if ($use_anon == 1) { |
|
275 | 275 | $w8_ext .= '<IdentityPrivacy>true</IdentityPrivacy> |
276 | 276 | '; |
277 | - if(isset($outer_id) && $outer_id) |
|
278 | - $w8_ext .='<AnonymousIdentity>'.$outer_id.'</AnonymousIdentity> |
|
277 | + if (isset($outer_id) && $outer_id) |
|
278 | + $w8_ext .= '<AnonymousIdentity>' . $outer_id . '</AnonymousIdentity> |
|
279 | 279 | '; |
280 | 280 | else |
281 | - $w8_ext .='<AnonymousIdentity/> |
|
281 | + $w8_ext .= '<AnonymousIdentity/> |
|
282 | 282 | '; |
283 | 283 | } else { |
284 | 284 | $w8_ext .= '<IdentityPrivacy>false</IdentityPrivacy> |
285 | 285 | '; |
286 | 286 | } |
287 | -$w8_ext .='</Phase1Identity> |
|
287 | +$w8_ext .= '</Phase1Identity> |
|
288 | 288 | </EapTtls> |
289 | 289 | </Config> |
290 | 290 | '; |
291 | -} elseif ( $eap == EAP::$PWD) { |
|
291 | +} elseif ($eap == EAP::$PWD) { |
|
292 | 292 | $profile_file_contents .= '<AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0</AuthorId> |
293 | 293 | </EapMethod> |
294 | 294 | '; |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | |
298 | 298 | $profile_file_contents_end = '</EapHostConfig></EAPConfig>'; |
299 | 299 | $return_array = []; |
300 | -$return_array['w8'] = $profile_file_contents.$w8_ext.$profile_file_contents_end; |
|
300 | +$return_array['w8'] = $profile_file_contents . $w8_ext . $profile_file_contents_end; |
|
301 | 301 | return $return_array; |
302 | 302 | } |
303 | 303 | |
@@ -309,13 +309,13 @@ discard block |
||
309 | 309 | /** |
310 | 310 | * produce PEAP, TLS and TTLS configuration files for Windows 8 |
311 | 311 | */ |
312 | - private function writeWLANprofile($wlan_profile_name,$ssid,$auth,$encryption,$eap_config,$i) { |
|
312 | + private function writeWLANprofile($wlan_profile_name, $ssid, $auth, $encryption, $eap_config, $i) { |
|
313 | 313 | $profile_file_contents = '<?xml version="1.0"?> |
314 | 314 | <WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1"> |
315 | -<name>'.$wlan_profile_name.'</name> |
|
315 | +<name>'.$wlan_profile_name . '</name> |
|
316 | 316 | <SSIDConfig> |
317 | 317 | <SSID> |
318 | -<name>'.$ssid.'</name> |
|
318 | +<name>'.$ssid . '</name> |
|
319 | 319 | </SSID> |
320 | 320 | <nonBroadcast>true</nonBroadcast> |
321 | 321 | </SSIDConfig> |
@@ -325,12 +325,12 @@ discard block |
||
325 | 325 | <MSM> |
326 | 326 | <security> |
327 | 327 | <authEncryption> |
328 | -<authentication>'.$auth.'</authentication> |
|
329 | -<encryption>'.$encryption.'</encryption> |
|
328 | +<authentication>'.$auth . '</authentication> |
|
329 | +<encryption>'.$encryption . '</encryption> |
|
330 | 330 | <useOneX>true</useOneX> |
331 | 331 | </authEncryption> |
332 | 332 | '; |
333 | -if($auth == 'WPA2') |
|
333 | +if ($auth == 'WPA2') |
|
334 | 334 | $profile_file_contents .= '<PMKCacheMode>enabled</PMKCacheMode> |
335 | 335 | <PMKCacheTTL>720</PMKCacheTTL> |
336 | 336 | <PMKCacheSize>128</PMKCacheSize> |
@@ -348,14 +348,14 @@ discard block |
||
348 | 348 | </WLANProfile> |
349 | 349 | '; |
350 | 350 | |
351 | -if(! is_dir('w8')) |
|
351 | +if (!is_dir('w8')) |
|
352 | 352 | mkdir('w8'); |
353 | 353 | $xml_f_name = "w8/wlan_prof-$i.xml"; |
354 | -$xml_f = fopen($xml_f_name,'w'); |
|
355 | -fwrite($xml_f,$profile_file_contents. $eap_config['w8']. $closing) ; |
|
354 | +$xml_f = fopen($xml_f_name, 'w'); |
|
355 | +fwrite($xml_f, $profile_file_contents . $eap_config['w8'] . $closing); |
|
356 | 356 | fclose($xml_f); |
357 | -debug(2,"Installer has been written into directory $this->FPATH\n"); |
|
358 | -debug(4,"WWWWLAN_Profile:$wlan_profile_name:$encryption\n"); |
|
357 | +debug(2, "Installer has been written into directory $this->FPATH\n"); |
|
358 | +debug(4, "WWWWLAN_Profile:$wlan_profile_name:$encryption\n"); |
|
359 | 359 | return("\"$wlan_profile_name\" \"$encryption\""); |
360 | 360 | } |
361 | 361 | |
@@ -375,29 +375,29 @@ discard block |
||
375 | 375 | </LANProfile> |
376 | 376 | '; |
377 | 377 | |
378 | -if(! is_dir('w8')) |
|
378 | +if (!is_dir('w8')) |
|
379 | 379 | mkdir('w8'); |
380 | 380 | $xml_f_name = "w8/lan_prof.xml"; |
381 | -$xml_f = fopen($xml_f_name,'w'); |
|
382 | -fwrite($xml_f,$profile_file_contents. $eap_config['w8']. $closing) ; |
|
381 | +$xml_f = fopen($xml_f_name, 'w'); |
|
382 | +fwrite($xml_f, $profile_file_contents . $eap_config['w8'] . $closing); |
|
383 | 383 | fclose($xml_f); |
384 | -debug(2,"Installer has been written into directory $this->FPATH\n"); |
|
384 | +debug(2, "Installer has been written into directory $this->FPATH\n"); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | |
388 | 388 | |
389 | -private function writeMainNSH($eap,$attr) { |
|
390 | -debug(4,"writeMainNSH"); debug(4,$attr); |
|
389 | +private function writeMainNSH($eap, $attr) { |
|
390 | +debug(4, "writeMainNSH"); debug(4, $attr); |
|
391 | 391 | $fcontents = "!define W8\n"; |
392 | -if(Config::$NSIS_VERSION >= 3) |
|
393 | - $fcontents .= "Unicode true\n"; |
|
392 | +if (Config::$NSIS_VERSION >= 3) |
|
393 | + $fcontents .= "Unicode true\n"; |
|
394 | 394 | |
395 | 395 | |
396 | 396 | $EAP_OPTS = [ |
397 | -PEAP=>['str'=>'PEAP','exec'=>'user'], |
|
398 | -TLS=>['str'=>'TLS','exec'=>'user'], |
|
399 | -TTLS=>['str'=>'TTLS','exec'=>'user'], |
|
400 | -PWD=>['str'=>'PWD','exec'=>'user'], |
|
397 | +PEAP=>['str'=>'PEAP', 'exec'=>'user'], |
|
398 | +TLS=>['str'=>'TLS', 'exec'=>'user'], |
|
399 | +TTLS=>['str'=>'TTLS', 'exec'=>'user'], |
|
400 | +PWD=>['str'=>'PWD', 'exec'=>'user'], |
|
401 | 401 | ]; |
402 | 402 | |
403 | 403 | // Uncomment the line below if you want this module to run under XP (only displaying a warning) |
@@ -407,24 +407,24 @@ discard block |
||
407 | 407 | $exec_level = $EAP_OPTS[$eap["OUTER"]]['exec']; |
408 | 408 | $eap_str = $EAP_OPTS[$eap["OUTER"]]['str']; |
409 | 409 | |
410 | -$fcontents .= '!define '.$eap_str; |
|
411 | -$fcontents .= "\n".'!define EXECLEVEL "'.$exec_level.'"'; |
|
410 | +$fcontents .= '!define ' . $eap_str; |
|
411 | +$fcontents .= "\n" . '!define EXECLEVEL "' . $exec_level . '"'; |
|
412 | 412 | |
413 | -if($attr['internal:profile_count'][0] > 1) |
|
414 | -$fcontents .= "\n".'!define USER_GROUP "'.$this->translateString(str_replace('"','$\\"',$attr['profile:name'][0]), $this->code_page).'"'; |
|
413 | +if ($attr['internal:profile_count'][0] > 1) |
|
414 | +$fcontents .= "\n" . '!define USER_GROUP "' . $this->translateString(str_replace('"', '$\\"', $attr['profile:name'][0]), $this->code_page) . '"'; |
|
415 | 415 | $fcontents .= ' |
416 | -Caption "'. $this->translateString(sprintf(sprint_nsi(_("%s installer for %s")),Config::$CONSORTIUM['name'],$attr['general:instname'][0]), $this->code_page).'" |
|
417 | -!define APPLICATION "'. $this->translateString(sprintf(sprint_nsi(_("%s installer for %s")),Config::$CONSORTIUM['name'],$attr['general:instname'][0]), $this->code_page).'" |
|
418 | -!define VERSION "'.CAT::$VERSION_MAJOR.'.'.CAT::$VERSION_MINOR.'" |
|
416 | +Caption "'. $this->translateString(sprintf(sprint_nsi(_("%s installer for %s")), Config::$CONSORTIUM['name'], $attr['general:instname'][0]), $this->code_page) . '" |
|
417 | +!define APPLICATION "'. $this->translateString(sprintf(sprint_nsi(_("%s installer for %s")), Config::$CONSORTIUM['name'], $attr['general:instname'][0]), $this->code_page) . '" |
|
418 | +!define VERSION "'.CAT::$VERSION_MAJOR . '.' . CAT::$VERSION_MINOR . '" |
|
419 | 419 | !define INSTALLER_NAME "installer.exe" |
420 | -!define LANG "'.$this->lang.'" |
|
420 | +!define LANG "'.$this->lang . '" |
|
421 | 421 | '; |
422 | 422 | $fcontents .= $this->msInfoFile($attr); |
423 | 423 | |
424 | 424 | $fcontents .= ';-------------------------------- |
425 | -!define ORGANISATION "'.$this->translateString($attr['general:instname'][0], $this->code_page).'" |
|
426 | -!define SUPPORT "'. ((isset($attr['support:email'][0]) && $attr['support:email'][0] ) ? $attr['support:email'][0] : $this->translateString($this->support_email_substitute , $this->code_page)) .'" |
|
427 | -!define URL "'. ((isset($attr['support:url'][0]) && $attr['support:url'][0] ) ? $attr['support:url'][0] : $this->translateString($this->support_url_substitute, $this->code_page)) .'" |
|
425 | +!define ORGANISATION "'.$this->translateString($attr['general:instname'][0], $this->code_page) . '" |
|
426 | +!define SUPPORT "'. ((isset($attr['support:email'][0]) && $attr['support:email'][0]) ? $attr['support:email'][0] : $this->translateString($this->support_email_substitute, $this->code_page)) . '" |
|
427 | +!define URL "'. ((isset($attr['support:url'][0]) && $attr['support:url'][0]) ? $attr['support:url'][0] : $this->translateString($this->support_url_substitute, $this->code_page)) . '" |
|
428 | 428 | |
429 | 429 | !ifdef TLS |
430 | 430 | '; |
@@ -434,33 +434,33 @@ discard block |
||
434 | 434 | !endif |
435 | 435 | '; |
436 | 436 | |
437 | -if(isset($this->attributes['media:wired'][0]) && $attr['media:wired'][0] == 'on') |
|
437 | +if (isset($this->attributes['media:wired'][0]) && $attr['media:wired'][0] == 'on') |
|
438 | 438 | $fcontents .= '!define WIRED |
439 | 439 | '; |
440 | 440 | |
441 | -$f = fopen('main.nsh','w'); |
|
441 | +$f = fopen('main.nsh', 'w'); |
|
442 | 442 | fwrite($f, $fcontents); |
443 | 443 | fclose($f); |
444 | 444 | |
445 | 445 | } |
446 | 446 | |
447 | -private function writeProfilesNSH($P,$ca_array,$wired=0) { |
|
448 | -debug(4,"writeProfilesNSH"); |
|
449 | -debug(4,$P); |
|
447 | +private function writeProfilesNSH($P, $ca_array, $wired = 0) { |
|
448 | +debug(4, "writeProfilesNSH"); |
|
449 | +debug(4, $P); |
|
450 | 450 | $fcontents = ''; |
451 | - foreach($P as $p) |
|
451 | + foreach ($P as $p) |
|
452 | 452 | $fcontents .= "!insertmacro define_wlan_profile $p\n"; |
453 | 453 | |
454 | -$f = fopen('profiles.nsh','w'); |
|
454 | +$f = fopen('profiles.nsh', 'w'); |
|
455 | 455 | fwrite($f, $fcontents); |
456 | 456 | fclose($f); |
457 | 457 | |
458 | 458 | $fcontents = ''; |
459 | -$f = fopen('certs.nsh','w'); |
|
460 | -if($ca_array) { |
|
459 | +$f = fopen('certs.nsh', 'w'); |
|
460 | +if ($ca_array) { |
|
461 | 461 | foreach ($ca_array as $CA) { |
462 | 462 | $store = $CA['root'] ? "root" : "ca"; |
463 | - $fcontents .= '!insertmacro install_ca_cert "'.$CA['file'].'" "'.$CA['sha1'].'" "'.$store."\"\n"; |
|
463 | + $fcontents .= '!insertmacro install_ca_cert "' . $CA['file'] . '" "' . $CA['sha1'] . '" "' . $store . "\"\n"; |
|
464 | 464 | } |
465 | 465 | fwrite($f, $fcontents); |
466 | 466 | } |
@@ -469,8 +469,8 @@ discard block |
||
469 | 469 | |
470 | 470 | //private function write |
471 | 471 | |
472 | -private function copyFiles ($eap) { |
|
473 | -debug(4,"copyFiles start\n"); |
|
472 | +private function copyFiles($eap) { |
|
473 | +debug(4, "copyFiles start\n"); |
|
474 | 474 | $result; |
475 | 475 | $result = $this->copyFile('wlan_test.exe'); |
476 | 476 | $result = $this->copyFile('check_wired.cmd'); |
@@ -480,16 +480,16 @@ discard block |
||
480 | 480 | $result = $this->copyFile('base64.nsh'); |
481 | 481 | $result = $result && $this->copyFile('cat32.ico'); |
482 | 482 | $result = $result && $this->copyFile('cat_150.bmp'); |
483 | - $this->translateFile('common.inc','common.nsh',$this->code_page); |
|
484 | - if($eap["OUTER"] == PWD) { |
|
485 | - $this->translateFile('pwd.inc','cat.NSI',$this->code_page); |
|
483 | + $this->translateFile('common.inc', 'common.nsh', $this->code_page); |
|
484 | + if ($eap["OUTER"] == PWD) { |
|
485 | + $this->translateFile('pwd.inc', 'cat.NSI', $this->code_page); |
|
486 | 486 | $result = $result && $this->copyFile('Aruba_Networks_EAP-pwd_x32.msi'); |
487 | 487 | $result = $result && $this->copyFile('Aruba_Networks_EAP-pwd_x64.msi'); |
488 | 488 | } else { |
489 | - $this->translateFile('eap_w8.inc','cat.NSI',$this->code_page); |
|
489 | + $this->translateFile('eap_w8.inc', 'cat.NSI', $this->code_page); |
|
490 | 490 | $result = 1; |
491 | 491 | } |
492 | -debug(4,"copyFiles end\n"); |
|
492 | +debug(4, "copyFiles end\n"); |
|
493 | 493 | return($result); |
494 | 494 | } |
495 | 495 |