Completed
Branch master (03ec64)
by Brook
14:43
created
core/CAT.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -230,7 +230,7 @@
 block discarded – undo
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) {
Please login to merge, or discard this patch.
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -191,9 +191,9 @@
 block discarded – undo
191 191
      * gets the language setting in CAT
192 192
      */
193 193
     static public function get_lang() {
194
-       if(self::$LANG === '')
195
-         list(self::$LANG, $xx) = self::set_lang();
196
-       return self::$LANG;
194
+        if(self::$LANG === '')
195
+            list(self::$LANG, $xx) = self::set_lang();
196
+        return self::$LANG;
197 197
     }
198 198
 
199 199
     /**
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -73,12 +73,12 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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");
Please login to merge, or discard this patch.
Braces   +17 added lines, -12 removed lines patch added patch discarded remove patch
@@ -74,14 +74,16 @@  discard block
 block discarded – undo
74 74
 
75 75
         if (CAT::$RELEASE_VERSION) {
76 76
             $temp_version = "CAT-".CAT::$VERSION_MAJOR.".".CAT::$VERSION_MINOR;
77
-            if (CAT::$VERSION_PATCH != 0)
78
-                    $temp_version .= ".".CAT::$VERSION_PATCH;
79
-            if (CAT::$VERSION_EXTRA != "")
80
-                $temp_version .= "-".CAT::$VERSION_EXTRA;
77
+            if (CAT::$VERSION_PATCH != 0) {
78
+                                $temp_version .= ".".CAT::$VERSION_PATCH;
79
+            }
80
+            if (CAT::$VERSION_EXTRA != "") {
81
+                            $temp_version .= "-".CAT::$VERSION_EXTRA;
82
+            }
81 83
             CAT::$VERSION = sprintf(_("Release %s"), $temp_version );
84
+        } else {
85
+                    CAT::$VERSION = _("Unreleased SVN Revision");
82 86
         }
83
-        else
84
-            CAT::$VERSION = _("Unreleased SVN Revision");
85 87
     }
86 88
 
87 89
     /** 
@@ -170,16 +172,18 @@  discard block
 block discarded – undo
170 172
             // we need to map stuff manually
171 173
             $thelang = $try_lang;
172 174
 
173
-            foreach (Config::$LANGUAGES as $language => $value)
174
-                if (preg_match("/^" . $language . ".*/", $try_lang)) {
175
+            foreach (Config::$LANGUAGES as $language => $value) {
176
+                            if (preg_match("/^" . $language . ".*/", $try_lang)) {
175 177
                     $thelang = $value['locale'];
178
+            }
176 179
                     $lang_index = $language;
177 180
                 }
178 181
 
179 182
             // echo "Trying to set language to $thelang...";
180 183
 //        putenv("LC_ALL=$thelang");
181
-            if (setlocale(LC_ALL, $thelang))
182
-                break;
184
+            if (setlocale(LC_ALL, $thelang)) {
185
+                            break;
186
+            }
183 187
         }
184 188
         putenv("LC_ALL=" . $thelang);
185 189
         debug(4, "selected lang:$lang_index:$thelang\n");
@@ -191,8 +195,9 @@  discard block
 block discarded – undo
191 195
      * gets the language setting in CAT
192 196
      */
193 197
     static public function get_lang() {
194
-       if(self::$LANG === '')
195
-         list(self::$LANG, $xx) = self::set_lang();
198
+       if(self::$LANG === '') {
199
+                list(self::$LANG, $xx) = self::set_lang();
200
+       }
196 201
        return self::$LANG;
197 202
     }
198 203
 
Please login to merge, or discard this patch.
core/DBConnection.php 2 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -87,6 +87,7 @@  discard block
 block discarded – undo
87 87
     /**
88 88
      * executes a query and triggers logging to the SQL audit log if it's not a SELECT
89 89
      * @param string $querystring the query to be executed
90
+     * @param string $db
90 91
      * @return mixed the query result as mysqli_result object; or TRUE on non-return-value statements
91 92
      */
92 93
     public static function exec($db, $querystring) {
@@ -134,6 +135,8 @@  discard block
 block discarded – undo
134 135
     /**
135 136
      * Checks if a raw data pointer is public data (return value FALSE) or if 
136 137
      * yes who the authorised admins to view it are (return array of user IDs)
138
+     * @param string $table
139
+     * @param string $row
137 140
      */
138 141
     public static function isDataRestricted($table, $row) {
139 142
         if ($table != "institution_option" && $table != "profile_option" && $table != "federation_option")
@@ -175,6 +178,7 @@  discard block
 block discarded – undo
175 178
 
176 179
     /**
177 180
      * Retrieves the last auto-id of an INSERT. Needs to be called immediately after the corresponding exec() call
181
+     * @param string $db
178 182
      * @return int the last autoincrement-ID
179 183
      */
180 184
     public static function lastID($db) {
Please login to merge, or discard this patch.
Braces   +25 added lines, -14 removed lines patch added patch discarded remove patch
@@ -106,8 +106,9 @@  discard block
 block discarded – undo
106 106
         }
107 107
 
108 108
         // log exact query to audit log, if it's not a SELECT
109
-        if (preg_match("/^SELECT/i", $querystring) == 0)
110
-            CAT::writeSQLAudit("[DB: " . strtoupper($db) . "] " . $querystring);
109
+        if (preg_match("/^SELECT/i", $querystring) == 0) {
110
+                    CAT::writeSQLAudit("[DB: " . strtoupper($db) . "] " . $querystring);
111
+        }
111 112
         return $result;
112 113
     }
113 114
 
@@ -120,14 +121,17 @@  discard block
 block discarded – undo
120 121
      */
121 122
     public static function fetchRawDataByIndex($table, $row) {
122 123
         // only for select tables!
123
-        if ($table != "institution_option" && $table != "profile_option" && $table != "federation_option")
124
-            return FALSE;
124
+        if ($table != "institution_option" && $table != "profile_option" && $table != "federation_option") {
125
+                    return FALSE;
126
+        }
125 127
         $blob_query = DBConnection::exec("INST", "SELECT option_value from $table WHERE row = $row");
126
-        while ($a = mysqli_fetch_object($blob_query))
127
-            $blob = $a->option_value;
128
+        while ($a = mysqli_fetch_object($blob_query)) {
129
+                    $blob = $a->option_value;
130
+        }
128 131
 
129
-        if (!isset($blob))
130
-            return FALSE;
132
+        if (!isset($blob)) {
133
+                    return FALSE;
134
+        }
131 135
         return $blob;
132 136
     }
133 137
 
@@ -136,13 +140,17 @@  discard block
 block discarded – undo
136 140
      * yes who the authorised admins to view it are (return array of user IDs)
137 141
      */
138 142
     public static function isDataRestricted($table, $row) {
139
-        if ($table != "institution_option" && $table != "profile_option" && $table != "federation_option")
140
-            return []; // better safe than sorry: that's an error, so assume nobody is authorised to act on that data
143
+        if ($table != "institution_option" && $table != "profile_option" && $table != "federation_option") {
144
+                    return [];
145
+        }
146
+        // better safe than sorry: that's an error, so assume nobody is authorised to act on that data
141 147
         switch ($table) {
142 148
             case "profile_option":
143 149
                 $blob_query = DBConnection::exec("INST", "SELECT profile_id from $table WHERE row = $row");
144
-                while ($a = mysqli_fetch_object($blob_query)) // only one row
150
+                while ($a = mysqli_fetch_object($blob_query)) {
151
+                    // only one row
145 152
                     $blobprofile = $a->profile_id;
153
+                }
146 154
                 // is the profile in question public?
147 155
                 $profile = new Profile($blobprofile);
148 156
                 if ($profile->getShowtime() == TRUE) { // public data
@@ -154,8 +162,10 @@  discard block
 block discarded – undo
154 162
                 break;
155 163
             case "institution_option":
156 164
                 $blob_query = DBConnection::exec("INST", "SELECT institution_id from $table WHERE row = $row");
157
-                while ($a = mysqli_fetch_object($blob_query)) // only one row
165
+                while ($a = mysqli_fetch_object($blob_query)) {
166
+                    // only one row
158 167
                     $blobinst = $a->institution_id;
168
+                }
159 169
                 $inst = new IdP($blobinst);
160 170
                 // if at least one of the profiles belonging to the inst is public, the data is public
161 171
                 if ($inst->isOneProfileShowtime()) { // public data
@@ -209,8 +219,9 @@  discard block
 block discarded – undo
209 219
             exit(1);
210 220
         }
211 221
 
212
-        if ($db == "EXTERNAL" && Config::$CONSORTIUM['name'] == "eduroam" && isset(Config::$CONSORTIUM['deployment-voodoo']) && Config::$CONSORTIUM['deployment-voodoo'] == "Operations Team")
213
-            mysqli_query($this->connection, "SET NAMES 'latin1'");
222
+        if ($db == "EXTERNAL" && Config::$CONSORTIUM['name'] == "eduroam" && isset(Config::$CONSORTIUM['deployment-voodoo']) && Config::$CONSORTIUM['deployment-voodoo'] == "Operations Team") {
223
+                    mysqli_query($this->connection, "SET NAMES 'latin1'");
224
+        }
214 225
     }
215 226
 
216 227
 }
Please login to merge, or discard this patch.
core/DeviceConfig.php 4 patches
Doc Comments   +2 added lines, -5 removed lines patch added patch discarded remove patch
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
     */
Please login to merge, or discard this patch.
Indentation   +421 added lines, -421 removed lines patch added patch discarded remove patch
@@ -6,10 +6,10 @@  discard block
 block discarded – undo
6 6
 ?>
7 7
 <?php
8 8
 /**
9
-  * This file defines the abstract Device class
10
-  *
11
-  * @package ModuleWriting
12
-  */
9
+ * This file defines the abstract Device class
10
+ *
11
+ * @package ModuleWriting
12
+ */
13 13
 
14 14
 /**
15 15
  * 
@@ -46,10 +46,10 @@  discard block
 block discarded – undo
46 46
  */
47 47
 
48 48
 abstract class DeviceConfig {
49
-   /**
50
-    * stores the path to the temporary working directory for a module instance
51
-    * @var string $FPATH
52
-    */
49
+    /**
50
+     * stores the path to the temporary working directory for a module instance
51
+     * @var string $FPATH
52
+     */
53 53
     public $FPATH;
54 54
 
55 55
     /**
@@ -58,390 +58,390 @@  discard block
 block discarded – undo
58 58
      */
59 59
     public $specialities;
60 60
 
61
-   /**
61
+    /**
62 62
      * device module constructor should be defined by each module, but if it is not, then here is a default one
63 63
      */
64 64
 
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);
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);
69 69
     }
70 70
 
71 71
 
72
-   /**
73
-    * Set up working environment for a device module
74
-    *
75
-    * Sets up the device module environment taking into account the actual profile
76
-    * selected by the user in the GUI. The selected profile is passed as the
77
-    * Profile $profile argumant.
78
-    *
79
-    * This method needs to be called after the device instance has been created (the GUI class does that)
80
-    *
81
-    * setup performs the following tasks:
82
-    * - collect profile attributes and pass them as the attributes property;
83
-    * - create the temporary working directory
84
-    * - process CA certificates and store them as 'internal:CAs' attribute
85
-    * - process and save optional info files and store references to them in
86
-    *   'internal:info_file' attribute
87
-    * @param Profile $profile the profile object which will be passed by the caller
88
-    * @final not to be redefined
89
-    */
72
+    /**
73
+     * Set up working environment for a device module
74
+     *
75
+     * Sets up the device module environment taking into account the actual profile
76
+     * selected by the user in the GUI. The selected profile is passed as the
77
+     * Profile $profile argumant.
78
+     *
79
+     * This method needs to be called after the device instance has been created (the GUI class does that)
80
+     *
81
+     * setup performs the following tasks:
82
+     * - collect profile attributes and pass them as the attributes property;
83
+     * - create the temporary working directory
84
+     * - process CA certificates and store them as 'internal:CAs' attribute
85
+     * - process and save optional info files and store references to them in
86
+     *   'internal:info_file' attribute
87
+     * @param Profile $profile the profile object which will be passed by the caller
88
+     * @final not to be redefined
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");
94
-          error("No profile has been set");
95
-          exit;
96
-       }
97
-       $this->attributes = $this->getProfileAttributes($profile);
98
-       if(! $this->selected_eap) {
99
-          error("No EAP type specified.");
100
-          exit;
101
-       }
102
-       // create temporary directory, its full path will be saved in $this->FPATH;
103
-       $T = createTemporaryDirectory('installer');
104
-       $this->FPATH = $T['dir'];
105
-       mkdir($T['dir'].'/tmp');
106
-       chdir($T['dir'].'/tmp');
107
-       $CAs = [];
108
-       if(isset($this->attributes['eap:ca_file'])) {
109
-       foreach ($this->attributes['eap:ca_file'] as $ca) {
110
-          if($c = X509::processCertificate($ca))
111
-             $CAs[] = $c;
112
-          }
113
-          $this->attributes['internal:CAs'][0]=$CAs;
114
-       }
115
-       if(isset($this->attributes['support:info_file'])) {
116
-          $this->attributes['internal:info_file'][0] = 
117
-             $this->saveInfoFile($this->attributes['support:info_file'][0]);
118
-       }
119
-       if(isset($this->attributes['general:logo_file']))
120
-          $this->attributes['internal:logo_file'] = 
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'];;
124
-       $this->attributes['internal:consortia'] = $this->getConsortia();
125
-       $this->lang_index = CAT::get_lang();
126
-       // phpMD says the below is not needed. Wow.
127
-       // $idp = new IdP($profile->institution);
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']);
131
-       CAT::set_locale($olddomain);
132
-
133
-       if($this->signer && $this->options['sign'])
134
-         $this->sign = CAT::$root . '/signer/'. $this->signer;
135
-       $this->installerBasename = $this->getInstallerBasename();
91
+        debug(4,"module setup start\n");
92
+        if(! $profile instanceof Profile) {
93
+            debug(2,"No profile has been set\n");
94
+            error("No profile has been set");
95
+            exit;
96
+        }
97
+        $this->attributes = $this->getProfileAttributes($profile);
98
+        if(! $this->selected_eap) {
99
+            error("No EAP type specified.");
100
+            exit;
101
+        }
102
+        // create temporary directory, its full path will be saved in $this->FPATH;
103
+        $T = createTemporaryDirectory('installer');
104
+        $this->FPATH = $T['dir'];
105
+        mkdir($T['dir'].'/tmp');
106
+        chdir($T['dir'].'/tmp');
107
+        $CAs = [];
108
+        if(isset($this->attributes['eap:ca_file'])) {
109
+        foreach ($this->attributes['eap:ca_file'] as $ca) {
110
+            if($c = X509::processCertificate($ca))
111
+                $CAs[] = $c;
112
+            }
113
+            $this->attributes['internal:CAs'][0]=$CAs;
114
+        }
115
+        if(isset($this->attributes['support:info_file'])) {
116
+            $this->attributes['internal:info_file'][0] = 
117
+                $this->saveInfoFile($this->attributes['support:info_file'][0]);
118
+        }
119
+        if(isset($this->attributes['general:logo_file']))
120
+            $this->attributes['internal:logo_file'] = 
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'];;
124
+        $this->attributes['internal:consortia'] = $this->getConsortia();
125
+        $this->lang_index = CAT::get_lang();
126
+        // phpMD says the below is not needed. Wow.
127
+        // $idp = new IdP($profile->institution);
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']);
131
+        CAT::set_locale($olddomain);
132
+
133
+        if($this->signer && $this->options['sign'])
134
+            $this->sign = CAT::$root . '/signer/'. $this->signer;
135
+        $this->installerBasename = $this->getInstallerBasename();
136 136
     }
137 137
 
138
-  /**
139
-    * Selects the preferred eap method based on profile EAP configuration and device EAP capabilities
140
-    *
141
-    * @param array eap_array an array of eap methods supported by a given device
142
-    * @return the best matching EAP type for the profile; or 0 if no match was found
143
-    */   
144
-   public function getPreferredEapType($eap_array) {
145
-     foreach ($eap_array as $eap) {
146
-         if(in_array($eap,$this->supportedEapMethods)) {
138
+    /**
139
+     * Selects the preferred eap method based on profile EAP configuration and device EAP capabilities
140
+     *
141
+     * @param array eap_array an array of eap methods supported by a given device
142
+     * @return the best matching EAP type for the profile; or 0 if no match was found
143
+     */   
144
+    public function getPreferredEapType($eap_array) {
145
+        foreach ($eap_array as $eap) {
146
+            if(in_array($eap,$this->supportedEapMethods)) {
147 147
             $this->selected_eap = $eap;
148 148
             debug(4,"Selected EAP:");
149 149
             debug(4,$eap);
150 150
             return($eap);
151
-         }
152
-     }
153
-     return(0);
154
-   }
155
-  /**
156
-    * prepare usage information for the installer
157
-    * every device module should override this method
158
-    *
159
-    * @return String HTML text to be displayed
160
-    */ 
161
-   public function writeDeviceInfo() {
162
-     return _("Sorry, this should not happen - no additional information is available");
163
-   }
164
-
165
-  /**
166
-    *  Copy a file from the module location to the temporary directory.
167
-    *
168
-    * If the second argument is provided then the file will be saved under the name 
169
-    * taken form this argument. If only one parameter is given, source and destination
170
-    * filenames are the same
171
-    * Source file can be located either in the Files subdirectory or in the sibdirectory of Files
172
-    * named the same as device_id. The second option takes precedence.
173
-    *
174
-    * @param string $source_name The source file name
175
-    * @param string $output_name The destination file name
176
-    *
177
-    * @return bool result of the copy operation
178
-    * @final not to be redefined
179
-    */
180
-   final protected function copyFile($source_name, $output_name = 0) {
181
-      if  ( $output_name === 0)
151
+            }
152
+        }
153
+        return(0);
154
+    }
155
+    /**
156
+     * prepare usage information for the installer
157
+     * every device module should override this method
158
+     *
159
+     * @return String HTML text to be displayed
160
+     */ 
161
+    public function writeDeviceInfo() {
162
+        return _("Sorry, this should not happen - no additional information is available");
163
+    }
164
+
165
+    /**
166
+     *  Copy a file from the module location to the temporary directory.
167
+     *
168
+     * If the second argument is provided then the file will be saved under the name 
169
+     * taken form this argument. If only one parameter is given, source and destination
170
+     * filenames are the same
171
+     * Source file can be located either in the Files subdirectory or in the sibdirectory of Files
172
+     * named the same as device_id. The second option takes precedence.
173
+     *
174
+     * @param string $source_name The source file name
175
+     * @param string $output_name The destination file name
176
+     *
177
+     * @return bool result of the copy operation
178
+     * @final not to be redefined
179
+     */
180
+    final protected function copyFile($source_name, $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;
189
-      else {
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
+        else {
190 190
         debug(2,"fileCopy:reqested file $source_name does not exist\n");
191 191
         return(FALSE);
192
-      }
193
-      debug(4,"Copying $source to $output_name\n");
194
-      $result = copy($source,"$output_name");
195
-      if(! $result )
192
+        }
193
+        debug(4,"Copying $source to $output_name\n");
194
+        $result = copy($source,"$output_name");
195
+        if(! $result )
196 196
         debug(2,"fileCopy($source_name, $output_name) failed\n");
197
-      return($result); 
198
-   }
199
-
200
-
201
-  /**
202
-    *  Copy a file from the module location to the temporary directory aplying transcoding.
203
-    *
204
-    * Transcoding is only required for Windows installers, and no Unicode support
205
-    * in NSIS (NSIS version below 3)
206
-    * Trancoding is only applied if the third optional parameter is set and nonzero
207
-    * If Config::$NSIS_VERSION is set to 3 or more, no transcoding will be applied
208
-    * regardless of the third parameter value.
209
-    * If the second argument is provided and is not equal to 0, then the file will be
210
-    * saved under the name taken from this argument.
211
-    * If only one parameter is given or the second is equal to 0, source and destination
212
-    * filenames are the same.
213
-    * The third optional parameter, if nonzero, should be the character set understood by iconv
214
-    * This is required by the Windows installer and is expected to go away in the future.
215
-    * Source file can be located either in the Files subdirectory or in the sibdirectory of Files
216
-    * named the same as device_id. The second option takes precedence.
217
-    *
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
221
-    *
222
-    * @final not to be redefined
223
-    */
224
-
225
-   final protected function translateFile($source_name, $output_name = 0, $encoding = 0) {
226
-      if(Config::$NSIS_VERSION >= 3)
197
+        return($result); 
198
+    }
199
+
200
+
201
+    /**
202
+     *  Copy a file from the module location to the temporary directory aplying transcoding.
203
+     *
204
+     * Transcoding is only required for Windows installers, and no Unicode support
205
+     * in NSIS (NSIS version below 3)
206
+     * Trancoding is only applied if the third optional parameter is set and nonzero
207
+     * If Config::$NSIS_VERSION is set to 3 or more, no transcoding will be applied
208
+     * regardless of the third parameter value.
209
+     * If the second argument is provided and is not equal to 0, then the file will be
210
+     * saved under the name taken from this argument.
211
+     * If only one parameter is given or the second is equal to 0, source and destination
212
+     * filenames are the same.
213
+     * The third optional parameter, if nonzero, should be the character set understood by iconv
214
+     * This is required by the Windows installer and is expected to go away in the future.
215
+     * Source file can be located either in the Files subdirectory or in the sibdirectory of Files
216
+     * named the same as device_id. The second option takes precedence.
217
+     *
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
221
+     *
222
+     * @final not to be redefined
223
+     */
224
+
225
+    final protected function translateFile($source_name, $output_name = 0, $encoding = 0) {
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");
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;
238
-      include($source);
239
-      $output = ob_get_clean();
240
-      if($encoding) {
231
+        debug(4,"translateFile($source_name, $output_name, $encoding)\n");
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;
238
+        include($source);
239
+        $output = ob_get_clean();
240
+        if($encoding) {
241 241
         $output_c = iconv('UTF-8',$encoding.'//TRANSLIT',$output);
242 242
         if($output_c)
243
-           $output = $output_c;
244
-      }
245
-      $f = fopen("$output_name","w");
246
-      if(! $f)
247
-         debug(2,"translateFile($source, $output_name, $encoding) failed\n");
248
-      fwrite($f,$output);
249
-      fclose($f);
250
-      debug(4,"translateFile($source, $output_name, $encoding) end\n");
251
-   }
252
-
253
-
254
-  /**
255
-    * Transcode a string adding double quotes escaping
256
-    *
257
-    * Transcoding is only required for Windows installers, and no Unicode support
258
-    * in NSIS (NSIS version below 3)
259
-    * Trancoding is only applied if the third optional parameter is set and nonzero
260
-    * If Config::$NSIS_VERSION is set to 3 or more, no transcoding will be applied
261
-    * regardless of the second parameter value.
262
-    * The second optional parameter, if nonzero, should be the character set understood by iconv
263
-    * This is required by the Windows installer and is expected to go away in the future.
264
-    *
265
-    * @param string $source_name The source file name
266
-    * @param int $use_win_cp Set Windows charset if non-zero
267
-    *
268
-    * @final not to be redefined
269
-    */
270
-
271
-   final protected function translateString($source_string,$encoding = 0) {
272
-      if(Config::$NSIS_VERSION >= 3)
243
+            $output = $output_c;
244
+        }
245
+        $f = fopen("$output_name","w");
246
+        if(! $f)
247
+            debug(2,"translateFile($source, $output_name, $encoding) failed\n");
248
+        fwrite($f,$output);
249
+        fclose($f);
250
+        debug(4,"translateFile($source, $output_name, $encoding) end\n");
251
+    }
252
+
253
+
254
+    /**
255
+     * Transcode a string adding double quotes escaping
256
+     *
257
+     * Transcoding is only required for Windows installers, and no Unicode support
258
+     * in NSIS (NSIS version below 3)
259
+     * Trancoding is only applied if the third optional parameter is set and nonzero
260
+     * If Config::$NSIS_VERSION is set to 3 or more, no transcoding will be applied
261
+     * regardless of the second parameter value.
262
+     * The second optional parameter, if nonzero, should be the character set understood by iconv
263
+     * This is required by the Windows installer and is expected to go away in the future.
264
+     *
265
+     * @param string $source_name The source file name
266
+     * @param int $use_win_cp Set Windows charset if non-zero
267
+     *
268
+     * @final not to be redefined
269
+     */
270
+
271
+    final protected function translateString($source_string,$encoding = 0) {
272
+        if(Config::$NSIS_VERSION >= 3)
273 273
         $encoding = 0;
274
-      if($encoding)
274
+        if($encoding)
275 275
         $output_c = iconv('UTF-8',$encoding.'//TRANSLIT',$source_string);
276
-      else
276
+        else
277 277
         $output_c = $source_string;
278
-      if($output_c) 
279
-         $source_string  = str_replace('"','$\\"',$output_c);
280
-      else
281
-         debug(2,"Failed to convert string $source_string\n");
282
-      return $source_string;
283
-   }
284
-
285
-
286
-  /**
287
-   * Save certificate files in either DER or PEM format
288
-   *
289
-   * Certificate files will be saved in the module working directory.
290
-   * @param string $format  only "der" and "pem" are currently allowed
291
-   * @return array an array of arrays or FALSE on error
292
-   * saved certificate file names are avalable under the 'file' index
293
-   * additional array entries are indexed as 'sha1', 'md5', and 'root'.
294
-   * sha1 and md5 are correcponding certificate hashes
295
-   * root is set to 1 for the CA roor certicicate and 0 otherwise
296
-  */ 
297
-   final protected function saveCertificateFiles($format) {
298
-     if($format == 'der' || $format == 'pam') {
299
-       $i = 0;
300
-       $CA_files = [];
301
-       $ca_array = $this->attributes['internal:CAs'][0];
302
-       if(! $ca_array)
303
-         return(FALSE);
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")
278
+        if($output_c) 
279
+            $source_string  = str_replace('"','$\\"',$output_c);
280
+        else
281
+            debug(2,"Failed to convert string $source_string\n");
282
+        return $source_string;
283
+    }
284
+
285
+
286
+    /**
287
+     * Save certificate files in either DER or PEM format
288
+     *
289
+     * Certificate files will be saved in the module working directory.
290
+     * @param string $format  only "der" and "pem" are currently allowed
291
+     * @return array an array of arrays or FALSE on error
292
+     * saved certificate file names are avalable under the 'file' index
293
+     * additional array entries are indexed as 'sha1', 'md5', and 'root'.
294
+     * sha1 and md5 are correcponding certificate hashes
295
+     * root is set to 1 for the CA roor certicicate and 0 otherwise
296
+     */ 
297
+    final protected function saveCertificateFiles($format) {
298
+        if($format == 'der' || $format == 'pam') {
299
+        $i = 0;
300
+        $CA_files = [];
301
+        $ca_array = $this->attributes['internal:CAs'][0];
302
+        if(! $ca_array)
303
+            return(FALSE);
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 308
             fwrite($f,$CA['pem']);
309
-         else
309
+            else
310 310
             fwrite($f,$CA['der']);
311
-         fclose($f);
312
-         $C = [];
313
-         $C['file'] = "cert-$i.crt";
314
-         $C['sha1'] = $CA['sha1'];
315
-         $C['md5'] = $CA['md5'];
316
-         $C['root'] = $CA['root'];
317
-         $CA_files[] = $C;
318
-         $i++;
319
-       }
320
-       return($CA_files);
321
-     } else {
322
-       debug(2, 'incorrect format value specified');
323
-       return(FALSE);
324
-     }
311
+            fclose($f);
312
+            $C = [];
313
+            $C['file'] = "cert-$i.crt";
314
+            $C['sha1'] = $CA['sha1'];
315
+            $C['md5'] = $CA['md5'];
316
+            $C['root'] = $CA['root'];
317
+            $CA_files[] = $C;
318
+            $i++;
319
+        }
320
+        return($CA_files);
321
+        } else {
322
+        debug(2, 'incorrect format value specified');
323
+        return(FALSE);
324
+        }
325 325
       
