@@ -64,23 +64,23 @@ discard block |
||
64 | 64 | function sn_db_connect($external_db_settings = null) { |
65 | 65 | $this->db_disconnect(); |
66 | 66 | |
67 | - if(!empty($external_db_settings) && is_array($external_db_settings)) { |
|
67 | + if (!empty($external_db_settings) && is_array($external_db_settings)) { |
|
68 | 68 | $this->dbsettings = $external_db_settings; |
69 | 69 | } |
70 | 70 | |
71 | - if(empty($this->dbsettings)) { |
|
71 | + if (empty($this->dbsettings)) { |
|
72 | 72 | $this->load_db_settings(); |
73 | 73 | } |
74 | 74 | |
75 | 75 | // TODO - фатальные (?) ошибки на каждом шагу. Хотя - скорее Эксепшны |
76 | - if(!empty($this->dbsettings)) { |
|
76 | + if (!empty($this->dbsettings)) { |
|
77 | 77 | $driver_name = empty($this->dbsettings['sn_driver']) ? 'db_mysql_v5' : $this->dbsettings['sn_driver']; |
78 | 78 | $this->driver = new $driver_name(); |
79 | 79 | $this->db_prefix = $this->dbsettings['prefix']; |
80 | 80 | |
81 | 81 | $this->connected = $this->connected || $this->driver_connect(); |
82 | 82 | |
83 | - if($this->connected) { |
|
83 | + if ($this->connected) { |
|
84 | 84 | $this->table_list = $this->db_get_table_list(); |
85 | 85 | // TODO Проверка на пустоту |
86 | 86 | } |
@@ -94,11 +94,11 @@ discard block |
||
94 | 94 | function driver_connect() { |
95 | 95 | global $debug; |
96 | 96 | |
97 | - if(!is_object($this->driver)) { |
|
97 | + if (!is_object($this->driver)) { |
|
98 | 98 | $debug->error_fatal('DB Error - No driver for MySQL found!'); |
99 | 99 | } |
100 | 100 | |
101 | - if(!method_exists($this->driver, 'mysql_connect')) { |
|
101 | + if (!method_exists($this->driver, 'mysql_connect')) { |
|
102 | 102 | $debug->error_fatal('DB Error - WRONG MySQL driver!'); |
103 | 103 | } |
104 | 104 | |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | } |
107 | 107 | |
108 | 108 | function db_disconnect() { |
109 | - if($this->connected) { |
|
109 | + if ($this->connected) { |
|
110 | 110 | $this->connected = !$this->driver_disconnect(); |
111 | 111 | $this->connected = false; |
112 | 112 | } |
@@ -117,11 +117,11 @@ discard block |
||
117 | 117 | function doquery($query, $table = '', $fetch = false, $skip_query_check = false) { |
118 | 118 | global $numqueries, $debug; |
119 | 119 | |
120 | - if(!is_string($table)) { |
|
120 | + if (!is_string($table)) { |
|
121 | 121 | $fetch = $table; |
122 | 122 | } |
123 | 123 | |
124 | - if(!$this->connected) { |
|
124 | + if (!$this->connected) { |
|
125 | 125 | $this->sn_db_connect(); |
126 | 126 | } |
127 | 127 | |
@@ -130,13 +130,13 @@ discard block |
||
130 | 130 | !$skip_query_check ? $this->security_query_check_bad_words($query) : false; |
131 | 131 | |
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 | } |
138 | 138 | |
139 | - if(classSupernova::$config->debug) { |
|
139 | + if (classSupernova::$config->debug) { |
|
140 | 140 | $numqueries++; |
141 | 141 | $arr = debug_backtrace(); |
142 | 142 | $file = end(explode('/', $arr[0]['file'])); |
@@ -144,16 +144,16 @@ discard block |
||
144 | 144 | $debug->add("<tr><th>Query $numqueries: </th><th>$query</th><th>$file($line)</th><th>$table</th><th>$fetch</th></tr>"); |
145 | 145 | } |
146 | 146 | |
147 | - if(defined('DEBUG_SQL_COMMENT')) { |
|
147 | + if (defined('DEBUG_SQL_COMMENT')) { |
|
148 | 148 | $backtrace = debug_backtrace(); |
149 | 149 | $sql_comment = $debug->compact_backtrace($backtrace, defined('DEBUG_SQL_COMMENT_LONG')); |
150 | 150 | |
151 | 151 | $sql_commented = '/* ' . implode("<br />", $sql_comment) . '<br /> */ ' . preg_replace("/\s+/", ' ', $sql); |
152 | - if(defined('DEBUG_SQL_ONLINE')) { |
|
152 | + if (defined('DEBUG_SQL_ONLINE')) { |
|
153 | 153 | $debug->warning($sql_commented, 'SQL Debug', LOG_DEBUG_SQL); |
154 | 154 | } |
155 | 155 | |
156 | - if(defined('DEBUG_SQL_ERROR')) { |
|
156 | + if (defined('DEBUG_SQL_ERROR')) { |
|
157 | 157 | array_unshift($sql_comment, preg_replace("/\s+/", ' ', $sql)); |
158 | 158 | $debug->add_to_array($sql_comment); |
159 | 159 | // $debug->add_to_array($sql_comment . preg_replace("/\s+/", ' ', $sql)); |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | // TODO Заменить это на новый логгер |
172 | 172 | global $is_watching, $user, $debug; |
173 | 173 | |
174 | - if( |
|
174 | + if ( |
|
175 | 175 | !$is_watching // Not already watching |
176 | 176 | && !empty(classSupernova::$config->game_watchlist_array) // There is some players in watchlist |
177 | 177 | && in_array($user['id'], classSupernova::$config->game_watchlist_array) // Current player is in watchlist |
@@ -179,10 +179,10 @@ discard block |
||
179 | 179 | ) { |
180 | 180 | $is_watching = true; |
181 | 181 | $msg = "\$query = \"{$query}\"\n\r"; |
182 | - if(!empty($_POST)) { |
|
182 | + if (!empty($_POST)) { |
|
183 | 183 | $msg .= "\n\r" . dump($_POST, '$_POST'); |
184 | 184 | } |
185 | - if(!empty($_GET)) { |
|
185 | + if (!empty($_GET)) { |
|
186 | 186 | $msg .= "\n\r" . dump($_GET, '$_GET'); |
187 | 187 | } |
188 | 188 | $debug->warning($msg, "Watching user {$user['id']}", 399, array('base_dump' => true)); |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | function security_query_check_bad_words($query) { |
195 | 195 | global $user, $dm_change_legit, $mm_change_legit; |
196 | 196 | |
197 | - switch(true) { |
|
197 | + switch (true) { |
|
198 | 198 | case stripos($query, 'RUNCATE TABL') != false: |
199 | 199 | case stripos($query, 'ROP TABL') != false: |
200 | 200 | case stripos($query, 'ENAME TABL') != false: |
@@ -256,11 +256,11 @@ discard block |
||
256 | 256 | $prefix_length = strlen($this->db_prefix); |
257 | 257 | |
258 | 258 | $tl = array(); |
259 | - while($row = $this->db_fetch($query)) { |
|
260 | - foreach($row as $table_name) { |
|
261 | - if(strpos($table_name, $this->db_prefix) === 0) { |
|
259 | + while ($row = $this->db_fetch($query)) { |
|
260 | + foreach ($row as $table_name) { |
|
261 | + if (strpos($table_name, $this->db_prefix) === 0) { |
|
262 | 262 | $table_name = substr($table_name, $prefix_length); |
263 | - } elseif($prefixed_only) { |
|
263 | + } elseif ($prefixed_only) { |
|
264 | 264 | continue; |
265 | 265 | } |
266 | 266 | // $table_name = str_replace($db_prefix, '', $table_name); |