Test Failed
Branch trunk (412648)
by SuperNova.WS
03:40
created
classes/debug.php 1 patch
Spacing   +42 added lines, -43 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
  * que esperabas!!! soy newbie!!! D':<
25 25
 */
26 26
 
27
-if(!defined('INSIDE')) {
27
+if (!defined('INSIDE')) {
28 28
   die("attemp hacking");
29 29
 }
30 30
 
@@ -37,16 +37,16 @@  discard block
 block discarded – undo
37 37
   function log_file($message, $ident_change = 0) {
38 38
     static $ident = 0;
39 39
 
40
-    if(!defined('SN_DEBUG_LOG')) {
40
+    if (!defined('SN_DEBUG_LOG')) {
41 41
       return;
42 42
     }
43 43
 
44
-    if($this->log_file_handler === null) {
44
+    if ($this->log_file_handler === null) {
45 45
       $this->log_file_handler = @fopen(SN_ROOT_PHYSICAL . '/.logs/supernova.log', 'a+');
46 46
       @fwrite($this->log_file_handler, "\r\n\r\n");
47 47
     }
48 48
     $ident_change < 0 ? $ident += $ident_change * 2 : false;
49
-    if($this->log_file_handler) {
49
+    if ($this->log_file_handler) {
50 50
       @fwrite($this->log_file_handler, date(FMT_DATE_TIME_SQL, time()) . str_repeat(' ', $ident + 1) . $message . "\r\n");
51 51
     }
52 52
     $ident_change > 0 ? $ident += $ident_change * 2 : false;
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
     $result = array();
82 82
     $transaction_id = classSupernova::db_transaction_check(false) ? classSupernova::$transaction_id : classSupernova::$transaction_id++;
83 83
     $result[] = "tID {$transaction_id}";
84
-    foreach($backtrace as $a_trace) {
85
-      if(in_array($a_trace['function'], $exclude_functions)) {
84
+    foreach ($backtrace as $a_trace) {
85
+      if (in_array($a_trace['function'], $exclude_functions)) {
86 86
         continue;
87 87
       }
88 88
       $function =
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 
99 99
       $result[] = "{$function} - '{$file}' Line {$a_trace['line']}";
100 100
 
101
-      if(!$long_comment) {
101
+      if (!$long_comment) {
102 102
         break;
103 103
       }
104 104
     }
@@ -107,26 +107,26 @@  discard block
 block discarded – undo
107 107
   }
108 108
 
109 109
   function dump($dump = false, $force_base = false, $deadlock = false) {
110
-    if($dump === false) {
110
+    if ($dump === false) {
111 111
       return;
112 112
     }
113 113
 
114 114
     $error_backtrace = array();
115 115
     $base_dump = false;
116 116
 
117
-    if($force_base === true) {
117
+    if ($force_base === true) {
118 118
       $base_dump = true;
119 119
     }
120 120
 
121
-    if($dump === true) {
121
+    if ($dump === true) {
122 122
       $base_dump = true;
123 123
     } else {
124
-      if(!is_array($dump)) {
124
+      if (!is_array($dump)) {
125 125
         $dump = array('var' => $dump);
126 126
       }
127 127
 
128
-      foreach($dump as $dump_var_name => $dump_var) {
129
-        if($dump_var_name == 'base_dump') {
128
+      foreach ($dump as $dump_var_name => $dump_var) {
129
+        if ($dump_var_name == 'base_dump') {
130 130
           $base_dump = $dump_var;
131 131
         } else {
132 132
           $error_backtrace[$dump_var_name] = $dump_var;
@@ -134,25 +134,24 @@  discard block
 block discarded – undo
134 134
       }
135 135
     }
136 136
 
137
-    if($deadlock && ($q = db_fetch(classSupernova::$db->mysql_get_innodb_status()))) {
137
+    if ($deadlock && ($q = db_fetch(classSupernova::$db->mysql_get_innodb_status()))) {
138 138
       $error_backtrace['deadlock'] = explode("\n", $q['Status']);
139 139
       $error_backtrace['locks'] = classSupernova::$locks;
140 140
       $error_backtrace['cSN_data'] = classSupernova::$data;
141
-      foreach($error_backtrace['cSN_data'] as &$location) {
142
-        foreach($location as $location_id => &$location_data) //          $location_data = $location_id;
141
+      foreach ($error_backtrace['cSN_data'] as &$location) {
142
+        foreach ($location as $location_id => &$location_data) //          $location_data = $location_id;
143 143
         {
144
-          $location_data = isset($location_data['username']) ? $location_data['username'] :
145
-            (isset($location_data['name']) ? $location_data['name'] : $location_id);
144
+          $location_data = isset($location_data['username']) ? $location_data['username'] : (isset($location_data['name']) ? $location_data['name'] : $location_id);
146 145
         }
147 146
       }
148 147
       $error_backtrace['cSN_queries'] = classSupernova::$queries;
149 148
     }
150 149
 
151
-    if($base_dump) {
152
-      if(!is_array($this->log_array) || empty($this->log_array)) {
150
+    if ($base_dump) {
151
+      if (!is_array($this->log_array) || empty($this->log_array)) {
153 152
         $this->log_array = [];
154 153
       } else {
155
-        foreach($this->log_array as $log) {
154
+        foreach ($this->log_array as $log) {
156 155
           $error_backtrace['queries'][] = $log;
157 156
         }
158 157
       }
@@ -164,17 +163,17 @@  discard block
 block discarded – undo
164 163
       // Converting object instances to object names
165 164
 
166 165
       foreach ($error_backtrace['backtrace'] as &$backtrace) {
167
-        if(is_object($backtrace['object'])) {
166
+        if (is_object($backtrace['object'])) {
168 167
           $backtrace['object'] = get_class($backtrace['object']);
169 168
         }
170 169
 
171
-        if(empty($backtrace['args'])) {
170
+        if (empty($backtrace['args'])) {
172 171
           continue;
173 172
         }
174 173
 
175 174
         // Doing same conversion for backtrace params
176
-        foreach($backtrace['args'] as &$arg) {
177
-          if(is_object($arg)) {
175
+        foreach ($backtrace['args'] as &$arg) {
176
+          if (is_object($arg)) {
178 177
             $arg = 'object::' . get_class($arg);
179 178
           }
180 179
         }
@@ -203,14 +202,14 @@  discard block
 block discarded – undo
203 202
   function error($message = 'There is a error on page', $title = 'Internal Error', $error_code = 500, $dump = true) {
204 203
     global $config, $sys_stop_log_hit, $lang, $sys_log_disabled, $user;
205 204
 
206
-    if(empty(classSupernova::$db->connected)) {
205
+    if (empty(classSupernova::$db->connected)) {
207 206
       // TODO - писать ошибку в файл
208 207
       die('SQL server currently unavailable. Please contact Administration...');
209 208
     }
210 209
 
211 210
     sn_db_transaction_rollback();
212 211
 
213
-    if(classSupernova::$config->debug == 1) {
212
+    if (classSupernova::$config->debug == 1) {
214 213
       echo "<h2>{$title}</h2><br><font color=red>{$message}</font><br><hr>";
215 214
       echo "<table>{$this->log}</table>";
216 215
     }
@@ -220,7 +219,7 @@  discard block
 block discarded – undo
220 219
     $error_text = db_escape($message);
221 220
     $error_backtrace = $this->dump($dump, true, strpos($message, 'Deadlock') !== false);
222 221
 
223
-    if(!$sys_log_disabled) {
222
+    if (!$sys_log_disabled) {
224 223
       $query = "INSERT INTO `{{logs}}` SET
225 224
         `log_time` = '" . time() . "', `log_code` = '" . db_escape($error_code) . "', `log_sender` = '" . ($user['id'] ? db_escape($user['id']) : 0) . "',
226 225
         `log_username` = '" . db_escape($user['user_name']) . "', `log_title` = '" . db_escape($title) . "',  `log_text` = '" . db_escape($message) . "',
@@ -238,7 +237,7 @@  discard block
 block discarded – undo
238 237
       ob_start();
239 238
       print("<hr>User ID {$user['id']} raised error code {$error_code} titled '{$title}' with text '{$error_text}' on page {$_SERVER['SCRIPT_NAME']}");
240 239
 
241
-      foreach($error_backtrace as $name => $value) {
240
+      foreach ($error_backtrace as $name => $value) {
242 241
         print('<hr>');
243 242
         pdump($value, $name);
244 243
       }
@@ -250,14 +249,14 @@  discard block
 block discarded – undo
250 249
   function warning($message, $title = 'System Message', $log_code = 300, $dump = false) {
251 250
     global $user, $lang, $sys_log_disabled;
252 251
 
253
-    if(empty(classSupernova::$db->connected)) {
252
+    if (empty(classSupernova::$db->connected)) {
254 253
       // TODO - писать ошибку в файл
255 254
       die('SQL server currently unavailable. Please contact Administration...');
256 255
     }
257 256
 
258 257
     $error_backtrace = $this->dump($dump, false);
259 258
 
260
-    if(!$sys_log_disabled) {
259
+    if (!$sys_log_disabled) {
261 260
       $query = "INSERT INTO `{{logs}}` SET
262 261
         `log_time` = '" . time() . "', `log_code` = '" . db_escape($log_code) . "', `log_sender` = '" . ($user['id'] ? db_escape($user['id']) : 0) . "',
263 262
         `log_username` = '" . db_escape($user['user_name']) . "', `log_title` = '" . db_escape($title) . "',  `log_text` = '" . db_escape($message) . "',
@@ -275,11 +274,11 @@  discard block
 block discarded – undo
275 274
 // Dump variables nicer then var_dump()
276 275
 
277 276
 function dump($value, $varname = null, $level = 0, $dumper = '') {
278
-  if(isset($varname)) {
277
+  if (isset($varname)) {
279 278
     $varname .= " = ";
280 279
   }
281 280
 
282
-  if($level == -1) {
281
+  if ($level == -1) {
283 282
     $trans[' '] = '&there4;';
284 283
     $trans["\t"] = '&rArr;';
285 284
     $trans["\n"] = '&para;;';
@@ -288,7 +287,7 @@  discard block
 block discarded – undo
288 287
 
289 288
     return strtr(htmlspecialchars($value), $trans);
290 289
   }
291
-  if($level == 0) {
290
+  if ($level == 0) {
292 291
 //    $dumper = '<pre>' . mt_rand(10, 99) . '|' . $varname;
293 292
     $dumper = mt_rand(10, 99) . '|' . $varname;
294 293
   }
@@ -296,22 +295,22 @@  discard block
 block discarded – undo
296 295
   $type = gettype($value);
297 296
   $dumper .= $type;
298 297
 
299
-  if($type == 'string') {
298
+  if ($type == 'string') {
300 299
     $dumper .= '(' . strlen($value) . ')';
301 300
     $value = dump($value, '', -1);
302
-  } elseif($type == 'boolean') {
301
+  } elseif ($type == 'boolean') {
303 302
     $value = ($value ? 'true' : 'false');
304
-  } elseif($type == 'object') {
303
+  } elseif ($type == 'object') {
305 304
     $props = get_class_vars(get_class($value));
306 305
     $dumper .= '(' . count($props) . ') <u>' . get_class($value) . '</u>';
307
-    foreach($props as $key => $val) {
306
+    foreach ($props as $key => $val) {
308 307
       $dumper .= "\n" . str_repeat("\t", $level + 1) . $key . ' => ';
309 308
       $dumper .= dump($value->$key, '', $level + 1);
310 309
     }
311 310
     $value = '';
312
-  } elseif($type == 'array') {
311
+  } elseif ($type == 'array') {
313 312
     $dumper .= '(' . count($value) . ')';
314
-    foreach($value as $key => $val) {
313
+    foreach ($value as $key => $val) {
315 314
       $dumper .= "\n" . str_repeat("\t", $level + 1) . dump($key, '', -1) . ' => ';
316 315
       $dumper .= dump($val, '', $level + 1);
317 316
     }
@@ -331,7 +330,7 @@  discard block
 block discarded – undo
331 330
 //  $backtrace = $backtrace[1];
332 331
 
333 332
   $caller = '';
334
-  if(defined('SN_DEBUG_PDUMP_CALLER') && SN_DEBUG_PDUMP_CALLER) {
333
+  if (defined('SN_DEBUG_PDUMP_CALLER') && SN_DEBUG_PDUMP_CALLER) {
335 334
     $caller = (!empty($backtrace[1]['class']) ? $backtrace[1]['class'] : '') .
336 335
       (!empty($backtrace[1]['type']) ? $backtrace[1]['type'] : '') .
337 336
       $backtrace[1]['function'] .
@@ -358,7 +357,7 @@  discard block
 block discarded – undo
358 357
 }
359 358
 
360 359
 function pr($prePrint = false) {
361
-  if($prePrint) {
360
+  if ($prePrint) {
362 361
     print("<br>");
363 362
   }
364 363
   print(mt_rand() . "<br>");
@@ -368,7 +367,7 @@  discard block
 block discarded – undo
368 367
   global $_PRINT_COUNT_VALUE;
369 368
   $_PRINT_COUNT_VALUE++;
370 369
 
371
-  if($prePrint) {
370
+  if ($prePrint) {
372 371
     print("<br>");
373 372
   }
374 373
   print($_PRINT_COUNT_VALUE . "<br>");
Please login to merge, or discard this patch.
classes/classPersistent.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
     $this->sql_index_field = "{$table_name}_name";
34 34
     $this->sql_value_field = "{$table_name}_value";
35 35
 
36
-    if(!$this->_DB_LOADED) {
36
+    if (!$this->_DB_LOADED) {
37 37
       $this->db_loadAll();
38 38
     }
39 39
   }
@@ -53,10 +53,10 @@  discard block
 block discarded – undo
53 53
    */
54 54
   public function db_loadItem($index) {
55 55
     $result = null;
56
-    if($index) {
56
+    if ($index) {
57 57
       $index_safe = db_escape($index);
58 58
       $queryResult = doquery("SELECT `{$this->sql_value_field}` FROM `{{{$this->table_name}}}` WHERE `{$this->sql_index_field}` = '{$index_safe}' FOR UPDATE", true);
59
-      if(is_array($queryResult) && !empty($queryResult)) {
59
+      if (is_array($queryResult) && !empty($queryResult)) {
60 60
         $this->$index = $result = $queryResult[$this->sql_value_field];
61 61
       }
62 62
     }
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
     $this->loadDefaults();
69 69
 
70 70
     $query = doquery("SELECT * FROM {{{$this->table_name}}} FOR UPDATE;");
71
-    while($row = db_fetch($query)) {
71
+    while ($row = db_fetch($query)) {
72 72
       $this->$row[$this->sql_index_field] = $row[$this->sql_value_field];
73 73
     }
74 74
 
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
   }
77 77
 
78 78
   public function loadDefaults() {
79
-    foreach($this->defaults as $defName => $defValue) {
79
+    foreach ($this->defaults as $defName => $defValue) {
80 80
       $this->$defName = $defValue;
81 81
     }
82 82
   }
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
   }
93 93
 
94 94
   public function db_saveItem($item_list, $value = NULL) {
95
-    if(empty($item_list)) {
95
+    if (empty($item_list)) {
96 96
       return;
97 97
     }
98 98
 
@@ -100,8 +100,8 @@  discard block
 block discarded – undo
100 100
 
101 101
     // Сначала записываем данные в базу - что бы поймать все блокировки
102 102
     $qry = array();
103
-    foreach($item_list as $item_name => $item_value) {
104
-      if($item_name) {
103
+    foreach ($item_list as $item_name => $item_value) {
104
+      if ($item_name) {
105 105
         $item_value = db_escape($item_value === NULL ? $this->$item_name : $item_value);
106 106
         $item_name = db_escape($item_name);
107 107
         $qry[] = "('{$item_name}', '{$item_value}')";
@@ -110,8 +110,8 @@  discard block
 block discarded – undo
110 110
     doquery("REPLACE INTO `{{" . $this->table_name . "}}` (`{$this->sql_index_field}`, `{$this->sql_value_field}`) VALUES " . implode(',', $qry) . ";");
111 111
 
112 112
     // И только после взятия блокировок - меняем значения в кэше
113
-    foreach($item_list as $item_name => $item_value) {
114
-      if($item_name && $item_value !== null) {
113
+    foreach ($item_list as $item_name => $item_value) {
114
+      if ($item_name && $item_value !== null) {
115 115
         $this->__set($item_name, $item_value);
116 116
       }
117 117
     }
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
   }
127 127
 
128 128
   public function __get($name) {
129
-    if($this->force) {
129
+    if ($this->force) {
130 130
       $this->force = false;
131 131
       $this->db_loadItem($name);
132 132
     }
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
   }
136 136
 
137 137
   public function __set($name, $value) {
138
-    if($this->force) {
138
+    if ($this->force) {
139 139
       $this->force = false;
140 140
       $this->db_saveItem($name, $value);
141 141
     }
Please login to merge, or discard this patch.