@@ -30,11 +30,11 @@ 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'); |
| 39 | 39 | } |
| 40 | 40 | |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | return mysqli_real_escape_string($this->link, $unescaped_string); |
| 91 | 91 | } |
| 92 | 92 | function mysql_close_link() { |
| 93 | - if(is_object($this->link)) { |
|
| 93 | + if (is_object($this->link)) { |
|
| 94 | 94 | $this->link->close(); |
| 95 | 95 | $this->connected = false; |
| 96 | 96 | unset($this->link); |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
| 127 | - * @param $query |
|
| 127 | + * @param string $query |
|
| 128 | 128 | * |
| 129 | 129 | * @return mixed |
| 130 | 130 | */ |
@@ -140,8 +140,8 @@ discard block |
||
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | /** |
| 143 | - * @param $query |
|
| 144 | - * @param $fetch |
|
| 143 | + * @param string $query |
|
| 144 | + * @param boolean $fetch |
|
| 145 | 145 | */ |
| 146 | 146 | public function logQuery($query, $fetch) { |
| 147 | 147 | if(!classSupernova::$config->debug) { |
@@ -204,6 +204,10 @@ discard block |
||
| 204 | 204 | |
| 205 | 205 | |
| 206 | 206 | // TODO Заменить это на новый логгер |
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * @param string $query |
|
| 210 | + */ |
|
| 207 | 211 | function security_watch_user_queries($query) { |
| 208 | 212 | global $user; |
| 209 | 213 | |
@@ -227,6 +231,9 @@ discard block |
||
| 227 | 231 | } |
| 228 | 232 | |
| 229 | 233 | |
| 234 | + /** |
|
| 235 | + * @param string $query |
|
| 236 | + */ |
|
| 230 | 237 | function security_query_check_bad_words($query) { |
| 231 | 238 | global $user, $dm_change_legit, $mm_change_legit; |
| 232 | 239 | |
@@ -73,23 +73,23 @@ discard block |
||
| 73 | 73 | function sn_db_connect($external_db_settings = null) { |
| 74 | 74 | $this->db_disconnect(); |
| 75 | 75 | |
| 76 | - if(!empty($external_db_settings) && is_array($external_db_settings)) { |
|
| 76 | + if (!empty($external_db_settings) && is_array($external_db_settings)) { |
|
| 77 | 77 | $this->dbsettings = $external_db_settings; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - if(empty($this->dbsettings)) { |
|
| 80 | + if (empty($this->dbsettings)) { |
|
| 81 | 81 | $this->load_db_settings(); |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | // TODO - фатальные (?) ошибки на каждом шагу. Хотя - скорее Эксепшны |
| 85 | - if(!empty($this->dbsettings)) { |
|
| 85 | + if (!empty($this->dbsettings)) { |
|
| 86 | 86 | $driver_name = empty($this->dbsettings['sn_driver']) ? 'db_mysql_v5' : $this->dbsettings['sn_driver']; |
| 87 | 87 | $this->driver = new $driver_name(); |
| 88 | 88 | $this->db_prefix = $this->dbsettings['prefix']; |
| 89 | 89 | |
| 90 | 90 | $this->connected = $this->connected || $this->driver_connect(); |
| 91 | 91 | |
| 92 | - if($this->connected) { |
|
| 92 | + if ($this->connected) { |
|
| 93 | 93 | $this->table_list = $this->db_get_table_list(); |
| 94 | 94 | // TODO Проверка на пустоту |
| 95 | 95 | } |
@@ -103,11 +103,11 @@ discard block |
||
| 103 | 103 | function driver_connect() { |
| 104 | 104 | global $debug; |
| 105 | 105 | |
| 106 | - if(!is_object($this->driver)) { |
|
| 106 | + if (!is_object($this->driver)) { |
|
| 107 | 107 | $debug->error_fatal('DB Error - No driver for MySQL found!'); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - if(!method_exists($this->driver, 'mysql_connect')) { |
|
| 110 | + if (!method_exists($this->driver, 'mysql_connect')) { |
|
| 111 | 111 | $debug->error_fatal('DB Error - WRONG MySQL driver!'); |
| 112 | 112 | } |
| 113 | 113 | |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | function db_disconnect() { |
| 118 | - if($this->connected) { |
|
| 118 | + if ($this->connected) { |
|
| 119 | 119 | $this->connected = !$this->driver_disconnect(); |
| 120 | 120 | $this->connected = false; |
| 121 | 121 | } |
@@ -130,8 +130,8 @@ discard block |
||
| 130 | 130 | */ |
| 131 | 131 | public function replaceTablePlaceholders($query) { |
| 132 | 132 | $sql = $query; |
| 133 | - if(strpos($sql, '{{') !== false) { |
|
| 134 | - foreach($this->table_list as $tableName) { |
|
| 133 | + if (strpos($sql, '{{') !== false) { |
|
| 134 | + foreach ($this->table_list as $tableName) { |
|
| 135 | 135 | $sql = str_replace("{{{$tableName}}}", $this->db_prefix . $tableName, $sql); |
| 136 | 136 | } |
| 137 | 137 | } |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * @param $fetch |
| 145 | 145 | */ |
| 146 | 146 | public function logQuery($query, $fetch) { |
| 147 | - if(!classSupernova::$config->debug) { |
|
| 147 | + if (!classSupernova::$config->debug) { |
|
| 148 | 148 | return; |
| 149 | 149 | } |
| 150 | 150 | |
@@ -162,18 +162,18 @@ discard block |
||
| 162 | 162 | * @return void |
| 163 | 163 | */ |
| 164 | 164 | public function commentQuery(&$sql) { |
| 165 | - if(!defined('DEBUG_SQL_COMMENT')) { |
|
| 165 | + if (!defined('DEBUG_SQL_COMMENT')) { |
|
| 166 | 166 | return; |
| 167 | 167 | } |
| 168 | 168 | $backtrace = debug_backtrace(); |
| 169 | 169 | $sql_comment = classSupernova::$debug->compact_backtrace($backtrace, defined('DEBUG_SQL_COMMENT_LONG')); |
| 170 | 170 | |
| 171 | 171 | $sql_commented = '/* ' . implode("<br />", $sql_comment) . '<br /> */ ' . preg_replace("/\s+/", ' ', $sql); |
| 172 | - if(defined('DEBUG_SQL_ONLINE')) { |
|
| 172 | + if (defined('DEBUG_SQL_ONLINE')) { |
|
| 173 | 173 | classSupernova::$debug->warning($sql_commented, 'SQL Debug', LOG_DEBUG_SQL); |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - if(defined('DEBUG_SQL_ERROR')) { |
|
| 176 | + if (defined('DEBUG_SQL_ERROR')) { |
|
| 177 | 177 | array_unshift($sql_comment, preg_replace("/\s+/", ' ', $sql)); |
| 178 | 178 | classSupernova::$debug->add_to_array($sql_comment); |
| 179 | 179 | } |
@@ -182,11 +182,11 @@ discard block |
||
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | public function doquery($query, $table = '', $fetch = false, $skip_query_check = false) { |
| 185 | - if(!is_string($table)) { |
|
| 185 | + if (!is_string($table)) { |
|
| 186 | 186 | $fetch = $table; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - if(!$this->connected) { |
|
| 189 | + if (!$this->connected) { |
|
| 190 | 190 | $this->sn_db_connect(); |
| 191 | 191 | } |
| 192 | 192 | |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | function security_watch_user_queries($query) { |
| 208 | 208 | global $user; |
| 209 | 209 | |
| 210 | - if( |
|
| 210 | + if ( |
|
| 211 | 211 | !$this->isWatching // Not already watching |
| 212 | 212 | && !empty(classSupernova::$config->game_watchlist_array) // There is some players in watchlist |
| 213 | 213 | && in_array($user['id'], classSupernova::$config->game_watchlist_array) // Current player is in watchlist |
@@ -215,10 +215,10 @@ discard block |
||
| 215 | 215 | ) { |
| 216 | 216 | $this->isWatching = true; |
| 217 | 217 | $msg = "\$query = \"{$query}\"\n\r"; |
| 218 | - if(!empty($_POST)) { |
|
| 218 | + if (!empty($_POST)) { |
|
| 219 | 219 | $msg .= "\n\r" . dump($_POST, '$_POST'); |
| 220 | 220 | } |
| 221 | - if(!empty($_GET)) { |
|
| 221 | + if (!empty($_GET)) { |
|
| 222 | 222 | $msg .= "\n\r" . dump($_GET, '$_GET'); |
| 223 | 223 | } |
| 224 | 224 | classSupernova::$debug->warning($msg, "Watching user {$user['id']}", 399, array('base_dump' => true)); |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | function security_query_check_bad_words($query) { |
| 231 | 231 | global $user, $dm_change_legit, $mm_change_legit; |
| 232 | 232 | |
| 233 | - switch(true) { |
|
| 233 | + switch (true) { |
|
| 234 | 234 | case stripos($query, 'RUNCATE TABL') != false: |
| 235 | 235 | case stripos($query, 'ROP TABL') != false: |
| 236 | 236 | case stripos($query, 'ENAME TABL') != false: |
@@ -292,11 +292,11 @@ discard block |
||
| 292 | 292 | $prefix_length = strlen($this->db_prefix); |
| 293 | 293 | |
| 294 | 294 | $tl = array(); |
| 295 | - while($row = $this->db_fetch($query)) { |
|
| 296 | - foreach($row as $table_name) { |
|
| 297 | - if(strpos($table_name, $this->db_prefix) === 0) { |
|
| 295 | + while ($row = $this->db_fetch($query)) { |
|
| 296 | + foreach ($row as $table_name) { |
|
| 297 | + if (strpos($table_name, $this->db_prefix) === 0) { |
|
| 298 | 298 | $table_name = substr($table_name, $prefix_length); |
| 299 | - } elseif($prefixed_only) { |
|
| 299 | + } elseif ($prefixed_only) { |
|
| 300 | 300 | continue; |
| 301 | 301 | } |
| 302 | 302 | // $table_name = str_replace($db_prefix, '', $table_name); |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | $result = array(); |
| 400 | 400 | |
| 401 | 401 | $status = explode(' ', $this->driver->mysql_stat()); |
| 402 | - foreach($status as $value) { |
|
| 402 | + foreach ($status as $value) { |
|
| 403 | 403 | $row = explode(': ', $value); |
| 404 | 404 | $result[$row[0]] = $row[1]; |
| 405 | 405 | } |
@@ -411,7 +411,7 @@ discard block |
||
| 411 | 411 | $result = array(); |
| 412 | 412 | |
| 413 | 413 | $query = doquery('SHOW STATUS;'); |
| 414 | - while($row = db_fetch($query)) { |
|
| 414 | + while ($row = db_fetch($query)) { |
|
| 415 | 415 | $result[$row['Variable_name']] = $row['Value']; |
| 416 | 416 | } |
| 417 | 417 | |
@@ -62,7 +62,7 @@ |
||
| 62 | 62 | /** |
| 63 | 63 | * Является ли запись пустой - т.е. при исполнении _dbSave должен быть удалён |
| 64 | 64 | * |
| 65 | - * @return bool |
|
| 65 | + * @return boolean|null |
|
| 66 | 66 | */ |
| 67 | 67 | public function isEmpty() { |
| 68 | 68 | // TODO: Implement isEmpty() method. |
@@ -2,19 +2,19 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | $classLocale = classLocale::$lang; |
| 4 | 4 | |
| 5 | -if(classSupernova::$config->server_updater_check_auto && classSupernova::$config->server_updater_check_last + classSupernova::$config->server_updater_check_period <= SN_TIME_NOW) { |
|
| 5 | +if (classSupernova::$config->server_updater_check_auto && classSupernova::$config->server_updater_check_last + classSupernova::$config->server_updater_check_period <= SN_TIME_NOW) { |
|
| 6 | 6 | include(SN_ROOT_PHYSICAL . 'ajax_version_check' . DOT_PHP_EX); |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | -if(classSupernova::$config->user_birthday_gift && SN_TIME_NOW - classSupernova::$config->user_birthday_celebrate > PERIOD_DAY) { |
|
| 9 | +if (classSupernova::$config->user_birthday_gift && SN_TIME_NOW - classSupernova::$config->user_birthday_celebrate > PERIOD_DAY) { |
|
| 10 | 10 | require_once(SN_ROOT_PHYSICAL . "includes/includes/user_birthday_celebrate" . DOT_PHP_EX); |
| 11 | 11 | sn_user_birthday_celebrate(); |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | -if(!classSupernova::$config->var_online_user_count || classSupernova::$config->var_online_user_time + 30 < SN_TIME_NOW) { |
|
| 14 | +if (!classSupernova::$config->var_online_user_count || classSupernova::$config->var_online_user_time + 30 < SN_TIME_NOW) { |
|
| 15 | 15 | classSupernova::$config->db_saveItem('var_online_user_count', db_user_count(true)); |
| 16 | 16 | classSupernova::$config->db_saveItem('var_online_user_time', SN_TIME_NOW); |
| 17 | - if(classSupernova::$config->server_log_online) { |
|
| 17 | + if (classSupernova::$config->server_log_online) { |
|
| 18 | 18 | db_log_online_insert(); |
| 19 | 19 | } |
| 20 | 20 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | $template_result[F_ACCOUNT_IS_AUTHORIZED] = $sys_user_logged_in = !empty($user) && isset($user['id']) && $user['id']; |
| 42 | 42 | //pdump($template_result[F_ACCOUNT_IS_AUTHORIZED]);die(); |
| 43 | 43 | |
| 44 | -if(!empty($user['id'])) { |
|
| 44 | +if (!empty($user['id'])) { |
|
| 45 | 45 | classSupernova::$user_options->user_change($user['id']); |
| 46 | 46 | } |
| 47 | 47 | |
@@ -54,15 +54,15 @@ discard block |
||
| 54 | 54 | : false |
| 55 | 55 | ); |
| 56 | 56 | |
| 57 | -if($template_result[F_LOGIN_STATUS] == LOGIN_ERROR_USERNAME_RESTRICTED_CHARACTERS) { |
|
| 58 | - $prohibited_characters = array_map(function ($value) { |
|
| 57 | +if ($template_result[F_LOGIN_STATUS] == LOGIN_ERROR_USERNAME_RESTRICTED_CHARACTERS) { |
|
| 58 | + $prohibited_characters = array_map(function($value) { |
|
| 59 | 59 | return "'" . htmlentities($value, ENT_QUOTES, 'UTF-8') . "'"; |
| 60 | 60 | }, str_split(LOGIN_REGISTER_CHARACTERS_PROHIBITED)); |
| 61 | 61 | $template_result[F_LOGIN_MESSAGE] .= implode(', ', $prohibited_characters); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | |
| 65 | -if(defined('DEBUG_AUTH') && DEBUG_AUTH && !defined('IN_AJAX')) { |
|
| 65 | +if (defined('DEBUG_AUTH') && DEBUG_AUTH && !defined('IN_AJAX')) { |
|
| 66 | 66 | pdump("Отключи отладку перед продакшном!"); |
| 67 | 67 | } |
| 68 | 68 | |
@@ -76,17 +76,17 @@ discard block |
||
| 76 | 76 | ? define('INSTALL_MODE', GAME_DISABLE_INSTALL) |
| 77 | 77 | : false; |
| 78 | 78 | |
| 79 | -if($template_result[F_GAME_DISABLE] = classSupernova::$config->game_disable) { |
|
| 79 | +if ($template_result[F_GAME_DISABLE] = classSupernova::$config->game_disable) { |
|
| 80 | 80 | $template_result[F_GAME_DISABLE_REASON] = sys_bbcodeParse( |
| 81 | 81 | classSupernova::$config->game_disable == GAME_DISABLE_REASON |
| 82 | 82 | ? classSupernova::$config->game_disable_reason |
| 83 | 83 | : classLocale::$lang['sys_game_disable_reason'][classSupernova::$config->game_disable] |
| 84 | 84 | ); |
| 85 | - if(defined('IN_API')) { |
|
| 85 | + if (defined('IN_API')) { |
|
| 86 | 86 | return; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - if( |
|
| 89 | + if ( |
|
| 90 | 90 | ($user['authlevel'] < 1 || !(defined('IN_ADMIN') && IN_ADMIN)) |
| 91 | 91 | && |
| 92 | 92 | !(defined('INSTALL_MODE') && defined('LOGIN_LOGOUT')) |
@@ -100,8 +100,8 @@ discard block |
||
| 100 | 100 | |
| 101 | 101 | // TODO ban |
| 102 | 102 | // TODO $skip_ban_check |
| 103 | -if($template_result[F_BANNED_STATUS] && !$skip_ban_check) { |
|
| 104 | - if(defined('IN_API')) { |
|
| 103 | +if ($template_result[F_BANNED_STATUS] && !$skip_ban_check) { |
|
| 104 | + if (defined('IN_API')) { |
|
| 105 | 105 | return; |
| 106 | 106 | } |
| 107 | 107 | |
@@ -119,13 +119,13 @@ discard block |
||
| 119 | 119 | // pdump($allow_anonymous, '$allow_anonymous'); |
| 120 | 120 | // pdump($sys_user_logged_in, '$sys_user_logged_in'); |
| 121 | 121 | |
| 122 | -if($sys_user_logged_in && INITIAL_PAGE == 'login') { |
|
| 122 | +if ($sys_user_logged_in && INITIAL_PAGE == 'login') { |
|
| 123 | 123 | sys_redirect(SN_ROOT_VIRTUAL . 'overview.php'); |
| 124 | -} elseif($account_logged_in && !$sys_user_logged_in) { // empty(core_auth::$user['id']) |
|
| 124 | +} elseif ($account_logged_in && !$sys_user_logged_in) { // empty(core_auth::$user['id']) |
|
| 125 | 125 | // pdump($sn_page_name); |
| 126 | 126 | // pdump(INITIAL_PAGE); |
| 127 | 127 | // die('{Тут должна быть ваша реклама. Точнее - ввод имени игрока}'); |
| 128 | -} elseif(!$allow_anonymous && !$sys_user_logged_in) { |
|
| 128 | +} elseif (!$allow_anonymous && !$sys_user_logged_in) { |
|
| 129 | 129 | // sn_setcookie(SN_COOKIE, '', time() - PERIOD_WEEK, SN_ROOT_RELATIVE); |
| 130 | 130 | sys_redirect(SN_ROOT_VIRTUAL . 'login.php'); |
| 131 | 131 | } |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | |
| 147 | 147 | global $skip_fleet_update; |
| 148 | 148 | $skip_fleet_update = $skip_fleet_update || $supernova->options['fleet_update_skip'] || defined('IN_ADMIN'); |
| 149 | -if( |
|
| 149 | +if ( |
|
| 150 | 150 | !$skip_fleet_update |
| 151 | 151 | && !(defined('IN_AJAX') && IN_AJAX === true) |
| 152 | 152 | && SN_TIME_NOW - strtotime(classSupernova::$config->fleet_update_last) > classSupernova::$config->fleet_update_interval |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | flt_flying_fleet_handler($skip_fleet_update); |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | -if(!defined('IN_AJAX')) { |
|
| 158 | +if (!defined('IN_AJAX')) { |
|
| 159 | 159 | print("Scheduled processes is disabled<br />"); |
| 160 | 160 | } |
| 161 | 161 | // scheduler_process(); |
@@ -138,14 +138,14 @@ discard block |
||
| 138 | 138 | |
| 139 | 139 | // If method is not getter or setter OR property name not exists in $_properties - raising exception |
| 140 | 140 | // Descendants can catch this Exception to make own __call magic |
| 141 | - if(($left3 != 'get' && $left3 != 'set') || empty(static::$_properties[$propertyName])) { |
|
| 141 | + if (($left3 != 'get' && $left3 != 'set') || empty(static::$_properties[$propertyName])) { |
|
| 142 | 142 | throw new ExceptionPropertyNotExists('Property ' . $propertyName . ' not exists when calling getter/setter ' . get_called_class() . '::' . $name, ERR_ERROR); |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | // TODO check for read-only |
| 146 | 146 | |
| 147 | - if($left3 == 'set') { |
|
| 148 | - if(!empty($this->propertiesAdjusted[$propertyName])) { |
|
| 147 | + if ($left3 == 'set') { |
|
| 148 | + if (!empty($this->propertiesAdjusted[$propertyName])) { |
|
| 149 | 149 | throw new PropertyAccessException('Property ' . $propertyName . ' already was adjusted so no SET is possible until dbSave in ' . get_called_class() . '::' . $name, ERR_ERROR); |
| 150 | 150 | } |
| 151 | 151 | $this->propertiesChanged[$propertyName] = 1; |
@@ -154,13 +154,13 @@ discard block |
||
| 154 | 154 | // Now deciding - will we call a protected setter or will we work with protected property |
| 155 | 155 | |
| 156 | 156 | // If method exists - just calling it |
| 157 | - if(method_exists($this, $name)) { |
|
| 157 | + if (method_exists($this, $name)) { |
|
| 158 | 158 | return call_user_func_array(array($this, $name), $arguments); |
| 159 | 159 | } |
| 160 | 160 | // No getter/setter exists - works directly with protected property |
| 161 | 161 | |
| 162 | 162 | // Is it getter? |
| 163 | - if($left3 === 'get') { |
|
| 163 | + if ($left3 === 'get') { |
|
| 164 | 164 | return $this->{'_' . $propertyName}; |
| 165 | 165 | } |
| 166 | 166 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | */ |
| 183 | 183 | public function dbLoad($dbId, $lockSkip = false) { |
| 184 | 184 | $dbId = idval($dbId); |
| 185 | - if($dbId <= 0) { |
|
| 185 | + if ($dbId <= 0) { |
|
| 186 | 186 | classSupernova::$debug->error(get_called_class() . '::dbLoad $dbId not positive = ' . $dbId); |
| 187 | 187 | |
| 188 | 188 | return; |
@@ -191,12 +191,12 @@ discard block |
||
| 191 | 191 | $this->_dbId = $dbId; |
| 192 | 192 | $this->lockSkip = $lockSkip; |
| 193 | 193 | // TODO - Use classSupernova::$db_records_locked |
| 194 | - if(false && !$lockSkip && sn_db_transaction_check(false)) { |
|
| 194 | + if (false && !$lockSkip && sn_db_transaction_check(false)) { |
|
| 195 | 195 | $this->dbGetLockById($this->_dbId); |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | $db_row = doquery("SELECT * FROM `{{" . static::$_table . "}}` WHERE `" . static::$_dbIdFieldName . "` = " . $this->_dbId . " LIMIT 1 FOR UPDATE;", true); |
| 199 | - if(empty($db_row)) { |
|
| 199 | + if (empty($db_row)) { |
|
| 200 | 200 | return; |
| 201 | 201 | } |
| 202 | 202 | |
@@ -224,26 +224,26 @@ discard block |
||
| 224 | 224 | */ |
| 225 | 225 | // TODO - perform operations only if properties was changed |
| 226 | 226 | public function dbSave() { |
| 227 | - if($this->isNew()) { |
|
| 227 | + if ($this->isNew()) { |
|
| 228 | 228 | // No DB_ID - new unit |
| 229 | - if($this->isEmpty()) { |
|
| 229 | + if ($this->isEmpty()) { |
|
| 230 | 230 | classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - object is empty on ' . get_called_class() . '::dbSave'); |
| 231 | 231 | } |
| 232 | 232 | $this->dbInsert(); |
| 233 | 233 | } else { |
| 234 | 234 | // DB_ID is present |
| 235 | - if($this->isEmpty()) { |
|
| 235 | + if ($this->isEmpty()) { |
|
| 236 | 236 | $this->dbDelete(); |
| 237 | 237 | } else { |
| 238 | - if(!sn_db_transaction_check(false)) { |
|
| 238 | + if (!sn_db_transaction_check(false)) { |
|
| 239 | 239 | classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - transaction should always be started on ' . get_called_class() . '::dbUpdate'); |
| 240 | 240 | } |
| 241 | 241 | $this->dbUpdate(); |
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | - if(!empty($this->triggerDbOperationOn)) { |
|
| 246 | - foreach($this->triggerDbOperationOn as $item) { |
|
| 245 | + if (!empty($this->triggerDbOperationOn)) { |
|
| 246 | + foreach ($this->triggerDbOperationOn as $item) { |
|
| 247 | 247 | $item->dbSave(); |
| 248 | 248 | } |
| 249 | 249 | } |
@@ -263,12 +263,12 @@ discard block |
||
| 263 | 263 | */ |
| 264 | 264 | // TODO - protected |
| 265 | 265 | public function dbInsert() { |
| 266 | - if(!$this->isNew()) { |
|
| 266 | + if (!$this->isNew()) { |
|
| 267 | 267 | classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - record db_id is not empty on ' . get_called_class() . '::dbInsert'); |
| 268 | 268 | } |
| 269 | 269 | $this->_dbId = $this->db_field_set_create($this->dbMakeFieldSet()); |
| 270 | 270 | |
| 271 | - if(empty($this->_dbId)) { |
|
| 271 | + if (empty($this->_dbId)) { |
|
| 272 | 272 | classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - error saving record ' . get_called_class() . '::dbInsert'); |
| 273 | 273 | } |
| 274 | 274 | |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | // TODO - protected |
| 282 | 282 | public function dbUpdate() { |
| 283 | 283 | // TODO - Update |
| 284 | - if($this->isNew()) { |
|
| 284 | + if ($this->isNew()) { |
|
| 285 | 285 | classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - unit db_id is empty on dbUpdate'); |
| 286 | 286 | } |
| 287 | 287 | $this->db_field_update($this->dbMakeFieldSet(true)); |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | */ |
| 293 | 293 | // TODO - protected |
| 294 | 294 | public function dbDelete() { |
| 295 | - if($this->isNew()) { |
|
| 295 | + if ($this->isNew()) { |
|
| 296 | 296 | classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - unit db_id is empty on dbDelete'); |
| 297 | 297 | } |
| 298 | 298 | doquery("DELETE FROM {{" . static::$_table . "}} WHERE `" . static::$_dbIdFieldName . "` = " . $this->_dbId); |
@@ -334,18 +334,18 @@ discard block |
||
| 334 | 334 | * @param array $db_row |
| 335 | 335 | */ |
| 336 | 336 | public function dbRowParse(array $db_row) { |
| 337 | - foreach(static::$_properties as $property_name => &$property_data) { |
|
| 337 | + foreach (static::$_properties as $property_name => &$property_data) { |
|
| 338 | 338 | // Advanced values extraction procedure. Should be used when at least one of following rules is matched: |
| 339 | 339 | // - one field should translate to several properties; |
| 340 | 340 | // - one property should be filled according to several fields; |
| 341 | 341 | // - property filling requires some lookup in object values; |
| 342 | - if(!empty($property_data[P_METHOD_EXTRACT]) && is_callable(array($this, $property_data[P_METHOD_EXTRACT]))) { |
|
| 342 | + if (!empty($property_data[P_METHOD_EXTRACT]) && is_callable(array($this, $property_data[P_METHOD_EXTRACT]))) { |
|
| 343 | 343 | call_user_func_array(array($this, $property_data[P_METHOD_EXTRACT]), array(&$db_row)); |
| 344 | 344 | continue; |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | // If property is read-only - doing nothing |
| 348 | - if(!empty($property_data[P_READ_ONLY])) { |
|
| 348 | + if (!empty($property_data[P_READ_ONLY])) { |
|
| 349 | 349 | continue; |
| 350 | 350 | } |
| 351 | 351 | |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | !empty($property_data[P_FUNC_INPUT]) && is_callable($property_data[P_FUNC_INPUT]) ? $value = call_user_func($property_data[P_FUNC_INPUT], $value) : false; |
| 357 | 357 | |
| 358 | 358 | // If there is setter for this field - using it. Setters is always a methods of $THIS |
| 359 | - if(!empty($property_data[P_METHOD_SET]) && is_callable(array($this, $property_data[P_METHOD_SET]))) { |
|
| 359 | + if (!empty($property_data[P_METHOD_SET]) && is_callable(array($this, $property_data[P_METHOD_SET]))) { |
|
| 360 | 360 | call_user_func(array($this, $property_data[P_METHOD_SET]), $value); |
| 361 | 361 | } else { |
| 362 | 362 | $this->{$property_name} = $value; |
@@ -372,21 +372,21 @@ discard block |
||
| 372 | 372 | protected function dbMakeFieldSet($isUpdate = false) { |
| 373 | 373 | $array = array(); |
| 374 | 374 | |
| 375 | - foreach(static::$_properties as $property_name => &$property_data) { |
|
| 375 | + foreach (static::$_properties as $property_name => &$property_data) { |
|
| 376 | 376 | // TODO - on isUpdate add only changed/adjusted properties |
| 377 | 377 | |
| 378 | - if(!empty($property_data[P_METHOD_INJECT]) && is_callable(array($this, $property_data[P_METHOD_INJECT]))) { |
|
| 378 | + if (!empty($property_data[P_METHOD_INJECT]) && is_callable(array($this, $property_data[P_METHOD_INJECT]))) { |
|
| 379 | 379 | call_user_func_array(array($this, $property_data[P_METHOD_INJECT]), array(&$array)); |
| 380 | 380 | continue; |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | // Skipping properties which have no corresponding field in DB |
| 384 | - if(empty($property_data[P_DB_FIELD])) { |
|
| 384 | + if (empty($property_data[P_DB_FIELD])) { |
|
| 385 | 385 | continue; |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | // Checking - is property was adjusted or changed |
| 389 | - if($isUpdate && array_key_exists($property_name, $this->propertiesAdjusted)) { |
|
| 389 | + if ($isUpdate && array_key_exists($property_name, $this->propertiesAdjusted)) { |
|
| 390 | 390 | // For adjusted property - take value from propertiesAdjusted array |
| 391 | 391 | // TODO - differ how treated conversion to string for changed and adjusted properties |
| 392 | 392 | $value = $this->propertiesAdjusted[$property_name]; |
@@ -416,17 +416,17 @@ discard block |
||
| 416 | 416 | */ |
| 417 | 417 | protected function isFieldChanged($fieldName) { |
| 418 | 418 | $isFieldChanged = false; |
| 419 | - foreach($this->propertiesChanged as $propertyName => $cork) { |
|
| 419 | + foreach ($this->propertiesChanged as $propertyName => $cork) { |
|
| 420 | 420 | $propertyScheme = static::$_properties[$propertyName]; |
| 421 | - if(!empty($propertyScheme[P_DB_FIELDS_LINKED])) { |
|
| 422 | - foreach($propertyScheme[P_DB_FIELDS_LINKED] as $linkedFieldName) { |
|
| 423 | - if($linkedFieldName == $fieldName) { |
|
| 421 | + if (!empty($propertyScheme[P_DB_FIELDS_LINKED])) { |
|
| 422 | + foreach ($propertyScheme[P_DB_FIELDS_LINKED] as $linkedFieldName) { |
|
| 423 | + if ($linkedFieldName == $fieldName) { |
|
| 424 | 424 | $isFieldChanged = $propertyName; |
| 425 | 425 | break 2; |
| 426 | 426 | } |
| 427 | 427 | } |
| 428 | 428 | } |
| 429 | - if(!empty($propertyScheme[P_DB_FIELD]) && $propertyScheme[P_DB_FIELD] == $fieldName) { |
|
| 429 | + if (!empty($propertyScheme[P_DB_FIELD]) && $propertyScheme[P_DB_FIELD] == $fieldName) { |
|
| 430 | 430 | $isFieldChanged = $propertyName; |
| 431 | 431 | break; |
| 432 | 432 | } |
@@ -448,7 +448,7 @@ discard block |
||
| 448 | 448 | $fields = implode(',', array_keys($field_set)); |
| 449 | 449 | |
| 450 | 450 | $result = 0; |
| 451 | - if(classSupernova::db_query("INSERT INTO `{{" . static::$_table . "}}` ({$fields}) VALUES ({$values});")) { |
|
| 451 | + if (classSupernova::db_query("INSERT INTO `{{" . static::$_table . "}}` ({$fields}) VALUES ({$values});")) { |
|
| 452 | 452 | $result = db_insert_id(); |
| 453 | 453 | } |
| 454 | 454 | |
@@ -466,13 +466,13 @@ discard block |
||
| 466 | 466 | sn_db_field_set_safe_flag_clear($field_set); |
| 467 | 467 | |
| 468 | 468 | $set = array(); |
| 469 | - foreach($field_set as $fieldName => $value) { |
|
| 470 | - if(!($changedProperty = $this->isFieldChanged($fieldName))) { |
|
| 469 | + foreach ($field_set as $fieldName => $value) { |
|
| 470 | + if (!($changedProperty = $this->isFieldChanged($fieldName))) { |
|
| 471 | 471 | continue; |
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | // TODO - separate sets from adjusts |
| 475 | - if(array_key_exists($changedProperty, $this->propertiesAdjusted)) { |
|
| 475 | + if (array_key_exists($changedProperty, $this->propertiesAdjusted)) { |
|
| 476 | 476 | $value = "`{$fieldName}` + ($value)"; // braces for negative values |
| 477 | 477 | } |
| 478 | 478 | |
@@ -34,69 +34,69 @@ |
||
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | switch($mode) { |
| 37 | - case ADM_TOOL_CONFIG_RELOAD: |
|
| 38 | - classSupernova::$config->db_loadAll(); |
|
| 39 | - sys_refresh_tablelist(); |
|
| 40 | - |
|
| 41 | - classSupernova::$config->db_loadItem('game_watchlist'); |
|
| 42 | - if(classSupernova::$config->game_watchlist) { |
|
| 43 | - classSupernova::$config->game_watchlist_array = explode(';', classSupernova::$config->game_watchlist); |
|
| 44 | - } else { |
|
| 45 | - unset(classSupernova::$config->game_watchlist_array); |
|
| 46 | - } |
|
| 47 | - break; |
|
| 48 | - |
|
| 49 | - case ADM_TOOL_MD5: |
|
| 50 | - $template = gettemplate("admin/md5enc", true); |
|
| 51 | - $password_seed = sys_get_param_str_unsafe('seed', SN_SYS_SEC_CHARS_ALLOWED); |
|
| 52 | - $password_length = sys_get_param_int('length', 16); |
|
| 53 | - $string = ($string = sys_get_param_str_unsafe('string')) ? $string : sys_random_string($password_length, $password_seed); |
|
| 54 | - |
|
| 55 | - $template->assign_vars(array( |
|
| 56 | - 'SEED' => $password_seed, |
|
| 57 | - 'LENGTH' => $password_length, |
|
| 58 | - 'STRING' => htmlentities($string), |
|
| 59 | - 'MD5' => md5($string), |
|
| 60 | - )); |
|
| 61 | - display($template, classLocale::$lang['adm_tools_md5_header'], false, '', true); |
|
| 62 | - break; |
|
| 63 | - |
|
| 64 | - case ADM_TOOL_FORCE_ALL: |
|
| 65 | - classSupernova::$config->db_saveItem('db_version', 0); |
|
| 66 | - require_once('../includes/update.php'); |
|
| 67 | - break; |
|
| 68 | - |
|
| 69 | - case ADM_TOOL_FORCE_LAST: |
|
| 70 | - classSupernova::$config->db_saveItem('db_version', floor(classSupernova::$config->db_version - 1)); |
|
| 71 | - require_once('../includes/update.php'); |
|
| 72 | - break; |
|
| 73 | - |
|
| 74 | - case ADM_TOOL_INFO_PHP: |
|
| 75 | - phpinfo(); |
|
| 76 | - break; |
|
| 77 | - |
|
| 78 | - case ADM_TOOL_INFO_SQL: |
|
| 79 | - $template = gettemplate("simple_table", true); |
|
| 80 | - |
|
| 81 | - $status = array( |
|
| 82 | - classLocale::$lang['adm_tool_sql_server_version'] => classSupernova::$db->db_get_server_info(), |
|
| 83 | - classLocale::$lang['adm_tool_sql_client_version'] => classSupernova::$db->db_get_client_info(), |
|
| 84 | - classLocale::$lang['adm_tool_sql_host_info'] => classSupernova::$db->db_get_host_info(), |
|
| 85 | - ); |
|
| 86 | - templateAssignTable($template, 'server', $status); |
|
| 87 | - |
|
| 88 | - templateAssignTable($template, 'status', classSupernova::$db->db_get_server_stat()); |
|
| 89 | - templateAssignTable($template, 'params', classSupernova::$db->db_core_show_status()); |
|
| 90 | - |
|
| 91 | - $template->assign_vars(array( |
|
| 92 | - 'PAGE_HEADER' => classLocale::$lang['adm_tool_sql_page_header'], |
|
| 93 | - 'COLUMN_NAME_1' => classLocale::$lang['adm_tool_sql_param_name'], |
|
| 94 | - 'COLUMN_NAME_2' => classLocale::$lang['adm_tool_sql_param_value'], |
|
| 95 | - 'TABLE_FOOTER' => 'test', |
|
| 96 | - )); |
|
| 97 | - |
|
| 98 | - display($template, classLocale::$lang['adm_bn_ttle'], false, '', true); |
|
| 99 | - break; |
|
| 37 | + case ADM_TOOL_CONFIG_RELOAD: |
|
| 38 | + classSupernova::$config->db_loadAll(); |
|
| 39 | + sys_refresh_tablelist(); |
|
| 40 | + |
|
| 41 | + classSupernova::$config->db_loadItem('game_watchlist'); |
|
| 42 | + if(classSupernova::$config->game_watchlist) { |
|
| 43 | + classSupernova::$config->game_watchlist_array = explode(';', classSupernova::$config->game_watchlist); |
|
| 44 | + } else { |
|
| 45 | + unset(classSupernova::$config->game_watchlist_array); |
|
| 46 | + } |
|
| 47 | + break; |
|
| 48 | + |
|
| 49 | + case ADM_TOOL_MD5: |
|
| 50 | + $template = gettemplate("admin/md5enc", true); |
|
| 51 | + $password_seed = sys_get_param_str_unsafe('seed', SN_SYS_SEC_CHARS_ALLOWED); |
|
| 52 | + $password_length = sys_get_param_int('length', 16); |
|
| 53 | + $string = ($string = sys_get_param_str_unsafe('string')) ? $string : sys_random_string($password_length, $password_seed); |
|
| 54 | + |
|
| 55 | + $template->assign_vars(array( |
|
| 56 | + 'SEED' => $password_seed, |
|
| 57 | + 'LENGTH' => $password_length, |
|
| 58 | + 'STRING' => htmlentities($string), |
|
| 59 | + 'MD5' => md5($string), |
|
| 60 | + )); |
|
| 61 | + display($template, classLocale::$lang['adm_tools_md5_header'], false, '', true); |
|
| 62 | + break; |
|
| 63 | + |
|
| 64 | + case ADM_TOOL_FORCE_ALL: |
|
| 65 | + classSupernova::$config->db_saveItem('db_version', 0); |
|
| 66 | + require_once('../includes/update.php'); |
|
| 67 | + break; |
|
| 68 | + |
|
| 69 | + case ADM_TOOL_FORCE_LAST: |
|
| 70 | + classSupernova::$config->db_saveItem('db_version', floor(classSupernova::$config->db_version - 1)); |
|
| 71 | + require_once('../includes/update.php'); |
|
| 72 | + break; |
|
| 73 | + |
|
| 74 | + case ADM_TOOL_INFO_PHP: |
|
| 75 | + phpinfo(); |
|
| 76 | + break; |
|
| 77 | + |
|
| 78 | + case ADM_TOOL_INFO_SQL: |
|
| 79 | + $template = gettemplate("simple_table", true); |
|
| 80 | + |
|
| 81 | + $status = array( |
|
| 82 | + classLocale::$lang['adm_tool_sql_server_version'] => classSupernova::$db->db_get_server_info(), |
|
| 83 | + classLocale::$lang['adm_tool_sql_client_version'] => classSupernova::$db->db_get_client_info(), |
|
| 84 | + classLocale::$lang['adm_tool_sql_host_info'] => classSupernova::$db->db_get_host_info(), |
|
| 85 | + ); |
|
| 86 | + templateAssignTable($template, 'server', $status); |
|
| 87 | + |
|
| 88 | + templateAssignTable($template, 'status', classSupernova::$db->db_get_server_stat()); |
|
| 89 | + templateAssignTable($template, 'params', classSupernova::$db->db_core_show_status()); |
|
| 90 | + |
|
| 91 | + $template->assign_vars(array( |
|
| 92 | + 'PAGE_HEADER' => classLocale::$lang['adm_tool_sql_page_header'], |
|
| 93 | + 'COLUMN_NAME_1' => classLocale::$lang['adm_tool_sql_param_name'], |
|
| 94 | + 'COLUMN_NAME_2' => classLocale::$lang['adm_tool_sql_param_value'], |
|
| 95 | + 'TABLE_FOOTER' => 'test', |
|
| 96 | + )); |
|
| 97 | + |
|
| 98 | + display($template, classLocale::$lang['adm_bn_ttle'], false, '', true); |
|
| 99 | + break; |
|
| 100 | 100 | |
| 101 | 101 | } |
| 102 | 102 | |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | require('../common.' . substr(strrchr(__FILE__, '.'), 1)); |
| 13 | 13 | |
| 14 | 14 | // if($user['authlevel'] < 1) |
| 15 | -if($user['authlevel'] < 3) { |
|
| 15 | +if ($user['authlevel'] < 3) { |
|
| 16 | 16 | AdminMessage(classLocale::$lang['adm_err_denied']); |
| 17 | 17 | } |
| 18 | 18 | |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | function templateAssignTable($template, $str, $status) { |
| 27 | 27 | $template->assign_block_vars('table', classLocale::$lang['adm_tool_sql_table'][$str]); |
| 28 | - foreach($status as $key => $value) { |
|
| 28 | + foreach ($status as $key => $value) { |
|
| 29 | 29 | $template->assign_block_vars('table.row', array( |
| 30 | 30 | 'VALUE_1' => $key, |
| 31 | 31 | 'VALUE_2' => $value, |
@@ -33,13 +33,13 @@ discard block |
||
| 33 | 33 | } |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | -switch($mode) { |
|
| 36 | +switch ($mode) { |
|
| 37 | 37 | case ADM_TOOL_CONFIG_RELOAD: |
| 38 | 38 | classSupernova::$config->db_loadAll(); |
| 39 | 39 | sys_refresh_tablelist(); |
| 40 | 40 | |
| 41 | 41 | classSupernova::$config->db_loadItem('game_watchlist'); |
| 42 | - if(classSupernova::$config->game_watchlist) { |
|
| 42 | + if (classSupernova::$config->game_watchlist) { |
|
| 43 | 43 | classSupernova::$config->game_watchlist_array = explode(';', classSupernova::$config->game_watchlist); |
| 44 | 44 | } else { |
| 45 | 45 | unset(classSupernova::$config->game_watchlist_array); |