326
-   }
327
-
328
-   /**
329
-    * Generate installer filename base.
330
-    * Device module should use this name adding an extension.
331
-    * Normally the device identifier follows the Consortium name.
332
-    * The sting taken for the device identifier equals (by default) to the index in the listDevices array,
333
-    * but can be overriden with the 'device_id' device option.
334
-    */
335
-   private function getInstallerBasename() {
336
-      $replace_pattern = '/[ ()\/\'"]+/';
337
-      debug(4,"getInstallerBasename1:".$this->attributes['general:instname'][0]."\n");
338
-      $inst = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', $this->attributes['general:instname'][0]));
339
-      debug(4,"getInstallerBasename2:$inst\n");
340
-      $Inst_a = explode('_',$inst);
341
-      if(count($Inst_a) > 2) {
342
-         $inst = '';
343
-         foreach($Inst_a as $i)
344
-           $inst .= $i[0];
345
-      }   
346
-      $c_name = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', Config::$CONSORTIUM['name']));
347
-      if($this->attributes['internal:profile_count'][0] > 1) {
348
-         if(!empty($this->attributes['profile:name']) && ! empty($this->attributes['profile:name'][0])) {
349
-             $prof = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', $this->attributes['profile:name'][0]));
350
-             $prof = preg_replace('/_+$/','',$prof);
351
-             return $c_name. '-'. $this->getDeviceId() . $inst .'-'. $prof;
352
-         }
353
-      }
354
-      return $c_name. '-'. $this->getDeviceId() . $inst;
355
-  }
356
-
357
-  private function getDeviceId() {
326
+    }
327
+
328
+    /**
329
+     * Generate installer filename base.
330
+     * Device module should use this name adding an extension.
331
+     * Normally the device identifier follows the Consortium name.
332
+     * The sting taken for the device identifier equals (by default) to the index in the listDevices array,
333
+     * but can be overriden with the 'device_id' device option.
334
+     */
335
+    private function getInstallerBasename() {
336
+        $replace_pattern = '/[ ()\/\'"]+/';
337
+        debug(4,"getInstallerBasename1:".$this->attributes['general:instname'][0]."\n");
338
+        $inst = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', $this->attributes['general:instname'][0]));
339
+        debug(4,"getInstallerBasename2:$inst\n");
340
+        $Inst_a = explode('_',$inst);
341
+        if(count($Inst_a) > 2) {
342
+            $inst = '';
343
+            foreach($Inst_a as $i)
344
+            $inst .= $i[0];
345
+        }   
346
+        $c_name = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', Config::$CONSORTIUM['name']));
347
+        if($this->attributes['internal:profile_count'][0] > 1) {
348
+            if(!empty($this->attributes['profile:name']) && ! empty($this->attributes['profile:name'][0])) {
349
+                $prof = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', $this->attributes['profile:name'][0]));
350
+                $prof = preg_replace('/_+$/','',$prof);
351
+                return $c_name. '-'. $this->getDeviceId() . $inst .'-'. $prof;
352
+            }
353
+        }
354
+        return $c_name. '-'. $this->getDeviceId() . $inst;
355
+    }
356
+
357
+    private function getDeviceId() {
358 358
     $d_id = $this->device_id;
359 359
     if(isset($this->options['device_id'])) 
360
-      $d_id = $this->options['device_id'];
360
+        $d_id = $this->options['device_id'];
361 361
     if($d_id !== '')
362
-      $d_id .= '-';
362
+        $d_id .= '-';
363 363
     return $d_id;
364
-  }
364
+    }
365 365
 
366 366
 
367
-  private function getSSIDs() {
367
+    private function getSSIDs() {
368 368
     $S['add']=[];
369 369
     $S['del']=[];
370 370
     if (isset(Config::$CONSORTIUM['ssid'])) {
371
-       foreach (Config::$CONSORTIUM['ssid'] as $ssid) {
371
+        foreach (Config::$CONSORTIUM['ssid'] as $ssid) {
372 372
         if(isset(Config::$CONSORTIUM['tkipsupport']) && Config::$CONSORTIUM['tkipsupport'] == TRUE)
373
-          $S['add'][$ssid] = 'TKIP';
373
+            $S['add'][$ssid] = 'TKIP';
374 374
         else {
375
-          $S['add'][$ssid] = 'AES';
376
-          $S['del'][$ssid] = 'TKIP';
375
+            $S['add'][$ssid] = 'AES';
376
+            $S['del'][$ssid] = 'TKIP';
377
+        }
377 378
         }
378
-       }
379 379
     }
380 380
     if(isset($this->attributes['media:SSID'])) {
381
-      $SSID = $this->attributes['media:SSID'];
381
+        $SSID = $this->attributes['media:SSID'];
382 382
 
383
-      foreach($SSID as $ssid)
384
-         $S['add'][$ssid] = 'AES';
385
-      }
383
+        foreach($SSID as $ssid)
384
+            $S['add'][$ssid] = 'AES';
385
+        }
386 386
     if(isset($this->attributes['media:SSID_with_legacy'])) {
387
-      $SSID = $this->attributes['media:SSID_with_legacy'];
388
-      foreach($SSID as $ssid)
389
-         $S['add'][$ssid] = 'TKIP';
387
+        $SSID = $this->attributes['media:SSID_with_legacy'];
388
+        foreach($SSID as $ssid)
389
+            $S['add'][$ssid] = 'TKIP';
390 390
     }
391 391
     if(isset($this->attributes['media:remove_SSID'])) {
392
-      $SSID = $this->attributes['media:remove_SSID'];
393
-      foreach($SSID as $ssid)
394
-         $S['del'][$ssid] = 'DEL';
392
+        $SSID = $this->attributes['media:remove_SSID'];
393
+        foreach($SSID as $ssid)
394
+            $S['del'][$ssid] = 'DEL';
395 395
     }
396 396
     return $S;
397
-  }
397
+    }
398 398
 
399
-  private function getConsortia() {
400
-      $OIs = [];
401
-      $OIs = array_merge($OIs, Config::$CONSORTIUM['interworking-consortium-oi']);
402
-      if (isset($this->attributes['media:consortium_OI']))
403
-          foreach ($this->attributes['media:consortium_OI'] as $new_oi)
399
+    private function getConsortia() {
400
+        $OIs = [];
401
+        $OIs = array_merge($OIs, Config::$CONSORTIUM['interworking-consortium-oi']);
402
+        if (isset($this->attributes['media:consortium_OI']))
403
+            foreach ($this->attributes['media:consortium_OI'] as $new_oi)
404 404
             $OIs[] = $new_oi;
405
-      return $OIs;
406
-  }
405
+        return $OIs;
406
+    }
407 407
   
408
-  /**
409
-   * An array with shorthand definitions for MIME types
410
-   * @var array
411
-   */
412
-  private $mime_extensions = [
413
-     'text/plain' => 'txt',
414
-     'text/rtf' => 'rtf',
415
-     'application/pdf' =>'pdf',
416
-  ];
417
-
418
-  private function saveLogoFile($Logos) {
408
+    /**
409
+     * An array with shorthand definitions for MIME types
410
+     * @var array
411
+     */
412
+    private $mime_extensions = [
413
+        'text/plain' => 'txt',
414
+        'text/rtf' => 'rtf',
415
+        'application/pdf' =>'pdf',
416
+    ];
417
+
418
+    private function saveLogoFile($Logos) {
419 419
     $i=0;
420 420
     $returnarray= [];
421 421
     foreach ($Logos as $blob) {
422
-      $finfo = new finfo(FILEINFO_MIME_TYPE);
423
-      $mime = $finfo->buffer($blob);
424
-      if(preg_match('/^image\/(.*)/',$mime,$m))
422
+        $finfo = new finfo(FILEINFO_MIME_TYPE);
423
+        $mime = $finfo->buffer($blob);
424
+        if(preg_match('/^image\/(.*)/',$mime,$m))
425 425
         $ext = $m[1];
426
-      else
426
+        else
427 427
         $ext = 'unsupported';
428
-      debug(4,"saveLogoFile: $mime : $ext\n");
429
-      $f_name = 'logo-'.$i.'.'.$ext;
430
-      $f = fopen($f_name,"w");
431
-      if(! $f) {
432
-          debug(2,"saveLogoFile failed for: $f_name\n");
433
-          die("problem opening the file\n");
434
-      }
435
-      fwrite($f,$blob);
436
-      fclose($f);
437
-      $returnarray[]= ['name'=>$f_name,'mime'=>$ext];
438
-      $i++;
428
+        debug(4,"saveLogoFile: $mime : $ext\n");
429
+        $f_name = 'logo-'.$i.'.'.$ext;
430
+        $f = fopen($f_name,"w");
431
+        if(! $f) {
432
+            debug(2,"saveLogoFile failed for: $f_name\n");
433
+            die("problem opening the file\n");
434
+        }
435
+        fwrite($f,$blob);
436
+        fclose($f);
437
+        $returnarray[]= ['name'=>$f_name,'mime'=>$ext];
438
+        $i++;
439 439
     }
440 440
     return($returnarray);
441
-  }
441
+    }
442 442
 
443 443
 
444
-  private function saveInfoFile($blob) {
444
+    private function saveInfoFile($blob) {
445 445
     $finfo = new finfo(FILEINFO_MIME_TYPE);
446 446
     $mime = $finfo->buffer($blob);
447 447
     $ext = isset($this->mime_extensions[$mime]) ? $this->mime_extensions[$mime] : 'usupported';
@@ -451,43 +451,43 @@  discard block
 block discarded – undo
451 451
     fwrite($f,$blob);
452 452
     fclose($f);
453 453
     return(['name'=>'local-info.'.$ext,'mime'=>$ext]);
454
-  }
455
-
456
-  private function getProfileAttributes(Profile $profile) {
457
-     $eaps = $profile->getEapMethodsinOrderOfPreference(1);
458
-     if($eap = $this->getPreferredEapType($eaps)) {
459
-          $a = $profile->getCollapsedAttributes($eap);
460
-          $a['eap'] = $eap;
461
-          $a['all_eaps'] = $eaps;
462
-          return($a);
463
-     } else {
464
-       error("No supported eap types found for this profile.");
465
-       return(FALSE);
466
-  }
467
-  }
454
+    }
455
+
456
+    private function getProfileAttributes(Profile $profile) {
457
+        $eaps = $profile->getEapMethodsinOrderOfPreference(1);
458
+        if($eap = $this->getPreferredEapType($eaps)) {
459
+            $a = $profile->getCollapsedAttributes($eap);
460
+            $a['eap'] = $eap;
461
+            $a['all_eaps'] = $eaps;
462
+            return($a);
463
+        } else {
464
+        error("No supported eap types found for this profile.");
465
+        return(FALSE);
466
+    }
467
+    }
468 468
 /**
469
-  * dumps attributes for debugging purposes
470
-  *
471
-  * dumpAttibutes method is supplied for debuging purposes, it simply dumps the attribute array
472
-  * to a file with name passed in the attribute.
473
-  * @param string $file the output file name
474
-  */
475
-  protected function dumpAttibutes($file) {
469
+     * dumps attributes for debugging purposes
470
+     *
471
+     * dumpAttibutes method is supplied for debuging purposes, it simply dumps the attribute array
472
+     * to a file with name passed in the attribute.
473
+     * @param string $file the output file name
474
+     */
475
+    protected function dumpAttibutes($file) {
476 476
         ob_start();
477 477
         print_r($this->attributes);
478 478
         $output = ob_get_clean();
479 479
         $f = fopen($file,"w");
480 480
         fwrite($f,$output);
481 481
         fclose($f);
482
-  }
482
+    }
483 483
 /** 
484
- * placeholder for the main device method
485
- *
486
- */
484
+     * placeholder for the main device method
485
+     *
486
+     */
487 487
 
488
-  protected function writeInstaller() {
489
-     return("download path");
490
-  }
488
+    protected function writeInstaller() {
489
+        return("download path");
490
+    }
491 491
 
492 492
 /**
493 493
  * Array passing all options to the device module.
@@ -521,76 +521,76 @@  discard block
 block discarded – undo
521 521
  * @see X509::processCertificate()
522 522
  * @var array $attributes
523 523
  */
524
-  public $attributes;
524
+    public $attributes;
525 525
 /**
526
-  * stores the path to the module source location and is used 
527
-  * by copyFile and translateFile
528
-  * the only reason for it to be a public variable ies that it is set by the DeviceFactory class
529
-  * module_path should not be used by module drivers.
530
-  * @var string 
531
-  */
532
-  public $module_path;
526
+     * stores the path to the module source location and is used 
527
+     * by copyFile and translateFile
528
+     * the only reason for it to be a public variable ies that it is set by the DeviceFactory class
529
+     * module_path should not be used by module drivers.
530
+     * @var string 
531
+     */
532
+    public $module_path;
533 533
 
534 534
 /**
535 535
  * The optimal EAP type
536 536
  *
537 537
  */ 
538 538
 /**
539
-  * optimal EAP method selected given profile and device
540
-  * @var EAP::constant
541
-  */
542
-  public $selected_eap;
539
+ * optimal EAP method selected given profile and device
540
+ * @var EAP::constant
541
+ */
542
+    public $selected_eap;
543 543
 /**
544
-  * the path to the profile signing program
545
-  * device modules which require signing should use this property to exec the signer
546
-  * the signer program must accept two arguments - input and output file names
547
-  * the signer program mus operate in the local directory and filenames are relative to this
548
-  * directory
549
-  *
550
-  *@var string
551
-  */
552
-  public $sign;
553
-  public $signer;
544
+     * the path to the profile signing program
545
+     * device modules which require signing should use this property to exec the signer
546
+     * the signer program must accept two arguments - input and output file names
547
+     * the signer program mus operate in the local directory and filenames are relative to this
548
+     * directory
549
+     *
550
+     *@var string
551
+     */
552
+    public $sign;
553
+    public $signer;
554 554
 /**
555
- * the string referencing the language (index ot the Config::$LANGUAGES array).
556
- * It is set to the current language and may be used by the device module to
557
- * set its language
558
- *
559
- *@var string
560
- */
561
-  public $lang_index;
562
-  /**
563
-   * The string identifier of the device (don't show this to users)
564
-   * @var string
565
-   */
566
-  public $device_id;
567
-
568
-  /**
569
-   * See devices-template.php for a list of available options
570
-   * @var array
571
-   */
572
-  public $options;
573
-
574
-  /**
575
-   * This string will be shown if no support email was configured by the admin
576
-   * 
577
-   * @var string 
578
-   */
579
-  public static $support_email_substitute;
580
-
581
-  /**
582
-   * This string will be shown if no support URL was configured by the admin
583
-   * 
584
-   * @var string 
585
-   */
586
-  public static $support_url_substitute;
587
-
588
-  /**
589
-   * This string should be used by all installer modules to set the 
590
-   * installer file basename.
591
-   *
592
-   * @var string 
593
-   */
594
-  public static $installerBasename;
555
+     * the string referencing the language (index ot the Config::$LANGUAGES array).
556
+     * It is set to the current language and may be used by the device module to
557
+     * set its language
558
+     *
559
+     *@var string
560
+     */
561
+    public $lang_index;
562
+    /**
563
+     * The string identifier of the device (don't show this to users)
564
+     * @var string
565
+     */
566
+    public $device_id;
567
+
568
+    /**
569
+     * See devices-template.php for a list of available options
570
+     * @var array
571
+     */
572
+    public $options;
573
+
574
+    /**
575
+     * This string will be shown if no support email was configured by the admin
576
+     * 
577
+     * @var string 
578
+     */
579
+    public static $support_email_substitute;
580
+
581
+    /**
582
+     * This string will be shown if no support URL was configured by the admin
583
+     * 
584
+     * @var string 
585
+     */
586
+    public static $support_url_substitute;
587
+
588
+    /**
589
+     * This string should be used by all installer modules to set the 
590
+     * installer file basename.
591
+     *
592
+     * @var string 
593
+     */
594
+    public static $installerBasename;
595 595
 }
