Completed
Push — work-fleets ( b4179a...b8fd67 )
by SuperNova.WS
05:25
created
includes/classes/DBStaticRecord.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -45,11 +45,11 @@  discard block
 block discarded – undo
45 45
             $result[] = 'NULL';
46 46
           break;
47 47
           default:
48
-            $string = (string)$fieldName;
48
+            $string = (string) $fieldName;
49 49
             if ($string == '') {
50 50
               throw new ExceptionDBFieldEmpty();
51 51
             }
52
-            $result[] = '`' . $string . '`';
52
+            $result[] = '`'.$string.'`';
53 53
         }
54 54
       }
55 55
     } else {
@@ -77,10 +77,10 @@  discard block
 block discarded – undo
77 77
     if (!empty($fieldList)) {
78 78
       $user_record = self::$dbStatic->doquery(
79 79
         (
80
-          "SELECT {$fieldList}" .
81
-          " FROM {{" . self::$_table . "}}" .
82
-          (!empty($where) ? " WHERE {$where}" : '') .
83
-          (!empty($for_update) ? " FOR UPDATE" : '') .
80
+          "SELECT {$fieldList}".
81
+          " FROM {{".self::$_table."}}".
82
+          (!empty($where) ? " WHERE {$where}" : '').
83
+          (!empty($for_update) ? " FOR UPDATE" : '').
84 84
           ($returnFirst ? ' LIMIT 1' : '')
85 85
         ),
86 86
         $returnFirst
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
    */
138 138
   public static function getRecordById($recordId, $fieldList = '*', $forUpdate = false) {
139 139
 //    return static::getRecord(array(static::$_idField => $recordId), $fieldList, $forUpdate);
140
-    return static::getRecord(array(static::$_idField . '=' . $recordId), $fieldList, $forUpdate);
140
+    return static::getRecord(array(static::$_idField.'='.$recordId), $fieldList, $forUpdate);
141 141
   }
142 142
 
143 143
 
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
   public static function queryExistsIdInList($idList) {
150 150
     $query = null;
151 151
     if (!empty($idList)) {
152
-      $query = self::$dbStatic->doquery("SELECT `" . static::$_idField . "` FROM `{{" . static::$_table . "}}` WHERE `" . static::$_idField . "` IN (" . implode(',', $idList) . ")");
152
+      $query = self::$dbStatic->doquery("SELECT `".static::$_idField."` FROM `{{".static::$_table."}}` WHERE `".static::$_idField."` IN (".implode(',', $idList).")");
153 153
     }
154 154
 
155 155
     return !empty($query) ? $query : null;
Please login to merge, or discard this patch.
includes/classes/db_mysql.php 1 patch
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
   public function load_db_settings() {
66 66
     $dbsettings = array();
67 67
 
68
-    require(SN_ROOT_PHYSICAL . "config" . DOT_PHP_EX);
68
+    require(SN_ROOT_PHYSICAL."config".DOT_PHP_EX);
69 69
 
70 70
     $this->dbsettings = $dbsettings;
71 71
   }
@@ -73,23 +73,23 @@  discard block
 block discarded – undo
73 73
   public 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
       }
@@ -101,11 +101,11 @@  discard block
 block discarded – undo
101 101
   }
102 102
 
103 103
   protected function driver_connect() {
104
-    if(!is_object($this->driver)) {
104
+    if (!is_object($this->driver)) {
105 105
       classSupernova::$debug->error_fatal('DB Error - No driver for MySQL found!');
106 106
     }
107 107
 
108
-    if(!method_exists($this->driver, 'mysql_connect')) {
108
+    if (!method_exists($this->driver, 'mysql_connect')) {
109 109
       classSupernova::$debug->error_fatal('DB Error - WRONG MySQL driver!');
110 110
     }
111 111
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
   }
114 114
 
115 115
   public function db_disconnect() {
116
-    if($this->connected) {
116
+    if ($this->connected) {
117 117
       $this->connected = !$this->driver_disconnect();
118 118
       $this->connected = false;
119 119
     }
@@ -128,9 +128,9 @@  discard block
 block discarded – undo
128 128
    */
129 129
   public function replaceTablePlaceholders($query) {
130 130
     $sql = $query;
131
-    if(strpos($sql, '{{') !== false) {
132
-      foreach($this->table_list as $tableName) {
133
-        $sql = str_replace("{{{$tableName}}}", $this->db_prefix . $tableName, $sql);
131
+    if (strpos($sql, '{{') !== false) {
132
+      foreach ($this->table_list as $tableName) {
133
+        $sql = str_replace("{{{$tableName}}}", $this->db_prefix.$tableName, $sql);
134 134
       }
135 135
     }
136 136
 
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
    * @param       $fetch
143 143
    */
144 144
   protected function logQuery($query, $fetch) {
145
-    if(!classSupernova::$config->debug) {
145
+    if (!classSupernova::$config->debug) {
146 146
       return;
147 147
     }
148 148
 
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
     $arr = debug_backtrace();
151 151
     $file = end(explode('/', $arr[0]['file']));
152 152
     $line = $arr[0]['line'];
153
-    classSupernova::$debug->add("<tr><th>Query {$this->queryCount}: </th><th>$query</th><th>{$file} @ {$line}</th><th>&nbsp;</th><th> " . ($fetch ? '+' : '&nbsp;') . " </th></tr>");
153
+    classSupernova::$debug->add("<tr><th>Query {$this->queryCount}: </th><th>$query</th><th>{$file} @ {$line}</th><th>&nbsp;</th><th> ".($fetch ? '+' : '&nbsp;')." </th></tr>");
154 154
   }
155 155
 
156 156
 
@@ -160,18 +160,18 @@  discard block
 block discarded – undo
160 160
    * @return void
161 161
    */
162 162
   protected function commentQuery(&$sql) {
163
-    if(!defined('DEBUG_SQL_COMMENT')) {
163
+    if (!defined('DEBUG_SQL_COMMENT')) {
164 164
       return;
165 165
     }
166 166
     $backtrace = debug_backtrace();
167 167
     $sql_comment = classSupernova::$debug->compact_backtrace($backtrace, defined('DEBUG_SQL_COMMENT_LONG'));
168 168
 
169
-    $sql_commented = '/* ' . implode("<br />", $sql_comment) . '<br /> */ ' . preg_replace("/\s+/", ' ', $sql);
170
-    if(defined('DEBUG_SQL_ONLINE')) {
169
+    $sql_commented = '/* '.implode("<br />", $sql_comment).'<br /> */ '.preg_replace("/\s+/", ' ', $sql);
170
+    if (defined('DEBUG_SQL_ONLINE')) {
171 171
       classSupernova::$debug->warning($sql_commented, 'SQL Debug', LOG_DEBUG_SQL);
172 172
     }
173 173
 
174
-    if(defined('DEBUG_SQL_ERROR')) {
174
+    if (defined('DEBUG_SQL_ERROR')) {
175 175
       array_unshift($sql_comment, preg_replace("/\s+/", ' ', $sql));
176 176
       classSupernova::$debug->add_to_array($sql_comment);
177 177
     }
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
    * @return array|bool|mysqli_result|null
186 186
    */
187 187
   public function execute($statement) {
188
-    return $this->doquery((string)$statement);
188
+    return $this->doquery((string) $statement);
189 189
   }
190 190
 
191 191
   /**
@@ -199,11 +199,11 @@  discard block
 block discarded – undo
199 199
   }
200 200
 
201 201
   public function doquery($query, $table = '', $fetch = false, $skip_query_check = false) {
202
-    if(!is_string($table)) {
202
+    if (!is_string($table)) {
203 203
       $fetch = $table;
204 204
     }
205 205
 
206
-    if(!$this->connected) {
206
+    if (!$this->connected) {
207 207
       $this->sn_db_connect();
208 208
     }
209 209
 
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 
215 215
     $sql = $this->replaceTablePlaceholders($query);
216 216
     $this->commentQuery($sql);
217
-    !($sqlquery = $this->db_sql_query($sql)) ? classSupernova::$debug->error(db_error() . "<br />$sql<br />", 'SQL Error') : false;
217
+    !($sqlquery = $this->db_sql_query($sql)) ? classSupernova::$debug->error(db_error()."<br />$sql<br />", 'SQL Error') : false;
218 218
 
219 219
     return $fetch ? $this->db_fetch($sqlquery) : $sqlquery;
220 220
   }
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
   protected function security_watch_user_queries($query) {
225 225
     global $user;
226 226
 
227
-    if(
227
+    if (
228 228
       !$this->isWatching // Not already watching
229 229
       && !empty(classSupernova::$config->game_watchlist_array) // There is some players in watchlist
230 230
       && in_array($user['id'], classSupernova::$config->game_watchlist_array) // Current player is in watchlist
@@ -232,11 +232,11 @@  discard block
 block discarded – undo
232 232
     ) {
233 233
       $this->isWatching = true;
234 234
       $msg = "\$query = \"{$query}\"\n\r";
235
-      if(!empty($_POST)) {
236
-        $msg .= "\n\r" . dump($_POST, '$_POST');
235
+      if (!empty($_POST)) {
236
+        $msg .= "\n\r".dump($_POST, '$_POST');
237 237
       }
238
-      if(!empty($_GET)) {
239
-        $msg .= "\n\r" . dump($_GET, '$_GET');
238
+      if (!empty($_GET)) {
239
+        $msg .= "\n\r".dump($_GET, '$_GET');
240 240
       }
241 241
       classSupernova::$debug->warning($msg, "Watching user {$user['id']}", 399, array('base_dump' => true));
242 242
       $this->isWatching = false;
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
   public function security_query_check_bad_words($query) {
248 248
     global $user, $dm_change_legit, $mm_change_legit;
249 249
 
250
-    switch(true) {
250
+    switch (true) {
251 251
       case stripos($query, 'RUNCATE TABL') != false:
252 252
       case stripos($query, 'ROP TABL') != false:
253 253
       case stripos($query, 'ENAME TABL') != false:
@@ -258,37 +258,37 @@  discard block
 block discarded – undo
258 258
       case stripos($query, 'RPG_POINTS') != false && stripos(trim($query), 'UPDATE ') === 0 && !$dm_change_legit:
259 259
       case stripos($query, 'METAMATTER') != false && stripos(trim($query), 'UPDATE ') === 0 && !$mm_change_legit:
260 260
       case stripos($query, 'AUTHLEVEL') != false && $user['authlevel'] < 3 && stripos($query, 'SELECT') !== 0:
261
-        $report = "Hacking attempt (" . date("d.m.Y H:i:s") . " - [" . time() . "]):\n";
261
+        $report = "Hacking attempt (".date("d.m.Y H:i:s")." - [".time()."]):\n";
262 262
         $report .= ">Database Inforamation\n";
263
-        $report .= "\tID - " . $user['id'] . "\n";
264
-        $report .= "\tUser - " . $user['username'] . "\n";
265
-        $report .= "\tAuth level - " . $user['authlevel'] . "\n";
266
-        $report .= "\tAdmin Notes - " . $user['adminNotes'] . "\n";
267
-        $report .= "\tCurrent Planet - " . $user['current_planet'] . "\n";
268
-        $report .= "\tUser IP - " . $user['user_lastip'] . "\n";
269
-        $report .= "\tUser IP at Reg - " . $user['ip_at_reg'] . "\n";
270
-        $report .= "\tUser Agent- " . $_SERVER['HTTP_USER_AGENT'] . "\n";
271
-        $report .= "\tCurrent Page - " . $user['current_page'] . "\n";
272
-        $report .= "\tRegister Time - " . $user['register_time'] . "\n";
263
+        $report .= "\tID - ".$user['id']."\n";
264
+        $report .= "\tUser - ".$user['username']."\n";
265
+        $report .= "\tAuth level - ".$user['authlevel']."\n";
266
+        $report .= "\tAdmin Notes - ".$user['adminNotes']."\n";
267
+        $report .= "\tCurrent Planet - ".$user['current_planet']."\n";
268
+        $report .= "\tUser IP - ".$user['user_lastip']."\n";
269
+        $report .= "\tUser IP at Reg - ".$user['ip_at_reg']."\n";
270
+        $report .= "\tUser Agent- ".$_SERVER['HTTP_USER_AGENT']."\n";
271
+        $report .= "\tCurrent Page - ".$user['current_page']."\n";
272
+        $report .= "\tRegister Time - ".$user['register_time']."\n";
273 273
         $report .= "\n";
274 274
 
275 275
         $report .= ">Query Information\n";
276
-        $report .= "\tQuery - " . $query . "\n";
276
+        $report .= "\tQuery - ".$query."\n";
277 277
         $report .= "\n";
278 278
 
279 279
         $report .= ">\$_SERVER Information\n";
280
-        $report .= "\tIP - " . $_SERVER['REMOTE_ADDR'] . "\n";
281
-        $report .= "\tHost Name - " . $_SERVER['HTTP_HOST'] . "\n";
282
-        $report .= "\tUser Agent - " . $_SERVER['HTTP_USER_AGENT'] . "\n";
283
-        $report .= "\tRequest Method - " . $_SERVER['REQUEST_METHOD'] . "\n";
284
-        $report .= "\tCame From - " . $_SERVER['HTTP_REFERER'] . "\n";
285
-        $report .= "\tPage is - " . $_SERVER['SCRIPT_NAME'] . "\n";
286
-        $report .= "\tUses Port - " . $_SERVER['REMOTE_PORT'] . "\n";
287
-        $report .= "\tServer Protocol - " . $_SERVER['SERVER_PROTOCOL'] . "\n";
280
+        $report .= "\tIP - ".$_SERVER['REMOTE_ADDR']."\n";
281
+        $report .= "\tHost Name - ".$_SERVER['HTTP_HOST']."\n";
282
+        $report .= "\tUser Agent - ".$_SERVER['HTTP_USER_AGENT']."\n";
283
+        $report .= "\tRequest Method - ".$_SERVER['REQUEST_METHOD']."\n";
284
+        $report .= "\tCame From - ".$_SERVER['HTTP_REFERER']."\n";
285
+        $report .= "\tPage is - ".$_SERVER['SCRIPT_NAME']."\n";
286
+        $report .= "\tUses Port - ".$_SERVER['REMOTE_PORT']."\n";
287
+        $report .= "\tServer Protocol - ".$_SERVER['SERVER_PROTOCOL']."\n";
288 288
 
289 289
         $report .= "\n--------------------------------------------------------------------------------------------------\n";
290 290
 
291
-        $fp = fopen(SN_ROOT_PHYSICAL . 'badqrys.txt', 'a');
291
+        $fp = fopen(SN_ROOT_PHYSICAL.'badqrys.txt', 'a');
292 292
         fwrite($fp, $report);
293 293
         fclose($fp);
294 294
 
@@ -309,11 +309,11 @@  discard block
 block discarded – undo
309 309
     $prefix_length = strlen($this->db_prefix);
310 310
 
311 311
     $tl = array();
312
-    while($row = $this->db_fetch($query)) {
313
-      foreach($row as $table_name) {
314
-        if(strpos($table_name, $this->db_prefix) === 0) {
312
+    while ($row = $this->db_fetch($query)) {
313
+      foreach ($row as $table_name) {
314
+        if (strpos($table_name, $this->db_prefix) === 0) {
315 315
           $table_name = substr($table_name, $prefix_length);
316
-        } elseif($prefixed_only) {
316
+        } elseif ($prefixed_only) {
317 317
           continue;
318 318
         }
319 319
         // $table_name = str_replace($db_prefix, '', $table_name);
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
     $result = array();
409 409
 
410 410
     $status = explode('  ', $this->driver->mysql_stat());
411
-    foreach($status as $value) {
411
+    foreach ($status as $value) {
412 412
       $row = explode(': ', $value);
413 413
       $result[$row[0]] = $row[1];
414 414
     }
@@ -424,10 +424,10 @@  discard block
 block discarded – undo
424 424
     $result = array();
425 425
 
426 426
     $query = $this->db_sql_query('SHOW STATUS;');
427
-    if(is_bool($query)) {
427
+    if (is_bool($query)) {
428 428
       throw new Exception('Result of SHOW STATUS command is boolean - which should never happen. Connection to DB is lost?');
429 429
     }
430
-    while($row = db_fetch($query)) {
430
+    while ($row = db_fetch($query)) {
431 431
       $result[$row['Variable_name']] = $row['Value'];
432 432
     }
433 433
 
Please login to merge, or discard this patch.
includes/classes/DBStaticNote.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
    * @param $note_id_edit
37 37
    */
38 38
   public static function db_note_update_by_id($note_priority, $note_title, $note_text, $note_galaxy, $note_system, $note_planet, $note_planet_type, $note_sticky, $note_id_edit) {
39
-    doquery("UPDATE {{notes}} SET `time` = " . SN_TIME_NOW . ", `priority` = {$note_priority}, `title` = '{$note_title}', `text` = '{$note_text}',
39
+    doquery("UPDATE {{notes}} SET `time` = ".SN_TIME_NOW.", `priority` = {$note_priority}, `title` = '{$note_title}', `text` = '{$note_text}',
40 40
         `galaxy` = {$note_galaxy}, `system` = {$note_system}, `planet` = {$note_planet}, `planet_type` = {$note_planet_type}, `sticky` = {$note_sticky}
41 41
         WHERE `id` = {$note_id_edit} LIMIT 1;");
42 42
   }
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
    * @param $note_sticky
54 54
    */
55 55
   public static function db_note_insert($user, $note_priority, $note_title, $note_text, $note_galaxy, $note_system, $note_planet, $note_planet_type, $note_sticky) {
56
-    doquery("INSERT INTO {{notes}} SET `owner` = {$user['id']}, `time` = " . SN_TIME_NOW . ", `priority` = {$note_priority}, `title` = '{$note_title}', `text` = '{$note_text}',
56
+    doquery("INSERT INTO {{notes}} SET `owner` = {$user['id']}, `time` = ".SN_TIME_NOW.", `priority` = {$note_priority}, `title` = '{$note_title}', `text` = '{$note_text}',
57 57
         `galaxy` = {$note_galaxy}, `system` = {$note_system}, `planet` = {$note_planet}, `planet_type` = {$note_planet_type}, `sticky` = {$note_sticky};");
58 58
   }
59 59
 
Please login to merge, or discard this patch.
includes/classes/DbSqlStatement.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
    */
45 45
   public static function build($db = null, $className = '') {
46 46
     $result = new self($db);
47
-    if(!empty($className) && is_string($className)) {
47
+    if (!empty($className) && is_string($className)) {
48 48
       $result->getParamsFromStaticClass($className);
49 49
     }
50 50
     return $result;
@@ -186,23 +186,23 @@  discard block
 block discarded – undo
186 186
     $result = '';
187 187
     $result .= $this->stringEscape($this->operation);
188 188
 
189
-    $result .= ' ' . $this->selectFieldsToString($this->fields);
189
+    $result .= ' '.$this->selectFieldsToString($this->fields);
190 190
 
191 191
     $result .= ' FROM';
192
-    $result .= ' `{{' . $this->stringEscape($this->table) . '}}`';
193
-    $result .= !empty($this->alias) ? ' AS `' . $this->stringEscape($this->alias) . '`' : '';
192
+    $result .= ' `{{'.$this->stringEscape($this->table).'}}`';
193
+    $result .= !empty($this->alias) ? ' AS `'.$this->stringEscape($this->alias).'`' : '';
194 194
 
195 195
     // TODO - fields should be escaped !!
196
-    $result .= !empty($this->where) ? ' WHERE ' . implode(' AND ', $this->where) : '';
196
+    $result .= !empty($this->where) ? ' WHERE '.implode(' AND ', $this->where) : '';
197 197
 
198 198
     // TODO - fields should be escaped !!
199
-    $result .= !empty($this->group) ? ' GROUP BY ' . implode(',', $this->group) : '';
199
+    $result .= !empty($this->group) ? ' GROUP BY '.implode(',', $this->group) : '';
200 200
 
201 201
     // TODO - fields should be escaped !!
202
-    $result .= !empty($this->order) ? ' ORDER BY ' . implode(',', $this->order) : '';
202
+    $result .= !empty($this->order) ? ' ORDER BY '.implode(',', $this->order) : '';
203 203
 
204 204
     // TODO - fields should be escaped !!
205
-    $result .= !empty($this->limit) ? ' LIMIT ' . implode(',', $this->limit) : '';
205
+    $result .= !empty($this->limit) ? ' LIMIT '.implode(',', $this->limit) : '';
206 206
 
207 207
     // TODO - protect from double escape!
208 208
 
@@ -240,17 +240,17 @@  discard block
 block discarded – undo
240 240
         break;
241 241
 
242 242
         default:
243
-          $string = (string)$fieldName;
243
+          $string = (string) $fieldName;
244 244
           if ($string == '') {
245 245
             continue;
246 246
           }
247 247
 
248
-          if($fieldName instanceof DbSqlLiteral) {
248
+          if ($fieldName instanceof DbSqlLiteral) {
249 249
             // Literals plays as they are - they do properly format by itself
250 250
             $result[] = $string;
251 251
           } else {
252 252
             // Other should be formatted
253
-            $result[] = '`' . $this->stringEscape($string) . '`';
253
+            $result[] = '`'.$this->stringEscape($string).'`';
254 254
           }
255 255
       }
256 256
     }
Please login to merge, or discard this patch.