Completed
Branch work-fleets (23812c)
by SuperNova.WS
13:52
created
includes/classes/Account.php 2 patches
Doc Comments   +20 added lines patch added patch discarded remove patch
@@ -169,6 +169,10 @@  discard block
 block discarded – undo
169 169
    * @return bool
170 170
    */
171 171
   // OK v4.5
172
+
173
+  /**
174
+   * @param string $account_name_unsafe
175
+   */
172 176
   public function db_get_by_name($account_name_unsafe) {
173 177
     $this->reset();
174 178
 
@@ -203,6 +207,11 @@  discard block
 block discarded – undo
203 207
    *
204 208
    */
205 209
   // OK v4.5
210
+
211
+  /**
212
+   * @param string $account_name_unsafe
213
+   * @param string $email_unsafe
214
+   */
206 215
   public function db_get_by_name_or_email($account_name_unsafe, $email_unsafe) {
207 216
     $this->reset();
208 217
 
@@ -218,6 +227,13 @@  discard block
 block discarded – undo
218 227
    * @throws Exception
219 228
    */
220 229
   // OK v4.5
230
+
231
+  /**
232
+   * @param string $account_name_unsafe
233
+   * @param string $password_raw
234
+   * @param string $email_unsafe
235
+   * @param string $language_unsafe
236
+   */
221 237
   public function db_create($account_name_unsafe, $password_raw, $email_unsafe, $language_unsafe = null, $salt_unsafe = null) {
222 238
     $this->reset();
223 239
 
@@ -312,6 +328,10 @@  discard block
 block discarded – undo
312 328
    * @return int|string
313 329
    */
314 330
   // OK 4.8
331
+
332
+  /**
333
+   * @param double $metamatter
334
+   */
315 335
   protected function db_mm_log_insert($comment, $change_type, $metamatter, $user_id_unsafe) {
316 336
     $provider_id_safe = intval(core_auth::$main_provider->provider_id);
317 337
     //$account_id_safe = $this->db->db_escape($this->account_id);
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -78,8 +78,8 @@  discard block
 block discarded – undo
78 78
     $this->reset();
79 79
     $this->db = is_object($db) ? $db : classSupernova::$db;
80 80
 
81
-    foreach($this->table_check as $table_name) {
82
-      if(empty($this->db->table_list[$table_name])) {
81
+    foreach ($this->table_check as $table_name) {
82
+      if (empty($this->db->table_list[$table_name])) {
83 83
         die('Если вы видите это сообщение первый раз после обновления релиза - просто перегрузите страницу.<br />
84 84
               В противном случае - сообщите Администрации сервера об ошибке.<br/>
85 85
               Не хватает таблицы для работы системы авторизации: ' . $table_name);
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
    */
104 104
   // OK v4.6
105 105
   public function password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe = null) {
106
-    if(!$this->password_check($old_password_unsafe)) {
106
+    if (!$this->password_check($old_password_unsafe)) {
107 107
       return false;
108 108
     }
109 109
 
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
   // OK v4.5
125 125
   public function assign_from_db_row($row) {
126 126
     $this->reset();
127
-    if(empty($row) || !is_array($row)) {
127
+    if (empty($row) || !is_array($row)) {
128 128
       return false;
129 129
     }
130 130
     $this->account_id = $row['account_id'];
@@ -237,11 +237,11 @@  discard block
 block discarded – undo
237 237
         `account_email` = LOWER('{$email_safe}'),
238 238
         `account_language` = '{$language_safe}'"
239 239
     );
240
-    if(!$result) {
240
+    if (!$result) {
241 241
       throw new Exception(REGISTER_ERROR_ACCOUNT_CREATE, ERR_ERROR);
242 242
     }
243 243
 
244
-    if(!($account_id = $this->db->db_insert_id())) {
244
+    if (!($account_id = $this->db->db_insert_id())) {
245 245
       throw new Exception(REGISTER_ERROR_ACCOUNT_CREATE, ERR_ERROR);
246 246
     }
247 247
 
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
       WHERE `account_id` = '{$account_id_safe}'"
272 272
     ) ? true : false;
273 273
 
274
-    if($result) {
274
+    if ($result) {
275 275
       $result = $this->db_get_by_id($this->account_id);
276 276
     }
277 277
 
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
   public function metamatter_change($change_type, $metamatter, $comment = false, $already_changed = false) {
352 352
     global $debug, $mm_change_legit, $config;
353 353
 
354
-    if(!$this->is_exists || !($metamatter = round(floatval($metamatter)))) {
354
+    if (!$this->is_exists || !($metamatter = round(floatval($metamatter)))) {
355 355
       $debug->error('Ошибка при попытке манипуляции с ММ');
356 356
       return false;
357 357
     }
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
 
361 361
     $mm_change_legit = true;
362 362
     // $sn_data_metamatter_db_name = pname_resource_name(RES_METAMATTER);
363
-    if($already_changed) {
363
+    if ($already_changed) {
364 364
       $metamatter_total_delta = 0;
365 365
       $result = -1;
366 366
     } else {
@@ -373,13 +373,13 @@  discard block
 block discarded – undo
373 373
           ($metamatter_total_delta ? ", `account_immortal` = IF(`account_metamatter_total` + '{$metamatter_total_delta}' >= {$config->player_metamatter_immortal}, NOW(), `account_immortal`), `account_metamatter_total` = `account_metamatter_total` + '{$metamatter_total_delta}'" : '') .
374 374
         " WHERE `account_id` = {$account_id_safe}"
375 375
       );
376
-      if(!$result) {
376
+      if (!$result) {
377 377
         $debug->error("Error adjusting Metamatter for player ID {$this->account_id} (Player Not Found?) with {$metamatter}. Reason: {$comment}", 'Metamatter Change', 402);
378 378
       }
379 379
       $result = classSupernova::$db->db_affected_rows();
380 380
     }
381 381
 
382
-    if(empty(core_auth::$user['id'])) {
382
+    if (empty(core_auth::$user['id'])) {
383 383
       $user_list = PlayerToAccountTranslate::db_translate_get_users_from_account_list(core_auth::$main_provider->provider_id, $this->account_id);
384 384
       reset($user_list);
385 385
       $user_id_unsafe = key($user_list);
@@ -388,30 +388,30 @@  discard block
 block discarded – undo
388 388
     }
389 389
     $user_id_safe = $this->db->db_escape($user_id_unsafe);
390 390
 
391
-    if(!$result) {
391
+    if (!$result) {
392 392
       $debug->error("Error adjusting Metamatter for player ID {$this->account_id} (Player Not Found?) with {$metamatter}. Reason: {$comment}", 'Metamatter Change', 402);
393 393
     }
394 394
 
395
-    if(!$already_changed) {
395
+    if (!$already_changed) {
396 396
       $this->account_metamatter += $metamatter;
397 397
       $this->account_metamatter_total += $metamatter_total_delta;
398 398
     }
399 399
 
400
-    if(is_array($comment)) {
400
+    if (is_array($comment)) {
401 401
       $comment = call_user_func_array('sprintf', $comment);
402 402
     }
403 403
 
404 404
     $result = $this->db_mm_log_insert($comment, $change_type, $metamatter, $user_id_unsafe);
405 405
 
406
-    if($metamatter > 0 && !empty($user_id_safe)) {
406
+    if ($metamatter > 0 && !empty($user_id_safe)) {
407 407
       $old_referral = doquery("SELECT * FROM {{referrals}} WHERE `id` = {$user_id_safe} LIMIT 1 FOR UPDATE;", '', true);
408
-      if($old_referral['id']) {
408
+      if ($old_referral['id']) {
409 409
         $dark_matter_from_metamatter = $metamatter * AFFILIATE_MM_TO_REFERRAL_DM;
410 410
         doquery("UPDATE {{referrals}} SET dark_matter = dark_matter + '{$dark_matter_from_metamatter}' WHERE `id` = {$user_id_safe} LIMIT 1;");
411 411
         $new_referral = doquery("SELECT * FROM {{referrals}} WHERE `id` = {$user_id_safe} LIMIT 1;", '', true);
412 412
 
413 413
         $partner_bonus = floor($new_referral['dark_matter'] / $config->rpg_bonus_divisor) - ($old_referral['dark_matter'] >= $config->rpg_bonus_minimum ? floor($old_referral['dark_matter'] / $config->rpg_bonus_divisor) : 0);
414
-        if($partner_bonus > 0 && $new_referral['dark_matter'] >= $config->rpg_bonus_minimum) {
414
+        if ($partner_bonus > 0 && $new_referral['dark_matter'] >= $config->rpg_bonus_minimum) {
415 415
           rpg_points_change($new_referral['id_partner'], RPG_REFERRAL_BOUGHT_MM, $partner_bonus, "Incoming MM From Referral ID {$user_id_safe}");
416 416
         }
417 417
       }
Please login to merge, or discard this patch.
includes/classes/auth_local.php 2 patches
Doc Comments   +7 added lines patch added patch discarded remove patch
@@ -209,6 +209,10 @@  discard block
 block discarded – undo
209 209
    * @return array|bool|resource
210 210
    */
211 211
   // OK v4.5
212
+
213
+  /**
214
+   * @param string $salt_unsafe
215
+   */
212 216
   public function password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe = null) {
213 217
     $result = parent::password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe);
214 218
     if($result) {
@@ -218,6 +222,9 @@  discard block
 block discarded – undo
218 222
     return $result;
219 223
   }
220 224
 
225
+  /**
226
+   * @param Account $account_to_impersonate
227
+   */
221 228
   public function impersonate($account_to_impersonate) {
222 229
     $this->cookie_set($account_to_impersonate);
223 230
   }
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 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;
@@ -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
 
@@ -241,12 +241,12 @@  discard block
 block discarded – undo
241 241
   protected function password_reset_send_code() {
242 242
     global $lang, $config;
243 243
 
244
-    if(!$this->is_password_reset) {
244
+    if (!$this->is_password_reset) {
245 245
       return $this->account_login_status;
246 246
     }
247 247
 
248 248
     // Проверяем поддержку сброса пароля
249
-    if(!$this->is_feature_supported(AUTH_FEATURE_PASSWORD_RESET)) {
249
+    if (!$this->is_feature_supported(AUTH_FEATURE_PASSWORD_RESET)) {
250 250
       return $this->account_login_status;
251 251
     }
252 252
 
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
       unset($this->account);
257 257
       $this->account = new Account($this->db);
258 258
 
259
-      if(!$this->account->db_get_by_email($email_unsafe)) {
259
+      if (!$this->account->db_get_by_email($email_unsafe)) {
260 260
         throw new Exception(PASSWORD_RESTORE_ERROR_EMAIL_NOT_EXISTS, ERR_ERROR);
261 261
         // return $this->account_login_status;
262 262
       }
@@ -266,14 +266,14 @@  discard block
 block discarded – undo
266 266
 
267 267
       // TODO - Проверять уровень доступа аккаунта!
268 268
       // Аккаунты с АУТЛЕВЕЛ больше 0 - НЕ СБРАСЫВАЮТ ПАРОЛИ!
269
-      foreach($user_list as $user_id => $user_data) {
270
-        if($user_data['authlevel'] > AUTH_LEVEL_REGISTERED) {
269
+      foreach ($user_list as $user_id => $user_data) {
270
+        if ($user_data['authlevel'] > AUTH_LEVEL_REGISTERED) {
271 271
           throw new Exception(PASSWORD_RESTORE_ERROR_ADMIN_ACCOUNT, ERR_ERROR);
272 272
         }
273 273
       }
274 274
 
275 275
       $confirmation = $this->confirmation->db_confirmation_get_latest_by_type_and_email(CONFIRM_PASSWORD_RESET, $email_unsafe); // OK 4.5
276
-      if(isset($confirmation['create_time']) && SN_TIME_NOW - strtotime($confirmation['create_time']) < PERIOD_MINUTE_10) {
276
+      if (isset($confirmation['create_time']) && SN_TIME_NOW - strtotime($confirmation['create_time']) < PERIOD_MINUTE_10) {
277 277
         throw new Exception(PASSWORD_RESTORE_ERROR_TOO_OFTEN, ERR_ERROR);
278 278
       }
279 279
 
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
       );
291 291
 
292 292
       $result = $result ? PASSWORD_RESTORE_SUCCESS_CODE_SENT : PASSWORD_RESTORE_ERROR_SENDING;
293
-    } catch(Exception $e) {
293
+    } catch (Exception $e) {
294 294
       sn_db_transaction_rollback();
295 295
       $result = $e->getMessage();
296 296
     }
@@ -306,46 +306,46 @@  discard block
 block discarded – undo
306 306
   protected function password_reset_confirm() {
307 307
     global $lang, $config;
308 308
 
309
-    if(!$this->is_password_reset_confirm) {
309
+    if (!$this->is_password_reset_confirm) {
310 310
       return $this->account_login_status;
311 311
     }
312 312
 
313
-    if($this->account_login_status != LOGIN_UNDEFINED) {
313
+    if ($this->account_login_status != LOGIN_UNDEFINED) {
314 314
       return $this->account_login_status;
315 315
     }
316 316
 
317 317
     // Проверяем поддержку сброса пароля
318
-    if(!$this->is_feature_supported(AUTH_FEATURE_PASSWORD_RESET)) {
318
+    if (!$this->is_feature_supported(AUTH_FEATURE_PASSWORD_RESET)) {
319 319
       return $this->account_login_status;
320 320
     }
321 321
 
322 322
     try {
323 323
       $code_unsafe = sys_get_param_str_unsafe('password_reset_code');
324
-      if(empty($code_unsafe)) {
324
+      if (empty($code_unsafe)) {
325 325
         throw new Exception(PASSWORD_RESTORE_ERROR_CODE_EMPTY, ERR_ERROR);
326 326
       }
327 327
 
328 328
       sn_db_transaction_start();
329 329
       $confirmation = $this->confirmation->db_confirmation_get_by_type_and_code(CONFIRM_PASSWORD_RESET, $code_unsafe); // OK 4.5
330 330
 
331
-      if(empty($confirmation)) {
331
+      if (empty($confirmation)) {
332 332
         throw new Exception(PASSWORD_RESTORE_ERROR_CODE_WRONG, ERR_ERROR);
333 333
       }
334 334
 
335
-      if(SN_TIME_NOW - strtotime($confirmation['create_time']) > AUTH_PASSWORD_RESET_CONFIRMATION_EXPIRE) {
335
+      if (SN_TIME_NOW - strtotime($confirmation['create_time']) > AUTH_PASSWORD_RESET_CONFIRMATION_EXPIRE) {
336 336
         throw new Exception(PASSWORD_RESTORE_ERROR_CODE_TOO_OLD, ERR_ERROR);
337 337
       }
338 338
 
339 339
       unset($this->account);
340 340
       $this->account = new Account($this->db);
341 341
 
342
-      if(!$this->account->db_get_by_email($confirmation['email'])) {
342
+      if (!$this->account->db_get_by_email($confirmation['email'])) {
343 343
         throw new Exception(PASSWORD_RESTORE_ERROR_CODE_OK_BUT_NO_ACCOUNT_FOR_EMAIL, ERR_ERROR);
344 344
       }
345 345
 
346 346
       $new_password_unsafe = $this->make_random_password();
347 347
       $salt_unsafe = $this->password_salt_generate();
348
-      if(!$this->account->db_set_password($new_password_unsafe, $salt_unsafe)) {
348
+      if (!$this->account->db_set_password($new_password_unsafe, $salt_unsafe)) {
349 349
         // Ошибка смены пароля
350 350
         throw new Exception(AUTH_ERROR_INTERNAL_PASSWORD_CHANGE_ON_RESTORE, ERR_ERROR);
351 351
       }
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
       $this->cookie_set();
356 356
       $this->login_cookie();
357 357
 
358
-      if($this->account_login_status == LOGIN_SUCCESS) {
358
+      if ($this->account_login_status == LOGIN_SUCCESS) {
359 359
         // TODO - НЕ ОБЯЗАТЕЛЬНО ОТПРАВЛЯТЬ ЧЕРЕЗ ЕМЕЙЛ! ЕСЛИ ЭТО ФЕЙСБУЧЕК ИЛИ ВКШЕЧКА - МОЖНО ЧЕРЕЗ ЛС ПИСАТЬ!!
360 360
         $message_header = sprintf($lang['log_lost_email_title'], $config->game_name);
361 361
         $message = sprintf($lang['log_lost_email_pass'], $config->game_name, $this->account->account_name, $new_password_unsafe);
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
 
364 364
         // $users_translated = classSupernova::$auth->db_translate_get_users_from_account_list($this->provider_id, $this->account->account_id); // OK 4.5
365 365
         $users_translated = PlayerToAccountTranslate::db_translate_get_users_from_account_list($this->provider_id, $this->account->account_id); // OK 4.5
366
-        if(!empty($users_translated)) {
366
+        if (!empty($users_translated)) {
367 367
           // Отправляем в лички письмо о сбросе пароля
368 368
 
369 369
           // ПО ОПРЕДЕЛЕНИЮ в $users_translated только
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
           $message = sys_bbcodeParse($message) . '<br><br>';
376 376
           // msg_send_simple_message($found_provider->data[F_USER_ID], 0, SN_TIME_NOW, MSG_TYPE_ADMIN, $lang['sys_administration'], $lang['sys_login_register_message_title'], $message);
377 377
 
378
-          foreach($users_translated as $user_id => $providers_list) {
378
+          foreach ($users_translated as $user_id => $providers_list) {
379 379
             msg_send_simple_message($user_id, 0, SN_TIME_NOW, MSG_TYPE_ADMIN, $lang['sys_administration'], $lang['sys_login_register_message_title'], $message);
380 380
           }
381 381
         } else {
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
     $this->flog('Регистрация: начинаем. Провайдер ' . $this->provider_id);
431 431
 
432 432
     try {
433
-      if(!$this->is_register) {
433
+      if (!$this->is_register) {
434 434
         $this->flog('Регистрация: не выставлен флаг регистрации - пропускаем');
435 435
         throw new Exception(LOGIN_UNDEFINED, ERR_ERROR);
436 436
       }
@@ -442,8 +442,8 @@  discard block
 block discarded – undo
442 442
       // $this->account_check_duplicate_name_or_email($this->input_login_unsafe, $this->input_email_unsafe);
443 443
 
444 444
       $this->account->db_get_by_name_or_email($this->input_login_unsafe, $this->input_email_unsafe);
445
-      if($this->account->is_exists) {
446
-        if($this->account->account_email == $this->input_email_unsafe) {
445
+      if ($this->account->is_exists) {
446
+        if ($this->account->account_email == $this->input_email_unsafe) {
447 447
           throw new Exception(REGISTER_ERROR_EMAIL_EXISTS, ERR_ERROR);
448 448
         } else {
449 449
           throw new Exception(REGISTER_ERROR_ACCOUNT_NAME_EXISTS, ERR_ERROR);
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
       // А вот это пока не нужно. Трансляцией аккаунтов в юзеров и созданием новых юзеров для новозашедших аккаунтов занимается Auth
483 483
       // $this->register_account();
484 484
       sn_db_transaction_commit();
485
-    } catch(Exception $e) {
485
+    } catch (Exception $e) {
486 486
       sn_db_transaction_rollback();
487 487
       $this->account_login_status == LOGIN_UNDEFINED ? $this->account_login_status = $e->getMessage() : false;
488 488
     }
@@ -498,15 +498,15 @@  discard block
 block discarded – undo
498 498
    */
499 499
   // OK v4.5
500 500
   protected function login_cookie() {
501
-    if($this->account_login_status != LOGIN_UNDEFINED) {
501
+    if ($this->account_login_status != LOGIN_UNDEFINED) {
502 502
       return $this->account_login_status;
503 503
     }
504 504
 
505 505
     // Пытаемся войти по куке
506
-    if(!empty($_COOKIE[$this->cookie_name])) {
506
+    if (!empty($_COOKIE[$this->cookie_name])) {
507 507
 // Кто хотел - уже сконвертировал старые куки в новые
508 508
 // Update оказывается - не все...
509
-      if(count(explode("/%/", $_COOKIE[$this->cookie_name])) < 4) {
509
+      if (count(explode("/%/", $_COOKIE[$this->cookie_name])) < 4) {
510 510
         list($account_id_unsafe, $cookie_password_hash_salted, $user_remember_me) = explode(AUTH_COOKIE_DELIMETER, $_COOKIE[$this->cookie_name]);
511 511
       } else {
512 512
         list($account_id_unsafe, $user_name, $cookie_password_hash_salted, $user_remember_me) = explode("/%/", $_COOKIE[$this->cookie_name]);
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
 
515 515
       // $account = $this->db_account_get_by_id($account_id_unsafe);
516 516
 
517
-      if(
517
+      if (
518 518
         $this->account->db_get_by_id($account_id_unsafe)
519 519
         && ($this->password_encode_for_cookie($this->account->account_password) == $cookie_password_hash_salted)
520 520
       ) {
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
       }
525 525
     }
526 526
 
527
-    if($this->account_login_status != LOGIN_SUCCESS) {
527
+    if ($this->account_login_status != LOGIN_SUCCESS) {
528 528
       // Невалидная кука - чистим
529 529
       $this->cookie_clear();
530 530
     }
@@ -542,13 +542,13 @@  discard block
 block discarded – undo
542 542
   protected function login_username() {
543 543
     // TODO - Логин по старым именам
544 544
     try {
545
-      if(!$this->is_login) {
545
+      if (!$this->is_login) {
546 546
         $this->flog('Логин: не выставлен флаг входа в игру - это не логин');
547 547
         throw new Exception(LOGIN_UNDEFINED, ERR_ERROR);
548 548
       }
549 549
 
550 550
       // TODO Пустое имя аккаунта
551
-      if(!$this->input_login_unsafe) {
551
+      if (!$this->input_login_unsafe) {
552 552
         throw new Exception(LOGIN_UNDEFINED, ERR_ERROR);
553 553
       }
554 554
 
@@ -558,11 +558,11 @@  discard block
 block discarded – undo
558 558
 //      if(empty($account)) {
559 559
 //        throw new Exception(LOGIN_ERROR_USERNAME, ERR_ERROR);
560 560
 //      }
561
-      if(!$this->account->db_get_by_name($this->input_login_unsafe) && !$this->account->db_get_by_email($this->input_login_unsafe)) {
561
+      if (!$this->account->db_get_by_name($this->input_login_unsafe) && !$this->account->db_get_by_email($this->input_login_unsafe)) {
562 562
         throw new Exception(LOGIN_ERROR_USERNAME, ERR_ERROR);
563 563
       }
564 564
 
565
-      if(!$this->account->password_check($this->input_login_password_raw)) {
565
+      if (!$this->account->password_check($this->input_login_password_raw)) {
566 566
         throw new Exception(LOGIN_ERROR_PASSWORD, ERR_ERROR);
567 567
       }
568 568
 
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
 
571 571
       $this->cookie_set();
572 572
       $this->account_login_status = LOGIN_SUCCESS;
573
-    } catch(Exception $e) {
573
+    } catch (Exception $e) {
574 574
       $this->account_login_status == LOGIN_UNDEFINED ? $this->account_login_status = $e->getMessage() : false;
575 575
     }
576 576
 
@@ -592,11 +592,11 @@  discard block
 block discarded – undo
592 592
   protected function cookie_set($account_to_impersonate = null) {
593 593
     $this_account = is_object($account_to_impersonate) ? $account_to_impersonate : $this->account;
594 594
 
595
-    if(!is_object($this_account) || !$this_account->is_exists) {
595
+    if (!is_object($this_account) || !$this_account->is_exists) {
596 596
       throw new Exception(LOGIN_ERROR_NO_ACCOUNT_FOR_COOKIE_SET, ERR_ERROR);
597 597
     }
598 598
 
599
-    if(is_object($account_to_impersonate) && $account_to_impersonate->is_exists) {
599
+    if (is_object($account_to_impersonate) && $account_to_impersonate->is_exists) {
600 600
       sn_setcookie($this->cookie_name_impersonate, $_COOKIE[$this->cookie_name], SN_TIME_NOW + PERIOD_YEAR, $this->sn_root_path, $this->domain);
601 601
     }
602 602
 
@@ -614,7 +614,7 @@  discard block
 block discarded – undo
614 614
   // OK v4.1
615 615
   protected function cookie_clear() {
616 616
     // Автоматически вообще-то - если установлена кука имперсонатора - то чистим обычную, а куку имперсонатора - копируем в неё
617
-    if(!empty($_COOKIE[$this->cookie_name_impersonate])) {
617
+    if (!empty($_COOKIE[$this->cookie_name_impersonate])) {
618 618
       sn_setcookie($this->cookie_name, $_COOKIE[$this->cookie_name_impersonate], SN_TIME_NOW + PERIOD_YEAR, $this->sn_root_path, $this->domain);
619 619
       sn_setcookie($this->cookie_name_impersonate, '', SN_TIME_NOW - PERIOD_WEEK, $this->sn_root_path, $this->domain);
620 620
     } else {
@@ -633,10 +633,10 @@  discard block
 block discarded – undo
633 633
   protected function login_validate_input() {
634 634
     // Проверяем, что бы в начале и конце не было пустых символов
635 635
     // TODO - при копировании Эксель -> Опера - в конце образуются пустые места. Это не должно быть проблемой! Вынести проверку пароля в регистрацию!
636
-    if($this->input_login_password_raw != trim($this->input_login_password_raw)) {
636
+    if ($this->input_login_password_raw != trim($this->input_login_password_raw)) {
637 637
       throw new Exception(LOGIN_ERROR_PASSWORD_TRIMMED, ERR_ERROR);
638 638
     }
639
-    if(!$this->input_login_password_raw) {
639
+    if (!$this->input_login_password_raw) {
640 640
       throw new Exception(LOGIN_ERROR_PASSWORD_EMPTY, ERR_ERROR);
641 641
     }
642 642
   }
@@ -652,37 +652,37 @@  discard block
 block discarded – undo
652 652
     $this->login_validate_input();
653 653
 
654 654
     // Если нет имени пользователя - NO GO!
655
-    if(!$this->input_login_unsafe) {
655
+    if (!$this->input_login_unsafe) {
656 656
       throw new Exception(LOGIN_ERROR_USERNAME_EMPTY, ERR_ERROR);
657 657
     }
658 658
     // Если логин имеет запрещенные символы - NO GO!
659
-    if(strpbrk($this->input_login_unsafe, LOGIN_REGISTER_CHARACTERS_PROHIBITED)) {
659
+    if (strpbrk($this->input_login_unsafe, LOGIN_REGISTER_CHARACTERS_PROHIBITED)) {
660 660
       throw new Exception(LOGIN_ERROR_USERNAME_RESTRICTED_CHARACTERS, ERR_ERROR);
661 661
     }
662 662
     // Если логин меньше минимальной длины - NO GO!
663
-    if(strlen($this->input_login_unsafe) < LOGIN_LENGTH_MIN) {
663
+    if (strlen($this->input_login_unsafe) < LOGIN_LENGTH_MIN) {
664 664
       throw new Exception(REGISTER_ERROR_USERNAME_SHORT, ERR_ERROR);
665 665
     }
666 666
     // Если пароль меньше минимальной длины - NO GO!
667
-    if(strlen($this->input_login_password_raw) < PASSWORD_LENGTH_MIN) {
667
+    if (strlen($this->input_login_password_raw) < PASSWORD_LENGTH_MIN) {
668 668
       throw new Exception(REGISTER_ERROR_PASSWORD_INSECURE, ERR_ERROR);
669 669
     }
670 670
     // Если пароль имеет пробельные символы в начале или конце - NO GO!
671
-    if($this->input_login_password_raw != trim($this->input_login_password_raw)) {
671
+    if ($this->input_login_password_raw != trim($this->input_login_password_raw)) {
672 672
       throw new Exception(LOGIN_ERROR_PASSWORD_TRIMMED, ERR_ERROR);
673 673
     }
674 674
     // Если пароль не совпадает с подтверждением - NO GO! То, что у пароля нет пробельных символов в начале/конце - мы уже проверили выше
675 675
     //Если они есть у повтора - значит пароль и повтор не совпадут
676
-    if($this->input_login_password_raw <> $this->input_login_password_raw_repeat) {
676
+    if ($this->input_login_password_raw <> $this->input_login_password_raw_repeat) {
677 677
       throw new Exception(REGISTER_ERROR_PASSWORD_DIFFERENT, ERR_ERROR);
678 678
     }
679 679
     // Если нет емейла - NO GO!
680 680
     // TODO - регистрация без емейла
681
-    if(!$this->input_email_unsafe) {
681
+    if (!$this->input_email_unsafe) {
682 682
       throw new Exception(REGISTER_ERROR_EMAIL_EMPTY, ERR_ERROR);
683 683
     }
684 684
     // Если емейл не является емейлом - NO GO!
685
-    if(!is_email($this->input_email_unsafe)) {
685
+    if (!is_email($this->input_email_unsafe)) {
686 686
       throw new Exception(REGISTER_ERROR_EMAIL_WRONG, ERR_ERROR);
687 687
     }
688 688
   }
@@ -715,7 +715,7 @@  discard block
 block discarded – undo
715 715
     return core_auth::make_random_password();
716 716
   }
717 717
   protected function flog($message, $die = false) {
718
-    if(!defined('DEBUG_AUTH') || !DEBUG_AUTH) {
718
+    if (!defined('DEBUG_AUTH') || !DEBUG_AUTH) {
719 719
       return;
720 720
     }
721 721
     list($called, $caller) = debug_backtrace(false);
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
     $_SERVER['SERVER_NAME'] == 'localhost' ? print("<div class='debug'>$message - $caller_name\r\n</div>") : false;
732 732
 
733 733
     classSupernova::log_file("$message - $caller_name");
734
-    if($die) {
734
+    if ($die) {
735 735
       // pdump($caller);
736 736
       // pdump(debug_backtrace(false));
737 737
       $die && die("<div class='negative'>СТОП! Функция {$caller_name} при вызове в " . get_called_class() . " (располагается в " . get_class() . "). СООБЩИТЕ АДМИНИСТРАЦИИ!</div>");
Please login to merge, or discard this patch.
includes/classes/cache.php 3 patches
Doc Comments   +13 added lines patch added patch discarded remove patch
@@ -81,6 +81,10 @@  discard block
 block discarded – undo
81 81
   // -------------------------------------------------------------------------
82 82
   // Here comes low-level functions - those that directly works with cacher engines
83 83
   // -------------------------------------------------------------------------
84
+
85
+  /**
86
+   * @param string $name
87
+   */
84 88
   public function __set($name, $value) {
85 89
     switch ($name) {
86 90
       case '_MODE':
@@ -132,6 +136,9 @@  discard block
 block discarded – undo
132 136
     return null;
133 137
   }
134 138
 
139
+  /**
140
+   * @param string $name
141
+   */
135 142
   public function __isset($name) {
136 143
     switch (self::$mode) {
137 144
       case CACHER_NO_CACHE:
@@ -332,6 +339,9 @@  discard block
 block discarded – undo
332 339
     return self::$cacheObject;
333 340
   }
334 341
 
342
+  /**
343
+   * @param string $index
344
+   */
335 345
   public function db_loadItem($index) {
336 346
     $result = null;
337 347
     if($index) {
@@ -371,6 +381,9 @@  discard block
 block discarded – undo
371 381
     $this->db_saveItem(array_combine(array_keys($this->defaults), array_fill(0, count($this->defaults), null)));
372 382
   }
373 383
 
384
+  /**
385
+   * @param integer $value
386
+   */
374 387
   public function db_saveItem($item_list, $value = NULL) {
375 388
     if(empty($item_list)) {
376 389
       return;
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@
 block discarded – undo
59 59
       if(self::$mode === CACHER_NOT_INIT) {
60 60
         self::$mode = CACHER_NO_CACHE;
61 61
         if(!self::$data) {
62
-         self::$data = array();
62
+          self::$data = array();
63 63
         }
64 64
       }
65 65
     }
Please login to merge, or discard this patch.
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -13,8 +13,8 @@  discard block
 block discarded – undo
13 13
 * Defining some constants
14 14
 */
15 15
 define('CACHER_NOT_INIT', -1);
16
-define('CACHER_NO_CACHE',  0);
17
-define('CACHER_XCACHE'  ,  1);
16
+define('CACHER_NO_CACHE', 0);
17
+define('CACHER_XCACHE', 1);
18 18
 
19 19
 define('CACHER_LOCK_WAIT', 5); // maximum cacher wait for table unlock in seconds. Can be float
20 20
 
@@ -46,19 +46,19 @@  discard block
 block discarded – undo
46 46
   protected static $cacheObject;
47 47
 
48 48
   public function __construct($prefIn = 'CACHE_', $init_mode = false) {
49
-    if( !($init_mode === false || $init_mode === CACHER_NO_CACHE || ($init_mode === CACHER_XCACHE && extension_loaded('xcache')) )) {
49
+    if (!($init_mode === false || $init_mode === CACHER_NO_CACHE || ($init_mode === CACHER_XCACHE && extension_loaded('xcache')))) {
50 50
       throw new UnexpectedValueException('Wrong work mode or current mode does not supported on your server');
51 51
     }
52 52
 
53 53
     $this->prefix = $prefIn;
54
-    if(extension_loaded('xcache') && ($init_mode === CACHER_XCACHE || $init_mode === false)) {
55
-      if(self::$mode === CACHER_NOT_INIT) {
54
+    if (extension_loaded('xcache') && ($init_mode === CACHER_XCACHE || $init_mode === false)) {
55
+      if (self::$mode === CACHER_NOT_INIT) {
56 56
         self::$mode = CACHER_XCACHE;
57 57
       }
58 58
     } else {
59
-      if(self::$mode === CACHER_NOT_INIT) {
59
+      if (self::$mode === CACHER_NOT_INIT) {
60 60
         self::$mode = CACHER_NO_CACHE;
61
-        if(!self::$data) {
61
+        if (!self::$data) {
62 62
          self::$data = array();
63 63
         }
64 64
       }
@@ -94,11 +94,11 @@  discard block
 block discarded – undo
94 94
       default:
95 95
         switch (self::$mode) {
96 96
           case CACHER_NO_CACHE:
97
-            self::$data[$this->prefix.$name] = $value;
97
+            self::$data[$this->prefix . $name] = $value;
98 98
           break;
99 99
 
100 100
           case CACHER_XCACHE:
101
-            xcache_set($this->prefix.$name, $value);
101
+            xcache_set($this->prefix . $name, $value);
102 102
           break;
103 103
         }
104 104
       break;
@@ -118,11 +118,11 @@  discard block
 block discarded – undo
118 118
       default:
119 119
         switch (self::$mode) {
120 120
           case CACHER_NO_CACHE:
121
-            return self::$data[$this->prefix.$name];
121
+            return self::$data[$this->prefix . $name];
122 122
           break;
123 123
 
124 124
           case CACHER_XCACHE:
125
-            return xcache_get($this->prefix.$name);
125
+            return xcache_get($this->prefix . $name);
126 126
           break;
127 127
 
128 128
         }
@@ -135,11 +135,11 @@  discard block
 block discarded – undo
135 135
   public function __isset($name) {
136 136
     switch (self::$mode) {
137 137
       case CACHER_NO_CACHE:
138
-        return isset(self::$data[$this->prefix.$name]);
138
+        return isset(self::$data[$this->prefix . $name]);
139 139
       break;
140 140
 
141 141
       case CACHER_XCACHE:
142
-        return xcache_isset($this->prefix.$name) && ($this->__get($name) !== null);
142
+        return xcache_isset($this->prefix . $name) && ($this->__get($name) !== null);
143 143
       break;
144 144
     }
145 145
 
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 
161 161
   public function unset_by_prefix($prefix_unset = '') {
162 162
     static $array_clear;
163
-    !$array_clear ? $array_clear = function(&$v,$k,$p) {
163
+    !$array_clear ? $array_clear = function(&$v, $k, $p) {
164 164
       strpos($k, $p) === 0 ? $v = NULL : false;
165 165
     } : false;
166 166
 
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
       break;
173 173
 
174 174
       case CACHER_XCACHE:
175
-        if(!function_exists('xcache_unset_by_prefix')) {
175
+        if (!function_exists('xcache_unset_by_prefix')) {
176 176
           return false;
177 177
         }
178 178
         return xcache_unset_by_prefix($this->prefix . $prefix_unset);
@@ -188,13 +188,13 @@  discard block
 block discarded – undo
188 188
   protected function make_element_name($args, $diff = 0) {
189 189
     $num_args = count($args);
190 190
 
191
-    if($num_args < 1) {
191
+    if ($num_args < 1) {
192 192
       return false;
193 193
     }
194 194
 
195 195
     $name = '';
196 196
     $aName = array();
197
-    for($i = 0; $i <= $num_args - 1 - $diff; $i++) {
197
+    for ($i = 0; $i <= $num_args - 1 - $diff; $i++) {
198 198
       $name .= "[{$args[$i]}]";
199 199
       array_unshift($aName, $name);
200 200
     }
@@ -206,15 +206,15 @@  discard block
 block discarded – undo
206 206
     $args = func_get_args();
207 207
     $name = $this->make_element_name($args, 1);
208 208
 
209
-    if(!$name) {
209
+    if (!$name) {
210 210
       return NULL;
211 211
     }
212 212
 
213
-    if($this->$name[0] === NULL) {
214
-      for($i = count($name) - 1; $i > 0; $i--) {
213
+    if ($this->$name[0] === NULL) {
214
+      for ($i = count($name) - 1; $i > 0; $i--) {
215 215
         $cName = "{$name[$i]}_COUNT";
216
-        $cName1 = "{$name[$i-1]}_COUNT";
217
-        if($this->$cName1 == NULL || $i == 1) {
216
+        $cName1 = "{$name[$i - 1]}_COUNT";
217
+        if ($this->$cName1 == NULL || $i == 1) {
218 218
           $this->$cName++;
219 219
         }
220 220
       }
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 
227 227
   public function array_get() {
228 228
     $name = $this->make_element_name(func_get_args());
229
-    if(!$name) {
229
+    if (!$name) {
230 230
       return NULL;
231 231
     }
232 232
     return $this->$name[0];
@@ -234,12 +234,12 @@  discard block
 block discarded – undo
234 234
 
235 235
   public function array_count() {
236 236
     $name = $this->make_element_name(func_get_args());
237
-    if(!$name) {
237
+    if (!$name) {
238 238
       return 0;
239 239
     }
240 240
     $cName = "{$name[0]}_COUNT";
241 241
     $retVal = $this->$cName;
242
-    if(!$retVal) {
242
+    if (!$retVal) {
243 243
       $retVal = NULL;
244 244
     }
245 245
     return $retVal;
@@ -248,18 +248,18 @@  discard block
 block discarded – undo
248 248
   public function array_unset() {
249 249
     $name = $this->make_element_name(func_get_args());
250 250
 
251
-    if(!$name) {
251
+    if (!$name) {
252 252
       return false;
253 253
     }
254 254
     $this->unset_by_prefix($name[0]);
255 255
 
256
-    for($i = 1; $i < count($name); $i++) {
256
+    for ($i = 1; $i < count($name); $i++) {
257 257
       $cName = "{$name[$i]}_COUNT";
258
-      $cName1 = "{$name[$i-1]}_COUNT";
258
+      $cName1 = "{$name[$i - 1]}_COUNT";
259 259
 
260
-      if($i == 1 || $this->$cName1 === NULL) {
260
+      if ($i == 1 || $this->$cName1 === NULL) {
261 261
         $this->$cName--;
262
-        if($this->$cName <= 0) {
262
+        if ($this->$cName <= 0) {
263 263
           unset($this->$cName);
264 264
         }
265 265
       }
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
     $this->sql_index_field = "{$table_name}_name";
320 320
     $this->sql_value_field = "{$table_name}_value";
321 321
 
322
-    if(!$this->_DB_LOADED) {
322
+    if (!$this->_DB_LOADED) {
323 323
       $this->db_loadAll();
324 324
     }
325 325
   }
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
 
335 335
   public function db_loadItem($index) {
336 336
     $result = null;
337
-    if($index) {
337
+    if ($index) {
338 338
       $index_safe = db_escape($index);
339 339
       $result = doquery("SELECT `{$this->sql_value_field}` FROM `{{{$this->table_name}}}` WHERE `{$this->sql_index_field}` = '{$index_safe}' FOR UPDATE", true);
340 340
       // В две строки - что бы быть уверенным в порядке выполнения
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
     $this->loadDefaults();
349 349
 
350 350
     $query = doquery("SELECT * FROM {{{$this->table_name}}} FOR UPDATE;");
351
-    while($row = db_fetch($query)) {
351
+    while ($row = db_fetch($query)) {
352 352
       $this->$row[$this->sql_index_field] = $row[$this->sql_value_field];
353 353
     }
354 354
 
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
   }
357 357
 
358 358
   public function loadDefaults() {
359
-    foreach($this->defaults as $defName => $defValue) {
359
+    foreach ($this->defaults as $defName => $defValue) {
360 360
       $this->$defName = $defValue;
361 361
     }
362 362
   }
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
   }
373 373
 
374 374
   public function db_saveItem($item_list, $value = NULL) {
375
-    if(empty($item_list)) {
375
+    if (empty($item_list)) {
376 376
       return;
377 377
     }
378 378
 
@@ -380,8 +380,8 @@  discard block
 block discarded – undo
380 380
 
381 381
     // Сначала записываем данные в базу - что бы поймать все блокировки
382 382
     $qry = array();
383
-    foreach($item_list as $item_name => $item_value) {
384
-      if($item_name) {
383
+    foreach ($item_list as $item_name => $item_value) {
384
+      if ($item_name) {
385 385
         $item_value = db_escape($item_value === NULL ? $this->$item_name : $item_value);
386 386
         $item_name = db_escape($item_name);
387 387
         $qry[] = "('{$item_name}', '{$item_value}')";
@@ -390,8 +390,8 @@  discard block
 block discarded – undo
390 390
     doquery("REPLACE INTO `{{" . $this->table_name . "}}` (`{$this->sql_index_field}`, `{$this->sql_value_field}`) VALUES " . implode(',', $qry) . ";");
391 391
 
392 392
     // И только после взятия блокировок - меняем значения в кэше
393
-    foreach($item_list as $item_name => $item_value) {
394
-      if($item_name && $item_value !== NULL) {
393
+    foreach ($item_list as $item_name => $item_value) {
394
+      if ($item_name && $item_value !== NULL) {
395 395
         $this->$item_name = $item_value;
396 396
       }
397 397
     }
@@ -419,9 +419,9 @@  discard block
 block discarded – undo
419 419
     'advGoogleLeftMenuCode'        => '(Place here code for banner)',
420 420
 
421 421
     // Alliance bonus calculations
422
-    'ali_bonus_algorithm'          => 0,  // Bonus calculation algorithm
422
+    'ali_bonus_algorithm'          => 0, // Bonus calculation algorithm
423 423
     'ali_bonus_brackets'           => 10, // Brackets count for ALI_BONUS_BY_RANK
424
-    'ali_bonus_brackets_divisor'   => 10,// Bonus divisor for ALI_BONUS_BY_RANK
424
+    'ali_bonus_brackets_divisor'   => 10, // Bonus divisor for ALI_BONUS_BY_RANK
425 425
     'ali_bonus_divisor'            => 10000000, // Rank divisor for ALI_BONUS_BY_POINTS
426 426
     'ali_bonus_members'            => 10, // Minumum alliace size to start using bonus
427 427
 
@@ -452,25 +452,25 @@  discard block
 block discarded – undo
452 452
     'deuterium_basic_income'       => 0,
453 453
     'eco_scale_storage'            => 1,
454 454
     'eco_stockman_fleet'           => '', // Black Market - Starting amount of s/h ship merchant to sell
455
-    'eco_stockman_fleet_populate'  => 1,  // Populate empty Stockman fleet with ships or not
455
+    'eco_stockman_fleet_populate'  => 1, // Populate empty Stockman fleet with ships or not
456 456
     'empire_mercenary_base_period' => PERIOD_MONTH, // Base
457 457
     'empire_mercenary_temporary'   => 0, // Temporary empire-wide mercenaries
458 458
     'energy_basic_income'          => 0,
459 459
 
460 460
     // Bashing protection settings
461
-    'fleet_bashing_attacks'        => 3,      // Max amount of attack per wave - 3 by default
462
-    'fleet_bashing_interval'       => 1800,   // Maximum interval between attacks when they still count as one wave - 30m by default
463
-    'fleet_bashing_scope'          => 86400,  // Interval on which bashing waves counts - 24h by default
464
-    'fleet_bashing_war_delay'      => 43200,  // Delay before start bashing after declaring war to alliance - 12h by default
465
-    'fleet_bashing_waves'          => 3,      // Max amount of waves per day - 3 by default
461
+    'fleet_bashing_attacks'        => 3, // Max amount of attack per wave - 3 by default
462
+    'fleet_bashing_interval'       => 1800, // Maximum interval between attacks when they still count as one wave - 30m by default
463
+    'fleet_bashing_scope'          => 86400, // Interval on which bashing waves counts - 24h by default
464
+    'fleet_bashing_war_delay'      => 43200, // Delay before start bashing after declaring war to alliance - 12h by default
465
+    'fleet_bashing_waves'          => 3, // Max amount of waves per day - 3 by default
466 466
 
467 467
     'Fleet_Cdr'                    => 30,
468 468
     'fleet_speed'                  => 1,
469 469
 
470 470
     'fleet_update_interval'        => 4,
471 471
 
472
-    'game_adminEmail'              => 'root@localhost',    // Admin's email to show to users
473
-    'game_counter'                 => 0,  // Does built-in page hit counter is on?
472
+    'game_adminEmail'              => 'root@localhost', // Admin's email to show to users
473
+    'game_counter'                 => 0, // Does built-in page hit counter is on?
474 474
     // Defaults
475 475
     'game_default_language'        => 'ru',
476 476
     'game_default_skin'            => 'skins/EpicBlue/',
@@ -484,13 +484,13 @@  discard block
 block discarded – undo
484 484
     'game_maxSystem'               => 199,
485 485
     'game_maxPlanet'               => 15,
486 486
     // Game global settings
487
-    'game_mode'                    => 0,           // 0 - SuperNova, 1 - oGame
487
+    'game_mode'                    => 0, // 0 - SuperNova, 1 - oGame
488 488
     'game_name'                    => 'SuperNova', // Server name (would be on banners and on top of left menu)
489 489
 
490 490
     'game_news_actual'             => 259200, // How long announcement would be marked as "New". In seconds. Default - 3 days
491
-    'game_news_overview'           => 3,    // How much last news to show in Overview page
491
+    'game_news_overview'           => 3, // How much last news to show in Overview page
492 492
     // Noob protection
493
-    'game_noob_factor'             => 5,    // Multiplier to divide "stronger" and "weaker" users
493
+    'game_noob_factor'             => 5, // Multiplier to divide "stronger" and "weaker" users
494 494
     'game_noob_points'             => 5000, // Below this point user threated as noob. 0 to disable
495 495
 
496 496
     'game_multiaccount_enabled'    => 0, // 1 - allow interactions for players with same IP (multiaccounts)
@@ -539,8 +539,8 @@  discard block
 block discarded – undo
539 539
     'payment_currency_exchange_wmu' => 30,
540 540
     'payment_currency_exchange_wmz' => 1,
541 541
 
542
-    'payment_lot_price'             => 1,     // Lot price in default currency
543
-    'payment_lot_size'              => 2500,  // Lot size. Also service as minimum amount of DM that could be bought with one transaction
542
+    'payment_lot_price'             => 1, // Lot price in default currency
543
+    'payment_lot_size'              => 2500, // Lot size. Also service as minimum amount of DM that could be bought with one transaction
544 544
 
545 545
     'planet_teleport_cost'         => 50000, // 
546 546
     'planet_teleport_timeout'      => 86400, // 
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
     'resource_multiplier'          => 1,
559 559
 
560 560
     //Roleplay system
561
-    'rpg_bonus_divisor'            => 10,    // Amount of DM referral shoud get for partner have 1 DM bonus
561
+    'rpg_bonus_divisor'            => 10, // Amount of DM referral shoud get for partner have 1 DM bonus
562 562
     'rpg_bonus_minimum'            => 10000, // Minimum DM ammount for starting paying bonuses to affiliate
563 563
 
564 564
     // Black Market - General
@@ -644,7 +644,7 @@  discard block
 block discarded – undo
644 644
   }
645 645
 
646 646
   public static function getInstance($gamePrefix = 'sn_', $table_name = 'config') {
647
-    if(!isset(self::$cacheObject)) {
647
+    if (!isset(self::$cacheObject)) {
648 648
       $className = get_class();
649 649
       self::$cacheObject = new $className($gamePrefix, $table_name);
650 650
     }
Please login to merge, or discard this patch.
includes/classes/Confirmation.php 2 patches
Doc Comments   +19 added lines patch added patch discarded remove patch
@@ -18,6 +18,11 @@  discard block
 block discarded – undo
18 18
 
19 19
   // TODO - НЕ ОБЯЗАТЕЛЬНО ОТПРАВЛЯТЬ ЧЕРЕЗ ЕМЕЙЛ! ЕСЛИ ЭТО ФЕЙСБУЧЕК ИЛИ ВКШЕЧКА - МОЖНО ЧЕРЕЗ ЛС ПИСАТЬ!!
20 20
   // TODO - OK 4.6
21
+
22
+  /**
23
+   * @param integer $confirmation_type_safe
24
+   * @param string $email_unsafe
25
+   */
21 26
   public function db_confirmation_get_latest_by_type_and_email($confirmation_type_safe, $email_unsafe) {
22 27
     $email_safe = $this->db->db_escape($email_unsafe);
23 28
 
@@ -26,12 +31,21 @@  discard block
 block discarded – undo
26 31
           `type` = {$confirmation_type_safe} AND `email` = '{$email_safe}' ORDER BY create_time DESC LIMIT 1;", true);
27 32
   }
28 33
   // TODO - OK 4.6
34
+
35
+  /**
36
+   * @param integer $confirmation_type_safe
37
+   */
29 38
   public function db_confirmation_delete_by_type_and_email($confirmation_type_safe, $email_unsafe) {
30 39
     $email_safe = $this->db->db_escape($email_unsafe);
31 40
 
32 41
     return $this->db->doquery("DELETE FROM {{confirmations}} WHERE `type` = {$confirmation_type_safe} AND `email` = '{$email_safe}'");
33 42
   }
34 43
   // TODO - OK 4.6
44
+
45
+  /**
46
+   * @param integer $confirmation_type_safe
47
+   * @param string $email_unsafe
48
+   */
35 49
   public function db_confirmation_get_unique_code_by_type_and_email($confirmation_type_safe, $email_unsafe) {
36 50
     $email_safe = $this->db->db_escape($email_unsafe);
37 51
 
@@ -50,6 +64,11 @@  discard block
 block discarded – undo
50 64
     return $confirm_code_unsafe;
51 65
   }
52 66
   // TODO - OK 4.6
67
+
68
+  /**
69
+   * @param integer $confirmation_type_safe
70
+   * @param string $confirmation_code_unsafe
71
+   */
53 72
   public function db_confirmation_get_by_type_and_code($confirmation_type_safe, $confirmation_code_unsafe) {
54 73
     $confirmation_code_safe = $this->db->db_escape($confirmation_code_unsafe);
55 74
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@
 block discarded – undo
41 41
       // $query = static::$db->doquery("SELECT `id` FROM {{confirmations}} WHERE `code` = '{$confirm_code_safe}' AND `type` = {$confirmation_type_safe} FOR UPDATE", true);
42 42
       // Тип не нужен для проверки - код подтверждения должен быть уникален от слова "совсем"
43 43
       $query = $this->db->doquery("SELECT `id` FROM {{confirmations}} WHERE `code` = '{$confirm_code_safe}' FOR UPDATE", true);
44
-    } while($query);
44
+    } while ($query);
45 45
 
46 46
     $this->db->doquery(
47 47
       "REPLACE INTO {{confirmations}}
Please login to merge, or discard this patch.
includes/classes/core_auth.php 2 patches
Doc Comments   +7 added lines patch added patch discarded remove patch
@@ -829,10 +829,17 @@
 block discarded – undo
829 829
 
830 830
   // OK v4.5
831 831
   // TODO - REMEMBER_ME
832
+
833
+  /**
834
+   * @param integer $period
835
+   */
832 836
   protected static function cookie_set($value, $impersonate = false, $period = null) {
833 837
     sn_setcookie($impersonate ? SN_COOKIE_U_I : SN_COOKIE_U, $value, $period === null ? SN_TIME_NOW + PERIOD_YEAR : $period, SN_ROOT_RELATIVE);
834 838
   }
835 839
 
840
+  /**
841
+   * @param string $message
842
+   */
836 843
   protected static function flog($message, $die = false) {
837 844
     if(!defined('DEBUG_AUTH') || !DEBUG_AUTH) {
838 845
       return;
Please login to merge, or discard this patch.
Spacing   +62 added lines, -62 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,7 +218,7 @@  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
 
@@ -227,15 +227,15 @@  discard block
 block discarded – undo
227 227
         sn_db_transaction_rollback();
228 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) {
236
+      if ($this->register_status == LOGIN_SUCCESS) {
237 237
         sys_redirect(SN_ROOT_VIRTUAL . 'overview.php');
238
-      } elseif($this->register_status == REGISTER_ERROR_PLAYER_NAME_EXISTS && $original_suggest == $this->player_suggested_name) {
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,7 +259,7 @@  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 264
         return "'" . htmlentities($value, ENT_QUOTES, 'UTF-8') . "'";
265 265
       }, str_split(LOGIN_REGISTER_CHARACTERS_PROHIBITED));
@@ -293,27 +293,27 @@  discard block
 block discarded – undo
293 293
     global $sn_module_list, $lang;
294 294
 
295 295
     // !self::$is_init ? self::init() : false;
296
-    if(empty($sn_module_list['auth'])) {
296
+    if (empty($sn_module_list['auth'])) {
297 297
       die('{Не обнаружено ни одного провайдера авторизации в core_auth::login()!}');
298 298
     }
299 299
 
300 300
     !empty($_POST) ? self::flog(dump($_POST, '$_POST')) : false;
301 301
     !empty($_GET) ? self::flog(dump($_GET, '$_GET')) : false;
302
-    !empty($_COOKIE) ? self::flog(dump($_COOKIE,'$_COOKIE')) : false;
302
+    !empty($_COOKIE) ? self::flog(dump($_COOKIE, '$_COOKIE')) : false;
303 303
 
304 304
     $this->auth_reset(); // OK v4.5
305 305
 
306 306
     $this->providers = array();
307
-    foreach($sn_module_list['auth'] as $module_name => $module) {
307
+    foreach ($sn_module_list['auth'] as $module_name => $module) {
308 308
       $this->providers[$module->provider_id] = $module;
309 309
     }
310 310
 
311 311
     // $this->providers = array_reverse($this->providers, true); // НИНАДА! СН-аккаунт должен всегда авторизироваться первым!
312 312
 
313
-    foreach($this->providers as $provider_id => $provider) {
313
+    foreach ($this->providers as $provider_id => $provider) {
314 314
       $login_status = $provider->login(); // OK v4.5
315 315
       self::flog(($provider->manifest['name'] . '->' . 'login_try - ') . (empty($provider->account->account_id) ? $lang['sys_login_messages'][$provider->account_login_status] : dump($provider)));
316
-      if($login_status == LOGIN_SUCCESS && is_object($provider->account) && $provider->account instanceof Account && $provider->account->account_id) {
316
+      if ($login_status == LOGIN_SUCCESS && is_object($provider->account) && $provider->account instanceof Account && $provider->account->account_id) {
317 317
         $this->providers_authorised[$provider_id] = &$this->providers[$provider_id];
318 318
 
319 319
         $this->user_id_to_provider = array_replace_recursive(
@@ -321,15 +321,15 @@  discard block
 block discarded – undo
321 321
           // static::db_translate_get_users_from_account_list($provider_id, $provider->account->account_id) // OK 4.5
322 322
           PlayerToAccountTranslate::db_translate_get_users_from_account_list($provider_id, $provider->account->account_id) // OK 4.5
323 323
         );
324
-      } elseif($login_status != LOGIN_UNDEFINED) {
324
+      } elseif ($login_status != LOGIN_UNDEFINED) {
325 325
         $this->provider_error_list[$provider_id] = $login_status;
326 326
       }
327 327
     }
328 328
 
329
-    if(empty($this->providers_authorised)) {
329
+    if (empty($this->providers_authorised)) {
330 330
       // Ни один аккаунт не авторизирован
331 331
       // Проверяем - есть ли у нас ошибки в аккаунтах?
332
-      if(!empty($this->provider_error_list)) {
332
+      if (!empty($this->provider_error_list)) {
333 333
         // Если есть - выводим их
334 334
         self::$login_status = reset($this->provider_error_list);
335 335
       }
@@ -344,12 +344,12 @@  discard block
 block discarded – undo
344 344
       // В self::$accessible_user_row_list - список доступных игроков для данных аккаунтов с соответствующими записями из таблицы `users`
345 345
 
346 346
       // Остались ли у нас в списке доступные игроки?
347
-      if(empty($this->accessible_user_row_list)) {
347
+      if (empty($this->accessible_user_row_list)) {
348 348
         // Нет ни одного игрока ни на одном авторизированном аккаунте
349 349
         // Надо регать нового игрока
350 350
 
351 351
         // Сейчас происходит процесс регистрации игрока?
352
-        if(!$this->is_player_register) {
352
+        if (!$this->is_player_register) {
353 353
           // Нет - отправляем на процесс регистрации
354 354
           $partner_id = sys_get_param_int('id_ref', sys_get_param_int('partner_id'));
355 355
           sys_redirect(SN_ROOT_VIRTUAL . 'index.php?page=player_register&player_register=1' . ($partner_id ? '&id_ref=' . $partner_id : ''));
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
         // Да, есть доступные игроки, которые так же прописаны в базе
359 359
         $this->get_active_user(); // 4.5
360 360
 
361
-        if($this->is_impersonating = !empty($_COOKIE[SN_COOKIE_U_I]) ? $_COOKIE[SN_COOKIE_U_I] : 0) {
361
+        if ($this->is_impersonating = !empty($_COOKIE[SN_COOKIE_U_I]) ? $_COOKIE[SN_COOKIE_U_I] : 0) {
362 362
           $a_user = db_user_by_id($this->is_impersonating);
363 363
           $this->impersonator_username = $a_user['username'];
364 364
         }
@@ -366,9 +366,9 @@  discard block
 block discarded – undo
366 366
 
367 367
         //Прописываем текущего игрока на все авторизированные аккаунты
368 368
         // TODO - ИЛИ ВСЕХ ИГРОКОВ??
369
-        if(empty($this->is_impersonating)) {
370
-          foreach($this->providers_authorised as $provider_id => $provider) {
371
-            if(empty($this->user_id_to_provider[self::$user['id']][$provider_id])) {
369
+        if (empty($this->is_impersonating)) {
370
+          foreach ($this->providers_authorised as $provider_id => $provider) {
371
+            if (empty($this->user_id_to_provider[self::$user['id']][$provider_id])) {
372 372
               // self::db_translate_register_user($provider_id, $provider->account->account_id, self::$user['id']);
373 373
               PlayerToAccountTranslate::db_translate_register_user($provider_id, $provider->account->account_id, self::$user['id']);
374 374
               $this->user_id_to_provider[self::$user['id']][$provider_id][$provider->account->account_id] = true;
@@ -378,9 +378,9 @@  discard block
 block discarded – undo
378 378
       }
379 379
     }
380 380
 
381
-    if(empty(self::$user['id'])) {
381
+    if (empty(self::$user['id'])) {
382 382
       self::cookie_set(''); // OK 4.5
383
-    } elseif(self::$user['id'] != $_COOKIE[SN_COOKIE_U]) {
383
+    } elseif (self::$user['id'] != $_COOKIE[SN_COOKIE_U]) {
384 384
       self::cookie_set(self::$user['id']); // OK 4.5
385 385
     }
386 386
 
@@ -399,21 +399,21 @@  discard block
 block discarded – undo
399 399
    */
400 400
   // OK v4.7
401 401
   public function logout($redirect = true) {
402
-    if(!empty($_COOKIE[SN_COOKIE_U_I])) {
402
+    if (!empty($_COOKIE[SN_COOKIE_U_I])) {
403 403
       self::cookie_set($_COOKIE[SN_COOKIE_U_I]);
404 404
       self::cookie_set(0, true);
405 405
       self::$main_provider->logout();
406 406
     } else {
407
-      foreach($this->providers as $provider_name => $provider) {
407
+      foreach ($this->providers as $provider_name => $provider) {
408 408
         $provider->logout();
409 409
       }
410 410
 
411 411
       self::cookie_set(0);
412 412
     }
413 413
 
414
-    if($redirect === true) {
414
+    if ($redirect === true) {
415 415
       sys_redirect(SN_ROOT_RELATIVE . (empty($_COOKIE[SN_COOKIE_U]) ? 'login.php' : 'admin/overview.php'));
416
-    } elseif($redirect !== false) {
416
+    } elseif ($redirect !== false) {
417 417
       sys_redirect($redirect);
418 418
     }
419 419
   }
@@ -424,15 +424,15 @@  discard block
 block discarded – undo
424 424
    * @param $user_selected
425 425
    */
426 426
   public function impersonate($user_selected) {
427
-    if($_COOKIE[SN_COOKIE_U_I]) {
427
+    if ($_COOKIE[SN_COOKIE_U_I]) {
428 428
       die('You already impersonating someone. Go back to living other\'s life! Or clear your cookies and try again'); // TODO: Log it
429 429
     }
430 430
 
431
-    if($this->auth_level_max_local < AUTH_LEVEL_ADMINISTRATOR) {
431
+    if ($this->auth_level_max_local < AUTH_LEVEL_ADMINISTRATOR) {
432 432
       die('You can\'t impersonate - too low level'); // TODO: Log it
433 433
     }
434 434
 
435
-    if($this->auth_level_max_local <= $user_selected['authlevel']) {
435
+    if ($this->auth_level_max_local <= $user_selected['authlevel']) {
436 436
       die('You can\'t impersonate this account - level is greater or equal to yours'); // TODO: Log it
437 437
     }
438 438
 
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
     $account_translate = reset($account_translate[$user_selected['id']][self::$main_provider->provider_id]);
441 441
     $account_to_impersonate = new Account(self::$main_provider->db);
442 442
     $account_to_impersonate->db_get_by_id($account_translate['provider_account_id']);
443
-    if(!$account_to_impersonate->is_exists) {
443
+    if (!$account_to_impersonate->is_exists) {
444 444
       die('Какая-то ошибка - не могу найти аккаунт для имперсонации'); // TODO: Log it
445 445
     }
446 446
     self::$main_provider->impersonate($account_to_impersonate);
@@ -466,12 +466,12 @@  discard block
 block discarded – undo
466 466
   public function password_check($password_unsafe) {
467 467
     $result = false;
468 468
 
469
-    if(empty($this->providers_authorised)) {
469
+    if (empty($this->providers_authorised)) {
470 470
       // TODO - такого быть не может!
471 471
       self::flog("password_check: Не найдено ни одного авторизированного провайдера в self::\$providers_authorised", true);
472 472
     } else {
473
-      foreach($this->providers_authorised as $provider_id => $provider) {
474
-        if($provider->is_feature_supported(AUTH_FEATURE_HAS_PASSWORD)) {
473
+      foreach ($this->providers_authorised as $provider_id => $provider) {
474
+        if ($provider->is_feature_supported(AUTH_FEATURE_HAS_PASSWORD)) {
475 475
           $result = $result || $provider->password_check($password_unsafe);
476 476
         }
477 477
       }
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
   public function password_change($old_password_unsafe, $new_password_unsafe) {
493 493
     global $lang;
494 494
 
495
-    if(empty($this->providers_authorised)) {
495
+    if (empty($this->providers_authorised)) {
496 496
       // TODO - такого быть не может!
497 497
       self::flog("Не найдено ни одного авторизированного провайдера в self::\$providers_authorised", true);
498 498
       return false;
@@ -505,8 +505,8 @@  discard block
 block discarded – undo
505 505
     $salt_unsafe = self::password_salt_generate();
506 506
 
507 507
     $providers_changed_password = array();
508
-    foreach($this->providers_authorised as $provider_id => $provider) {
509
-      if(
508
+    foreach ($this->providers_authorised as $provider_id => $provider) {
509
+      if (
510 510
         !$provider->is_feature_supported(AUTH_FEATURE_PASSWORD_CHANGE)
511 511
         || !$provider->password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe)
512 512
       ) {
@@ -518,7 +518,7 @@  discard block
 block discarded – undo
518 518
       $account_translation = PlayerToAccountTranslate::db_translate_get_users_from_account_list($provider_id, $provider->account->account_id);
519 519
 
520 520
       // Рассылаем уведомления о смене пароля в ЛС
521
-      foreach($account_translation as $user_id => $provider_info) {
521
+      foreach ($account_translation as $user_id => $provider_info) {
522 522
         // TODO - УКазывать тип аккаунта, на котором сменён пароль
523 523
         msg_send_simple_message($user_id, 0, SN_TIME_NOW, MSG_TYPE_ADMIN,
524 524
           $lang['sys_administration'], $lang['sys_login_register_message_title'],
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
       sn_db_transaction_start();
566 566
       // Проверить наличие такого имени в истории имён
567 567
 
568
-      if(db_player_name_exists($player_name_unsafe)) {
568
+      if (db_player_name_exists($player_name_unsafe)) {
569 569
         throw new Exception(REGISTER_ERROR_PLAYER_NAME_EXISTS, ERR_ERROR);
570 570
       }
571 571
 
@@ -573,11 +573,11 @@  discard block
 block discarded – undo
573 573
       $player_language = '';
574 574
       $player_email = '';
575 575
       // TODO - порнография - работа должна происходить над списком аккаунтов, а не только на одном аккаунте...
576
-      foreach($this->providers_authorised as $provider) {
577
-        if(!$player_language && $provider->account->account_language) {
576
+      foreach ($this->providers_authorised as $provider) {
577
+        if (!$player_language && $provider->account->account_language) {
578 578
           $player_language = $provider->account->account_language;
579 579
         }
580
-        if(!$player_email && $provider->account->account_email) {
580
+        if (!$player_email && $provider->account->account_email) {
581 581
           $player_email = $provider->account->account_email;
582 582
         }
583 583
       }
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
       ));
594 594
       // Зарегестрировать на него аккаунты из self::$accounts_authorised
595 595
       $a_user = self::$user;
596
-      foreach($this->providers_authorised as $provider) {
596
+      foreach ($this->providers_authorised as $provider) {
597 597
         // TODO - порнография. Должен быть отдельный класс трансляторов - в т.ч. и кэширующий транслятор
598 598
         // TODO - ну и работа должна происходить над списком аккаунтов, а не только на одном аккаунте...
599 599
         // self::db_translate_register_user($provider->provider_id, $provider->account->account_id, $a_user['id']);
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
 
606 606
       sn_db_transaction_commit();
607 607
       $this->register_status = LOGIN_SUCCESS;
608
-    } catch(Exception $e) {
608
+    } catch (Exception $e) {
609 609
       sn_db_transaction_rollback();
610 610
 
611 611
       // Если старое имя занято
@@ -624,10 +624,10 @@  discard block
 block discarded – undo
624 624
     // Пробиваем все ИД игроков по базе - есть ли вообще такие записи
625 625
     // Вообще-то это не особо нужно - у нас по определению стоят констраинты
626 626
     // Зато так мы узнаем максимальный authlevel, проверим права имперсонейта и вытащим все записи юзеров
627
-    foreach($this->user_id_to_provider as $user_id => $cork) {
627
+    foreach ($this->user_id_to_provider as $user_id => $cork) {
628 628
       $user = db_user_by_id($user_id);
629 629
       // Если записи игрока в БД не существует?
630
-      if(empty($user['id'])) {
630
+      if (empty($user['id'])) {
631 631
         // Удаляем этого и переходим к следующему
632 632
         unset($this->user_id_to_provider[$user_id]);
633 633
         // Де-регистрируем игрока из таблицы трансляции игроков
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
   // OK v4.5
649 649
   protected function get_active_user() {
650 650
     // Проверяем куку "текущего игрока" из браузера
651
-    if(
651
+    if (
652 652
       // Кука не пустая
653 653
       ($_COOKIE[SN_COOKIE_U] = trim($_COOKIE[SN_COOKIE_U])) && !empty($_COOKIE[SN_COOKIE_U])
654 654
       // И в куке находится ID
@@ -673,7 +673,7 @@  discard block
 block discarded – undo
673 673
     }
674 674
 
675 675
     // В куке нет валидного ИД записи игрока, доступной с текущих аккаунтов
676
-    if(empty(self::$user['id'])) {
676
+    if (empty(self::$user['id'])) {
677 677
       // Берем первого из доступных
678 678
       // TODO - default_user
679 679
       self::$user = reset($this->accessible_user_row_list);
@@ -697,7 +697,7 @@  discard block
 block discarded – undo
697 697
 
698 698
     $result = array();
699 699
 
700
-    if($user_id && empty($this->is_impersonating)) {
700
+    if ($user_id && empty($this->is_impersonating)) {
701 701
       // self::db_counter_insert();
702 702
       self::$device->db_counter_insert($user_id);
703 703
 
@@ -705,12 +705,12 @@  discard block
 block discarded – undo
705 705
 
706 706
       sys_user_options_unpack($user);
707 707
 
708
-      if($user['banaday'] && $user['banaday'] <= SN_TIME_NOW) {
708
+      if ($user['banaday'] && $user['banaday'] <= SN_TIME_NOW) {
709 709
         $user['banaday'] = 0;
710 710
         $user['vacation'] = SN_TIME_NOW;
711 711
       }
712 712
 
713
-      $user['user_lastip'] = self::$device->ip_v4_string;// $ip['ip'];
713
+      $user['user_lastip'] = self::$device->ip_v4_string; // $ip['ip'];
714 714
       $user['user_proxy'] = self::$device->ip_v4_proxy_chain; //$ip['proxy_chain'];
715 715
 
716 716
       $result[F_BANNED_STATUS] = $user['banaday'];
@@ -724,9 +724,9 @@  discard block
 block discarded – undo
724 724
       );
725 725
     }
726 726
 
727
-    if($extra = $config->security_ban_extra) {
727
+    if ($extra = $config->security_ban_extra) {
728 728
       $extra = explode(',', $extra);
729
-      array_walk($extra,'trim');
729
+      array_walk($extra, 'trim');
730 730
       in_array(self::$device->device_id, $extra) and die();
731 731
     }
732 732
 
@@ -762,21 +762,21 @@  discard block
 block discarded – undo
762 762
   protected function register_player_name_validate($player_name_unsafe) {
763 763
     // TODO - переделать под RAW-строки
764 764
     // Если имя игрока пустое - NO GO!
765
-    if(trim($player_name_unsafe) == '') {
765
+    if (trim($player_name_unsafe) == '') {
766 766
       throw new Exception(REGISTER_ERROR_PLAYER_NAME_EMPTY, ERR_ERROR);
767 767
     }
768 768
     // Проверяем, что бы в начале и конце не было пустых символов
769
-    if($player_name_unsafe != trim($player_name_unsafe)) {
769
+    if ($player_name_unsafe != trim($player_name_unsafe)) {
770 770
       throw new Exception(REGISTER_ERROR_PLAYER_NAME_TRIMMED, ERR_ERROR);
771 771
     }
772 772
     // Если логин имеет запрещенные символы - NO GO!
773
-    if(strpbrk($player_name_unsafe, LOGIN_REGISTER_CHARACTERS_PROHIBITED)) {
773
+    if (strpbrk($player_name_unsafe, LOGIN_REGISTER_CHARACTERS_PROHIBITED)) {
774 774
       // TODO - выдавать в сообщение об ошибке список запрещенных символов
775 775
       // TODO - заранее извещать игрока, какие символы являются запрещенными
776 776
       throw new Exception(REGISTER_ERROR_PLAYER_NAME_RESTRICTED_CHARACTERS, ERR_ERROR);
777 777
     }
778 778
     // Если логин меньше минимальной длины - NO GO!
779
-    if(strlen($player_name_unsafe) < LOGIN_LENGTH_MIN) {
779
+    if (strlen($player_name_unsafe) < LOGIN_LENGTH_MIN) {
780 780
       // TODO - выдавать в сообщение об ошибке минимальную длину имени игрока
781 781
       // TODO - заранее извещать игрока, какая минимальная и максимальная длина имени
782 782
       throw new Exception(REGISTER_ERROR_PLAYER_NAME_SHORT, ERR_ERROR);
@@ -834,7 +834,7 @@  discard block
 block discarded – undo
834 834
   }
835 835
 
836 836
   protected static function flog($message, $die = false) {
837
-    if(!defined('DEBUG_AUTH') || !DEBUG_AUTH) {
837
+    if (!defined('DEBUG_AUTH') || !DEBUG_AUTH) {
838 838
       return;
839 839
     }
840 840
     list($called, $caller) = debug_backtrace(false);
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
     $_SERVER['SERVER_NAME'] == 'localhost' ? print("<div class='debug'>$message - $caller_name\r\n</div>") : false;
848 848
 
849 849
     classSupernova::log_file("$message - $caller_name");
850
-    if($die) {
850
+    if ($die) {
851 851
       // pdump($caller);
852 852
       // pdump(debug_backtrace(false));
853 853
       $die && die("<div class='negative'>СТОП! Функция {$caller_name} при вызове в " . get_called_class() . " (располагается в " . get_class() . "). СООБЩИТЕ АДМИНИСТРАЦИИ!</div>");
Please login to merge, or discard this patch.
includes/classes/db_mysql.php 2 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -180,6 +180,9 @@  discard block
 block discarded – undo
180 180
   }
181 181
 
182 182
 
183
+  /**
184
+   * @param string $query
185
+   */
183 186
   function security_watch_user_queries($query) {
184 187
     // TODO Заменить это на новый логгер
185 188
     global $config, $is_watching, $user, $debug;
@@ -202,6 +205,9 @@  discard block
 block discarded – undo
202 205
   }
203 206
 
204 207
 
208
+  /**
209
+   * @param string $query
210
+   */
205 211
   function security_query_check_bad_words($query) {
206 212
     global $user, $dm_change_legit, $mm_change_legit;
207 213
 
Please login to merge, or discard this patch.
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -76,23 +76,23 @@  discard block
 block discarded – undo
76 76
   function sn_db_connect($external_db_settings = null) {
77 77
     $this->db_disconnect();
78 78
 
79
-    if(!empty($external_db_settings) && is_array($external_db_settings)) {
79
+    if (!empty($external_db_settings) && is_array($external_db_settings)) {
80 80
       $this->dbsettings = $external_db_settings;
81 81
     }
82 82
 
83
-    if(empty($this->dbsettings)) {
83
+    if (empty($this->dbsettings)) {
84 84
       $this->load_db_settings();
85 85
     }
86 86
 
87 87
     // TODO - фатальные (?) ошибки на каждом шагу. Хотя - скорее Эксепшны
88
-    if(!empty($this->dbsettings)) {
88
+    if (!empty($this->dbsettings)) {
89 89
       $driver_name = empty($this->dbsettings['sn_driver']) ? 'db_mysql_v5' : $this->dbsettings['sn_driver'];
90 90
       $this->driver = new $driver_name();
91 91
       $this->db_prefix = $this->dbsettings['prefix'];
92 92
 
93 93
       $this->connected = $this->connected || $this->driver_connect();
94 94
 
95
-      if($this->connected) {
95
+      if ($this->connected) {
96 96
         $this->table_list = $this->db_get_table_list();
97 97
         // TODO Проверка на пустоту
98 98
       }
@@ -106,11 +106,11 @@  discard block
 block discarded – undo
106 106
   function driver_connect() {
107 107
     global $debug;
108 108
 
109
-    if(!is_object($this->driver)) {
109
+    if (!is_object($this->driver)) {
110 110
       $debug->error_fatal('DB Error - No driver for MySQL found!');
111 111
     }
112 112
 
113
-    if(!method_exists($this->driver, 'mysql_connect')) {
113
+    if (!method_exists($this->driver, 'mysql_connect')) {
114 114
       $debug->error_fatal('DB Error - WRONG MySQL driver!');
115 115
     }
116 116
 
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
   }
119 119
 
120 120
   function db_disconnect() {
121
-    if($this->connected) {
121
+    if ($this->connected) {
122 122
       $this->connected = !$this->driver_disconnect();
123 123
       $this->connected = false;
124 124
     }
@@ -129,11 +129,11 @@  discard block
 block discarded – undo
129 129
   function doquery($query, $table = '', $fetch = false, $skip_query_check = false) {
130 130
     global $numqueries, $debug, $sn_cache, $config;
131 131
 
132
-    if(!is_string($table)) {
132
+    if (!is_string($table)) {
133 133
       $fetch = $table;
134 134
     }
135 135
 
136
-    if(!$this->connected) {
136
+    if (!$this->connected) {
137 137
       $this->sn_db_connect();
138 138
     }
139 139
 
@@ -142,31 +142,31 @@  discard block
 block discarded – undo
142 142
     $skip_query_check or $this->security_query_check_bad_words($query);
143 143
 
144 144
     $sql = $query;
145
-    if(strpos($sql, '{{') !== false) {
145
+    if (strpos($sql, '{{') !== false) {
146 146
 //     foreach($sn_cache->tables as $tableName) {
147
-      foreach($this->table_list as $tableName) {
147
+      foreach ($this->table_list as $tableName) {
148 148
         $sql = str_replace("{{{$tableName}}}", $this->db_prefix . $tableName, $sql);
149 149
       }
150 150
     }
151 151
 
152
-    if($config->debug) {
152
+    if ($config->debug) {
153 153
       $numqueries++;
154 154
       $arr = debug_backtrace();
155
-      $file = end(explode('/',$arr[0]['file']));
155
+      $file = end(explode('/', $arr[0]['file']));
156 156
       $line = $arr[0]['line'];
157 157
       $debug->add("<tr><th>Query $numqueries: </th><th>$query</th><th>$file($line)</th><th>$table</th><th>$fetch</th></tr>");
158 158
     }
159 159
 
160
-    if(defined('DEBUG_SQL_COMMENT')) {
160
+    if (defined('DEBUG_SQL_COMMENT')) {
161 161
       $backtrace = debug_backtrace();
162 162
       $sql_comment = $debug->compact_backtrace($backtrace, defined('DEBUG_SQL_COMMENT_LONG'));
163 163
 
164 164
       $sql_commented = '/* ' . implode("<br />", $sql_comment) . '<br /> */ ' . preg_replace("/\s+/", ' ', $sql);
165
-      if(defined('DEBUG_SQL_ONLINE')) {
165
+      if (defined('DEBUG_SQL_ONLINE')) {
166 166
         $debug->warning($sql_commented, 'SQL Debug', LOG_DEBUG_SQL);
167 167
       }
168 168
 
169
-      if(defined('DEBUG_SQL_ERROR')) {
169
+      if (defined('DEBUG_SQL_ERROR')) {
170 170
         array_unshift($sql_comment, preg_replace("/\s+/", ' ', $sql));
171 171
         $debug->add_to_array($sql_comment);
172 172
         // $debug->add_to_array($sql_comment . preg_replace("/\s+/", ' ', $sql));
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
       $sql = $sql_commented;
175 175
     }
176 176
 
177
-    $sqlquery = $this->db_sql_query($sql) or $debug->error(db_error()."<br />$sql<br />",'SQL Error');
177
+    $sqlquery = $this->db_sql_query($sql) or $debug->error(db_error() . "<br />$sql<br />", 'SQL Error');
178 178
 
179 179
     return $fetch ? $this->db_fetch($sqlquery) : $sqlquery;
180 180
   }
@@ -184,16 +184,16 @@  discard block
 block discarded – undo
184 184
     // TODO Заменить это на новый логгер
185 185
     global $config, $is_watching, $user, $debug;
186 186
 
187
-    if(!$is_watching && $config->game_watchlist_array && in_array($user['id'], $config->game_watchlist_array))
187
+    if (!$is_watching && $config->game_watchlist_array && in_array($user['id'], $config->game_watchlist_array))
188 188
     {
189
-      if(!preg_match('/^(select|commit|rollback|start transaction)/i', $query)) {
189
+      if (!preg_match('/^(select|commit|rollback|start transaction)/i', $query)) {
190 190
         $is_watching = true;
191 191
         $msg = "\$query = \"{$query}\"\n\r";
192
-        if(!empty($_POST)) {
193
-          $msg .= "\n\r" . dump($_POST,'$_POST');
192
+        if (!empty($_POST)) {
193
+          $msg .= "\n\r" . dump($_POST, '$_POST');
194 194
         }
195
-        if(!empty($_GET)) {
196
-          $msg .= "\n\r" . dump($_GET,'$_GET');
195
+        if (!empty($_GET)) {
196
+          $msg .= "\n\r" . dump($_GET, '$_GET');
197 197
         }
198 198
         $debug->warning($msg, "Watching user {$user['id']}", 399, array('base_dump' => true));
199 199
         $is_watching = false;
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
   function security_query_check_bad_words($query) {
206 206
     global $user, $dm_change_legit, $mm_change_legit;
207 207
 
208
-    switch(true) {
208
+    switch (true) {
209 209
       case stripos($query, 'RUNCATE TABL') != false:
210 210
       case stripos($query, 'ROP TABL') != false:
211 211
       case stripos($query, 'ENAME TABL') != false:
@@ -216,33 +216,33 @@  discard block
 block discarded – undo
216 216
       case stripos($query, 'RPG_POINTS') != false && stripos(trim($query), 'UPDATE ') === 0 && !$dm_change_legit:
217 217
       case stripos($query, 'METAMATTER') != false && stripos(trim($query), 'UPDATE ') === 0 && !$mm_change_legit:
218 218
       case stripos($query, 'AUTHLEVEL') != false && $user['authlevel'] < 3 && stripos($query, 'SELECT') !== 0:
219
-        $report  = "Hacking attempt (".date("d.m.Y H:i:s")." - [".time()."]):\n";
219
+        $report  = "Hacking attempt (" . date("d.m.Y H:i:s") . " - [" . time() . "]):\n";
220 220
         $report .= ">Database Inforamation\n";
221
-        $report .= "\tID - ".$user['id']."\n";
222
-        $report .= "\tUser - ".$user['username']."\n";
223
-        $report .= "\tAuth level - ".$user['authlevel']."\n";
224
-        $report .= "\tAdmin Notes - ".$user['adminNotes']."\n";
225
-        $report .= "\tCurrent Planet - ".$user['current_planet']."\n";
226
-        $report .= "\tUser IP - ".$user['user_lastip']."\n";
227
-        $report .= "\tUser IP at Reg - ".$user['ip_at_reg']."\n";
228
-        $report .= "\tUser Agent- ".$_SERVER['HTTP_USER_AGENT']."\n";
229
-        $report .= "\tCurrent Page - ".$user['current_page']."\n";
230
-        $report .= "\tRegister Time - ".$user['register_time']."\n";
221
+        $report .= "\tID - " . $user['id'] . "\n";
222
+        $report .= "\tUser - " . $user['username'] . "\n";
223
+        $report .= "\tAuth level - " . $user['authlevel'] . "\n";
224
+        $report .= "\tAdmin Notes - " . $user['adminNotes'] . "\n";
225
+        $report .= "\tCurrent Planet - " . $user['current_planet'] . "\n";
226
+        $report .= "\tUser IP - " . $user['user_lastip'] . "\n";
227
+        $report .= "\tUser IP at Reg - " . $user['ip_at_reg'] . "\n";
228
+        $report .= "\tUser Agent- " . $_SERVER['HTTP_USER_AGENT'] . "\n";
229
+        $report .= "\tCurrent Page - " . $user['current_page'] . "\n";
230
+        $report .= "\tRegister Time - " . $user['register_time'] . "\n";
231 231
         $report .= "\n";
232 232
 
233 233
         $report .= ">Query Information\n";
234
-        $report .= "\tQuery - ".$query."\n";
234
+        $report .= "\tQuery - " . $query . "\n";
235 235
         $report .= "\n";
236 236
 
237 237
         $report .= ">\$_SERVER Information\n";
238
-        $report .= "\tIP - ".$_SERVER['REMOTE_ADDR']."\n";
239
-        $report .= "\tHost Name - ".$_SERVER['HTTP_HOST']."\n";
240
-        $report .= "\tUser Agent - ".$_SERVER['HTTP_USER_AGENT']."\n";
241
-        $report .= "\tRequest Method - ".$_SERVER['REQUEST_METHOD']."\n";
242
-        $report .= "\tCame From - ".$_SERVER['HTTP_REFERER']."\n";
243
-        $report .= "\tPage is - ".$_SERVER['SCRIPT_NAME']."\n";
244
-        $report .= "\tUses Port - ".$_SERVER['REMOTE_PORT']."\n";
245
-        $report .= "\tServer Protocol - ".$_SERVER['SERVER_PROTOCOL']."\n";
238
+        $report .= "\tIP - " . $_SERVER['REMOTE_ADDR'] . "\n";
239
+        $report .= "\tHost Name - " . $_SERVER['HTTP_HOST'] . "\n";
240
+        $report .= "\tUser Agent - " . $_SERVER['HTTP_USER_AGENT'] . "\n";
241
+        $report .= "\tRequest Method - " . $_SERVER['REQUEST_METHOD'] . "\n";
242
+        $report .= "\tCame From - " . $_SERVER['HTTP_REFERER'] . "\n";
243
+        $report .= "\tPage is - " . $_SERVER['SCRIPT_NAME'] . "\n";
244
+        $report .= "\tUses Port - " . $_SERVER['REMOTE_PORT'] . "\n";
245
+        $report .= "\tServer Protocol - " . $_SERVER['SERVER_PROTOCOL'] . "\n";
246 246
 
247 247
         $report .= "\n--------------------------------------------------------------------------------------------------\n";
248 248
 
@@ -262,11 +262,11 @@  discard block
 block discarded – undo
262 262
     $prefix_length = strlen($this->db_prefix);
263 263
 
264 264
     $tl = array();
265
-    while($row = $this->db_fetch($query)) {
266
-      foreach($row as $table_name) {
267
-        if(strpos($table_name, $this->db_prefix) === 0) {
265
+    while ($row = $this->db_fetch($query)) {
266
+      foreach ($row as $table_name) {
267
+        if (strpos($table_name, $this->db_prefix) === 0) {
268 268
           $table_name = substr($table_name, $prefix_length);
269
-        } elseif($prefixed_only) {
269
+        } elseif ($prefixed_only) {
270 270
           continue;
271 271
         }
272 272
         // $table_name = str_replace($db_prefix, '', $table_name);
Please login to merge, or discard this patch.
includes/classes/db_mysql_v4.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -55,6 +55,9 @@
 block discarded – undo
55 55
     return true;
56 56
   }
57 57
 
58
+  /**
59
+   * @param string $query_string
60
+   */
58 61
   function mysql_query($query_string) {
59 62
     return mysql_query($query_string, $this->link);
60 63
   }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -30,17 +30,17 @@  discard block
 block discarded – undo
30 30
 
31 31
     static $need_keys = array('server', 'user', 'pass', 'name', 'prefix');
32 32
 
33
-    if($this->connected) {
33
+    if ($this->connected) {
34 34
       return true;
35 35
     }
36 36
 
37
-    if(empty($settings) || !is_array($settings) || array_intersect($need_keys, array_keys($settings)) != $need_keys) {
37
+    if (empty($settings) || !is_array($settings) || array_intersect($need_keys, array_keys($settings)) != $need_keys) {
38 38
       $debug->error_fatal('There is missconfiguration in your config.php. Check it again', $this->mysql_error());
39 39
     }
40 40
 
41 41
     // TODO !!!!!! DEBUG -> error!!!!
42 42
     @$this->link = mysql_connect($settings['server'], $settings['user'], $settings['pass']);
43
-    if(!is_resource($this->link)) {
43
+    if (!is_resource($this->link)) {
44 44
       $debug->error_fatal('DB Error - cannot connect to server', $this->mysql_error());
45 45
     }
46 46
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
     return mysql_real_escape_string($unescaped_string, $this->link);
69 69
   }
70 70
   function mysql_close_link() {
71
-    if($this->connected) {
71
+    if ($this->connected) {
72 72
       $this->connected = false;
73 73
       mysql_close($this->link);
74 74
       unset($this->link);
Please login to merge, or discard this patch.
includes/classes/functions_template.php 4 patches
Doc Comments   +8 added lines patch added patch discarded remove patch
@@ -47,6 +47,7 @@  discard block
 block discarded – undo
47 47
 
48 48
   /**
49 49
   * constuctor
50
+  * @param template $template
50 51
   */
51 52
   function template_compile(&$template)
52 53
   {
@@ -463,6 +464,7 @@  discard block
 block discarded – undo
463 464
   * Compile IF tags - much of this is from Smarty with
464 465
   * some adaptions for our block level methods
465 466
   * @access private
467
+  * @param boolean $elseif
466 468
   */
467 469
   function compile_tag_if($tag_args, $elseif)
468 470
   {
@@ -620,6 +622,7 @@  discard block
 block discarded – undo
620 622
   /**
621 623
   * Compile DEFINE tags
622 624
   * @access private
625
+  * @param boolean $op
623 626
   */
624 627
   function compile_tag_define($tag_args, $op)
625 628
   {
@@ -698,6 +701,7 @@  discard block
 block discarded – undo
698 701
   * parse expression
699 702
   * This is from Smarty
700 703
   * @access private
704
+  * @param string $is_arg
701 705
   */
702 706
   function _parse_is_expr($is_arg, $tokens)
703 707
   {
@@ -794,6 +798,8 @@  discard block
 block discarded – undo
794 798
   * If $include_last_iterator is true, then [$_childN_i] will be appended to the form shown above.
795 799
   * NOTE: does not expect a trailing "." on the blockname.
796 800
   * @access private
801
+  * @param string $blockname
802
+  * @param boolean $include_last_iterator
797 803
   */
798 804
   function generate_block_data_ref($blockname, $include_last_iterator, $defop = false)
799 805
   {
@@ -832,6 +838,7 @@  discard block
 block discarded – undo
832 838
   /**
833 839
   * Write compiled file to cache directory
834 840
   * @access private
841
+  * @param string $data
835 842
   */
836 843
   function compile_write($handle, $data)
837 844
   {
@@ -857,6 +864,7 @@  discard block
 block discarded – undo
857 864
   /**
858 865
   * Minifies template w/i PHP code by removing extra spaces
859 866
   * @access private
867
+  * @return string
860 868
   */
861 869
   function minify($html)
862 870
   {
Please login to merge, or discard this patch.
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -46,17 +46,17 @@  discard block
 block discarded – undo
46 46
   var $block_else_level = array();
47 47
 
48 48
   /**
49
-  * constuctor
50
-  */
49
+   * constuctor
50
+   */
51 51
   function template_compile(&$template)
52 52
   {
53 53
     $this->template = &$template;
54 54
   }
55 55
 
56 56
   /**
57
-  * Load template source from file
58
-  * @access private
59
-  */
57
+   * Load template source from file
58
+   * @access private
59
+   */
60 60
   function _tpl_load_file($handle, $store_in_db = false)
61 61
   {
62 62
     // Try and open template for read
@@ -99,10 +99,10 @@  discard block
 block discarded – undo
99 99
   }
100 100
 
101 101
   /**
102
-  * Remove any PHP tags that do not belong, these regular expressions are derived from
103
-  * the ones that exist in zend_language_scanner.l
104
-  * @access private
105
-  */
102
+   * Remove any PHP tags that do not belong, these regular expressions are derived from
103
+   * the ones that exist in zend_language_scanner.l
104
+   * @access private
105
+   */
106 106
   function remove_php_tags(&$code)
107 107
   {
108 108
     // This matches the information gathered from the internal PHP lexer
@@ -116,9 +116,9 @@  discard block
 block discarded – undo
116 116
   }
117 117
 
118 118
   /**
119
-  * The all seeing all doing compile method. Parts are inspired by or directly from Smarty
120
-  * @access private
121
-  */
119
+   * The all seeing all doing compile method. Parts are inspired by or directly from Smarty
120
+   * @access private
121
+   */
122 122
   function compile($code, $no_echo = false, $echo_var = '')
123 123
   {
124 124
     global $config;
@@ -289,9 +289,9 @@  discard block
 block discarded – undo
289 289
   }
290 290
 
291 291
   /**
292
-  * Compile variables
293
-  * @access private
294
-  */
292
+   * Compile variables
293
+   * @access private
294
+   */
295 295
   function compile_var_tags(&$text_blocks)
296 296
   {
297 297
     // including $lang variable
@@ -354,9 +354,9 @@  discard block
 block discarded – undo
354 354
   }
355 355
 
356 356
   /**
357
-  * Compile blocks
358
-  * @access private
359
-  */
357
+   * Compile blocks
358
+   * @access private
359
+   */
360 360
   function compile_tag_block($tag_args)
361 361
   {
362 362
     $no_nesting = false;
@@ -442,14 +442,14 @@  discard block
 block discarded – undo
442 442
     $tag_template_php .= 'if ($_' . $tag_args . '_count) {';
443 443
 
444 444
     /**
445
-    * The following uses foreach for iteration instead of a for loop, foreach is faster but requires PHP to make a copy of the contents of the array which uses more memory
446
-    * <code>
447
-    * if (!$offset)
448
-    * {
449
-    *   $tag_template_php .= 'foreach (' . $varref . ' as $_' . $tag_args . '_i => $_' . $tag_args . '_val){';
450
-    * }
451
-    * </code>
452
-    */
445
+     * The following uses foreach for iteration instead of a for loop, foreach is faster but requires PHP to make a copy of the contents of the array which uses more memory
446
+     * <code>
447
+     * if (!$offset)
448
+     * {
449
+     *   $tag_template_php .= 'foreach (' . $varref . ' as $_' . $tag_args . '_i => $_' . $tag_args . '_val){';
450
+     * }
451
+     * </code>
452
+     */
453 453
 
454 454
     $tag_template_php .= 'for ($_' . $tag_args . '_i = ' . $loop_start . '; $_' . $tag_args . '_i < ' . $loop_end . '; ++$_' . $tag_args . '_i){';
455 455
 //    $tag_template_php .= '$this->_block_counter["'. $tag_args . '"] = $_' . $tag_args . '_i;';
@@ -460,10 +460,10 @@  discard block
 block discarded – undo
460 460
   }
461 461
 
462 462
   /**
463
-  * Compile IF tags - much of this is from Smarty with
464
-  * some adaptions for our block level methods
465
-  * @access private
466
-  */
463
+   * Compile IF tags - much of this is from Smarty with
464
+   * some adaptions for our block level methods
465
+   * @access private
466
+   */
467 467
   function compile_tag_if($tag_args, $elseif)
468 468
   {
469 469
     // Tokenize args for 'if' tag.
@@ -618,9 +618,9 @@  discard block
 block discarded – undo
618 618
   }
619 619
 
620 620
   /**
621
-  * Compile DEFINE tags
622
-  * @access private
623
-  */
621
+   * Compile DEFINE tags
622
+   * @access private
623
+   */
624 624
   function compile_tag_define($tag_args, $op)
625 625
   {
626 626
     preg_match('#^((?:[a-z0-9\-_]+\.)+)?\$(?=[A-Z])([A-Z0-9_\-]*)(?: = (\'?)([^\']*)(\'?))?$#', $tag_args, $match);
@@ -671,9 +671,9 @@  discard block
 block discarded – undo
671 671
   }
672 672
 
673 673
   /**
674
-  * Compile INCLUDE tag
675
-  * @access private
676
-  */
674
+   * Compile INCLUDE tag
675
+   * @access private
676
+   */
677 677
   function compile_tag_include($tag_args)
678 678
   {
679 679
     // Process dynamic includes
@@ -686,19 +686,19 @@  discard block
 block discarded – undo
686 686
   }
687 687
 
688 688
   /**
689
-  * Compile INCLUDE_PHP tag
690
-  * @access private
691
-  */
689
+   * Compile INCLUDE_PHP tag
690
+   * @access private
691
+   */
692 692
   function compile_tag_include_php($tag_args)
693 693
   {
694 694
     return "\$this->_php_include('$tag_args');";
695 695
   }
696 696
 
697 697
   /**
698
-  * parse expression
699
-  * This is from Smarty
700
-  * @access private
701
-  */
698
+   * parse expression
699
+   * This is from Smarty
700
+   * @access private
701
+   */
702 702
   function _parse_is_expr($is_arg, $tokens)
703 703
   {
704 704
     $expr_end = 0;
@@ -763,13 +763,13 @@  discard block
 block discarded – undo
763 763
   }
764 764
 
765 765
   /**
766
-  * Generates a reference to the given variable inside the given (possibly nested)
767
-  * block namespace. This is a string of the form:
768
-  * ' . $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['varname'] . '
769
-  * It's ready to be inserted into an "echo" line in one of the templates.
770
-  * NOTE: expects a trailing "." on the namespace.
771
-  * @access private
772
-  */
766
+   * Generates a reference to the given variable inside the given (possibly nested)
767
+   * block namespace. This is a string of the form:
768
+   * ' . $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['varname'] . '
769
+   * It's ready to be inserted into an "echo" line in one of the templates.
770
+   * NOTE: expects a trailing "." on the namespace.
771
+   * @access private
772
+   */
773 773
   function generate_block_varref($namespace, $varname, $echo = true, $defop = false)
774 774
   {
775 775
     // Strip the trailing period.
@@ -787,14 +787,14 @@  discard block
 block discarded – undo
787 787
   }
788 788
 
789 789
   /**
790
-  * Generates a reference to the array of data values for the given
791
-  * (possibly nested) block namespace. This is a string of the form:
792
-  * $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['$childN']
793
-  *
794
-  * If $include_last_iterator is true, then [$_childN_i] will be appended to the form shown above.
795
-  * NOTE: does not expect a trailing "." on the blockname.
796
-  * @access private
797
-  */
790
+   * Generates a reference to the array of data values for the given
791
+   * (possibly nested) block namespace. This is a string of the form:
792
+   * $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['$childN']
793
+   *
794
+   * If $include_last_iterator is true, then [$_childN_i] will be appended to the form shown above.
795
+   * NOTE: does not expect a trailing "." on the blockname.
796
+   * @access private
797
+   */
798 798
   function generate_block_data_ref($blockname, $include_last_iterator, $defop = false)
799 799
   {
800 800
     // Get an array of the blocks involved.
@@ -830,9 +830,9 @@  discard block
 block discarded – undo
830 830
   }
831 831
 
832 832
   /**
833
-  * Write compiled file to cache directory
834
-  * @access private
835
-  */
833
+   * Write compiled file to cache directory
834
+   * @access private
835
+   */
836 836
   function compile_write($handle, $data)
837 837
   {
838 838
     $filename = $this->template->cachepath . str_replace('/', '.', $this->template->filename[$handle]) . DOT_PHP_EX;
@@ -855,9 +855,9 @@  discard block
 block discarded – undo
855 855
 
856 856
   // Gorlum's minifier BOF
857 857
   /**
858
-  * Minifies template w/i PHP code by removing extra spaces
859
-  * @access private
860
-  */
858
+   * Minifies template w/i PHP code by removing extra spaces
859
+   * @access private
860
+   */
861 861
   function minify($html)
862 862
   {
863 863
     global $config;
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -142,9 +142,9 @@  discard block
 block discarded – undo
142 142
 
143 143
     preg_match_all('#<!-- INCLUDE (\{\$?[A-Z0-9\-_]+\}|[a-zA-Z0-9\_\-\+\./]+) -->#', $code, $matches);
144 144
     $include_blocks = $matches[1];
145
-    if($include_blocks)
145
+    if ($include_blocks)
146 146
     {
147
-      foreach($include_blocks as &$included_file)
147
+      foreach ($include_blocks as &$included_file)
148 148
       {
149 149
         $included_file .= '.tpl.html';
150 150
       }
@@ -453,8 +453,8 @@  discard block
 block discarded – undo
453 453
 
454 454
     $tag_template_php .= 'for ($_' . $tag_args . '_i = ' . $loop_start . '; $_' . $tag_args . '_i < ' . $loop_end . '; ++$_' . $tag_args . '_i){';
455 455
 //    $tag_template_php .= '$this->_block_counter["'. $tag_args . '"] = $_' . $tag_args . '_i;';
456
-    $tag_template_php .= '$_'. $tag_args . '_val = &' . $varref . '[$_'. $tag_args. '_i];';
457
-    $tag_template_php .= '$this->_block_value["'. $tag_args . '"] = &' . $varref . '[$_'. $tag_args. '_i];';
456
+    $tag_template_php .= '$_' . $tag_args . '_val = &' . $varref . '[$_' . $tag_args . '_i];';
457
+    $tag_template_php .= '$this->_block_value["' . $tag_args . '"] = &' . $varref . '[$_' . $tag_args . '_i];';
458 458
 
459 459
     return $tag_template_php;
460 460
   }
@@ -558,10 +558,10 @@  discard block
 block discarded – undo
558 558
         break;
559 559
 
560 560
         case 'is':
561
-          $is_arg_start = ($tokens[$i-1] == ')') ? array_pop($is_arg_stack) : $i-1;
561
+          $is_arg_start = ($tokens[$i - 1] == ')') ? array_pop($is_arg_stack) : $i - 1;
562 562
           $is_arg = implode(' ', array_slice($tokens, $is_arg_start, $i - $is_arg_start));
563 563
 
564
-          $new_tokens = $this->_parse_is_expr($is_arg, array_slice($tokens, $i+1));
564
+          $new_tokens = $this->_parse_is_expr($is_arg, array_slice($tokens, $i + 1));
565 565
 
566 566
           array_splice($tokens, $is_arg_start, sizeof($tokens), $new_tokens);
567 567
 
@@ -821,11 +821,11 @@  discard block
 block discarded – undo
821 821
     }
822 822
     else if ($include_last_iterator)
823 823
     {
824
-      return '$_'. $blocks[$blockcount] . '_val';
824
+      return '$_' . $blocks[$blockcount] . '_val';
825 825
     }
826 826
     else
827 827
     {
828
-      return '$_'. $blocks[$blockcount - 1] . '_val[\''. $blocks[$blockcount]. '\']';
828
+      return '$_' . $blocks[$blockcount - 1] . '_val[\'' . $blocks[$blockcount] . '\']';
829 829
     }
830 830
   }
831 831
 
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
     if ($fp = @fopen($filename, 'wb'))
843 843
     {
844 844
       @flock($fp, LOCK_EX);
845
-      @fwrite ($fp, $data);
845
+      @fwrite($fp, $data);
846 846
       @flock($fp, LOCK_UN);
847 847
       @fclose($fp);
848 848
 
@@ -862,7 +862,7 @@  discard block
 block discarded – undo
862 862
   {
863 863
     global $config;
864 864
 
865
-    if(!$config->tpl_minifier)
865
+    if (!$config->tpl_minifier)
866 866
     {
867 867
       return $html;
868 868
     }
@@ -874,14 +874,14 @@  discard block
 block discarded – undo
874 874
     //$html = preg_replace('/[\r\n\t]+/', ' ', $html);
875 875
     $html = preg_replace('/>[\s]*</', '><', $html); // Strip spacechars between tags
876 876
     $html = preg_replace('/[\s]+/', ' ', $html); // Replace several spacechars with one space
877
-    if(!empty($pre[0]))
877
+    if (!empty($pre[0]))
878 878
     {
879
-      foreach($pre[0] as $tag)
879
+      foreach ($pre[0] as $tag)
880 880
       {
881 881
         $tag = preg_replace('/^\ *\/\/[^\<]*?$/m', ' ', $tag); // Strips comments - except those that contains HTML comment inside
882 882
         $tag = preg_replace('/[\ \t]{2,}/', ' ', $tag); // Replace several spaces by one
883 883
         $tag = preg_replace('/\s{2,}/', "\r\n", $tag); // Replace several linefeeds by one
884
-        $html = preg_replace('/#pre#/', $tag, $html,1);
884
+        $html = preg_replace('/#pre#/', $tag, $html, 1);
885 885
       }
886 886
     }
887 887
 
Please login to merge, or discard this patch.
Braces   +18 added lines, -36 removed lines patch added patch discarded remove patch
@@ -66,8 +66,7 @@  discard block
 block discarded – undo
66 66
       {
67 67
         return;
68 68
         trigger_error("template->_tpl_load_file(): File {$this->template->files[$handle]} does not exist or is empty", E_USER_ERROR);
69
-      }
70
-      else
69
+      } else
71 70
       {
72 71
         $this->template->files[$handle] = $this->template->files_inherit[$handle];
73 72
       }
@@ -225,15 +224,13 @@  discard block
 block discarded – undo
225 224
               $var = substr($temp, 2, -1);
226 225
               //$file = $this->template->_tpldata['DEFINE']['.'][$var];
227 226
               $temp = "\$this->_tpldata['DEFINE']['.']['$var']";
228
-            }
229
-            else
227
+            } else
230 228
             {
231 229
               $var = substr($temp, 1, -1);
232 230
               //$file = $this->template->_rootref[$var];
233 231
               $temp = "\$this->_rootref['$var']";
234 232
             }
235
-          }
236
-          else
233
+          } else
237 234
           {
238 235
             $file = $temp;
239 236
           }
@@ -381,8 +378,7 @@  discard block
 block discarded – undo
381 378
       if ($match[2] < 0)
382 379
       {
383 380
         $loop_start = '($_' . $tag_args . '_count ' . $match[2] . ' < 0 ? 0 : $_' . $tag_args . '_count ' . $match[2] . ')';
384
-      }
385
-      else
381
+      } else
386 382
       {
387 383
         $loop_start = '($_' . $tag_args . '_count < ' . $match[2] . ' ? $_' . $tag_args . '_count : ' . $match[2] . ')';
388 384
       }
@@ -390,17 +386,14 @@  discard block
 block discarded – undo
390 386
       if (strlen($match[3]) < 1 || $match[3] == -1)
391 387
       {
392 388
         $loop_end = '$_' . $tag_args . '_count';
393
-      }
394
-      else if ($match[3] >= 0)
389
+      } else if ($match[3] >= 0)
395 390
       {
396 391
         $loop_end = '(' . ($match[3] + 1) . ' > $_' . $tag_args . '_count ? $_' . $tag_args . '_count : ' . ($match[3] + 1) . ')';
397
-      }
398
-      else //if ($match[3] < -1)
392
+      } else //if ($match[3] < -1)
399 393
       {
400 394
         $loop_end = '$_' . $tag_args . '_count' . ($match[3] + 1);
401 395
       }
402
-    }
403
-    else
396
+    } else
404 397
     {
405 398
       $loop_start = 0;
406 399
       $loop_end = '$_' . $tag_args . '_count';
@@ -413,8 +406,7 @@  discard block
 block discarded – undo
413 406
     {
414 407
       // We need to implode $no_nesting times from the end...
415 408
       $block = array_slice($this->block_names, -$no_nesting);
416
-    }
417
-    else
409
+    } else
418 410
     {
419 411
       $block = $this->block_names;
420 412
     }
@@ -424,8 +416,7 @@  discard block
 block discarded – undo
424 416
       // Block is not nested.
425 417
       $tag_template_php = '$_' . $tag_args . "_count = (isset(\$this->_tpldata['$tag_args'])) ? sizeof(\$this->_tpldata['$tag_args']) : 0;";
426 418
       $varref = "\$this->_tpldata['$tag_args']";
427
-    }
428
-    else
419
+    } else
429 420
     {
430 421
       // This block is nested.
431 422
       // Generate a namespace string for this block.
@@ -573,8 +564,7 @@  discard block
 block discarded – undo
573 564
           if (preg_match('#^((?:[a-z0-9\-_]+\.)+)?(\$)?(?=[A-Za-z])([A-Za-z0-9\-_]+)#s', $token, $varrefs))
574 565
           {
575 566
             $token = (!empty($varrefs[1])) ? $this->generate_block_data_ref(substr($varrefs[1], 0, -1), true, $varrefs[2]) . '[\'' . $varrefs[3] . '\']' : (($varrefs[2]) ? '$this->_tpldata[\'DEFINE\'][\'.\'][\'' . $varrefs[3] . '\']' : '$this->_rootref[\'' . $varrefs[3] . '\']');
576
-          }
577
-          else if (preg_match('#^\.((?:[a-z0-9\-_]+\.?)+)$#s', $token, $varrefs))
567
+          } else if (preg_match('#^\.((?:[a-z0-9\-_]+\.?)+)$#s', $token, $varrefs))
578 568
           {
579 569
             // Allow checking if loops are set with .loopname
580 570
             // It is also possible to check the loop count by doing <!-- IF .loopname > 1 --> for example
@@ -590,8 +580,7 @@  discard block
 block discarded – undo
590 580
 
591 581
               // Add the block reference for the last child.
592 582
               $varref .= "['" . $block . "']";
593
-            }
594
-            else
583
+            } else
595 584
             {
596 585
               $varref = '$this->_tpldata';
597 586
 
@@ -599,8 +588,7 @@  discard block
 block discarded – undo
599 588
               $varref .= "['" . $blocks[0] . "']";
600 589
             }
601 590
             $token = "sizeof($varref)";
602
-          }
603
-          else if (!empty($token))
591
+          } else if (!empty($token))
604 592
           {
605 593
             $token = '(' . $token . ')';
606 594
           }
@@ -645,8 +633,7 @@  discard block
 block discarded – undo
645 633
 
646 634
       // Now replace the php code
647 635
       $match[4] = "'" . str_replace(array('<?php echo ', '; ?>'), array("' . ", " . '"), $match[4]) . "'";
648
-    }
649
-    else
636
+    } else
650 637
     {
651 638
       preg_match('#true|false|\.#i', $match[4], $type);
652 639
 
@@ -708,8 +695,7 @@  discard block
 block discarded – undo
708 695
     {
709 696
       $negate_expr = true;
710 697
       $expr_type = array_shift($tokens);
711
-    }
712
-    else
698
+    } else
713 699
     {
714 700
       $expr_type = $first_token;
715 701
     }
@@ -722,8 +708,7 @@  discard block
 block discarded – undo
722 708
           $expr_end++;
723 709
           $expr_arg = $tokens[$expr_end++];
724 710
           $expr = "!(($is_arg / $expr_arg) % $expr_arg)";
725
-        }
726
-        else
711
+        } else
727 712
         {
728 713
           $expr = "!($is_arg & 1)";
729 714
         }
@@ -735,8 +720,7 @@  discard block
 block discarded – undo
735 720
           $expr_end++;
736 721
           $expr_arg = $tokens[$expr_end++];
737 722
           $expr = "(($is_arg / $expr_arg) % $expr_arg)";
738
-        }
739
-        else
723
+        } else
740 724
         {
741 725
           $expr = "($is_arg & 1)";
742 726
         }
@@ -818,12 +802,10 @@  discard block
 block discarded – undo
818 802
         $varref .= '[$_' . $blocks[$blockcount] . '_i]';
819 803
       }
820 804
       return $varref;
821
-    }
822
-    else if ($include_last_iterator)
805
+    } else if ($include_last_iterator)
823 806
     {
824 807
       return '$_'. $blocks[$blockcount] . '_val';
825
-    }
826
-    else
808
+    } else
827 809
     {
828 810
       return '$_'. $blocks[$blockcount - 1] . '_val[\''. $blocks[$blockcount]. '\']';
829 811
     }
Please login to merge, or discard this patch.
includes/classes/locale.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -173,6 +173,9 @@
 block discarded – undo
173 173
   }
174 174
 
175 175
 
176
+  /**
177
+   * @param string $path
178
+   */
176 179
   protected function lng_try_filepath($path, $file_path_relative) {
177 180
     $file_path = SN_ROOT_PHYSICAL . ($path && file_exists(SN_ROOT_PHYSICAL . $path . $file_path_relative) ? $path : '') . $file_path_relative;
178 181
     return file_exists($file_path) ? $file_path : false;
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -28,13 +28,13 @@  discard block
 block discarded – undo
28 28
 
29 29
     $this->container = array();
30 30
 
31
-    if(classSupernova::$cache->_MODE != CACHER_NO_CACHE && !classSupernova::$config->locale_cache_disable) {
31
+    if (classSupernova::$cache->_MODE != CACHER_NO_CACHE && !classSupernova::$config->locale_cache_disable) {
32 32
       $this->cache = classSupernova::$cache;
33 33
       classSupernova::log_file('locale.__constructor: Cache is present');
34 34
 //$this->cache->unset_by_prefix($this->cache_prefix); // TODO - remove? 'cause debug!
35 35
     }
36 36
 
37
-    if($enable_stat_usage && empty($this->stat_usage)) {
37
+    if ($enable_stat_usage && empty($this->stat_usage)) {
38 38
       $this->enable_stat_usage = $enable_stat_usage;
39 39
       $this->usage_stat_load();
40 40
       // TODO shutdown function
@@ -60,9 +60,9 @@  discard block
 block discarded – undo
60 60
     unset($fallback[$this->active]);
61 61
 
62 62
     // Проходим по оставшимся локалям
63
-    foreach($fallback as $try_language) {
63
+    foreach ($fallback as $try_language) {
64 64
       // Если нет такой строки - пытаемся вытащить из кэша
65
-      if(!isset($this->container[$try_language][$offset]) && $this->cache) {
65
+      if (!isset($this->container[$try_language][$offset]) && $this->cache) {
66 66
         $this->container[$try_language][$offset] = $this->cache->__get($this->cache_prefix . $try_language . '_' . $offset);
67 67
 // Записываем результат работы кэша
68 68
 $locale_cache_statistic['queries']++;
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
       }
72 72
 
73 73
       // Если мы как-то где-то нашли строку...
74
-      if(isset($this->container[$try_language][$offset])) {
74
+      if (isset($this->container[$try_language][$offset])) {
75 75
         // ...значит она получена в результате фоллбэка и записываем её в кэш и контейнер
76 76
         $this[$offset] = $this->container[$try_language][$offset];
77 77
         $locale_cache_statistic['fallbacks']++;
@@ -87,16 +87,16 @@  discard block
 block discarded – undo
87 87
       $this->container[$this->active][] = $value;
88 88
     } else {
89 89
       $this->container[$this->active][$offset] = $value;
90
-      if($this->cache) {
90
+      if ($this->cache) {
91 91
         $this->cache->__set($this->cache_prefix_lang . $offset, $value);
92 92
       }
93 93
     }
94 94
   }
95 95
   public function offsetExists($offset) {
96 96
     // Шорткат если у нас уже есть строка в памяти PHP
97
-    if(!isset($this->container[$this->active][$offset])) {
97
+    if (!isset($this->container[$this->active][$offset])) {
98 98
 //        pdump($this->cache_prefix_lang . $offset);
99
-      if(!$this->cache || !($this->container[$this->active][$offset] = $this->cache->__get($this->cache_prefix_lang . $offset))) {
99
+      if (!$this->cache || !($this->container[$this->active][$offset] = $this->cache->__get($this->cache_prefix_lang . $offset))) {
100 100
 //        pdump($this->cache_prefix_lang . $offset);
101 101
         // Если нету такой строки - делаем фоллбэк
102 102
         $this->locale_string_fallback($offset);
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
   }
113 113
   public function offsetGet($offset) {
114 114
     $value = $this->offsetExists($offset) ? $this->container[$this->active][$offset] : null;
115
-    if($this->enable_stat_usage) {
115
+    if ($this->enable_stat_usage) {
116 116
       $this->usage_stat_log($offset, $value);
117 117
     }
118 118
     return $value;
@@ -129,24 +129,24 @@  discard block
 block discarded – undo
129 129
   public function usage_stat_load() {
130 130
     global $sn_cache;
131 131
 
132
-    $this->stat_usage = $sn_cache->lng_stat_usage  = array(); // TODO for debug
133
-    if(empty($this->stat_usage)) {
132
+    $this->stat_usage = $sn_cache->lng_stat_usage = array(); // TODO for debug
133
+    if (empty($this->stat_usage)) {
134 134
       $query = doquery("SELECT * FROM {{lng_usage_stat}}");
135
-      while($row = db_fetch($query)) {
135
+      while ($row = db_fetch($query)) {
136 136
         $this->stat_usage[$row['lang_code'] . ':' . $row['string_id'] . ':' . $row['file'] . ':' . $row['line']] = $row['is_empty'];
137 137
       }
138 138
     }
139 139
   }
140 140
   public function usage_stat_save() {
141
-    if(!empty($this->stat_usage_new)) {
141
+    if (!empty($this->stat_usage_new)) {
142 142
       global $sn_cache;
143 143
       $sn_cache->lng_stat_usage = $this->stat_usage;
144 144
       doquery("SELECT 1 FROM {{lng_usage_stat}} LIMIT 1");
145
-      foreach($this->stat_usage_new as &$value) {
146
-        foreach($value as &$value2) {
145
+      foreach ($this->stat_usage_new as &$value) {
146
+        foreach ($value as &$value2) {
147 147
           $value2 = '"' . db_escape($value2) . '"';
148 148
         }
149
-        $value = '(' . implode(',', $value) .')';
149
+        $value = '(' . implode(',', $value) . ')';
150 150
       }
151 151
       doquery("REPLACE INTO {{lng_usage_stat}} (lang_code,string_id,`file`,line,is_empty,locale) VALUES " . implode(',', $this->stat_usage_new));
152 152
     }
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
     $file = str_replace('\\', '/', substr($trace[1]['file'], strlen(SN_ROOT_PHYSICAL) - 1));
160 160
 
161 161
     $string_id = $this->active . ':' . $offset . ':' . $file . ':' . $trace[1]['line'];
162
-    if(!isset($this->stat_usage[$string_id]) || $this->stat_usage[$string_id] != $empty) {
162
+    if (!isset($this->stat_usage[$string_id]) || $this->stat_usage[$string_id] != $empty) {
163 163
       $this->stat_usage[$string_id] = empty($value);
164 164
       $this->stat_usage_new[] = array(
165 165
         'lang_code' => $this->active,
@@ -199,11 +199,11 @@  discard block
 block discarded – undo
199 199
     $cache_file_key = $this->cache_prefix_lang . '__' . $filename;
200 200
 
201 201
     // Подключен ли внешний кэш?
202
-    if($this->cache) {
202
+    if ($this->cache) {
203 203
       // Загружен ли уже данный файл?
204 204
       $cache_file_status = $this->cache->__get($cache_file_key);
205 205
       classSupernova::log_file("locale.include: Cache - '{$filename}' has key '{$cache_file_key}' and is " . ($cache_file_status ? 'already loaded - EXIT' : 'EMPTY'), $cache_file_status ? -1 : 0);
206
-      if($cache_file_status) {
206
+      if ($cache_file_status) {
207 207
         // Если да - повторять загрузку нет смысла
208 208
         return null;
209 209
       }
@@ -217,35 +217,35 @@  discard block
 block discarded – undo
217 217
     $this->make_fallback($language);
218 218
 
219 219
     $file_path = '';
220
-    foreach($this->fallback as $lang_try) {
221
-      if(!$lang_try /* || isset($language_tried[$lang_try]) */) {
220
+    foreach ($this->fallback as $lang_try) {
221
+      if (!$lang_try /* || isset($language_tried[$lang_try]) */) {
222 222
         continue;
223 223
       }
224 224
 
225
-      if($file_path = $this->lng_try_filepath($path, "language/{$lang_try}/{$filename_ext}")) {
225
+      if ($file_path = $this->lng_try_filepath($path, "language/{$lang_try}/{$filename_ext}")) {
226 226
         break;
227 227
       }
228 228
 
229
-      if($file_path = $this->lng_try_filepath($path, "language/{$filename}_{$lang_try}{$ext}")) {
229
+      if ($file_path = $this->lng_try_filepath($path, "language/{$filename}_{$lang_try}{$ext}")) {
230 230
         break;
231 231
       }
232 232
 
233 233
       $file_path = '';
234 234
     }
235 235
 
236
-    if($file_path) {
236
+    if ($file_path) {
237 237
       include($file_path);
238 238
 
239
-      if(!empty($a_lang_array)) {
239
+      if (!empty($a_lang_array)) {
240 240
         $this->merge($a_lang_array);
241 241
 
242 242
         // Загрузка данных из файла в кэш
243
-        if($this->cache) {
243
+        if ($this->cache) {
244 244
           classSupernova::log_file("Locale: loading '{$filename}' into cache");
245
-          foreach($a_lang_array as $key => $value) {
245
+          foreach ($a_lang_array as $key => $value) {
246 246
             $value_cache_key = $this->cache_prefix_lang . $key;
247
-            if($this->cache->__isset($value_cache_key)) {
248
-              if(is_array($value)) {
247
+            if ($this->cache->__isset($value_cache_key)) {
248
+              if (is_array($value)) {
249 249
                 $alt_value = $this->cache->__get($value_cache_key);
250 250
                 $value = array_replace_recursive($alt_value, $value);
251 251
                 // pdump($alt_value, $alt_value);
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
         }
257 257
       }
258 258
 
259
-      if($this->cache) {
259
+      if ($this->cache) {
260 260
         $this->cache->__set($cache_file_key, true);
261 261
       }
262 262
 
@@ -269,14 +269,14 @@  discard block
 block discarded – undo
269 269
   }
270 270
 
271 271
   public function lng_load_i18n($i18n) {
272
-    if(!isset($i18n)) {
272
+    if (!isset($i18n)) {
273 273
       return;
274 274
     }
275 275
 
276
-    foreach($i18n as $i18n_data) {
277
-      if(is_string($i18n_data)) {
276
+    foreach ($i18n as $i18n_data) {
277
+      if (is_string($i18n_data)) {
278 278
         $this->lng_include($i18n_data);
279
-      } elseif(is_array($i18n_data)) {
279
+      } elseif (is_array($i18n_data)) {
280 280
         $this->lng_include($i18n_data['file'], $i18n_data['path']);
281 281
       }
282 282
     }
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
 
295 295
     classSupernova::log_file("locale.switch: Trying to switch language to '{$language_new}'");
296 296
 
297
-    if($language_new == $this->active) {
297
+    if ($language_new == $this->active) {
298 298
       classSupernova::log_file("locale.switch: New language '{$language_new}' is equal to current language '{$this->active}' - EXIT", -1);
299 299
       return false;
300 300
     }
@@ -305,10 +305,10 @@  discard block
 block discarded – undo
305 305
     $this['LANG_INFO'] = $this->lng_get_info($this->active);
306 306
     $this->make_fallback($this->active);
307 307
 
308
-    if($this->cache) {
308
+    if ($this->cache) {
309 309
       $cache_lang_init_status = $this->cache->__get($this->cache_prefix_lang . '__INIT');
310 310
       classSupernova::log_file("locale.switch: Cache for '{$this->active}' prefixed '{$this->cache_prefix_lang}' is " . ($cache_lang_init_status ? 'already loaded. Doing nothing - EXIT' : 'EMPTY'), $cache_lang_init_status ? -1 : 0);
311
-      if($cache_lang_init_status) {
311
+      if ($cache_lang_init_status) {
312 312
         return false;
313 313
       }
314 314
 
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
     // Loading global language files
325 325
     $this->lng_load_i18n($sn_mvc['i18n']['']);
326 326
 
327
-    if($this->cache) {
327
+    if ($this->cache) {
328 328
       classSupernova::log_file("locale.switch: Cache - setting flag " . $this->cache_prefix_lang . '__INIT');
329 329
       $this->cache->__set($this->cache_prefix_lang . '__INIT', true);
330 330
     }
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
   public function lng_get_info($entry) {
339 339
     $file_name = SN_ROOT_PHYSICAL . 'language/' . $entry . '/language.mo.php';
340 340
     $lang_info = array();
341
-    if(file_exists($file_name)) {
341
+    if (file_exists($file_name)) {
342 342
       include($file_name);
343 343
     }
344 344
 
@@ -346,15 +346,15 @@  discard block
 block discarded – undo
346 346
   }
347 347
 
348 348
   public function lng_get_list() {
349
-    if(empty($this->lang_list)) {
349
+    if (empty($this->lang_list)) {
350 350
       $this->lang_list = array();
351 351
 
352 352
       $path = SN_ROOT_PHYSICAL . 'language/';
353 353
       $dir = dir($path);
354
-      while(false !== ($entry = $dir->read())) {
355
-        if(is_dir($path . $entry) && $entry[0] != '.') {
354
+      while (false !== ($entry = $dir->read())) {
355
+        if (is_dir($path . $entry) && $entry[0] != '.') {
356 356
           $lang_info = $this->lng_get_info($entry);
357
-          if($lang_info['LANG_NAME_ISO2'] == $entry) {
357
+          if ($lang_info['LANG_NAME_ISO2'] == $entry) {
358 358
             $this->lang_list[$lang_info['LANG_NAME_ISO2']] = $lang_info;
359 359
           }
360 360
         }
Please login to merge, or discard this patch.