596 596
 ?>
Please login to merge, or discard this patch.
Spacing   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -63,9 +63,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
295 295
    * root is set to 1 for the CA roor certicicate and 0 otherwise
296 296
   */ 
297 297
    final protected function saveCertificateFiles($format) {
298
-     if($format == 'der' || $format == 'pam') {
298
+     if ($format == 'der' || $format == 'pam') {
299 299
        $i = 0;
300 300
        $CA_files = [];
301 301
        $ca_array = $this->attributes['internal:CAs'][0];
302
-       if(! $ca_array)
302
+       if (!$ca_array)
303 303
          return(FALSE);
304 304
        foreach ($ca_array as $CA) {
305
-         $f = fopen("cert-$i.crt","w");
306
-         if(! $f) die("problem opening the file\n");
307
-         if($format == "pem")
308
-            fwrite($f,$CA['pem']);
305
+         $f = fopen("cert-$i.crt", "w");
306
+         if (!$f) die("problem opening the file\n");
307
+         if ($format == "pem")
308
+            fwrite($f, $CA['pem']);
309 309
          else
310
-            fwrite($f,$CA['der']);
310
+            fwrite($f, $CA['der']);
311 311
          fclose($f);
312 312
          $C = [];
313 313
          $C['file'] = "cert-$i.crt";
@@ -334,42 +334,42 @@  discard block
 block discarded – undo
334 334
     */
335 335
    private function getInstallerBasename() {
336 336
       $replace_pattern = '/[ ()\/\'"]+/';
337
-      debug(4,"getInstallerBasename1:".$this->attributes['general:instname'][0]."\n");
337
+      debug(4, "getInstallerBasename1:" . $this->attributes['general:instname'][0] . "\n");
338 338
       $inst = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', $this->attributes['general:instname'][0]));
339
-      debug(4,"getInstallerBasename2:$inst\n");
340
-      $Inst_a = explode('_',$inst);
341
-      if(count($Inst_a) > 2) {
339
+      debug(4, "getInstallerBasename2:$inst\n");
340
+      $Inst_a = explode('_', $inst);
341
+      if (count($Inst_a) > 2) {
342 342
          $inst = '';
343
-         foreach($Inst_a as $i)
343
+         foreach ($Inst_a as $i)
344 344
            $inst .= $i[0];
345 345
       }   
346 346
       $c_name = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', Config::$CONSORTIUM['name']));
347
-      if($this->attributes['internal:profile_count'][0] > 1) {
348
-         if(!empty($this->attributes['profile:name']) && ! empty($this->attributes['profile:name'][0])) {
347
+      if ($this->attributes['internal:profile_count'][0] > 1) {
348
+         if (!empty($this->attributes['profile:name']) && !empty($this->attributes['profile:name'][0])) {
349 349
              $prof = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', $this->attributes['profile:name'][0]));
350
-             $prof = preg_replace('/_+$/','',$prof);
351
-             return $c_name. '-'. $this->getDeviceId() . $inst .'-'. $prof;
350
+             $prof = preg_replace('/_+$/', '', $prof);
351
+             return $c_name . '-' . $this->getDeviceId() . $inst . '-' . $prof;
352 352
          }
353 353
       }
354
-      return $c_name. '-'. $this->getDeviceId() . $inst;
354
+      return $c_name . '-' . $this->getDeviceId() . $inst;
355 355
   }
356 356
 
357 357
   private function getDeviceId() {
358 358
     $d_id = $this->device_id;
359
-    if(isset($this->options['device_id'])) 
359
+    if (isset($this->options['device_id'])) 
360 360
       $d_id = $this->options['device_id'];
361
-    if($d_id !== '')
361
+    if ($d_id !== '')
362 362
       $d_id .= '-';
363 363
     return $d_id;
364 364
   }
365 365
 
366 366
 
367 367
   private function getSSIDs() {
368
-    $S['add']=[];
369
-    $S['del']=[];
368
+    $S['add'] = [];
369
+    $S['del'] = [];
370 370
     if (isset(Config::$CONSORTIUM['ssid'])) {
371 371
        foreach (Config::$CONSORTIUM['ssid'] as $ssid) {
372
-        if(isset(Config::$CONSORTIUM['tkipsupport']) && Config::$CONSORTIUM['tkipsupport'] == TRUE)
372
+        if (isset(Config::$CONSORTIUM['tkipsupport']) && Config::$CONSORTIUM['tkipsupport'] == TRUE)
373 373
           $S['add'][$ssid] = 'TKIP';
374 374
         else {
375 375
           $S['add'][$ssid] = 'AES';
@@ -377,20 +377,20 @@  discard block
 block discarded – undo
377 377
         }
378 378
        }
379 379
     }
380
-    if(isset($this->attributes['media:SSID'])) {
380
+    if (isset($this->attributes['media:SSID'])) {
381 381
       $SSID = $this->attributes['media:SSID'];
382 382
 
383
-      foreach($SSID as $ssid)
383
+      foreach ($SSID as $ssid)
384 384
          $S['add'][$ssid] = 'AES';
385 385
       }
386
-    if(isset($this->attributes['media:SSID_with_legacy'])) {
386
+    if (isset($this->attributes['media:SSID_with_legacy'])) {
387 387
       $SSID = $this->attributes['media:SSID_with_legacy'];
388
-      foreach($SSID as $ssid)
388
+      foreach ($SSID as $ssid)
389 389
          $S['add'][$ssid] = 'TKIP';
390 390
     }
391
-    if(isset($this->attributes['media:remove_SSID'])) {
391
+    if (isset($this->attributes['media:remove_SSID'])) {
392 392
       $SSID = $this->attributes['media:remove_SSID'];
393
-      foreach($SSID as $ssid)
393
+      foreach ($SSID as $ssid)
394 394
          $S['del'][$ssid] = 'DEL';
395 395
     }
396 396
     return $S;
@@ -416,25 +416,25 @@  discard block
 block discarded – undo
416 416
   ];
417 417
 
418 418
   private function saveLogoFile($Logos) {
419
-    $i=0;
420
-    $returnarray= [];
419
+    $i = 0;
420
+    $returnarray = [];
421 421
     foreach ($Logos as $blob) {
422 422
       $finfo = new finfo(FILEINFO_MIME_TYPE);
423 423
       $mime = $finfo->buffer($blob);
424
-      if(preg_match('/^image\/(.*)/',$mime,$m))
424
+      if (preg_match('/^image\/(.*)/', $mime, $m))
425 425
         $ext = $m[1];
426 426
       else
427 427
         $ext = 'unsupported';
428
-      debug(4,"saveLogoFile: $mime : $ext\n");
429
-      $f_name = 'logo-'.$i.'.'.$ext;
430
-      $f = fopen($f_name,"w");
431
-      if(! $f) {
432
-          debug(2,"saveLogoFile failed for: $f_name\n");
428
+      debug(4, "saveLogoFile: $mime : $ext\n");
429
+      $f_name = 'logo-' . $i . '.' . $ext;
430
+      $f = fopen($f_name, "w");
431
+      if (!$f) {
432
+          debug(2, "saveLogoFile failed for: $f_name\n");
433 433
           die("problem opening the file\n");
434 434
       }
435
-      fwrite($f,$blob);
435
+      fwrite($f, $blob);
436 436
       fclose($f);
437
-      $returnarray[]= ['name'=>$f_name,'mime'=>$ext];
437
+      $returnarray[] = ['name'=>$f_name, 'mime'=>$ext];
438 438
       $i++;
439 439
     }
440 440
     return($returnarray);
@@ -445,17 +445,17 @@  discard block
 block discarded – undo
445 445
     $finfo = new finfo(FILEINFO_MIME_TYPE);
446 446
     $mime = $finfo->buffer($blob);
447 447
     $ext = isset($this->mime_extensions[$mime]) ? $this->mime_extensions[$mime] : 'usupported';
448
-    debug(4,"saveInfoFile: $mime : $ext\n");
449
-    $f = fopen('local-info.'.$ext,"w");
450
-    if(! $f) die("problem opening the file\n");
451
-    fwrite($f,$blob);
448
+    debug(4, "saveInfoFile: $mime : $ext\n");
449
+    $f = fopen('local-info.' . $ext, "w");
450
+    if (!$f) die("problem opening the file\n");
451
+    fwrite($f, $blob);
452 452
     fclose($f);
453
-    return(['name'=>'local-info.'.$ext,'mime'=>$ext]);
453
+    return(['name'=>'local-info.' . $ext, 'mime'=>$ext]);
454 454
   }
455 455
 
456 456
   private function getProfileAttributes(Profile $profile) {
457 457
      $eaps = $profile->getEapMethodsinOrderOfPreference(1);
458
-     if($eap = $this->getPreferredEapType($eaps)) {
458
+     if ($eap = $this->getPreferredEapType($eaps)) {
459 459
           $a = $profile->getCollapsedAttributes($eap);
460 460
           $a['eap'] = $eap;
461 461
           $a['all_eaps'] = $eaps;
@@ -476,8 +476,8 @@  discard block
 block discarded – undo
476 476
         ob_start();
477 477
         print_r($this->attributes);
478 478
         $output = ob_get_clean();
479
-        $f = fopen($file,"w");
480
-        fwrite($f,$output);
479
+        $f = fopen($file, "w");
480
+        fwrite($f, $output);
481 481
         fclose($f);
482 482
   }
483 483
 /** 
Please login to merge, or discard this patch.
Braces   +93 added lines, -66 removed lines patch added patch discarded remove patch
@@ -107,8 +107,9 @@  discard block
 block discarded – undo
107 107
        $CAs = [];
108 108
        if(isset($this->attributes['eap:ca_file'])) {
109 109
        foreach ($this->attributes['eap:ca_file'] as $ca) {
110
-          if($c = X509::processCertificate($ca))
111
-             $CAs[] = $c;
110
+          if($c = X509::processCertificate($ca)) {
111
+                       $CAs[] = $c;
112
+          }
112 113
           }
113 114
           $this->attributes['internal:CAs'][0]=$CAs;
114 115
        }
@@ -116,9 +117,10 @@  discard block
 block discarded – undo
116 117
           $this->attributes['internal:info_file'][0] = 
117 118
              $this->saveInfoFile($this->attributes['support:info_file'][0]);
118 119
        }
119
-       if(isset($this->attributes['general:logo_file']))
120
-          $this->attributes['internal:logo_file'] = 
120
+       if(isset($this->attributes['general:logo_file'])) {
121
+                 $this->attributes['internal:logo_file'] = 
121 122
              $this->saveLogoFile($this->attributes['general:logo_file']);
123
+       }
122 124
        $this->attributes['internal:SSID'] = $this->getSSIDs()['add'];;
123 125
        $this->attributes['internal:remove_SSID'] = $this->getSSIDs()['del'];;
124 126
        $this->attributes['internal:consortia'] = $this->getConsortia();
@@ -130,8 +132,9 @@  discard block
 block discarded – undo
130 132
        $this->support_url_substitute = sprintf(_("your local %s support page"),Config::$CONSORTIUM['name']);
131 133
        CAT::set_locale($olddomain);
132 134
 
133
-       if($this->signer && $this->options['sign'])
134
-         $this->sign = CAT::$root . '/signer/'. $this->signer;
135
+       if($this->signer && $this->options['sign']) {
136
+                $this->sign = CAT::$root . '/signer/'. $this->signer;
137
+       }
135 138
        $this->installerBasename = $this->getInstallerBasename();
136 139
     }
137 140
 
@@ -178,22 +181,24 @@  discard block
 block discarded – undo
178 181
     * @final not to be redefined
179 182
     */
180 183
    final protected function copyFile($source_name, $output_name = 0) {
181
-      if  ( $output_name === 0)
182
-        $output_name = $source_name;
184
+      if  ( $output_name === 0) {
185
+              $output_name = $source_name;
186
+      }
183 187
 
184 188
       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
-      else {
189
+      if(is_file($this->module_path.'/Files/'.$this->device_id.'/'.$source_name)) {
190
+               $source = $this->module_path.'/Files/'.$this->device_id.'/'.$source_name;
191
+      } elseif(is_file($this->module_path.'/Files/'.$source_name)) {
192
+               $source = $this->module_path.'/Files/'.$source_name;
193
+      } else {
190 194
         debug(2,"fileCopy:reqested file $source_name does not exist\n");
191 195
         return(FALSE);
192 196
       }
193 197
       debug(4,"Copying $source to $output_name\n");
194 198
       $result = copy($source,"$output_name");
195
-      if(! $result )
196
-        debug(2,"fileCopy($source_name, $output_name) failed\n");
199
+      if(! $result ) {
200
+              debug(2,"fileCopy($source_name, $output_name) failed\n");
201
+      }
197 202
       return($result); 
198 203
    }
199 204
 
@@ -223,28 +228,33 @@  discard block
 block discarded – undo
223 228
     */
224 229
 
225 230
    final protected function translateFile($source_name, $output_name = 0, $encoding = 0) {
226
-      if(Config::$NSIS_VERSION >= 3)
227
-        $encoding = 0;
228
-      if  ( $output_name === 0)
229
-        $output_name = $source_name;
231
+      if(Config::$NSIS_VERSION >= 3) {
232
+              $encoding = 0;
233
+      }
234
+      if  ( $output_name === 0) {
235
+              $output_name = $source_name;
236
+      }
230 237
 
231 238
       debug(4,"translateFile($source_name, $output_name, $encoding)\n");
232 239
       ob_start();
233 240
       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;
241
+      if(is_file($this->module_path.'/Files/'.$this->device_id.'/'.$source_name)) {
242
+               $source = $this->module_path.'/Files/'.$this->device_id.'/'.$source_name;
243
+      } elseif(is_file($this->module_path.'/Files/'.$source_name)) {
244
+               $source = $this->module_path.'/Files/'.$source_name;
245
+      }
238 246
       include($source);
239 247
       $output = ob_get_clean();
240 248
       if($encoding) {
241 249
         $output_c = iconv('UTF-8',$encoding.'//TRANSLIT',$output);
242
-        if($output_c)
243
-           $output = $output_c;
250
+        if($output_c) {
251
+                   $output = $output_c;
252
+        }
244 253
       }
245 254
       $f = fopen("$output_name","w");
246
-      if(! $f)
247
-         debug(2,"translateFile($source, $output_name, $encoding) failed\n");
255
+      if(! $f) {
256
+               debug(2,"translateFile($source, $output_name, $encoding) failed\n");
257
+      }
248 258
       fwrite($f,$output);
249 259
       fclose($f);
250 260
       debug(4,"translateFile($source, $output_name, $encoding) end\n");
@@ -269,16 +279,19 @@  discard block
 block discarded – undo
269 279
     */
270 280
 
271 281
    final protected function translateString($source_string,$encoding = 0) {
272
-      if(Config::$NSIS_VERSION >= 3)
273
-        $encoding = 0;
274
-      if($encoding)
275
-        $output_c = iconv('UTF-8',$encoding.'//TRANSLIT',$source_string);
276
-      else
277
-        $output_c = $source_string;
278
-      if($output_c) 
279
-         $source_string  = str_replace('"','$\\"',$output_c);
280
-      else
281
-         debug(2,"Failed to convert string $source_string\n");
282
+      if(Config::$NSIS_VERSION >= 3) {
283
+              $encoding = 0;
284
+      }
285
+      if($encoding) {
286
+              $output_c = iconv('UTF-8',$encoding.'//TRANSLIT',$source_string);
287
+      } else {
288
+              $output_c = $source_string;
289
+      }
290
+      if($output_c) {
291
+               $source_string  = str_replace('"','$\\"',$output_c);
292
+      } else {
293
+               debug(2,"Failed to convert string $source_string\n");
294
+      }
282 295
       return $source_string;
283 296
    }
284 297
 
@@ -299,15 +312,19 @@  discard block
 block discarded – undo
299 312
        $i = 0;
300 313
        $CA_files = [];
301 314
        $ca_array = $this->attributes['internal:CAs'][0];
302
-       if(! $ca_array)
303
-         return(FALSE);
315
+       if(! $ca_array) {
316
+                return(FALSE);
317
+       }
304 318
        foreach ($ca_array as $CA) {
305 319
          $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
-         else
310
-            fwrite($f,$CA['der']);
320
+         if(! $f) {
321
+             die("problem opening the file\n");
322
+         }
323
+         if($format == "pem") {
324
+                     fwrite($f,$CA['pem']);
325
+         } else {
326
+                     fwrite($f,$CA['der']);
327
+         }
311 328
          fclose($f);
312 329
          $C = [];
313 330
          $C['file'] = "cert-$i.crt";
@@ -340,8 +357,9 @@  discard block
 block discarded – undo
340 357
       $Inst_a = explode('_',$inst);
341 358
       if(count($Inst_a) > 2) {
342 359
          $inst = '';
343
-         foreach($Inst_a as $i)
344
-           $inst .= $i[0];
360
+         foreach($Inst_a as $i) {
361
+                    $inst .= $i[0];
362
+         }
345 363
       }   
346 364
       $c_name = iconv("UTF-8", "US-ASCII//TRANSLIT", preg_replace($replace_pattern, '_', Config::$CONSORTIUM['name']));
347 365
       if($this->attributes['internal:profile_count'][0] > 1) {
@@ -356,10 +374,12 @@  discard block
 block discarded – undo
356 374
 
357 375
   private function getDeviceId() {
358 376
     $d_id = $this->device_id;
359
-    if(isset($this->options['device_id'])) 
360
-      $d_id = $this->options['device_id'];
361
-    if($d_id !== '')
362
-      $d_id .= '-';
377
+    if(isset($this->options['device_id'])) {
378
+          $d_id = $this->options['device_id'];
379
+    }
380
+    if($d_id !== '') {
381
+          $d_id .= '-';
382
+    }
363 383
     return $d_id;
364 384
   }
365 385
 
@@ -369,9 +389,9 @@  discard block
 block discarded – undo
369 389
     $S['del']=[];
370 390
     if (isset(Config::$CONSORTIUM['ssid'])) {
371 391
        foreach (Config::$CONSORTIUM['ssid'] as $ssid) {
372
-        if(isset(Config::$CONSORTIUM['tkipsupport']) && Config::$CONSORTIUM['tkipsupport'] == TRUE)
373
-          $S['add'][$ssid] = 'TKIP';
374
-        else {
392
+        if(isset(Config::$CONSORTIUM['tkipsupport']) && Config::$CONSORTIUM['tkipsupport'] == TRUE) {
393
+                  $S['add'][$ssid] = 'TKIP';
394
+        } else {
375 395
           $S['add'][$ssid] = 'AES';
376 396
           $S['del'][$ssid] = 'TKIP';
377 397
         }
@@ -380,18 +400,21 @@  discard block
 block discarded – undo
380 400
     if(isset($this->attributes['media:SSID'])) {
381 401
       $SSID = $this->attributes['media:SSID'];
382 402
 
383
-      foreach($SSID as $ssid)
384
-         $S['add'][$ssid] = 'AES';
403
+      foreach($SSID as $ssid) {
404
+               $S['add'][$ssid] = 'AES';
405
+      }
385 406
       }
386 407
     if(isset($this->attributes['media:SSID_with_legacy'])) {
387 408
       $SSID = $this->attributes['media:SSID_with_legacy'];
388
-      foreach($SSID as $ssid)
389
-         $S['add'][$ssid] = 'TKIP';
409
+      foreach($SSID as $ssid) {
410
+               $S['add'][$ssid] = 'TKIP';
411
+      }
390 412
     }
391 413
     if(isset($this->attributes['media:remove_SSID'])) {
392 414
       $SSID = $this->attributes['media:remove_SSID'];
393
-      foreach($SSID as $ssid)
394
-         $S['del'][$ssid] = 'DEL';
415
+      foreach($SSID as $ssid) {
416
+               $S['del'][$ssid] = 'DEL';
417
+      }
395 418
     }
396 419
     return $S;
397 420
   }
@@ -399,9 +422,10 @@  discard block
 block discarded – undo
399 422
   private function getConsortia() {
400 423
       $OIs = [];
401 424
       $OIs = array_merge($OIs, Config::$CONSORTIUM['interworking-consortium-oi']);
402
-      if (isset($this->attributes['media:consortium_OI']))
403
-          foreach ($this->attributes['media:consortium_OI'] as $new_oi)
425
+      if (isset($this->attributes['media:consortium_OI'])) {
426
+                foreach ($this->attributes['media:consortium_OI'] as $new_oi)
404 427
             $OIs[] = $new_oi;
428
+      }
405 429
       return $OIs;
406 430
   }
407 431
   
@@ -421,10 +445,11 @@  discard block
 block discarded – undo
421 445
     foreach ($Logos as $blob) {
422 446
       $finfo = new finfo(FILEINFO_MIME_TYPE);
423 447
       $mime = $finfo->buffer($blob);
424
-      if(preg_match('/^image\/(.*)/',$mime,$m))
425
-        $ext = $m[1];
426
-      else
427
-        $ext = 'unsupported';
448
+      if(preg_match('/^image\/(.*)/',$mime,$m)) {
449
+              $ext = $m[1];
450
+      } else {
451
+              $ext = 'unsupported';
452
+      }
428 453
       debug(4,"saveLogoFile: $mime : $ext\n");
429 454
       $f_name = 'logo-'.$i.'.'.$ext;
430 455
       $f = fopen($f_name,"w");
@@ -447,7 +472,9 @@  discard block
 block discarded – undo
447 472
     $ext = isset($this->mime_extensions[$mime]) ? $this->mime_extensions[$mime] : 'usupported';
448 473
     debug(4,"saveInfoFile: $mime : $ext\n");
449 474
     $f = fopen('local-info.'.$ext,"w");
450
-    if(! $f) die("problem opening the file\n");
475
+    if(! $f) {
476
+        die("problem opening the file\n");
477
+    }
451 478
     fwrite($f,$blob);
452 479
     fclose($f);
453 480
     return(['name'=>'local-info.'.$ext,'mime'=>$ext]);
Please login to merge, or discard this patch.
core/Federation.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -661,7 +661,7 @@
 block discarded – undo
661 661
      * This function retrieves the federation attributes. If called with the optional parameter, only attribute values for the attribute
662 662
      * name in $option_name are retrieved; otherwise, all attributes are retrieved.
663 663
      *
664
-     * @param string $option_name optionally, the name of the attribute that is to be retrieved
664
+     * @param integer $option_name optionally, the name of the attribute that is to be retrieved
665 665
      * @return array of arrays of attributes which were set for this IdP
666 666
      */
667 667
     public function getAttributes($option_name = 0) {
Please login to merge, or discard this patch.
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -678,10 +678,10 @@
 block discarded – undo
678 678
     }
679 679
     
680 680
         /**
681
-     * deletes all attributes in this federation except the _file ones, these are reported as array
682
-     *
683
-     * @return array list of row id's of file-based attributes which weren't deleted
684
-     */
681
+         * deletes all attributes in this federation except the _file ones, these are reported as array
682
+         *
683
+         * @return array list of row id's of file-based attributes which weren't deleted
684
+         */
685 685
     public function beginFlushAttributes() {
686 686
         DBConnection::exec(Federation::$DB_TYPE, "DELETE FROM federation_option WHERE federation_id = '$this->identifier' AND option_name NOT LIKE '%_file'");
687 687
         $exec_q = DBConnection::exec(Federation::$DB_TYPE, "SELECT row FROM federation_option WHERE federation_id = '$this->identifier'");
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
         
75 75
         $retstring = "";
76 76
         if (!$astablerows)
77
-            $retstring .= "<federation id='" . ( $federationid == NULL ? "ALL" : $federationid ) . "' ts='$timestamp'>\n";
77
+            $retstring .= "<federation id='" . ($federationid == NULL ? "ALL" : $federationid) . "' ts='$timestamp'>\n";
78 78
 
79 79
         foreach (Devices::listDevices() as $index => $device_array) {
80 80
             $query = "SELECT SUM(downloads_admin) AS admin, SUM(downloads_user) AS user FROM downloads, profile, institution WHERE device_id = '$index' AND downloads.profile_id = profile.profile_id AND profile.inst_id = institution.inst_id ";
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
                 if ($astablerows)
88 88
                     $retstring .= "<td>" . $device_array['display'] . "</td>";
89 89
                 $retstring .= ($astablerows ? "<td>" : "    <downloads group='admin'>");
90
-                $retstring .= ( $a->admin === NULL ? "0" : $a->admin);
90
+                $retstring .= ($a->admin === NULL ? "0" : $a->admin);
91 91
                 $retstring .= ($astablerows ? "</td><td>" : "</downloads>\n    <downloads group='user'>");
92
-                $retstring .= ( $a->user === NULL ? "0" : $a->user);
92
+                $retstring .= ($a->user === NULL ? "0" : $a->user);
93 93
                 $retstring .= ($astablerows ? "</td>" : "</downloads>\n");
94 94
                 $gross_admin = $gross_admin + $a->admin;
95 95
                 $gross_user = $gross_user + $a->user;
Please login to merge, or discard this patch.
Braces   +79 added lines, -55 removed lines patch added patch discarded remove patch
@@ -73,8 +73,9 @@  discard block
 block discarded – undo
73 73
         $timestamp = date("Y-m-d") . "T" . date("H:i:s");
74 74
         
75 75
         $retstring = "";
76
-        if (!$astablerows)
77
-            $retstring .= "<federation id='" . ( $federationid == NULL ? "ALL" : $federationid ) . "' ts='$timestamp'>\n";
76
+        if (!$astablerows) {
77
+                    $retstring .= "<federation id='" . ( $federationid == NULL ? "ALL" : $federationid ) . "' ts='$timestamp'>\n";
78
+        }
78 79
 
79 80
         foreach (Devices::listDevices() as $index => $device_array) {
80 81
             $query = "SELECT SUM(downloads_admin) AS admin, SUM(downloads_user) AS user FROM downloads, profile, institution WHERE device_id = '$index' AND downloads.profile_id = profile.profile_id AND profile.inst_id = institution.inst_id ";
@@ -84,8 +85,9 @@  discard block
 block discarded – undo
84 85
             $retstring .= ($astablerows ? "<tr>" : "  <device name='" . $device_array['display'] . "'>\n");
85 86
             $admin_query = DBConnection::exec("INST", $query);
86 87
             while ($a = mysqli_fetch_object($admin_query)) {
87
-                if ($astablerows)
88
-                    $retstring .= "<td>" . $device_array['display'] . "</td>";
88
+                if ($astablerows) {
89
+                                    $retstring .= "<td>" . $device_array['display'] . "</td>";
90
+                }
89 91
                 $retstring .= ($astablerows ? "<td>" : "    <downloads group='admin'>");
90 92
                 $retstring .= ( $a->admin === NULL ? "0" : $a->admin);
91 93
                 $retstring .= ($astablerows ? "</td><td>" : "</downloads>\n    <downloads group='user'>");
@@ -97,16 +99,18 @@  discard block
 block discarded – undo
97 99
             $retstring .= ($astablerows ? "</tr>" : "  </device>\n");
98 100
         }
99 101
         $retstring .= ($astablerows ? "<tr>" : "  <total>\n");
100
-        if ($astablerows)
101
-            $retstring .= "<td><strong>TOTAL</ts>";
102
+        if ($astablerows) {
103
+                    $retstring .= "<td><strong>TOTAL</ts>";
104
+        }
102 105
         $retstring .= ($astablerows ? "<td><strong>" : "    <downloads group='admin'>");
103 106
         $retstring .= $gross_admin;
104 107
         $retstring .= ($astablerows ? "</strong></td><td><strong>" : "</downloads>\n    <downloads group='user'>");
105 108
         $retstring .= $gross_user;
106 109
         $retstring .= ($astablerows ? "</strong></td>" : "</downloads>\n");
107 110
         $retstring .= ($astablerows ? "</tr>" : "  </total>\n");
108
-        if (!$astablerows)
109
-            $retstring .= "</federation>\n";
111
+        if (!$astablerows) {
112
+                    $retstring .= "</federation>\n";
113
+        }
110 114
 
111 115
         return $retstring;
112 116
     }
@@ -437,8 +441,9 @@  discard block
 block discarded – undo
437 441
         $level = DBConnection::escape_value(Federation::$DB_TYPE, $level);
438 442
         $mail = DBConnection::escape_value(Federation::$DB_TYPE, $mail);
439 443
 
440
-        if ($owner_id != "PENDING")
441
-            DBConnection::exec(Federation::$DB_TYPE, "INSERT INTO ownership (user_id,institution_id, blesslevel, orig_mail) VALUES('$owner_id', $identifier, '$level', '$mail')");
444
+        if ($owner_id != "PENDING") {
445
+                    DBConnection::exec(Federation::$DB_TYPE, "INSERT INTO ownership (user_id,institution_id, blesslevel, orig_mail) VALUES('$owner_id', $identifier, '$level', '$mail')");
446
+        }
442 447
         return $identifier;
443 448
     }
444 449
 
@@ -485,13 +490,16 @@  discard block
 block discarded – undo
485 490
 
486 491
     public function listFederationAdmins() {
487 492
         $returnarray = [];
488
-        if (Config::$CONSORTIUM['name'] == "eduroam" && isset(Config::$CONSORTIUM['deployment-voodoo']) && Config::$CONSORTIUM['deployment-voodoo'] == "Operations Team") // SW: APPROVED
493
+        if (Config::$CONSORTIUM['name'] == "eduroam" && isset(Config::$CONSORTIUM['deployment-voodoo']) && Config::$CONSORTIUM['deployment-voodoo'] == "Operations Team") {
494
+            // SW: APPROVED
489 495
             $admins = DBConnection::exec("USER", "SELECT eptid as user_id FROM view_admin WHERE role = 'fedadmin' AND realm = '" . strtolower($this->identifier) . "'");
490
-        else
491
-            $admins = DBConnection::exec("USER", "SELECT user_id FROM user_options WHERE option_name = 'user:fedadmin' AND option_value = '" . strtoupper($this->identifier) . "'");
496
+        } else {
497
+                    $admins = DBConnection::exec("USER", "SELECT user_id FROM user_options WHERE option_name = 'user:fedadmin' AND option_value = '" . strtoupper($this->identifier) . "'");
498
+        }
492 499
 
493
-        while ($a = mysqli_fetch_object($admins))
494
-            $returnarray[] = $a->user_id;
500
+        while ($a = mysqli_fetch_object($admins)) {
501
+                    $returnarray[] = $a->user_id;
502
+        }
495 503
         return $returnarray;
496 504
     }
497 505
 
@@ -499,10 +507,11 @@  discard block
 block discarded – undo
499 507
         $returnarray = [];
500 508
         $countrysuffix = "";
501 509
         
502
-        if ($this->identifier != "")
503
-            $countrysuffix = " WHERE country = '" . strtolower($this->identifier) . "'";
504
-        else
505
-            $countrysuffix = "";
510
+        if ($this->identifier != "") {
511
+                    $countrysuffix = " WHERE country = '" . strtolower($this->identifier) . "'";
512
+        } else {
513
+                    $countrysuffix = "";
514
+        }
506 515
         
507 516
         if (Config::$CONSORTIUM['name'] == "eduroam" && isset(Config::$CONSORTIUM['deployment-voodoo']) && Config::$CONSORTIUM['deployment-voodoo'] == "Operations Team") { // SW: APPROVED
508 517
             $usedarray = [];
@@ -515,15 +524,18 @@  discard block
 block discarded – undo
515 524
                                                                                                       WHERE external_db_uniquehandle IS NOT NULL 
516 525
                                                                                                       AND invite_created >= TIMESTAMPADD(DAY, -1, NOW()) 
517 526
                                                                                                       AND used = 0");
518
-            while ($a = mysqli_fetch_object($already_used))
519
-                $usedarray[] = $a->external_db_id;
520
-            while ($a = mysqli_fetch_object($pending_invite))
521
-                if (!in_array($a->external_db_uniquehandle, $usedarray))
527
+            while ($a = mysqli_fetch_object($already_used)) {
528
+                            $usedarray[] = $a->external_db_id;
529
+            }
530
+            while ($a = mysqli_fetch_object($pending_invite)) {
531
+                            if (!in_array($a->external_db_uniquehandle, $usedarray))
522 532
                     $usedarray[] = $a->external_db_uniquehandle;
533
+            }
523 534
             while ($a = mysqli_fetch_object($externals)) {
524 535
                 if ($unmapped_only === TRUE) {
525
-                    if (in_array($a->id, $usedarray))
526
-                        continue;
536
+                    if (in_array($a->id, $usedarray)) {
537
+                                            continue;
538
+                    }
527 539
                 }
528 540
                 $names = explode('#', $a->collapsed_name);
529 541
                 // trim name list to current best language match
@@ -547,8 +559,9 @@  discard block
 block discarded – undo
547 559
                     $matches = [];
548 560
                     preg_match("/^n: (.*), e: (.*), p: .*$/", $contact, $matches);
549 561
                     if ($matches[2] != "") {
550
-                        if ($mailnames != "")
551
-                            $mailnames .= ", ";
562
+                        if ($mailnames != "") {
563
+                                                    $mailnames .= ", ";
564
+                        }
552 565
                         // extracting real names is nice, but the <> notation
553 566
                         // really gets screwed up on POSTs and HTML safety
554 567
                         // so better not do this; use only mail addresses
@@ -567,10 +580,11 @@  discard block
 block discarded – undo
567 580
     public static function getExternalDBEntityDetails($external_id, $realm = NULL) {
568 581
         $list = [];
569 582
         if (Config::$CONSORTIUM['name'] == "eduroam" && isset(Config::$CONSORTIUM['deployment-voodoo']) && Config::$CONSORTIUM['deployment-voodoo'] == "Operations Team") { // SW: APPROVED
570
-            if ($realm !== NULL)
571
-                $scanforrealm = "OR inst_realm LIKE '%$realm%'";
572
-            else
573
-                $scanforrealm = "";
583
+            if ($realm !== NULL) {
584
+                            $scanforrealm = "OR inst_realm LIKE '%$realm%'";
585
+            } else {
586
+                            $scanforrealm = "";
587
+            }
574 588
             $info_list = DBConnection::exec("EXTERNAL", "SELECT name AS collapsed_name, inst_realm as realmlist, contact AS collapsed_contact, country FROM view_active_idp_institution WHERE id_institution = $external_id $scanforrealm");
575 589
             // split names and contacts into proper pairs
576 590
             while ($a = mysqli_fetch_object($info_list)) {
@@ -604,14 +618,16 @@  discard block
 block discarded – undo
604 618
         $query = "SELECT distinct institution.inst_id AS inst_id, institution.country AS country,
605 619
                      group_concat(concat_ws('===',institution_option.option_name,LEFT(institution_option.option_value,200)) separator '---') AS options
606 620
                      FROM institution ";
607
-        if ($active_only == 1)
608
-            $query .= "JOIN profile ON institution.inst_id = profile.inst_id ";
621
+        if ($active_only == 1) {
622
+                    $query .= "JOIN profile ON institution.inst_id = profile.inst_id ";
623
+        }
609 624
         $query .= "JOIN institution_option ON institution.inst_id = institution_option.institution_id ";
610 625
         $query .= "WHERE (institution_option.option_name = 'general:instname' 
611 626
                           OR institution_option.option_name = 'general:geo_coordinates'
612 627
                           OR institution_option.option_name = 'general:logo_file') ";
613
-        if ($active_only == 1)
614
-            $query .= "AND profile.showtime = 1 ";
628
+        if ($active_only == 1) {
629
+                    $query .= "AND profile.showtime = 1 ";
630
+        }
615 631
 
616 632
         if ($country) {
617 633
             // escape the parameter
@@ -624,34 +640,41 @@  discard block
 block discarded – undo
624 640
         while ($a = mysqli_fetch_object($allIDPs)) {
625 641
             $O = explode('---', $a->options);
626 642
             $A = [];
627
-            if (isset($geo))
628
-                unset($geo);
629
-            if (isset($names))
630
-                unset($names);
643
+            if (isset($geo)) {
644
+                            unset($geo);
645
+            }
646
+            if (isset($names)) {
647
+                            unset($names);
648
+            }
631 649
             $A['entityID'] = $a->inst_id;
632 650
             $A['country'] = strtoupper($a->country);
633 651
             foreach ($O as $o) {
634 652
                 $opt = explode('===', $o);
635
-                if ($opt[0] == 'general:logo_file')
636
-                    $A['icon'] = $a->inst_id;
653
+                if ($opt[0] == 'general:logo_file') {
654
+                                    $A['icon'] = $a->inst_id;
655
+                }
637 656
                 if ($opt[0] == 'general:geo_coordinates') {
638 657
                     $at1 = unserialize($opt[1]);
639
-                    if (!isset($geo))
640
-                        $geo = [];
658
+                    if (!isset($geo)) {
659
+                                            $geo = [];
660
+                    }
641 661
                     $geo[] = $at1;
642 662
                 }
643 663
                 if ($opt[0] == 'general:instname') {
644
-                    if (!isset($names))
645
-                        $names = [];
664
+                    if (!isset($names)) {
665
+                                            $names = [];
666
+                    }
646 667
                     $names[] = ['value' => $opt[1]];
647 668
                 }
648 669
             }
649 670
             $name = getLocalisedValue($names, CAT::get_lang());
650
-            if (!$name)
651
-                continue;
671
+            if (!$name) {
672
+                            continue;
673
+            }
652 674
             $A['title'] = $name;
653
-            if (isset($geo))
654
-                $A['geo'] = $geo;
675
+            if (isset($geo)) {
676
+                            $A['geo'] = $geo;
677
+            }
655 678
             $returnarray[] = $A;
656 679
         }
657 680
         return $returnarray;
@@ -667,12 +690,12 @@  discard block
 block discarded – undo
667 690
     public function getAttributes($option_name = 0) {
668 691
         if ($option_name) {
669 692
             $returnarray = Array();
670
-            foreach ($this->priv_attributes as $the_attr)
671
-                if ($the_attr['name'] == $option_name)
693
+            foreach ($this->priv_attributes as $the_attr) {
694
+                            if ($the_attr['name'] == $option_name)
672 695
                     $returnarray[] = $the_attr;
696
+            }
673 697
             return $returnarray;
674
-        }
675
-        else {
698
+        } else {
676 699
             return $this->priv_attributes;
677 700
         }
678 701
     }
@@ -686,8 +709,9 @@  discard block
 block discarded – undo
686 709
         DBConnection::exec(Federation::$DB_TYPE, "DELETE FROM federation_option WHERE federation_id = '$this->identifier' AND option_name NOT LIKE '%_file'");
687 710
         $exec_q = DBConnection::exec(Federation::$DB_TYPE, "SELECT row FROM federation_option WHERE federation_id = '$this->identifier'");
688 711
         $return_array = [];
689
-        while ($a = mysqli_fetch_object($exec_q))
690
-            $return_array[$a->row] = "KILLME";
712
+        while ($a = mysqli_fetch_object($exec_q)) {
713
+                    $return_array[$a->row] = "KILLME";
714
+        }
691 715
         return $return_array;
692 716
     }
693 717
 
Please login to merge, or discard this patch.
core/Helper.php 4 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -32,6 +32,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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) 
Please login to merge, or discard this patch.
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -180,32 +180,32 @@  discard block
 block discarded – undo
180 180
 function createTemporaryDirectory($purpose = 'installer',$fail = 1) {
181 181
         $name = md5(time().rand());
182 182
         switch($purpose) {
183
-           case 'installer':
183
+            case 'installer':
184 184
              $path = CAT::$root.'/var/installer_cache';
185
-             break;
186
-           case 'logo':
185
+                break;
186
+            case 'logo':
187 187
              $path = CAT::$root.'/web/downloads/logos';
188
-             break;
189
-           case 'test':
188
+                break;
189
+            case 'test':
190 190
              $path = CAT::$root.'/var/tmp';
191
-             break;
192
-           default:
191
+                break;
192
+            default:
193 193
              error("unable to create temporary directory for unknown purpose: $purpose\n");
194
-             exit;
194
+                exit;
195 195
         }
196 196
         $tmp_dir = $path .'/'. $name;
197 197
         debug(4,"temp dir: $purpose : $tmp_dir\n");
198 198
         if(! mkdir($tmp_dir,0700, true)) {
199
-          if($fail) {
200
-             error("unable to create temporary directory: $tmp_dir\n");
201
-             exit;
202
-          } else  {
199
+            if($fail) {
200
+                error("unable to create temporary directory: $tmp_dir\n");
201
+                exit;
202
+            } else  {
203 203
             debug(4, "Directory creation failed for $tmp_dir\n");
204 204
             return ['base'=>$path,'dir'=>'',$name=>''];
205
-          }
205
+            }
206 206
         } else
207
-         debug(4, "Directory created: $tmp_dir\n");
208
-     return ['base'=>$path,'dir'=>$tmp_dir,'name'=>$name];
207
+            debug(4, "Directory created: $tmp_dir\n");
208
+        return ['base'=>$path,'dir'=>$tmp_dir,'name'=>$name];
209 209
 }
210 210
 
211 211
 function png_inject_consortium_logo ($inputpngstring, $symbolsize = 12, $marginsymbols = 4) {
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
     $targetplacementy = $symbolsize * round(($sizeinput[1] / 2 - ($targetheight - $symbolsize) / 2)/$symbolsize);
237 237
     imagecopyresized($inputgd, $whiteimage, $targetplacementx-$symbolsize, $targetplacementy-$symbolsize, 0, 0, $targetwidth+2*$symbolsize, $targetheight+2*$symbolsize, $targetwidth+2*$symbolsize, $targetheight+2*$symbolsize);
238 238
     imagecopyresized($inputgd, $logogd,     $targetplacementx, $targetplacementy, 0, 0, $targetwidth   , $targetheight   , $sizelogo[0]   , $sizelogo[1]);
239
- // imagecopyresized($dst_image, $src_image, $dst_x,                               $dst_y,                                $src_x, $src_y, $dst_w,       $dst_h,        $src_w,       $src_h);
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);
242 242
     return ob_get_clean();
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -177,65 +177,65 @@
 block discarded – undo
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);
Please login to merge, or discard this patch.
Braces   +40 added lines, -30 removed lines patch added patch discarded remove patch
@@ -56,10 +56,11 @@  discard block
 block discarded – undo
56 56
 
57 57
 function rrmdir($dir) {
58 58
     foreach (glob($dir . '/*') as $file) {
59
-        if (is_dir($file))
60
-            rrmdir($file);
61
-        else
62
-            unlink($file);
59
+        if (is_dir($file)) {
60
+                    rrmdir($file);
61
+        } else {
62
+                    unlink($file);
63
+        }
63 64
     }
64 65
     rmdir($dir);
65 66
 }
@@ -73,36 +74,42 @@  discard block
 block discarded – undo
73 74
  */
74 75
 function calculateCommonHostSuffix(array $hosts) {
75 76
     // massage names. A trailing dot can be omitted
76
-    foreach ($hosts as $index => $host)
77
-        if (substr($host, -1) == '.') {
77
+    foreach ($hosts as $index => $host) {
78
+            if (substr($host, -1) == '.') {
78 79
             $hosts[$index] = substr($host, 0, -1);
80
+    }
79 81
             echo "Changed host to " . $hosts[$index] . "\n";
80 82
         }
81 83
     // easy :-)
82
-    if (count($hosts) == 1)
83
-        return $hosts[0];
84
+    if (count($hosts) == 1) {
85
+            return $hosts[0];
86
+    }
84 87
     // not so easy :-(
85 88
     else {
86 89
         // look for the last dot from the end; if the corresponding substring is
87 90
         // different, no common match!
88 91
         $explodednames = [];
89
-        foreach ($hosts as $host)
90
-            $explodednames[] = explode('.', $host);
92
+        foreach ($hosts as $host) {
93
+                    $explodednames[] = explode('.', $host);
94
+        }
91 95
         $commonsuffix = [];
92 96
         while (count($explodednames[0]) > 0) {
93 97
             $match = TRUE;
94 98
             $testname = array_pop($explodednames[0]);
95 99
             for ($i = 1; $i < count($explodednames); $i = $i + 1) {
96
-                if (count($explodednames[$i]) == 0)
97
-                    $match = FALSE;
100
+                if (count($explodednames[$i]) == 0) {
101
+                                    $match = FALSE;
102
+                }
98 103
                 $bla = array_pop($explodednames[$i]);
99
-                if ($bla != $testname)
100
-                    $match = FALSE;
104
+                if ($bla != $testname) {
105
+                                    $match = FALSE;
106
+                }
107
+            }
108
+            if ($match == TRUE) {
109
+                            $commonsuffix[] = $testname;
110
+            } else {
111
+                            break;
101 112
             }
102
-            if ($match == TRUE)
103
-                $commonsuffix[] = $testname;
104
-            else
105
-                break;
106 113
         }
107 114
         $finalsuffix = array_reverse($commonsuffix);
108 115
         return implode('.', $finalsuffix);
@@ -133,10 +140,11 @@  discard block
 block discarded – undo
133 140
  * @return UUID (possibly prefixed)
134 141
  */
135 142
 function uuid($prefix = '', $deterministic_source = NULL) {
136
-    if ($deterministic_source === NULL) 
137
-        $chars = md5(uniqid(mt_rand(), true));
138
-    else
139
-        $chars = md5($deterministic_source);
143
+    if ($deterministic_source === NULL) {
144
+            $chars = md5(uniqid(mt_rand(), true));
145
+    } else {
146
+            $chars = md5($deterministic_source);
147
+    }
140 148
     $uuid = substr($chars, 0, 8) . '-';
141 149
     $uuid .= substr($chars, 8, 4) . '-';
142 150
     $uuid .= substr($chars, 12, 4) . '-';
@@ -159,12 +167,13 @@  discard block
 block discarded – undo
159 167
             $try = unserialize($val['value']);
160 168
             $r_val[$try['lang']] = $try['content'];
161 169
         }
162
-        if (isset($r_val[$locale]))
163
-            $out = $r_val[$locale];
164
-        elseif (isset($r_val['C']))
165
-            $out = $r_val['C'];
166
-        else
167
-            $out = 0;
170
+        if (isset($r_val[$locale])) {
171
+                    $out = $r_val[$locale];
172
+        } elseif (isset($r_val['C'])) {
173
+                    $out = $r_val['C'];
174
+        } else {
175
+                    $out = 0;
176
+        }
168 177
     } else {
169 178
         $out = 0;
170 179
     }
@@ -203,8 +212,9 @@  discard block
 block discarded – undo
203 212
             debug(4, "Directory creation failed for $tmp_dir\n");
204 213
             return ['base'=>$path,'dir'=>'',$name=>''];
205 214
           }
206
-        } else
207
-         debug(4, "Directory created: $tmp_dir\n");
215
+        } else {
216
+                 debug(4, "Directory created: $tmp_dir\n");
217
+        }
208 218
      return ['base'=>$path,'dir'=>$tmp_dir,'name'=>$name];
209 219
 }
210 220
 
Please login to merge, or discard this patch.
core/IdP.php 3 patches
Doc Comments   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -68,6 +68,7 @@  discard block
 block discarded – undo
68 68
      * Cannot be used to define a new IdP in the database! This happens via Federation::newIdP()
69 69
      *
70 70
      * @param integer $i_id the database row identifier
71
+     * @return string
71 72
      */
72 73
     public function __construct($i_id) {
73 74
         debug(3, "--- BEGIN Constructing new IdP object ... ---\n");
@@ -247,7 +248,7 @@  discard block
 block discarded – undo
247 248
      * This function retrieves the IdP-wide attributes. If called with the optional parameter, only attribute values for the attribute
248 249
      * name in $option_name are retrieved; otherwise, all attributes are retrieved.
249 250
      *
250
-     * @param string $option_name optionally, the name of the attribute that is to be retrieved
251
+     * @param integer $option_name optionally, the name of the attribute that is to be retrieved
251 252
      * @return array of arrays of attributes which were set for this IdP
252 253
      */
253 254
     public function getAttributes($option_name = 0) {
@@ -318,7 +319,7 @@  discard block
 block discarded – undo
318 319
      * Adds a new profile to this IdP.
319 320
      * Only creates the DB entry for the Profile. If you want to add attributes later, see Profile::addAttribute().
320 321
      *
321
-     * @return object new Profile object if successful, or FALSE if an error occured
322
+     * @return Profile|null new Profile object if successful, or FALSE if an error occured
322 323
      */
323 324
     public function newProfile() {
324 325
         DBConnection::exec(IdP::$DB_TYPE, "INSERT INTO profile (inst_id) VALUES($this->identifier)");
Please login to merge, or discard this patch.
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -118,10 +118,10 @@
 block discarded – undo
118 118
             }
119 119
         }
120 120
         $this->priv_attributes[] = ["name" => "internal:country", 
121
-                                         "value" => $this->federation, 
122
-                                         "level" => "IdP", 
123
-                                         "row" => 0, 
124
-                                         "flag" => NULL];
121
+                                            "value" => $this->federation, 
122
+                                            "level" => "IdP", 
123
+                                            "row" => 0, 
124
+                                            "flag" => NULL];
125 125
 
126 126
         $this->name = getLocalisedValue($this->getAttributes('general:instname', 0, 0), CAT::get_lang());
127 127
         debug(3, "--- END Constructing new IdP object ... ---\n");
Please login to merge, or discard this patch.
Braces   +72 added lines, -52 removed lines patch added patch discarded remove patch
@@ -136,8 +136,9 @@  discard block
 block discarded – undo
136 136
      */
137 137
     public function listProfiles($active_only = 0) {
138 138
         $query = "SELECT profile_id FROM profile WHERE inst_id = $this->identifier";
139
-        if ($active_only)
140
-            $query .= " AND showtime = 1";
139
+        if ($active_only) {
140
+                    $query .= " AND showtime = 1";
141
+        }
141 142
         $allProfiles = DBConnection::exec(IdP::$DB_TYPE, $query);
142 143
         $returnarray = [];
143 144
         while ($a = mysqli_fetch_object($allProfiles)) {
@@ -152,24 +153,27 @@  discard block
 block discarded – undo
152 153
         // migration phase: are there NULLs in the profile list sufficient_config column?
153 154
         // if so, run prepShowtime on all profiles
154 155
         $needTreatment = DBConnection::exec(IdP::$DB_TYPE, "SELECT profile_id FROM profile WHERE inst_id = $this->identifier AND sufficient_config IS NULL");
155
-        if (mysqli_num_rows($needTreatment) > 0)
156
-            foreach ($this->listProfiles() as $prof)
156
+        if (mysqli_num_rows($needTreatment) > 0) {
157
+                    foreach ($this->listProfiles() as $prof)
157 158
                 $prof->prepShowtime();
159
+        }
158 160
        
159 161
         // now, just look in the DB
160 162
         $allProfiles = DBConnection::exec(IdP::$DB_TYPE, "SELECT profile_id FROM profile WHERE inst_id = $this->identifier AND sufficient_config = 1");
161
-        if (mysqli_num_rows($allProfiles) > 0)
162
-            return TRUE;
163
-        else
164
-            return FALSE;
163
+        if (mysqli_num_rows($allProfiles) > 0) {
164
+                    return TRUE;
165
+        } else {
166
+                    return FALSE;
167
+        }
165 168
     }
166 169
 
167 170
     public function isOneProfileShowtime() {
168 171
         $allProfiles = DBConnection::exec(IdP::$DB_TYPE, "SELECT profile_id FROM profile WHERE inst_id = $this->identifier AND showtime = 1");
169
-        if (mysqli_num_rows($allProfiles) > 0)
170
-            return TRUE;
171
-        else
172
-            return FALSE;
172
+        if (mysqli_num_rows($allProfiles) > 0) {
173
+                    return TRUE;
174
+        } else {
175
+                    return FALSE;
176
+        }
173 177
         
174 178
     }
175 179
     
@@ -177,16 +181,21 @@  discard block
 block discarded – undo
177 181
         $allProfiles = DBConnection::exec(IdP::$DB_TYPE, "SELECT status_dns, status_cert, status_reachability, status_TLS, last_status_check FROM profile WHERE inst_id = $this->identifier AND sufficient_config = 1");
178 182
         $returnarray = ['dns' => RETVAL_SKIPPED, 'cert' => L_OK, 'reachability' => RETVAL_SKIPPED, 'TLS' => RETVAL_SKIPPED, 'checktime' => NULL];
179 183
         while ($a = mysqli_fetch_object($allProfiles)) {
180
-            if ($a->status_dns < $returnarray['dns'])
181
-                $returnarray['dns'] = $a->status_dns;
182
-            if ($a->status_reachability < $returnarray['reachability'])
183
-                $returnarray['reachability'] = $a->status_reachability;
184
-            if ($a->status_TLS < $returnarray['TLS'])
185
-                $returnarray['TLS'] = $a->status_TLS;
186
-            if ($a->status_cert < $returnarray['cert'])
187
-                $returnarray['cert'] = $a->status_cert;
188
-            if ($a->last_status_check > $returnarray['checktime'])
189
-                $returnarray['checktime'] = $a->last_status_check;
184
+            if ($a->status_dns < $returnarray['dns']) {
185
+                            $returnarray['dns'] = $a->status_dns;
186
+            }
187
+            if ($a->status_reachability < $returnarray['reachability']) {
188
+                            $returnarray['reachability'] = $a->status_reachability;
189
+            }
190
+            if ($a->status_TLS < $returnarray['TLS']) {
191
+                            $returnarray['TLS'] = $a->status_TLS;
192
+            }
193
+            if ($a->status_cert < $returnarray['cert']) {
194
+                            $returnarray['cert'] = $a->status_cert;
195
+            }
196
+            if ($a->last_status_check > $returnarray['checktime']) {
197
+                            $returnarray['checktime'] = $a->last_status_check;
198
+            }
190 199
         }
191 200
         return $returnarray;
192 201
     }
@@ -199,8 +208,9 @@  discard block
 block discarded – undo
199 208
     public function owner() {
200 209
         $returnarray = [];
201 210
         $admins = DBConnection::exec(IdP::$DB_TYPE, "SELECT user_id, orig_mail, blesslevel FROM ownership WHERE institution_id = $this->identifier ORDER BY user_id");
202
-        while ($a = mysqli_fetch_object($admins))
203
-            $returnarray[] = ['ID' => $a->user_id, 'MAIL' => $a->orig_mail, 'LEVEL' => $a->blesslevel];
211
+        while ($a = mysqli_fetch_object($admins)) {
212
+                    $returnarray[] = ['ID' => $a->user_id, 'MAIL' => $a->orig_mail, 'LEVEL' => $a->blesslevel];
213
+        }
204 214
         return $returnarray;
205 215
     }
206 216
 
@@ -253,12 +263,12 @@  discard block
 block discarded – undo
253 263
     public function getAttributes($option_name = 0) {
254 264
         if ($option_name) {
255 265
             $returnarray = [];
256
-            foreach ($this->priv_attributes as $the_attr)
257
-                if ($the_attr['name'] == $option_name)
266
+            foreach ($this->priv_attributes as $the_attr) {
267
+                            if ($the_attr['name'] == $option_name)
258 268
                     $returnarray[] = $the_attr;
269
+            }
259 270
             return $returnarray;
260
-        }
261
-        else {
271
+        } else {
262 272
             return $this->priv_attributes;
263 273
         }
264 274
     }
@@ -273,8 +283,9 @@  discard block
 block discarded – undo
273 283
         $this->updateFreshness();
274 284
         $exec_q = DBConnection::exec(IdP::$DB_TYPE, "SELECT row FROM institution_option WHERE institution_id = $this->identifier");
275 285
         $return_array = [];
276
-        while ($a = mysqli_fetch_object($exec_q))
277
-            $return_array[$a->row] = "KILLME";
286
+        while ($a = mysqli_fetch_object($exec_q)) {
287
+                    $return_array[$a->row] = "KILLME";
288
+        }
278 289
         return $return_array;
279 290
     }
280 291
 
@@ -324,10 +335,11 @@  discard block
 block discarded – undo
324 335
         DBConnection::exec(IdP::$DB_TYPE, "INSERT INTO profile (inst_id) VALUES($this->identifier)");
325 336
         $identifier = DBConnection::lastID(IdP::$DB_TYPE);
326 337
 
327
-        if ($identifier > 0)
328
-            return new Profile($identifier, $this);
329
-        else
330
-            return NULL;
338
+        if ($identifier > 0) {
339
+                    return new Profile($identifier, $this);
340
+        } else {
341
+                    return NULL;
342
+        }
331 343
     }
332 344
 
333 345
     /**
@@ -335,13 +347,15 @@  discard block
 block discarded – undo
335 347
      */
336 348
     public function destroy() {
337 349
         /* delete all profiles */
338
-        foreach ($this->listProfiles() as $profile)
339
-            $profile->destroy();
350
+        foreach ($this->listProfiles() as $profile) {
351
+                    $profile->destroy();
352
+        }
340 353
         /* double-check that all profiles are gone */
341 354
         $profiles = $this->listProfiles();
342 355
 
343
-        if (count($profiles) > 0)
344
-            die("This IdP shouldn't have any profiles any more!");
356
+        if (count($profiles) > 0) {
357
+                    die("This IdP shouldn't have any profiles any more!");
358
+        }
345 359
 
346 360
         DBConnection::exec(IdP::$DB_TYPE, "DELETE FROM ownership WHERE institution_id = $this->identifier");
347 361
         DBConnection::exec(IdP::$DB_TYPE, "DELETE FROM institution_option WHERE institution_id = $this->identifier");
@@ -380,13 +394,15 @@  discard block
 block discarded – undo
380 394
             $candidate_list = DBConnection::exec("EXTERNAL", "SELECT id_institution AS id, name AS collapsed_name FROM view_active_idp_institution WHERE country = '" . strtolower($this->federation) . "'");
381 395
 
382 396
             $already_used = DBConnection::exec(IdP::$DB_TYPE, "SELECT DISTINCT external_db_id FROM institution WHERE external_db_id IS NOT NULL AND external_db_syncstate = " . EXTERNAL_DB_SYNCSTATE_SYNCED);
383
-            while ($a = mysqli_fetch_object($already_used))
384
-                $usedarray[] = $a->external_db_id;
397
+            while ($a = mysqli_fetch_object($already_used)) {
398
+                            $usedarray[] = $a->external_db_id;
399
+            }
385 400
 
386 401
             // and split them into ID, LANG, NAME pairs
387 402
             while ($a = mysqli_fetch_object($candidate_list)) {
388
-                if (in_array($a->id, $usedarray))
389
-                    continue;
403
+                if (in_array($a->id, $usedarray)) {
404
+                                    continue;
405
+                }
390 406
                 $names = explode('#', $a->collapsed_name);
391 407
                 foreach ($names as $name) {
392 408
                     $perlang = explode(': ', $name, 2);
@@ -396,12 +412,14 @@  discard block
 block discarded – undo
396 412
             // now see if any of the languages in CAT match any of those in the external DB
397 413
             $mynames = $this->getAttributes("general:instname");
398 414
             $matching_candidates = [];
399
-            foreach ($mynames as $onename)
400
-                foreach ($list as $listentry) {
415
+            foreach ($mynames as $onename) {
416
+                            foreach ($list as $listentry) {
401 417
                     $unserialised = unserialize($onename['value']);
402
-                    if (($unserialised['lang'] == $listentry['lang'] || $unserialised['lang'] == "C") && $unserialised['content'] == $listentry['name'])
403
-                        if (array_search($listentry['ID'], $matching_candidates) === FALSE)
418
+            }
419
+                    if (($unserialised['lang'] == $listentry['lang'] || $unserialised['lang'] == "C") && $unserialised['content'] == $listentry['name']) {
420
+                                            if (array_search($listentry['ID'], $matching_candidates) === FALSE)
404 421
                             $matching_candidates[] = $listentry['ID'];
422
+                    }
405 423
                 }
406 424
 
407 425
             return $matching_candidates;
@@ -441,10 +459,11 @@  discard block
 block discarded – undo
441 459
      */
442 460
     public function getExternalDBEntityDetails() {
443 461
         $external_id = $this->getExternalDBId();
444
-        if ($external_id !== FALSE)
445
-            return Federation::getExternalDBEntityDetails($external_id);
446
-        else
447
-            return [];
462
+        if ($external_id !== FALSE) {
463
+                    return Federation::getExternalDBEntityDetails($external_id);
464
+        } else {
465
+                    return [];
466
+        }
448 467
     }
449 468
 
450 469
     public function setExternalDBId($identifier) {
@@ -452,8 +471,9 @@  discard block
 block discarded – undo
452 471
         if (Config::$CONSORTIUM['name'] == "eduroam" && isset(Config::$CONSORTIUM['deployment-voodoo']) && Config::$CONSORTIUM['deployment-voodoo'] == "Operations Team") { // SW: APPROVED
453 472
             $already_used = DBConnection::exec(IdP::$DB_TYPE, "SELECT DISTINCT external_db_id FROM institution WHERE external_db_id = '$identifier' AND external_db_syncstate = " . EXTERNAL_DB_SYNCSTATE_SYNCED);
454 473
 
455
-            if (mysqli_num_rows($already_used) == 0)
456
-                DBConnection::exec(IdP::$DB_TYPE, "UPDATE institution SET external_db_id = '$identifier', external_db_syncstate = " . EXTERNAL_DB_SYNCSTATE_SYNCED . " WHERE inst_id = $this->identifier");
474
+            if (mysqli_num_rows($already_used) == 0) {
475
+                            DBConnection::exec(IdP::$DB_TYPE, "UPDATE institution SET external_db_id = '$identifier', external_db_syncstate = " . EXTERNAL_DB_SYNCSTATE_SYNCED . " WHERE inst_id = $this->identifier");
476
+            }
457 477
         }
458 478
     }
459 479
 
Please login to merge, or discard this patch.
core/Options.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -94,7 +94,7 @@
 block discarded – undo
94 94
      * 
95 95
      * @assert ("user") == Array("user:email","user:fedadmin","user:realname")
96 96
      * 
97
-     * @param string $class_name optionally specifies the class of options to be listed (class is the part of the option name before the : sign)
97
+     * @param integer $class_name optionally specifies the class of options to be listed (class is the part of the option name before the : sign)
98 98
      * @return array of options
99 99
      */
100 100
     public function availableOptions($class_name = 0) {
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@
 block discarded – undo
29 29
  */
30 30
 class Options {
31 31
     
32
-   /**
32
+    /**
33 33
      * database which this class queries by default
34 34
      * 
35 35
      * @var string
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -77,15 +77,15 @@  discard block
 block discarded – undo
77 77
      */
78 78
     private function __construct() {
79 79
         $this->type_db = [];
80
-        debug(3,"--- BEGIN constructing Options instance ---\n");
80
+        debug(3, "--- BEGIN constructing Options instance ---\n");
81 81
         $options = DBConnection::exec(Options::$DB_TYPE, "SELECT name,type,flag from profile_option_dict ORDER BY name");
82
-        while($a = mysqli_fetch_object($options))
83
-            $this->type_db[$a->name]       =  ["type" => $a->type, "flag" => $a->flag];
84
-        $this->type_db["general:logo_url"] =  ["type" => "string", "flag" => NULL];
85
-        $this->type_db["eap:ca_url"]       =  ["type" => "string", "flag" => NULL];
86
-        $this->type_db["internal:country"] =  ["type" => "string", "flag" => NULL];
82
+        while ($a = mysqli_fetch_object($options))
83
+            $this->type_db[$a->name]       = ["type" => $a->type, "flag" => $a->flag];
84
+        $this->type_db["general:logo_url"] = ["type" => "string", "flag" => NULL];
85
+        $this->type_db["eap:ca_url"]       = ["type" => "string", "flag" => NULL];
86
+        $this->type_db["internal:country"] = ["type" => "string", "flag" => NULL];
87 87
 
88
-        debug(3,"--- END constructing Options instance ---\n");
88
+        debug(3, "--- END constructing Options instance ---\n");
89 89
     }
90 90
     
91 91
     /**
@@ -99,13 +99,13 @@  discard block
 block discarded – undo
99 99
      */
100 100
     public function availableOptions($class_name = 0) {
101 101
         $temporary_array = [];
102
-        debug(3,"CLASSNAME IS $class_name\n");
102
+        debug(3, "CLASSNAME IS $class_name\n");
103 103
         
104 104
         foreach (array_keys($this->type_db) as $name) {
105 105
             if ($class_name === 0) {
106 106
                 $temporary_array[] = $name;
107 107
             } else {
108
-                if ( preg_match('/^'.$class_name.':/', $name) > 0 ) {
108
+                if (preg_match('/^' . $class_name . ':/', $name) > 0) {
109 109
                         $temporary_array[] = $name;
110 110
                 }
111 111
             }
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -79,8 +79,9 @@
 block discarded – undo
79 79
         $this->type_db = [];
80 80
         debug(3,"--- BEGIN constructing Options instance ---\n");
81 81
         $options = DBConnection::exec(Options::$DB_TYPE, "SELECT name,type,flag from profile_option_dict ORDER BY name");
82
-        while($a = mysqli_fetch_object($options))
83
-            $this->type_db[$a->name]       =  ["type" => $a->type, "flag" => $a->flag];
82
+        while($a = mysqli_fetch_object($options)) {
83
+                    $this->type_db[$a->name]       =  ["type" => $a->type, "flag" => $a->flag];
84
+        }
84 85
         $this->type_db["general:logo_url"] =  ["type" => "string", "flag" => NULL];
85 86
         $this->type_db["eap:ca_url"]       =  ["type" => "string", "flag" => NULL];
86 87
         $this->type_db["internal:country"] =  ["type" => "string", "flag" => NULL];
Please login to merge, or discard this patch.
core/phpqrcode.php 4 patches
Doc Comments   +108 added lines patch added patch discarded remove patch
@@ -96,6 +96,10 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -74,32 +74,32 @@  discard block
 block discarded – undo
74 74
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
75 75
  */
76 76
  
77
-	// Encoding modes
77
+    // Encoding modes
78 78
 	 
79
-	define('QR_MODE_NUL', -1);
80
-	define('QR_MODE_NUM', 0);
81
-	define('QR_MODE_AN', 1);
82
-	define('QR_MODE_8', 2);
83
-	define('QR_MODE_KANJI', 3);
84
-	define('QR_MODE_STRUCTURE', 4);
85
-
86
-	// Levels of error correction.
87
-
88
-	define('QR_ECLEVEL_L', 0);
89
-	define('QR_ECLEVEL_M', 1);
90
-	define('QR_ECLEVEL_Q', 2);
91
-	define('QR_ECLEVEL_H', 3);
79
+    define('QR_MODE_NUL', -1);
80
+    define('QR_MODE_NUM', 0);
81
+    define('QR_MODE_AN', 1);
82
+    define('QR_MODE_8', 2);
83
+    define('QR_MODE_KANJI', 3);
84
+    define('QR_MODE_STRUCTURE', 4);
85
+
86
+    // Levels of error correction.
87
+
88
+    define('QR_ECLEVEL_L', 0);
89
+    define('QR_ECLEVEL_M', 1);
90
+    define('QR_ECLEVEL_Q', 2);
91
+    define('QR_ECLEVEL_H', 3);
92 92
 	
93
-	// Supported output formats
93
+    // Supported output formats
94 94
 	
95
-	define('QR_FORMAT_TEXT', 0);
96
-	define('QR_FORMAT_PNG',  1);
95
+    define('QR_FORMAT_TEXT', 0);
96
+    define('QR_FORMAT_PNG',  1);
97 97
 	
98
-	class qrstr {
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));
101
-		}
102
-	}	
98
+    class qrstr {
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));
101
+        }
102
+    }	
103 103
 
104 104
 
105 105
 
@@ -211,9 +211,9 @@  discard block
 block discarded – undo
211 211
         //----------------------------------------------------------------------
212 212
         public static function buildCache()
213 213
         {
214
-			QRtools::markTime('before_build_cache');
214
+            QRtools::markTime('before_build_cache');
215 215
 			
216
-			$mask = new QRmask();
216
+            $mask = new QRmask();
217 217
             for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) {
218 218
                 $frame = QRspec::newFrame($a);
219 219
                 if (QR_IMAGE) {
@@ -221,13 +221,13 @@  discard block
 block discarded – undo
221 221
                     QRimage::png(self::binarize($frame), $fileName, 1, 0);
222 222
                 }
223 223
 				
224
-				$width = count($frame);
225
-				$bitMask = array_fill(0, $width, array_fill(0, $width, 0));
226
-				for ($maskNo=0; $maskNo<8; $maskNo++)
227
-					$mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
224
+                $width = count($frame);
225
+                $bitMask = array_fill(0, $width, array_fill(0, $width, 0));
226
+                for ($maskNo=0; $maskNo<8; $maskNo++)
227
+                    $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
228 228
             }
229 229
 			
230
-			QRtools::markTime('after_build_cache');
230
+            QRtools::markTime('after_build_cache');
231 231
         }
232 232
 
233 233
         //----------------------------------------------------------------------
@@ -647,10 +647,10 @@  discard block
 block discarded – undo
647 647
 
648 648
         // Version information pattern -----------------------------------------
649 649
 
650
-		// Version information pattern (BCH coded).
650
+        // Version information pattern (BCH coded).
651 651
         // See Table 1 in Appendix D (pp.68) of JIS X0510:2004.
652 652
         
653
-		// size: [QRSPEC_VERSION_MAX - 6]
653
+        // size: [QRSPEC_VERSION_MAX - 6]
654 654
 		
655 655
         public static $versionPattern = [
656 656
             0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d,
@@ -1438,7 +1438,7 @@  discard block
 block discarded – undo
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,
@@ -2500,17 +2500,17 @@  discard block
 block discarded – undo
2500 2500
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2501 2501
  */
2502 2502
  
2503
-	define('N1', 3);
2504
-	define('N2', 3);
2505
-	define('N3', 40);
2506
-	define('N4', 10);
2503
+    define('N1', 3);
2504
+    define('N2', 3);
2505
+    define('N3', 40);
2506
+    define('N4', 10);
2507 2507
 
2508
-	class QRmask {
2508
+    class QRmask {
2509 2509
 	
2510
-		public $runLength = [];
2510
+        public $runLength = [];
2511 2511
 		
2512
-		//----------------------------------------------------------------------
2513
-		public function __construct() 
2512
+        //----------------------------------------------------------------------
2513
+        public function __construct() 
2514 2514
         {
2515 2515
             $this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0);
2516 2516
         }
Please login to merge, or discard this patch.
Spacing   +512 added lines, -512 removed lines patch added patch discarded remove patch
@@ -93,11 +93,11 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
818 818
             } else {
819 819
             
820 820
                 foreach ($frame as &$frameLine) {
821
-                    $frameLine = join('<span class="m">&nbsp;</span>',  explode("\xc0", $frameLine));
821
+                    $frameLine = join('<span class="m">&nbsp;</span>', explode("\xc0", $frameLine));
822 822
                     $frameLine = join('<span class="m">&#9618;</span>', explode("\xc1", $frameLine));
823
-                    $frameLine = join('<span class="p">&nbsp;</span>',  explode("\xa0", $frameLine));
823
+                    $frameLine = join('<span class="p">&nbsp;</span>', explode("\xa0", $frameLine));
824 824
                     $frameLine = join('<span class="p">&#9618;</span>', explode("\xa1", $frameLine));
825 825
                     $frameLine = join('<span class="s">&#9671;</span>', explode("\x84", $frameLine)); //format 0
826 826
                     $frameLine = join('<span class="s">&#9670;</span>', explode("\x85", $frameLine)); //format 1
827 827
                     $frameLine = join('<span class="x">&#9762;</span>', explode("\x81", $frameLine)); //special bit
828
-                    $frameLine = join('<span class="c">&nbsp;</span>',  explode("\x90", $frameLine)); //clock 0
828
+                    $frameLine = join('<span class="c">&nbsp;</span>', explode("\x90", $frameLine)); //clock 0
829 829
                     $frameLine = join('<span class="c">&#9719;</span>', explode("\x91", $frameLine)); //clock 1
830
-                    $frameLine = join('<span class="f">&nbsp;</span>',  explode("\x88", $frameLine)); //version
830
+                    $frameLine = join('<span class="f">&nbsp;</span>', explode("\x88", $frameLine)); //version
831 831
                     $frameLine = join('<span class="f">&#9618;</span>', explode("\x89", $frameLine)); //version
832 832
                     $frameLine = join('&#9830;', explode("\x01", $frameLine));
833 833
                     $frameLine = join('&#8901;', explode("\0", $frameLine));
@@ -865,12 +865,12 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
             
Please login to merge, or discard this patch.
Braces   +194 added lines, -109 removed lines patch added patch discarded remove patch
@@ -176,8 +176,9 @@  discard block
 block discarded – undo
176 176
         {
177 177
             $barcode_array = [];
178 178
             
179
-            if (!is_array($mode))
180
-                $mode = explode(',', $mode);
179
+            if (!is_array($mode)) {
180
+                            $mode = explode(',', $mode);
181
+            }
181 182
                 
182 183
             $eccLevel = 'L';
183 184
                 
@@ -194,8 +195,9 @@  discard block
 block discarded – undo
194 195
                 
195 196
             foreach ($qrTab as $line) {
196 197
                 $arrAdd = [];
197
-                foreach(str_split($line) as $char)
198
-                    $arrAdd[] = ($char=='1')?1:0;
198
+                foreach(str_split($line) as $char) {
199
+                                    $arrAdd[] = ($char=='1')?1:0;
200
+                }
199 201
                 $barcode_array['bcode'][] = $arrAdd;
200 202
             }
201 203
                     
@@ -223,8 +225,9 @@  discard block
 block discarded – undo
223 225
 				
224 226
 				$width = count($frame);
225 227
 				$bitMask = array_fill(0, $width, array_fill(0, $width, 0));
226
-				for ($maskNo=0; $maskNo<8; $maskNo++)
227
-					$mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
228
+				for ($maskNo=0; $maskNo<8; $maskNo++) {
229
+									$mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
230
+				}
228 231
             }
229 232
 			
230 233
 			QRtools::markTime('after_build_cache');
@@ -261,8 +264,9 @@  discard block
 block discarded – undo
261 264
             list($usec, $sec) = explode(" ", microtime());
262 265
             $time = ((float)$usec + (float)$sec);
263 266
             
264
-            if (!isset($GLOBALS['qr_time_bench']))
265
-                $GLOBALS['qr_time_bench'] = [];
267
+            if (!isset($GLOBALS['qr_time_bench'])) {
268
+                            $GLOBALS['qr_time_bench'] = [];
269
+            }
266 270
             
267 271
             $GLOBALS['qr_time_bench'][$markerId] = $time;
268 272
         }
@@ -427,8 +431,9 @@  discard block
 block discarded – undo
427 431
 
428 432
             for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) {
429 433
                 $words  = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level];
430
-                if($words >= $size) 
431
-                    return $i;
434
+                if($words >= $size) {
435
+                                    return $i;
436
+                }
432 437
             }
433 438
 
434 439
             return -1;
@@ -446,8 +451,9 @@  discard block
 block discarded – undo
446 451
         //----------------------------------------------------------------------
447 452
         public static function lengthIndicator($mode, $version)
448 453
         {
449
-            if ($mode == QR_MODE_STRUCTURE)
450
-                return 0;
454
+            if ($mode == QR_MODE_STRUCTURE) {
455
+                            return 0;
456
+            }
451 457
                 
452 458
             if ($version <= 9) {
453 459
                 $l = 0;
@@ -463,8 +469,9 @@  discard block
 block discarded – undo
463 469
         //----------------------------------------------------------------------
464 470
         public static function maximumWords($mode, $version)
465 471
         {
466
-            if($mode == QR_MODE_STRUCTURE) 
467
-                return 3;
472
+            if($mode == QR_MODE_STRUCTURE) {
473
+                            return 3;
474
+            }
468 475
                 
469 476
             if($version <= 9) {
470 477
                 $l = 0;
@@ -610,8 +617,9 @@  discard block
 block discarded – undo
610 617
         //----------------------------------------------------------------------
611 618
         public static function putAlignmentPattern($version, &$frame, $width)
612 619
         {
613
-            if($version < 2)
614
-                return;
620
+            if($version < 2) {
621
+                            return;
622
+            }
615 623
 
616 624
             $d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0];
617 625
             if($d < 0) {
@@ -663,8 +671,9 @@  discard block
 block discarded – undo
663 671
         //----------------------------------------------------------------------
664 672
         public static function getVersionPattern($version)
665 673
         {
666
-            if($version < 7 || $version > QRSPEC_VERSION_MAX)
667
-                return 0;
674
+            if($version < 7 || $version > QRSPEC_VERSION_MAX) {
675
+                            return 0;
676
+            }
668 677
 
669 678
             return self::$versionPattern[$version -7];
670 679
         }
@@ -681,11 +690,13 @@  discard block
 block discarded – undo
681 690
 
682 691
         public static function getFormatInfo($mask, $level)
683 692
         {
684
-            if($mask < 0 || $mask > 7)
685
-                return 0;
693
+            if($mask < 0 || $mask > 7) {
694
+                            return 0;
695
+            }
686 696
                 
687
-            if($level < 0 || $level > 3)
688
-                return 0;                
697
+            if($level < 0 || $level > 3) {
698
+                            return 0;
699
+            }
689 700
 
690 701
             return self::$formatInfo[$level][$mask];
691 702
         }
@@ -865,8 +876,9 @@  discard block
 block discarded – undo
865 876
         //----------------------------------------------------------------------
866 877
         public static function newFrame($version)
867 878
         {
868
-            if($version < 1 || $version > QRSPEC_VERSION_MAX) 
869
-                return null;
879
+            if($version < 1 || $version > QRSPEC_VERSION_MAX) {
880
+                            return null;
881
+            }
870 882
 
871 883
             if(!isset(self::$frames[$version])) {
872 884
                 
@@ -884,8 +896,9 @@  discard block
 block discarded – undo
884 896
                 }
885 897
             }
886 898
             
887
-            if(is_null(self::$frames[$version]))
888
-                return null;
899
+            if(is_null(self::$frames[$version])) {
900
+                            return null;
901
+            }
889 902
 
890 903
             return self::$frames[$version];
891 904
         }
@@ -953,7 +966,7 @@  discard block
 block discarded – undo
953 966
                     ImagePng($image, $filename);
954 967
                     header("Content-type: image/png");
955 968
                     ImagePng($image);
956
-                }else{
969
+                } else{
957 970
                     ImagePng($image, $filename);
958 971
                 }
959 972
             }
@@ -1213,8 +1226,9 @@  discard block
 block discarded – undo
1213 1226
         {
1214 1227
             $bits = 0;
1215 1228
 
1216
-            if($version == 0) 
1217
-                $version = 1;
1229
+            if($version == 0) {
1230
+                            $version = 1;
1231
+            }
1218 1232
 
1219 1233
             switch($this->mode) {
1220 1234
                 case QR_MODE_NUM:        $bits = QRinput::estimateBitsModeNum($this->size);    break;
@@ -1273,8 +1287,9 @@  discard block
 block discarded – undo
1273 1287
                             break;
1274 1288
                     }
1275 1289
                     
1276
-                    if($ret < 0)
1277
-                        return -1;
1290
+                    if($ret < 0) {
1291
+                                            return -1;
1292
+                    }
1278 1293
                 }
1279 1294
 
1280 1295
                 return $this->bstream->size();
@@ -1491,8 +1506,9 @@  discard block
 block discarded – undo
1491 1506
         //----------------------------------------------------------------------
1492 1507
         public static function checkModeKanji($size, $data)
1493 1508
         {
1494
-            if($size & 1)
1495
-                return false;
1509
+            if($size & 1) {
1510
+                            return false;
1511
+            }
1496 1512
 
1497 1513
             for($i=0; $i<$size; $i+=2) {
1498 1514
                 $val = (ord($data[$i]) << 8) | ord($data[$i+1]);
@@ -1512,8 +1528,9 @@  discard block
 block discarded – undo
1512 1528
 
1513 1529
         public static function check($mode, $size, $data)
1514 1530
         {
1515
-            if($size <= 0) 
1516
-                return false;
1531
+            if($size <= 0) {
1532
+                            return false;
1533
+            }
1517 1534
 
1518 1535
             switch($mode) {
1519 1536
                 case QR_MODE_NUM:       return self::checkModeNum($size, $data);   break;
@@ -1578,8 +1595,9 @@  discard block
 block discarded – undo
1578 1595
                     $chunks = (int)($payload / 11);
1579 1596
                     $remain = $payload - $chunks * 11;
1580 1597
                     $size = $chunks * 2;
1581
-                    if($remain >= 6) 
1582
-                        $size++;
1598
+                    if($remain >= 6) {
1599
+                                            $size++;
1600
+                    }
1583 1601
                     break;
1584 1602
                 case QR_MODE_8:
1585 1603
                     $size = (int)($payload / 8);
@@ -1596,8 +1614,12 @@  discard block
 block discarded – undo
1596 1614
             }
1597 1615
             
1598 1616
             $maxsize = QRspec::maximumWords($mode, $version);
1599
-            if($size < 0) $size = 0;
1600
-            if($size > $maxsize) $size = $maxsize;
1617
+            if($size < 0) {
1618
+                $size = 0;
1619
+            }
1620
+            if($size > $maxsize) {
1621
+                $size = $maxsize;
1622
+            }
1601 1623
 
1602 1624
             return $size;
1603 1625
         }
@@ -1610,8 +1632,9 @@  discard block
 block discarded – undo
1610 1632
             foreach($this->items as $item) {
1611 1633
                 $bits = $item->encodeBitStream($this->version);
1612 1634
                 
1613
-                if($bits < 0) 
1614
-                    return -1;
1635
+                if($bits < 0) {
1636
+                                    return -1;
1637
+                }
1615 1638
                     
1616 1639
                 $total += $bits;
1617 1640
             }
@@ -1630,8 +1653,9 @@  discard block
 block discarded – undo
1630 1653
             for(;;) {
1631 1654
                 $bits = $this->createBitStream();
1632 1655
                 
1633
-                if($bits < 0) 
1634
-                    return -1;
1656
+                if($bits < 0) {
1657
+                                    return -1;
1658
+                }
1635 1659
                     
1636 1660
                 $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level);
1637 1661
                 if($ver < 0) {
@@ -1668,8 +1692,9 @@  discard block
 block discarded – undo
1668 1692
             $padding = new QRbitstream();
1669 1693
             $ret = $padding->appendNum($words * 8 - $bits + 4, 0);
1670 1694
             
1671
-            if($ret < 0) 
1672
-                return $ret;
1695
+            if($ret < 0) {
1696
+                            return $ret;
1697
+            }
1673 1698
 
1674 1699
             $padlen = $maxwords - $words;
1675 1700
             
@@ -1682,8 +1707,9 @@  discard block
 block discarded – undo
1682 1707
                 
1683 1708
                 $ret = $padding->appendBytes($padlen, $padbuf);
1684 1709
                 
1685
-                if($ret < 0)
1686
-                    return $ret;
1710
+                if($ret < 0) {
1711
+                                    return $ret;
1712
+                }
1687 1713
                 
1688 1714
             }
1689 1715
 
@@ -1860,13 +1886,15 @@  discard block
 block discarded – undo
1860 1886
         //----------------------------------------------------------------------
1861 1887
         public function appendNum($bits, $num)
1862 1888
         {
1863
-            if ($bits == 0) 
1864
-                return 0;
1889
+            if ($bits == 0) {
1890
+                            return 0;
1891
+            }
1865 1892
 
1866 1893
             $b = QRbitstream::newFromNum($bits, $num);
1867 1894
             
1868
-            if(is_null($b))
1869
-                return -1;
1895
+            if(is_null($b)) {
1896
+                            return -1;
1897
+            }
1870 1898
 
1871 1899
             $ret = $this->append($b);
1872 1900
             unset($b);
@@ -1877,13 +1905,15 @@  discard block
 block discarded – undo
1877 1905
         //----------------------------------------------------------------------
1878 1906
         public function appendBytes($size, $data)
1879 1907
         {
1880
-            if ($size == 0) 
1881
-                return 0;
1908
+            if ($size == 0) {
1909
+                            return 0;
1910
+            }
1882 1911
 
1883 1912
             $b = QRbitstream::newFromBytes($size, $data);
1884 1913
             
1885
-            if(is_null($b))
1886
-                return -1;
1914
+            if(is_null($b)) {
1915
+                            return -1;
1916
+            }
1887 1917
 
1888 1918
             $ret = $this->append($b);
1889 1919
             unset($b);
@@ -1987,8 +2017,9 @@  discard block
 block discarded – undo
1987 2017
         //----------------------------------------------------------------------
1988 2018
         public static function isdigitat($str, $pos)
1989 2019
         {    
1990
-            if ($pos >= strlen($str))
1991
-                return false;
2020
+            if ($pos >= strlen($str)) {
2021
+                            return false;
2022
+            }
1992 2023
             
1993 2024
             return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9')));
1994 2025
         }
@@ -1996,8 +2027,9 @@  discard block
 block discarded – undo
1996 2027
         //----------------------------------------------------------------------
1997 2028
         public static function isalnumat($str, $pos)
1998 2029
         {
1999
-            if ($pos >= strlen($str))
2000
-                return false;
2030
+            if ($pos >= strlen($str)) {
2031
+                            return false;
2032
+            }
2001 2033
                 
2002 2034
             return (QRinput::lookAnTable(ord($str[$pos])) >= 0);
2003 2035
         }
@@ -2005,8 +2037,9 @@  discard block
 block discarded – undo
2005 2037
         //----------------------------------------------------------------------
2006 2038
         public function identifyMode($pos)
2007 2039
         {
2008
-            if ($pos >= strlen($this->dataStr)) 
2009
-                return QR_MODE_NUL;
2040
+            if ($pos >= strlen($this->dataStr)) {
2041
+                            return QR_MODE_NUL;
2042
+            }
2010 2043
                 
2011 2044
             $c = $this->dataStr[$pos];
2012 2045
             
@@ -2060,8 +2093,9 @@  discard block
 block discarded – undo
2060 2093
             }
2061 2094
             
2062 2095
             $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr));
2063
-            if($ret < 0)
2064
-                return -1;
2096
+            if($ret < 0) {
2097
+                            return -1;
2098
+            }
2065 2099
 
2066 2100
             return $run;
2067 2101
         }
@@ -2107,8 +2141,9 @@  discard block
 block discarded – undo
2107 2141
             }
2108 2142
 
2109 2143
             $ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr));
2110
-            if($ret < 0)
2111
-                return -1;
2144
+            if($ret < 0) {
2145
+                            return -1;
2146
+            }
2112 2147
 
2113 2148
             return $run;
2114 2149
         }
@@ -2123,8 +2158,9 @@  discard block
 block discarded – undo
2123 2158
             }
2124 2159
             
2125 2160
             $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr));
2126
-            if($ret < 0)
2127
-                return -1;
2161
+            if($ret < 0) {
2162
+                            return -1;
2163
+            }
2128 2164
 
2129 2165
             return $run;
2130 2166
         }
@@ -2178,8 +2214,9 @@  discard block
 block discarded – undo
2178 2214
             $run = $p;
2179 2215
             $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr));
2180 2216
             
2181
-            if($ret < 0)
2182
-                return -1;
2217
+            if($ret < 0) {
2218
+                            return -1;
2219
+            }
2183 2220
 
2184 2221
             return $run;
2185 2222
         }
@@ -2189,8 +2226,9 @@  discard block
 block discarded – undo
2189 2226
         {
2190 2227
             while (strlen($this->dataStr) > 0)
2191 2228
             {
2192
-                if($this->dataStr == '')
2193
-                    return 0;
2229
+                if($this->dataStr == '') {
2230
+                                    return 0;
2231
+                }
2194 2232
 
2195 2233
                 $mode = $this->identifyMode(0);
2196 2234
                 
@@ -2198,16 +2236,22 @@  discard block
 block discarded – undo
2198 2236
                     case QR_MODE_NUM: $length = $this->eatNum(); break;
2199 2237
                     case QR_MODE_AN:  $length = $this->eatAn(); break;
2200 2238
                     case QR_MODE_KANJI:
2201
-                        if ($hint == QR_MODE_KANJI)
2202
-                                $length = $this->eatKanji();
2203
-                        else    $length = $this->eat8();
2239
+                        if ($hint == QR_MODE_KANJI) {
2240
+                                                        $length = $this->eatKanji();
2241
+                        } else {
2242
+                            $length = $this->eat8();
2243
+                        }
2204 2244
                         break;
2205 2245
                     default: $length = $this->eat8(); break;
2206 2246
                 
2207 2247
                 }
2208 2248
 
2209
-                if($length == 0) return 0;
2210
-                if($length < 0)  return -1;
2249
+                if($length == 0) {
2250
+                    return 0;
2251
+                }
2252
+                if($length < 0) {
2253
+                    return -1;
2254
+                }
2211 2255
                 
2212 2256
                 $this->dataStr = substr($this->dataStr, $length);
2213 2257
             }
@@ -2243,8 +2287,9 @@  discard block
 block discarded – undo
2243 2287
 
2244 2288
             $split = new QRsplit($string, $input, $modeHint);
2245 2289
             
2246
-            if(!$casesensitive)
2247
-                $split->toUpper();
2290
+            if(!$casesensitive) {
2291
+                            $split->toUpper();
2292
+            }
2248 2293
                 
2249 2294
             return $split->splitString();
2250 2295
         }
@@ -2321,11 +2366,23 @@  discard block
 block discarded – undo
2321 2366
             $rs = null;
2322 2367
             
2323 2368
             // 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
2369
+            if($symsize < 0 || $symsize > 8) {
2370
+                return $rs;
2371
+            }
2372
+            if($fcr < 0 || $fcr >= (1<<$symsize)) {
2373
+                return $rs;
2374
+            }
2375
+            if($prim <= 0 || $prim >= (1<<$symsize)) {
2376
+                return $rs;
2377
+            }
2378
+            if($nroots < 0 || $nroots >= (1<<$symsize)) {
2379
+                return $rs;
2380
+            }
2381
+            // Can't have more roots than symbol values!
2382
+            if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) {
2383
+                return $rs;
2384
+            }
2385
+            // Too much padding
2329 2386
 
2330 2387
             $rs = new QRrsItem();
2331 2388
             $rs->mm = $symsize;
@@ -2391,8 +2448,9 @@  discard block
 block discarded – undo
2391 2448
             }
2392 2449
             
2393 2450
             // convert rs->genpoly[] to index form for quicker encoding
2394
-            for ($i = 0; $i <= $nroots; $i++)
2395
-                $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]];
2451
+            for ($i = 0; $i <= $nroots; $i++) {
2452
+                            $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]];
2453
+            }
2396 2454
 
2397 2455
             return $rs;
2398 2456
         }
@@ -2450,12 +2508,24 @@  discard block
 block discarded – undo
2450 2508
         public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)
2451 2509
         {
2452 2510
             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;
2511
+                if($rs->pad != $pad) {
2512
+                    continue;
2513
+                }
2514
+                if($rs->nroots != $nroots) {
2515
+                    continue;
2516
+                }
2517
+                if($rs->mm != $symsize) {
2518
+                    continue;
2519
+                }
2520
+                if($rs->gfpoly != $gfpoly) {
2521
+                    continue;
2522
+                }
2523
+                if($rs->fcr != $fcr) {
2524
+                    continue;
2525
+                }
2526
+                if($rs->prim != $prim) {
2527
+                    continue;
2528
+                }
2459 2529
 
2460 2530
                 return $rs;
2461 2531
             }
@@ -2594,8 +2664,9 @@  discard block
 block discarded – undo
2594 2664
         {
2595 2665
             $codeArr = [];
2596 2666
             
2597
-            foreach ($bitFrame as $line)
2598
-                $codeArr[] = join('', $line);
2667
+            foreach ($bitFrame as $line) {
2668
+                            $codeArr[] = join('', $line);
2669
+            }
2599 2670
                 
2600 2671
             return gzcompress(join("\n", $codeArr), 9);
2601 2672
         }
@@ -2606,8 +2677,9 @@  discard block
 block discarded – undo
2606 2677
             $codeArr = [];
2607 2678
             
2608 2679
             $codeLines = explode("\n", gzuncompress($code));
2609
-            foreach ($codeLines as $line)
2610
-                $codeArr[] = str_split($line);
2680
+            foreach ($codeLines as $line) {
2681
+                            $codeArr[] = str_split($line);
2682
+            }
2611 2683
             
2612 2684
             return $codeArr;
2613 2685
         }
@@ -2625,16 +2697,18 @@  discard block
 block discarded – undo
2625 2697
                     $bitMask = self::unserial(file_get_contents($fileName));
2626 2698
                 } else {
2627 2699
                     $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d);
2628
-                    if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo))
2629
-                        mkdir(QR_CACHE_DIR.'mask_'.$maskNo);
2700
+                    if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo)) {
2701
+                                            mkdir(QR_CACHE_DIR.'mask_'.$maskNo);
2702
+                    }
2630 2703
                     file_put_contents($fileName, self::serial($bitMask));
