@@ -209,6 +209,10 @@ discard block |
||
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 |
||
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 | } |
@@ -136,12 +136,12 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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>"); |
@@ -18,6 +18,11 @@ discard block |
||
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 |
||
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 |
||
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 |
@@ -41,7 +41,7 @@ |
||
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}} |
@@ -55,6 +55,9 @@ |
||
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 | } |
@@ -30,17 +30,17 @@ discard block |
||
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 |
||
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); |
@@ -47,6 +47,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | { |
@@ -138,9 +138,9 @@ discard block |
||
138 | 138 | |
139 | 139 | preg_match_all('#<!-- INCLUDE (\{\$?[A-Z0-9\-_]+\}|[a-zA-Z0-9\_\-\+\./]+) -->#', $code, $matches); |
140 | 140 | $include_blocks = $matches[1]; |
141 | - if($include_blocks) |
|
141 | + if ($include_blocks) |
|
142 | 142 | { |
143 | - foreach($include_blocks as &$included_file) |
|
143 | + foreach ($include_blocks as &$included_file) |
|
144 | 144 | { |
145 | 145 | $included_file .= '.tpl.html'; |
146 | 146 | } |
@@ -446,8 +446,8 @@ discard block |
||
446 | 446 | |
447 | 447 | $tag_template_php .= 'for ($_' . $tag_args . '_i = ' . $loop_start . '; $_' . $tag_args . '_i < ' . $loop_end . '; ++$_' . $tag_args . '_i){'; |
448 | 448 | // $tag_template_php .= '$this->_block_counter["'. $tag_args . '"] = $_' . $tag_args . '_i;'; |
449 | - $tag_template_php .= '$_'. $tag_args . '_val = &' . $varref . '[$_'. $tag_args. '_i];'; |
|
450 | - $tag_template_php .= '$this->_block_value["'. $tag_args . '"] = &' . $varref . '[$_'. $tag_args. '_i];'; |
|
449 | + $tag_template_php .= '$_' . $tag_args . '_val = &' . $varref . '[$_' . $tag_args . '_i];'; |
|
450 | + $tag_template_php .= '$this->_block_value["' . $tag_args . '"] = &' . $varref . '[$_' . $tag_args . '_i];'; |
|
451 | 451 | |
452 | 452 | return $tag_template_php; |
453 | 453 | } |
@@ -551,10 +551,10 @@ discard block |
||
551 | 551 | break; |
552 | 552 | |
553 | 553 | case 'is': |
554 | - $is_arg_start = ($tokens[$i-1] == ')') ? array_pop($is_arg_stack) : $i-1; |
|
554 | + $is_arg_start = ($tokens[$i - 1] == ')') ? array_pop($is_arg_stack) : $i - 1; |
|
555 | 555 | $is_arg = implode(' ', array_slice($tokens, $is_arg_start, $i - $is_arg_start)); |
556 | 556 | |
557 | - $new_tokens = $this->_parse_is_expr($is_arg, array_slice($tokens, $i+1)); |
|
557 | + $new_tokens = $this->_parse_is_expr($is_arg, array_slice($tokens, $i + 1)); |
|
558 | 558 | |
559 | 559 | array_splice($tokens, $is_arg_start, sizeof($tokens), $new_tokens); |
560 | 560 | |
@@ -814,11 +814,11 @@ discard block |
||
814 | 814 | } |
815 | 815 | else if ($include_last_iterator) |
816 | 816 | { |
817 | - return '$_'. $blocks[$blockcount] . '_val'; |
|
817 | + return '$_' . $blocks[$blockcount] . '_val'; |
|
818 | 818 | } |
819 | 819 | else |
820 | 820 | { |
821 | - return '$_'. $blocks[$blockcount - 1] . '_val[\''. $blocks[$blockcount]. '\']'; |
|
821 | + return '$_' . $blocks[$blockcount - 1] . '_val[\'' . $blocks[$blockcount] . '\']'; |
|
822 | 822 | } |
823 | 823 | } |
824 | 824 | |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | if ($fp = @fopen($filename, 'wb')) |
836 | 836 | { |
837 | 837 | @flock($fp, LOCK_EX); |
838 | - @fwrite ($fp, $data); |
|
838 | + @fwrite($fp, $data); |
|
839 | 839 | @flock($fp, LOCK_UN); |
840 | 840 | @fclose($fp); |
841 | 841 | |
@@ -852,7 +852,7 @@ discard block |
||
852 | 852 | */ |
853 | 853 | private function minify($html) |
854 | 854 | { |
855 | - if(!classSupernova::$config->tpl_minifier) |
|
855 | + if (!classSupernova::$config->tpl_minifier) |
|
856 | 856 | { |
857 | 857 | return $html; |
858 | 858 | } |
@@ -862,14 +862,14 @@ discard block |
||
862 | 862 | $html = preg_replace('/(<script[^>]*?>.*?<\/script>)/si', '#pre#', $html); |
863 | 863 | $html = preg_replace('/>[\s]*</', '><', $html); // Strip spacechars between tags |
864 | 864 | $html = preg_replace('/[\s]+/', ' ', $html); // Replace several spacechars with one space |
865 | - if(!empty($pre[0])) |
|
865 | + if (!empty($pre[0])) |
|
866 | 866 | { |
867 | - foreach($pre[0] as $tag) |
|
867 | + foreach ($pre[0] as $tag) |
|
868 | 868 | { |
869 | 869 | $tag = preg_replace('/^\ *\/\/[^\<]*?$/m', ' ', $tag); // Strips comments - except those that contains HTML comment inside |
870 | 870 | $tag = preg_replace('/[\ \t]{2,}/', ' ', $tag); // Replace several spaces by one |
871 | 871 | $tag = preg_replace('/\s{2,}/', "\r\n", $tag); // Replace several linefeeds by one |
872 | - $html = preg_replace('/#pre#/', $tag, $html,1); |
|
872 | + $html = preg_replace('/#pre#/', $tag, $html, 1); |
|
873 | 873 | } |
874 | 874 | } |
875 | 875 |
@@ -173,6 +173,9 @@ |
||
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; |
@@ -28,13 +28,13 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -702,7 +702,7 @@ discard block |
||
702 | 702 | * Рассчёт бонуса ММ |
703 | 703 | * |
704 | 704 | * @param $dark_matter |
705 | - * @param bool|true $direct |
|
705 | + * @param boolean $direct |
|
706 | 706 | * @param bool|false $return_bonus |
707 | 707 | * |
708 | 708 | * @return float|int |
@@ -738,6 +738,12 @@ discard block |
||
738 | 738 | |
739 | 739 | // Дополнительная ре-трансляция адреса, если в каком-то случае платежная система ожидает нелогичный ответ |
740 | 740 | // Пример: иксолла при неправильно заданном пользователе в ордере ожидает НЕПРАВИЛЬНЫЙ_ОРДЕР, а не НЕПРАВИЛЬНЫЙ_ПОЛЬЗОВАТЕЛЬ |
741 | + |
|
742 | + /** |
|
743 | + * @param integer $error_code |
|
744 | + * |
|
745 | + * @return integer|null |
|
746 | + */ |
|
741 | 747 | function retranslate_error($error_code, $options = array()) { |
742 | 748 | return isset($options['retranslate_error'][$error_code]) ? $options['retranslate_error'][$error_code] : $error_code; |
743 | 749 | } |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | public function compile_request($request) { |
451 | 451 | global $config, $user; |
452 | 452 | |
453 | - if(!(classSupernova::$auth->account instanceof Account)) { |
|
453 | + if (!(classSupernova::$auth->account instanceof Account)) { |
|
454 | 454 | // TODO - throw new Exception($lang['pay_msg_mm_request_amount_invalid'], SN_PAYMENT_REQUEST_ERROR_UNIT_AMOUNT); |
455 | 455 | } |
456 | 456 | $this->account = classSupernova::$auth->account; |
@@ -471,15 +471,15 @@ discard block |
||
471 | 471 | $this->payment_currency = $config->payment_currency_default; |
472 | 472 | $this->payment_amount = self::currency_convert($this->payment_dark_matter_paid, 'MM_', $this->payment_currency); |
473 | 473 | |
474 | - if(empty($this->payment_external_currency) && !empty($this->config['currency'])) { |
|
474 | + if (empty($this->payment_external_currency) && !empty($this->config['currency'])) { |
|
475 | 475 | $this->payment_external_currency = $this->config['currency']; |
476 | 476 | } |
477 | - if(empty($this->payment_external_currency)) { |
|
477 | + if (empty($this->payment_external_currency)) { |
|
478 | 478 | throw new Exception(classLocale::$lang['pay_error_internal_no_external_currency_set'], SN_PAYMENT_ERROR_INTERNAL_NO_EXTERNAL_CURRENCY_SET); |
479 | 479 | } |
480 | 480 | |
481 | 481 | $this->payment_external_amount = self::currency_convert($this->payment_dark_matter_paid, 'MM_', $this->payment_external_currency); |
482 | - if($this->payment_external_amount < 0.01) { |
|
482 | + if ($this->payment_external_amount < 0.01) { |
|
483 | 483 | throw new Exception(classLocale::$lang['pay_msg_mm_request_amount_invalid'], SN_PAYMENT_REQUEST_ERROR_UNIT_AMOUNT); |
484 | 484 | } |
485 | 485 | |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | $this->generate_description(); |
489 | 489 | |
490 | 490 | $this->db_insert(); |
491 | - if(!$this->is_exists) { |
|
491 | + if (!$this->is_exists) { |
|
492 | 492 | throw new Exception(classLocale::$lang['pay_msg_request_error_db_payment_create'], SN_PAYMENT_REQUEST_DB_ERROR_PAYMENT_CREATE); |
493 | 493 | } |
494 | 494 | } |
@@ -503,24 +503,24 @@ discard block |
||
503 | 503 | protected function payment_request_process($options = array()) { |
504 | 504 | global $lang, $config; |
505 | 505 | |
506 | - if(!$this->manifest['active']) { |
|
506 | + if (!$this->manifest['active']) { |
|
507 | 507 | throw new Exception(classLocale::$lang['pay_msg_module_disabled'], SN_MODULE_DISABLED); |
508 | 508 | } |
509 | 509 | |
510 | 510 | // Если есть payment_id - загружаем под него данные |
511 | - if(!empty($this->payment_params['payment_id'])) { |
|
511 | + if (!empty($this->payment_params['payment_id'])) { |
|
512 | 512 | $this->request_payment_id = sys_get_param_id($this->payment_params['payment_id']); |
513 | - if(!$this->request_payment_id) { |
|
513 | + if (!$this->request_payment_id) { |
|
514 | 514 | throw new Exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_INTERNAL_ID_WRONG); |
515 | 515 | } |
516 | 516 | |
517 | - if(!$this->db_get_by_id($this->request_payment_id)) { |
|
517 | + if (!$this->db_get_by_id($this->request_payment_id)) { |
|
518 | 518 | throw new Exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_INTERNAL_ID_WRONG); |
519 | 519 | } |
520 | 520 | |
521 | 521 | // Проверяем - был ли этот платеж обработан? |
522 | 522 | // TODO - Статусы бывают разные. Нужен спецфлаг payment_processed |
523 | - if($this->payment_status != PAYMENT_STATUS_NONE) { |
|
523 | + if ($this->payment_status != PAYMENT_STATUS_NONE) { |
|
524 | 524 | sn_db_transaction_rollback(); |
525 | 525 | sys_redirect(SN_ROOT_VIRTUAL . 'metamatter.php?payment_id=' . $this->payment_id); |
526 | 526 | die(); |
@@ -530,89 +530,89 @@ discard block |
||
530 | 530 | // Пытаемся получить из запроса ИД аккаунта |
531 | 531 | $request_account_id = !empty($this->payment_params['account_id']) ? sys_get_param_id($this->payment_params['account_id']) : 0; |
532 | 532 | // Если в запросе нет ИД аккаунта - пытаемся использовать payment_account_id |
533 | - if(empty($request_account_id) && !empty($this->payment_account_id)) { |
|
533 | + if (empty($request_account_id) && !empty($this->payment_account_id)) { |
|
534 | 534 | $request_account_id = $this->payment_account_id; |
535 | 535 | } |
536 | 536 | // Если теперь у нас нету ИД аккаунта ни в запросе, ни в записи таблицы - можно паниковать |
537 | - if(empty($request_account_id)) { |
|
537 | + if (empty($request_account_id)) { |
|
538 | 538 | // TODO - аккаунт |
539 | 539 | throw new Exception(classLocale::$lang['pay_msg_request_user_invalid'], $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options)); |
540 | 540 | } |
541 | 541 | // Если нет записи в таблице - тогда берем payment_account_id из запроса |
542 | - if(empty($this->payment_account_id)) { |
|
542 | + if (empty($this->payment_account_id)) { |
|
543 | 543 | $this->payment_account_id = $request_account_id; |
544 | 544 | } |
545 | 545 | // Если у нас отличаются ИД аккаунта в запросе и ИД аккаунта в записи - тоже можно паниковать |
546 | - if($this->payment_account_id != $request_account_id) { |
|
546 | + if ($this->payment_account_id != $request_account_id) { |
|
547 | 547 | // TODO - Поменять сообщение об ошибке |
548 | 548 | throw new Exception(classLocale::$lang['pay_msg_request_user_invalid'], $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options)); |
549 | 549 | } |
550 | 550 | // Проверяем существование аккаунта с данным ИД |
551 | - if(!$this->account->db_get_by_id($this->payment_account_id)) { |
|
551 | + if (!$this->account->db_get_by_id($this->payment_account_id)) { |
|
552 | 552 | throw new Exception(classLocale::$lang['pay_msg_request_user_invalid'] . ' ID ' . $this->payment_account_id, $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options)); |
553 | 553 | } |
554 | 554 | |
555 | 555 | // TODO Проверка на сервер_ид - как бы и не нужна, наверное? |
556 | - if(!empty($this->payment_params['server_id'])) { |
|
556 | + if (!empty($this->payment_params['server_id'])) { |
|
557 | 557 | $this->request_server_id = sys_get_param_str($this->payment_params['server_id']); |
558 | - if(SN_ROOT_VIRTUAL != $this->request_server_id) { |
|
558 | + if (SN_ROOT_VIRTUAL != $this->request_server_id) { |
|
559 | 559 | throw new Exception(classLocale::$lang['pay_msg_request_server_wrong'] . " {$this->request_server_id} вместо " . SN_ROOT_VIRTUAL, SN_PAYMENT_REQUEST_SERVER_WRONG); |
560 | 560 | } |
561 | 561 | } |
562 | 562 | |
563 | 563 | // Сверка количества оплаченной ММ с учётом бонусов |
564 | - if(!empty($this->payment_params['payment_dark_matter_gained'])) { |
|
564 | + if (!empty($this->payment_params['payment_dark_matter_gained'])) { |
|
565 | 565 | $request_mm_amount = sys_get_param_id($this->payment_params['payment_dark_matter_gained']); |
566 | - if($request_mm_amount != $this->payment_dark_matter_gained && $this->is_loaded) { |
|
566 | + if ($request_mm_amount != $this->payment_dark_matter_gained && $this->is_loaded) { |
|
567 | 567 | throw new Exception(classLocale::$lang['pay_msg_mm_request_amount_invalid'] . " пришло {$request_mm_amount} ММ вместо {$this->payment_dark_matter_gained} ММ", SN_PAYMENT_REQUEST_MM_AMOUNT_INVALID); |
568 | 568 | } |
569 | 569 | empty($this->payment_dark_matter_gained) ? $this->payment_dark_matter_gained = $request_mm_amount : false; |
570 | 570 | } |
571 | - if(empty($this->payment_dark_matter_paid)) { |
|
571 | + if (empty($this->payment_dark_matter_paid)) { |
|
572 | 572 | // TODO - обратный расчёт из gained |
573 | 573 | } |
574 | 574 | |
575 | 575 | // Проверка наличия внешнего ИД платежа |
576 | - if(!empty($this->payment_params['payment_external_id'])) { |
|
576 | + if (!empty($this->payment_params['payment_external_id'])) { |
|
577 | 577 | $request_payment_external_id = sys_get_param_id($this->payment_params['payment_external_id']); |
578 | - if(empty($request_payment_external_id)) { |
|
578 | + if (empty($request_payment_external_id)) { |
|
579 | 579 | throw new exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_EXTERNAL_ID_WRONG); |
580 | - } elseif(!empty($this->payment_external_id) && $this->payment_external_id != $request_payment_external_id) { |
|
580 | + } elseif (!empty($this->payment_external_id) && $this->payment_external_id != $request_payment_external_id) { |
|
581 | 581 | // TODO - Может быть поменять сообщение |
582 | 582 | throw new exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_EXTERNAL_ID_WRONG); |
583 | 583 | } |
584 | 584 | $this->payment_external_id = $request_payment_external_id; |
585 | 585 | } |
586 | 586 | // Сверка суммы, запрошенной СН к оплате |
587 | - if(!empty($this->payment_params['payment_external_money'])) { |
|
587 | + if (!empty($this->payment_params['payment_external_money'])) { |
|
588 | 588 | $request_money_out = sys_get_param_float($this->payment_params['payment_external_money']); |
589 | - if($request_money_out != $this->payment_external_amount && $this->is_loaded) { |
|
589 | + if ($request_money_out != $this->payment_external_amount && $this->is_loaded) { |
|
590 | 590 | throw new Exception(classLocale::$lang['pay_msg_request_payment_amount_invalid'] . " пришло {$request_money_out} денег вместо {$this->payment_external_amount} денег", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID); |
591 | 591 | } |
592 | 592 | empty($this->payment_external_amount) ? $this->payment_external_amount = $request_money_out : false; |
593 | 593 | } |
594 | 594 | // Заполняем поле валюты платёжной системы |
595 | - if(!empty($this->payment_params['payment_external_currency'])) { |
|
595 | + if (!empty($this->payment_params['payment_external_currency'])) { |
|
596 | 596 | $this->payment_external_currency = sys_get_param_str($this->payment_params['payment_external_currency']); |
597 | - if(empty($this->payment_external_currency)) { |
|
597 | + if (empty($this->payment_external_currency)) { |
|
598 | 598 | // TODO - поменять сообщение |
599 | 599 | throw new Exception(classLocale::$lang['pay_msg_request_payment_amount_invalid'] . " {$this->payment_external_currency}", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID); |
600 | 600 | } |
601 | 601 | } |
602 | - if(empty($this->payment_external_currency)) { |
|
602 | + if (empty($this->payment_external_currency)) { |
|
603 | 603 | $this->payment_external_currency = $this->config['currency']; |
604 | 604 | } |
605 | 605 | |
606 | 606 | // Заполнение внутренней суммы и валюты из внешних данных |
607 | - if(empty($this->payment_currency)) { |
|
607 | + if (empty($this->payment_currency)) { |
|
608 | 608 | $this->payment_currency = $config->payment_currency_default; |
609 | 609 | } |
610 | - if(empty($this->payment_amount) && !empty($this->payment_external_currency)) { |
|
610 | + if (empty($this->payment_amount) && !empty($this->payment_external_currency)) { |
|
611 | 611 | $this->payment_amount = self::currency_convert($this->payment_external_amount, $this->payment_external_currency, $this->payment_currency); |
612 | 612 | } |
613 | 613 | |
614 | 614 | // TODO - Тестовый режим |
615 | - if(!empty($this->payment_params['test'])) { |
|
615 | + if (!empty($this->payment_params['test'])) { |
|
616 | 616 | $this->payment_test = $this->config['test'] || sys_get_param_int($this->payment_params['test']); |
617 | 617 | } |
618 | 618 | |
@@ -641,12 +641,12 @@ discard block |
||
641 | 641 | sn_db_transaction_start(); |
642 | 642 | try { |
643 | 643 | $response = $this->payment_request_process(); |
644 | - } catch(Exception $e) { |
|
644 | + } catch (Exception $e) { |
|
645 | 645 | $response['result'] = $e->getCode(); |
646 | 646 | $response['message'] = $e->getMessage(); |
647 | 647 | } |
648 | 648 | |
649 | - if($response['result'] == SN_PAYMENT_REQUEST_OK) { |
|
649 | + if ($response['result'] == SN_PAYMENT_REQUEST_OK) { |
|
650 | 650 | sn_db_transaction_commit(); |
651 | 651 | $debug->warning('Результат операции: код ' . $response['result'] . ' сообщение "' . $response['message'] . '"', 'Успешный платёж', LOG_INFO_PAYMENT); |
652 | 652 | } else { |
@@ -655,7 +655,7 @@ discard block |
||
655 | 655 | } |
656 | 656 | |
657 | 657 | // Переводим код результата из СН в код платежной системы |
658 | - if(is_array($this->result_translations) && !empty($this->result_translations)) { |
|
658 | + if (is_array($this->result_translations) && !empty($this->result_translations)) { |
|
659 | 659 | $response['result'] = isset($this->result_translations[$response['result']]) ? $this->result_translations[$response['result']] : $this->result_translations[SN_PAYMENT_REQUEST_UNDEFINED_ERROR]; |
660 | 660 | } |
661 | 661 | |
@@ -680,7 +680,7 @@ discard block |
||
680 | 680 | $currency_from = strtolower($currency_from); |
681 | 681 | $currency_to = strtolower($currency_to); |
682 | 682 | |
683 | - if($currency_from != $currency_to) { |
|
683 | + if ($currency_from != $currency_to) { |
|
684 | 684 | // $config_currency_from_name = 'payment_currency_exchange_' . $currency_from; |
685 | 685 | // $config_currency_to_name = 'payment_currency_exchange_' . $currency_to; |
686 | 686 | |
@@ -710,10 +710,10 @@ discard block |
||
710 | 710 | public static function bonus_calculate($dark_matter, $direct = true, $return_bonus = false) { |
711 | 711 | $bonus = 0; |
712 | 712 | $dark_matter_new = $dark_matter; |
713 | - if(!empty(self::$bonus_table) && $dark_matter >= self::$bonus_table[0]) { |
|
714 | - if($direct) { |
|
715 | - foreach(self::$bonus_table as $dm_for_bonus => $multiplier) { |
|
716 | - if($dm_for_bonus <= $dark_matter) { |
|
713 | + if (!empty(self::$bonus_table) && $dark_matter >= self::$bonus_table[0]) { |
|
714 | + if ($direct) { |
|
715 | + foreach (self::$bonus_table as $dm_for_bonus => $multiplier) { |
|
716 | + if ($dm_for_bonus <= $dark_matter) { |
|
717 | 717 | $dark_matter_new = $dark_matter * (1 + $multiplier); |
718 | 718 | $bonus = $multiplier; |
719 | 719 | } else { |
@@ -721,9 +721,9 @@ discard block |
||
721 | 721 | } |
722 | 722 | } |
723 | 723 | } else { |
724 | - foreach(self::$bonus_table as $dm_for_bonus => $multiplier) { |
|
724 | + foreach (self::$bonus_table as $dm_for_bonus => $multiplier) { |
|
725 | 725 | $temp = $dm_for_bonus * (1 + $multiplier); |
726 | - if($dark_matter >= $temp) { |
|
726 | + if ($dark_matter >= $temp) { |
|
727 | 727 | $dark_matter_new = round($dark_matter / (1 + $multiplier)); |
728 | 728 | $bonus = $multiplier; |
729 | 729 | } else { |
@@ -779,13 +779,13 @@ discard block |
||
779 | 779 | ); |
780 | 780 | |
781 | 781 | $replace = false; |
782 | - if($this->payment_id) { |
|
782 | + if ($this->payment_id) { |
|
783 | 783 | $payment['payment_id'] = $this->payment_id; |
784 | 784 | $replace = true; |
785 | 785 | } |
786 | 786 | |
787 | 787 | $query = array(); |
788 | - foreach($payment as $key => $value) { |
|
788 | + foreach ($payment as $key => $value) { |
|
789 | 789 | $value = is_string($value) ? '"' . db_escape($value) . '"' : $value; |
790 | 790 | $query[] = "`{$key}` = {$value}"; |
791 | 791 | } |
@@ -797,12 +797,12 @@ discard block |
||
797 | 797 | |
798 | 798 | |
799 | 799 | function payment_adjust_mm_new() { |
800 | - if(!$this->payment_test) { |
|
800 | + if (!$this->payment_test) { |
|
801 | 801 | // Not a test payment. Adding DM to account |
802 | 802 | $this->account = new Account($this->db); |
803 | 803 | $this->account->db_get_by_id($this->payment_account_id); |
804 | 804 | $result = $this->account->metamatter_change(RPG_PURCHASE, $this->payment_dark_matter_gained, $this->payment_comment); |
805 | - if(!$result) { |
|
805 | + if (!$result) { |
|
806 | 806 | throw new Exception('Ошибка начисления ММ', SN_METAMATTER_ERROR_ADJUST); |
807 | 807 | } |
808 | 808 | } |
@@ -812,25 +812,25 @@ discard block |
||
812 | 812 | die('{НЕ РАБОТАЕТ! СООБЩИТЕ АДМИНИСТРАЦИИ!}'); |
813 | 813 | global $lang; |
814 | 814 | |
815 | - if(!isset($payment['payment_status'])) { |
|
815 | + if (!isset($payment['payment_status'])) { |
|
816 | 816 | throw new exception(classLocale::$lang['pay_msg_request_payment_not_found'], SN_PAYMENT_REQUEST_ORDER_NOT_FOUND); |
817 | 817 | } |
818 | 818 | |
819 | - if($payment['payment_status'] == PAYMENT_STATUS_COMPLETE) { |
|
820 | - $safe_comment = db_escape($payment['payment_comment'] = classLocale::$lang['pay_msg_request_payment_cancelled'] .' ' . $payment['payment_comment']); |
|
819 | + if ($payment['payment_status'] == PAYMENT_STATUS_COMPLETE) { |
|
820 | + $safe_comment = db_escape($payment['payment_comment'] = classLocale::$lang['pay_msg_request_payment_cancelled'] . ' ' . $payment['payment_comment']); |
|
821 | 821 | |
822 | - if(!$payment['payment_test']) { |
|
822 | + if (!$payment['payment_test']) { |
|
823 | 823 | $result = $this->account->metamatter_change(RPG_PURCHASE_CANCEL, -$payment['payment_dark_matter_gained'], $payment['payment_comment']); |
824 | - if(!$result) { |
|
824 | + if (!$result) { |
|
825 | 825 | throw new exception('Ошибка начисления ММ', SN_METAMATTER_ERROR_ADJUST); |
826 | 826 | } |
827 | 827 | } |
828 | 828 | $payment['payment_status'] = PAYMENT_STATUS_CANCELED; |
829 | 829 | db_payment_update($payment, $safe_comment); |
830 | 830 | throw new exception(classLocale::$lang['pay_msg_request_payment_cancel_complete'], SN_PAYMENT_REQUEST_OK); |
831 | - } elseif($payment['payment_status'] == PAYMENT_STATUS_CANCELED) { |
|
831 | + } elseif ($payment['payment_status'] == PAYMENT_STATUS_CANCELED) { |
|
832 | 832 | throw new exception(classLocale::$lang['pay_msg_request_payment_cancelled_already'], SN_PAYMENT_REQUEST_OK); |
833 | - } elseif($payment['payment_status'] == PAYMENT_STATUS_NONE) { |
|
833 | + } elseif ($payment['payment_status'] == PAYMENT_STATUS_NONE) { |
|
834 | 834 | throw new exception(classLocale::$lang['pay_msg_request_payment_cancel_not_complete'], SN_PAYMENT_REQUEST_PAYMENT_NOT_COMPLETE); |
835 | 835 | } |
836 | 836 | } |
@@ -844,8 +844,8 @@ discard block |
||
844 | 844 | |
845 | 845 | protected function db_complete_payment() { |
846 | 846 | // TODO - поле payment_processed |
847 | - if($this->payment_status == PAYMENT_STATUS_NONE) { |
|
848 | - if(!defined('PAYMENT_EXPIRE_TIME') || PAYMENT_EXPIRE_TIME == 0 || empty($this->payment_date) || strtotime($this->payment_date) + PAYMENT_EXPIRE_TIME <= SN_TIME_NOW) { |
|
847 | + if ($this->payment_status == PAYMENT_STATUS_NONE) { |
|
848 | + if (!defined('PAYMENT_EXPIRE_TIME') || PAYMENT_EXPIRE_TIME == 0 || empty($this->payment_date) || strtotime($this->payment_date) + PAYMENT_EXPIRE_TIME <= SN_TIME_NOW) { |
|
849 | 849 | $this->payment_adjust_mm_new(); |
850 | 850 | $this->payment_status = PAYMENT_STATUS_COMPLETE; |
851 | 851 | } else { |
@@ -892,7 +892,7 @@ discard block |
||
892 | 892 | protected function db_assign_payment($payment = null) { |
893 | 893 | $this->payment_reset(); |
894 | 894 | |
895 | - if(is_array($payment) && isset($payment['payment_id'])) { |
|
895 | + if (is_array($payment) && isset($payment['payment_id'])) { |
|
896 | 896 | $this->payment_id = $payment['payment_id']; |
897 | 897 | $this->payment_status = $payment['payment_status']; |
898 | 898 | $this->payment_date = $payment['payment_date']; |
@@ -103,6 +103,7 @@ |
||
103 | 103 | /** |
104 | 104 | * Set custom template location (able to use directory outside of phpBB) |
105 | 105 | * @access public |
106 | + * @param string $template_path |
|
106 | 107 | */ |
107 | 108 | function set_custom_template($template_path, $template_name, $fallback_template_path = false) |
108 | 109 | { |
@@ -628,7 +628,7 @@ discard block |
||
628 | 628 | // Re-position template blocks |
629 | 629 | for ($i = sizeof($this->_tpldata[$blockname]); $i > $key; $i--) |
630 | 630 | { |
631 | - $this->_tpldata[$blockname][$i] = $this->_tpldata[$blockname][$i-1]; |
|
631 | + $this->_tpldata[$blockname][$i] = $this->_tpldata[$blockname][$i - 1]; |
|
632 | 632 | $this->_tpldata[$blockname][$i]['S_ROW_COUNT'] = $i; |
633 | 633 | } |
634 | 634 | |
@@ -710,13 +710,13 @@ discard block |
||
710 | 710 | */ |
711 | 711 | function assign_recursive($values, $name = '') |
712 | 712 | { |
713 | - if(isset($values['.'])) |
|
713 | + if (isset($values['.'])) |
|
714 | 714 | { |
715 | 715 | $values_extra = $values['.']; |
716 | 716 | unset($values['.']); |
717 | 717 | } |
718 | 718 | |
719 | - if(!$name) |
|
719 | + if (!$name) |
|
720 | 720 | { |
721 | 721 | $this->assign_vars($values); |
722 | 722 | } |
@@ -725,12 +725,12 @@ discard block |
||
725 | 725 | $this->assign_block_vars($name, $values); |
726 | 726 | } |
727 | 727 | |
728 | - if(isset($values_extra)) |
|
728 | + if (isset($values_extra)) |
|
729 | 729 | { |
730 | - foreach($values_extra as $sub_array_name => $sub_array) |
|
730 | + foreach ($values_extra as $sub_array_name => $sub_array) |
|
731 | 731 | { |
732 | 732 | $new_name = $name . ($name ? '.' : '') . $sub_array_name; |
733 | - foreach($sub_array as $sub_element) |
|
733 | + foreach ($sub_array as $sub_element) |
|
734 | 734 | { |
735 | 735 | $this->assign_recursive($sub_element, $new_name); |
736 | 736 | } |
@@ -151,6 +151,9 @@ |
||
151 | 151 | } |
152 | 152 | |
153 | 153 | |
154 | + /** |
|
155 | + * @param integer $user_id |
|
156 | + */ |
|
154 | 157 | public function __construct($user_id) { |
155 | 158 | $this->user_change($user_id); |
156 | 159 | } |
@@ -116,8 +116,8 @@ discard block |
||
116 | 116 | |
117 | 117 | $update_cache = false; |
118 | 118 | |
119 | - if(!empty($this->to_write)) { |
|
120 | - foreach($this->to_write as $key => $cork) { |
|
119 | + if (!empty($this->to_write)) { |
|
120 | + foreach ($this->to_write as $key => $cork) { |
|
121 | 121 | $value = is_array($this->data[$key]) ? serialize($this->data[$key]) : $this->data[$key]; // Сериализация для массивов при сохранении в БД |
122 | 122 | $this->to_write[$key] = "({$this->user_id}, '" . db_escape($key) . "', '" . db_escape($value) . "')"; |
123 | 123 | } |
@@ -128,19 +128,19 @@ discard block |
||
128 | 128 | $update_cache = true; |
129 | 129 | } |
130 | 130 | |
131 | - if(!empty($this->to_delete)) { |
|
132 | - foreach($this->to_delete as $key => &$value) { |
|
133 | - $value = is_string($key) ? "'". db_escape($key) . "'" : $key; |
|
131 | + if (!empty($this->to_delete)) { |
|
132 | + foreach ($this->to_delete as $key => &$value) { |
|
133 | + $value = is_string($key) ? "'" . db_escape($key) . "'" : $key; |
|
134 | 134 | } |
135 | 135 | |
136 | - doquery("DELETE FROM {{player_options}} WHERE `player_id` = {$this->user_id} AND `option_id` IN (". implode(',', $this->to_delete) . ") "); |
|
136 | + doquery("DELETE FROM {{player_options}} WHERE `player_id` = {$this->user_id} AND `option_id` IN (" . implode(',', $this->to_delete) . ") "); |
|
137 | 137 | // pdump("DELETE FROM {{player_options}} WHERE `player_id` = {$this->user_id} AND `option_id` IN (". implode(',', $this->to_delete) . ") "); |
138 | 138 | |
139 | 139 | $this->to_delete = array(); |
140 | 140 | $update_cache = true; |
141 | 141 | } |
142 | 142 | |
143 | - if($update_cache) { |
|
143 | + if ($update_cache) { |
|
144 | 144 | global $sn_cache; |
145 | 145 | |
146 | 146 | $field_name = $this->cached_name(); |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | protected function load() { |
168 | 168 | global $sn_cache; |
169 | 169 | |
170 | - if($this->loaded) { |
|
170 | + if ($this->loaded) { |
|
171 | 171 | return; |
172 | 172 | } |
173 | 173 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | $this->to_write = array(); |
176 | 176 | $this->to_delete = array(); |
177 | 177 | |
178 | - if(!$this->user_id) { |
|
178 | + if (!$this->user_id) { |
|
179 | 179 | $this->loaded = true; |
180 | 180 | return; |
181 | 181 | } |
@@ -183,13 +183,13 @@ discard block |
||
183 | 183 | $field_name = $this->cached_name(); |
184 | 184 | $a_data = $sn_cache->$field_name; |
185 | 185 | |
186 | - if(!empty($a_data)) { |
|
186 | + if (!empty($a_data)) { |
|
187 | 187 | $this->data = array_replace_recursive($this->data, $a_data); |
188 | 188 | return; |
189 | 189 | } |
190 | 190 | |
191 | 191 | $query = doquery("SELECT * FROM `{{player_options}}` WHERE `player_id` = {$this->user_id} FOR UPDATE"); |
192 | - while($row = db_fetch($query)) { |
|
192 | + while ($row = db_fetch($query)) { |
|
193 | 193 | // $this->data[$row['option_id']] = $row['value']; |
194 | 194 | $this->data[$row['option_id']] = is_string($row['value']) && ($temp = unserialize($row['value'])) !== false ? $temp : $row['value']; // Десериализация |
195 | 195 | } |
@@ -269,14 +269,14 @@ discard block |
||
269 | 269 | // Если в массиве индекса только один элемент - значит это просто индекс |
270 | 270 | is_array($option_id) && count($option_id) == 1 ? $option_id = reset($option_id) : false; |
271 | 271 | |
272 | - if(!isset($this->data[is_array($option_id) ? reset($option_id) : $option_id])) { |
|
272 | + if (!isset($this->data[is_array($option_id) ? reset($option_id) : $option_id])) { |
|
273 | 273 | $this->load(); |
274 | 274 | } |
275 | 275 | |
276 | - if(is_array($option_id)) { |
|
276 | + if (is_array($option_id)) { |
|
277 | 277 | $result = $this->data; |
278 | - foreach($option_id as $sub_key) { |
|
279 | - if(!isset($result) || !isset($result[$sub_key])) { |
|
278 | + foreach ($option_id as $sub_key) { |
|
279 | + if (!isset($result) || !isset($result[$sub_key])) { |
|
280 | 280 | $result = null; |
281 | 281 | break; |
282 | 282 | } |
@@ -296,12 +296,12 @@ discard block |
||
296 | 296 | public function __set($option, $value = null) { |
297 | 297 | global $sn_cache; |
298 | 298 | |
299 | - if(empty($option) || !$this->user_id) { |
|
299 | + if (empty($option) || !$this->user_id) { |
|
300 | 300 | return; |
301 | 301 | } |
302 | 302 | |
303 | 303 | // Если в массиве индекса только один элемент - значит это просто индекс |
304 | - if(is_array($option) && count($option) == 1) { |
|
304 | + if (is_array($option) && count($option) == 1) { |
|
305 | 305 | // Разворачиваем его в индекс |
306 | 306 | $option = array(reset($option) => $value); |
307 | 307 | unset($value); |
@@ -310,13 +310,13 @@ discard block |
||
310 | 310 | |
311 | 311 | $to_write = array(); |
312 | 312 | // Адресация многомерного массива через массив индексов в $option |
313 | - if(is_array($option) && isset($value)) { |
|
313 | + if (is_array($option) && isset($value)) { |
|
314 | 314 | $a_data = &$this->data; |
315 | - foreach($option as $option_id) { |
|
315 | + foreach ($option as $option_id) { |
|
316 | 316 | !is_array($a_data[$option_id]) ? $a_data[$option_id] = array() : false; |
317 | 317 | $a_data = &$a_data[$option_id]; |
318 | 318 | } |
319 | - if($a_data != $value) { |
|
319 | + if ($a_data != $value) { |
|
320 | 320 | $a_data = $value; |
321 | 321 | $to_write[reset($option)] = null; |
322 | 322 | } |
@@ -324,10 +324,10 @@ discard block |
||
324 | 324 | // Пакетная запись из массива ключ -> значение |
325 | 325 | !is_array($option) ? $option = array($option => $value) : false; |
326 | 326 | |
327 | - foreach($option as $option_id => $option_value) { |
|
328 | - if($this->data[$option_id] !== $option_value) { |
|
327 | + foreach ($option as $option_id => $option_value) { |
|
328 | + if ($this->data[$option_id] !== $option_value) { |
|
329 | 329 | // TODO - вынести отдельно в обработчик |
330 | - if($option_id == PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON && $option_value == PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON_HIDDEN) { |
|
330 | + if ($option_id == PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON && $option_value == PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON_HIDDEN) { |
|
331 | 331 | sn_setcookie(SN_COOKIE . '_menu_hidden', '0', time() - PERIOD_WEEK, SN_ROOT_RELATIVE); |
332 | 332 | } |
333 | 333 | |
@@ -337,11 +337,11 @@ discard block |
||
337 | 337 | } |
338 | 338 | } |
339 | 339 | |
340 | - if(!empty($to_write)) { |
|
340 | + if (!empty($to_write)) { |
|
341 | 341 | $field_name = $this->cached_name(); |
342 | 342 | $sn_cache->$field_name = $this->data; |
343 | 343 | |
344 | - foreach($to_write as $option_id => &$option_value) { |
|
344 | + foreach ($to_write as $option_id => &$option_value) { |
|
345 | 345 | $option_value = is_array($this->data[$option_id]) ? serialize($this->data[$option_id]) : $this->data[$option_id]; // Сериализация для массивов при сохранении в БД |
346 | 346 | $to_write[$option_id] = "({$this->user_id}, '" . db_escape($option_id) . "', '" . db_escape($option_value) . "')"; |
347 | 347 | } |
@@ -353,26 +353,26 @@ discard block |
||
353 | 353 | protected function load() { |
354 | 354 | global $sn_cache; |
355 | 355 | |
356 | - if($this->loaded) { |
|
356 | + if ($this->loaded) { |
|
357 | 357 | return; |
358 | 358 | } |
359 | 359 | |
360 | 360 | $this->data = $this->defaults; |
361 | 361 | |
362 | - if(!$this->user_id) { |
|
362 | + if (!$this->user_id) { |
|
363 | 363 | return; |
364 | 364 | } |
365 | 365 | |
366 | 366 | $field_name = $this->cached_name(); |
367 | 367 | $a_data = $sn_cache->$field_name; |
368 | 368 | |
369 | - if(!empty($a_data)) { |
|
369 | + if (!empty($a_data)) { |
|
370 | 370 | $this->data = array_replace($this->data, $a_data); |
371 | 371 | return; |
372 | 372 | } |
373 | 373 | |
374 | 374 | $query = doquery("SELECT * FROM `{{player_options}}` WHERE `player_id` = {$this->user_id} FOR UPDATE"); |
375 | - while($row = db_fetch($query)) { |
|
375 | + while ($row = db_fetch($query)) { |
|
376 | 376 | // $this->data[$row['option_id']] = $row['value']; |
377 | 377 | $this->data[$row['option_id']] = is_string($row['value']) && ($temp = unserialize($row['value'])) !== false ? $temp : $row['value']; // Десериализация |
378 | 378 | } |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | return $this->__get($offset); |
389 | 389 | } |
390 | 390 | public function offsetSet($offset, $value) { |
391 | - if(!is_null($offset)) { |
|
391 | + if (!is_null($offset)) { |
|
392 | 392 | // $this->data[$offset] = $value; |
393 | 393 | $this->__set($offset, $value); |
394 | 394 | } else { |
@@ -11,6 +11,9 @@ discard block |
||
11 | 11 | |
12 | 12 | require_once('db/db_queries.php'); |
13 | 13 | |
14 | +/** |
|
15 | + * @param string $tablename |
|
16 | + */ |
|
14 | 17 | function db_change_units_perform($query, $tablename, $object_id) { |
15 | 18 | $query = implode(',', $query); |
16 | 19 | if($query && $object_id) { |
@@ -63,6 +66,9 @@ discard block |
||
63 | 66 | db_change_units_perform($query[LOC_USER], 'users', $user['id']); |
64 | 67 | db_change_units_perform($query[LOC_PLANET], 'planets', $planet['id']); |
65 | 68 | } |
69 | +/** |
|
70 | + * @param string $table |
|
71 | + */ |
|
66 | 72 | function sn_db_perform($table, $values, $type = 'insert', $options = false) { |
67 | 73 | $mass_perform = false; |
68 | 74 | |
@@ -171,11 +177,8 @@ discard block |
||
171 | 177 | /** |
172 | 178 | * Функция проверяет статус транзакции |
173 | 179 | * |
174 | - * @param null|true|false $status Должна ли быть запущена транзакция в момент проверки |
|
175 | - * <p>null - транзакция НЕ должна быть запущена</p> |
|
176 | - * <p>true - транзакция должна быть запущена - для совместимости с $for_update</p> |
|
177 | - * <p>false - всё равно - для совместимости с $for_update</p> |
|
178 | - * @return bool Текущий статус транзакции |
|
180 | + * @param boolean $transaction_should_be_started |
|
181 | + * @return null|boolean Текущий статус транзакции |
|
179 | 182 | */ |
180 | 183 | function sn_db_transaction_check($transaction_should_be_started = null) { |
181 | 184 | return classSupernova::db_transaction_check($transaction_should_be_started); |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | function db_change_units_perform($query, $tablename, $object_id) { |
13 | 13 | $query = implode(',', $query); |
14 | - if($query && $object_id) { |
|
14 | + if ($query && $object_id) { |
|
15 | 15 | return classSupernova::db_upd_record_by_id($tablename == 'users' ? LOC_USER : LOC_PLANET, $object_id, $query); |
16 | 16 | // return doquery("UPDATE {{{$tablename}}} SET {$query} WHERE `id` = '{$object_id}' LIMIT 1;"); |
17 | 17 | } |
@@ -28,15 +28,15 @@ discard block |
||
28 | 28 | |
29 | 29 | $group = sn_get_groups('resources_loot'); |
30 | 30 | |
31 | - foreach($unit_list as $unit_id => $unit_amount) { |
|
32 | - if(!in_array($unit_id, $group)) { |
|
31 | + foreach ($unit_list as $unit_id => $unit_amount) { |
|
32 | + if (!in_array($unit_id, $group)) { |
|
33 | 33 | // TODO - remove later |
34 | 34 | print('<h1>СООБЩИТЕ ЭТО АДМИНУ: db_change_units() вызван для не-ресурсов!</h1>'); |
35 | 35 | pdump(debug_backtrace()); |
36 | 36 | die('db_change_units() вызван для не-ресурсов!'); |
37 | 37 | } |
38 | 38 | |
39 | - if(!$unit_amount) { |
|
39 | + if (!$unit_amount) { |
|
40 | 40 | continue; |
41 | 41 | } |
42 | 42 | |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | $unit_location = sys_get_unit_location($user, $planet, $unit_id); |
46 | 46 | |
47 | 47 | // Changing value in object |
48 | - switch($unit_location) { |
|
48 | + switch ($unit_location) { |
|
49 | 49 | case LOC_USER: |
50 | 50 | $user[$unit_db_name] += $unit_amount; |
51 | 51 | break; |
@@ -67,23 +67,23 @@ discard block |
||
67 | 67 | $field_set = ''; |
68 | 68 | $value_set = ''; |
69 | 69 | |
70 | - switch($type) { |
|
70 | + switch ($type) { |
|
71 | 71 | case 'delete': |
72 | 72 | $query = 'DELETE FROM'; |
73 | 73 | break; |
74 | 74 | |
75 | 75 | case 'insert': |
76 | 76 | $query = 'INSERT INTO'; |
77 | - if(isset($options['__multi'])) { |
|
77 | + if (isset($options['__multi'])) { |
|
78 | 78 | // Here we generate mass-insert set |
79 | 79 | break; |
80 | 80 | } |
81 | 81 | case 'update': |
82 | - if(!$query) { |
|
82 | + if (!$query) { |
|
83 | 83 | $query = 'UPDATE'; |
84 | 84 | } |
85 | 85 | |
86 | - foreach($values as $field => &$value) { |
|
86 | + foreach ($values as $field => &$value) { |
|
87 | 87 | $value_type = gettype($value); |
88 | 88 | if ($value_type == 'string') { |
89 | 89 | $value = "'" . db_escape($value) . "'"; |
@@ -111,12 +111,12 @@ discard block |
||
111 | 111 | $field_set['__IS_SAFE'] = true; |
112 | 112 | } |
113 | 113 | function sn_db_field_set_make_safe($field_set, $serialize = false) { |
114 | - if(!is_array($field_set)) { |
|
114 | + if (!is_array($field_set)) { |
|
115 | 115 | die('$field_set is not an array!'); |
116 | 116 | } |
117 | 117 | |
118 | 118 | $result = array(); |
119 | - foreach($field_set as $field => $value) { |
|
119 | + foreach ($field_set as $field => $value) { |
|
120 | 120 | $field = db_escape(trim($field)); |
121 | 121 | switch (true) { |
122 | 122 | case is_int($value): |