@@ -21,13 +21,13 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | public static function db_unit_count_by_user_and_type_and_snid($user_id, $unit_type = 0, $unit_snid = 0) { |
| 23 | 23 | $query = doquery( |
| 24 | - "SELECT unit_snid, sum(unit_level) as `qty` FROM {{unit}} WHERE `unit_player_id` = {$user_id} " . |
|
| 25 | - ($unit_type ? "AND `unit_type` = {$unit_type} " : '') . |
|
| 26 | - ($unit_snid ? "AND `unit_snid` = {$unit_snid} " : '') . |
|
| 24 | + "SELECT unit_snid, sum(unit_level) as `qty` FROM {{unit}} WHERE `unit_player_id` = {$user_id} ". |
|
| 25 | + ($unit_type ? "AND `unit_type` = {$unit_type} " : ''). |
|
| 26 | + ($unit_snid ? "AND `unit_snid` = {$unit_snid} " : ''). |
|
| 27 | 27 | 'GROUP BY `unit_snid`' |
| 28 | 28 | ); |
| 29 | 29 | $result = array(); |
| 30 | - while($row = db_fetch($query)) { |
|
| 30 | + while ($row = db_fetch($query)) { |
|
| 31 | 31 | $result[$row['unit_snid']] = $row; |
| 32 | 32 | } |
| 33 | 33 | |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | WHERE |
| 44 | 44 | f.fleet_owner = {$user_id} AND |
| 45 | 45 | (f.fleet_start_planet_id = {$location_id} OR f.fleet_end_planet_id = {$location_id}) |
| 46 | - AND u.unit_snid = {$unit_snid} AND u.`unit_location_type` = " . LOC_FLEET . " AND " . self::db_unit_time_restrictions() . |
|
| 47 | - " LIMIT 1" . |
|
| 46 | + AND u.unit_snid = {$unit_snid} AND u.`unit_location_type` = ".LOC_FLEET." AND ".self::db_unit_time_restrictions(). |
|
| 47 | + " LIMIT 1". |
|
| 48 | 48 | ($for_update ? ' FOR UPDATE' : '') |
| 49 | 49 | , true); |
| 50 | 50 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | public static function db_unit_list_laboratories($user_id) { |
| 54 | 54 | return doquery("SELECT DISTINCT unit_location_id AS `id` |
| 55 | 55 | FROM {{unit}} |
| 56 | - WHERE unit_player_id = {$user_id} AND unit_location_type = " . LOC_PLANET . " AND unit_level > 0 AND unit_snid IN (" . STRUC_LABORATORY . ", " . STRUC_LABORATORY_NANO . ");"); |
|
| 56 | + WHERE unit_player_id = {$user_id} AND unit_location_type = ".LOC_PLANET." AND unit_level > 0 AND unit_snid IN (".STRUC_LABORATORY.", ".STRUC_LABORATORY_NANO.");"); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | public static function db_unit_set_by_id($unit_id, $set) { |
@@ -71,9 +71,9 @@ discard block |
||
| 71 | 71 | |
| 72 | 72 | public static function db_unit_list_delete($user_id = 0, $unit_location_type, $unit_location_id = 0, $unit_snid = 0) { |
| 73 | 73 | return classSupernova::db_del_record_list(LOC_UNIT, |
| 74 | - "`unit_location_type` = {$unit_location_type}" . |
|
| 75 | - ($unit_location_id = idval($unit_location_id) ? " AND `unit_location_id` = {$unit_location_id}" : '') . |
|
| 76 | - ($user_id = idval($user_id) ? " AND `unit_player_id` = {$user_id}" : '') . |
|
| 74 | + "`unit_location_type` = {$unit_location_type}". |
|
| 75 | + ($unit_location_id = idval($unit_location_id) ? " AND `unit_location_id` = {$unit_location_id}" : ''). |
|
| 76 | + ($user_id = idval($user_id) ? " AND `unit_player_id` = {$user_id}" : ''). |
|
| 77 | 77 | ($unit_snid = idval($unit_snid) ? " AND `unit_snid` = {$unit_snid}" : '')); |
| 78 | 78 | } |
| 79 | 79 | |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | return doquery( |
| 82 | 82 | "SELECT unit_player_id, unit_type, unit_snid, unit_level, count(*) AS unit_amount |
| 83 | 83 | FROM `{{unit}}` |
| 84 | - WHERE unit_level > 0 AND " . self::db_unit_time_restrictions() . |
|
| 84 | + WHERE unit_level > 0 AND " . self::db_unit_time_restrictions(). |
|
| 85 | 85 | " GROUP BY unit_player_id, unit_type, unit_snid, unit_level" |
| 86 | 86 | ); |
| 87 | 87 | } |
@@ -93,15 +93,15 @@ discard block |
||
| 93 | 93 | |
| 94 | 94 | |
| 95 | 95 | public static function db_unit_list_admin_delete_mercenaries_finished() { |
| 96 | - return doquery("DELETE FROM {{unit}} WHERE unit_time_finish IS NOT NULL AND unit_time_finish < FROM_UNIXTIME(" . SN_TIME_NOW . ") AND unit_type = " . UNIT_MERCENARIES); |
|
| 96 | + return doquery("DELETE FROM {{unit}} WHERE unit_time_finish IS NOT NULL AND unit_time_finish < FROM_UNIXTIME(".SN_TIME_NOW.") AND unit_type = ".UNIT_MERCENARIES); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | public static function db_unit_list_admin_set_mercenaries_expire_time($default_length) { |
| 100 | 100 | return doquery( |
| 101 | 101 | "UPDATE {{unit}} |
| 102 | 102 | SET |
| 103 | - unit_time_start = FROM_UNIXTIME(" . SN_TIME_NOW . "), |
|
| 104 | - unit_time_finish = FROM_UNIXTIME(" . (SN_TIME_NOW + $default_length) . ") |
|
| 103 | + unit_time_start = FROM_UNIXTIME(" . SN_TIME_NOW."), |
|
| 104 | + unit_time_finish = FROM_UNIXTIME(" . (SN_TIME_NOW + $default_length).") |
|
| 105 | 105 | WHERE unit_type = " . UNIT_MERCENARIES |
| 106 | 106 | ); |
| 107 | 107 | } |
@@ -398,31 +398,31 @@ discard block |
||
| 398 | 398 | |
| 399 | 399 | return doquery( |
| 400 | 400 | // Блокировка самого флота |
| 401 | - "SELECT 1 FROM {{fleets}} AS f " . |
|
| 401 | + "SELECT 1 FROM {{fleets}} AS f ". |
|
| 402 | 402 | |
| 403 | 403 | // Блокировка всех юнитов, принадлежащих этому флоту |
| 404 | - "LEFT JOIN {{unit}} as unit ON unit.unit_location_type = " . static::$locationType . " AND unit.unit_location_id = f.fleet_id " . |
|
| 404 | + "LEFT JOIN {{unit}} as unit ON unit.unit_location_type = ".static::$locationType." AND unit.unit_location_id = f.fleet_id ". |
|
| 405 | 405 | |
| 406 | 406 | // Блокировка всех прилетающих и улетающих флотов, если нужно |
| 407 | 407 | // TODO - lock fleets by COORDINATES |
| 408 | - ($mission_data['dst_fleets'] ? "LEFT JOIN {{fleets}} AS fd ON fd.fleet_end_planet_id = f.fleet_end_planet_id OR fd.fleet_start_planet_id = f.fleet_end_planet_id " : '') . |
|
| 408 | + ($mission_data['dst_fleets'] ? "LEFT JOIN {{fleets}} AS fd ON fd.fleet_end_planet_id = f.fleet_end_planet_id OR fd.fleet_start_planet_id = f.fleet_end_planet_id " : ''). |
|
| 409 | 409 | // Блокировка всех юнитов, принадлежащих прилетающим и улетающим флотам - ufd = unit_fleet_destination |
| 410 | - ($mission_data['dst_fleets'] ? "LEFT JOIN {{unit}} AS ufd ON ufd.unit_location_type = " . static::$locationType . " AND ufd.unit_location_id = fd.fleet_id " : '') . |
|
| 410 | + ($mission_data['dst_fleets'] ? "LEFT JOIN {{unit}} AS ufd ON ufd.unit_location_type = ".static::$locationType." AND ufd.unit_location_id = fd.fleet_id " : ''). |
|
| 411 | 411 | |
| 412 | - ($mission_data['dst_user'] || $mission_data['dst_planet'] ? "LEFT JOIN {{users}} AS ud ON ud.id = f.fleet_target_owner " : '') . |
|
| 412 | + ($mission_data['dst_user'] || $mission_data['dst_planet'] ? "LEFT JOIN {{users}} AS ud ON ud.id = f.fleet_target_owner " : ''). |
|
| 413 | 413 | // Блокировка всех юнитов, принадлежащих владельцу планеты-цели |
| 414 | - ($mission_data['dst_user'] || $mission_data['dst_planet'] ? "LEFT JOIN {{unit}} AS unit_player_dest ON unit_player_dest.unit_player_id = ud.id " : '') . |
|
| 414 | + ($mission_data['dst_user'] || $mission_data['dst_planet'] ? "LEFT JOIN {{unit}} AS unit_player_dest ON unit_player_dest.unit_player_id = ud.id " : ''). |
|
| 415 | 415 | // Блокировка планеты-цели |
| 416 | - ($mission_data['dst_planet'] ? "LEFT JOIN {{planets}} AS pd ON pd.id = f.fleet_end_planet_id " : '') . |
|
| 416 | + ($mission_data['dst_planet'] ? "LEFT JOIN {{planets}} AS pd ON pd.id = f.fleet_end_planet_id " : ''). |
|
| 417 | 417 | // Блокировка всех юнитов, принадлежащих планете-цели - НЕ НУЖНО. Уже залочили ранее, как принадлежащие игроку-цели |
| 418 | 418 | // ($mission_data['dst_planet'] ? "LEFT JOIN {{unit}} AS upd ON upd.unit_location_type = " . LOC_PLANET . " AND upd.unit_location_id = pd.id " : '') . |
| 419 | 419 | |
| 420 | 420 | |
| 421 | - ($mission_data['src_user'] || $mission_data['src_planet'] ? "LEFT JOIN {{users}} AS us ON us.id = f.fleet_owner " : '') . |
|
| 421 | + ($mission_data['src_user'] || $mission_data['src_planet'] ? "LEFT JOIN {{users}} AS us ON us.id = f.fleet_owner " : ''). |
|
| 422 | 422 | // Блокировка всех юнитов, принадлежащих владельцу флота |
| 423 | - ($mission_data['src_user'] || $mission_data['src_planet'] ? "LEFT JOIN {{unit}} AS unit_player_src ON unit_player_src.unit_player_id = us.id " : '') . |
|
| 423 | + ($mission_data['src_user'] || $mission_data['src_planet'] ? "LEFT JOIN {{unit}} AS unit_player_src ON unit_player_src.unit_player_id = us.id " : ''). |
|
| 424 | 424 | // Блокировка планеты отправления |
| 425 | - ($mission_data['src_planet'] ? "LEFT JOIN {{planets}} AS ps ON ps.id = f.fleet_start_planet_id " : '') . |
|
| 425 | + ($mission_data['src_planet'] ? "LEFT JOIN {{planets}} AS ps ON ps.id = f.fleet_start_planet_id " : ''). |
|
| 426 | 426 | // Блокировка всех юнитов, принадлежащих планете с которой юниты были отправлены - НЕ НУЖНО. Уже залочили ранее, как принадлежащие владельцу флота |
| 427 | 427 | // ($mission_data['src_planet'] ? "LEFT JOIN {{unit}} AS ups ON ups.unit_location_type = " . LOC_PLANET . " AND ups.unit_location_id = ps.id " : '') . |
| 428 | 428 | |
@@ -439,11 +439,11 @@ discard block |
||
| 439 | 439 | public function dbGetLockById($dbId) { |
| 440 | 440 | doquery( |
| 441 | 441 | // Блокировка самого флота |
| 442 | - "SELECT 1 FROM {{fleets}} AS FLEET0 " . |
|
| 442 | + "SELECT 1 FROM {{fleets}} AS FLEET0 ". |
|
| 443 | 443 | // Lock fleet owner |
| 444 | - "LEFT JOIN {{users}} as USER0 on USER0.id = FLEET0.fleet_owner " . |
|
| 444 | + "LEFT JOIN {{users}} as USER0 on USER0.id = FLEET0.fleet_owner ". |
|
| 445 | 445 | // Блокировка всех юнитов, принадлежащих этому флоту |
| 446 | - "LEFT JOIN {{unit}} as UNIT0 ON UNIT0.unit_location_type = " . LOC_FLEET . " AND UNIT0.unit_location_id = FLEET0.fleet_id " . |
|
| 446 | + "LEFT JOIN {{unit}} as UNIT0 ON UNIT0.unit_location_type = ".LOC_FLEET." AND UNIT0.unit_location_id = FLEET0.fleet_id ". |
|
| 447 | 447 | |
| 448 | 448 | // Без предварительной выборки неизвестно - куда летит этот флот. |
| 449 | 449 | // Поэтому надо выбирать флоты, чьи координаты прибытия ИЛИ отбытия совпадают с координатами прибытия ИЛИ отбытия текущего флота. |
@@ -459,9 +459,9 @@ discard block |
||
| 459 | 459 | FLEET1.fleet_end_planet = FLEET0.fleet_end_planet |
| 460 | 460 | " . |
| 461 | 461 | // Блокировка всех юнитов, принадлежащих этим флотам |
| 462 | - "LEFT JOIN {{unit}} as UNIT1 ON UNIT1.unit_location_type = " . LOC_FLEET . " AND UNIT1.unit_location_id = FLEET1.fleet_id " . |
|
| 462 | + "LEFT JOIN {{unit}} as UNIT1 ON UNIT1.unit_location_type = ".LOC_FLEET." AND UNIT1.unit_location_id = FLEET1.fleet_id ". |
|
| 463 | 463 | // Lock fleet owner |
| 464 | - "LEFT JOIN {{users}} as USER1 on USER1.id = FLEET1.fleet_owner " . |
|
| 464 | + "LEFT JOIN {{users}} as USER1 on USER1.id = FLEET1.fleet_owner ". |
|
| 465 | 465 | |
| 466 | 466 | "LEFT JOIN {{fleets}} AS FLEET2 ON |
| 467 | 467 | FLEET2.fleet_mess = 1 AND FLEET0.fleet_mess = 0 AND |
@@ -471,7 +471,7 @@ discard block |
||
| 471 | 471 | " . |
| 472 | 472 | // Блокировка всех юнитов, принадлежащих этим флотам |
| 473 | 473 | "LEFT JOIN {{unit}} as UNIT2 ON |
| 474 | - UNIT2.unit_location_type = " . LOC_FLEET . " AND |
|
| 474 | + UNIT2.unit_location_type = " . LOC_FLEET." AND |
|
| 475 | 475 | UNIT2.unit_location_id = FLEET2.fleet_id |
| 476 | 476 | " . |
| 477 | 477 | // Lock fleet owner |
@@ -488,11 +488,11 @@ discard block |
||
| 488 | 488 | " . |
| 489 | 489 | // Блокировка всех юнитов, принадлежащих этим флотам |
| 490 | 490 | "LEFT JOIN {{unit}} as UNIT3 ON |
| 491 | - UNIT3.unit_location_type = " . LOC_FLEET . " AND |
|
| 491 | + UNIT3.unit_location_type = " . LOC_FLEET." AND |
|
| 492 | 492 | UNIT3.unit_location_id = FLEET3.fleet_id |
| 493 | 493 | " . |
| 494 | 494 | // Lock fleet owner |
| 495 | - "LEFT JOIN {{users}} as USER3 on USER3.id = FLEET3.fleet_owner " . |
|
| 495 | + "LEFT JOIN {{users}} as USER3 on USER3.id = FLEET3.fleet_owner ". |
|
| 496 | 496 | |
| 497 | 497 | "LEFT JOIN {{fleets}} AS FLEET4 ON |
| 498 | 498 | FLEET4.fleet_mess = 1 AND FLEET0.fleet_mess = 1 AND |
@@ -502,7 +502,7 @@ discard block |
||
| 502 | 502 | " . |
| 503 | 503 | // Блокировка всех юнитов, принадлежащих этим флотам |
| 504 | 504 | "LEFT JOIN {{unit}} as UNIT4 ON |
| 505 | - UNIT4.unit_location_type = " . LOC_FLEET . " AND |
|
| 505 | + UNIT4.unit_location_type = " . LOC_FLEET." AND |
|
| 506 | 506 | UNIT4.unit_location_id = FLEET4.fleet_id |
| 507 | 507 | " . |
| 508 | 508 | // Lock fleet owner |
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | " . |
| 525 | 525 | // Блокировка всех юнитов, принадлежащих этой планете |
| 526 | 526 | "LEFT JOIN {{unit}} as UNIT5 ON |
| 527 | - UNIT5.unit_location_type = " . LOC_PLANET . " AND |
|
| 527 | + UNIT5.unit_location_type = " . LOC_PLANET." AND |
|
| 528 | 528 | UNIT5.unit_location_id = PLANETS5.id |
| 529 | 529 | " . |
| 530 | 530 | |
@@ -542,7 +542,7 @@ discard block |
||
| 542 | 542 | " . |
| 543 | 543 | // Блокировка всех юнитов, принадлежащих этой планете |
| 544 | 544 | "LEFT JOIN {{unit}} as UNIT6 ON |
| 545 | - UNIT6.unit_location_type = " . LOC_PLANET . " AND |
|
| 545 | + UNIT6.unit_location_type = " . LOC_PLANET." AND |
|
| 546 | 546 | UNIT6.unit_location_id = PLANETS6.id |
| 547 | 547 | " . |
| 548 | 548 | "WHERE FLEET0.fleet_id = {$dbId} GROUP BY 1 FOR UPDATE" |
@@ -661,7 +661,7 @@ discard block |
||
| 661 | 661 | } elseif ($this->isResource($unit_id)) { |
| 662 | 662 | $this->resource_list[$unit_id] = $unit_count; |
| 663 | 663 | } else { |
| 664 | - throw new Exception('Trying to pass to fleet non-resource and non-ship ' . var_export($unit_array, true), ERR_ERROR); |
|
| 664 | + throw new Exception('Trying to pass to fleet non-resource and non-ship '.var_export($unit_array, true), ERR_ERROR); |
|
| 665 | 665 | } |
| 666 | 666 | } |
| 667 | 667 | } |
@@ -986,7 +986,7 @@ discard block |
||
| 986 | 986 | */ |
| 987 | 987 | public function resourcesSet($resource_list) { |
| 988 | 988 | if (!empty($this->propertiesAdjusted['resource_list'])) { |
| 989 | - throw new PropertyAccessException('Property "resource_list" already was adjusted so no SET is possible until dbSave in ' . get_called_class() . '::unitSetResourceList', ERR_ERROR); |
|
| 989 | + throw new PropertyAccessException('Property "resource_list" already was adjusted so no SET is possible until dbSave in '.get_called_class().'::unitSetResourceList', ERR_ERROR); |
|
| 990 | 990 | } |
| 991 | 991 | $this->resourcesAdjust($resource_list, true); |
| 992 | 992 | } |
@@ -1020,7 +1020,7 @@ discard block |
||
| 1020 | 1020 | // Check for negative unit value |
| 1021 | 1021 | if ($this->resource_list[$resource_id] < 0) { |
| 1022 | 1022 | // TODO |
| 1023 | - throw new Exception('Resource ' . $resource_id . ' will become negative in ' . get_called_class() . '::unitAdjustResourceList', ERR_ERROR); |
|
| 1023 | + throw new Exception('Resource '.$resource_id.' will become negative in '.get_called_class().'::unitAdjustResourceList', ERR_ERROR); |
|
| 1024 | 1024 | } |
| 1025 | 1025 | } |
| 1026 | 1026 | } |
@@ -1193,7 +1193,7 @@ discard block |
||
| 1193 | 1193 | |
| 1194 | 1194 | protected function printErrorIfNoShips() { |
| 1195 | 1195 | if ($this->unitList->unitsCount() <= 0) { |
| 1196 | - message(classLocale::$lang['fl_err_no_ships'], classLocale::$lang['fl_error'], 'fleet' . DOT_PHP_EX, 5); |
|
| 1196 | + message(classLocale::$lang['fl_err_no_ships'], classLocale::$lang['fl_error'], 'fleet'.DOT_PHP_EX, 5); |
|
| 1197 | 1197 | } |
| 1198 | 1198 | } |
| 1199 | 1199 | |
@@ -1540,7 +1540,7 @@ discard block |
||
| 1540 | 1540 | } catch (Exception $e) { |
| 1541 | 1541 | |
| 1542 | 1542 | // TODO - MESSAGE BOX |
| 1543 | - if($e instanceof ExceptionFleetInvalid) { |
|
| 1543 | + if ($e instanceof ExceptionFleetInvalid) { |
|
| 1544 | 1544 | sn_db_transaction_rollback(); |
| 1545 | 1545 | pdie(classLocale::$lang['fl_attack_error'][$e->getCode()]); |
| 1546 | 1546 | } else { |
@@ -1629,7 +1629,7 @@ discard block |
||
| 1629 | 1629 | $validator->validate(); |
| 1630 | 1630 | } catch (Exception $e) { |
| 1631 | 1631 | // TODO - MESSAGE BOX |
| 1632 | - if($e instanceof ExceptionFleetInvalid) { |
|
| 1632 | + if ($e instanceof ExceptionFleetInvalid) { |
|
| 1633 | 1633 | sn_db_transaction_rollback(); |
| 1634 | 1634 | pdie(classLocale::$lang['fl_attack_error'][$e->getCode()]); |
| 1635 | 1635 | } else { |
@@ -1690,7 +1690,7 @@ discard block |
||
| 1690 | 1690 | |
| 1691 | 1691 | |
| 1692 | 1692 | if (!empty($this->captain['unit_id'])) { |
| 1693 | - DBStaticUnit::db_unit_set_by_id($this->captain['unit_id'], "`unit_location_type` = " . LOC_FLEET . ", `unit_location_id` = {$this->_dbId}"); |
|
| 1693 | + DBStaticUnit::db_unit_set_by_id($this->captain['unit_id'], "`unit_location_type` = ".LOC_FLEET.", `unit_location_id` = {$this->_dbId}"); |
|
| 1694 | 1694 | } |
| 1695 | 1695 | |
| 1696 | 1696 | // return $this->fleet->acs['ankunft'] - $this->fleet->time_launch >= $this->fleet->travelData['duration']; |
@@ -1702,7 +1702,7 @@ discard block |
||
| 1702 | 1702 | $template_result['.']['fleets'][] = $this->renderFleet(SN_TIME_NOW, $timeMissionJob); |
| 1703 | 1703 | |
| 1704 | 1704 | $template_result += array( |
| 1705 | - 'mission' => classLocale::$lang['type_mission'][$this->_mission_type] . ($this->_mission_type == MT_EXPLORE || $this->_mission_type == MT_HOLD ? ' ' . pretty_time($timeMissionJob) : ''), |
|
| 1705 | + 'mission' => classLocale::$lang['type_mission'][$this->_mission_type].($this->_mission_type == MT_EXPLORE || $this->_mission_type == MT_HOLD ? ' '.pretty_time($timeMissionJob) : ''), |
|
| 1706 | 1706 | 'dist' => pretty_number($this->travelData['distance']), |
| 1707 | 1707 | 'speed' => pretty_number($this->travelData['fleet_speed']), |
| 1708 | 1708 | 'deute_need' => pretty_number($this->travelData['consumption']), |
@@ -35,13 +35,13 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | $this->container = array(); |
| 37 | 37 | |
| 38 | - if(classSupernova::$cache->_MODE != CACHER_NO_CACHE && !classSupernova::$config->locale_cache_disable) { |
|
| 38 | + if (classSupernova::$cache->_MODE != CACHER_NO_CACHE && !classSupernova::$config->locale_cache_disable) { |
|
| 39 | 39 | $this->cache = classSupernova::$cache; |
| 40 | 40 | classSupernova::log_file('locale.__constructor: Cache is present'); |
| 41 | 41 | //$this->cache->unset_by_prefix($this->cache_prefix); // TODO - remove? 'cause debug! |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - if($enable_stat_usage && empty($this->stat_usage)) { |
|
| 44 | + if ($enable_stat_usage && empty($this->stat_usage)) { |
|
| 45 | 45 | $this->enable_stat_usage = $enable_stat_usage; |
| 46 | 46 | $this->usage_stat_load(); |
| 47 | 47 | // TODO shutdown function |
@@ -67,18 +67,18 @@ discard block |
||
| 67 | 67 | unset($fallback[$this->active]); |
| 68 | 68 | |
| 69 | 69 | // Проходим по оставшимся локалям |
| 70 | - foreach($fallback as $try_language) { |
|
| 70 | + foreach ($fallback as $try_language) { |
|
| 71 | 71 | // Если нет такой строки - пытаемся вытащить из кэша |
| 72 | - if(!isset($this->container[$try_language][$offset]) && $this->cache) { |
|
| 73 | - $this->container[$try_language][$offset] = $this->cache->__get($this->cache_prefix . $try_language . '_' . $offset); |
|
| 72 | + if (!isset($this->container[$try_language][$offset]) && $this->cache) { |
|
| 73 | + $this->container[$try_language][$offset] = $this->cache->__get($this->cache_prefix.$try_language.'_'.$offset); |
|
| 74 | 74 | // Записываем результат работы кэша |
| 75 | 75 | $locale_cache_statistic['queries']++; |
| 76 | 76 | isset($this->container[$try_language][$offset]) ? $locale_cache_statistic['hits']++ : $locale_cache_statistic['misses']++; |
| 77 | -!isset($this->container[$try_language][$offset]) ? $locale_cache_statistic['missed_str'][] = $this->cache_prefix . $try_language . '_' . $offset : false; |
|
| 77 | +!isset($this->container[$try_language][$offset]) ? $locale_cache_statistic['missed_str'][] = $this->cache_prefix.$try_language.'_'.$offset : false; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // Если мы как-то где-то нашли строку... |
| 81 | - if(isset($this->container[$try_language][$offset])) { |
|
| 81 | + if (isset($this->container[$try_language][$offset])) { |
|
| 82 | 82 | // ...значит она получена в результате фоллбэка и записываем её в кэш и контейнер |
| 83 | 83 | $this[$offset] = $this->container[$try_language][$offset]; |
| 84 | 84 | $locale_cache_statistic['fallbacks']++; |
@@ -94,16 +94,16 @@ discard block |
||
| 94 | 94 | $this->container[$this->active][] = $value; |
| 95 | 95 | } else { |
| 96 | 96 | $this->container[$this->active][$offset] = $value; |
| 97 | - if($this->cache) { |
|
| 98 | - $this->cache->__set($this->cache_prefix_lang . $offset, $value); |
|
| 97 | + if ($this->cache) { |
|
| 98 | + $this->cache->__set($this->cache_prefix_lang.$offset, $value); |
|
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | public function offsetExists($offset) { |
| 103 | 103 | // Шорткат если у нас уже есть строка в памяти PHP |
| 104 | - if(!isset($this->container[$this->active][$offset])) { |
|
| 104 | + if (!isset($this->container[$this->active][$offset])) { |
|
| 105 | 105 | // pdump($this->cache_prefix_lang . $offset); |
| 106 | - if(!$this->cache || !($this->container[$this->active][$offset] = $this->cache->__get($this->cache_prefix_lang . $offset))) { |
|
| 106 | + if (!$this->cache || !($this->container[$this->active][$offset] = $this->cache->__get($this->cache_prefix_lang.$offset))) { |
|
| 107 | 107 | // pdump($this->cache_prefix_lang . $offset); |
| 108 | 108 | // Если нету такой строки - делаем фоллбэк |
| 109 | 109 | $this->locale_string_fallback($offset); |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | } |
| 120 | 120 | public function offsetGet($offset) { |
| 121 | 121 | $value = $this->offsetExists($offset) ? $this->container[$this->active][$offset] : null; |
| 122 | - if($this->enable_stat_usage) { |
|
| 122 | + if ($this->enable_stat_usage) { |
|
| 123 | 123 | $this->usage_stat_log($offset, $value); |
| 124 | 124 | } |
| 125 | 125 | return $value; |
@@ -136,26 +136,26 @@ discard block |
||
| 136 | 136 | public function usage_stat_load() { |
| 137 | 137 | global $sn_cache; |
| 138 | 138 | |
| 139 | - $this->stat_usage = $sn_cache->lng_stat_usage = array(); // TODO for debug |
|
| 140 | - if(empty($this->stat_usage)) { |
|
| 139 | + $this->stat_usage = $sn_cache->lng_stat_usage = array(); // TODO for debug |
|
| 140 | + if (empty($this->stat_usage)) { |
|
| 141 | 141 | $query = doquery("SELECT * FROM {{lng_usage_stat}}"); |
| 142 | - while($row = db_fetch($query)) { |
|
| 143 | - $this->stat_usage[$row['lang_code'] . ':' . $row['string_id'] . ':' . $row['file'] . ':' . $row['line']] = $row['is_empty']; |
|
| 142 | + while ($row = db_fetch($query)) { |
|
| 143 | + $this->stat_usage[$row['lang_code'].':'.$row['string_id'].':'.$row['file'].':'.$row['line']] = $row['is_empty']; |
|
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | public function usage_stat_save() { |
| 148 | - if(!empty($this->stat_usage_new)) { |
|
| 148 | + if (!empty($this->stat_usage_new)) { |
|
| 149 | 149 | global $sn_cache; |
| 150 | 150 | $sn_cache->lng_stat_usage = $this->stat_usage; |
| 151 | 151 | doquery("SELECT 1 FROM {{lng_usage_stat}} LIMIT 1"); |
| 152 | - foreach($this->stat_usage_new as &$value) { |
|
| 153 | - foreach($value as &$value2) { |
|
| 154 | - $value2 = '"' . db_escape($value2) . '"'; |
|
| 152 | + foreach ($this->stat_usage_new as &$value) { |
|
| 153 | + foreach ($value as &$value2) { |
|
| 154 | + $value2 = '"'.db_escape($value2).'"'; |
|
| 155 | 155 | } |
| 156 | - $value = '(' . implode(',', $value) .')'; |
|
| 156 | + $value = '('.implode(',', $value).')'; |
|
| 157 | 157 | } |
| 158 | - doquery("REPLACE INTO {{lng_usage_stat}} (lang_code,string_id,`file`,line,is_empty,locale) VALUES " . implode(',', $this->stat_usage_new)); |
|
| 158 | + doquery("REPLACE INTO {{lng_usage_stat}} (lang_code,string_id,`file`,line,is_empty,locale) VALUES ".implode(',', $this->stat_usage_new)); |
|
| 159 | 159 | } |
| 160 | 160 | } |
| 161 | 161 | public function usage_stat_log(&$offset, &$value) { |
@@ -165,8 +165,8 @@ discard block |
||
| 165 | 165 | |
| 166 | 166 | $file = str_replace('\\', '/', substr($trace[1]['file'], strlen(SN_ROOT_PHYSICAL) - 1)); |
| 167 | 167 | |
| 168 | - $string_id = $this->active . ':' . $offset . ':' . $file . ':' . $trace[1]['line']; |
|
| 169 | - if(!isset($this->stat_usage[$string_id]) || $this->stat_usage[$string_id] != empty($value)) { |
|
| 168 | + $string_id = $this->active.':'.$offset.':'.$file.':'.$trace[1]['line']; |
|
| 169 | + if (!isset($this->stat_usage[$string_id]) || $this->stat_usage[$string_id] != empty($value)) { |
|
| 170 | 170 | $this->stat_usage[$string_id] = empty($value); |
| 171 | 171 | $this->stat_usage_new[] = array( |
| 172 | 172 | 'lang_code' => $this->active, |
@@ -174,14 +174,14 @@ discard block |
||
| 174 | 174 | 'file' => $file, |
| 175 | 175 | 'line' => $trace[1]['line'], |
| 176 | 176 | 'is_empty' => intval(empty($value)), |
| 177 | - 'locale' => '' . $value, |
|
| 177 | + 'locale' => ''.$value, |
|
| 178 | 178 | ); |
| 179 | 179 | } |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | |
| 183 | 183 | protected function lng_try_filepath($path, $file_path_relative) { |
| 184 | - $file_path = SN_ROOT_PHYSICAL . ($path && file_exists(SN_ROOT_PHYSICAL . $path . $file_path_relative) ? $path : '') . $file_path_relative; |
|
| 184 | + $file_path = SN_ROOT_PHYSICAL.($path && file_exists(SN_ROOT_PHYSICAL.$path.$file_path_relative) ? $path : '').$file_path_relative; |
|
| 185 | 185 | return file_exists($file_path) ? $file_path : false; |
| 186 | 186 | } |
| 187 | 187 | |
@@ -203,14 +203,14 @@ discard block |
||
| 203 | 203 | |
| 204 | 204 | classSupernova::log_file("locale.include: Loading data from domain '{$filename}'", 1); |
| 205 | 205 | |
| 206 | - $cache_file_key = $this->cache_prefix_lang . '__' . $filename; |
|
| 206 | + $cache_file_key = $this->cache_prefix_lang.'__'.$filename; |
|
| 207 | 207 | |
| 208 | 208 | // Подключен ли внешний кэш? |
| 209 | - if($this->cache) { |
|
| 209 | + if ($this->cache) { |
|
| 210 | 210 | // Загружен ли уже данный файл? |
| 211 | 211 | $cache_file_status = $this->cache->__get($cache_file_key); |
| 212 | - 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); |
|
| 213 | - if($cache_file_status) { |
|
| 212 | + 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); |
|
| 213 | + if ($cache_file_status) { |
|
| 214 | 214 | // Если да - повторять загрузку нет смысла |
| 215 | 215 | return null; |
| 216 | 216 | } |
@@ -224,47 +224,47 @@ discard block |
||
| 224 | 224 | $this->make_fallback($language); |
| 225 | 225 | |
| 226 | 226 | $file_path = ''; |
| 227 | - foreach($this->fallback as $lang_try) { |
|
| 228 | - if(!$lang_try /* || isset($language_tried[$lang_try]) */) { |
|
| 227 | + foreach ($this->fallback as $lang_try) { |
|
| 228 | + if (!$lang_try /* || isset($language_tried[$lang_try]) */) { |
|
| 229 | 229 | continue; |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - if($file_path = $this->lng_try_filepath($path, "language/{$lang_try}/{$filename_ext}")) { |
|
| 232 | + if ($file_path = $this->lng_try_filepath($path, "language/{$lang_try}/{$filename_ext}")) { |
|
| 233 | 233 | break; |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - if($file_path = $this->lng_try_filepath($path, "language/{$filename}_{$lang_try}{$ext}")) { |
|
| 236 | + if ($file_path = $this->lng_try_filepath($path, "language/{$filename}_{$lang_try}{$ext}")) { |
|
| 237 | 237 | break; |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | $file_path = ''; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - if($file_path) { |
|
| 243 | + if ($file_path) { |
|
| 244 | 244 | $a_lang_array = array(); |
| 245 | 245 | include($file_path); |
| 246 | 246 | |
| 247 | - if(!empty($a_lang_array)) { |
|
| 247 | + if (!empty($a_lang_array)) { |
|
| 248 | 248 | $this->merge($a_lang_array); |
| 249 | 249 | |
| 250 | 250 | // Загрузка данных из файла в кэш |
| 251 | - if($this->cache) { |
|
| 251 | + if ($this->cache) { |
|
| 252 | 252 | classSupernova::log_file("Locale: loading '{$filename}' into cache"); |
| 253 | - foreach($a_lang_array as $key => $value) { |
|
| 254 | - $value_cache_key = $this->cache_prefix_lang . $key; |
|
| 255 | - if($this->cache->__isset($value_cache_key)) { |
|
| 256 | - if(is_array($value)) { |
|
| 253 | + foreach ($a_lang_array as $key => $value) { |
|
| 254 | + $value_cache_key = $this->cache_prefix_lang.$key; |
|
| 255 | + if ($this->cache->__isset($value_cache_key)) { |
|
| 256 | + if (is_array($value)) { |
|
| 257 | 257 | $alt_value = $this->cache->__get($value_cache_key); |
| 258 | 258 | $value = array_replace_recursive($alt_value, $value); |
| 259 | 259 | // pdump($alt_value, $alt_value); |
| 260 | 260 | } |
| 261 | 261 | } |
| 262 | - $this->cache->__set($this->cache_prefix_lang . $key, $value); |
|
| 262 | + $this->cache->__set($this->cache_prefix_lang.$key, $value); |
|
| 263 | 263 | } |
| 264 | 264 | } |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - if($this->cache) { |
|
| 267 | + if ($this->cache) { |
|
| 268 | 268 | $this->cache->__set($cache_file_key, true); |
| 269 | 269 | } |
| 270 | 270 | |
@@ -277,14 +277,14 @@ discard block |
||
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | public function lng_load_i18n($i18n) { |
| 280 | - if(!isset($i18n)) { |
|
| 280 | + if (!isset($i18n)) { |
|
| 281 | 281 | return; |
| 282 | 282 | } |
| 283 | 283 | |
| 284 | - foreach($i18n as $i18n_data) { |
|
| 285 | - if(is_string($i18n_data)) { |
|
| 284 | + foreach ($i18n as $i18n_data) { |
|
| 285 | + if (is_string($i18n_data)) { |
|
| 286 | 286 | $this->lng_include($i18n_data); |
| 287 | - } elseif(is_array($i18n_data)) { |
|
| 287 | + } elseif (is_array($i18n_data)) { |
|
| 288 | 288 | $this->lng_include($i18n_data['file'], $i18n_data['path']); |
| 289 | 289 | } |
| 290 | 290 | } |
@@ -302,27 +302,27 @@ discard block |
||
| 302 | 302 | |
| 303 | 303 | classSupernova::log_file("locale.switch: Trying to switch language to '{$language_new}'"); |
| 304 | 304 | |
| 305 | - if($language_new == $this->active) { |
|
| 305 | + if ($language_new == $this->active) { |
|
| 306 | 306 | classSupernova::log_file("locale.switch: New language '{$language_new}' is equal to current language '{$this->active}' - EXIT", -1); |
| 307 | 307 | return false; |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | $this->active = $language = $language_new; |
| 311 | - $this->cache_prefix_lang = $this->cache_prefix . $this->active . '_'; |
|
| 311 | + $this->cache_prefix_lang = $this->cache_prefix.$this->active.'_'; |
|
| 312 | 312 | |
| 313 | 313 | $this['LANG_INFO'] = $this->lng_get_info($this->active); |
| 314 | 314 | $this->make_fallback($this->active); |
| 315 | 315 | |
| 316 | - if($this->cache) { |
|
| 317 | - $cache_lang_init_status = $this->cache->__get($this->cache_prefix_lang . '__INIT'); |
|
| 318 | - 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); |
|
| 319 | - if($cache_lang_init_status) { |
|
| 316 | + if ($this->cache) { |
|
| 317 | + $cache_lang_init_status = $this->cache->__get($this->cache_prefix_lang.'__INIT'); |
|
| 318 | + 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); |
|
| 319 | + if ($cache_lang_init_status) { |
|
| 320 | 320 | return false; |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | // Чистим текущие локализации из кэша. Достаточно почистить только флаги инициализации языкового кэша и загрузки файлов - они начинаются с '__' |
| 324 | 324 | classSupernova::log_file("locale.switch: Cache - invalidating data"); |
| 325 | - $this->cache->unset_by_prefix($this->cache_prefix_lang . '__'); |
|
| 325 | + $this->cache->unset_by_prefix($this->cache_prefix_lang.'__'); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | $this->lng_include('system'); |
@@ -332,9 +332,9 @@ discard block |
||
| 332 | 332 | // Loading global language files |
| 333 | 333 | $this->lng_load_i18n(classSupernova::$sn_mvc['i18n']['']); |
| 334 | 334 | |
| 335 | - if($this->cache) { |
|
| 336 | - classSupernova::log_file("locale.switch: Cache - setting flag " . $this->cache_prefix_lang . '__INIT'); |
|
| 337 | - $this->cache->__set($this->cache_prefix_lang . '__INIT', true); |
|
| 335 | + if ($this->cache) { |
|
| 336 | + classSupernova::log_file("locale.switch: Cache - setting flag ".$this->cache_prefix_lang.'__INIT'); |
|
| 337 | + $this->cache->__set($this->cache_prefix_lang.'__INIT', true); |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | classSupernova::log_file("locale.switch: Complete - EXIT"); |
@@ -344,9 +344,9 @@ discard block |
||
| 344 | 344 | |
| 345 | 345 | |
| 346 | 346 | public function lng_get_info($entry) { |
| 347 | - $file_name = SN_ROOT_PHYSICAL . 'language/' . $entry . '/language.mo.php'; |
|
| 347 | + $file_name = SN_ROOT_PHYSICAL.'language/'.$entry.'/language.mo.php'; |
|
| 348 | 348 | $lang_info = array(); |
| 349 | - if(file_exists($file_name)) { |
|
| 349 | + if (file_exists($file_name)) { |
|
| 350 | 350 | include($file_name); |
| 351 | 351 | } |
| 352 | 352 | |
@@ -354,15 +354,15 @@ discard block |
||
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | public function lng_get_list() { |
| 357 | - if(empty($this->lang_list)) { |
|
| 357 | + if (empty($this->lang_list)) { |
|
| 358 | 358 | $this->lang_list = array(); |
| 359 | 359 | |
| 360 | - $path = SN_ROOT_PHYSICAL . 'language/'; |
|
| 360 | + $path = SN_ROOT_PHYSICAL.'language/'; |
|
| 361 | 361 | $dir = dir($path); |
| 362 | - while(false !== ($entry = $dir->read())) { |
|
| 363 | - if(is_dir($path . $entry) && $entry[0] != '.') { |
|
| 362 | + while (false !== ($entry = $dir->read())) { |
|
| 363 | + if (is_dir($path.$entry) && $entry[0] != '.') { |
|
| 364 | 364 | $lang_info = $this->lng_get_info($entry); |
| 365 | - if($lang_info['LANG_NAME_ISO2'] == $entry) { |
|
| 365 | + if ($lang_info['LANG_NAME_ISO2'] == $entry) { |
|
| 366 | 366 | $this->lang_list[$lang_info['LANG_NAME_ISO2']] = $lang_info; |
| 367 | 367 | } |
| 368 | 368 | } |