2631 2704
                 }
2632 2705
             } else {
2633 2706
                 $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d);
2634 2707
             }
2635 2708
 
2636
-            if ($maskGenOnly)
2637
-                return;
2709
+            if ($maskGenOnly) {
2710
+                            return;
2711
+            }
2638 2712
                 
2639 2713
             $d = $s;
2640 2714
 
@@ -2701,8 +2775,9 @@  discard block
 block discarded – undo
2701 2775
                 
2702 2776
                 $frameY = $frame[$y];
2703 2777
                 
2704
-                if ($y>0)
2705
-                    $frameYM = $frame[$y-1];
2778
+                if ($y>0) {
2779
+                                    $frameYM = $frame[$y-1];
2780
+                }
2706 2781
                 
2707 2782
                 for($x=0; $x<$width; $x++) {
2708 2783
                     if(($x > 0) && ($y > 0)) {
@@ -2915,14 +2990,17 @@  discard block
 block discarded – undo
2915 2990
                 $blockNo++;
2916 2991
             }
2917 2992
 
2918
-            if(QRspec::rsBlockNum2($spec) == 0)
2919
-                return 0;
2993
+            if(QRspec::rsBlockNum2($spec) == 0) {
2994
+                            return 0;
2995
+            }
2920 2996
 
2921 2997
             $dl = QRspec::rsDataCodes2($spec);
2922 2998
             $el = QRspec::rsEccCodes2($spec);
2923 2999
             $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
2924 3000
             
2925
-            if($rs == NULL) return -1;
3001
+            if($rs == NULL) {
3002
+                return -1;
3003
+            }
2926 3004
             
2927 3005
             for($i=0; $i<QRspec::rsBlockNum2($spec); $i++) {
2928 3006
                 $ecc = array_slice($this->ecccode,$eccPos);
@@ -3060,7 +3138,9 @@  discard block
 block discarded – undo
3060 3138
             }
3061 3139
 
3062 3140
             $input = new QRinput($version, $level);
3063
-            if($input == NULL) return NULL;
3141
+            if($input == NULL) {
3142
+                return NULL;
3143
+            }
3064 3144
 
3065 3145
             $ret = $input->append($input, QR_MODE_8, strlen($string), str_split($string));
3066 3146
             if($ret < 0) {
@@ -3080,7 +3160,9 @@  discard block
 block discarded – undo
3080 3160
             }
3081 3161
 
3082 3162
             $input = new QRinput($version, $level);
3083
-            if($input == NULL) return NULL;
3163
+            if($input == NULL) {
3164
+                return NULL;
3165
+            }
3084 3166
 
3085 3167
             $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive);
