Completed
Push — work-fleets ( 4d76fa...c97fe0 )
by SuperNova.WS
05:17
created
includes/classes/db_mysql.php 1 patch
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
   public function load_db_settings() {
66 66
     $dbsettings = array();
67 67
 
68
-    require(SN_ROOT_PHYSICAL . "config" . DOT_PHP_EX);
68
+    require(SN_ROOT_PHYSICAL."config".DOT_PHP_EX);
69 69
 
70 70
     $this->dbsettings = $dbsettings;
71 71
   }
@@ -73,23 +73,23 @@  discard block
 block discarded – undo
73 73
   public function sn_db_connect($external_db_settings = null) {
74 74
     $this->db_disconnect();
75 75
 
76
-    if(!empty($external_db_settings) && is_array($external_db_settings)) {
76
+    if (!empty($external_db_settings) && is_array($external_db_settings)) {
77 77
       $this->dbsettings = $external_db_settings;
78 78
     }
79 79
 
80
-    if(empty($this->dbsettings)) {
80
+    if (empty($this->dbsettings)) {
81 81
       $this->load_db_settings();
82 82
     }
83 83
 
84 84
     // TODO - фатальные (?) ошибки на каждом шагу. Хотя - скорее Эксепшны
85
-    if(!empty($this->dbsettings)) {
85
+    if (!empty($this->dbsettings)) {
86 86
       $driver_name = empty($this->dbsettings['sn_driver']) ? 'db_mysql_v5' : $this->dbsettings['sn_driver'];
87 87
       $this->driver = new $driver_name();
88 88
       $this->db_prefix = $this->dbsettings['prefix'];
89 89
 
90 90
       $this->connected = $this->connected || $this->driver_connect();
91 91
 
92
-      if($this->connected) {
92
+      if ($this->connected) {
93 93
         $this->table_list = $this->db_get_table_list();
94 94
         // TODO Проверка на пустоту
95 95
       }
@@ -101,11 +101,11 @@  discard block
 block discarded – undo
101 101
   }
102 102
 
103 103
   protected function driver_connect() {
104
-    if(!is_object($this->driver)) {
104
+    if (!is_object($this->driver)) {
105 105
       classSupernova::$debug->error_fatal('DB Error - No driver for MySQL found!');
106 106
     }
107 107
 
108
-    if(!method_exists($this->driver, 'mysql_connect')) {
108
+    if (!method_exists($this->driver, 'mysql_connect')) {
109 109
       classSupernova::$debug->error_fatal('DB Error - WRONG MySQL driver!');
110 110
     }
111 111
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
   }
114 114
 
115 115
   public function db_disconnect() {
116
-    if($this->connected) {
116
+    if ($this->connected) {
117 117
       $this->connected = !$this->driver_disconnect();
118 118
       $this->connected = false;
119 119
     }
@@ -128,9 +128,9 @@  discard block
 block discarded – undo
128 128
    */
129 129
   public function replaceTablePlaceholders($query) {
130 130
     $sql = $query;
131
-    if(strpos($sql, '{{') !== false) {
132
-      foreach($this->table_list as $tableName) {
133
-        $sql = str_replace("{{{$tableName}}}", $this->db_prefix . $tableName, $sql);
131
+    if (strpos($sql, '{{') !== false) {
132
+      foreach ($this->table_list as $tableName) {
133
+        $sql = str_replace("{{{$tableName}}}", $this->db_prefix.$tableName, $sql);
134 134
       }
135 135
     }
136 136
 
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
    * @param       $fetch
143 143
    */
144 144
   protected function logQuery($query, $fetch) {
145
-    if(!classSupernova::$config->debug) {
145
+    if (!classSupernova::$config->debug) {
146 146
       return;
147 147
     }
148 148
 
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
     $arr = debug_backtrace();
151 151
     $file = end(explode('/', $arr[0]['file']));
152 152
     $line = $arr[0]['line'];
153
-    classSupernova::$debug->add("<tr><th>Query {$this->queryCount}: </th><th>$query</th><th>{$file} @ {$line}</th><th>&nbsp;</th><th> " . ($fetch ? '+' : '&nbsp;') . " </th></tr>");
153
+    classSupernova::$debug->add("<tr><th>Query {$this->queryCount}: </th><th>$query</th><th>{$file} @ {$line}</th><th>&nbsp;</th><th> ".($fetch ? '+' : '&nbsp;')." </th></tr>");
154 154
   }
155 155
 
156 156
 
@@ -160,18 +160,18 @@  discard block
 block discarded – undo
160 160
    * @return void
161 161
    */
162 162
   protected function commentQuery(&$sql) {
163
-    if(!defined('DEBUG_SQL_COMMENT')) {
163
+    if (!defined('DEBUG_SQL_COMMENT')) {
164 164
       return;
165 165
     }
166 166
     $backtrace = debug_backtrace();
167 167
     $sql_comment = classSupernova::$debug->compact_backtrace($backtrace, defined('DEBUG_SQL_COMMENT_LONG'));
168 168
 
169
-    $sql_commented = '/* ' . implode("<br />", $sql_comment) . '<br /> */ ' . preg_replace("/\s+/", ' ', $sql);
170
-    if(defined('DEBUG_SQL_ONLINE')) {
169
+    $sql_commented = '/* '.implode("<br />", $sql_comment).'<br /> */ '.preg_replace("/\s+/", ' ', $sql);
170
+    if (defined('DEBUG_SQL_ONLINE')) {
171 171
       classSupernova::$debug->warning($sql_commented, 'SQL Debug', LOG_DEBUG_SQL);
172 172
     }
173 173
 
174
-    if(defined('DEBUG_SQL_ERROR')) {
174
+    if (defined('DEBUG_SQL_ERROR')) {
175 175
       array_unshift($sql_comment, preg_replace("/\s+/", ' ', $sql));
176 176
       classSupernova::$debug->add_to_array($sql_comment);
177 177
     }
@@ -180,11 +180,11 @@  discard block
 block discarded – undo
180 180
   }
181 181
 
182 182
   public function doquery($query, $table = '', $fetch = false, $skip_query_check = false) {
183
-    if(!is_string($table)) {
183
+    if (!is_string($table)) {
184 184
       $fetch = $table;
185 185
     }
186 186
 
187
-    if(!$this->connected) {
187
+    if (!$this->connected) {
188 188
       $this->sn_db_connect();
189 189
     }
190 190
 
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 
196 196
     $sql = $this->replaceTablePlaceholders($query);
197 197
     $this->commentQuery($sql);
198
-    !($sqlquery = $this->db_sql_query($sql)) ? classSupernova::$debug->error(db_error() . "<br />$sql<br />", 'SQL Error') : false;
198
+    !($sqlquery = $this->db_sql_query($sql)) ? classSupernova::$debug->error(db_error()."<br />$sql<br />", 'SQL Error') : false;
199 199
 
200 200
     return $fetch ? $this->db_fetch($sqlquery) : $sqlquery;
201 201
   }
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
   protected function security_watch_user_queries($query) {
206 206
     global $user;
207 207
 
208
-    if(
208
+    if (
209 209
       !$this->isWatching // Not already watching
210 210
       && !empty(classSupernova::$config->game_watchlist_array) // There is some players in watchlist
211 211
       && in_array($user['id'], classSupernova::$config->game_watchlist_array) // Current player is in watchlist
@@ -213,11 +213,11 @@  discard block
 block discarded – undo
213 213
     ) {
214 214
       $this->isWatching = true;
215 215
       $msg = "\$query = \"{$query}\"\n\r";
216
-      if(!empty($_POST)) {
217
-        $msg .= "\n\r" . dump($_POST, '$_POST');
216
+      if (!empty($_POST)) {
217
+        $msg .= "\n\r".dump($_POST, '$_POST');
218 218
       }
219
-      if(!empty($_GET)) {
220
-        $msg .= "\n\r" . dump($_GET, '$_GET');
219
+      if (!empty($_GET)) {
220
+        $msg .= "\n\r".dump($_GET, '$_GET');
221 221
       }
222 222
       classSupernova::$debug->warning($msg, "Watching user {$user['id']}", 399, array('base_dump' => true));
223 223
       $this->isWatching = false;
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
   public function security_query_check_bad_words($query) {
229 229
     global $user, $dm_change_legit, $mm_change_legit;
230 230
 
231
-    switch(true) {
231
+    switch (true) {
232 232
       case stripos($query, 'RUNCATE TABL') != false:
233 233
       case stripos($query, 'ROP TABL') != false:
234 234
       case stripos($query, 'ENAME TABL') != false:
@@ -239,37 +239,37 @@  discard block
 block discarded – undo
239 239
       case stripos($query, 'RPG_POINTS') != false && stripos(trim($query), 'UPDATE ') === 0 && !$dm_change_legit:
240 240
       case stripos($query, 'METAMATTER') != false && stripos(trim($query), 'UPDATE ') === 0 && !$mm_change_legit:
241 241
       case stripos($query, 'AUTHLEVEL') != false && $user['authlevel'] < 3 && stripos($query, 'SELECT') !== 0:
242
-        $report = "Hacking attempt (" . date("d.m.Y H:i:s") . " - [" . time() . "]):\n";
242
+        $report = "Hacking attempt (".date("d.m.Y H:i:s")." - [".time()."]):\n";
243 243
         $report .= ">Database Inforamation\n";
244
-        $report .= "\tID - " . $user['id'] . "\n";
245
-        $report .= "\tUser - " . $user['username'] . "\n";
246
-        $report .= "\tAuth level - " . $user['authlevel'] . "\n";
247
-        $report .= "\tAdmin Notes - " . $user['adminNotes'] . "\n";
248
-        $report .= "\tCurrent Planet - " . $user['current_planet'] . "\n";
249
-        $report .= "\tUser IP - " . $user['user_lastip'] . "\n";
250
-        $report .= "\tUser IP at Reg - " . $user['ip_at_reg'] . "\n";
251
-        $report .= "\tUser Agent- " . $_SERVER['HTTP_USER_AGENT'] . "\n";
252
-        $report .= "\tCurrent Page - " . $user['current_page'] . "\n";
253
-        $report .= "\tRegister Time - " . $user['register_time'] . "\n";
244
+        $report .= "\tID - ".$user['id']."\n";
245
+        $report .= "\tUser - ".$user['username']."\n";
246
+        $report .= "\tAuth level - ".$user['authlevel']."\n";
247
+        $report .= "\tAdmin Notes - ".$user['adminNotes']."\n";
248
+        $report .= "\tCurrent Planet - ".$user['current_planet']."\n";
249
+        $report .= "\tUser IP - ".$user['user_lastip']."\n";
250
+        $report .= "\tUser IP at Reg - ".$user['ip_at_reg']."\n";
251
+        $report .= "\tUser Agent- ".$_SERVER['HTTP_USER_AGENT']."\n";
252
+        $report .= "\tCurrent Page - ".$user['current_page']."\n";
253
+        $report .= "\tRegister Time - ".$user['register_time']."\n";
254 254
         $report .= "\n";
255 255
 
256 256
         $report .= ">Query Information\n";
257
-        $report .= "\tQuery - " . $query . "\n";
257
+        $report .= "\tQuery - ".$query."\n";
258 258
         $report .= "\n";
259 259
 
260 260
         $report .= ">\$_SERVER Information\n";
261
-        $report .= "\tIP - " . $_SERVER['REMOTE_ADDR'] . "\n";
262
-        $report .= "\tHost Name - " . $_SERVER['HTTP_HOST'] . "\n";
263
-        $report .= "\tUser Agent - " . $_SERVER['HTTP_USER_AGENT'] . "\n";
264
-        $report .= "\tRequest Method - " . $_SERVER['REQUEST_METHOD'] . "\n";
265
-        $report .= "\tCame From - " . $_SERVER['HTTP_REFERER'] . "\n";
266
-        $report .= "\tPage is - " . $_SERVER['SCRIPT_NAME'] . "\n";
267
-        $report .= "\tUses Port - " . $_SERVER['REMOTE_PORT'] . "\n";
268
-        $report .= "\tServer Protocol - " . $_SERVER['SERVER_PROTOCOL'] . "\n";
261
+        $report .= "\tIP - ".$_SERVER['REMOTE_ADDR']."\n";
262
+        $report .= "\tHost Name - ".$_SERVER['HTTP_HOST']."\n";
263
+        $report .= "\tUser Agent - ".$_SERVER['HTTP_USER_AGENT']."\n";
264
+        $report .= "\tRequest Method - ".$_SERVER['REQUEST_METHOD']."\n";
265
+        $report .= "\tCame From - ".$_SERVER['HTTP_REFERER']."\n";
266
+        $report .= "\tPage is - ".$_SERVER['SCRIPT_NAME']."\n";
267
+        $report .= "\tUses Port - ".$_SERVER['REMOTE_PORT']."\n";
268
+        $report .= "\tServer Protocol - ".$_SERVER['SERVER_PROTOCOL']."\n";
269 269
 
270 270
         $report .= "\n--------------------------------------------------------------------------------------------------\n";
271 271
 
272
-        $fp = fopen(SN_ROOT_PHYSICAL . 'badqrys.txt', 'a');
272
+        $fp = fopen(SN_ROOT_PHYSICAL.'badqrys.txt', 'a');
273 273
         fwrite($fp, $report);
274 274
         fclose($fp);
275 275
 
@@ -290,11 +290,11 @@  discard block
 block discarded – undo
290 290
     $prefix_length = strlen($this->db_prefix);
291 291
 
292 292
     $tl = array();
293
-    while($row = $this->db_fetch($query)) {
294
-      foreach($row as $table_name) {
295
-        if(strpos($table_name, $this->db_prefix) === 0) {
293
+    while ($row = $this->db_fetch($query)) {
294
+      foreach ($row as $table_name) {
295
+        if (strpos($table_name, $this->db_prefix) === 0) {
296 296
           $table_name = substr($table_name, $prefix_length);
297
-        } elseif($prefixed_only) {
297
+        } elseif ($prefixed_only) {
298 298
           continue;
299 299
         }
300 300
         // $table_name = str_replace($db_prefix, '', $table_name);
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
     $result = array();
390 390
 
391 391
     $status = explode('  ', $this->driver->mysql_stat());
392
-    foreach($status as $value) {
392
+    foreach ($status as $value) {
393 393
       $row = explode(': ', $value);
394 394
       $result[$row[0]] = $row[1];
395 395
     }
@@ -405,10 +405,10 @@  discard block
 block discarded – undo
405 405
     $result = array();
406 406
 
407 407
     $query = $this->db_sql_query('SHOW STATUS;');
408
-    if(is_bool($query)) {
408
+    if (is_bool($query)) {
409 409
       throw new Exception('Result of SHOW STATUS command is boolean - which should never happen. Connection to DB is lost?');
410 410
     }
411
-    while($row = db_fetch($query)) {
411
+    while ($row = db_fetch($query)) {
412 412
       $result[$row['Variable_name']] = $row['Value'];
413 413
     }
414 414
 
Please login to merge, or discard this patch.
includes/classes/UnitResourceLoot.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
   public static function _init($group_name = '') {
27 27
     parent::_init($group_name);
28 28
 
29
-    foreach(static::$_group_unit_id_list as $resource_id) {
29
+    foreach (static::$_group_unit_id_list as $resource_id) {
30 30
       static::$_group_pnames[$resource_id] = pname_resource_name($resource_id);
31 31
     }
32 32
 
@@ -48,13 +48,13 @@  discard block
 block discarded – undo
48 48
 
49 49
     !is_array($resource_array) ? $resource_array = array() : false;
50 50
 
51
-    foreach($resource_array as $resource_id => $resource_actual_delta) {
52
-      if(!$resource_actual_delta) {
51
+    foreach ($resource_array as $resource_id => $resource_actual_delta) {
52
+      if (!$resource_actual_delta) {
53 53
         // No delta - no changes
54 54
         continue;
55 55
       }
56 56
 
57
-      $result[$prefix . static::$_group_pnames[$resource_id]] = $resource_actual_delta;
57
+      $result[$prefix.static::$_group_pnames[$resource_id]] = $resource_actual_delta;
58 58
     }
59 59
 
60 60
     return $result;
Please login to merge, or discard this patch.
includes/classes/core_auth.php 1 patch
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -199,18 +199,18 @@  discard block
 block discarded – undo
199 199
     // TODO Хотя тут может получится вечный цикл - ПОДУМАТЬ
200 200
     // TODO Тут же можно пробовать провести попытку слияния аккаунтов - хотя это и очень небезопасно
201 201
 
202
-    if(sys_get_param('login_player_register_logout')) {
202
+    if (sys_get_param('login_player_register_logout')) {
203 203
       $this->logout();
204 204
     }
205 205
 
206 206
     $original_suggest = '';
207 207
     // Смотрим - есть ли у нас данные от пользователя
208
-    if(($player_name_submitted = sys_get_param('submit_player_name'))) {
208
+    if (($player_name_submitted = sys_get_param('submit_player_name'))) {
209 209
       // Попытка регистрации нового игрока из данных, введенных пользователем
210 210
       $this->player_suggested_name = sys_get_param_str_unsafe('player_suggested_name');
211 211
     } else {
212
-      foreach($this->providers_authorised as $provider) {
213
-        if($this->player_suggested_name = $provider->player_name_suggest()) { // OK 4.5
212
+      foreach ($this->providers_authorised as $provider) {
213
+        if ($this->player_suggested_name = $provider->player_name_suggest()) { // OK 4.5
214 214
           $original_suggest = $provider->player_name_suggest();
215 215
           break;
216 216
         }
@@ -218,24 +218,24 @@  discard block
 block discarded – undo
218 218
     }
219 219
 
220 220
     // Если у нас провайдеры не дают имени и пользователь не дал свой вариант - это у нас первый логин в игру
221
-    if(!$this->player_suggested_name) {
221
+    if (!$this->player_suggested_name) {
222 222
       $max_user_id = db_player_get_max_id(); // 4.5
223 223
       // TODO - предлагать имя игрока по локали
224 224
 
225 225
       // Проверить наличие такого имени в истории имён
226 226
       do {
227 227
         sn_db_transaction_rollback();
228
-        $this->player_suggested_name = 'Emperor ' . mt_rand($max_user_id + 1, $max_user_id + 1000);
228
+        $this->player_suggested_name = 'Emperor '.mt_rand($max_user_id + 1, $max_user_id + 1000);
229 229
         sn_db_transaction_start();
230
-      } while(db_player_name_exists($this->player_suggested_name));
230
+      } while (db_player_name_exists($this->player_suggested_name));
231 231
 
232 232
     }
233 233
 
234
-    if($player_name_submitted) {
234
+    if ($player_name_submitted) {
235 235
       $this->register_player_db_create($this->player_suggested_name); // OK 4.5
236
-      if($this->register_status == LOGIN_SUCCESS) {
237
-        sys_redirect(SN_ROOT_VIRTUAL . 'overview.php');
238
-      } elseif($this->register_status == REGISTER_ERROR_PLAYER_NAME_EXISTS && $original_suggest == $this->player_suggested_name) {
236
+      if ($this->register_status == LOGIN_SUCCESS) {
237
+        sys_redirect(SN_ROOT_VIRTUAL.'overview.php');
238
+      } elseif ($this->register_status == REGISTER_ERROR_PLAYER_NAME_EXISTS && $original_suggest == $this->player_suggested_name) {
239 239
         // self::$player_suggested_name .= ' ' . $this->account->account_id;
240 240
       }
241 241
 //      if(self::$login_status != LOGIN_SUCCESS) {
@@ -259,9 +259,9 @@  discard block
 block discarded – undo
259 259
         : false
260 260
       );
261 261
 
262
-    if($this->register_status == LOGIN_ERROR_USERNAME_RESTRICTED_CHARACTERS) {
262
+    if ($this->register_status == LOGIN_ERROR_USERNAME_RESTRICTED_CHARACTERS) {
263 263
       $prohibited_characters = array_map(function($value) {
264
-        return "'" . htmlentities($value, ENT_QUOTES, 'UTF-8') . "'";
264
+        return "'".htmlentities($value, ENT_QUOTES, 'UTF-8')."'";
265 265
       }, str_split(LOGIN_REGISTER_CHARACTERS_PROHIBITED));
266 266
       $template_result[F_PLAYER_REGISTER_MESSAGE] .= implode(', ', $prohibited_characters);
267 267
     }
@@ -289,27 +289,27 @@  discard block
 block discarded – undo
289 289
    * @param null $result
290 290
    */
291 291
   public function login() {
292
-    if(empty(sn_module::$sn_module_list['auth'])) {
292
+    if (empty(sn_module::$sn_module_list['auth'])) {
293 293
       die('{Не обнаружено ни одного провайдера авторизации в core_auth::login()!}');
294 294
     }
295 295
 
296 296
     !empty($_POST) ? self::flog(dump($_POST, '$_POST')) : false;
297 297
     !empty($_GET) ? self::flog(dump($_GET, '$_GET')) : false;
298
-    !empty($_COOKIE) ? self::flog(dump($_COOKIE,'$_COOKIE')) : false;
298
+    !empty($_COOKIE) ? self::flog(dump($_COOKIE, '$_COOKIE')) : false;
299 299
 
300 300
     $this->auth_reset(); // OK v4.5
301 301
 
302 302
     $this->providers = array();
303
-    foreach(sn_module::$sn_module_list['auth'] as $module_name => $module) {
303
+    foreach (sn_module::$sn_module_list['auth'] as $module_name => $module) {
304 304
       $this->providers[$module->provider_id] = $module;
305 305
     }
306 306
 
307 307
     // $this->providers = array_reverse($this->providers, true); // НИНАДА! СН-аккаунт должен всегда авторизироваться первым!
308 308
 
309
-    foreach($this->providers as $provider_id => $provider) {
309
+    foreach ($this->providers as $provider_id => $provider) {
310 310
       $login_status = $provider->login(); // OK v4.5
311
-      self::flog(($provider->manifest['name'] . '->' . 'login_try - ') . (empty($provider->account->account_id) ? classLocale::$lang['sys_login_messages'][$provider->account_login_status] : dump($provider)));
312
-      if($login_status == LOGIN_SUCCESS && is_object($provider->account) && $provider->account instanceof Account && $provider->account->account_id) {
311
+      self::flog(($provider->manifest['name'].'->'.'login_try - ').(empty($provider->account->account_id) ? classLocale::$lang['sys_login_messages'][$provider->account_login_status] : dump($provider)));
312
+      if ($login_status == LOGIN_SUCCESS && is_object($provider->account) && $provider->account instanceof Account && $provider->account->account_id) {
313 313
         $this->providers_authorised[$provider_id] = &$this->providers[$provider_id];
314 314
 
315 315
         $this->user_id_to_provider = array_replace_recursive(
@@ -317,15 +317,15 @@  discard block
 block discarded – undo
317 317
           // static::db_translate_get_users_from_account_list($provider_id, $provider->account->account_id) // OK 4.5
318 318
           PlayerToAccountTranslate::db_translate_get_users_from_account_list($provider_id, $provider->account->account_id) // OK 4.5
319 319
         );
320
-      } elseif($login_status != LOGIN_UNDEFINED) {
320
+      } elseif ($login_status != LOGIN_UNDEFINED) {
321 321
         $this->provider_error_list[$provider_id] = $login_status;
322 322
       }
323 323
     }
324 324
 
325
-    if(empty($this->providers_authorised)) {
325
+    if (empty($this->providers_authorised)) {
326 326
       // Ни один аккаунт не авторизирован
327 327
       // Проверяем - есть ли у нас ошибки в аккаунтах?
328
-      if(!empty($this->provider_error_list)) {
328
+      if (!empty($this->provider_error_list)) {
329 329
         // Если есть - выводим их
330 330
         self::$login_status = reset($this->provider_error_list);
331 331
       }
@@ -340,21 +340,21 @@  discard block
 block discarded – undo
340 340
       // В self::$accessible_user_row_list - список доступных игроков для данных аккаунтов с соответствующими записями из таблицы `users`
341 341
 
342 342
       // Остались ли у нас в списке доступные игроки?
343
-      if(empty($this->accessible_user_row_list)) {
343
+      if (empty($this->accessible_user_row_list)) {
344 344
         // Нет ни одного игрока ни на одном авторизированном аккаунте
345 345
         // Надо регать нового игрока
346 346
 
347 347
         // Сейчас происходит процесс регистрации игрока?
348
-        if(!$this->is_player_register) {
348
+        if (!$this->is_player_register) {
349 349
           // Нет - отправляем на процесс регистрации
350 350
           $partner_id = sys_get_param_int('id_ref', sys_get_param_int('partner_id'));
351
-          sys_redirect(SN_ROOT_VIRTUAL . 'index.php?page=player_register&player_register=1' . ($partner_id ? '&id_ref=' . $partner_id : ''));
351
+          sys_redirect(SN_ROOT_VIRTUAL.'index.php?page=player_register&player_register=1'.($partner_id ? '&id_ref='.$partner_id : ''));
352 352
         }
353 353
       } else {
354 354
         // Да, есть доступные игроки, которые так же прописаны в базе
355 355
         $this->get_active_user(); // 4.5
356 356
 
357
-        if($this->is_impersonating = !empty($_COOKIE[SN_COOKIE_U_I]) ? $_COOKIE[SN_COOKIE_U_I] : 0) {
357
+        if ($this->is_impersonating = !empty($_COOKIE[SN_COOKIE_U_I]) ? $_COOKIE[SN_COOKIE_U_I] : 0) {
358 358
           $a_user = db_user_by_id($this->is_impersonating);
359 359
           $this->impersonator_username = $a_user['username'];
360 360
         }
@@ -362,9 +362,9 @@  discard block
 block discarded – undo
362 362
 
363 363
         //Прописываем текущего игрока на все авторизированные аккаунты
364 364
         // TODO - ИЛИ ВСЕХ ИГРОКОВ??
365
-        if(empty($this->is_impersonating)) {
366
-          foreach($this->providers_authorised as $provider_id => $provider) {
367
-            if(empty($this->user_id_to_provider[self::$user['id']][$provider_id])) {
365
+        if (empty($this->is_impersonating)) {
366
+          foreach ($this->providers_authorised as $provider_id => $provider) {
367
+            if (empty($this->user_id_to_provider[self::$user['id']][$provider_id])) {
368 368
               // self::db_translate_register_user($provider_id, $provider->account->account_id, self::$user['id']);
369 369
               PlayerToAccountTranslate::db_translate_register_user($provider_id, $provider->account->account_id, self::$user['id']);
370 370
               $this->user_id_to_provider[self::$user['id']][$provider_id][$provider->account->account_id] = true;
@@ -374,9 +374,9 @@  discard block
 block discarded – undo
374 374
       }
375 375
     }
376 376
 
377
-    if(empty(self::$user['id'])) {
377
+    if (empty(self::$user['id'])) {
378 378
       self::cookie_set(''); // OK 4.5
379
-    } elseif(self::$user['id'] != $_COOKIE[SN_COOKIE_U]) {
379
+    } elseif (self::$user['id'] != $_COOKIE[SN_COOKIE_U]) {
380 380
       self::cookie_set(self::$user['id']); // OK 4.5
381 381
     }
382 382
 
@@ -395,21 +395,21 @@  discard block
 block discarded – undo
395 395
    */
396 396
   // OK v4.7
397 397
   public function logout($redirect = true) {
398
-    if(!empty($_COOKIE[SN_COOKIE_U_I])) {
398
+    if (!empty($_COOKIE[SN_COOKIE_U_I])) {
399 399
       self::cookie_set($_COOKIE[SN_COOKIE_U_I]);
400 400
       self::cookie_set(0, true);
401 401
       self::$main_provider->logout();
402 402
     } else {
403
-      foreach($this->providers as $provider_name => $provider) {
403
+      foreach ($this->providers as $provider_name => $provider) {
404 404
         $provider->logout();
405 405
       }
406 406
 
407 407
       self::cookie_set(0);
408 408
     }
409 409
 
410
-    if($redirect === true) {
411
-      sys_redirect(SN_ROOT_RELATIVE . (empty($_COOKIE[SN_COOKIE_U]) ? 'login.php' : 'admin/overview.php'));
412
-    } elseif($redirect !== false) {
410
+    if ($redirect === true) {
411
+      sys_redirect(SN_ROOT_RELATIVE.(empty($_COOKIE[SN_COOKIE_U]) ? 'login.php' : 'admin/overview.php'));
412
+    } elseif ($redirect !== false) {
413 413
       sys_redirect($redirect);
414 414
     }
415 415
   }
@@ -420,15 +420,15 @@  discard block
 block discarded – undo
420 420
    * @param $user_selected
421 421
    */
422 422
   public function impersonate($user_selected) {
423
-    if($_COOKIE[SN_COOKIE_U_I]) {
423
+    if ($_COOKIE[SN_COOKIE_U_I]) {
424 424
       die('You already impersonating someone. Go back to living other\'s life! Or clear your cookies and try again'); // TODO: Log it
425 425
     }
426 426
 
427
-    if($this->auth_level_max_local < AUTH_LEVEL_ADMINISTRATOR) {
427
+    if ($this->auth_level_max_local < AUTH_LEVEL_ADMINISTRATOR) {
428 428
       die('You can\'t impersonate - too low level'); // TODO: Log it
429 429
     }
430 430
 
431
-    if($this->auth_level_max_local <= $user_selected['authlevel']) {
431
+    if ($this->auth_level_max_local <= $user_selected['authlevel']) {
432 432
       die('You can\'t impersonate this account - level is greater or equal to yours'); // TODO: Log it
433 433
     }
434 434
 
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
     $account_translate = reset($account_translate[$user_selected['id']][self::$main_provider->provider_id]);
437 437
     $account_to_impersonate = new Account(self::$main_provider->db);
438 438
     $account_to_impersonate->db_get_by_id($account_translate['provider_account_id']);
439
-    if(!$account_to_impersonate->is_exists) {
439
+    if (!$account_to_impersonate->is_exists) {
440 440
       die('Какая-то ошибка - не могу найти аккаунт для имперсонации'); // TODO: Log it
441 441
     }
442 442
     self::$main_provider->impersonate($account_to_impersonate);
@@ -462,12 +462,12 @@  discard block
 block discarded – undo
462 462
   public function password_check($password_unsafe) {
463 463
     $result = false;
464 464
 
465
-    if(empty($this->providers_authorised)) {
465
+    if (empty($this->providers_authorised)) {
466 466
       // TODO - такого быть не может!
467 467
       self::flog("password_check: Не найдено ни одного авторизированного провайдера в self::\$providers_authorised", true);
468 468
     } else {
469
-      foreach($this->providers_authorised as $provider_id => $provider) {
470
-        if($provider->is_feature_supported(AUTH_FEATURE_HAS_PASSWORD)) {
469
+      foreach ($this->providers_authorised as $provider_id => $provider) {
470
+        if ($provider->is_feature_supported(AUTH_FEATURE_HAS_PASSWORD)) {
471 471
           $result = $result || $provider->password_check($password_unsafe);
472 472
         }
473 473
       }
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
    */
487 487
   // OK v4.6
488 488
   public function password_change($old_password_unsafe, $new_password_unsafe) {
489
-    if(empty($this->providers_authorised)) {
489
+    if (empty($this->providers_authorised)) {
490 490
       // TODO - такого быть не может!
491 491
       self::flog("Не найдено ни одного авторизированного провайдера в self::\$providers_authorised", true);
492 492
       return false;
@@ -499,8 +499,8 @@  discard block
 block discarded – undo
499 499
     $salt_unsafe = self::password_salt_generate();
500 500
 
501 501
     $providers_changed_password = array();
502
-    foreach($this->providers_authorised as $provider_id => $provider) {
503
-      if(
502
+    foreach ($this->providers_authorised as $provider_id => $provider) {
503
+      if (
504 504
         !$provider->is_feature_supported(AUTH_FEATURE_PASSWORD_CHANGE)
505 505
         || !$provider->password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe)
506 506
       ) {
@@ -512,7 +512,7 @@  discard block
 block discarded – undo
512 512
       $account_translation = PlayerToAccountTranslate::db_translate_get_users_from_account_list($provider_id, $provider->account->account_id);
513 513
 
514 514
       // Рассылаем уведомления о смене пароля в ЛС
515
-      foreach($account_translation as $user_id => $provider_info) {
515
+      foreach ($account_translation as $user_id => $provider_info) {
516 516
         // TODO - УКазывать тип аккаунта, на котором сменён пароль
517 517
         msg_send_simple_message($user_id, 0, SN_TIME_NOW, MSG_TYPE_ADMIN,
518 518
           classLocale::$lang['sys_administration'], classLocale::$lang['sys_login_register_message_title'],
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
       sn_db_transaction_start();
560 560
       // Проверить наличие такого имени в истории имён
561 561
 
562
-      if(db_player_name_exists($player_name_unsafe)) {
562
+      if (db_player_name_exists($player_name_unsafe)) {
563 563
         throw new Exception(REGISTER_ERROR_PLAYER_NAME_EXISTS, ERR_ERROR);
564 564
       }
565 565
 
@@ -567,11 +567,11 @@  discard block
 block discarded – undo
567 567
       $player_language = '';
568 568
       $player_email = '';
569 569
       // TODO - порнография - работа должна происходить над списком аккаунтов, а не только на одном аккаунте...
570
-      foreach($this->providers_authorised as $provider) {
571
-        if(!$player_language && $provider->account->account_language) {
570
+      foreach ($this->providers_authorised as $provider) {
571
+        if (!$player_language && $provider->account->account_language) {
572 572
           $player_language = $provider->account->account_language;
573 573
         }
574
-        if(!$player_email && $provider->account->account_email) {
574
+        if (!$player_email && $provider->account->account_email) {
575 575
           $player_email = $provider->account->account_email;
576 576
         }
577 577
       }
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
       ));
588 588
       // Зарегестрировать на него аккаунты из self::$accounts_authorised
589 589
       $a_user = self::$user;
590
-      foreach($this->providers_authorised as $provider) {
590
+      foreach ($this->providers_authorised as $provider) {
591 591
         // TODO - порнография. Должен быть отдельный класс трансляторов - в т.ч. и кэширующий транслятор
592 592
         // TODO - ну и работа должна происходить над списком аккаунтов, а не только на одном аккаунте...
593 593
         // self::db_translate_register_user($provider->provider_id, $provider->account->account_id, $a_user['id']);
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
 
600 600
       sn_db_transaction_commit();
601 601
       $this->register_status = LOGIN_SUCCESS;
602
-    } catch(Exception $e) {
602
+    } catch (Exception $e) {
603 603
       sn_db_transaction_rollback();
604 604
 
605 605
       // Если старое имя занято
@@ -618,10 +618,10 @@  discard block
 block discarded – undo
618 618
     // Пробиваем все ИД игроков по базе - есть ли вообще такие записи
619 619
     // Вообще-то это не особо нужно - у нас по определению стоят констраинты
620 620
     // Зато так мы узнаем максимальный authlevel, проверим права имперсонейта и вытащим все записи юзеров
621
-    foreach($this->user_id_to_provider as $user_id => $cork) {
621
+    foreach ($this->user_id_to_provider as $user_id => $cork) {
622 622
       $user = db_user_by_id($user_id);
623 623
       // Если записи игрока в БД не существует?
624
-      if(empty($user['id'])) {
624
+      if (empty($user['id'])) {
625 625
         // Удаляем этого и переходим к следующему
626 626
         unset($this->user_id_to_provider[$user_id]);
627 627
         // Де-регистрируем игрока из таблицы трансляции игроков
@@ -642,7 +642,7 @@  discard block
 block discarded – undo
642 642
   // OK v4.5
643 643
   protected function get_active_user() {
644 644
     // Проверяем куку "текущего игрока" из браузера
645
-    if(
645
+    if (
646 646
       // Кука не пустая
647 647
       ($_COOKIE[SN_COOKIE_U] = trim($_COOKIE[SN_COOKIE_U])) && !empty($_COOKIE[SN_COOKIE_U])
648 648
       // И в куке находится ID
@@ -667,7 +667,7 @@  discard block
 block discarded – undo
667 667
     }
668 668
 
669 669
     // В куке нет валидного ИД записи игрока, доступной с текущих аккаунтов
670
-    if(empty(self::$user['id'])) {
670
+    if (empty(self::$user['id'])) {
671 671
       // Берем первого из доступных
672 672
       // TODO - default_user
673 673
       self::$user = reset($this->accessible_user_row_list);
@@ -689,7 +689,7 @@  discard block
 block discarded – undo
689 689
 
690 690
     $result = array();
691 691
 
692
-    if($user_id && empty($this->is_impersonating)) {
692
+    if ($user_id && empty($this->is_impersonating)) {
693 693
       // self::db_counter_insert();
694 694
       self::$device->db_counter_insert($user_id);
695 695
 
@@ -697,12 +697,12 @@  discard block
 block discarded – undo
697 697
 
698 698
       sys_user_options_unpack($user);
699 699
 
700
-      if($user['banaday'] && $user['banaday'] <= SN_TIME_NOW) {
700
+      if ($user['banaday'] && $user['banaday'] <= SN_TIME_NOW) {
701 701
         $user['banaday'] = 0;
702 702
         $user['vacation'] = SN_TIME_NOW;
703 703
       }
704 704
 
705
-      $user['user_lastip'] = self::$device->ip_v4_string;// $ip['ip'];
705
+      $user['user_lastip'] = self::$device->ip_v4_string; // $ip['ip'];
706 706
       $user['user_proxy'] = self::$device->ip_v4_proxy_chain; //$ip['proxy_chain'];
707 707
 
708 708
       $result[F_BANNED_STATUS] = $user['banaday'];
@@ -710,15 +710,15 @@  discard block
 block discarded – undo
710 710
 
711 711
       $proxy_safe = static::$db->db_escape(self::$device->ip_v4_proxy_chain);
712 712
 
713
-      db_user_set_by_id($user['id'], "`onlinetime` = " . SN_TIME_NOW . ",
714
-      `banaday` = " . static::$db->db_escape($user['banaday']) . ", `vacation` = " . static::$db->db_escape($user['vacation']) . ",
715
-      `user_lastip` = '" . static::$db->db_escape($user['user_lastip']) . "', `user_last_proxy` = '{$proxy_safe}', `user_last_browser_id` = " . self::$device->browser_id
713
+      db_user_set_by_id($user['id'], "`onlinetime` = ".SN_TIME_NOW.",
714
+      `banaday` = " . static::$db->db_escape($user['banaday']).", `vacation` = ".static::$db->db_escape($user['vacation']).",
715
+      `user_lastip` = '" . static::$db->db_escape($user['user_lastip'])."', `user_last_proxy` = '{$proxy_safe}', `user_last_browser_id` = ".self::$device->browser_id
716 716
       );
717 717
     }
718 718
 
719
-    if($extra = classSupernova::$config->security_ban_extra) {
719
+    if ($extra = classSupernova::$config->security_ban_extra) {
720 720
       $extra = explode(',', $extra);
721
-      array_walk($extra,'trim');
721
+      array_walk($extra, 'trim');
722 722
       in_array(self::$device->device_id, $extra) and die();
723 723
     }
724 724
 
@@ -754,21 +754,21 @@  discard block
 block discarded – undo
754 754
   protected function register_player_name_validate($player_name_unsafe) {
755 755
     // TODO - переделать под RAW-строки
756 756
     // Если имя игрока пустое - NO GO!
757
-    if(trim($player_name_unsafe) == '') {
757
+    if (trim($player_name_unsafe) == '') {
758 758
       throw new Exception(REGISTER_ERROR_PLAYER_NAME_EMPTY, ERR_ERROR);
759 759
     }
760 760
     // Проверяем, что бы в начале и конце не было пустых символов
761
-    if($player_name_unsafe != trim($player_name_unsafe)) {
761
+    if ($player_name_unsafe != trim($player_name_unsafe)) {
762 762
       throw new Exception(REGISTER_ERROR_PLAYER_NAME_TRIMMED, ERR_ERROR);
763 763
     }
764 764
     // Если логин имеет запрещенные символы - NO GO!
765
-    if(strpbrk($player_name_unsafe, LOGIN_REGISTER_CHARACTERS_PROHIBITED)) {
765
+    if (strpbrk($player_name_unsafe, LOGIN_REGISTER_CHARACTERS_PROHIBITED)) {
766 766
       // TODO - выдавать в сообщение об ошибке список запрещенных символов
767 767
       // TODO - заранее извещать игрока, какие символы являются запрещенными
768 768
       throw new Exception(REGISTER_ERROR_PLAYER_NAME_RESTRICTED_CHARACTERS, ERR_ERROR);
769 769
     }
770 770
     // Если логин меньше минимальной длины - NO GO!
771
-    if(strlen($player_name_unsafe) < LOGIN_LENGTH_MIN) {
771
+    if (strlen($player_name_unsafe) < LOGIN_LENGTH_MIN) {
772 772
       // TODO - выдавать в сообщение об ошибке минимальную длину имени игрока
773 773
       // TODO - заранее извещать игрока, какая минимальная и максимальная длина имени
774 774
       throw new Exception(REGISTER_ERROR_PLAYER_NAME_SHORT, ERR_ERROR);
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
    */
806 806
   // OK v4
807 807
   public static function password_encode($password, $salt) {
808
-    return md5($password . $salt);
808
+    return md5($password.$salt);
809 809
   }
810 810
   /**
811 811
    * Генерирует соль
@@ -826,23 +826,23 @@  discard block
 block discarded – undo
826 826
   }
827 827
 
828 828
   protected static function flog($message, $die = false) {
829
-    if(!defined('DEBUG_AUTH') || !DEBUG_AUTH) {
829
+    if (!defined('DEBUG_AUTH') || !DEBUG_AUTH) {
830 830
       return;
831 831
     }
832 832
     list($called, $caller) = debug_backtrace(false);
833 833
     $caller_name =
834
-      (!empty($caller['class']) ? $caller['class'] : '') .
835
-      (!empty($caller['type']) ? $caller['type'] : '') .
836
-      (!empty($caller['function']) ? $caller['function'] : '') .
837
-      (!empty($called['line']) ? ':' . $called['line'] : '');
834
+      (!empty($caller['class']) ? $caller['class'] : '').
835
+      (!empty($caller['type']) ? $caller['type'] : '').
836
+      (!empty($caller['function']) ? $caller['function'] : '').
837
+      (!empty($called['line']) ? ':'.$called['line'] : '');
838 838
 
839 839
     $_SERVER['SERVER_NAME'] == 'localhost' ? print("<div class='debug'>$message - $caller_name\r\n</div>") : false;
840 840
 
841 841
     classSupernova::log_file("$message - $caller_name");
842
-    if($die) {
842
+    if ($die) {
843 843
       // pdump($caller);
844 844
       // pdump(debug_backtrace(false));
845
-      $die && die("<div class='negative'>СТОП! Функция {$caller_name} при вызове в " . get_called_class() . " (располагается в " . get_class() . "). СООБЩИТЕ АДМИНИСТРАЦИИ!</div>");
845
+      $die && die("<div class='negative'>СТОП! Функция {$caller_name} при вызове в ".get_called_class()." (располагается в ".get_class()."). СООБЩИТЕ АДМИНИСТРАЦИИ!</div>");
846 846
     }
847 847
   }
848 848
 
Please login to merge, or discard this patch.
includes/classes/DBRow.php 1 patch
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
    */
109 109
   public function __get($name) {
110 110
     // Redirecting inaccessible get to __call which will handle the rest
111
-    return $this->__call('get' . ucfirst($name), array());
111
+    return $this->__call('get'.ucfirst($name), array());
112 112
   }
113 113
 
114 114
   /**
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
   // TODO - сеттер должен параллельно изменять значение db_row - for now...
121 121
   public function __set($name, $value) {
122 122
     // Redirecting inaccessible set to __call which will handle the rest
123
-    $this->__call('set' . ucfirst($name), array($value));
123
+    $this->__call('set'.ucfirst($name), array($value));
124 124
   }
125 125
 
126 126
   /**
@@ -138,15 +138,15 @@  discard block
 block discarded – undo
138 138
 
139 139
     // If method is not getter or setter OR property name not exists in $_properties - raising exception
140 140
     // Descendants can catch this Exception to make own __call magic
141
-    if(($left3 != 'get' && $left3 != 'set') || empty(static::$_properties[$propertyName])) {
142
-      throw new ExceptionPropertyNotExists('Property ' . $propertyName . ' not exists when calling getter/setter ' . get_called_class() . '::' . $name, ERR_ERROR);
141
+    if (($left3 != 'get' && $left3 != 'set') || empty(static::$_properties[$propertyName])) {
142
+      throw new ExceptionPropertyNotExists('Property '.$propertyName.' not exists when calling getter/setter '.get_called_class().'::'.$name, ERR_ERROR);
143 143
     }
144 144
 
145 145
     // TODO check for read-only
146 146
 
147
-    if($left3 == 'set') {
148
-      if(!empty($this->propertiesAdjusted[$propertyName])) {
149
-        throw new PropertyAccessException('Property ' . $propertyName . ' already was adjusted so no SET is possible until dbSave in ' . get_called_class() . '::' . $name, ERR_ERROR);
147
+    if ($left3 == 'set') {
148
+      if (!empty($this->propertiesAdjusted[$propertyName])) {
149
+        throw new PropertyAccessException('Property '.$propertyName.' already was adjusted so no SET is possible until dbSave in '.get_called_class().'::'.$name, ERR_ERROR);
150 150
       }
151 151
       $this->propertiesChanged[$propertyName] = 1;
152 152
     }
@@ -154,18 +154,18 @@  discard block
 block discarded – undo
154 154
     // Now deciding - will we call a protected setter or will we work with protected property
155 155
 
156 156
     // If method exists - just calling it
157
-    if(method_exists($this, $name)) {
157
+    if (method_exists($this, $name)) {
158 158
       return call_user_func_array(array($this, $name), $arguments);
159 159
     }
160 160
     // No getter/setter exists - works directly with protected property
161 161
 
162 162
     // Is it getter?
163
-    if($left3 === 'get') {
164
-      return $this->{'_' . $propertyName};
163
+    if ($left3 === 'get') {
164
+      return $this->{'_'.$propertyName};
165 165
     }
166 166
 
167 167
     // Not getter? Then it's setter
168
-    $this->{'_' . $propertyName} = $arguments[0];
168
+    $this->{'_'.$propertyName} = $arguments[0];
169 169
 
170 170
     return null;
171 171
   }
@@ -182,8 +182,8 @@  discard block
 block discarded – undo
182 182
    */
183 183
   public function dbLoad($dbId, $lockSkip = false) {
184 184
     $dbId = idval($dbId);
185
-    if($dbId <= 0) {
186
-      classSupernova::$debug->error(get_called_class() . '::dbLoad $dbId not positive = ' . $dbId);
185
+    if ($dbId <= 0) {
186
+      classSupernova::$debug->error(get_called_class().'::dbLoad $dbId not positive = '.$dbId);
187 187
 
188 188
       return;
189 189
     }
@@ -191,12 +191,12 @@  discard block
 block discarded – undo
191 191
     $this->_dbId = $dbId;
192 192
     $this->lockSkip = $lockSkip;
193 193
     // TODO - Use classSupernova::$db_records_locked
194
-    if(false && !$lockSkip && sn_db_transaction_check(false)) {
194
+    if (false && !$lockSkip && sn_db_transaction_check(false)) {
195 195
       $this->dbGetLockById($this->_dbId);
196 196
     }
197 197
 
198
-    $db_row = doquery("SELECT * FROM `{{" . static::$_table . "}}` WHERE `" . static::$_dbIdFieldName . "` = " . $this->_dbId . " LIMIT 1 FOR UPDATE;", true);
199
-    if(empty($db_row)) {
198
+    $db_row = doquery("SELECT * FROM `{{".static::$_table."}}` WHERE `".static::$_dbIdFieldName."` = ".$this->_dbId." LIMIT 1 FOR UPDATE;", true);
199
+    if (empty($db_row)) {
200 200
       return;
201 201
     }
202 202
 
@@ -224,26 +224,26 @@  discard block
 block discarded – undo
224 224
    */
225 225
   // TODO - perform operations only if properties was changed
226 226
   public function dbSave() {
227
-    if($this->isNew()) {
227
+    if ($this->isNew()) {
228 228
       // No DB_ID - new unit
229
-      if($this->isEmpty()) {
230
-        classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - object is empty on ' . get_called_class() . '::dbSave');
229
+      if ($this->isEmpty()) {
230
+        classSupernova::$debug->error(__FILE__.':'.__LINE__.' - object is empty on '.get_called_class().'::dbSave');
231 231
       }
232 232
       $this->dbInsert();
233 233
     } else {
234 234
       // DB_ID is present
235
-      if($this->isEmpty()) {
235
+      if ($this->isEmpty()) {
236 236
         $this->dbDelete();
237 237
       } else {
238
-        if(!sn_db_transaction_check(false)) {
239
-          classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - transaction should always be started on ' . get_called_class() . '::dbUpdate');
238
+        if (!sn_db_transaction_check(false)) {
239
+          classSupernova::$debug->error(__FILE__.':'.__LINE__.' - transaction should always be started on '.get_called_class().'::dbUpdate');
240 240
         }
241 241
         $this->dbUpdate();
242 242
       }
243 243
     }
244 244
 
245
-    if(!empty($this->triggerDbOperationOn)) {
246
-      foreach($this->triggerDbOperationOn as $item) {
245
+    if (!empty($this->triggerDbOperationOn)) {
246
+      foreach ($this->triggerDbOperationOn as $item) {
247 247
         $item->dbSave();
248 248
       }
249 249
     }
@@ -263,13 +263,13 @@  discard block
 block discarded – undo
263 263
    */
264 264
   // TODO - protected
265 265
   public function dbInsert() {
266
-    if(!$this->isNew()) {
267
-      classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - record db_id is not empty on ' . get_called_class() . '::dbInsert');
266
+    if (!$this->isNew()) {
267
+      classSupernova::$debug->error(__FILE__.':'.__LINE__.' - record db_id is not empty on '.get_called_class().'::dbInsert');
268 268
     }
269 269
     $this->_dbId = $this->db_field_set_create($this->dbMakeFieldSet());
270 270
 
271
-    if(empty($this->_dbId)) {
272
-      classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - error saving record ' . get_called_class() . '::dbInsert');
271
+    if (empty($this->_dbId)) {
272
+      classSupernova::$debug->error(__FILE__.':'.__LINE__.' - error saving record '.get_called_class().'::dbInsert');
273 273
     }
274 274
 
275 275
     return $this->_dbId;
@@ -281,8 +281,8 @@  discard block
 block discarded – undo
281 281
   // TODO - protected
282 282
   public function dbUpdate() {
283 283
     // TODO - Update
284
-    if($this->isNew()) {
285
-      classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - unit db_id is empty on dbUpdate');
284
+    if ($this->isNew()) {
285
+      classSupernova::$debug->error(__FILE__.':'.__LINE__.' - unit db_id is empty on dbUpdate');
286 286
     }
287 287
     $this->db_field_update($this->dbMakeFieldSet(true));
288 288
   }
@@ -292,10 +292,10 @@  discard block
 block discarded – undo
292 292
    */
293 293
   // TODO - protected
294 294
   public function dbDelete() {
295
-    if($this->isNew()) {
296
-      classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - unit db_id is empty on dbDelete');
295
+    if ($this->isNew()) {
296
+      classSupernova::$debug->error(__FILE__.':'.__LINE__.' - unit db_id is empty on dbDelete');
297 297
     }
298
-    doquery("DELETE FROM {{" . static::$_table . "}} WHERE `" . static::$_dbIdFieldName . "` = " . $this->_dbId);
298
+    doquery("DELETE FROM {{".static::$_table."}} WHERE `".static::$_dbIdFieldName."` = ".$this->_dbId);
299 299
     $this->_dbId = 0;
300 300
     // Обо всём остальном должен позаботиться контейнер
301 301
   }
@@ -334,18 +334,18 @@  discard block
 block discarded – undo
334 334
    * @param array $db_row
335 335
    */
336 336
   public function dbRowParse(array $db_row) {
337
-    foreach(static::$_properties as $property_name => &$property_data) {
337
+    foreach (static::$_properties as $property_name => &$property_data) {
338 338
       // Advanced values extraction procedure. Should be used when at least one of following rules is matched:
339 339
       // - one field should translate to several properties;
340 340
       // - one property should be filled according to several fields;
341 341
       // - property filling requires some lookup in object values;
342
-      if(!empty($property_data[P_METHOD_EXTRACT]) && is_callable(array($this, $property_data[P_METHOD_EXTRACT]))) {
342
+      if (!empty($property_data[P_METHOD_EXTRACT]) && is_callable(array($this, $property_data[P_METHOD_EXTRACT]))) {
343 343
         call_user_func_array(array($this, $property_data[P_METHOD_EXTRACT]), array(&$db_row));
344 344
         continue;
345 345
       }
346 346
 
347 347
       // If property is read-only - doing nothing
348
-      if(!empty($property_data[P_READ_ONLY])) {
348
+      if (!empty($property_data[P_READ_ONLY])) {
349 349
         continue;
350 350
       }
351 351
 
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
       !empty($property_data[P_FUNC_INPUT]) && is_callable($property_data[P_FUNC_INPUT]) ? $value = call_user_func($property_data[P_FUNC_INPUT], $value) : false;
357 357
 
358 358
       // If there is setter for this field - using it. Setters is always a methods of $THIS
359
-      if(!empty($property_data[P_METHOD_SET]) && is_callable(array($this, $property_data[P_METHOD_SET]))) {
359
+      if (!empty($property_data[P_METHOD_SET]) && is_callable(array($this, $property_data[P_METHOD_SET]))) {
360 360
         call_user_func(array($this, $property_data[P_METHOD_SET]), $value);
361 361
       } else {
362 362
         $this->{$property_name} = $value;
@@ -372,21 +372,21 @@  discard block
 block discarded – undo
372 372
   protected function dbMakeFieldSet($isUpdate = false) {
373 373
     $array = array();
374 374
 
375
-    foreach(static::$_properties as $property_name => &$property_data) {
375
+    foreach (static::$_properties as $property_name => &$property_data) {
376 376
       // TODO - on isUpdate add only changed/adjusted properties
377 377
 
378
-      if(!empty($property_data[P_METHOD_INJECT]) && is_callable(array($this, $property_data[P_METHOD_INJECT]))) {
378
+      if (!empty($property_data[P_METHOD_INJECT]) && is_callable(array($this, $property_data[P_METHOD_INJECT]))) {
379 379
         call_user_func_array(array($this, $property_data[P_METHOD_INJECT]), array(&$array));
380 380
         continue;
381 381
       }
382 382
 
383 383
       // Skipping properties which have no corresponding field in DB
384
-      if(empty($property_data[P_DB_FIELD])) {
384
+      if (empty($property_data[P_DB_FIELD])) {
385 385
         continue;
386 386
       }
387 387
 
388 388
       // Checking - is property was adjusted or changed
389
-      if($isUpdate && array_key_exists($property_name, $this->propertiesAdjusted)) {
389
+      if ($isUpdate && array_key_exists($property_name, $this->propertiesAdjusted)) {
390 390
         // For adjusted property - take value from propertiesAdjusted array
391 391
         // TODO - differ how treated conversion to string for changed and adjusted properties
392 392
         $value = $this->propertiesAdjusted[$property_name];
@@ -416,17 +416,17 @@  discard block
 block discarded – undo
416 416
    */
417 417
   protected function isFieldChanged($fieldName) {
418 418
     $isFieldChanged = false;
419
-    foreach($this->propertiesChanged as $propertyName => $cork) {
419
+    foreach ($this->propertiesChanged as $propertyName => $cork) {
420 420
       $propertyScheme = static::$_properties[$propertyName];
421
-      if(!empty($propertyScheme[P_DB_FIELDS_LINKED])) {
422
-        foreach($propertyScheme[P_DB_FIELDS_LINKED] as $linkedFieldName) {
423
-          if($linkedFieldName == $fieldName) {
421
+      if (!empty($propertyScheme[P_DB_FIELDS_LINKED])) {
422
+        foreach ($propertyScheme[P_DB_FIELDS_LINKED] as $linkedFieldName) {
423
+          if ($linkedFieldName == $fieldName) {
424 424
             $isFieldChanged = $propertyName;
425 425
             break 2;
426 426
           }
427 427
         }
428 428
       }
429
-      if(!empty($propertyScheme[P_DB_FIELD]) && $propertyScheme[P_DB_FIELD] == $fieldName) {
429
+      if (!empty($propertyScheme[P_DB_FIELD]) && $propertyScheme[P_DB_FIELD] == $fieldName) {
430 430
         $isFieldChanged = $propertyName;
431 431
         break;
432 432
       }
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
     $fields = implode(',', array_keys($field_set));
449 449
 
450 450
     $result = 0;
451
-    if(classSupernova::db_query("INSERT INTO `{{" . static::$_table . "}}` ({$fields}) VALUES ({$values});")) {
451
+    if (classSupernova::db_query("INSERT INTO `{{".static::$_table."}}` ({$fields}) VALUES ({$values});")) {
452 452
       $result = db_insert_id();
453 453
     }
454 454
 
@@ -466,13 +466,13 @@  discard block
 block discarded – undo
466 466
     sn_db_field_set_safe_flag_clear($field_set);
467 467
 
468 468
     $set = array();
469
-    foreach($field_set as $fieldName => $value) {
470
-      if(!($changedProperty = $this->isFieldChanged($fieldName))) {
469
+    foreach ($field_set as $fieldName => $value) {
470
+      if (!($changedProperty = $this->isFieldChanged($fieldName))) {
471 471
         continue;
472 472
       }
473 473
 
474 474
       // TODO - separate sets from adjusts
475
-      if(array_key_exists($changedProperty, $this->propertiesAdjusted)) {
475
+      if (array_key_exists($changedProperty, $this->propertiesAdjusted)) {
476 476
         $value = "`{$fieldName}` + ($value)"; // braces for negative values
477 477
       }
478 478
 
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
 
485 485
     return empty($set_string)
486 486
       ? true
487
-      : classSupernova::db_query("UPDATE `{{" . static::$_table . "}}` SET {$set_string} WHERE `" . static::$_dbIdFieldName . "` = " . $this->_dbId);
487
+      : classSupernova::db_query("UPDATE `{{".static::$_table."}}` SET {$set_string} WHERE `".static::$_dbIdFieldName."` = ".$this->_dbId);
488 488
   }
489 489
 
490 490
 }
Please login to merge, or discard this patch.
includes/classes/db_mysql_v5.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -39,19 +39,19 @@
 block discarded – undo
39 39
 
40 40
     @$this->link = mysqli_connect($settings['server'], $settings['user'], $settings['pass'], $settings['name']);
41 41
     if (!is_object($this->link) || $this->link->connect_error) {
42
-      classSupernova::$debug->error_fatal('DB Error - cannot connect to server error #' . $this->link->connect_errno, $this->link->connect_error);
42
+      classSupernova::$debug->error_fatal('DB Error - cannot connect to server error #'.$this->link->connect_errno, $this->link->connect_error);
43 43
     }
44 44
 
45 45
 
46 46
     !$this->mysql_query("/*!40101 SET NAMES 'utf8' */")
47
-      ? classSupernova::$debug->error_fatal('DB error - cannot set names 1 error #' . $this->link->errno, $this->link->error)
47
+      ? classSupernova::$debug->error_fatal('DB error - cannot set names 1 error #'.$this->link->errno, $this->link->error)
48 48
       : false;
49 49
     !$this->mysql_query("SET NAMES 'utf8';")
50
-      ? classSupernova::$debug->error_fatal('DB error - cannot set names 2 error #' . $this->link->errno, $this->link->error)
50
+      ? classSupernova::$debug->error_fatal('DB error - cannot set names 2 error #'.$this->link->errno, $this->link->error)
51 51
       : false;
52 52
 
53
-    !$this->mysql_query('SET SESSION TRANSACTION ISOLATION LEVEL ' . self::DB_MYSQL_TRANSACTION_REPEATABLE_READ . ';')
54
-      ? classSupernova::$debug->error_fatal('DB error - cannot set desired isolation level error #' . $this->link->errno, $this->link->error)
53
+    !$this->mysql_query('SET SESSION TRANSACTION ISOLATION LEVEL '.self::DB_MYSQL_TRANSACTION_REPEATABLE_READ.';')
54
+      ? classSupernova::$debug->error_fatal('DB error - cannot set desired isolation level error #'.$this->link->errno, $this->link->error)
55 55
       : false;
56 56
 
57 57
     $this->connected = true;
Please login to merge, or discard this patch.
includes/classes/user_options.php 1 patch
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -122,31 +122,31 @@  discard block
 block discarded – undo
122 122
 
123 123
     $update_cache = false;
124 124
 
125
-    if(!empty($this->to_write)) {
126
-      foreach($this->to_write as $key => $cork) {
125
+    if (!empty($this->to_write)) {
126
+      foreach ($this->to_write as $key => $cork) {
127 127
         $value = is_array($this->data[$key]) ? serialize($this->data[$key]) : $this->data[$key]; // Сериализация для массивов при сохранении в БД
128
-        $this->to_write[$key] = "({$this->user_id}, '" . db_escape($key) . "', '" . db_escape($value) . "')";
128
+        $this->to_write[$key] = "({$this->user_id}, '".db_escape($key)."', '".db_escape($value)."')";
129 129
       }
130 130
 
131
-      doquery("REPLACE INTO {{player_options}} (`player_id`, `option_id`, `value`) VALUES " . implode(',', $this->to_write));
131
+      doquery("REPLACE INTO {{player_options}} (`player_id`, `option_id`, `value`) VALUES ".implode(',', $this->to_write));
132 132
 
133 133
       $this->to_write = array();
134 134
       $update_cache = true;
135 135
     }
136 136
 
137
-    if(!empty($this->to_delete)) {
138
-      foreach($this->to_delete as $key => &$value) {
139
-        $value = is_string($key) ? "'". db_escape($key) . "'" : $key;
137
+    if (!empty($this->to_delete)) {
138
+      foreach ($this->to_delete as $key => &$value) {
139
+        $value = is_string($key) ? "'".db_escape($key)."'" : $key;
140 140
       }
141 141
 
142
-      doquery("DELETE FROM {{player_options}} WHERE `player_id` = {$this->user_id} AND `option_id` IN (". implode(',', $this->to_delete) . ") ");
142
+      doquery("DELETE FROM {{player_options}} WHERE `player_id` = {$this->user_id} AND `option_id` IN (".implode(',', $this->to_delete).") ");
143 143
       // pdump("DELETE FROM {{player_options}} WHERE `player_id` = {$this->user_id} AND `option_id` IN (". implode(',', $this->to_delete) . ") ");
144 144
 
145 145
       $this->to_delete = array();
146 146
       $update_cache = true;
147 147
     }
148 148
 
149
-    if($update_cache) {
149
+    if ($update_cache) {
150 150
       global $sn_cache;
151 151
 
152 152
       $field_name = $this->cached_name();
@@ -167,13 +167,13 @@  discard block
 block discarded – undo
167 167
     $this->load();
168 168
   }
169 169
   protected function cached_name() {
170
-    return 'options_' . $this->user_id;
170
+    return 'options_'.$this->user_id;
171 171
   }
172 172
 
173 173
   protected function load() {
174 174
     global $sn_cache;
175 175
 
176
-    if($this->loaded) {
176
+    if ($this->loaded) {
177 177
       return;
178 178
     }
179 179
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
     $this->to_write = array();
182 182
     $this->to_delete = array();
183 183
 
184
-    if(!$this->user_id) {
184
+    if (!$this->user_id) {
185 185
       $this->loaded = true;
186 186
       return;
187 187
     }
@@ -189,13 +189,13 @@  discard block
 block discarded – undo
189 189
     $field_name = $this->cached_name();
190 190
     $a_data = $sn_cache->$field_name;
191 191
 
192
-    if(!empty($a_data)) {
192
+    if (!empty($a_data)) {
193 193
       $this->data = array_replace_recursive($this->data, $a_data);
194 194
       return;
195 195
     }
196 196
 
197 197
     $query = doquery("SELECT * FROM `{{player_options}}` WHERE `player_id` = {$this->user_id} FOR UPDATE");
198
-    while($row = db_fetch($query)) {
198
+    while ($row = db_fetch($query)) {
199 199
       // $this->data[$row['option_id']] = $row['value'];
200 200
       $this->data[$row['option_id']] = is_string($row['value']) && ($temp = unserialize($row['value'])) !== false ? $temp : $row['value']; // Десериализация
201 201
     }
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
   }
273 273
 
274 274
   protected function cached_name() {
275
-    return 'options_' . $this->user_id;
275
+    return 'options_'.$this->user_id;
276 276
   }
277 277
 
278 278
   // TODO - serialize/unserialize options
@@ -280,14 +280,14 @@  discard block
 block discarded – undo
280 280
     // Если в массиве индекса только один элемент - значит это просто индекс
281 281
     is_array($option_id) && count($option_id) == 1 ? $option_id = reset($option_id) : false;
282 282
 
283
-    if(!isset($this->data[is_array($option_id) ? reset($option_id) : $option_id])) {
283
+    if (!isset($this->data[is_array($option_id) ? reset($option_id) : $option_id])) {
284 284
       $this->load();
285 285
     }
286 286
 
287
-    if(is_array($option_id)) {
287
+    if (is_array($option_id)) {
288 288
       $result = $this->data;
289
-      foreach($option_id as $sub_key) {
290
-        if(!isset($result) || !isset($result[$sub_key])) {
289
+      foreach ($option_id as $sub_key) {
290
+        if (!isset($result) || !isset($result[$sub_key])) {
291 291
           $result = null;
292 292
           break;
293 293
         }
@@ -307,12 +307,12 @@  discard block
 block discarded – undo
307 307
   public function __set($option, $value = null) {
308 308
     global $sn_cache;
309 309
 
310
-    if(empty($option) || !$this->user_id) {
310
+    if (empty($option) || !$this->user_id) {
311 311
       return;
312 312
     }
313 313
 
314 314
     // Если в массиве индекса только один элемент - значит это просто индекс
315
-    if(is_array($option) && count($option) == 1) {
315
+    if (is_array($option) && count($option) == 1) {
316 316
       // Разворачиваем его в индекс
317 317
       $option = array(reset($option) => $value);
318 318
       unset($value);
@@ -321,13 +321,13 @@  discard block
 block discarded – undo
321 321
 
322 322
     $to_write = array();
323 323
     // Адресация многомерного массива через массив индексов в $option
324
-    if(is_array($option) && isset($value)) {
324
+    if (is_array($option) && isset($value)) {
325 325
       $a_data = &$this->data;
326
-      foreach($option as $option_id) {
326
+      foreach ($option as $option_id) {
327 327
         !is_array($a_data[$option_id]) ? $a_data[$option_id] = array() : false;
328 328
         $a_data = &$a_data[$option_id];
329 329
       }
330
-      if($a_data != $value) {
330
+      if ($a_data != $value) {
331 331
         $a_data = $value;
332 332
         $to_write[reset($option)] = null;
333 333
       }
@@ -335,11 +335,11 @@  discard block
 block discarded – undo
335 335
       // Пакетная запись из массива ключ -> значение
336 336
       !is_array($option) ? $option = array($option => $value) : false;
337 337
 
338
-      foreach($option as $option_id => $option_value) {
339
-        if($this->data[$option_id] !== $option_value) {
338
+      foreach ($option as $option_id => $option_value) {
339
+        if ($this->data[$option_id] !== $option_value) {
340 340
           // TODO - вынести отдельно в обработчик
341
-          if($option_id == PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON &&  $option_value == PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON_HIDDEN) {
342
-            sn_setcookie(SN_COOKIE . '_menu_hidden', '0', time() - PERIOD_WEEK, SN_ROOT_RELATIVE);
341
+          if ($option_id == PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON && $option_value == PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON_HIDDEN) {
342
+            sn_setcookie(SN_COOKIE.'_menu_hidden', '0', time() - PERIOD_WEEK, SN_ROOT_RELATIVE);
343 343
           }
344 344
 
345 345
           $this->data[$option_id] = $option_value;
@@ -348,42 +348,42 @@  discard block
 block discarded – undo
348 348
       }
349 349
     }
350 350
 
351
-    if(!empty($to_write)) {
351
+    if (!empty($to_write)) {
352 352
       $field_name = $this->cached_name();
353 353
       $sn_cache->$field_name = $this->data;
354 354
 
355
-      foreach($to_write as $option_id => &$option_value) {
355
+      foreach ($to_write as $option_id => &$option_value) {
356 356
         $option_value = is_array($this->data[$option_id]) ? serialize($this->data[$option_id]) : $this->data[$option_id]; // Сериализация для массивов при сохранении в БД
357
-        $to_write[$option_id] = "({$this->user_id}, '" . db_escape($option_id) . "', '" . db_escape($option_value) . "')";
357
+        $to_write[$option_id] = "({$this->user_id}, '".db_escape($option_id)."', '".db_escape($option_value)."')";
358 358
       }
359 359
 
360
-      doquery("REPLACE INTO {{player_options}} (`player_id`, `option_id`, `value`) VALUES " . implode(',', $to_write));
360
+      doquery("REPLACE INTO {{player_options}} (`player_id`, `option_id`, `value`) VALUES ".implode(',', $to_write));
361 361
     }
362 362
   }
363 363
 
364 364
   protected function load() {
365 365
     global $sn_cache;
366 366
 
367
-    if($this->loaded) {
367
+    if ($this->loaded) {
368 368
       return;
369 369
     }
370 370
 
371 371
     $this->data = $this->defaults;
372 372
 
373
-    if(!$this->user_id) {
373
+    if (!$this->user_id) {
374 374
       return;
375 375
     }
376 376
 
377 377
     $field_name = $this->cached_name();
378 378
     $a_data = $sn_cache->$field_name;
379 379
 
380
-    if(!empty($a_data)) {
380
+    if (!empty($a_data)) {
381 381
       $this->data = array_replace($this->data, $a_data);
382 382
       return;
383 383
     }
384 384
 
385 385
     $query = doquery("SELECT * FROM `{{player_options}}` WHERE `player_id` = {$this->user_id} FOR UPDATE");
386
-    while($row = db_fetch($query)) {
386
+    while ($row = db_fetch($query)) {
387 387
       // $this->data[$row['option_id']] = $row['value'];
388 388
       $this->data[$row['option_id']] = is_string($row['value']) && ($temp = unserialize($row['value'])) !== false ? $temp : $row['value']; // Десериализация
389 389
     }
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
     return $this->__get($offset);
400 400
   }
401 401
   public function offsetSet($offset, $value) {
402
-    if(!is_null($offset)) {
402
+    if (!is_null($offset)) {
403 403
       // $this->data[$offset] = $value;
404 404
       $this->__set($offset, $value);
405 405
     } else {
Please login to merge, or discard this patch.
includes/classes/PlayerToAccountTranslate.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
   protected static $is_init = false;
20 20
 
21 21
   protected static function init() {
22
-    if(!empty(static::$db)) {
22
+    if (!empty(static::$db)) {
23 23
       return;
24 24
     }
25 25
     static::$db = classSupernova::$db;
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
     $provider_id_safe = intval($provider_id_unsafe);
67 67
     !is_array($account_list) ? $account_list = array($account_list) : false;
68 68
 
69
-    foreach($account_list as $provider_account_id_unsafe) {
69
+    foreach ($account_list as $provider_account_id_unsafe) {
70 70
       $provider_account_id_safe = intval($provider_account_id_unsafe);
71 71
 
72 72
       // TODO - Здесь могут отсутствовать аккаунты - проверять провайдером
73 73
       $query = static::$db->doquery("SELECT `user_id` FROM {{account_translate}} WHERE `provider_id` = {$provider_id_safe} AND `provider_account_id` = {$provider_account_id_safe} FOR UPDATE");
74
-      while($row = static::$db->db_fetch($query)) {
74
+      while ($row = static::$db->db_fetch($query)) {
75 75
         $account_translation[$row['user_id']][$provider_id_unsafe][$provider_account_id_unsafe] = true;
76 76
       }
77 77
     }
@@ -88,10 +88,10 @@  discard block
 block discarded – undo
88 88
     $account_translation = array();
89 89
 
90 90
     $query = static::$db->doquery(
91
-      "SELECT * FROM {{account_translate}} WHERE `user_id` = {$user_id_safe} " .
92
-      ($provider_id_unsafe ? "AND `provider_id` = {$provider_id_safe} " : '') .
91
+      "SELECT * FROM {{account_translate}} WHERE `user_id` = {$user_id_safe} ".
92
+      ($provider_id_unsafe ? "AND `provider_id` = {$provider_id_safe} " : '').
93 93
       "ORDER BY `timestamp` FOR UPDATE");
94
-    while($row = static::$db->db_fetch($query)) {
94
+    while ($row = static::$db->db_fetch($query)) {
95 95
       $account_translation[$row['user_id']][$row['provider_id']][$row['provider_account_id']] = $row;
96 96
     }
97 97
 
Please login to merge, or discard this patch.
includes/classes/Account.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -79,8 +79,8 @@  discard block
 block discarded – undo
79 79
     $this->reset();
80 80
     $this->db = is_object($db) ? $db : classSupernova::$db;
81 81
 
82
-    foreach($this->table_check as $table_name) {
83
-      if(empty($this->db->table_list[$table_name])) {
82
+    foreach ($this->table_check as $table_name) {
83
+      if (empty($this->db->table_list[$table_name])) {
84 84
         die('Если вы видите это сообщение первый раз после обновления релиза - просто перегрузите страницу.<br />
85 85
               В противном случае - сообщите Администрации сервера об ошибке.<br/>
86 86
               Не хватает таблицы для работы системы авторизации: ' . $table_name);
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
    */
105 105
   // OK v4.6
106 106
   public function password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe = null) {
107
-    if(!$this->password_check($old_password_unsafe)) {
107
+    if (!$this->password_check($old_password_unsafe)) {
108 108
       return false;
109 109
     }
110 110
 
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
   // OK v4.5
126 126
   public function assign_from_db_row($row) {
127 127
     $this->reset();
128
-    if(empty($row) || !is_array($row)) {
128
+    if (empty($row) || !is_array($row)) {
129 129
       return false;
130 130
     }
131 131
     $this->account_id = $row['account_id'];
@@ -242,11 +242,11 @@  discard block
 block discarded – undo
242 242
         `account_email` = LOWER('{$email_safe}'),
243 243
         `account_language` = '{$language_safe}'"
244 244
     );
245
-    if(!$result) {
245
+    if (!$result) {
246 246
       throw new Exception(REGISTER_ERROR_ACCOUNT_CREATE, ERR_ERROR);
247 247
     }
248 248
 
249
-    if(!($account_id = $this->db->db_insert_id())) {
249
+    if (!($account_id = $this->db->db_insert_id())) {
250 250
       throw new Exception(REGISTER_ERROR_ACCOUNT_CREATE, ERR_ERROR);
251 251
     }
252 252
 
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
       WHERE `account_id` = '{$account_id_safe}'"
277 277
     ) ? true : false;
278 278
 
279
-    if($result) {
279
+    if ($result) {
280 280
       $result = $this->db_get_by_id($this->account_id);
281 281
     }
282 282
 
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
   public function metamatter_change($change_type, $metamatter, $comment = '', $already_changed = false) {
364 364
     global $mm_change_legit;
365 365
 
366
-    if(!$this->is_exists || !($metamatter = round(floatval($metamatter)))) {
366
+    if (!$this->is_exists || !($metamatter = round(floatval($metamatter)))) {
367 367
       classSupernova::$debug->error('Ошибка при попытке манипуляции с ММ');
368 368
 
369 369
       return false;
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
 
374 374
     $mm_change_legit = true;
375 375
     // $sn_data_metamatter_db_name = pname_resource_name(RES_METAMATTER);
376
-    if($already_changed) {
376
+    if ($already_changed) {
377 377
       $metamatter_total_delta = 0;
378 378
       $result = -1;
379 379
     } else {
@@ -383,17 +383,17 @@  discard block
 block discarded – undo
383 383
       $result = $this->db->doquery(
384 384
         "UPDATE {{account}}
385 385
         SET
386
-          `account_metamatter` = `account_metamatter` + '{$metamatter}'" .
387
-        ($metamatter_total_delta ? ", `account_immortal` = IF(`account_metamatter_total` + '{$metamatter_total_delta}' >= {$classConfig->player_metamatter_immortal}, NOW(), `account_immortal`), `account_metamatter_total` = `account_metamatter_total` + '{$metamatter_total_delta}'" : '') .
386
+          `account_metamatter` = `account_metamatter` + '{$metamatter}'".
387
+        ($metamatter_total_delta ? ", `account_immortal` = IF(`account_metamatter_total` + '{$metamatter_total_delta}' >= {$classConfig->player_metamatter_immortal}, NOW(), `account_immortal`), `account_metamatter_total` = `account_metamatter_total` + '{$metamatter_total_delta}'" : '').
388 388
         " WHERE `account_id` = {$account_id_safe}"
389 389
       );
390
-      if(!$result) {
390
+      if (!$result) {
391 391
         classSupernova::$debug->error("Error adjusting Metamatter for player ID {$this->account_id} (Player Not Found?) with {$metamatter}. Reason: {$comment}", 'Metamatter Change', 402);
392 392
       }
393 393
       $result = classSupernova::$db->db_affected_rows();
394 394
     }
395 395
 
396
-    if(empty(core_auth::$user['id'])) {
396
+    if (empty(core_auth::$user['id'])) {
397 397
       $user_list = PlayerToAccountTranslate::db_translate_get_users_from_account_list(core_auth::$main_provider->provider_id, $this->account_id);
398 398
       reset($user_list);
399 399
       $user_id_unsafe = key($user_list);
@@ -402,30 +402,30 @@  discard block
 block discarded – undo
402 402
     }
403 403
     $user_id_safe = $this->db->db_escape($user_id_unsafe);
404 404
 
405
-    if(!$result) {
405
+    if (!$result) {
406 406
       classSupernova::$debug->error("Error adjusting Metamatter for player ID {$this->account_id} (Player Not Found?) with {$metamatter}. Reason: {$comment}", 'Metamatter Change', 402);
407 407
     }
408 408
 
409
-    if(!$already_changed) {
409
+    if (!$already_changed) {
410 410
       $this->account_metamatter += $metamatter;
411 411
       $this->account_metamatter_total += $metamatter_total_delta;
412 412
     }
413 413
 
414
-    if(is_array($comment)) {
414
+    if (is_array($comment)) {
415 415
       $comment = call_user_func_array('sprintf', $comment);
416 416
     }
417 417
 
418 418
     $result = $this->db_mm_log_insert($comment, $change_type, $metamatter, $user_id_unsafe);
419 419
 
420
-    if($metamatter > 0 && !empty($user_id_safe)) {
420
+    if ($metamatter > 0 && !empty($user_id_safe)) {
421 421
       $old_referral = db_referral_get_by_id($user_id_safe);
422
-      if($old_referral['id']) {
422
+      if ($old_referral['id']) {
423 423
         $dark_matter_from_metamatter = $metamatter * AFFILIATE_MM_TO_REFERRAL_DM;
424 424
         db_referral_update_dm($user_id_safe, $dark_matter_from_metamatter);
425 425
         $new_referral = db_referral_get_by_id($user_id_safe);
426 426
 
427 427
         $partner_bonus = floor($new_referral['dark_matter'] / classSupernova::$config->rpg_bonus_divisor) - ($old_referral['dark_matter'] >= classSupernova::$config->rpg_bonus_minimum ? floor($old_referral['dark_matter'] / classSupernova::$config->rpg_bonus_divisor) : 0);
428
-        if($partner_bonus > 0 && $new_referral['dark_matter'] >= classSupernova::$config->rpg_bonus_minimum) {
428
+        if ($partner_bonus > 0 && $new_referral['dark_matter'] >= classSupernova::$config->rpg_bonus_minimum) {
429 429
           rpg_points_change($new_referral['id_partner'], RPG_REFERRAL_BOUGHT_MM, $partner_bonus, "Incoming MM From Referral ID {$user_id_safe}");
430 430
         }
431 431
       }
Please login to merge, or discard this patch.
includes/classes/auth_local.php 1 patch
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -136,12 +136,12 @@  discard block
 block discarded – undo
136 136
     $this->prepare();
137 137
 
138 138
     $this->manifest['active'] = false;
139
-    if(!empty($this->config) && is_array($this->config['db'])) {
139
+    if (!empty($this->config) && is_array($this->config['db'])) {
140 140
       // БД, отличная от стандартной
141 141
       $this->db = new db_mysql();
142 142
 
143 143
       $this->db->sn_db_connect($this->config['db']);
144
-      if($this->manifest['active'] = $this->db->connected) {
144
+      if ($this->manifest['active'] = $this->db->connected) {
145 145
         $this->provider_id = ACCOUNT_PROVIDER_CENTRAL;
146 146
 
147 147
         $this->domain = $this->config['domain'];
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
     }
156 156
 
157 157
     // Fallback to local DB
158
-    if(!$this->manifest['active']) {
158
+    if (!$this->manifest['active']) {
159 159
       $this->db = classSupernova::$db;
160 160
 
161 161
       $this->provider_id = ACCOUNT_PROVIDER_LOCAL;
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
       $this->manifest['active'] = true;
169 169
     }
170 170
 
171
-    $this->cookie_name_impersonate = $this->cookie_name . AUTH_COOKIE_IMPERSONATE_SUFFIX;
171
+    $this->cookie_name_impersonate = $this->cookie_name.AUTH_COOKIE_IMPERSONATE_SUFFIX;
172 172
 
173 173
     $this->account = new Account($this->db);
174 174
     $this->confirmation = new Confirmation($this->db);
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
   // OK v4.5
212 212
   public function password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe = null) {
213 213
     $result = parent::password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe);
214
-    if($result) {
214
+    if ($result) {
215 215
       $this->cookie_set();
216 216
     }
217 217
 
@@ -239,12 +239,12 @@  discard block
 block discarded – undo
239 239
    */
240 240
   // OK v4.6
241 241
   protected function password_reset_send_code() {
242
-    if(!$this->is_password_reset) {
242
+    if (!$this->is_password_reset) {
243 243
       return $this->account_login_status;
244 244
     }
245 245
 
246 246
     // Проверяем поддержку сброса пароля
247
-    if(!$this->is_feature_supported(AUTH_FEATURE_PASSWORD_RESET)) {
247
+    if (!$this->is_feature_supported(AUTH_FEATURE_PASSWORD_RESET)) {
248 248
       return $this->account_login_status;
249 249
     }
250 250
 
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
       unset($this->account);
255 255
       $this->account = new Account($this->db);
256 256
 
257
-      if(!$this->account->db_get_by_email($email_unsafe)) {
257
+      if (!$this->account->db_get_by_email($email_unsafe)) {
258 258
         throw new Exception(PASSWORD_RESTORE_ERROR_EMAIL_NOT_EXISTS, ERR_ERROR);
259 259
         // return $this->account_login_status;
260 260
       }
@@ -264,14 +264,14 @@  discard block
 block discarded – undo
264 264
 
265 265
       // TODO - Проверять уровень доступа аккаунта!
266 266
       // Аккаунты с АУТЛЕВЕЛ больше 0 - НЕ СБРАСЫВАЮТ ПАРОЛИ!
267
-      foreach($user_list as $user_id => $user_data) {
268
-        if($user_data['authlevel'] > AUTH_LEVEL_REGISTERED) {
267
+      foreach ($user_list as $user_id => $user_data) {
268
+        if ($user_data['authlevel'] > AUTH_LEVEL_REGISTERED) {
269 269
           throw new Exception(PASSWORD_RESTORE_ERROR_ADMIN_ACCOUNT, ERR_ERROR);
270 270
         }
271 271
       }
272 272
 
273 273
       $confirmation = $this->confirmation->db_confirmation_get_latest_by_type_and_email(CONFIRM_PASSWORD_RESET, $email_unsafe); // OK 4.5
274
-      if(isset($confirmation['create_time']) && SN_TIME_NOW - strtotime($confirmation['create_time']) < PERIOD_MINUTE_10) {
274
+      if (isset($confirmation['create_time']) && SN_TIME_NOW - strtotime($confirmation['create_time']) < PERIOD_MINUTE_10) {
275 275
         throw new Exception(PASSWORD_RESTORE_ERROR_TOO_OFTEN, ERR_ERROR);
276 276
       }
277 277
 
@@ -284,11 +284,11 @@  discard block
 block discarded – undo
284 284
 
285 285
       @$result = mymail($email_unsafe,
286 286
         sprintf(classLocale::$lang['log_lost_email_title'], classSupernova::$config->game_name),
287
-        sprintf(classLocale::$lang['log_lost_email_code'], SN_ROOT_VIRTUAL . 'login.php', $confirm_code_unsafe, date(FMT_DATE_TIME, SN_TIME_NOW + AUTH_PASSWORD_RESET_CONFIRMATION_EXPIRE), classSupernova::$config->game_name)
287
+        sprintf(classLocale::$lang['log_lost_email_code'], SN_ROOT_VIRTUAL.'login.php', $confirm_code_unsafe, date(FMT_DATE_TIME, SN_TIME_NOW + AUTH_PASSWORD_RESET_CONFIRMATION_EXPIRE), classSupernova::$config->game_name)
288 288
       );
289 289
 
290 290
       $result = $result ? PASSWORD_RESTORE_SUCCESS_CODE_SENT : PASSWORD_RESTORE_ERROR_SENDING;
291
-    } catch(Exception $e) {
291
+    } catch (Exception $e) {
292 292
       sn_db_transaction_rollback();
293 293
       $result = $e->getMessage();
294 294
     }
@@ -301,46 +301,46 @@  discard block
 block discarded – undo
301 301
    * @return int|string
302 302
    */
303 303
   protected function password_reset_confirm() {
304
-    if(!$this->is_password_reset_confirm) {
304
+    if (!$this->is_password_reset_confirm) {
305 305
       return $this->account_login_status;
306 306
     }
307 307
 
308
-    if($this->account_login_status != LOGIN_UNDEFINED) {
308
+    if ($this->account_login_status != LOGIN_UNDEFINED) {
309 309
       return $this->account_login_status;
310 310
     }
311 311
 
312 312
     // Проверяем поддержку сброса пароля
313
-    if(!$this->is_feature_supported(AUTH_FEATURE_PASSWORD_RESET)) {
313
+    if (!$this->is_feature_supported(AUTH_FEATURE_PASSWORD_RESET)) {
314 314
       return $this->account_login_status;
315 315
     }
316 316
 
317 317
     try {
318 318
       $code_unsafe = sys_get_param_str_unsafe('password_reset_code');
319
-      if(empty($code_unsafe)) {
319
+      if (empty($code_unsafe)) {
320 320
         throw new Exception(PASSWORD_RESTORE_ERROR_CODE_EMPTY, ERR_ERROR);
321 321
       }
322 322
 
323 323
       sn_db_transaction_start();
324 324
       $confirmation = $this->confirmation->db_confirmation_get_by_type_and_code(CONFIRM_PASSWORD_RESET, $code_unsafe); // OK 4.5
325 325
 
326
-      if(empty($confirmation)) {
326
+      if (empty($confirmation)) {
327 327
         throw new Exception(PASSWORD_RESTORE_ERROR_CODE_WRONG, ERR_ERROR);
328 328
       }
329 329
 
330
-      if(SN_TIME_NOW - strtotime($confirmation['create_time']) > AUTH_PASSWORD_RESET_CONFIRMATION_EXPIRE) {
330
+      if (SN_TIME_NOW - strtotime($confirmation['create_time']) > AUTH_PASSWORD_RESET_CONFIRMATION_EXPIRE) {
331 331
         throw new Exception(PASSWORD_RESTORE_ERROR_CODE_TOO_OLD, ERR_ERROR);
332 332
       }
333 333
 
334 334
       unset($this->account);
335 335
       $this->account = new Account($this->db);
336 336
 
337
-      if(!$this->account->db_get_by_email($confirmation['email'])) {
337
+      if (!$this->account->db_get_by_email($confirmation['email'])) {
338 338
         throw new Exception(PASSWORD_RESTORE_ERROR_CODE_OK_BUT_NO_ACCOUNT_FOR_EMAIL, ERR_ERROR);
339 339
       }
340 340
 
341 341
       $new_password_unsafe = $this->make_random_password();
342 342
       $salt_unsafe = $this->password_salt_generate();
343
-      if(!$this->account->db_set_password($new_password_unsafe, $salt_unsafe)) {
343
+      if (!$this->account->db_set_password($new_password_unsafe, $salt_unsafe)) {
344 344
         // Ошибка смены пароля
345 345
         throw new Exception(AUTH_ERROR_INTERNAL_PASSWORD_CHANGE_ON_RESTORE, ERR_ERROR);
346 346
       }
@@ -350,14 +350,14 @@  discard block
 block discarded – undo
350 350
       $this->cookie_set();
351 351
       $this->login_cookie();
352 352
 
353
-      if($this->account_login_status == LOGIN_SUCCESS) {
353
+      if ($this->account_login_status == LOGIN_SUCCESS) {
354 354
         // TODO - НЕ ОБЯЗАТЕЛЬНО ОТПРАВЛЯТЬ ЧЕРЕЗ ЕМЕЙЛ! ЕСЛИ ЭТО ФЕЙСБУЧЕК ИЛИ ВКШЕЧКА - МОЖНО ЧЕРЕЗ ЛС ПИСАТЬ!!
355 355
         $message_header = sprintf(classLocale::$lang['log_lost_email_title'], classSupernova::$config->game_name);
356 356
         $message = sprintf(classLocale::$lang['log_lost_email_pass'], classSupernova::$config->game_name, $this->account->account_name, $new_password_unsafe);
357 357
         @$operation_result = mymail($confirmation['email'], $message_header, htmlspecialchars($message));
358 358
 
359 359
         $users_translated = PlayerToAccountTranslate::db_translate_get_users_from_account_list($this->provider_id, $this->account->account_id); // OK 4.5
360
-        if(!empty($users_translated)) {
360
+        if (!empty($users_translated)) {
361 361
           // Отправляем в лички письмо о сбросе пароля
362 362
 
363 363
           // ПО ОПРЕДЕЛЕНИЮ в $users_translated только
@@ -366,9 +366,9 @@  discard block
 block discarded – undo
366 366
           //    - игроки, привязанные только к этим аккаунтам
367 367
           // Значит им всем сразу скопом можно отправлять сообщения
368 368
           $message = sprintf(classLocale::$lang['sys_password_reset_message_body'], $new_password_unsafe);
369
-          $message = sys_bbcodeParse($message) . '<br><br>';
369
+          $message = sys_bbcodeParse($message).'<br><br>';
370 370
 
371
-          foreach($users_translated as $user_id => $providers_list) {
371
+          foreach ($users_translated as $user_id => $providers_list) {
372 372
             msg_send_simple_message($user_id, 0, SN_TIME_NOW, MSG_TYPE_ADMIN, classLocale::$lang['sys_administration'], classLocale::$lang['sys_login_register_message_title'], $message);
373 373
           }
374 374
         } else {
@@ -420,10 +420,10 @@  discard block
 block discarded – undo
420 420
   // OK v4.5
421 421
   protected function register() {
422 422
     // TODO РЕГИСТРАЦИЯ ВСЕГДА ДОЛЖНА ЛОГИНИТЬ ПОЛЬЗОВАТЕЛЯ!
423
-    $this->flog('Регистрация: начинаем. Провайдер ' . $this->provider_id);
423
+    $this->flog('Регистрация: начинаем. Провайдер '.$this->provider_id);
424 424
 
425 425
     try {
426
-      if(!$this->is_register) {
426
+      if (!$this->is_register) {
427 427
         $this->flog('Регистрация: не выставлен флаг регистрации - пропускаем');
428 428
         throw new Exception(LOGIN_UNDEFINED, ERR_ERROR);
429 429
       }
@@ -435,8 +435,8 @@  discard block
 block discarded – undo
435 435
       // $this->account_check_duplicate_name_or_email($this->input_login_unsafe, $this->input_email_unsafe);
436 436
 
437 437
       $this->account->db_get_by_name_or_email($this->input_login_unsafe, $this->input_email_unsafe);
438
-      if($this->account->is_exists) {
439
-        if($this->account->account_email == $this->input_email_unsafe) {
438
+      if ($this->account->is_exists) {
439
+        if ($this->account->account_email == $this->input_email_unsafe) {
440 440
           throw new Exception(REGISTER_ERROR_EMAIL_EXISTS, ERR_ERROR);
441 441
         } else {
442 442
           throw new Exception(REGISTER_ERROR_ACCOUNT_NAME_EXISTS, ERR_ERROR);
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
       // А вот это пока не нужно. Трансляцией аккаунтов в юзеров и созданием новых юзеров для новозашедших аккаунтов занимается Auth
476 476
       // $this->register_account();
477 477
       sn_db_transaction_commit();
478
-    } catch(Exception $e) {
478
+    } catch (Exception $e) {
479 479
       sn_db_transaction_rollback();
480 480
       $this->account_login_status == LOGIN_UNDEFINED ? $this->account_login_status = $e->getMessage() : false;
481 481
     }
@@ -491,15 +491,15 @@  discard block
 block discarded – undo
491 491
    */
492 492
   // OK v4.5
493 493
   protected function login_cookie() {
494
-    if($this->account_login_status != LOGIN_UNDEFINED) {
494
+    if ($this->account_login_status != LOGIN_UNDEFINED) {
495 495
       return $this->account_login_status;
496 496
     }
497 497
 
498 498
     // Пытаемся войти по куке
499
-    if(!empty($_COOKIE[$this->cookie_name])) {
499
+    if (!empty($_COOKIE[$this->cookie_name])) {
500 500
 // Кто хотел - уже сконвертировал старые куки в новые
501 501
 // Update оказывается - не все...
502
-      if(count(explode("/%/", $_COOKIE[$this->cookie_name])) < 4) {
502
+      if (count(explode("/%/", $_COOKIE[$this->cookie_name])) < 4) {
503 503
         list($account_id_unsafe, $cookie_password_hash_salted, $user_remember_me) = explode(AUTH_COOKIE_DELIMETER, $_COOKIE[$this->cookie_name]);
504 504
       } else {
505 505
         list($account_id_unsafe, $user_name, $cookie_password_hash_salted, $user_remember_me) = explode("/%/", $_COOKIE[$this->cookie_name]);
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
 
508 508
       // $account = $this->db_account_get_by_id($account_id_unsafe);
509 509
 
510
-      if(
510
+      if (
511 511
         $this->account->db_get_by_id($account_id_unsafe)
512 512
         && ($this->password_encode_for_cookie($this->account->account_password) == $cookie_password_hash_salted)
513 513
       ) {
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
       }
518 518
     }
519 519
 
520
-    if($this->account_login_status != LOGIN_SUCCESS) {
520
+    if ($this->account_login_status != LOGIN_SUCCESS) {
521 521
       // Невалидная кука - чистим
522 522
       $this->cookie_clear();
523 523
     }
@@ -535,13 +535,13 @@  discard block
 block discarded – undo
535 535
   protected function login_username() {
536 536
     // TODO - Логин по старым именам
537 537
     try {
538
-      if(!$this->is_login) {
538
+      if (!$this->is_login) {
539 539
         $this->flog('Логин: не выставлен флаг входа в игру - это не логин');
540 540
         throw new Exception(LOGIN_UNDEFINED, ERR_ERROR);
541 541
       }
542 542
 
543 543
       // TODO Пустое имя аккаунта
544
-      if(!$this->input_login_unsafe) {
544
+      if (!$this->input_login_unsafe) {
545 545
         throw new Exception(LOGIN_UNDEFINED, ERR_ERROR);
546 546
       }
547 547
 
@@ -551,11 +551,11 @@  discard block
 block discarded – undo
551 551
 //      if(empty($account)) {
552 552
 //        throw new Exception(LOGIN_ERROR_USERNAME, ERR_ERROR);
553 553
 //      }
554
-      if(!$this->account->db_get_by_name($this->input_login_unsafe) && !$this->account->db_get_by_email($this->input_login_unsafe)) {
554
+      if (!$this->account->db_get_by_name($this->input_login_unsafe) && !$this->account->db_get_by_email($this->input_login_unsafe)) {
555 555
         throw new Exception(LOGIN_ERROR_USERNAME, ERR_ERROR);
556 556
       }
557 557
 
558
-      if(!$this->account->password_check($this->input_login_password_raw)) {
558
+      if (!$this->account->password_check($this->input_login_password_raw)) {
559 559
         throw new Exception(LOGIN_ERROR_PASSWORD, ERR_ERROR);
560 560
       }
561 561
 
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
 
564 564
       $this->cookie_set();
565 565
       $this->account_login_status = LOGIN_SUCCESS;
566
-    } catch(Exception $e) {
566
+    } catch (Exception $e) {
567 567
       $this->account_login_status == LOGIN_UNDEFINED ? $this->account_login_status = $e->getMessage() : false;
568 568
     }
569 569
 
@@ -585,18 +585,18 @@  discard block
 block discarded – undo
585 585
   protected function cookie_set($account_to_impersonate = null) {
586 586
     $this_account = is_object($account_to_impersonate) ? $account_to_impersonate : $this->account;
587 587
 
588
-    if(!is_object($this_account) || !$this_account->is_exists) {
588
+    if (!is_object($this_account) || !$this_account->is_exists) {
589 589
       throw new Exception(LOGIN_ERROR_NO_ACCOUNT_FOR_COOKIE_SET, ERR_ERROR);
590 590
     }
591 591
 
592
-    if(is_object($account_to_impersonate) && $account_to_impersonate->is_exists) {
592
+    if (is_object($account_to_impersonate) && $account_to_impersonate->is_exists) {
593 593
       sn_setcookie($this->cookie_name_impersonate, $_COOKIE[$this->cookie_name], SN_TIME_NOW + PERIOD_YEAR, $this->sn_root_path, $this->domain);
594 594
     }
595 595
 
596 596
     $expire_time = $this->remember_me ? SN_TIME_NOW + PERIOD_YEAR : 0;
597 597
 
598 598
     $password_encoded = $this->password_encode_for_cookie($this_account->account_password);
599
-    $cookie = $this_account->account_id . AUTH_COOKIE_DELIMETER . $password_encoded . AUTH_COOKIE_DELIMETER . $this->remember_me;
599
+    $cookie = $this_account->account_id.AUTH_COOKIE_DELIMETER.$password_encoded.AUTH_COOKIE_DELIMETER.$this->remember_me;
600 600
     $this->flog("cookie_set() - Устанавливаем куку {$cookie}");
601 601
     return sn_setcookie($this->cookie_name, $cookie, $expire_time, $this->sn_root_path, $this->domain);
602 602
   }
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
   // OK v4.1
608 608
   protected function cookie_clear() {
609 609
     // Автоматически вообще-то - если установлена кука имперсонатора - то чистим обычную, а куку имперсонатора - копируем в неё
610
-    if(!empty($_COOKIE[$this->cookie_name_impersonate])) {
610
+    if (!empty($_COOKIE[$this->cookie_name_impersonate])) {
611 611
       sn_setcookie($this->cookie_name, $_COOKIE[$this->cookie_name_impersonate], SN_TIME_NOW + PERIOD_YEAR, $this->sn_root_path, $this->domain);
612 612
       sn_setcookie($this->cookie_name_impersonate, '', SN_TIME_NOW - PERIOD_WEEK, $this->sn_root_path, $this->domain);
613 613
     } else {
@@ -626,10 +626,10 @@  discard block
 block discarded – undo
626 626
   protected function login_validate_input() {
627 627
     // Проверяем, что бы в начале и конце не было пустых символов
628 628
     // TODO - при копировании Эксель -> Опера - в конце образуются пустые места. Это не должно быть проблемой! Вынести проверку пароля в регистрацию!
629
-    if($this->input_login_password_raw != trim($this->input_login_password_raw)) {
629
+    if ($this->input_login_password_raw != trim($this->input_login_password_raw)) {
630 630
       throw new Exception(LOGIN_ERROR_PASSWORD_TRIMMED, ERR_ERROR);
631 631
     }
632
-    if(!$this->input_login_password_raw) {
632
+    if (!$this->input_login_password_raw) {
633 633
       throw new Exception(LOGIN_ERROR_PASSWORD_EMPTY, ERR_ERROR);
634 634
     }
635 635
   }
@@ -645,37 +645,37 @@  discard block
 block discarded – undo
645 645
     $this->login_validate_input();
646 646
 
647 647
     // Если нет имени пользователя - NO GO!
648
-    if(!$this->input_login_unsafe) {
648
+    if (!$this->input_login_unsafe) {
649 649
       throw new Exception(LOGIN_ERROR_USERNAME_EMPTY, ERR_ERROR);
650 650
     }
651 651
     // Если логин имеет запрещенные символы - NO GO!
652
-    if(strpbrk($this->input_login_unsafe, LOGIN_REGISTER_CHARACTERS_PROHIBITED)) {
652
+    if (strpbrk($this->input_login_unsafe, LOGIN_REGISTER_CHARACTERS_PROHIBITED)) {
653 653
       throw new Exception(LOGIN_ERROR_USERNAME_RESTRICTED_CHARACTERS, ERR_ERROR);
654 654
     }
655 655
     // Если логин меньше минимальной длины - NO GO!
656
-    if(strlen($this->input_login_unsafe) < LOGIN_LENGTH_MIN) {
656
+    if (strlen($this->input_login_unsafe) < LOGIN_LENGTH_MIN) {
657 657
       throw new Exception(REGISTER_ERROR_USERNAME_SHORT, ERR_ERROR);
658 658
     }
659 659
     // Если пароль меньше минимальной длины - NO GO!
660
-    if(strlen($this->input_login_password_raw) < PASSWORD_LENGTH_MIN) {
660
+    if (strlen($this->input_login_password_raw) < PASSWORD_LENGTH_MIN) {
661 661
       throw new Exception(REGISTER_ERROR_PASSWORD_INSECURE, ERR_ERROR);
662 662
     }
663 663
     // Если пароль имеет пробельные символы в начале или конце - NO GO!
664
-    if($this->input_login_password_raw != trim($this->input_login_password_raw)) {
664
+    if ($this->input_login_password_raw != trim($this->input_login_password_raw)) {
665 665
       throw new Exception(LOGIN_ERROR_PASSWORD_TRIMMED, ERR_ERROR);
666 666
     }
667 667
     // Если пароль не совпадает с подтверждением - NO GO! То, что у пароля нет пробельных символов в начале/конце - мы уже проверили выше
668 668
     //Если они есть у повтора - значит пароль и повтор не совпадут
669
-    if($this->input_login_password_raw <> $this->input_login_password_raw_repeat) {
669
+    if ($this->input_login_password_raw <> $this->input_login_password_raw_repeat) {
670 670
       throw new Exception(REGISTER_ERROR_PASSWORD_DIFFERENT, ERR_ERROR);
671 671
     }
672 672
     // Если нет емейла - NO GO!
673 673
     // TODO - регистрация без емейла
674
-    if(!$this->input_email_unsafe) {
674
+    if (!$this->input_email_unsafe) {
675 675
       throw new Exception(REGISTER_ERROR_EMAIL_EMPTY, ERR_ERROR);
676 676
     }
677 677
     // Если емейл не является емейлом - NO GO!
678
-    if(!is_email($this->input_email_unsafe)) {
678
+    if (!is_email($this->input_email_unsafe)) {
679 679
       throw new Exception(REGISTER_ERROR_EMAIL_WRONG, ERR_ERROR);
680 680
     }
681 681
   }
@@ -684,7 +684,7 @@  discard block
 block discarded – undo
684 684
 
685 685
   // OK v4
686 686
   protected function password_encode_for_cookie($password) {
687
-    return md5("{$password}--" . $this->secret_word);
687
+    return md5("{$password}--".$this->secret_word);
688 688
   }
689 689
   // OK v4
690 690
   protected function password_encode($password, $salt) {
@@ -708,26 +708,26 @@  discard block
 block discarded – undo
708 708
     return core_auth::make_random_password();
709 709
   }
710 710
   protected function flog($message, $die = false) {
711
-    if(!defined('DEBUG_AUTH') || !DEBUG_AUTH) {
711
+    if (!defined('DEBUG_AUTH') || !DEBUG_AUTH) {
712 712
       return;
713 713
     }
714 714
     list($called, $caller) = debug_backtrace(false);
715 715
 
716 716
     $caller_name =
717
-      ((get_called_class()) ? get_called_class() : (!empty($caller['class']) ? $caller['class'] : '')) .
718
-      (!empty($caller['type']) ? $caller['type'] : '') .
719
-      (!empty($caller['function']) ? $caller['function'] : '') .
720
-      (!empty($called['line']) ? ':' . $called['line'] : '');
717
+      ((get_called_class()) ? get_called_class() : (!empty($caller['class']) ? $caller['class'] : '')).
718
+      (!empty($caller['type']) ? $caller['type'] : '').
719
+      (!empty($caller['function']) ? $caller['function'] : '').
720
+      (!empty($called['line']) ? ':'.$called['line'] : '');
721 721
 
722 722
 //     $real_caller_class = get_called_class();
723 723
 
724 724
     $_SERVER['SERVER_NAME'] == 'localhost' ? print("<div class='debug'>$message - $caller_name\r\n</div>") : false;
725 725
 
726 726
     classSupernova::log_file("$message - $caller_name");
727
-    if($die) {
727
+    if ($die) {
728 728
       // pdump($caller);
729 729
       // pdump(debug_backtrace(false));
730
-      $die && die("<div class='negative'>СТОП! Функция {$caller_name} при вызове в " . get_called_class() . " (располагается в " . get_class() . "). СООБЩИТЕ АДМИНИСТРАЦИИ!</div>");
730
+      $die && die("<div class='negative'>СТОП! Функция {$caller_name} при вызове в ".get_called_class()." (располагается в ".get_class()."). СООБЩИТЕ АДМИНИСТРАЦИИ!</div>");
731 731
     }
732 732
   }
733 733
 
Please login to merge, or discard this patch.