@@ -103,6 +103,7 @@ |
||
| 103 | 103 | /** |
| 104 | 104 | * Set custom template location (able to use directory outside of phpBB) |
| 105 | 105 | * @access public |
| 106 | + * @param string $template_path |
|
| 106 | 107 | */ |
| 107 | 108 | function set_custom_template($template_path, $template_name, $fallback_template_path = false) |
| 108 | 109 | { |
@@ -25,11 +25,11 @@ discard block |
||
| 25 | 25 | class template |
| 26 | 26 | { |
| 27 | 27 | /** variable that holds all the data we'll be substituting into |
| 28 | - * the compiled templates. Takes form: |
|
| 29 | - * --> $this->_tpldata[block][iteration#][child][iteration#][child2][iteration#][variablename] == value |
|
| 30 | - * if it's a root-level variable, it'll be like this: |
|
| 31 | - * --> $this->_tpldata[.][0][varname] == value |
|
| 32 | - */ |
|
| 28 | + * the compiled templates. Takes form: |
|
| 29 | + * --> $this->_tpldata[block][iteration#][child][iteration#][child2][iteration#][variablename] == value |
|
| 30 | + * if it's a root-level variable, it'll be like this: |
|
| 31 | + * --> $this->_tpldata[.][0][varname] == value |
|
| 32 | + */ |
|
| 33 | 33 | var $_tpldata = array('.' => array(0 => array())); |
| 34 | 34 | var $_rootref; |
| 35 | 35 | // var $_block_counter = array(); |
@@ -60,9 +60,9 @@ discard block |
||
| 60 | 60 | var $parsed = false; |
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | - * Set template location |
|
| 64 | - * @access public |
|
| 65 | - */ |
|
| 63 | + * Set template location |
|
| 64 | + * @access public |
|
| 65 | + */ |
|
| 66 | 66 | function set_template() |
| 67 | 67 | { |
| 68 | 68 | global $phpbb_root_path, $user; |
@@ -101,9 +101,9 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
| 104 | - * Set custom template location (able to use directory outside of phpBB) |
|
| 105 | - * @access public |
|
| 106 | - */ |
|
| 104 | + * Set custom template location (able to use directory outside of phpBB) |
|
| 105 | + * @access public |
|
| 106 | + */ |
|
| 107 | 107 | function set_custom_template($template_path, $template_name, $fallback_template_path = false) |
| 108 | 108 | { |
| 109 | 109 | global $phpbb_root_path, $user; |
@@ -142,10 +142,10 @@ discard block |
||
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
| 145 | - * Sets the template filenames for handles. $filename_array |
|
| 146 | - * should be a hash of handle => filename pairs. |
|
| 147 | - * @access public |
|
| 148 | - */ |
|
| 145 | + * Sets the template filenames for handles. $filename_array |
|
| 146 | + * should be a hash of handle => filename pairs. |
|
| 147 | + * @access public |
|
| 148 | + */ |
|
| 149 | 149 | function set_filenames($filename_array) |
| 150 | 150 | { |
| 151 | 151 | if (!is_array($filename_array)) |
@@ -172,9 +172,9 @@ discard block |
||
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
| 175 | - * Destroy template data set |
|
| 176 | - * @access public |
|
| 177 | - */ |
|
| 175 | + * Destroy template data set |
|
| 176 | + * @access public |
|
| 177 | + */ |
|
| 178 | 178 | function destroy() |
| 179 | 179 | { |
| 180 | 180 | $this->_tpldata = array('.' => array(0 => array())); |
@@ -182,9 +182,9 @@ discard block |
||
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
| 185 | - * Reset/empty complete block |
|
| 186 | - * @access public |
|
| 187 | - */ |
|
| 185 | + * Reset/empty complete block |
|
| 186 | + * @access public |
|
| 187 | + */ |
|
| 188 | 188 | function destroy_block_vars($blockname) |
| 189 | 189 | { |
| 190 | 190 | if (strpos($blockname, '.') !== false) |
@@ -212,9 +212,9 @@ discard block |
||
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
| 215 | - * Display handle |
|
| 216 | - * @access public |
|
| 217 | - */ |
|
| 215 | + * Display handle |
|
| 216 | + * @access public |
|
| 217 | + */ |
|
| 218 | 218 | function display($handle, $include_once = true) |
| 219 | 219 | { |
| 220 | 220 | global $user, $phpbb_hook, $lang, $config; |
@@ -248,9 +248,9 @@ discard block |
||
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | /** |
| 251 | - * Display the handle and assign the output to a template variable or return the compiled result. |
|
| 252 | - * @access public |
|
| 253 | - */ |
|
| 251 | + * Display the handle and assign the output to a template variable or return the compiled result. |
|
| 252 | + * @access public |
|
| 253 | + */ |
|
| 254 | 254 | function assign_display($handle, $template_var = '', $return_content = true, $include_once = false) |
| 255 | 255 | { |
| 256 | 256 | ob_start(); |
@@ -268,9 +268,9 @@ discard block |
||
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /** |
| 271 | - * Load a compiled template if possible, if not, recompile it |
|
| 272 | - * @access private |
|
| 273 | - */ |
|
| 271 | + * Load a compiled template if possible, if not, recompile it |
|
| 272 | + * @access private |
|
| 273 | + */ |
|
| 274 | 274 | function _tpl_load(&$handle) |
| 275 | 275 | { |
| 276 | 276 | global $user, $config; |
@@ -453,9 +453,9 @@ discard block |
||
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | /** |
| 456 | - * Assign key variable pairs from an array |
|
| 457 | - * @access public |
|
| 458 | - */ |
|
| 456 | + * Assign key variable pairs from an array |
|
| 457 | + * @access public |
|
| 458 | + */ |
|
| 459 | 459 | function assign_vars($vararray) |
| 460 | 460 | { |
| 461 | 461 | foreach ($vararray as $key => $val) |
@@ -467,9 +467,9 @@ discard block |
||
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | /** |
| 470 | - * Assign a single variable to a single key |
|
| 471 | - * @access public |
|
| 472 | - */ |
|
| 470 | + * Assign a single variable to a single key |
|
| 471 | + * @access public |
|
| 472 | + */ |
|
| 473 | 473 | function assign_var($varname, $varval) |
| 474 | 474 | { |
| 475 | 475 | $this->_rootref[$varname] = $varval; |
@@ -478,9 +478,9 @@ discard block |
||
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | /** |
| 481 | - * Assign key variable pairs from an array to a specified block |
|
| 482 | - * @access public |
|
| 483 | - */ |
|
| 481 | + * Assign key variable pairs from an array to a specified block |
|
| 482 | + * @access public |
|
| 483 | + */ |
|
| 484 | 484 | function assign_block_vars($blockname, $vararray) |
| 485 | 485 | { |
| 486 | 486 | if (strpos($blockname, '.') !== false) |
@@ -545,33 +545,33 @@ discard block |
||
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | /** |
| 548 | - * Change already assigned key variable pair (one-dimensional - single loop entry) |
|
| 549 | - * |
|
| 550 | - * An example of how to use this function: |
|
| 551 | - * {@example alter_block_array.php} |
|
| 552 | - * |
|
| 553 | - * @param string $blockname the blockname, for example 'loop' |
|
| 554 | - * @param array $vararray the var array to insert/add or merge |
|
| 555 | - * @param mixed $key Key to search for |
|
| 556 | - * |
|
| 557 | - * array: KEY => VALUE [the key/value pair to search for within the loop to determine the correct position] |
|
| 558 | - * |
|
| 559 | - * int: Position [the position to change or insert at directly given] |
|
| 560 | - * |
|
| 561 | - * If key is false the position is set to 0 |
|
| 562 | - * If key is true the position is set to the last entry |
|
| 563 | - * |
|
| 564 | - * @param string $mode Mode to execute (valid modes are 'insert' and 'change') |
|
| 565 | - * |
|
| 566 | - * If insert, the vararray is inserted at the given position (position counting from zero). |
|
| 567 | - * If change, the current block gets merged with the vararray (resulting in new key/value pairs be added and existing keys be replaced by the new value). |
|
| 568 | - * |
|
| 569 | - * Since counting begins by zero, inserting at the last position will result in this array: array(vararray, last positioned array) |
|
| 570 | - * and inserting at position 1 will result in this array: array(first positioned array, vararray, following vars) |
|
| 571 | - * |
|
| 572 | - * @return bool false on error, true on success |
|
| 573 | - * @access public |
|
| 574 | - */ |
|
| 548 | + * Change already assigned key variable pair (one-dimensional - single loop entry) |
|
| 549 | + * |
|
| 550 | + * An example of how to use this function: |
|
| 551 | + * {@example alter_block_array.php} |
|
| 552 | + * |
|
| 553 | + * @param string $blockname the blockname, for example 'loop' |
|
| 554 | + * @param array $vararray the var array to insert/add or merge |
|
| 555 | + * @param mixed $key Key to search for |
|
| 556 | + * |
|
| 557 | + * array: KEY => VALUE [the key/value pair to search for within the loop to determine the correct position] |
|
| 558 | + * |
|
| 559 | + * int: Position [the position to change or insert at directly given] |
|
| 560 | + * |
|
| 561 | + * If key is false the position is set to 0 |
|
| 562 | + * If key is true the position is set to the last entry |
|
| 563 | + * |
|
| 564 | + * @param string $mode Mode to execute (valid modes are 'insert' and 'change') |
|
| 565 | + * |
|
| 566 | + * If insert, the vararray is inserted at the given position (position counting from zero). |
|
| 567 | + * If change, the current block gets merged with the vararray (resulting in new key/value pairs be added and existing keys be replaced by the new value). |
|
| 568 | + * |
|
| 569 | + * Since counting begins by zero, inserting at the last position will result in this array: array(vararray, last positioned array) |
|
| 570 | + * and inserting at position 1 will result in this array: array(first positioned array, vararray, following vars) |
|
| 571 | + * |
|
| 572 | + * @return bool false on error, true on success |
|
| 573 | + * @access public |
|
| 574 | + */ |
|
| 575 | 575 | function alter_block_array($blockname, $vararray, $key = false, $mode = 'insert') |
| 576 | 576 | { |
| 577 | 577 | if (strpos($blockname, '.') !== false) |
@@ -655,9 +655,9 @@ discard block |
||
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | /** |
| 658 | - * Include a separate template |
|
| 659 | - * @access private |
|
| 660 | - */ |
|
| 658 | + * Include a separate template |
|
| 659 | + * @access private |
|
| 660 | + */ |
|
| 661 | 661 | function _tpl_include($filename, $include = true) |
| 662 | 662 | { |
| 663 | 663 | global $lang, $config; |
@@ -686,9 +686,9 @@ discard block |
||
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | /** |
| 689 | - * Include a php-file |
|
| 690 | - * @access private |
|
| 691 | - */ |
|
| 689 | + * Include a php-file |
|
| 690 | + * @access private |
|
| 691 | + */ |
|
| 692 | 692 | function _php_include($filename) |
| 693 | 693 | { |
| 694 | 694 | global $phpbb_root_path; |
@@ -705,9 +705,9 @@ discard block |
||
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | /** |
| 708 | - * Assign key variable pairs from an array with block support |
|
| 709 | - * @access public |
|
| 710 | - */ |
|
| 708 | + * Assign key variable pairs from an array with block support |
|
| 709 | + * @access public |
|
| 710 | + */ |
|
| 711 | 711 | function assign_recursive($values, $name = '') |
| 712 | 712 | { |
| 713 | 713 | if(isset($values['.'])) |
@@ -628,7 +628,7 @@ discard block |
||
| 628 | 628 | // Re-position template blocks |
| 629 | 629 | for ($i = sizeof($this->_tpldata[$blockname]); $i > $key; $i--) |
| 630 | 630 | { |
| 631 | - $this->_tpldata[$blockname][$i] = $this->_tpldata[$blockname][$i-1]; |
|
| 631 | + $this->_tpldata[$blockname][$i] = $this->_tpldata[$blockname][$i - 1]; |
|
| 632 | 632 | $this->_tpldata[$blockname][$i]['S_ROW_COUNT'] = $i; |
| 633 | 633 | } |
| 634 | 634 | |
@@ -710,13 +710,13 @@ discard block |
||
| 710 | 710 | */ |
| 711 | 711 | function assign_recursive($values, $name = '') |
| 712 | 712 | { |
| 713 | - if(isset($values['.'])) |
|
| 713 | + if (isset($values['.'])) |
|
| 714 | 714 | { |
| 715 | 715 | $values_extra = $values['.']; |
| 716 | 716 | unset($values['.']); |
| 717 | 717 | } |
| 718 | 718 | |
| 719 | - if(!$name) |
|
| 719 | + if (!$name) |
|
| 720 | 720 | { |
| 721 | 721 | $this->assign_vars($values); |
| 722 | 722 | } |
@@ -725,12 +725,12 @@ discard block |
||
| 725 | 725 | $this->assign_block_vars($name, $values); |
| 726 | 726 | } |
| 727 | 727 | |
| 728 | - if(isset($values_extra)) |
|
| 728 | + if (isset($values_extra)) |
|
| 729 | 729 | { |
| 730 | - foreach($values_extra as $sub_array_name => $sub_array) |
|
| 730 | + foreach ($values_extra as $sub_array_name => $sub_array) |
|
| 731 | 731 | { |
| 732 | 732 | $new_name = $name . ($name ? '.' : '') . $sub_array_name; |
| 733 | - foreach($sub_array as $sub_element) |
|
| 733 | + foreach ($sub_array as $sub_element) |
|
| 734 | 734 | { |
| 735 | 735 | $this->assign_recursive($sub_element, $new_name); |
| 736 | 736 | } |
@@ -89,8 +89,7 @@ discard block |
||
| 89 | 89 | { |
| 90 | 90 | $this->inherit_root = $phpbb_root_path . 'styles/' . $user->theme['template_inherit_path'] . '/template'; |
| 91 | 91 | } |
| 92 | - } |
|
| 93 | - else |
|
| 92 | + } else |
|
| 94 | 93 | { |
| 95 | 94 | trigger_error('Template path could not be found: styles/' . $user->theme['template_path'] . '/template', E_USER_ERROR); |
| 96 | 95 | } |
@@ -126,8 +125,7 @@ discard block |
||
| 126 | 125 | |
| 127 | 126 | $this->inherit_root = $fallback_template_path; |
| 128 | 127 | $this->orig_tpl_inherits_id = true; |
| 129 | - } |
|
| 130 | - else |
|
| 128 | + } else |
|
| 131 | 129 | { |
| 132 | 130 | $this->orig_tpl_inherits_id = false; |
| 133 | 131 | } |
@@ -201,8 +199,7 @@ discard block |
||
| 201 | 199 | } |
| 202 | 200 | |
| 203 | 201 | unset($str[$blocks[$blockcount]]); |
| 204 | - } |
|
| 205 | - else |
|
| 202 | + } else |
|
| 206 | 203 | { |
| 207 | 204 | // Top-level block. |
| 208 | 205 | unset($this->_tpldata[$blockname]); |
@@ -238,8 +235,7 @@ discard block |
||
| 238 | 235 | if ($filename = $this->_tpl_load($handle)) |
| 239 | 236 | { |
| 240 | 237 | ($include_once) ? include_once($filename) : include($filename); |
| 241 | - } |
|
| 242 | - else |
|
| 238 | + } else |
|
| 243 | 239 | { |
| 244 | 240 | eval(' ?>' . $this->compiled_code[$handle] . '<?php '); |
| 245 | 241 | } |
@@ -293,8 +289,7 @@ discard block |
||
| 293 | 289 | if (!file_exists($filename) || @filesize($filename) === 0) |
| 294 | 290 | { |
| 295 | 291 | $recompile = true; |
| 296 | - } |
|
| 297 | - else if ($config->load_tplcompile) |
|
| 292 | + } else if ($config->load_tplcompile) |
|
| 298 | 293 | { |
| 299 | 294 | // No way around it: we need to check inheritance here |
| 300 | 295 | if ($user->theme['template_inherits_id'] && !file_exists($this->files[$handle])) |
@@ -382,15 +377,13 @@ discard block |
||
| 382 | 377 | $this->files[$row['template_filename']] = $file; |
| 383 | 378 | $this->files_inherit[$row['template_filename']] = $file; |
| 384 | 379 | $this->files_template[$row['template_filename']] = $user->theme['template_inherits_id']; |
| 385 | - } |
|
| 386 | - else if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id']) |
|
| 380 | + } else if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id']) |
|
| 387 | 381 | { |
| 388 | 382 | // Ok, we have a situation. There is a file in the subtemplate, but nothing in the DB. We have to fix that. |
| 389 | 383 | $force_reload = true; |
| 390 | 384 | $this->files_template[$row['template_filename']] = $user->theme['template_inherits_id']; |
| 391 | 385 | } |
| 392 | - } |
|
| 393 | - else |
|
| 386 | + } else |
|
| 394 | 387 | { |
| 395 | 388 | $this->files_template[$row['template_filename']] = $user->theme['template_id']; |
| 396 | 389 | } |
@@ -400,8 +393,7 @@ discard block |
||
| 400 | 393 | if ($row['template_filename'] == $this->filename[$handle]) |
| 401 | 394 | { |
| 402 | 395 | $compile->_tpl_load_file($handle, true); |
| 403 | - } |
|
| 404 | - else |
|
| 396 | + } else |
|
| 405 | 397 | { |
| 406 | 398 | $this->files[$row['template_filename']] = $file; |
| 407 | 399 | $this->filename[$row['template_filename']] = $row['template_filename']; |
@@ -416,8 +408,7 @@ discard block |
||
| 416 | 408 | { |
| 417 | 409 | $this->compiled_code[$handle] = $compile->compile(trim($row['template_data'])); |
| 418 | 410 | $compile->compile_write($handle, $this->compiled_code[$handle]); |
| 419 | - } |
|
| 420 | - else |
|
| 411 | + } else |
|
| 421 | 412 | { |
| 422 | 413 | // Only bother compiling if it doesn't already exist |
| 423 | 414 | if (!file_exists($this->cachepath . str_replace('/', '.', $row['template_filename']) . DOT_PHP_EX)) |
@@ -428,8 +419,7 @@ discard block |
||
| 428 | 419 | } |
| 429 | 420 | } |
| 430 | 421 | } |
| 431 | - } |
|
| 432 | - else |
|
| 422 | + } else |
|
| 433 | 423 | { |
| 434 | 424 | $file = $this->root . '/' . $row['template_filename']; |
| 435 | 425 | |
@@ -517,8 +507,7 @@ discard block |
||
| 517 | 507 | // We're adding a new iteration to this block with the given |
| 518 | 508 | // variable assignments. |
| 519 | 509 | $str[$blocks[$blockcount]][] = $vararray; |
| 520 | - } |
|
| 521 | - else |
|
| 510 | + } else |
|
| 522 | 511 | { |
| 523 | 512 | // Top-level block. |
| 524 | 513 | $s_row_count = (isset($this->_tpldata[$blockname])) ? sizeof($this->_tpldata[$blockname]) : 0; |
@@ -618,8 +607,7 @@ discard block |
||
| 618 | 607 | $key = sizeof($this->_tpldata[$blockname]); |
| 619 | 608 | unset($this->_tpldata[$blockname][($key - 1)]['S_LAST_ROW']); |
| 620 | 609 | $vararray['S_LAST_ROW'] = true; |
| 621 | - } |
|
| 622 | - else if ($key === 0) |
|
| 610 | + } else if ($key === 0) |
|
| 623 | 611 | { |
| 624 | 612 | unset($this->_tpldata[$blockname][0]['S_FIRST_ROW']); |
| 625 | 613 | $vararray['S_FIRST_ROW'] = true; |
@@ -719,8 +707,7 @@ discard block |
||
| 719 | 707 | if(!$name) |
| 720 | 708 | { |
| 721 | 709 | $this->assign_vars($values); |
| 722 | - } |
|
| 723 | - else |
|
| 710 | + } else |
|
| 724 | 711 | { |
| 725 | 712 | $this->assign_block_vars($name, $values); |
| 726 | 713 | } |
@@ -151,6 +151,9 @@ |
||
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | |
| 154 | + /** |
|
| 155 | + * @param integer $user_id |
|
| 156 | + */ |
|
| 154 | 157 | public function __construct($user_id) { |
| 155 | 158 | $this->user_change($user_id); |
| 156 | 159 | } |
@@ -116,8 +116,8 @@ discard block |
||
| 116 | 116 | |
| 117 | 117 | $update_cache = false; |
| 118 | 118 | |
| 119 | - if(!empty($this->to_write)) { |
|
| 120 | - foreach($this->to_write as $key => $cork) { |
|
| 119 | + if (!empty($this->to_write)) { |
|
| 120 | + foreach ($this->to_write as $key => $cork) { |
|
| 121 | 121 | $value = is_array($this->data[$key]) ? serialize($this->data[$key]) : $this->data[$key]; // Сериализация для массивов при сохранении в БД |
| 122 | 122 | $this->to_write[$key] = "({$this->user_id}, '" . db_escape($key) . "', '" . db_escape($value) . "')"; |
| 123 | 123 | } |
@@ -128,19 +128,19 @@ discard block |
||
| 128 | 128 | $update_cache = true; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - if(!empty($this->to_delete)) { |
|
| 132 | - foreach($this->to_delete as $key => &$value) { |
|
| 133 | - $value = is_string($key) ? "'". db_escape($key) . "'" : $key; |
|
| 131 | + if (!empty($this->to_delete)) { |
|
| 132 | + foreach ($this->to_delete as $key => &$value) { |
|
| 133 | + $value = is_string($key) ? "'" . db_escape($key) . "'" : $key; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - doquery("DELETE FROM {{player_options}} WHERE `player_id` = {$this->user_id} AND `option_id` IN (". implode(',', $this->to_delete) . ") "); |
|
| 136 | + doquery("DELETE FROM {{player_options}} WHERE `player_id` = {$this->user_id} AND `option_id` IN (" . implode(',', $this->to_delete) . ") "); |
|
| 137 | 137 | // pdump("DELETE FROM {{player_options}} WHERE `player_id` = {$this->user_id} AND `option_id` IN (". implode(',', $this->to_delete) . ") "); |
| 138 | 138 | |
| 139 | 139 | $this->to_delete = array(); |
| 140 | 140 | $update_cache = true; |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - if($update_cache) { |
|
| 143 | + if ($update_cache) { |
|
| 144 | 144 | global $sn_cache; |
| 145 | 145 | |
| 146 | 146 | $field_name = $this->cached_name(); |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | protected function load() { |
| 168 | 168 | global $sn_cache; |
| 169 | 169 | |
| 170 | - if($this->loaded) { |
|
| 170 | + if ($this->loaded) { |
|
| 171 | 171 | return; |
| 172 | 172 | } |
| 173 | 173 | |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | $this->to_write = array(); |
| 176 | 176 | $this->to_delete = array(); |
| 177 | 177 | |
| 178 | - if(!$this->user_id) { |
|
| 178 | + if (!$this->user_id) { |
|
| 179 | 179 | $this->loaded = true; |
| 180 | 180 | return; |
| 181 | 181 | } |
@@ -183,13 +183,13 @@ discard block |
||
| 183 | 183 | $field_name = $this->cached_name(); |
| 184 | 184 | $a_data = $sn_cache->$field_name; |
| 185 | 185 | |
| 186 | - if(!empty($a_data)) { |
|
| 186 | + if (!empty($a_data)) { |
|
| 187 | 187 | $this->data = array_replace_recursive($this->data, $a_data); |
| 188 | 188 | return; |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | $query = doquery("SELECT * FROM `{{player_options}}` WHERE `player_id` = {$this->user_id} FOR UPDATE"); |
| 192 | - while($row = db_fetch($query)) { |
|
| 192 | + while ($row = db_fetch($query)) { |
|
| 193 | 193 | // $this->data[$row['option_id']] = $row['value']; |
| 194 | 194 | $this->data[$row['option_id']] = is_string($row['value']) && ($temp = unserialize($row['value'])) !== false ? $temp : $row['value']; // Десериализация |
| 195 | 195 | } |
@@ -269,14 +269,14 @@ discard block |
||
| 269 | 269 | // Если в массиве индекса только один элемент - значит это просто индекс |
| 270 | 270 | is_array($option_id) && count($option_id) == 1 ? $option_id = reset($option_id) : false; |
| 271 | 271 | |
| 272 | - if(!isset($this->data[is_array($option_id) ? reset($option_id) : $option_id])) { |
|
| 272 | + if (!isset($this->data[is_array($option_id) ? reset($option_id) : $option_id])) { |
|
| 273 | 273 | $this->load(); |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | - if(is_array($option_id)) { |
|
| 276 | + if (is_array($option_id)) { |
|
| 277 | 277 | $result = $this->data; |
| 278 | - foreach($option_id as $sub_key) { |
|
| 279 | - if(!isset($result) || !isset($result[$sub_key])) { |
|
| 278 | + foreach ($option_id as $sub_key) { |
|
| 279 | + if (!isset($result) || !isset($result[$sub_key])) { |
|
| 280 | 280 | $result = null; |
| 281 | 281 | break; |
| 282 | 282 | } |
@@ -296,12 +296,12 @@ discard block |
||
| 296 | 296 | public function __set($option, $value = null) { |
| 297 | 297 | global $sn_cache; |
| 298 | 298 | |
| 299 | - if(empty($option) || !$this->user_id) { |
|
| 299 | + if (empty($option) || !$this->user_id) { |
|
| 300 | 300 | return; |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | // Если в массиве индекса только один элемент - значит это просто индекс |
| 304 | - if(is_array($option) && count($option) == 1) { |
|
| 304 | + if (is_array($option) && count($option) == 1) { |
|
| 305 | 305 | // Разворачиваем его в индекс |
| 306 | 306 | $option = array(reset($option) => $value); |
| 307 | 307 | unset($value); |
@@ -310,13 +310,13 @@ discard block |
||
| 310 | 310 | |
| 311 | 311 | $to_write = array(); |
| 312 | 312 | // Адресация многомерного массива через массив индексов в $option |
| 313 | - if(is_array($option) && isset($value)) { |
|
| 313 | + if (is_array($option) && isset($value)) { |
|
| 314 | 314 | $a_data = &$this->data; |
| 315 | - foreach($option as $option_id) { |
|
| 315 | + foreach ($option as $option_id) { |
|
| 316 | 316 | !is_array($a_data[$option_id]) ? $a_data[$option_id] = array() : false; |
| 317 | 317 | $a_data = &$a_data[$option_id]; |
| 318 | 318 | } |
| 319 | - if($a_data != $value) { |
|
| 319 | + if ($a_data != $value) { |
|
| 320 | 320 | $a_data = $value; |
| 321 | 321 | $to_write[reset($option)] = null; |
| 322 | 322 | } |
@@ -324,10 +324,10 @@ discard block |
||
| 324 | 324 | // Пакетная запись из массива ключ -> значение |
| 325 | 325 | !is_array($option) ? $option = array($option => $value) : false; |
| 326 | 326 | |
| 327 | - foreach($option as $option_id => $option_value) { |
|
| 328 | - if($this->data[$option_id] !== $option_value) { |
|
| 327 | + foreach ($option as $option_id => $option_value) { |
|
| 328 | + if ($this->data[$option_id] !== $option_value) { |
|
| 329 | 329 | // TODO - вынести отдельно в обработчик |
| 330 | - if($option_id == PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON && $option_value == PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON_HIDDEN) { |
|
| 330 | + if ($option_id == PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON && $option_value == PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON_HIDDEN) { |
|
| 331 | 331 | sn_setcookie(SN_COOKIE . '_menu_hidden', '0', time() - PERIOD_WEEK, SN_ROOT_RELATIVE); |
| 332 | 332 | } |
| 333 | 333 | |
@@ -337,11 +337,11 @@ discard block |
||
| 337 | 337 | } |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | - if(!empty($to_write)) { |
|
| 340 | + if (!empty($to_write)) { |
|
| 341 | 341 | $field_name = $this->cached_name(); |
| 342 | 342 | $sn_cache->$field_name = $this->data; |
| 343 | 343 | |
| 344 | - foreach($to_write as $option_id => &$option_value) { |
|
| 344 | + foreach ($to_write as $option_id => &$option_value) { |
|
| 345 | 345 | $option_value = is_array($this->data[$option_id]) ? serialize($this->data[$option_id]) : $this->data[$option_id]; // Сериализация для массивов при сохранении в БД |
| 346 | 346 | $to_write[$option_id] = "({$this->user_id}, '" . db_escape($option_id) . "', '" . db_escape($option_value) . "')"; |
| 347 | 347 | } |
@@ -353,26 +353,26 @@ discard block |
||
| 353 | 353 | protected function load() { |
| 354 | 354 | global $sn_cache; |
| 355 | 355 | |
| 356 | - if($this->loaded) { |
|
| 356 | + if ($this->loaded) { |
|
| 357 | 357 | return; |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | $this->data = $this->defaults; |
| 361 | 361 | |
| 362 | - if(!$this->user_id) { |
|
| 362 | + if (!$this->user_id) { |
|
| 363 | 363 | return; |
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | $field_name = $this->cached_name(); |
| 367 | 367 | $a_data = $sn_cache->$field_name; |
| 368 | 368 | |
| 369 | - if(!empty($a_data)) { |
|
| 369 | + if (!empty($a_data)) { |
|
| 370 | 370 | $this->data = array_replace($this->data, $a_data); |
| 371 | 371 | return; |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | $query = doquery("SELECT * FROM `{{player_options}}` WHERE `player_id` = {$this->user_id} FOR UPDATE"); |
| 375 | - while($row = db_fetch($query)) { |
|
| 375 | + while ($row = db_fetch($query)) { |
|
| 376 | 376 | // $this->data[$row['option_id']] = $row['value']; |
| 377 | 377 | $this->data[$row['option_id']] = is_string($row['value']) && ($temp = unserialize($row['value'])) !== false ? $temp : $row['value']; // Десериализация |
| 378 | 378 | } |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | return $this->__get($offset); |
| 389 | 389 | } |
| 390 | 390 | public function offsetSet($offset, $value) { |
| 391 | - if(!is_null($offset)) { |
|
| 391 | + if (!is_null($offset)) { |
|
| 392 | 392 | // $this->data[$offset] = $value; |
| 393 | 393 | $this->__set($offset, $value); |
| 394 | 394 | } else { |
@@ -11,6 +11,9 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | require_once('db/db_queries.php'); |
| 13 | 13 | |
| 14 | +/** |
|
| 15 | + * @param string $tablename |
|
| 16 | + */ |
|
| 14 | 17 | function db_change_units_perform($query, $tablename, $object_id) { |
| 15 | 18 | $query = implode(',', $query); |
| 16 | 19 | if($query && $object_id) { |
@@ -63,6 +66,9 @@ discard block |
||
| 63 | 66 | db_change_units_perform($query[LOC_USER], 'users', $user['id']); |
| 64 | 67 | db_change_units_perform($query[LOC_PLANET], 'planets', $planet['id']); |
| 65 | 68 | } |
| 69 | +/** |
|
| 70 | + * @param string $table |
|
| 71 | + */ |
|
| 66 | 72 | function sn_db_perform($table, $values, $type = 'insert', $options = false) { |
| 67 | 73 | $mass_perform = false; |
| 68 | 74 | |
@@ -171,11 +177,8 @@ discard block |
||
| 171 | 177 | /** |
| 172 | 178 | * Функция проверяет статус транзакции |
| 173 | 179 | * |
| 174 | - * @param null|true|false $status Должна ли быть запущена транзакция в момент проверки |
|
| 175 | - * <p>null - транзакция НЕ должна быть запущена</p> |
|
| 176 | - * <p>true - транзакция должна быть запущена - для совместимости с $for_update</p> |
|
| 177 | - * <p>false - всё равно - для совместимости с $for_update</p> |
|
| 178 | - * @return bool Текущий статус транзакции |
|
| 180 | + * @param boolean $transaction_should_be_started |
|
| 181 | + * @return null|boolean Текущий статус транзакции |
|
| 179 | 182 | */ |
| 180 | 183 | function sn_db_transaction_check($transaction_should_be_started = null) { |
| 181 | 184 | return classSupernova::db_transaction_check($transaction_should_be_started); |
@@ -169,14 +169,14 @@ |
||
| 169 | 169 | return classSupernova::db_changeset_apply($db_changeset); |
| 170 | 170 | } |
| 171 | 171 | /** |
| 172 | - * Функция проверяет статус транзакции |
|
| 173 | - * |
|
| 174 | - * @param null|true|false $status Должна ли быть запущена транзакция в момент проверки |
|
| 175 | - * <p>null - транзакция НЕ должна быть запущена</p> |
|
| 176 | - * <p>true - транзакция должна быть запущена - для совместимости с $for_update</p> |
|
| 177 | - * <p>false - всё равно - для совместимости с $for_update</p> |
|
| 178 | - * @return bool Текущий статус транзакции |
|
| 179 | - */ |
|
| 172 | + * Функция проверяет статус транзакции |
|
| 173 | + * |
|
| 174 | + * @param null|true|false $status Должна ли быть запущена транзакция в момент проверки |
|
| 175 | + * <p>null - транзакция НЕ должна быть запущена</p> |
|
| 176 | + * <p>true - транзакция должна быть запущена - для совместимости с $for_update</p> |
|
| 177 | + * <p>false - всё равно - для совместимости с $for_update</p> |
|
| 178 | + * @return bool Текущий статус транзакции |
|
| 179 | + */ |
|
| 180 | 180 | function sn_db_transaction_check($transaction_should_be_started = null) { |
| 181 | 181 | return classSupernova::db_transaction_check($transaction_should_be_started); |
| 182 | 182 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | * @copyright 2008-2015 Gorlum for Project "SuperNova.WS" |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -if(!defined('INSIDE')) { |
|
| 8 | +if (!defined('INSIDE')) { |
|
| 9 | 9 | die(); |
| 10 | 10 | } |
| 11 | 11 | |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | function db_change_units_perform($query, $tablename, $object_id) { |
| 15 | 15 | $query = implode(',', $query); |
| 16 | - if($query && $object_id) { |
|
| 16 | + if ($query && $object_id) { |
|
| 17 | 17 | return classSupernova::db_upd_record_by_id($tablename == 'users' ? LOC_USER : LOC_PLANET, $object_id, $query); |
| 18 | 18 | // return doquery("UPDATE {{{$tablename}}} SET {$query} WHERE `id` = '{$object_id}' LIMIT 1;"); |
| 19 | 19 | } |
@@ -30,15 +30,15 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | $group = sn_get_groups('resources_loot'); |
| 32 | 32 | |
| 33 | - foreach($unit_list as $unit_id => $unit_amount) { |
|
| 34 | - if(!in_array($unit_id, $group)) { |
|
| 33 | + foreach ($unit_list as $unit_id => $unit_amount) { |
|
| 34 | + if (!in_array($unit_id, $group)) { |
|
| 35 | 35 | // TODO - remove later |
| 36 | 36 | print('<h1>СООБЩИТЕ ЭТО АДМИНУ: db_change_units() вызван для не-ресурсов!</h1>'); |
| 37 | 37 | pdump(debug_backtrace()); |
| 38 | 38 | die('db_change_units() вызван для не-ресурсов!'); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - if(!$unit_amount) { |
|
| 41 | + if (!$unit_amount) { |
|
| 42 | 42 | continue; |
| 43 | 43 | } |
| 44 | 44 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | $unit_location = sys_get_unit_location($user, $planet, $unit_id); |
| 48 | 48 | |
| 49 | 49 | // Changing value in object |
| 50 | - switch($unit_location) { |
|
| 50 | + switch ($unit_location) { |
|
| 51 | 51 | case LOC_USER: |
| 52 | 52 | $user[$unit_db_name] += $unit_amount; |
| 53 | 53 | break; |
@@ -69,23 +69,23 @@ discard block |
||
| 69 | 69 | $field_set = ''; |
| 70 | 70 | $value_set = ''; |
| 71 | 71 | |
| 72 | - switch($type) { |
|
| 72 | + switch ($type) { |
|
| 73 | 73 | case 'delete': |
| 74 | 74 | $query = 'DELETE FROM'; |
| 75 | 75 | break; |
| 76 | 76 | |
| 77 | 77 | case 'insert': |
| 78 | 78 | $query = 'INSERT INTO'; |
| 79 | - if(isset($options['__multi'])) { |
|
| 79 | + if (isset($options['__multi'])) { |
|
| 80 | 80 | // Here we generate mass-insert set |
| 81 | 81 | break; |
| 82 | 82 | } |
| 83 | 83 | case 'update': |
| 84 | - if(!$query) { |
|
| 84 | + if (!$query) { |
|
| 85 | 85 | $query = 'UPDATE'; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - foreach($values as $field => &$value) { |
|
| 88 | + foreach ($values as $field => &$value) { |
|
| 89 | 89 | $value_type = gettype($value); |
| 90 | 90 | if ($value_type == 'string') { |
| 91 | 91 | $value = "'" . db_escape($value) . "'"; |
@@ -113,12 +113,12 @@ discard block |
||
| 113 | 113 | $field_set['__IS_SAFE'] = true; |
| 114 | 114 | } |
| 115 | 115 | function sn_db_field_set_make_safe($field_set, $serialize = false) { |
| 116 | - if(!is_array($field_set)) { |
|
| 116 | + if (!is_array($field_set)) { |
|
| 117 | 117 | die('$field_set is not an array!'); |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | $result = array(); |
| 121 | - foreach($field_set as $field => $value) { |
|
| 121 | + foreach ($field_set as $field => $value) { |
|
| 122 | 122 | $field = db_escape(trim($field)); |
| 123 | 123 | switch (true) { |
| 124 | 124 | case is_int($value): |
@@ -4,11 +4,20 @@ discard block |
||
| 4 | 4 | { |
| 5 | 5 | return classSupernova::db_get_record_by_id(LOC_PLANET, $planet_id, $for_update, $fields); |
| 6 | 6 | } |
| 7 | +/** |
|
| 8 | + * @param integer $galaxy |
|
| 9 | + * @param integer $system |
|
| 10 | + * @param integer $planet |
|
| 11 | + * @param integer $planet_type |
|
| 12 | + */ |
|
| 7 | 13 | function db_planet_by_gspt_safe($galaxy, $system, $planet, $planet_type, $for_update = false, $fields = '*') |
| 8 | 14 | { |
| 9 | 15 | return classSupernova::db_get_record_list(LOC_PLANET, |
| 10 | 16 | "{{planets}}.`galaxy` = {$galaxy} AND {{planets}}.`system` = {$system} AND {{planets}}.`planet` = {$planet} AND {{planets}}.`planet_type` = {$planet_type}", true); |
| 11 | 17 | } |
| 18 | +/** |
|
| 19 | + * @param integer $planet_type |
|
| 20 | + */ |
|
| 12 | 21 | function db_planet_by_gspt($galaxy, $system, $planet, $planet_type, $for_update = false, $fields = '*') |
| 13 | 22 | { |
| 14 | 23 | $galaxy = intval($galaxy); |
@@ -79,6 +88,9 @@ discard block |
||
| 79 | 88 | return classSupernova::db_get_record_list(LOC_PLANET, |
| 80 | 89 | "`id_owner` = '{$user_row['id']}' {$conditions} ORDER BY {$order_by}"); |
| 81 | 90 | } |
| 91 | +/** |
|
| 92 | + * @param integer $planet_id |
|
| 93 | + */ |
|
| 82 | 94 | function db_planet_list_by_user_or_planet($user_id, $planet_id) { |
| 83 | 95 | if(!($user_id = idval($user_id)) && !($planet_id = idval($planet_id))) return false; |
| 84 | 96 | |
@@ -92,6 +104,9 @@ discard block |
||
| 92 | 104 | if(!($planet_id = idval($planet_id))) return false; |
| 93 | 105 | return classSupernova::db_upd_record_by_id(LOC_PLANET, $planet_id, $set); |
| 94 | 106 | } |
| 107 | +/** |
|
| 108 | + * @param integer $ui_planet_type |
|
| 109 | + */ |
|
| 95 | 110 | function db_planet_set_by_gspt($ui_galaxy, $ui_system, $ui_planet, $ui_planet_type = PT_ALL, $set) |
| 96 | 111 | { |
| 97 | 112 | if(!($set = trim($set))) return false; |
@@ -23,8 +23,7 @@ discard block |
||
| 23 | 23 | $galaxy = isset($vector[$prefix . 'galaxy']) ? intval($vector[$prefix . 'galaxy']) : 0; |
| 24 | 24 | $system = isset($vector[$prefix . 'system']) ? intval($vector[$prefix . 'system']) : 0; |
| 25 | 25 | $planet = isset($vector[$prefix . 'planet']) ? intval($vector[$prefix . 'planet']) : 0; |
| 26 | - $planet_type = isset($vector[$prefix . 'planet_type']) ? intval($vector[$prefix . 'planet_type']) : |
|
| 27 | - (isset($vector[$prefix . 'type']) ? intval($vector[$prefix . 'type']) : 0); |
|
| 26 | + $planet_type = isset($vector[$prefix . 'planet_type']) ? intval($vector[$prefix . 'planet_type']) : (isset($vector[$prefix . 'type']) ? intval($vector[$prefix . 'type']) : 0); |
|
| 28 | 27 | $planet_type = $planet_type == PT_DEBRIS ? PT_PLANET : $planet_type; |
| 29 | 28 | |
| 30 | 29 | return db_planet_by_gspt_safe($galaxy, $system, $planet, $planet_type, $for_update, $fields); |
@@ -32,14 +31,14 @@ discard block |
||
| 32 | 31 | function db_planet_by_parent($parent_id, $for_update = false, $fields = '*') |
| 33 | 32 | { |
| 34 | 33 | //if(!($parent_id = intval($parent_id))) return false; |
| 35 | - if(!($parent_id = idval($parent_id))) return false; |
|
| 34 | + if (!($parent_id = idval($parent_id))) return false; |
|
| 36 | 35 | return classSupernova::db_get_record_list(LOC_PLANET, |
| 37 | 36 | "`parent_planet` = {$parent_id} AND `planet_type` = " . PT_MOON, true); |
| 38 | 37 | } |
| 39 | 38 | function db_planet_by_id_and_owner($planet_id, $owner_id, $for_update = false, $fields = '*') |
| 40 | 39 | { |
| 41 | 40 | //if(!($planet_id = intval($planet_id)) || !($owner_id = intval($owner_id))) return false; |
| 42 | - if(!($planet_id = idval($planet_id)) || !($owner_id = idval($owner_id))) return false; |
|
| 41 | + if (!($planet_id = idval($planet_id)) || !($owner_id = idval($owner_id))) return false; |
|
| 43 | 42 | return classSupernova::db_get_record_list(LOC_PLANET, |
| 44 | 43 | "`id` = {$planet_id} AND `id_owner` = {$owner_id}", true); |
| 45 | 44 | } |
@@ -48,7 +47,7 @@ discard block |
||
| 48 | 47 | function db_planet_list_moon_other($user_id, $this_moon_id) |
| 49 | 48 | { |
| 50 | 49 | // if(!($user_id = intval($user_id)) || !($this_moon_id = intval($this_moon_id))) return false; |
| 51 | - if(!($user_id = idval($user_id)) || !($this_moon_id = idval($this_moon_id))) return false; |
|
| 50 | + if (!($user_id = idval($user_id)) || !($this_moon_id = idval($this_moon_id))) return false; |
|
| 52 | 51 | return classSupernova::db_get_record_list(LOC_PLANET, |
| 53 | 52 | "`planet_type` = " . PT_MOON . " AND `id_owner` = {$user_id} AND `id` != {$this_moon_id}"); |
| 54 | 53 | } |
@@ -61,7 +60,7 @@ discard block |
||
| 61 | 60 | } |
| 62 | 61 | |
| 63 | 62 | function db_planet_list_sorted($user_row, $skip_planet_id = false, $field_list = '', $conditions = '') { |
| 64 | - if(!is_array($user_row)) return false; |
|
| 63 | + if (!is_array($user_row)) return false; |
|
| 65 | 64 | // $field_list = $field_list != '*' ? "{{planets}}.`id`, `name`, `image`, {{planets}}.`galaxy`, {{planets}}.`system`, {{planets}}.`planet`, `planet_type`{$field_list}" : $field_list; |
| 66 | 65 | $conditions .= $skip_planet_id ? " AND `id` <> {$skip_planet_id} " : ''; |
| 67 | 66 | |
@@ -80,7 +79,7 @@ discard block |
||
| 80 | 79 | "`id_owner` = '{$user_row['id']}' {$conditions} ORDER BY {$order_by}"); |
| 81 | 80 | } |
| 82 | 81 | function db_planet_list_by_user_or_planet($user_id, $planet_id) { |
| 83 | - if(!($user_id = idval($user_id)) && !($planet_id = idval($planet_id))) return false; |
|
| 82 | + if (!($user_id = idval($user_id)) && !($planet_id = idval($planet_id))) return false; |
|
| 84 | 83 | |
| 85 | 84 | return classSupernova::db_get_record_list(LOC_PLANET, |
| 86 | 85 | $planet_id = idval($planet_id) ? "{{planets}}.`id` = {$planet_id}" : "`id_owner` = {$user_id}", $planet_id); |
@@ -89,12 +88,12 @@ discard block |
||
| 89 | 88 | function db_planet_set_by_id($planet_id, $set) |
| 90 | 89 | { |
| 91 | 90 | // if(!($planet_id = intval($planet_id))) return false; |
| 92 | - if(!($planet_id = idval($planet_id))) return false; |
|
| 91 | + if (!($planet_id = idval($planet_id))) return false; |
|
| 93 | 92 | return classSupernova::db_upd_record_by_id(LOC_PLANET, $planet_id, $set); |
| 94 | 93 | } |
| 95 | 94 | function db_planet_set_by_gspt($ui_galaxy, $ui_system, $ui_planet, $ui_planet_type = PT_ALL, $set) |
| 96 | 95 | { |
| 97 | - if(!($set = trim($set))) return false; |
|
| 96 | + if (!($set = trim($set))) return false; |
|
| 98 | 97 | |
| 99 | 98 | $si_galaxy = intval($ui_galaxy); |
| 100 | 99 | $si_system = intval($ui_system); |
@@ -106,13 +105,13 @@ discard block |
||
| 106 | 105 | function db_planet_set_by_parent($ui_parent_id, $ss_set) |
| 107 | 106 | { |
| 108 | 107 | //if(!($si_parent_id = intval($ui_parent_id)) || !($ss_set = trim($ss_set))) return false; |
| 109 | - if(!($si_parent_id = idval($ui_parent_id)) || !($ss_set = trim($ss_set))) return false; |
|
| 108 | + if (!($si_parent_id = idval($ui_parent_id)) || !($ss_set = trim($ss_set))) return false; |
|
| 110 | 109 | return classSupernova::db_upd_record_list(LOC_PLANET, "`parent_planet` = {$si_parent_id}", $ss_set); |
| 111 | 110 | } |
| 112 | 111 | function db_planet_set_by_owner($ui_owner_id, $ss_set) |
| 113 | 112 | { |
| 114 | 113 | //if(!($si_owner_id = intval($ui_owner_id)) || !($ss_set = trim($ss_set))) return false; |
| 115 | - if(!($si_owner_id = idval($ui_owner_id)) || !($ss_set = trim($ss_set))) return false; |
|
| 114 | + if (!($si_owner_id = idval($ui_owner_id)) || !($ss_set = trim($ss_set))) return false; |
|
| 116 | 115 | return classSupernova::db_upd_record_list(LOC_PLANET, "`id_owner` = {$si_owner_id}", $ss_set); |
| 117 | 116 | } |
| 118 | 117 | |
@@ -120,7 +119,7 @@ discard block |
||
| 120 | 119 | function db_planet_delete_by_id($planet_id) |
| 121 | 120 | { |
| 122 | 121 | // if(!($planet_id = intval($planet_id))) return false; |
| 123 | - if(!($planet_id = idval($planet_id))) return false; |
|
| 122 | + if (!($planet_id = idval($planet_id))) return false; |
|
| 124 | 123 | classSupernova::db_del_record_by_id(LOC_PLANET, $planet_id); |
| 125 | 124 | classSupernova::db_del_record_list(LOC_UNIT, "`unit_location_type` = " . LOC_PLANET . " AND `unit_location_id` = " . $planet_id); |
| 126 | 125 | // Очереди очистятся автоматически по FOREIGN KEY |
@@ -129,7 +128,7 @@ discard block |
||
| 129 | 128 | function db_planet_list_delete_by_owner($ui_owner_id) |
| 130 | 129 | { |
| 131 | 130 | // if(!($si_owner_id = intval($ui_owner_id))) return false; |
| 132 | - if(!($si_owner_id = idval($ui_owner_id))) return false; |
|
| 131 | + if (!($si_owner_id = idval($ui_owner_id))) return false; |
|
| 133 | 132 | classSupernova::db_del_record_list(LOC_PLANET, "`id_owner` = {$si_owner_id}"); |
| 134 | 133 | classSupernova::db_del_record_list(LOC_UNIT, "`unit_location_type` = " . LOC_PLANET . " AND `unit_player_id` = " . $si_owner_id); |
| 135 | 134 | // Очереди очистятся автоматически по FOREIGN KEY |
@@ -32,14 +32,18 @@ discard block |
||
| 32 | 32 | function db_planet_by_parent($parent_id, $for_update = false, $fields = '*') |
| 33 | 33 | { |
| 34 | 34 | //if(!($parent_id = intval($parent_id))) return false; |
| 35 | - if(!($parent_id = idval($parent_id))) return false; |
|
| 35 | + if(!($parent_id = idval($parent_id))) { |
|
| 36 | + return false; |
|
| 37 | + } |
|
| 36 | 38 | return classSupernova::db_get_record_list(LOC_PLANET, |
| 37 | 39 | "`parent_planet` = {$parent_id} AND `planet_type` = " . PT_MOON, true); |
| 38 | 40 | } |
| 39 | 41 | function db_planet_by_id_and_owner($planet_id, $owner_id, $for_update = false, $fields = '*') |
| 40 | 42 | { |
| 41 | 43 | //if(!($planet_id = intval($planet_id)) || !($owner_id = intval($owner_id))) return false; |
| 42 | - if(!($planet_id = idval($planet_id)) || !($owner_id = idval($owner_id))) return false; |
|
| 44 | + if(!($planet_id = idval($planet_id)) || !($owner_id = idval($owner_id))) { |
|
| 45 | + return false; |
|
| 46 | + } |
|
| 43 | 47 | return classSupernova::db_get_record_list(LOC_PLANET, |
| 44 | 48 | "`id` = {$planet_id} AND `id_owner` = {$owner_id}", true); |
| 45 | 49 | } |
@@ -48,7 +52,9 @@ discard block |
||
| 48 | 52 | function db_planet_list_moon_other($user_id, $this_moon_id) |
| 49 | 53 | { |
| 50 | 54 | // if(!($user_id = intval($user_id)) || !($this_moon_id = intval($this_moon_id))) return false; |
| 51 | - if(!($user_id = idval($user_id)) || !($this_moon_id = idval($this_moon_id))) return false; |
|
| 55 | + if(!($user_id = idval($user_id)) || !($this_moon_id = idval($this_moon_id))) { |
|
| 56 | + return false; |
|
| 57 | + } |
|
| 52 | 58 | return classSupernova::db_get_record_list(LOC_PLANET, |
| 53 | 59 | "`planet_type` = " . PT_MOON . " AND `id_owner` = {$user_id} AND `id` != {$this_moon_id}"); |
| 54 | 60 | } |
@@ -61,7 +67,9 @@ discard block |
||
| 61 | 67 | } |
| 62 | 68 | |
| 63 | 69 | function db_planet_list_sorted($user_row, $skip_planet_id = false, $field_list = '', $conditions = '') { |
| 64 | - if(!is_array($user_row)) return false; |
|
| 70 | + if(!is_array($user_row)) { |
|
| 71 | + return false; |
|
| 72 | + } |
|
| 65 | 73 | // $field_list = $field_list != '*' ? "{{planets}}.`id`, `name`, `image`, {{planets}}.`galaxy`, {{planets}}.`system`, {{planets}}.`planet`, `planet_type`{$field_list}" : $field_list; |
| 66 | 74 | $conditions .= $skip_planet_id ? " AND `id` <> {$skip_planet_id} " : ''; |
| 67 | 75 | |
@@ -80,7 +88,9 @@ discard block |
||
| 80 | 88 | "`id_owner` = '{$user_row['id']}' {$conditions} ORDER BY {$order_by}"); |
| 81 | 89 | } |
| 82 | 90 | function db_planet_list_by_user_or_planet($user_id, $planet_id) { |
| 83 | - if(!($user_id = idval($user_id)) && !($planet_id = idval($planet_id))) return false; |
|
| 91 | + if(!($user_id = idval($user_id)) && !($planet_id = idval($planet_id))) { |
|
| 92 | + return false; |
|
| 93 | + } |
|
| 84 | 94 | |
| 85 | 95 | return classSupernova::db_get_record_list(LOC_PLANET, |
| 86 | 96 | $planet_id = idval($planet_id) ? "{{planets}}.`id` = {$planet_id}" : "`id_owner` = {$user_id}", $planet_id); |
@@ -89,12 +99,16 @@ discard block |
||
| 89 | 99 | function db_planet_set_by_id($planet_id, $set) |
| 90 | 100 | { |
| 91 | 101 | // if(!($planet_id = intval($planet_id))) return false; |
| 92 | - if(!($planet_id = idval($planet_id))) return false; |
|
| 102 | + if(!($planet_id = idval($planet_id))) { |
|
| 103 | + return false; |
|
| 104 | + } |
|
| 93 | 105 | return classSupernova::db_upd_record_by_id(LOC_PLANET, $planet_id, $set); |
| 94 | 106 | } |
| 95 | 107 | function db_planet_set_by_gspt($ui_galaxy, $ui_system, $ui_planet, $ui_planet_type = PT_ALL, $set) |
| 96 | 108 | { |
| 97 | - if(!($set = trim($set))) return false; |
|
| 109 | + if(!($set = trim($set))) { |
|
| 110 | + return false; |
|
| 111 | + } |
|
| 98 | 112 | |
| 99 | 113 | $si_galaxy = intval($ui_galaxy); |
| 100 | 114 | $si_system = intval($ui_system); |
@@ -106,13 +120,17 @@ discard block |
||
| 106 | 120 | function db_planet_set_by_parent($ui_parent_id, $ss_set) |
| 107 | 121 | { |
| 108 | 122 | //if(!($si_parent_id = intval($ui_parent_id)) || !($ss_set = trim($ss_set))) return false; |
| 109 | - if(!($si_parent_id = idval($ui_parent_id)) || !($ss_set = trim($ss_set))) return false; |
|
| 123 | + if(!($si_parent_id = idval($ui_parent_id)) || !($ss_set = trim($ss_set))) { |
|
| 124 | + return false; |
|
| 125 | + } |
|
| 110 | 126 | return classSupernova::db_upd_record_list(LOC_PLANET, "`parent_planet` = {$si_parent_id}", $ss_set); |
| 111 | 127 | } |
| 112 | 128 | function db_planet_set_by_owner($ui_owner_id, $ss_set) |
| 113 | 129 | { |
| 114 | 130 | //if(!($si_owner_id = intval($ui_owner_id)) || !($ss_set = trim($ss_set))) return false; |
| 115 | - if(!($si_owner_id = idval($ui_owner_id)) || !($ss_set = trim($ss_set))) return false; |
|
| 131 | + if(!($si_owner_id = idval($ui_owner_id)) || !($ss_set = trim($ss_set))) { |
|
| 132 | + return false; |
|
| 133 | + } |
|
| 116 | 134 | return classSupernova::db_upd_record_list(LOC_PLANET, "`id_owner` = {$si_owner_id}", $ss_set); |
| 117 | 135 | } |
| 118 | 136 | |
@@ -120,7 +138,9 @@ discard block |
||
| 120 | 138 | function db_planet_delete_by_id($planet_id) |
| 121 | 139 | { |
| 122 | 140 | // if(!($planet_id = intval($planet_id))) return false; |
| 123 | - if(!($planet_id = idval($planet_id))) return false; |
|
| 141 | + if(!($planet_id = idval($planet_id))) { |
|
| 142 | + return false; |
|
| 143 | + } |
|
| 124 | 144 | classSupernova::db_del_record_by_id(LOC_PLANET, $planet_id); |
| 125 | 145 | classSupernova::db_del_record_list(LOC_UNIT, "`unit_location_type` = " . LOC_PLANET . " AND `unit_location_id` = " . $planet_id); |
| 126 | 146 | // Очереди очистятся автоматически по FOREIGN KEY |
@@ -129,7 +149,9 @@ discard block |
||
| 129 | 149 | function db_planet_list_delete_by_owner($ui_owner_id) |
| 130 | 150 | { |
| 131 | 151 | // if(!($si_owner_id = intval($ui_owner_id))) return false; |
| 132 | - if(!($si_owner_id = idval($ui_owner_id))) return false; |
|
| 152 | + if(!($si_owner_id = idval($ui_owner_id))) { |
|
| 153 | + return false; |
|
| 154 | + } |
|
| 133 | 155 | classSupernova::db_del_record_list(LOC_PLANET, "`id_owner` = {$si_owner_id}"); |
| 134 | 156 | classSupernova::db_del_record_list(LOC_UNIT, "`unit_location_type` = " . LOC_PLANET . " AND `unit_player_id` = " . $si_owner_id); |
| 135 | 157 | // Очереди очистятся автоматически по FOREIGN KEY |
@@ -1,5 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | +/** |
|
| 4 | + * @param boolean $player |
|
| 5 | + */ |
|
| 3 | 6 | function db_user_by_id($user_id_unsafe, $for_update = false, $fields = '*', $player = null) { |
| 4 | 7 | return classSupernova::db_get_user_by_id($user_id_unsafe, $for_update, $fields, $player); |
| 5 | 8 | } |
@@ -161,7 +161,7 @@ |
||
| 161 | 161 | !is_array($user_id_list) ? $user_id_list = array($user_id_list) : false; |
| 162 | 162 | |
| 163 | 163 | $user_list = array(); |
| 164 | - foreach($user_id_list as $user_id_unsafe) { |
|
| 164 | + foreach ($user_id_list as $user_id_unsafe) { |
|
| 165 | 165 | $user = db_user_by_id($user_id_unsafe); |
| 166 | 166 | !empty($user) ? $user_list[$user_id_unsafe] = $user : false; |
| 167 | 167 | } |
@@ -10,6 +10,7 @@ discard block |
||
| 10 | 10 | * |
| 11 | 11 | * 1.0 - copyright (c) 2010 by Gorlum for http://supernova.ws |
| 12 | 12 | * @version 1.0 |
| 13 | + * @param integer $lab_require |
|
| 13 | 14 | */ |
| 14 | 15 | function eco_get_lab_max_effective_level(&$user, $lab_require) |
| 15 | 16 | { |
@@ -193,6 +194,9 @@ discard block |
||
| 193 | 194 | return $result; |
| 194 | 195 | } |
| 195 | 196 | |
| 197 | +/** |
|
| 198 | + * @param integer[] $unit_list |
|
| 199 | + */ |
|
| 196 | 200 | function eco_is_builds_in_que($planet_que, $unit_list) |
| 197 | 201 | { |
| 198 | 202 | $eco_is_builds_in_que = false; |
@@ -38,8 +38,7 @@ discard block |
||
| 38 | 38 | if($user['user_as_ally']) |
| 39 | 39 | { |
| 40 | 40 | $lab_level = doquery("SELECT ally_members AS effective_level FROM {{alliance}} WHERE id = {$user['user_as_ally']} LIMIT 1", true); |
| 41 | - } |
|
| 42 | - else |
|
| 41 | + } else |
|
| 43 | 42 | { |
| 44 | 43 | $tech_intergalactic = mrc_get_level($user, false, TECH_RESEARCH) + 1; |
| 45 | 44 | $lab_level['effective_level'] = 0; |
@@ -238,8 +237,7 @@ discard block |
||
| 238 | 237 | //{ |
| 239 | 238 | // $result = true; |
| 240 | 239 | //} |
| 241 | - } |
|
| 242 | - elseif(($unit_id == UNIT_TECHNOLOGIES || in_array($unit_id, sn_get_groups('tech'))) && !$config->BuildLabWhileRun && $planet['que']) |
|
| 240 | + } elseif(($unit_id == UNIT_TECHNOLOGIES || in_array($unit_id, sn_get_groups('tech'))) && !$config->BuildLabWhileRun && $planet['que']) |
|
| 243 | 241 | { |
| 244 | 242 | $result = eco_is_builds_in_que($planet['que'], array(STRUC_LABORATORY, STRUC_LABORATORY_NANO)); |
| 245 | 243 | } |
@@ -13,13 +13,13 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | function eco_get_lab_max_effective_level(&$user, $lab_require) |
| 15 | 15 | { |
| 16 | - if(!$user['user_as_ally'] && !isset($user['laboratories_active'])) |
|
| 16 | + if (!$user['user_as_ally'] && !isset($user['laboratories_active'])) |
|
| 17 | 17 | { |
| 18 | 18 | $user['laboratories_active'] = array(); |
| 19 | 19 | $query = db_unit_list_laboratories($user['id']); |
| 20 | - while($row = db_fetch($query)) |
|
| 20 | + while ($row = db_fetch($query)) |
|
| 21 | 21 | { |
| 22 | - if(!eco_unit_busy($user, $row, UNIT_TECHNOLOGIES)) |
|
| 22 | + if (!eco_unit_busy($user, $row, UNIT_TECHNOLOGIES)) |
|
| 23 | 23 | { |
| 24 | 24 | $row += array( |
| 25 | 25 | STRUC_LABORATORY => $level_lab = mrc_get_level($user, $row, STRUC_LABORATORY), |
@@ -33,9 +33,9 @@ discard block |
||
| 33 | 33 | uasort($user['laboratories_active'], 'eco_lab_sort_effectivness'); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - if(!isset($user['research_effective_level'][$lab_require])) |
|
| 36 | + if (!isset($user['research_effective_level'][$lab_require])) |
|
| 37 | 37 | { |
| 38 | - if($user['user_as_ally']) |
|
| 38 | + if ($user['user_as_ally']) |
|
| 39 | 39 | { |
| 40 | 40 | $lab_level = db_ally_get_ally_count($user); |
| 41 | 41 | } |
@@ -44,13 +44,13 @@ discard block |
||
| 44 | 44 | $tech_intergalactic = mrc_get_level($user, false, TECH_RESEARCH) + 1; |
| 45 | 45 | $lab_level['effective_level'] = 0; |
| 46 | 46 | |
| 47 | - foreach($user['laboratories_active'] as $data) |
|
| 47 | + foreach ($user['laboratories_active'] as $data) |
|
| 48 | 48 | { |
| 49 | - if($tech_intergalactic <= 0) |
|
| 49 | + if ($tech_intergalactic <= 0) |
|
| 50 | 50 | { |
| 51 | 51 | break; |
| 52 | 52 | } |
| 53 | - if($data[STRUC_LABORATORY] >= $lab_require) |
|
| 53 | + if ($data[STRUC_LABORATORY] >= $lab_require) |
|
| 54 | 54 | { |
| 55 | 55 | $lab_level['effective_level'] += $data['laboratory_effective_level']; |
| 56 | 56 | $tech_intergalactic--; |
@@ -79,8 +79,8 @@ discard block |
||
| 79 | 79 | $time = 0; |
| 80 | 80 | $only_dark_matter = 0; |
| 81 | 81 | $cost_in_metal = 0; |
| 82 | - foreach($unit_data[P_COST] as $resource_id => $resource_amount) { |
|
| 83 | - if($resource_id === P_FACTOR || !($resource_cost = $resource_amount * $price_increase)) { |
|
| 82 | + foreach ($unit_data[P_COST] as $resource_id => $resource_amount) { |
|
| 83 | + if ($resource_id === P_FACTOR || !($resource_cost = $resource_amount * $price_increase)) { |
|
| 84 | 84 | continue; |
| 85 | 85 | } |
| 86 | 86 | |
@@ -89,12 +89,12 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | $resource_db_name = pname_resource_name($resource_id); |
| 91 | 91 | $cost_in_metal += $cost[BUILD_CREATE][$resource_id] * $config->__get("rpg_exchange_{$resource_db_name}"); |
| 92 | - if(in_array($resource_id, sn_get_groups('resources_loot'))) { |
|
| 92 | + if (in_array($resource_id, sn_get_groups('resources_loot'))) { |
|
| 93 | 93 | $time += $resource_cost * $config->__get("rpg_exchange_{$resource_db_name}") / $rpg_exchange_deuterium; |
| 94 | 94 | $resource_got = mrc_get_level($user, $planet, $resource_id); |
| 95 | - } elseif($resource_id == RES_DARK_MATTER) { |
|
| 95 | + } elseif ($resource_id == RES_DARK_MATTER) { |
|
| 96 | 96 | $resource_got = mrc_get_level($user, null, $resource_id); |
| 97 | - } elseif($resource_id == RES_ENERGY) { |
|
| 97 | + } elseif ($resource_id == RES_ENERGY) { |
|
| 98 | 98 | $resource_got = max(0, $planet['energy_max'] - $planet['energy_used']); |
| 99 | 99 | } else { |
| 100 | 100 | $resource_got = 0; |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | |
| 108 | 108 | $resources_normalized = 0; |
| 109 | 109 | $resources_loot = sn_get_groups('resources_loot'); |
| 110 | - foreach($resources_loot as $resource_id) { |
|
| 110 | + foreach ($resources_loot as $resource_id) { |
|
| 111 | 111 | $resource_db_name = pname_resource_name($resource_id); |
| 112 | 112 | $resource_got = mrc_get_level($user, $planet, $resource_id); |
| 113 | 113 | $resources_normalized += floor($resource_got) * $config->__get("rpg_exchange_{$resource_db_name}"); |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | $cost[P_OPTIONS][P_TIME_RAW] = $time = $time * 60 * 60 / get_game_speed() / 2500; |
| 126 | 126 | |
| 127 | 127 | // TODO - Вынести в отдельную процедуру расчёт стоимости |
| 128 | - if($only_cost) { |
|
| 128 | + if ($only_cost) { |
|
| 129 | 129 | return $cost; |
| 130 | 130 | } |
| 131 | 131 | |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | $mercenary = 0; |
| 136 | 136 | $cost['RESULT'][BUILD_DESTROY] = BUILD_INDESTRUCTABLE; |
| 137 | - if(in_array($unit_id, sn_get_groups('structures'))) { |
|
| 137 | + if (in_array($unit_id, sn_get_groups('structures'))) { |
|
| 138 | 138 | $time = $time * pow(0.5, mrc_get_level($user, $planet, STRUC_FACTORY_NANO)) / (mrc_get_level($user, $planet, STRUC_FACTORY_ROBOT) + 1); |
| 139 | 139 | $mercenary = MRC_ENGINEER; |
| 140 | 140 | $cost['RESULT'][BUILD_DESTROY] = |
@@ -144,23 +144,23 @@ discard block |
||
| 144 | 144 | : BUILD_NO_RESOURCES |
| 145 | 145 | ) |
| 146 | 146 | : BUILD_NO_UNITS; |
| 147 | - } elseif(in_array($unit_id, sn_get_groups('tech'))) { |
|
| 147 | + } elseif (in_array($unit_id, sn_get_groups('tech'))) { |
|
| 148 | 148 | $lab_level = eco_get_lab_max_effective_level($user, intval($unit_data['require'][STRUC_LABORATORY])); |
| 149 | 149 | $time = $time / $lab_level; |
| 150 | 150 | $mercenary = MRC_ACADEMIC; |
| 151 | - } elseif(in_array($unit_id, sn_get_groups('defense'))) { |
|
| 152 | - $time = $time * pow(0.5, mrc_get_level($user, $planet, STRUC_FACTORY_NANO)) / (mrc_get_level($user, $planet, STRUC_FACTORY_HANGAR) + 1) ; |
|
| 151 | + } elseif (in_array($unit_id, sn_get_groups('defense'))) { |
|
| 152 | + $time = $time * pow(0.5, mrc_get_level($user, $planet, STRUC_FACTORY_NANO)) / (mrc_get_level($user, $planet, STRUC_FACTORY_HANGAR) + 1); |
|
| 153 | 153 | $mercenary = MRC_FORTIFIER; |
| 154 | - } elseif(in_array($unit_id, sn_get_groups('fleet'))) { |
|
| 154 | + } elseif (in_array($unit_id, sn_get_groups('fleet'))) { |
|
| 155 | 155 | $time = $time * pow(0.5, mrc_get_level($user, $planet, STRUC_FACTORY_NANO)) / (mrc_get_level($user, $planet, STRUC_FACTORY_HANGAR) + 1); |
| 156 | 156 | $mercenary = MRC_ENGINEER; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - if($mercenary) { |
|
| 159 | + if ($mercenary) { |
|
| 160 | 160 | $time = $time / mrc_modify_value($user, $planet, $mercenary, 1); |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - if(in_array($unit_id, sn_get_groups('governors')) || $only_dark_matter) { |
|
| 163 | + if (in_array($unit_id, sn_get_groups('governors')) || $only_dark_matter) { |
|
| 164 | 164 | $cost[RES_TIME][BUILD_CREATE] = $cost[RES_TIME][BUILD_DESTROY] = 0; |
| 165 | 165 | } else { |
| 166 | 166 | $cost[RES_TIME][BUILD_CREATE] = round($time >= 1 ? $time : 1); |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | return $cost; |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | -function eco_can_build_unit($user, $planet, $unit_id){return sn_function_call(__FUNCTION__, array($user, $planet, $unit_id, &$result));} |
|
| 173 | +function eco_can_build_unit($user, $planet, $unit_id) {return sn_function_call(__FUNCTION__, array($user, $planet, $unit_id, &$result)); } |
|
| 174 | 174 | function sn_eco_can_build_unit($user, $planet, $unit_id, &$result) { |
| 175 | 175 | global $config; |
| 176 | 176 | |
@@ -178,11 +178,11 @@ discard block |
||
| 178 | 178 | $result = $result == BUILD_ALLOWED && eco_unit_busy($user, $planet, $unit_id) ? BUILD_UNIT_BUSY : $result; |
| 179 | 179 | |
| 180 | 180 | $unit_param = get_unit_param($unit_id); |
| 181 | - if($unit_param[P_UNIT_TYPE] != UNIT_MERCENARIES || !$config->empire_mercenary_temporary) { |
|
| 181 | + if ($unit_param[P_UNIT_TYPE] != UNIT_MERCENARIES || !$config->empire_mercenary_temporary) { |
|
| 182 | 182 | $requirement = &$unit_param[P_REQUIRE]; |
| 183 | - if($result == BUILD_ALLOWED && $requirement) { |
|
| 184 | - foreach($requirement as $require_id => $require_level) { |
|
| 185 | - if(mrc_get_level($user, $planet, $require_id) < $require_level) { |
|
| 183 | + if ($result == BUILD_ALLOWED && $requirement) { |
|
| 184 | + foreach ($requirement as $require_id => $require_level) { |
|
| 185 | + if (mrc_get_level($user, $planet, $require_id) < $require_level) { |
|
| 186 | 186 | $result = BUILD_REQUIRE_NOT_MEET; |
| 187 | 187 | break; |
| 188 | 188 | } |
@@ -199,12 +199,12 @@ discard block |
||
| 199 | 199 | |
| 200 | 200 | $unit_list = is_array($unit_list) ? $unit_list : array($unit_list => $unit_list); |
| 201 | 201 | $planet_que = explode(';', $planet_que); |
| 202 | - foreach($planet_que as $planet_que_item) |
|
| 202 | + foreach ($planet_que as $planet_que_item) |
|
| 203 | 203 | { |
| 204 | - if($planet_que_item) |
|
| 204 | + if ($planet_que_item) |
|
| 205 | 205 | { |
| 206 | 206 | list($planet_que_item) = explode(',', $planet_que_item); |
| 207 | - if(in_array($planet_que_item, $unit_list)) |
|
| 207 | + if (in_array($planet_que_item, $unit_list)) |
|
| 208 | 208 | { |
| 209 | 209 | $eco_is_builds_in_que = true; |
| 210 | 210 | break; |
@@ -215,21 +215,21 @@ discard block |
||
| 215 | 215 | return $eco_is_builds_in_que; |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | -function eco_unit_busy(&$user, &$planet, $unit_id){return sn_function_call(__FUNCTION__, array(&$user, &$planet, $unit_id, &$result));} |
|
| 218 | +function eco_unit_busy(&$user, &$planet, $unit_id) {return sn_function_call(__FUNCTION__, array(&$user, &$planet, $unit_id, &$result)); } |
|
| 219 | 219 | function sn_eco_unit_busy(&$user, &$planet, $unit_id, &$result) |
| 220 | 220 | { |
| 221 | 221 | global $config; |
| 222 | 222 | |
| 223 | 223 | $result = isset($result) ? $result : false; |
| 224 | - if(!$result) |
|
| 224 | + if (!$result) |
|
| 225 | 225 | { |
| 226 | - if(($unit_id == STRUC_LABORATORY || $unit_id == STRUC_LABORATORY_NANO) && !$config->BuildLabWhileRun) |
|
| 226 | + if (($unit_id == STRUC_LABORATORY || $unit_id == STRUC_LABORATORY_NANO) && !$config->BuildLabWhileRun) |
|
| 227 | 227 | { |
| 228 | 228 | $global_que = que_get($user['id'], $planet['id'], QUE_RESEARCH, false); |
| 229 | - if(is_array($global_que['ques'][QUE_RESEARCH][$user['id']])) |
|
| 229 | + if (is_array($global_que['ques'][QUE_RESEARCH][$user['id']])) |
|
| 230 | 230 | { |
| 231 | 231 | $first_element = reset($global_que['ques'][QUE_RESEARCH][$user['id']]); |
| 232 | - if(is_array($first_element)) |
|
| 232 | + if (is_array($first_element)) |
|
| 233 | 233 | { |
| 234 | 234 | $result = true; |
| 235 | 235 | } |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | // $result = true; |
| 240 | 240 | //} |
| 241 | 241 | } |
| 242 | - elseif(($unit_id == UNIT_TECHNOLOGIES || in_array($unit_id, sn_get_groups('tech'))) && !$config->BuildLabWhileRun && $planet['que']) |
|
| 242 | + elseif (($unit_id == UNIT_TECHNOLOGIES || in_array($unit_id, sn_get_groups('tech'))) && !$config->BuildLabWhileRun && $planet['que']) |
|
| 243 | 243 | { |
| 244 | 244 | $result = eco_is_builds_in_que($planet['que'], array(STRUC_LABORATORY, STRUC_LABORATORY_NANO)); |
| 245 | 245 | } |
@@ -55,6 +55,9 @@ discard block |
||
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | |
| 58 | +/** |
|
| 59 | + * @param integer $build_mode |
|
| 60 | + */ |
|
| 58 | 61 | function que_build($user, $planet, $build_mode = BUILD_CREATE, $redirect = true) { |
| 59 | 62 | global $lang, $config; |
| 60 | 63 | |
@@ -378,6 +381,9 @@ discard block |
||
| 378 | 381 | return classSupernova::db_que_list_by_type_location($user_id, $planet_id, $que_type, $for_update); |
| 379 | 382 | } |
| 380 | 383 | |
| 384 | +/** |
|
| 385 | + * @param integer $unit_id |
|
| 386 | + */ |
|
| 381 | 387 | function que_add_unit($unit_id, $user = array(), $planet = array(), $build_data, $unit_level = 0, $unit_amount = 1, $build_mode = BUILD_CREATE) { |
| 382 | 388 | // TODO Унифицировать проверки |
| 383 | 389 | |
@@ -458,8 +458,7 @@ |
||
| 458 | 458 | |
| 459 | 459 | if(is_numeric($planet['id'])) { |
| 460 | 460 | db_planet_set_by_id($planet['id'], "`que_processed` = UNIX_TIMESTAMP(NOW())"); |
| 461 | - } |
|
| 462 | - elseif(is_numeric($user['id'])) { |
|
| 461 | + } elseif(is_numeric($user['id'])) { |
|
| 463 | 462 | db_user_set_by_id($user['id'], '`que_processed` = UNIX_TIMESTAMP(NOW())'); |
| 464 | 463 | } |
| 465 | 464 | |
@@ -2,8 +2,8 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | function que_get_unit_que($unit_id) { |
| 4 | 4 | $que_type = false; |
| 5 | - foreach(sn_get_groups('ques') as $que_id => $que_data) { |
|
| 6 | - if(in_array($unit_id, $que_data['unit_list'])) { |
|
| 5 | + foreach (sn_get_groups('ques') as $que_id => $que_data) { |
|
| 6 | + if (in_array($unit_id, $que_data['unit_list'])) { |
|
| 7 | 7 | $que_type = $que_id; |
| 8 | 8 | break; |
| 9 | 9 | } |
@@ -16,14 +16,14 @@ discard block |
||
| 16 | 16 | function que_get_max_que_length($user, $planet, $que_id, $que_data = null) { |
| 17 | 17 | global $config; |
| 18 | 18 | |
| 19 | - if(empty($que_data)) { |
|
| 19 | + if (empty($que_data)) { |
|
| 20 | 20 | $que_data = sn_get_groups('ques'); |
| 21 | 21 | $que_data = $que_data[$que_id]; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
| 25 | 25 | $que_length = 1; |
| 26 | - switch($que_id) { |
|
| 26 | + switch ($que_id) { |
|
| 27 | 27 | case QUE_RESEARCH: |
| 28 | 28 | $que_length = $config->server_que_length_research + mrc_get_level($user, '', UNIT_PREMIUM); // TODO - вынести в модуль |
| 29 | 29 | break; |
@@ -37,8 +37,8 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | function eco_que_str2arr($que_str) { |
| 39 | 39 | $que_arr = explode(';', $que_str); |
| 40 | - foreach($que_arr as $que_index => &$que_item) { |
|
| 41 | - if($que_item) { |
|
| 40 | + foreach ($que_arr as $que_index => &$que_item) { |
|
| 41 | + if ($que_item) { |
|
| 42 | 42 | $que_item = explode(',', $que_item); |
| 43 | 43 | } else { |
| 44 | 44 | unset($que_arr[$que_index]); |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | function eco_que_arr2str($que_arr) { |
| 51 | - foreach($que_arr as &$que_item) { |
|
| 51 | + foreach ($que_arr as &$que_item) { |
|
| 52 | 52 | $que_item = implode(',', $que_item); |
| 53 | 53 | } |
| 54 | 54 | return implode(';', $que_arr); |
@@ -59,14 +59,14 @@ discard block |
||
| 59 | 59 | global $lang, $config; |
| 60 | 60 | |
| 61 | 61 | $is_autoconvert = false; |
| 62 | - if($build_mode == BUILD_AUTOCONVERT || sys_get_param_int('auto_convert')) { |
|
| 62 | + if ($build_mode == BUILD_AUTOCONVERT || sys_get_param_int('auto_convert')) { |
|
| 63 | 63 | $build_mode = BUILD_CREATE; |
| 64 | 64 | $is_autoconvert = true; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | $unit_amount_qued = 0; |
| 68 | 68 | try { |
| 69 | - if(!$user['id']) { |
|
| 69 | + if (!$user['id']) { |
|
| 70 | 70 | throw new exception('{Нет идентификатора пользователя - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION |
| 71 | 71 | } |
| 72 | 72 | |
@@ -77,16 +77,16 @@ discard block |
||
| 77 | 77 | foreach($unit_list as $unit_id => $unit_amount) if($unit_amount) break; |
| 78 | 78 | } |
| 79 | 79 | */ |
| 80 | - if(!$unit_id) { |
|
| 80 | + if (!$unit_id) { |
|
| 81 | 81 | throw new exception('{Нет идентификатора юнита - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | $que_id = que_get_unit_que($unit_id); |
| 85 | - if(!$que_id) { |
|
| 85 | + if (!$que_id) { |
|
| 86 | 86 | throw new exception('{Неправильный тип очереди - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - if($build_mode == BUILD_DESTROY && $que_id != QUE_STRUCTURES) { |
|
| 89 | + if ($build_mode == BUILD_DESTROY && $que_id != QUE_STRUCTURES) { |
|
| 90 | 90 | throw new exception('{Уничтожать можно только здания на планете}', ERR_ERROR); // TODO EXCEPTION |
| 91 | 91 | } |
| 92 | 92 | |
@@ -94,11 +94,11 @@ discard block |
||
| 94 | 94 | $que_data = $que_data[$que_id]; |
| 95 | 95 | |
| 96 | 96 | // TODO Переделать под подочереди |
| 97 | - if($que_id == QUE_STRUCTURES) { |
|
| 97 | + if ($que_id == QUE_STRUCTURES) { |
|
| 98 | 98 | $sn_groups_build_allow = sn_get_groups('build_allow'); |
| 99 | 99 | $que_data['unit_list'] = $sn_groups_build_allow[$planet['planet_type']]; |
| 100 | 100 | |
| 101 | - if(!isset($que_data['unit_list'][$unit_id])) { |
|
| 101 | + if (!isset($que_data['unit_list'][$unit_id])) { |
|
| 102 | 102 | throw new exception('{Это здание нельзя строить на ' . ($planet['planet_type'] == PT_PLANET ? 'планете' : 'луне'), ERR_ERROR); // TODO EXCEPTION |
| 103 | 103 | } |
| 104 | 104 | } |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | // Это нужно, что бы заблокировать пользователя и работу с очередями |
| 120 | 120 | $user = db_user_by_id($user['id']); |
| 121 | 121 | // Это нужно, что бы заблокировать планету от списания ресурсов |
| 122 | - if(isset($planet['id']) && $planet['id']) { |
|
| 122 | + if (isset($planet['id']) && $planet['id']) { |
|
| 123 | 123 | $planet = db_planet_by_id($planet['id'], true); |
| 124 | 124 | } else { |
| 125 | 125 | $planet['id'] = 0; |
@@ -131,17 +131,17 @@ discard block |
||
| 131 | 131 | $in_que = &$que['in_que'][$que_id][$user['id']][$planet_id]; |
| 132 | 132 | $que_max_length = que_get_max_que_length($user, $planet, $que_id, $que_data); |
| 133 | 133 | // TODO Добавить вызовы функций проверок текущей и максимальной длин очередей |
| 134 | - if(count($in_que) >= $que_max_length) { |
|
| 134 | + if (count($in_que) >= $que_max_length) { |
|
| 135 | 135 | throw new exception('{Все слоты очереди заняты}', ERR_ERROR); // TODO EXCEPTION |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | // TODO Отдельно посмотреть на уничтожение зданий - что бы можно было уничтожать их без планов |
| 139 | - switch(eco_can_build_unit($user, $planet, $unit_id)) { |
|
| 139 | + switch (eco_can_build_unit($user, $planet, $unit_id)) { |
|
| 140 | 140 | case BUILD_ALLOWED: break; |
| 141 | 141 | case BUILD_UNIT_BUSY: throw new exception('{Строение занято}', ERR_ERROR); break; // TODO EXCEPTION eco_bld_msg_err_laboratory_upgrading |
| 142 | 142 | // case BUILD_REQUIRE_NOT_MEET: |
| 143 | 143 | default: |
| 144 | - if($build_mode == BUILD_CREATE) { |
|
| 144 | + if ($build_mode == BUILD_CREATE) { |
|
| 145 | 145 | throw new exception('{Требования не удовлетворены}', ERR_ERROR); |
| 146 | 146 | } |
| 147 | 147 | break; // TODO EXCEPTION eco_bld_msg_err_requirements_not_meet |
@@ -151,14 +151,14 @@ discard block |
||
| 151 | 151 | $unit_amount_qued = $unit_amount; |
| 152 | 152 | $units_qued = isset($in_que[$unit_id]) ? $in_que[$unit_id] : 0; |
| 153 | 153 | $unit_level = mrc_get_level($user, $planet, $unit_id, true, true) + $units_qued; |
| 154 | - if($unit_max = get_unit_param($unit_id, P_MAX_STACK)) { |
|
| 155 | - if($unit_level >= $unit_max) { |
|
| 154 | + if ($unit_max = get_unit_param($unit_id, P_MAX_STACK)) { |
|
| 155 | + if ($unit_level >= $unit_max) { |
|
| 156 | 156 | throw new exception('{Максимальное количество юнитов данного типа уже достигнуто или будет достигнуто по окончанию очереди}', ERR_ERROR); // TODO EXCEPTION |
| 157 | 157 | } |
| 158 | 158 | $unit_amount = max(0, min($unit_amount, $unit_max - $unit_level)); |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - if($unit_amount < 1) { |
|
| 161 | + if ($unit_amount < 1) { |
|
| 162 | 162 | throw new exception('{Неправильное количество юнитов - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION |
| 163 | 163 | } |
| 164 | 164 | |
@@ -174,21 +174,21 @@ discard block |
||
| 174 | 174 | // { |
| 175 | 175 | // die('Unit busy'); // TODO EXCEPTION |
| 176 | 176 | // } |
| 177 | - if(get_unit_param($unit_id, P_STACKABLE)) { |
|
| 177 | + if (get_unit_param($unit_id, P_STACKABLE)) { |
|
| 178 | 178 | // TODO Поле 'max_Lot_size' для ограничения размера стэка в очереди - то ли в юниты, то ли в очередь |
| 179 | - if(in_array($unit_id, $group_missile = sn_get_groups('missile'))) { |
|
| 179 | + if (in_array($unit_id, $group_missile = sn_get_groups('missile'))) { |
|
| 180 | 180 | // TODO Поле 'container' - указывает на родительску структуру, в которой хранится данный юнит и по вместительности которой нужно применять размер юнита |
| 181 | 181 | $used_silo = 0; |
| 182 | - foreach($group_missile as $missile_id) { |
|
| 182 | + foreach ($group_missile as $missile_id) { |
|
| 183 | 183 | $missile_qued = isset($in_que[$missile_id]) ? $in_que[$missile_id] : 0; |
| 184 | 184 | $used_silo += (mrc_get_level($user, $planet, $missile_id, true, true) + $missile_qued) * get_unit_param($missile_id, P_UNIT_SIZE); |
| 185 | 185 | } |
| 186 | 186 | $free_silo = mrc_get_level($user, $planet, STRUC_SILO) * get_unit_param(STRUC_SILO, P_CAPACITY) - $used_silo; |
| 187 | - if($free_silo <= 0) { |
|
| 187 | + if ($free_silo <= 0) { |
|
| 188 | 188 | throw new exception('{Ракетная шахта уже заполнена или будет заполнена по окончанию очереди}', ERR_ERROR); // TODO EXCEPTION |
| 189 | 189 | } |
| 190 | 190 | $unit_size = get_unit_param($unit_id, P_UNIT_SIZE); |
| 191 | - if($free_silo < $unit_size) { |
|
| 191 | + if ($free_silo < $unit_size) { |
|
| 192 | 192 | throw new exception("{В ракетной шахте нет места для {$lang['tech'][$unit_id]}}", ERR_ERROR); // TODO EXCEPTION |
| 193 | 193 | } |
| 194 | 194 | $unit_amount = max(0, min($unit_amount, floor($free_silo / $unit_size))); |
@@ -196,10 +196,10 @@ discard block |
||
| 196 | 196 | $unit_level = $new_unit_level = 0; |
| 197 | 197 | } else { |
| 198 | 198 | $unit_amount = 1; |
| 199 | - if($que_id == QUE_STRUCTURES) { |
|
| 199 | + if ($que_id == QUE_STRUCTURES) { |
|
| 200 | 200 | // if($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $que['sectors'][$planet['id']] <= 0) |
| 201 | 201 | $sectors_qued = is_array($in_que) ? array_sum($in_que) : 0; |
| 202 | - if($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $sectors_qued <= 0) |
|
| 202 | + if ($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $sectors_qued <= 0) |
|
| 203 | 203 | { |
| 204 | 204 | throw new exception('{Не хватает секторов на планете}', ERR_ERROR); // TODO EXCEPTION |
| 205 | 205 | } |
@@ -217,9 +217,9 @@ discard block |
||
| 217 | 217 | |
| 218 | 218 | $exchange = array(); |
| 219 | 219 | $market_get_autoconvert_cost = market_get_autoconvert_cost(); |
| 220 | - if($is_autoconvert && $build_data[BUILD_AUTOCONVERT]) { |
|
| 220 | + if ($is_autoconvert && $build_data[BUILD_AUTOCONVERT]) { |
|
| 221 | 221 | $dark_matter = mrc_get_level($user, null, RES_DARK_MATTER); |
| 222 | - if(mrc_get_level($user, null, RES_DARK_MATTER) < $market_get_autoconvert_cost) { |
|
| 222 | + if (mrc_get_level($user, null, RES_DARK_MATTER) < $market_get_autoconvert_cost) { |
|
| 223 | 223 | throw new exception("{Нет хватает " . ($market_get_autoconvert_cost - $dark_matter) . "ТМ на постройки с автоконвертацией ресурсов}", ERR_ERROR); // TODO EXCEPTION |
| 224 | 224 | } |
| 225 | 225 | |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | $resource_exchange_rates = array(); |
| 230 | 230 | $resource_diff = array(); |
| 231 | 231 | $all_positive = true; |
| 232 | - foreach($resources_loot as $resource_id) { |
|
| 232 | + foreach ($resources_loot as $resource_id) { |
|
| 233 | 233 | $resource_db_name = pname_resource_name($resource_id); |
| 234 | 234 | $resource_got[$resource_id] = floor(mrc_get_level($user, $planet, $resource_id)); |
| 235 | 235 | $resource_exchange_rates[$resource_id] = $config->__get("rpg_exchange_{$resource_db_name}"); |
@@ -237,15 +237,15 @@ discard block |
||
| 237 | 237 | $all_positive = $all_positive && ($resource_diff[$resource_id] > 0); |
| 238 | 238 | } |
| 239 | 239 | // Нужна автоконвертация |
| 240 | - if($all_positive) { |
|
| 240 | + if ($all_positive) { |
|
| 241 | 241 | $is_autoconvert = false; |
| 242 | 242 | } else { |
| 243 | - foreach($resource_diff as $resource_diff_id => &$resource_diff_amount) { |
|
| 244 | - if($resource_diff_amount >= 0) { |
|
| 243 | + foreach ($resource_diff as $resource_diff_id => &$resource_diff_amount) { |
|
| 244 | + if ($resource_diff_amount >= 0) { |
|
| 245 | 245 | continue; |
| 246 | 246 | } |
| 247 | - foreach($resource_diff as $resource_got_id => &$resource_got_amount) { |
|
| 248 | - if($resource_got_amount <= 0) { |
|
| 247 | + foreach ($resource_diff as $resource_got_id => &$resource_got_amount) { |
|
| 248 | + if ($resource_got_amount <= 0) { |
|
| 249 | 249 | continue; |
| 250 | 250 | } |
| 251 | 251 | $current_exchange = $resource_exchange_rates[$resource_got_id] / $resource_exchange_rates[$resource_diff_id]; |
@@ -261,14 +261,14 @@ discard block |
||
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | $is_autoconvert_ok = true; |
| 264 | - foreach($resource_diff as $resource_diff_amount2) { |
|
| 265 | - if($resource_diff_amount2 < 0) { |
|
| 264 | + foreach ($resource_diff as $resource_diff_amount2) { |
|
| 265 | + if ($resource_diff_amount2 < 0) { |
|
| 266 | 266 | $is_autoconvert_ok = false; |
| 267 | 267 | break; |
| 268 | 268 | } |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - if($is_autoconvert_ok) { |
|
| 271 | + if ($is_autoconvert_ok) { |
|
| 272 | 272 | $build_data['RESULT'][$build_mode] = BUILD_ALLOWED; |
| 273 | 273 | $build_data['CAN'][$build_mode] = $unit_amount; |
| 274 | 274 | } else { |
@@ -277,19 +277,19 @@ discard block |
||
| 277 | 277 | } |
| 278 | 278 | } |
| 279 | 279 | $unit_amount = min($build_data['CAN'][$build_mode], $unit_amount); |
| 280 | - if($unit_amount <= 0) { |
|
| 280 | + if ($unit_amount <= 0) { |
|
| 281 | 281 | throw new exception('{Не хватает ресурсов}', ERR_ERROR); // TODO EXCEPTION |
| 282 | 282 | } |
| 283 | 283 | |
| 284 | - if($new_unit_level < 0) { |
|
| 284 | + if ($new_unit_level < 0) { |
|
| 285 | 285 | throw new exception('{Нельзя уничтожить больше юнитов, чем есть}', ERR_ERROR); // TODO EXCEPTION |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | - if($build_data['RESULT'][$build_mode] != BUILD_ALLOWED) { |
|
| 288 | + if ($build_data['RESULT'][$build_mode] != BUILD_ALLOWED) { |
|
| 289 | 289 | throw new exception('{Строительство блокировано}', ERR_ERROR); // TODO EXCEPTION |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - if($is_autoconvert) { |
|
| 292 | + if ($is_autoconvert) { |
|
| 293 | 293 | ksort($exchange); |
| 294 | 294 | ksort($resource_got); |
| 295 | 295 | db_change_units($user, $planet, array( |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | $unit_amount_qued = 0; |
| 307 | - while($unit_amount > 0 && count($que['ques'][$que_id][$user['id']][$planet_id]) < $que_max_length) { |
|
| 307 | + while ($unit_amount > 0 && count($que['ques'][$que_id][$user['id']][$planet_id]) < $que_max_length) { |
|
| 308 | 308 | $place = min($unit_amount, MAX_FLEET_OR_DEFS_PER_ROW); |
| 309 | 309 | que_add_unit($unit_id, $user, $planet, $build_data, $new_unit_level, $place, $build_mode); |
| 310 | 310 | $unit_amount -= $place; |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | |
| 315 | 315 | sn_db_transaction_commit(); |
| 316 | 316 | |
| 317 | - if($redirect) { |
|
| 317 | + if ($redirect) { |
|
| 318 | 318 | sys_redirect("{$_SERVER['PHP_SELF']}?mode=" . sys_get_param_str('mode') . "&ally_id=" . sys_get_param_id('ally_id')); |
| 319 | 319 | die(); |
| 320 | 320 | } |
@@ -323,7 +323,7 @@ discard block |
||
| 323 | 323 | 'STATUS' => ERR_NONE, |
| 324 | 324 | 'MESSAGE' => '{Строительство начато}', |
| 325 | 325 | ); |
| 326 | - } catch(exception $e) { |
|
| 326 | + } catch (exception $e) { |
|
| 327 | 327 | sn_db_transaction_rollback(); |
| 328 | 328 | $operation_result = array( |
| 329 | 329 | 'STATUS' => in_array($e->getCode(), array(ERR_NONE, ERR_WARNING, ERR_ERROR)) ? $e->getCode() : ERR_ERROR, |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | ); |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - if(!empty($operation_result['MESSAGE'])) { |
|
| 334 | + if (!empty($operation_result['MESSAGE'])) { |
|
| 335 | 335 | $operation_result['MESSAGE'] .= ' ' . ($unit_amount_qued ? $unit_amount_qued : $unit_amount) . 'x[' . $lang['tech'][$unit_id] . ']'; |
| 336 | 336 | } |
| 337 | 337 | |
@@ -345,11 +345,11 @@ discard block |
||
| 345 | 345 | function que_recalculate($old_que) { |
| 346 | 346 | $new_que = array(); |
| 347 | 347 | |
| 348 | - if(!is_array($old_que['items'])) { |
|
| 348 | + if (!is_array($old_que['items'])) { |
|
| 349 | 349 | return $new_que; |
| 350 | 350 | } |
| 351 | - foreach($old_que['items'] as $row) { |
|
| 352 | - if(!isset($row) || !$row || $row['que_unit_amount'] <= 0) { |
|
| 351 | + foreach ($old_que['items'] as $row) { |
|
| 352 | + if (!isset($row) || !$row || $row['que_unit_amount'] <= 0) { |
|
| 353 | 353 | continue; |
| 354 | 354 | } |
| 355 | 355 | |
@@ -360,9 +360,9 @@ discard block |
||
| 360 | 360 | |
| 361 | 361 | $last_id = count($new_que['items']) - 1; |
| 362 | 362 | |
| 363 | - if($row['que_planet_id']) { |
|
| 363 | + if ($row['que_planet_id']) { |
|
| 364 | 364 | $new_que['planets'][$row['que_planet_id']][$row['que_type']][] = &$new_que['items'][$last_id]; |
| 365 | - } elseif($row['que_type'] == QUE_RESEARCH) { |
|
| 365 | + } elseif ($row['que_type'] == QUE_RESEARCH) { |
|
| 366 | 366 | $new_que['players'][$row['que_player_id']][$row['que_type']][] = &$new_que['items'][$last_id]; |
| 367 | 367 | } |
| 368 | 368 | $new_que['ques'][$row['que_type']][$row['que_player_id']][intval($row['que_planet_id'])][] = &$new_que['items'][$last_id]; |
@@ -397,9 +397,9 @@ discard block |
||
| 397 | 397 | $que_type = que_get_unit_que($unit_id); |
| 398 | 398 | $planet_id_origin = $planet['id'] ? $planet['id'] : 'NULL'; |
| 399 | 399 | $planet_id = $que_type == QUE_RESEARCH ? 'NULL' : $planet_id_origin; |
| 400 | - if(is_numeric($planet_id)) { |
|
| 400 | + if (is_numeric($planet_id)) { |
|
| 401 | 401 | db_planet_set_by_id($planet_id, "`que_processed` = UNIX_TIMESTAMP(NOW())"); |
| 402 | - } elseif(is_numeric($user['id'])) { |
|
| 402 | + } elseif (is_numeric($user['id'])) { |
|
| 403 | 403 | db_user_set_by_id($user['id'], '`que_processed` = UNIX_TIMESTAMP(NOW())'); |
| 404 | 404 | } |
| 405 | 405 | |
@@ -429,17 +429,17 @@ discard block |
||
| 429 | 429 | $planet['id'] = $planet['id'] && $que_type !== QUE_RESEARCH ? $planet['id'] : 0; |
| 430 | 430 | $global_que = que_get($user['id'], $planet['id'], $que_type, true); |
| 431 | 431 | |
| 432 | - if(!empty($global_que['ques'][$que_type][$user['id']][$planet['id']])) { |
|
| 432 | + if (!empty($global_que['ques'][$que_type][$user['id']][$planet['id']])) { |
|
| 433 | 433 | $que = array_reverse($global_que['ques'][$que_type][$user['id']][$planet['id']]); |
| 434 | 434 | |
| 435 | - foreach($que as $que_item) { |
|
| 435 | + foreach ($que as $que_item) { |
|
| 436 | 436 | db_que_delete_by_id($que_item['que_id']); |
| 437 | 437 | |
| 438 | - if($que_item['que_planet_id_origin']) { |
|
| 438 | + if ($que_item['que_planet_id_origin']) { |
|
| 439 | 439 | $planet['id'] = $que_item['que_planet_id_origin']; |
| 440 | 440 | } |
| 441 | 441 | |
| 442 | - if(!isset($planets_locked[$planet['id']])) { |
|
| 442 | + if (!isset($planets_locked[$planet['id']])) { |
|
| 443 | 443 | $planets_locked[$planet['id']] = $planet['id'] ? db_planet_by_id($planet['id'], true) : $planet; |
| 444 | 444 | } |
| 445 | 445 | |
@@ -451,15 +451,15 @@ discard block |
||
| 451 | 451 | RES_DEUTERIUM => $build_data[RES_DEUTERIUM] * $que_item['que_unit_amount'], |
| 452 | 452 | )); |
| 453 | 453 | |
| 454 | - if(!$clear) { |
|
| 454 | + if (!$clear) { |
|
| 455 | 455 | break; |
| 456 | 456 | } |
| 457 | 457 | } |
| 458 | 458 | |
| 459 | - if(is_numeric($planet['id'])) { |
|
| 459 | + if (is_numeric($planet['id'])) { |
|
| 460 | 460 | db_planet_set_by_id($planet['id'], "`que_processed` = UNIX_TIMESTAMP(NOW())"); |
| 461 | 461 | } |
| 462 | - elseif(is_numeric($user['id'])) { |
|
| 462 | + elseif (is_numeric($user['id'])) { |
|
| 463 | 463 | db_user_set_by_id($user['id'], '`que_processed` = UNIX_TIMESTAMP(NOW())'); |
| 464 | 464 | } |
| 465 | 465 | |
@@ -504,21 +504,21 @@ discard block |
||
| 504 | 504 | // TODO: Переделать для $que_type === false |
| 505 | 505 | $planet['id'] = $planet['id'] ? $planet['id'] : 0; |
| 506 | 506 | |
| 507 | - if(!is_array($que)) { |
|
| 507 | + if (!is_array($que)) { |
|
| 508 | 508 | $que = que_get($user['id'], $planet['id'], $que_type); |
| 509 | 509 | } |
| 510 | 510 | |
| 511 | - if(is_array($que) && isset($que['items'])) { |
|
| 511 | + if (is_array($que) && isset($que['items'])) { |
|
| 512 | 512 | $que = $que['ques'][$que_type][$user['id']][$planet['id']]; |
| 513 | 513 | } |
| 514 | 514 | |
| 515 | - if($que) { |
|
| 516 | - foreach($que as $que_element) { |
|
| 515 | + if ($que) { |
|
| 516 | + foreach ($que as $que_element) { |
|
| 517 | 517 | $template->assign_block_vars('que', que_tpl_parse_element($que_element, $short_names)); |
| 518 | 518 | } |
| 519 | 519 | } |
| 520 | 520 | |
| 521 | - if($que_type == QUE_RESEARCH) { |
|
| 521 | + if ($que_type == QUE_RESEARCH) { |
|
| 522 | 522 | // TODO Исправить |
| 523 | 523 | // $template->assign_var('RESEARCH_ONGOING', count($global_que[QUE_RESEARCH][0]) >= $config->server_que_length_research); |
| 524 | 524 | } |
@@ -546,7 +546,7 @@ discard block |
||
| 546 | 546 | $user = db_user_by_id($user['id'], true); |
| 547 | 547 | |
| 548 | 548 | $time_left[$user['id']][0] = max(0, $on_time - $user['que_processed']); |
| 549 | - if($planet === null && !$time_left[$user['id']][0]) { |
|
| 549 | + if ($planet === null && !$time_left[$user['id']][0]) { |
|
| 550 | 550 | // TODO |
| 551 | 551 | return $que; |
| 552 | 552 | } |
@@ -555,12 +555,12 @@ discard block |
||
| 555 | 555 | $que_type_id = $planet === null ? QUE_RESEARCH : false; |
| 556 | 556 | $planet = intval(is_array($planet) ? $planet['id'] : $planet); // В $planet у нас теперь только её ID или шаблон null/0/false |
| 557 | 557 | $que = que_get($user['id'], $planet, $que_type_id, true); |
| 558 | - if(empty($que['items'])) { |
|
| 558 | + if (empty($que['items'])) { |
|
| 559 | 559 | return $que; |
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | $planet_list = array(); |
| 563 | - if($planet !== null) { |
|
| 563 | + if ($planet !== null) { |
|
| 564 | 564 | // Если нужно изменять данные на планетах - блокируем планеты и получаем данные о них |
| 565 | 565 | // TODO - от них не надо ничего, кроме ID и que_processed |
| 566 | 566 | $planet_row = db_planet_list_by_user_or_planet($user['id'], $planet); |
@@ -569,21 +569,21 @@ discard block |
||
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | // Теперь в $time_left лежит время обсчета всех очередей по каждой из планеты |
| 572 | - if(array_sum($time_left[$user['id']]) == 0) { |
|
| 572 | + if (array_sum($time_left[$user['id']]) == 0) { |
|
| 573 | 573 | return $que; |
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | $db_changeset = array(); |
| 577 | 577 | $unit_changes = array(); |
| 578 | - foreach($que['items'] as &$que_item) { |
|
| 578 | + foreach ($que['items'] as &$que_item) { |
|
| 579 | 579 | $que_player_id = &$que_item['que_player_id']; |
| 580 | 580 | $que_planet_id = intval($que_item['que_planet_id']); |
| 581 | 581 | |
| 582 | 582 | $que_time_left = &$que['time_left'][$que_player_id][$que_planet_id][$que_item['que_type']]; |
| 583 | - if(!isset($que_time_left)) { |
|
| 583 | + if (!isset($que_time_left)) { |
|
| 584 | 584 | $que_time_left = $time_left[$que_player_id][$que_planet_id]; |
| 585 | 585 | } |
| 586 | - if($que_time_left <= 0 || $que_item['que_unit_amount'] <= 0) { |
|
| 586 | + if ($que_time_left <= 0 || $que_item['que_unit_amount'] <= 0) { |
|
| 587 | 587 | continue; |
| 588 | 588 | } |
| 589 | 589 | // Дальше мы идем, если только осталось время в очереди И юниты к постройке |
@@ -596,7 +596,7 @@ discard block |
||
| 596 | 596 | // Теперь работаем с остатком времени на юните. Оно не может быть равно или меньше нуля |
| 597 | 597 | |
| 598 | 598 | // Если времени в очереди осталось не меньше, чем время текущего юнита - значит мы достроили юнит |
| 599 | - if($que_time_left >= $que_item['que_time_left']) { |
|
| 599 | + if ($que_time_left >= $que_item['que_time_left']) { |
|
| 600 | 600 | // Увеличиваем количество отстроенных юнитов |
| 601 | 601 | $unit_processed++; |
| 602 | 602 | // Вычитаем из времени очереди потраченное на постройку время |
@@ -609,12 +609,12 @@ discard block |
||
| 609 | 609 | $que_item['que_unit_amount'] -= $unit_processed; |
| 610 | 610 | |
| 611 | 611 | // Если еще остались юниты - значит ВСЁ оставшееся время приходится на достройку следующего юнита |
| 612 | - if($que_item['que_unit_amount'] > 0) { |
|
| 612 | + if ($que_item['que_unit_amount'] > 0) { |
|
| 613 | 613 | $que_item['que_time_left'] = $que_item['que_time_left'] - $que_time_left; |
| 614 | 614 | $que_time_left = 0; |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | - if($que_item['que_unit_amount'] <= 0) { |
|
| 617 | + if ($que_item['que_unit_amount'] <= 0) { |
|
| 618 | 618 | $db_changeset['que'][] = array( |
| 619 | 619 | 'action' => SQL_OP_DELETE, |
| 620 | 620 | P_VERSION => 1, |
@@ -640,14 +640,14 @@ discard block |
||
| 640 | 640 | ); |
| 641 | 641 | } |
| 642 | 642 | |
| 643 | - if($unit_processed) { |
|
| 643 | + if ($unit_processed) { |
|
| 644 | 644 | $unit_processed_delta = $unit_processed * ($que_item['que_unit_mode'] == BUILD_CREATE ? 1 : -1); |
| 645 | 645 | $unit_changes[$que_player_id][$que_planet_id][$que_item['que_unit_id']] += $unit_processed_delta; |
| 646 | 646 | } |
| 647 | 647 | } |
| 648 | 648 | |
| 649 | - foreach($time_left as $player_id => $planet_data) { |
|
| 650 | - foreach($planet_data as $planet_id => $time_on_planet) { |
|
| 649 | + foreach ($time_left as $player_id => $planet_data) { |
|
| 650 | + foreach ($planet_data as $planet_id => $time_on_planet) { |
|
| 651 | 651 | $table = $planet_id ? 'planets' : 'users'; |
| 652 | 652 | $id = $planet_id ? $planet_id : $player_id; |
| 653 | 653 | $db_changeset[$table][] = array( |
@@ -663,8 +663,8 @@ discard block |
||
| 663 | 663 | ), |
| 664 | 664 | ); |
| 665 | 665 | |
| 666 | - if(is_array($unit_changes[$player_id][$planet_id])) { |
|
| 667 | - foreach($unit_changes[$player_id][$planet_id] as $unit_id => $unit_amount) { |
|
| 666 | + if (is_array($unit_changes[$player_id][$planet_id])) { |
|
| 667 | + foreach ($unit_changes[$player_id][$planet_id] as $unit_id => $unit_amount) { |
|
| 668 | 668 | $db_changeset['unit'][] = sn_db_unit_changeset_prepare($unit_id, $unit_amount, $user, $planet_id ? $planet_id : null); |
| 669 | 669 | } |
| 670 | 670 | } |
@@ -674,38 +674,38 @@ discard block |
||
| 674 | 674 | $que = que_recalculate($que); |
| 675 | 675 | |
| 676 | 676 | // TODO: Re-enable quests for Alliances |
| 677 | - if(!empty($unit_changes) && !$user['user_as_ally']) { |
|
| 677 | + if (!empty($unit_changes) && !$user['user_as_ally']) { |
|
| 678 | 678 | $quest_list = qst_get_quests($user['id']); |
| 679 | 679 | $quest_triggers = qst_active_triggers($quest_list); |
| 680 | 680 | $quest_rewards = array(); |
| 681 | 681 | |
| 682 | 682 | |
| 683 | 683 | $xp_incoming = array(); |
| 684 | - foreach($unit_changes as $user_id => $planet_changes) { |
|
| 685 | - foreach($planet_changes as $planet_id => $changes) { |
|
| 684 | + foreach ($unit_changes as $user_id => $planet_changes) { |
|
| 685 | + foreach ($planet_changes as $planet_id => $changes) { |
|
| 686 | 686 | $planet_this = $planet_id ? classSupernova::db_get_record_by_id(LOC_PLANET, $planet_id) : array(); |
| 687 | - foreach($changes as $unit_id => $unit_value) { |
|
| 687 | + foreach ($changes as $unit_id => $unit_value) { |
|
| 688 | 688 | $que_id = que_get_unit_que($unit_id); |
| 689 | 689 | $unit_level_new = mrc_get_level($user, $planet_this, $unit_id, false, true) + $unit_value; |
| 690 | - if($que_id == QUE_STRUCTURES || $que_id == QUE_RESEARCH) { |
|
| 690 | + if ($que_id == QUE_STRUCTURES || $que_id == QUE_RESEARCH) { |
|
| 691 | 691 | $build_data = eco_get_build_data($user, $planet_this, $unit_id, $unit_level_new - 1); |
| 692 | 692 | $build_data = $build_data[BUILD_CREATE]; |
| 693 | - foreach(sn_get_groups('resources_loot') as $resource_id) { |
|
| 693 | + foreach (sn_get_groups('resources_loot') as $resource_id) { |
|
| 694 | 694 | $xp_incoming[$que_id] += $build_data[$resource_id]; // TODO - добавить конверсию рейтов обмена |
| 695 | 695 | } |
| 696 | 696 | } |
| 697 | 697 | |
| 698 | - if(is_array($quest_triggers)) { |
|
| 698 | + if (is_array($quest_triggers)) { |
|
| 699 | 699 | // TODO: Check mutiply condition quests |
| 700 | 700 | $quest_trigger_list = array_keys($quest_triggers, $unit_id); |
| 701 | - if(is_array($quest_trigger_list)) { |
|
| 702 | - foreach($quest_trigger_list as $quest_id) { |
|
| 701 | + if (is_array($quest_trigger_list)) { |
|
| 702 | + foreach ($quest_trigger_list as $quest_id) { |
|
| 703 | 703 | $quest_unit_level = $unit_level_new; |
| 704 | - if(get_unit_param($unit_id, P_UNIT_TYPE) == UNIT_SHIPS) { |
|
| 704 | + if (get_unit_param($unit_id, P_UNIT_TYPE) == UNIT_SHIPS) { |
|
| 705 | 705 | $quest_unit_level = db_unit_count_by_user_and_type_and_snid($user_id, 0, $unit_id); |
| 706 | 706 | $quest_unit_level = $quest_unit_level[$unit_id]['qty']; |
| 707 | 707 | } |
| 708 | - if($quest_list[$quest_id]['quest_status_status'] != QUEST_STATUS_COMPLETE && $quest_list[$quest_id]['quest_unit_amount'] <= $quest_unit_level) { |
|
| 708 | + if ($quest_list[$quest_id]['quest_status_status'] != QUEST_STATUS_COMPLETE && $quest_list[$quest_id]['quest_unit_amount'] <= $quest_unit_level) { |
|
| 709 | 709 | $quest_rewards[$quest_id][$user_id][$planet_id] = $quest_list[$quest_id]['quest_rewards_list']; |
| 710 | 710 | $quest_list[$quest_id]['quest_status_status'] = QUEST_STATUS_COMPLETE; |
| 711 | 711 | } |
@@ -718,7 +718,7 @@ discard block |
||
| 718 | 718 | // TODO: Изменить начисление награды за квесты на ту планету, на которой происходил ресеч |
| 719 | 719 | qst_reward($user, $quest_rewards, $quest_list); |
| 720 | 720 | |
| 721 | - foreach($xp_incoming as $que_id => $xp) { |
|
| 721 | + foreach ($xp_incoming as $que_id => $xp) { |
|
| 722 | 722 | rpg_level_up($user, $que_id == QUE_RESEARCH ? RPG_TECH : RPG_STRUCTURE, $xp / 1000); |
| 723 | 723 | } |
| 724 | 724 | } |
@@ -37,6 +37,9 @@ |
||
| 37 | 37 | return $list; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | +/** |
|
| 41 | + * @param integer $message_type |
|
| 42 | + */ |
|
| 40 | 43 | function msg_send_simple_message($owners, $sender, $timestamp, $message_type, $from, $subject, $text, $escaped = false, $force = false) |
| 41 | 44 | { |
| 42 | 45 | global $config, $user, $sn_message_class_list; |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | "ally_id = '{$ally_id}'" . ($ally_rank_id >= 0 ? " AND ally_rank_id = {$ally_rank_id}" : ''), |
| 27 | 27 | false, 'id, username'); |
| 28 | 28 | // while ($u = db_fetch($query)) |
| 29 | - foreach($query as $u) |
|
| 29 | + foreach ($query as $u) |
|
| 30 | 30 | { |
| 31 | 31 | $sendList[] = $u['id']; |
| 32 | 32 | $list .= "<br>{$u['username']} "; |
@@ -41,19 +41,19 @@ discard block |
||
| 41 | 41 | { |
| 42 | 42 | global $config, $user, $sn_message_class_list; |
| 43 | 43 | |
| 44 | - if(!$owners) |
|
| 44 | + if (!$owners) |
|
| 45 | 45 | { |
| 46 | 46 | return; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | $timestamp = $timestamp ? $timestamp : SN_TIME_NOW; |
| 50 | 50 | $sender = intval($sender); |
| 51 | - if(!is_array($owners)) |
|
| 51 | + if (!is_array($owners)) |
|
| 52 | 52 | { |
| 53 | 53 | $owners = array($owners); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - if(!$escaped) |
|
| 56 | + if (!$escaped) |
|
| 57 | 57 | { |
| 58 | 58 | $from = db_escape($from); |
| 59 | 59 | $subject = db_escape($subject); |
@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | $message_class_name_total = $sn_message_class_list[MSG_TYPE_NEW]['name']; |
| 71 | 71 | |
| 72 | - if($owners[0] == '*') |
|
| 72 | + if ($owners[0] == '*') |
|
| 73 | 73 | { |
| 74 | - if($user['authlevel'] < 3) |
|
| 74 | + if ($user['authlevel'] < 3) |
|
| 75 | 75 | { |
| 76 | 76 | return false; |
| 77 | 77 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | |
| 88 | 88 | foreach ($owners as $owner) |
| 89 | 89 | { |
| 90 | - if($user['id'] != $owner) |
|
| 90 | + if ($user['id'] != $owner) |
|
| 91 | 91 | { |
| 92 | 92 | $owner_row = db_user_by_id($owner); |
| 93 | 93 | } |
@@ -97,18 +97,18 @@ discard block |
||
| 97 | 97 | } |
| 98 | 98 | sys_user_options_unpack($owner_row); |
| 99 | 99 | |
| 100 | - if($force || !$message_class_switchable || $owner_row["opt_{$message_class_name}"]) |
|
| 100 | + if ($force || !$message_class_switchable || $owner_row["opt_{$message_class_name}"]) |
|
| 101 | 101 | { |
| 102 | 102 | $insert_values[] = sprintf($insert_template, $owner); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - if($message_class_email && $config->game_email_pm && $owner_row["opt_email_{$message_class_name}"]) |
|
| 105 | + if ($message_class_email && $config->game_email_pm && $owner_row["opt_email_{$message_class_name}"]) |
|
| 106 | 106 | { |
| 107 | 107 | @$result = mymail($owner_row['email'], $subject, $text_unescaped, '', true); |
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - if(empty($insert_values)) |
|
| 111 | + if (empty($insert_values)) |
|
| 112 | 112 | { |
| 113 | 113 | return; |
| 114 | 114 | } |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | } |
| 119 | 119 | db_user_list_set_mass_mail($owners, "`{$message_class_name}` = `{$message_class_name}` + 1, `{$message_class_name_total}` = `{$message_class_name_total}` + 1"); |
| 120 | 120 | |
| 121 | - if(in_array($user['id'], $owners) || $owners[0] == '*') |
|
| 121 | + if (in_array($user['id'], $owners) || $owners[0] == '*') |
|
| 122 | 122 | { |
| 123 | 123 | $user[$message_class_name]++; |
| 124 | 124 | $user[$message_class_name_total]++; |
@@ -79,8 +79,7 @@ discard block |
||
| 79 | 79 | // TODO Добавить $sender - рассылка может быть и от кого-то |
| 80 | 80 | db_message_insert_all($message_type, $from, $subject, $text); |
| 81 | 81 | $owners = array(); |
| 82 | - } |
|
| 83 | - else |
|
| 82 | + } else |
|
| 84 | 83 | { |
| 85 | 84 | $insert_values = array(); |
| 86 | 85 | $insert_template = "('%u'," . str_replace('%', '%%', " '{$sender}', '{$timestamp}', '{$message_type}', '{$from}', '{$subject}', '{$text}')"); |
@@ -90,8 +89,7 @@ discard block |
||
| 90 | 89 | if($user['id'] != $owner) |
| 91 | 90 | { |
| 92 | 91 | $owner_row = db_user_by_id($owner); |
| 93 | - } |
|
| 94 | - else |
|
| 92 | + } else |
|
| 95 | 93 | { |
| 96 | 94 | $owner_row = $user; |
| 97 | 95 | } |
@@ -161,6 +161,9 @@ discard block |
||
| 161 | 161 | return $rows_affected; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | +/** |
|
| 165 | + * @param integer $type |
|
| 166 | + */ |
|
| 164 | 167 | function rpg_level_up(&$user, $type, $xp_to_add = 0) |
| 165 | 168 | { |
| 166 | 169 | $q = 1.03; |
@@ -223,6 +226,10 @@ discard block |
||
| 223 | 226 | } |
| 224 | 227 | } |
| 225 | 228 | |
| 229 | +/** |
|
| 230 | + * @param integer $b1 |
|
| 231 | + * @param double $q |
|
| 232 | + */ |
|
| 226 | 233 | function rpg_xp_for_level($level, $b1, $q) |
| 227 | 234 | { |
| 228 | 235 | return floor($b1 * (pow($q, $level) - 1)/($q - 1)); |
@@ -233,6 +240,9 @@ discard block |
||
| 233 | 240 | return rpg_xp_for_level($level, 50, 1.03); |
| 234 | 241 | } |
| 235 | 242 | |
| 243 | +/** |
|
| 244 | + * @param integer $level |
|
| 245 | + */ |
|
| 236 | 246 | function RPG_get_raider_xp($level) |
| 237 | 247 | { |
| 238 | 248 | return rpg_xp_for_level($level, 10, 1.03); |
@@ -85,28 +85,28 @@ discard block |
||
| 85 | 85 | function rpg_points_change($user_id, $change_type, $dark_matter, $comment = false, $already_changed = false) { |
| 86 | 86 | global $debug, $config, $dm_change_legit, $user; |
| 87 | 87 | |
| 88 | - if(!$user_id) { |
|
| 88 | + if (!$user_id) { |
|
| 89 | 89 | return false; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | $dm_change_legit = true; |
| 93 | 93 | $sn_data_dark_matter_db_name = pname_resource_name(RES_DARK_MATTER); |
| 94 | 94 | |
| 95 | - if($already_changed) { |
|
| 95 | + if ($already_changed) { |
|
| 96 | 96 | $rows_affected = 1; |
| 97 | 97 | } else { |
| 98 | 98 | $changeset = array(); |
| 99 | 99 | $a_user = db_user_by_id($user_id, true); |
| 100 | - if($dark_matter < 0) { |
|
| 100 | + if ($dark_matter < 0) { |
|
| 101 | 101 | $dark_matter_exists = mrc_get_level($a_user, null, RES_DARK_MATTER, false, true); |
| 102 | 102 | $dark_matter_exists < 0 ? $dark_matter_exists = 0 : false; |
| 103 | 103 | $metamatter_to_reduce = -$dark_matter - $dark_matter_exists; |
| 104 | - if($metamatter_to_reduce > 0) { |
|
| 104 | + if ($metamatter_to_reduce > 0) { |
|
| 105 | 105 | $metamatter_exists = mrc_get_level($a_user, null, RES_METAMATTER); |
| 106 | - if($metamatter_exists < $metamatter_to_reduce) { |
|
| 106 | + if ($metamatter_exists < $metamatter_to_reduce) { |
|
| 107 | 107 | $debug->error('Ошибка снятия ТМ - ММ+ТМ меньше, чем сумма для снятия!', 'Ошибка снятия ТМ', LOG_ERR_INT_NOT_ENOUGH_DARK_MATTER); |
| 108 | 108 | } |
| 109 | - if(is_array($comment)) { |
|
| 109 | + if (is_array($comment)) { |
|
| 110 | 110 | $comment = call_user_func_array('sprintf', $comment); |
| 111 | 111 | } |
| 112 | 112 | // mm_points_change($user_id, $change_type, -$metamatter_to_reduce, 'ММ в ТМ: ' . (-$dark_matter) . ' ТМ = ' . $dark_matter_exists . ' ТМ + ' . $metamatter_to_reduce . ' ММ. ' . $comment); |
@@ -121,9 +121,9 @@ discard block |
||
| 121 | 121 | $rows_affected = classSupernova::$db->db_affected_rows(); |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - if($rows_affected || !$dark_matter) { |
|
| 124 | + if ($rows_affected || !$dark_matter) { |
|
| 125 | 125 | $page_url = db_escape($_SERVER['SCRIPT_NAME']); |
| 126 | - if(is_array($comment)) { |
|
| 126 | + if (is_array($comment)) { |
|
| 127 | 127 | $comment = call_user_func_array('sprintf', $comment); |
| 128 | 128 | } |
| 129 | 129 | $comment = db_escape($comment); |
@@ -137,18 +137,18 @@ discard block |
||
| 137 | 137 | {$dark_matter}, '{$comment}', '{$page_url}', {$user_id} |
| 138 | 138 | );"); |
| 139 | 139 | |
| 140 | - if($user['id'] == $user_id) { |
|
| 140 | + if ($user['id'] == $user_id) { |
|
| 141 | 141 | $user['dark_matter'] += $dark_matter; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - if($dark_matter > 0) { |
|
| 144 | + if ($dark_matter > 0) { |
|
| 145 | 145 | $old_referral = doquery("SELECT * FROM {{referrals}} WHERE `id` = {$user_id} LIMIT 1 FOR UPDATE;", '', true); |
| 146 | - if($old_referral['id']) { |
|
| 146 | + if ($old_referral['id']) { |
|
| 147 | 147 | doquery("UPDATE {{referrals}} SET dark_matter = dark_matter + '{$dark_matter}' WHERE `id` = {$user_id} LIMIT 1;"); |
| 148 | 148 | $new_referral = doquery("SELECT * FROM {{referrals}} WHERE `id` = {$user_id} LIMIT 1;", '', true); |
| 149 | 149 | |
| 150 | 150 | $partner_bonus = floor($new_referral['dark_matter'] / $config->rpg_bonus_divisor) - ($old_referral['dark_matter'] >= $config->rpg_bonus_minimum ? floor($old_referral['dark_matter'] / $config->rpg_bonus_divisor) : 0); |
| 151 | - if($partner_bonus > 0 && $new_referral['dark_matter'] >= $config->rpg_bonus_minimum) { |
|
| 151 | + if ($partner_bonus > 0 && $new_referral['dark_matter'] >= $config->rpg_bonus_minimum) { |
|
| 152 | 152 | rpg_points_change($new_referral['id_partner'], RPG_REFERRAL, $partner_bonus, "Incoming From Referral ID {$user_id}"); |
| 153 | 153 | } |
| 154 | 154 | } |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | { |
| 166 | 166 | $q = 1.03; |
| 167 | 167 | |
| 168 | - switch($type) |
|
| 168 | + switch ($type) |
|
| 169 | 169 | { |
| 170 | 170 | case RPG_STRUCTURE: |
| 171 | 171 | $field_level = 'lvl_minier'; |
@@ -203,19 +203,19 @@ discard block |
||
| 203 | 203 | |
| 204 | 204 | $xp = &$user[$field_xp]; |
| 205 | 205 | |
| 206 | - if($xp_to_add) |
|
| 206 | + if ($xp_to_add) |
|
| 207 | 207 | { |
| 208 | 208 | $xp += $xp_to_add; |
| 209 | 209 | db_user_set_by_id($user['id'], "`{$field_xp}` = `{$field_xp}` + '{$xp_to_add}'"); |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | $level = $user[$field_level]; |
| 213 | - while($xp > rpg_xp_for_level($level + 1, $b1, $q)) |
|
| 213 | + while ($xp > rpg_xp_for_level($level + 1, $b1, $q)) |
|
| 214 | 214 | { |
| 215 | 215 | $level++; |
| 216 | 216 | } |
| 217 | 217 | $level -= $user[$field_level]; |
| 218 | - if($level > 0) |
|
| 218 | + if ($level > 0) |
|
| 219 | 219 | { |
| 220 | 220 | db_user_set_by_id($user['id'], "`{$field_level}` = `{$field_level}` + '{$level}'"); |
| 221 | 221 | rpg_points_change($user['id'], $type, $level * 1000, $comment); |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | |
| 226 | 226 | function rpg_xp_for_level($level, $b1, $q) |
| 227 | 227 | { |
| 228 | - return floor($b1 * (pow($q, $level) - 1)/($q - 1)); |
|
| 228 | + return floor($b1 * (pow($q, $level) - 1) / ($q - 1)); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | function rpg_get_miner_xp($level) |