3086 3168
             if($ret < 0) {
@@ -3190,7 +3272,9 @@  discard block
 block discarded – undo
3190 3272
                         }
3191 3273
                     }
3192 3274
                 }
3193
-                if($x < 0 || $y < 0) return null;
3275
+                if($x < 0 || $y < 0) {
3276
+                    return null;
3277
+                }
3194 3278
 
3195 3279
                 $this->x = $x;
3196 3280
                 $this->y = $y;
@@ -3297,8 +3381,9 @@  discard block
 block discarded – undo
3297 3381
                 $err = ob_get_contents();
3298 3382
                 ob_end_clean();
3299 3383
                 
3300
-                if ($err != '')
3301
-                    QRtools::log($outfile, $err);
3384
+                if ($err != '') {
3385
+                                    QRtools::log($outfile, $err);
3386
+                }
3302 3387
                 
3303 3388
                 $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin));
3304 3389
                 
Please login to merge, or discard this patch.
core/Profile.php 4 patches
Doc Comments   +11 added lines, -9 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
      * supported EAP types from the DB and stores them in the priv_ arrays.
74 74
      * 
75 75
      * @param int $p_id identifier of the profile in the DB
76
-     * @param IdP $idp_object optionally, the institution to which this Profile belongs. Saves the construction of the IdP instance. If omitted, an extra query and instantiation is executed to find out.
76
+     * @param integer $idp_object optionally, the institution to which this Profile belongs. Saves the construction of the IdP instance. If omitted, an extra query and instantiation is executed to find out.
77 77
      */
78 78
     public function __construct($p_id, $idp_object = 0) {
79 79
         debug(3, "--- BEGIN Constructing new Profile object ... ---\n");
@@ -372,6 +372,8 @@  discard block
 block discarded – undo
372 372
      * 
373 373
      * @param string device the device identifier string
374 374
      * @param string path the path where the new installer can be found
375
+     * @param string $device
376
+     * @param string $path
375 377
      */
376 378
     public function updateCache($device, $path,$mime) {
377 379
         $device = DBConnection::escape_value(Profile::$DB_TYPE, $device);
@@ -384,9 +386,9 @@  discard block
 block discarded – undo
384 386
     /**
385 387
      * Log a new download for our stats
386 388
      * 
387
-     * @param device the device id string
388
-     * @param area either admin or user
389
-     * @return TRUE if incrementing worked, FALSE if not
389
+     * @param device string device id string
390
+     * @param area string admin or user
391
+     * @return boolean if incrementing worked, FALSE if not
390 392
      */
391 393
     public function incrementDownloadStats($device, $area) {
392 394
         $device = DBConnection::escape_value(Profile::$DB_TYPE, $device);
@@ -399,7 +401,7 @@  discard block
 block discarded – undo
399 401
 
400 402
     /**
401 403
      * Retrieve current download stats from database, either for one specific device or for all devices
402
-     * @param string $device the device id string
404
+     * @param integer $device the device id string
403 405
      * @return mixed user downloads of this profile; if device is given, returns the counter as int, otherwise an array with devicename => counter
404 406
      */
405 407
     public function getUserDownloadStats($device = 0) {
@@ -464,7 +466,7 @@  discard block
 block discarded – undo
464 466
      * @param string $attr_name name of the attribute to set
465 467
      * @param string $attr_value value of the attribute to set
466 468
      * @param int $eap_type identifier of the EAP type in the database. 0 if the attribute is valid for all EAP types.
467
-     * @param string $device identifier of the device in the databse. Omit the argument if attribute is valid for all devices.
469
+     * @param integer $device identifier of the device in the databse. Omit the argument if attribute is valid for all devices.
468 470
      */
469 471
     public function addAttribute($attr_name, $attr_value, $eap_type, $device = 0) {
470 472
         $attr_name = DBConnection::escape_value(Profile::$DB_TYPE, $attr_name);
@@ -574,7 +576,7 @@  discard block
 block discarded – undo
574 576
     /** Returns an array of the profile's attributes.
575 577
      * 
576 578
      * @param string option_name the name of a specific option. If set, only returns option values for this option name
577
-     * @param eapmethod the EAP type, in array ("OUTER/INNER") notation. If set, returns only attributes which are specific to that EAP type
579
+     * @param eapmethod integer EAP type, in array ("OUTER/INNER") notation. If set, returns only attributes which are specific to that EAP type
578 580
      * @param string device the device ID string. If set, returns only attributes which are specific to that device
579 581
      * @return array attributes of the profile
580 582
      */
@@ -658,7 +660,7 @@  discard block
 block discarded – undo
658 660
     /**
659 661
      * list all devices marking their availabiblity and possible redirects
660 662
      *
661
-     * @param string $locale for text-based attributes, either returns values for the default value, or if specified here, in the locale specified
663
+     * @param integer $locale for text-based attributes, either returns values for the default value, or if specified here, in the locale specified
662 664
      * @return array of device ids display names and their status
663 665
      */
664 666
     public function listDevices($locale = 0) {
@@ -713,7 +715,7 @@  discard block
 block discarded – undo
713 715
      * as wel as the chosen language.
714 716
      * can be called with an optional $eap argument
715 717
      * 
716
-     * @param array $eap if specified, retrieves attributes specific to the given EAP type
718
+     * @param integer $eap if specified, retrieves attributes specific to the given EAP type
717 719
      * @return array list of attributes in collapsed style (index is the attrib name, value is an array of different values)
718 720
      */
719 721
     public function getCollapsedAttributes($eap = 0) {
Please login to merge, or discard this patch.
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -680,27 +680,27 @@
 block discarded – undo
680 680
             $redirect_url = getLocalisedValue($this->getAttributes("device-specific:redirect", 0, $d), $locale);
681 681
             $dev_status = AVAILABLE;
682 682
             if(isset($D['options']) && isset($D['options']['message']) && $D['options']['message']) 
683
-               $message = $D['options']['message'];
683
+                $message = $D['options']['message'];
684 684
             else
685
-               $message = 0;
685
+                $message = 0;
686 686
 
687 687
             if ($redirect_url === 0) {
688 688
                 if(isset($D['options']) && isset($D['options']['redirect']) && $D['options']['redirect']) {
689
-                   $dev_status = HIDDEN;
689
+                    $dev_status = HIDDEN;
690 690
                 }  else {
691
-                   $eap = $dev->getPreferredEapType($preferred_eap);
692
-                   if ($eap) {
693
-                       if (isset($EAP_options["eap-specific:customtext"][serialize($eap)]))
694
-                           $eap_customtext = $EAP_options["eap-specific:customtext"][serialize($eap)];
695
-                       else {
696
-                           $eap_customtext = getLocalisedValue($this->getAttributes("eap-specific:customtext", $eap, 0), $locale);
697
-                           $EAP_options["eap-specific:customtext"][serialize($eap)] = $eap_customtext;
698
-                       }
699
-                       $device_customtext = getLocalisedValue($this->getAttributes("device-specific:customtext", 0, $d), $locale);
700
-                   } else {
691
+                    $eap = $dev->getPreferredEapType($preferred_eap);
692
+                    if ($eap) {
693
+                        if (isset($EAP_options["eap-specific:customtext"][serialize($eap)]))
694
+                            $eap_customtext = $EAP_options["eap-specific:customtext"][serialize($eap)];
695
+                        else {
696
+                            $eap_customtext = getLocalisedValue($this->getAttributes("eap-specific:customtext", $eap, 0), $locale);
697
+                            $EAP_options["eap-specific:customtext"][serialize($eap)] = $eap_customtext;
698
+                        }
699
+                        $device_customtext = getLocalisedValue($this->getAttributes("device-specific:customtext", 0, $d), $locale);
700
+                    } else {
701 701
                     $dev_status = UNAVAILABLE;
702
-                   }
703
-               }
702
+                    }
703
+                }
704 704
             }
705 705
             $returnarray[] = ['id' => $d, 'display' => $D['display'], 'status' => $dev_status, 'redirect' => $redirect_url, 'eap_customtext' => $eap_customtext, 'device_customtext' => $device_customtext, 'message' => $message, 'options'=>$D['options']];
706 706
         }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
                 $temparray[] = [
121 121
                     "name" => $a->option_name,
122 122
                     "value" => $a->option_value,
123
-                    "level" => ($a->device_id == NULL && $a->method == 0 ? "Profile" : "Method" ),
123
+                    "level" => ($a->device_id == NULL && $a->method == 0 ? "Profile" : "Method"),
124 124
                     "row" => $a->row,
125 125
                     "device" => $a->device_id,
126 126
                     "flag" => $optinfo['flag'],
@@ -141,8 +141,8 @@  discard block
 block discarded – undo
141 141
 
142 142
                 $temparray[] = [
143 143
                     "name" => $a->option_name,
144
-                    "value" => ( $lang == "" ? $content : serialize(['lang' => $lang, 'content' => $content])),
145
-                    "level" => ($a->device_id == NULL && $a->method == 0 ? "Profile" : "Method" ),
144
+                    "value" => ($lang == "" ? $content : serialize(['lang' => $lang, 'content' => $content])),
145
+                    "level" => ($a->device_id == NULL && $a->method == 0 ? "Profile" : "Method"),
146 146
                     "row" => $a->row,
147 147
                     "flag" => $optinfo['flag'],
148 148
                     "device" => $a->device_id,
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
             if ($lc = mysqli_fetch_object($exec_update)->last_change) {
356 356
                 if ($lc < $cache->tm) {
357 357
                     debug(4, "Installer cached:$cache->download_path\n");
358
-                    return(['cache'=>$cache->download_path,'mime'=>$cache->mime]);
358
+                    return(['cache'=>$cache->download_path, 'mime'=>$cache->mime]);
359 359
                 }
360 360
                 else
361 361
                     return NULL;
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
      * @param string device the device identifier string
374 374
      * @param string path the path where the new installer can be found
375 375
      */
376
-    public function updateCache($device, $path,$mime) {
376
+    public function updateCache($device, $path, $mime) {
377 377
         $device = DBConnection::escape_value(Profile::$DB_TYPE, $device);
378 378
         $path   = DBConnection::escape_value(Profile::$DB_TYPE, $path);
379 379
         DBConnection::exec(Profile::$DB_TYPE, "INSERT INTO downloads (profile_id,device_id,download_path,mime,lang,installer_time) 
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
         $attr_value = DBConnection::escape_value(Profile::$DB_TYPE, $attr_value);
472 472
         
473 473
         DBConnection::exec(Profile::$DB_TYPE, "INSERT INTO profile_option (profile_id, option_name, option_value, eap_method_id" . ($device !== 0 ? ",device_id" : "") . ") 
474
-                          VALUES(". $this->identifier . ", '$attr_name', '$attr_value', $eap_type" . ($device !== 0 ? ",'". DBConnection::escape_value(Profile::$DB_TYPE, $device) . "'" : "" ) . ")");
474
+                          VALUES(". $this->identifier . ", '$attr_name', '$attr_value', $eap_type" . ($device !== 0 ? ",'" . DBConnection::escape_value(Profile::$DB_TYPE, $device) . "'" : "") . ")");
475 475
         $this->updateFreshness();
476 476
     }
477 477
 
@@ -524,20 +524,20 @@  discard block
 block discarded – undo
524 524
      * @param string $localpart the username
525 525
      *
526 526
      */
527
-    public function setRealmCheckUser($shallwe,$localpart = NULL) {
527
+    public function setRealmCheckUser($shallwe, $localpart = NULL) {
528 528
         DBConnection::exec(Profile::$DB_TYPE, 
529 529
                 "UPDATE profile SET checkuser_outer = " . ($shallwe == true ? "1" : "0") . 
530
-                ( $localpart !== NULL ? ", checkuser_value = '$localpart' " : "") .
530
+                ($localpart !== NULL ? ", checkuser_value = '$localpart' " : "") .
531 531
                 " WHERE profile_id = $this->identifier");
532 532
     }
533 533
 
534 534
     /** should username be verified or even prefilled?
535 535
      * 
536 536
      */
537
-    public function setInputVerificationPreference($verify,$hint) {
537
+    public function setInputVerificationPreference($verify, $hint) {
538 538
         DBConnection::exec(Profile::$DB_TYPE, 
539 539
                 "UPDATE profile SET verify_userinput_suffix = " . ($verify == true ? "1" : "0") . 
540
-                ", hint_userinput_suffix = ". ($hint == true ? "1" : "0") .
540
+                ", hint_userinput_suffix = " . ($hint == true ? "1" : "0") .
541 541
                 " WHERE profile_id = $this->identifier");
542 542
     }
543 543
     
@@ -679,15 +679,15 @@  discard block
 block discarded – undo
679 679
             $dev = $factory->device;
680 680
             $redirect_url = getLocalisedValue($this->getAttributes("device-specific:redirect", 0, $d), $locale);
681 681
             $dev_status = AVAILABLE;
682
-            if(isset($D['options']) && isset($D['options']['message']) && $D['options']['message']) 
682
+            if (isset($D['options']) && isset($D['options']['message']) && $D['options']['message']) 
683 683
                $message = $D['options']['message'];
684 684
             else
685 685
                $message = 0;
686 686
 
687 687
             if ($redirect_url === 0) {
688
-                if(isset($D['options']) && isset($D['options']['redirect']) && $D['options']['redirect']) {
688
+                if (isset($D['options']) && isset($D['options']['redirect']) && $D['options']['redirect']) {
689 689
                    $dev_status = HIDDEN;
690
-                }  else {
690
+                } else {
691 691
                    $eap = $dev->getPreferredEapType($preferred_eap);
692 692
                    if ($eap) {
693 693
                        if (isset($EAP_options["eap-specific:customtext"][serialize($eap)]))
Please login to merge, or discard this patch.
Braces   +120 added lines, -88 removed lines patch added patch discarded remove patch
@@ -240,8 +240,8 @@  discard block
 block discarded – undo
240 240
 
241 241
         $idpoptions = $idp->getAttributes();
242 242
 
243
-        foreach ($idpoptions as $the_attr)
244
-            $temparray[] = [
243
+        foreach ($idpoptions as $the_attr) {
244
+                    $temparray[] = [
245 245
                 "name" => $the_attr["name"],
246 246
                 "value" => $the_attr["value"],
247 247
                 "level" => $the_attr["level"],
@@ -250,30 +250,35 @@  discard block
 block discarded – undo
250 250
                 "device" => NULL,
251 251
                 "eapmethod" => NULL,
252 252
             ];
253
+        }
253 254
 
254 255
         $this->priv_attributes = [];
255 256
 
256 257
         // check sanity (device and eapmethod are mutually exclusive) and first batch of adding (method level)
257 258
 
258 259
         foreach ($temparray as $attrib) {
259
-            if ($attrib["device"] != NULL && $attrib["eapmethod"] != NULL)
260
-                debug(2, "Sanity check failed - device and eapmethod are set!\n");
260
+            if ($attrib["device"] != NULL && $attrib["eapmethod"] != NULL) {
261
+                            debug(2, "Sanity check failed - device and eapmethod are set!\n");
262
+            }
261 263
         }
262 264
 
263 265
         foreach ($temparray as $attrib) {
264
-            if ($attrib["device"] != NULL || $attrib["eapmethod"] != NULL)
265
-                $this->priv_attributes[] = $attrib;
266
+            if ($attrib["device"] != NULL || $attrib["eapmethod"] != NULL) {
267
+                            $this->priv_attributes[] = $attrib;
268
+            }
266 269
         }
267 270
         // pick all attributes which are profile specific and place into final array if no eap/device-specific exists
268 271
 
269 272
         foreach ($temparray as $attrib) {
270 273
             if ($attrib["level"] == "Profile") {
271 274
                 $ignore = "";
272
-                foreach ($this->priv_attributes as $approved_attrib)
273
-                    if ($attrib["name"] == $approved_attrib["name"] && $approved_attrib["level"] != "IdP" && $approved_attrib["level"] != "Profile")
275
+                foreach ($this->priv_attributes as $approved_attrib) {
276
+                                    if ($attrib["name"] == $approved_attrib["name"] && $approved_attrib["level"] != "IdP" && $approved_attrib["level"] != "Profile")
274 277
                         $ignore = "YES";
275
-                if ($ignore != "YES")
276
-                    $this->priv_attributes[] = $attrib;
278
+                }
279
+                if ($ignore != "YES") {
280
+                                    $this->priv_attributes[] = $attrib;
281
+                }
277 282
             }
278 283
         }
279 284
 
@@ -282,11 +287,13 @@  discard block
 block discarded – undo
282 287
         foreach ($temparray as $attrib) {
283 288
             if ($attrib["level"] == "IdP") {
284 289
                 $ignore = "";
285
-                foreach ($this->priv_attributes as $approved_attrib)
286
-                    if ($attrib["name"] == $approved_attrib["name"] && $approved_attrib["level"] != "IdP")
290
+                foreach ($this->priv_attributes as $approved_attrib) {
291
+                                    if ($attrib["name"] == $approved_attrib["name"] && $approved_attrib["level"] != "IdP")
287 292
                         $ignore = "YES";
288
-                if ($ignore != "YES")
289
-                    $this->priv_attributes[] = $attrib;
293
+                }
294
+                if ($ignore != "YES") {
295
+                                    $this->priv_attributes[] = $attrib;
296
+                }
290 297
             }
291 298
         }
292 299
 
@@ -315,8 +322,9 @@  discard block
 block discarded – undo
315 322
         $exec_query = DBConnection::exec(Profile::$DB_TYPE, "SELECT profile_id FROM profile WHERE realm LIKE '%@$realm'");
316 323
         if ($a = mysqli_fetch_object($exec_query)) {
317 324
             return $a->profile_id;
318
-        } else
319
-            return FALSE;
325
+        } else {
326
+                    return FALSE;
327
+        }
320 328
     }
321 329
     
322 330
     /**
@@ -356,15 +364,15 @@  discard block
 block discarded – undo
356 364
                 if ($lc < $cache->tm) {
357 365
                     debug(4, "Installer cached:$cache->download_path\n");
358 366
                     return(['cache'=>$cache->download_path,'mime'=>$cache->mime]);
367
+                } else {
368
+                                    return NULL;
359 369
                 }
360
-                else
361
-                    return NULL;
370
+            } else {
371
+                            return NULL;
362 372
             }
363
-            else
364
-                return NULL;
373
+        } else {
374
+                    return NULL;
365 375
         }
366
-        else
367
-            return NULL;
368 376
     }
369 377
 
370 378
     /**
@@ -405,20 +413,23 @@  discard block
 block discarded – undo
405 413
     public function getUserDownloadStats($device = 0) {
406 414
         $returnarray = [];
407 415
         $numbers_q = DBConnection::exec(Profile::$DB_TYPE, "SELECT device_id, SUM(downloads_user) AS downloads_user FROM downloads WHERE profile_id = $this->identifier GROUP BY device_id");
408
-        while ($a = mysqli_fetch_object($numbers_q))
409
-            $returnarray[$a->device_id] = $a->downloads_user;
416
+        while ($a = mysqli_fetch_object($numbers_q)) {
417
+                    $returnarray[$a->device_id] = $a->downloads_user;
418
+        }
410 419
         if ($device !== 0) {
411
-            if (isset($returnarray[$device]))
412
-                return $returnarray[$device];
413
-            else
414
-                return 0;
420
+            if (isset($returnarray[$device])) {
421
+                            return $returnarray[$device];
422
+            } else {
423
+                            return 0;
424
+            }
415 425
         }
416 426
         // we should pretty-print the device names
417 427
         $finalarray = [];
418 428
         $devlist = Devices::listDevices();
419
-        foreach ($returnarray as $dev_id => $count)
420
-            if (isset($devlist[$dev_id]))
429
+        foreach ($returnarray as $dev_id => $count) {
430
+                    if (isset($devlist[$dev_id]))
421 431
                     $finalarray[$devlist[$dev_id]['display']] = $count;
432
+        }
422 433
         return $finalarray;
423 434
     }
424 435
 
@@ -434,15 +445,16 @@  discard block
 block discarded – undo
434 445
         if ($device !== 0) {
435 446
             $device = DBConnection::escape_value(Profile::$DB_TYPE, $device);
436 447
             $devicetext = "AND device_id = '$device'";
448
+        } else {
449
+                    $devicetext = "";
437 450
         }
438
-        else
439
-            $devicetext = "";
440 451
         DBConnection::exec(Profile::$DB_TYPE, "DELETE FROM profile_option WHERE profile_id = $this->identifier $devicetext AND eap_method_id = $eap_type_id AND option_name NOT LIKE '%_file'");
441 452
         $this->updateFreshness();
442 453
         $exec_q = DBConnection::exec(Profile::$DB_TYPE, "SELECT row FROM profile_option WHERE profile_id = $this->identifier $devicetext AND eap_method_id = $eap_type_id");
443 454
         $return_array = [];
444
-        while ($a = mysqli_fetch_object($exec_q))
445
-            $return_array[$a->row] = "KILLME";
455
+        while ($a = mysqli_fetch_object($exec_q)) {
456
+                    $return_array[$a->row] = "KILLME";
457
+        }
446 458
         return $return_array;
447 459
     }
448 460
 
@@ -564,9 +576,10 @@  discard block
 block discarded – undo
564 576
         if ($complete_only == 0) {
565 577
             return $this->priv_eaptypes;
566 578
         } else {
567
-            foreach ($this->priv_eaptypes as $type)
568
-                if ($this->isEapTypeDefinitionComplete($type) === true)
579
+            foreach ($this->priv_eaptypes as $type) {
580
+                            if ($this->isEapTypeDefinitionComplete($type) === true)
569 581
                     $temparray[] = $type;
582
+            }
570 583
             return($temparray);
571 584
         }
572 585
     }
@@ -583,27 +596,31 @@  discard block
 block discarded – undo
583 596
         $outarray = [];
584 597
         $temparray = [];
585 598
         if ($eapmethod) {
586
-            foreach ($this->priv_attributes as $the_attr) 
587
-                if ($the_attr["eapmethod"] == $eapmethod)
599
+            foreach ($this->priv_attributes as $the_attr) {
600
+                            if ($the_attr["eapmethod"] == $eapmethod)
588 601
                     $temparray[] = $the_attr;
602
+            }
589 603
         } else
590 604
         if ($device) {
591
-            foreach ($this->priv_attributes as $the_attr)
592
-                if ($the_attr["device"] == $device)
605
+            foreach ($this->priv_attributes as $the_attr) {
606
+                            if ($the_attr["device"] == $device)
593 607
                     $temparray[] = $the_attr;
608
+            }
594 609
         };
595 610
 
596
-        foreach ($this->priv_attributes as $the_attr)
597
-            if ($the_attr["device"] == NULL && $the_attr["eapmethod"] == NULL)
611
+        foreach ($this->priv_attributes as $the_attr) {
612
+                    if ($the_attr["device"] == NULL && $the_attr["eapmethod"] == NULL)
598 613
                 $temparray[] = $the_attr;
614
+        }
599 615
 
600 616
 
601 617
         // return only options by one name, if asked for
602 618
 
603 619
         if ($option_name) {
604
-            foreach ($temparray as $the_attr)
605
-                if ($the_attr["name"] == $option_name)
620
+            foreach ($temparray as $the_attr) {
621
+                            if ($the_attr["name"] == $option_name)
606 622
                     $outarray[] = $the_attr;
623
+            }
607 624
         } else {
608 625
             $outarray = $temparray;
609 626
         }
@@ -631,15 +648,18 @@  discard block
 block discarded – undo
631 648
                 foreach ($ca_option as $one_ca) {
632 649
                     $x509 = new X509();
633 650
                     $ca_parsed = $x509->processCertificate($one_ca['value']);
634
-                    if ($ca_parsed['root'] == 1)
635
-                        return true;
651
+                    if ($ca_parsed['root'] == 1) {
652
+                                            return true;
653
+                    }
636 654
                 }
637 655
                 $missing[] = "eap:ca_file";
638 656
             }
639
-            if (count($ca_option) == 0)
640
-                $missing[] = "eap:ca_file";
641
-            if (count($cn_option) == 0)
642
-                $missing[] = "eap:server_name";
657
+            if (count($ca_option) == 0) {
658
+                            $missing[] = "eap:ca_file";
659
+            }
660
+            if (count($cn_option) == 0) {
661
+                            $missing[] = "eap:server_name";
662
+            }
643 663
             return $missing;
644 664
         } elseif ($eaptype["OUTER"] == PWD) {
645 665
             /*
@@ -662,8 +682,9 @@  discard block
 block discarded – undo
662 682
      * @return array of device ids display names and their status
663 683
      */
664 684
     public function listDevices($locale = 0) {
665
-        if ($locale == 0)
666
-            $locale = $this->lang_index;
685
+        if ($locale == 0) {
686
+                    $locale = $this->lang_index;
687
+        }
667 688
         $redirect_url = 0;
668 689
         $message = 0;
669 690
         $returnarray = [];
@@ -679,20 +700,21 @@  discard block
 block discarded – undo
679 700
             $dev = $factory->device;
680 701
             $redirect_url = getLocalisedValue($this->getAttributes("device-specific:redirect", 0, $d), $locale);
681 702
             $dev_status = AVAILABLE;
682
-            if(isset($D['options']) && isset($D['options']['message']) && $D['options']['message']) 
683
-               $message = $D['options']['message'];
684
-            else
685
-               $message = 0;
703
+            if(isset($D['options']) && isset($D['options']['message']) && $D['options']['message']) {
704
+                           $message = $D['options']['message'];
705
+            } else {
706
+                           $message = 0;
707
+            }
686 708
 
687 709
             if ($redirect_url === 0) {
688 710
                 if(isset($D['options']) && isset($D['options']['redirect']) && $D['options']['redirect']) {
689 711
                    $dev_status = HIDDEN;
690
-                }  else {
712
+                } else {
691 713
                    $eap = $dev->getPreferredEapType($preferred_eap);
692 714
                    if ($eap) {
693
-                       if (isset($EAP_options["eap-specific:customtext"][serialize($eap)]))
694
-                           $eap_customtext = $EAP_options["eap-specific:customtext"][serialize($eap)];
695
-                       else {
715
+                       if (isset($EAP_options["eap-specific:customtext"][serialize($eap)])) {
716
+                                                  $eap_customtext = $EAP_options["eap-specific:customtext"][serialize($eap)];
717
+                       } else {
696 718
                            $eap_customtext = getLocalisedValue($this->getAttributes("eap-specific:customtext", $eap, 0), $locale);
697 719
                            $EAP_options["eap-specific:customtext"][serialize($eap)] = $eap_customtext;
698 720
                        }
@@ -725,8 +747,9 @@  discard block
 block discarded – undo
725 747
             $level = $b['level'];
726 748
 //            $S[$l] = $z[$l];
727 749
             $value = $b['value'];
728
-            if (!isset($temp[$name][$level]))
729
-                $temp[$name][$level] = [];
750
+            if (!isset($temp[$name][$level])) {
751
+                            $temp[$name][$level] = [];
752
+            }
730 753
             if ($b['flag'] == 'ML') {
731 754
                 $v = unserialize($value);
732 755
                 $value = [$v['lang'] => $v['content']];
@@ -738,25 +761,29 @@  discard block
 block discarded – undo
738 761
             if ($flags[$name] == 'ML') {
739 762
                 $S = [];
740 763
                 if (isset($temp[$name]['Profile'])) {
741
-                    foreach ($temp[$name]['Profile'] as $z)
742
-                        foreach ($z as $l => $w)
764
+                    foreach ($temp[$name]['Profile'] as $z) {
765
+                                            foreach ($z as $l => $w)
743 766
                             $S[$l] = $w;
767
+                    }
744 768
                 }
745 769
                 if (!$S && isset($temp[$name]['IdP'])) {
746
-                    foreach ($temp[$name]['IdP'] as $z)
747
-                        foreach ($z as $l => $w)
770
+                    foreach ($temp[$name]['IdP'] as $z) {
771
+                                            foreach ($z as $l => $w)
748 772
                             $S[$l] = $w;
773
+                    }
749 774
                 }
750 775
                 $out[$name]['langs'] = $S;
751
-                if (isset($S[$this->lang_index]) || isset($S['C']))
752
-                    $out[$name][0] = (isset($S[$this->lang_index])) ? $S[$this->lang_index] : $S['C'];
776
+                if (isset($S[$this->lang_index]) || isset($S['C'])) {
777
+                                    $out[$name][0] = (isset($S[$this->lang_index])) ? $S[$this->lang_index] : $S['C'];
778
+                }
753 779
             } else {
754
-                if (isset($temp[$name]['Method']))
755
-                    $out[$name] = $temp[$name]['Method'];
756
-                elseif (isset($temp[$name]['Profile']))
757
-                    $out[$name] = $temp[$name]['Profile'];
758
-                else
759
-                    $out[$name] = $temp[$name]['IdP'];
780
+                if (isset($temp[$name]['Method'])) {
781
+                                    $out[$name] = $temp[$name]['Method'];
782
+                } elseif (isset($temp[$name]['Profile'])) {
783
+                                    $out[$name] = $temp[$name]['Profile'];
784
+                } else {
785
+                                    $out[$name] = $temp[$name]['IdP'];
786
+                }
760 787
             }
761 788
         }
762 789
         return($out);
@@ -794,20 +821,23 @@  discard block
 block discarded – undo
794 821
         $proper_config = FALSE;
795 822
         $attribs = $this->getCollapsedAttributes();
796 823
         // do we have enough to go live? Check if any of the configured EAP methods is completely configured ...
797
-        if (sizeof($this->getEapMethodsinOrderOfPreference(1)) > 0)
798
-            $proper_config = TRUE;
824
+        if (sizeof($this->getEapMethodsinOrderOfPreference(1)) > 0) {
825
+                    $proper_config = TRUE;
826
+        }
799 827
         // if not, it could still be that general redirect has been set
800 828
         if (!$proper_config) {
801
-            if (isset($attribs['device-specific:redirect']))
802
-                $proper_config = TRUE;
829
+            if (isset($attribs['device-specific:redirect'])) {
830
+                            $proper_config = TRUE;
831
+            }
803 832
             // TODO: or maybe just a per-device redirect? would be good enough...
804 833
         }
805 834
         // do we know at least one SSID to configure, or work with wired? If not, it's not ready...
806 835
         if (!isset($attribs['media:SSID']) &&
807 836
                 !isset($attribs['media:SSID_with_legacy']) &&
808 837
                 (!isset(Config::$CONSORTIUM['ssid']) || count(Config::$CONSORTIUM['ssid']) == 0) &&
809
-                !isset($attribs['media:wired']))
810
-            $proper_config = FALSE;
838
+                !isset($attribs['media:wired'])) {
839
+                    $proper_config = FALSE;
840
+        }
811 841
         return $proper_config;
812 842
     }
813 843
 
@@ -816,10 +846,11 @@  discard block
 block discarded – undo
816 846
      */
817 847
     public function prepShowtime() {
818 848
         $proper_config = $this->readyForShowtime();
819
-        if ($proper_config)
820
-            DBConnection::exec(Profile::$DB_TYPE, "UPDATE profile SET sufficient_config = TRUE WHERE profile_id = " . $this->identifier);
821
-        else
822
-            DBConnection::exec(Profile::$DB_TYPE, "UPDATE profile SET sufficient_config = FALSE WHERE profile_id = " . $this->identifier);
849
+        if ($proper_config) {
850
+                    DBConnection::exec(Profile::$DB_TYPE, "UPDATE profile SET sufficient_config = TRUE WHERE profile_id = " . $this->identifier);
851
+        } else {
852
+                    DBConnection::exec(Profile::$DB_TYPE, "UPDATE profile SET sufficient_config = FALSE WHERE profile_id = " . $this->identifier);
853
+        }
823 854
         $attribs = $this->getCollapsedAttributes();
824 855
         // if not enough info to go live, set FALSE
825 856
         // even if enough info is there, admin has the ultimate say: 
@@ -843,10 +874,11 @@  discard block
 block discarded – undo
843 874
         /* echo "<pre>";
844 875
           print_r($r);
845 876
           echo "</pre>"; */
846
-        if ($r[0] == "0")
847
-            return FALSE;
848
-        else
849
-            return TRUE;
877
+        if ($r[0] == "0") {
878
+                    return FALSE;
879
+        } else {
880
+                    return TRUE;
881
+        }
850 882
     }
851 883
 
852 884
     /**
Please login to merge, or discard this patch.