@@ -39,8 +39,8 @@ |
||
| 39 | 39 | 0 => $row['visit_time'], // start |
| 40 | 40 | 1 => $row['visit_time'], // end |
| 41 | 41 | ) |
| 42 | - //: false |
|
| 43 | - ; |
|
| 42 | + //: false |
|
| 43 | + ; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | $session_list = array(); |
@@ -50,52 +50,52 @@ |
||
| 50 | 50 | stat_tpl_assign($template, $who, 'subject', $subject_list, $sn_group_stat_common); |
| 51 | 51 | |
| 52 | 52 | $stat_types = array( |
| 53 | - STAT_TOTAL => array( |
|
| 54 | - 'type' => 'total', |
|
| 55 | - ), |
|
| 53 | + STAT_TOTAL => array( |
|
| 54 | + 'type' => 'total', |
|
| 55 | + ), |
|
| 56 | 56 | |
| 57 | - STAT_FLEET => array( |
|
| 58 | - 'type' => 'fleet', |
|
| 59 | - ), |
|
| 57 | + STAT_FLEET => array( |
|
| 58 | + 'type' => 'fleet', |
|
| 59 | + ), |
|
| 60 | 60 | |
| 61 | - STAT_TECH => array( |
|
| 62 | - 'type' => 'tech', |
|
| 63 | - ), |
|
| 61 | + STAT_TECH => array( |
|
| 62 | + 'type' => 'tech', |
|
| 63 | + ), |
|
| 64 | 64 | |
| 65 | - STAT_BUILDING => array( |
|
| 66 | - 'type' => 'build', |
|
| 67 | - ), |
|
| 65 | + STAT_BUILDING => array( |
|
| 66 | + 'type' => 'build', |
|
| 67 | + ), |
|
| 68 | 68 | |
| 69 | - STAT_DEFENSE => array( |
|
| 70 | - 'type' => 'defs', |
|
| 71 | - ), |
|
| 69 | + STAT_DEFENSE => array( |
|
| 70 | + 'type' => 'defs', |
|
| 71 | + ), |
|
| 72 | 72 | |
| 73 | - STAT_RESOURCE => array( |
|
| 74 | - 'type' => 'res', |
|
| 75 | - ), |
|
| 73 | + STAT_RESOURCE => array( |
|
| 74 | + 'type' => 'res', |
|
| 75 | + ), |
|
| 76 | 76 | |
| 77 | - STAT_RAID_TOTAL => array( |
|
| 78 | - 'type' => 'raids', |
|
| 79 | - ), |
|
| 77 | + STAT_RAID_TOTAL => array( |
|
| 78 | + 'type' => 'raids', |
|
| 79 | + ), |
|
| 80 | 80 | |
| 81 | - STAT_RAID_WON => array( |
|
| 82 | - 'type' => 'raidswin', |
|
| 83 | - ), |
|
| 81 | + STAT_RAID_WON => array( |
|
| 82 | + 'type' => 'raidswin', |
|
| 83 | + ), |
|
| 84 | 84 | |
| 85 | - STAT_RAID_LOST => array( |
|
| 86 | - 'type' => 'raidsloose', |
|
| 87 | - ), |
|
| 85 | + STAT_RAID_LOST => array( |
|
| 86 | + 'type' => 'raidsloose', |
|
| 87 | + ), |
|
| 88 | 88 | |
| 89 | 89 | STAT_LVL_BUILDING => array( |
| 90 | - 'type' => 'lvl_minier', |
|
| 90 | + 'type' => 'lvl_minier', |
|
| 91 | 91 | ), |
| 92 | 92 | |
| 93 | 93 | STAT_LVL_TECH => array( |
| 94 | - 'type' => 'player_rpg_tech_level', |
|
| 94 | + 'type' => 'player_rpg_tech_level', |
|
| 95 | 95 | ), |
| 96 | 96 | |
| 97 | 97 | STAT_LVL_RAID => array( |
| 98 | - 'type' => 'lvl_raid', |
|
| 98 | + 'type' => 'lvl_raid', |
|
| 99 | 99 | ), |
| 100 | 100 | ); |
| 101 | 101 | stat_tpl_assign($template, $type, 'type', $stat_types, $sn_group_stat_common); |
@@ -27,7 +27,7 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | |
| 29 | 29 | if (!defined('INSIDE')) { |
| 30 | - die('Hack attempt!'); |
|
| 30 | + die('Hack attempt!'); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | global $config; |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | if (!defined('INSIDE')) |
| 30 | 30 | { |
| 31 | - die('Hack attempt!'); |
|
| 31 | + die('Hack attempt!'); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | $lang_info = array( |
@@ -689,15 +689,15 @@ discard block |
||
| 689 | 689 | ), |
| 690 | 690 | |
| 691 | 691 | 'months' => array( |
| 692 | - 1 =>'января', |
|
| 693 | - 2 =>'февраля', |
|
| 694 | - 3 =>'марта', |
|
| 695 | - 4 =>'апреля', |
|
| 696 | - 5 =>'мая', |
|
| 697 | - 6 =>'июня', |
|
| 698 | - 7 =>'июля', |
|
| 699 | - 8 =>'августа', |
|
| 700 | - 9 =>'сентября', |
|
| 692 | + 1 =>'января', |
|
| 693 | + 2 =>'февраля', |
|
| 694 | + 3 =>'марта', |
|
| 695 | + 4 =>'апреля', |
|
| 696 | + 5 =>'мая', |
|
| 697 | + 6 =>'июня', |
|
| 698 | + 7 =>'июля', |
|
| 699 | + 8 =>'августа', |
|
| 700 | + 9 =>'сентября', |
|
| 701 | 701 | 10 =>'октября', |
| 702 | 702 | 11 =>'ноября', |
| 703 | 703 | 12 =>'декабря' |
@@ -993,7 +993,7 @@ discard block |
||
| 993 | 993 | PASSWORD_RESTORE_ERROR_ACCOUNT_NOT_EXISTS => 'Внутренняя ошибка - при смене пароля аккаунт не найден! Сообщите об этой ошибке Администрации!', |
| 994 | 994 | AUTH_PASSWORD_RESET_INSIDE_ERROR_NO_ACCOUNT_FOR_CONFIRMATION => 'ВНУТРЕННЯЯ ОШИБКА! Нет аккаунтов для сброса пароля при корректном коде подтверждения! Пожалуйста, сообщите об этой ошибке Администрации Вселенной!', |
| 995 | 995 | LOGIN_ERROR_NO_ACCOUNT_FOR_COOKIE_SET => 'ВНУТРЕННЯЯ ОШИБКА! СООБЩИТЕ АДМИНИСТРАЦИИ! Не установлен аккаунт при cookie_set()! Пожалуйста, сообщите об этой ошибке Администрации Вселенной!', |
| 996 | - ), |
|
| 996 | + ), |
|
| 997 | 997 | |
| 998 | 998 | 'log_reg_email_title' => "Ваша регистрация на сервере %1\$s игры СуперНова", |
| 999 | 999 | 'log_reg_email_text' => "Подтверждение регистрации для %3\$s\r\n\r\n |
@@ -55,9 +55,9 @@ discard block |
||
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | - * Load template source from file |
|
| 59 | - * @access private |
|
| 60 | - */ |
|
| 58 | + * Load template source from file |
|
| 59 | + * @access private |
|
| 60 | + */ |
|
| 61 | 61 | function _tpl_load_file($handle, $store_in_db = false) |
| 62 | 62 | { |
| 63 | 63 | // Try and open template for read |
@@ -100,10 +100,10 @@ discard block |
||
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
| 103 | - * Remove any PHP tags that do not belong, these regular expressions are derived from |
|
| 104 | - * the ones that exist in zend_language_scanner.l |
|
| 105 | - * @access private |
|
| 106 | - */ |
|
| 103 | + * Remove any PHP tags that do not belong, these regular expressions are derived from |
|
| 104 | + * the ones that exist in zend_language_scanner.l |
|
| 105 | + * @access private |
|
| 106 | + */ |
|
| 107 | 107 | function remove_php_tags(&$code) |
| 108 | 108 | { |
| 109 | 109 | // This matches the information gathered from the internal PHP lexer |
@@ -117,9 +117,9 @@ discard block |
||
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
| 120 | - * The all seeing all doing compile method. Parts are inspired by or directly from Smarty |
|
| 121 | - * @access private |
|
| 122 | - */ |
|
| 120 | + * The all seeing all doing compile method. Parts are inspired by or directly from Smarty |
|
| 121 | + * @access private |
|
| 122 | + */ |
|
| 123 | 123 | function compile($code, $no_echo = false, $echo_var = '') |
| 124 | 124 | { |
| 125 | 125 | global $config; |
@@ -290,9 +290,9 @@ discard block |
||
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | /** |
| 293 | - * Compile variables |
|
| 294 | - * @access private |
|
| 295 | - */ |
|
| 293 | + * Compile variables |
|
| 294 | + * @access private |
|
| 295 | + */ |
|
| 296 | 296 | function compile_var_tags(&$text_blocks) |
| 297 | 297 | { |
| 298 | 298 | // including $lang variable |
@@ -359,9 +359,9 @@ discard block |
||
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | /** |
| 362 | - * Compile blocks |
|
| 363 | - * @access private |
|
| 364 | - */ |
|
| 362 | + * Compile blocks |
|
| 363 | + * @access private |
|
| 364 | + */ |
|
| 365 | 365 | function compile_tag_block($tag_args) |
| 366 | 366 | { |
| 367 | 367 | $no_nesting = false; |
@@ -447,14 +447,14 @@ discard block |
||
| 447 | 447 | $tag_template_php .= 'if ($_' . $tag_args . '_count) {'; |
| 448 | 448 | |
| 449 | 449 | /** |
| 450 | - * The following uses foreach for iteration instead of a for loop, foreach is faster but requires PHP to make a copy of the contents of the array which uses more memory |
|
| 451 | - * <code> |
|
| 452 | - * if (!$offset) |
|
| 453 | - * { |
|
| 454 | - * $tag_template_php .= 'foreach (' . $varref . ' as $_' . $tag_args . '_i => $_' . $tag_args . '_val){'; |
|
| 455 | - * } |
|
| 456 | - * </code> |
|
| 457 | - */ |
|
| 450 | + * The following uses foreach for iteration instead of a for loop, foreach is faster but requires PHP to make a copy of the contents of the array which uses more memory |
|
| 451 | + * <code> |
|
| 452 | + * if (!$offset) |
|
| 453 | + * { |
|
| 454 | + * $tag_template_php .= 'foreach (' . $varref . ' as $_' . $tag_args . '_i => $_' . $tag_args . '_val){'; |
|
| 455 | + * } |
|
| 456 | + * </code> |
|
| 457 | + */ |
|
| 458 | 458 | |
| 459 | 459 | $tag_template_php .= 'for ($_' . $tag_args . '_i = ' . $loop_start . '; $_' . $tag_args . '_i < ' . $loop_end . '; ++$_' . $tag_args . '_i){'; |
| 460 | 460 | // $tag_template_php .= '$this->_block_counter["'. $tag_args . '"] = $_' . $tag_args . '_i;'; |
@@ -465,10 +465,10 @@ discard block |
||
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | /** |
| 468 | - * Compile IF tags - much of this is from Smarty with |
|
| 469 | - * some adaptions for our block level methods |
|
| 470 | - * @access private |
|
| 471 | - */ |
|
| 468 | + * Compile IF tags - much of this is from Smarty with |
|
| 469 | + * some adaptions for our block level methods |
|
| 470 | + * @access private |
|
| 471 | + */ |
|
| 472 | 472 | function compile_tag_if($tag_args, $elseif) |
| 473 | 473 | { |
| 474 | 474 | // Tokenize args for 'if' tag. |
@@ -623,9 +623,9 @@ discard block |
||
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | /** |
| 626 | - * Compile DEFINE tags |
|
| 627 | - * @access private |
|
| 628 | - */ |
|
| 626 | + * Compile DEFINE tags |
|
| 627 | + * @access private |
|
| 628 | + */ |
|
| 629 | 629 | function compile_tag_define($tag_args, $op) |
| 630 | 630 | { |
| 631 | 631 | preg_match('#^((?:[a-z0-9\-_]+\.)+)?\$(?=[A-Z])([A-Z0-9_\-]*)(?: = (\'?)([^\']*)(\'?))?$#', $tag_args, $match); |
@@ -676,9 +676,9 @@ discard block |
||
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | /** |
| 679 | - * Compile INCLUDE tag |
|
| 680 | - * @access private |
|
| 681 | - */ |
|
| 679 | + * Compile INCLUDE tag |
|
| 680 | + * @access private |
|
| 681 | + */ |
|
| 682 | 682 | function compile_tag_include($tag_args) |
| 683 | 683 | { |
| 684 | 684 | // Process dynamic includes |
@@ -691,19 +691,19 @@ discard block |
||
| 691 | 691 | } |
| 692 | 692 | |
| 693 | 693 | /** |
| 694 | - * Compile INCLUDE_PHP tag |
|
| 695 | - * @access private |
|
| 696 | - */ |
|
| 694 | + * Compile INCLUDE_PHP tag |
|
| 695 | + * @access private |
|
| 696 | + */ |
|
| 697 | 697 | function compile_tag_include_php($tag_args) |
| 698 | 698 | { |
| 699 | 699 | return "\$this->_php_include('$tag_args');"; |
| 700 | 700 | } |
| 701 | 701 | |
| 702 | 702 | /** |
| 703 | - * parse expression |
|
| 704 | - * This is from Smarty |
|
| 705 | - * @access private |
|
| 706 | - */ |
|
| 703 | + * parse expression |
|
| 704 | + * This is from Smarty |
|
| 705 | + * @access private |
|
| 706 | + */ |
|
| 707 | 707 | function _parse_is_expr($is_arg, $tokens) |
| 708 | 708 | { |
| 709 | 709 | $expr_end = 0; |
@@ -768,13 +768,13 @@ discard block |
||
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | /** |
| 771 | - * Generates a reference to the given variable inside the given (possibly nested) |
|
| 772 | - * block namespace. This is a string of the form: |
|
| 773 | - * ' . $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['varname'] . ' |
|
| 774 | - * It's ready to be inserted into an "echo" line in one of the templates. |
|
| 775 | - * NOTE: expects a trailing "." on the namespace. |
|
| 776 | - * @access private |
|
| 777 | - */ |
|
| 771 | + * Generates a reference to the given variable inside the given (possibly nested) |
|
| 772 | + * block namespace. This is a string of the form: |
|
| 773 | + * ' . $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['varname'] . ' |
|
| 774 | + * It's ready to be inserted into an "echo" line in one of the templates. |
|
| 775 | + * NOTE: expects a trailing "." on the namespace. |
|
| 776 | + * @access private |
|
| 777 | + */ |
|
| 778 | 778 | function generate_block_varref($namespace, $varname, $echo = true, $defop = false) |
| 779 | 779 | { |
| 780 | 780 | // Strip the trailing period. |
@@ -792,14 +792,14 @@ discard block |
||
| 792 | 792 | } |
| 793 | 793 | |
| 794 | 794 | /** |
| 795 | - * Generates a reference to the array of data values for the given |
|
| 796 | - * (possibly nested) block namespace. This is a string of the form: |
|
| 797 | - * $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['$childN'] |
|
| 798 | - * |
|
| 799 | - * If $include_last_iterator is true, then [$_childN_i] will be appended to the form shown above. |
|
| 800 | - * NOTE: does not expect a trailing "." on the blockname. |
|
| 801 | - * @access private |
|
| 802 | - */ |
|
| 795 | + * Generates a reference to the array of data values for the given |
|
| 796 | + * (possibly nested) block namespace. This is a string of the form: |
|
| 797 | + * $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['$childN'] |
|
| 798 | + * |
|
| 799 | + * If $include_last_iterator is true, then [$_childN_i] will be appended to the form shown above. |
|
| 800 | + * NOTE: does not expect a trailing "." on the blockname. |
|
| 801 | + * @access private |
|
| 802 | + */ |
|
| 803 | 803 | function generate_block_data_ref($blockname, $include_last_iterator, $defop = false) |
| 804 | 804 | { |
| 805 | 805 | // Get an array of the blocks involved. |
@@ -835,9 +835,9 @@ discard block |
||
| 835 | 835 | } |
| 836 | 836 | |
| 837 | 837 | /** |
| 838 | - * Write compiled file to cache directory |
|
| 839 | - * @access private |
|
| 840 | - */ |
|
| 838 | + * Write compiled file to cache directory |
|
| 839 | + * @access private |
|
| 840 | + */ |
|
| 841 | 841 | function compile_write($handle, $data) |
| 842 | 842 | { |
| 843 | 843 | $filename = $this->template->cachepath . str_replace('/', '.', $this->template->filename[$handle]) . DOT_PHP_EX; |
@@ -860,9 +860,9 @@ discard block |
||
| 860 | 860 | |
| 861 | 861 | // Gorlum's minifier BOF |
| 862 | 862 | /** |
| 863 | - * Minifies template w/i PHP code by removing extra spaces |
|
| 864 | - * @access private |
|
| 865 | - */ |
|
| 863 | + * Minifies template w/i PHP code by removing extra spaces |
|
| 864 | + * @access private |
|
| 865 | + */ |
|
| 866 | 866 | function minify($html) |
| 867 | 867 | { |
| 868 | 868 | global $config; |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | protected $_repository; |
| 31 | 31 | |
| 32 | - /** |
|
| 32 | + /** |
|
| 33 | 33 | * @var ContainerPlus $_oldRepo |
| 34 | 34 | */ |
| 35 | 35 | protected $_oldRepo; |
@@ -75,121 +75,121 @@ discard block |
||
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | switch ($fleet_page) { |
| 78 | - case 3: |
|
| 78 | + case 3: |
|
| 79 | 79 | |
| 80 | - case 2: |
|
| 81 | - $fleet_group_mr = sys_get_param_id('fleet_group'); |
|
| 82 | - $fleetarray = json_decode(base64_decode(str_rot13(sys_get_param('usedfleet'))), true); |
|
| 83 | - $fleetarray = is_array($fleetarray) ? $fleetarray : array(); |
|
| 80 | + case 2: |
|
| 81 | + $fleet_group_mr = sys_get_param_id('fleet_group'); |
|
| 82 | + $fleetarray = json_decode(base64_decode(str_rot13(sys_get_param('usedfleet'))), true); |
|
| 83 | + $fleetarray = is_array($fleetarray) ? $fleetarray : array(); |
|
| 84 | 84 | |
| 85 | - foreach($fleetarray as $ship_id => &$ship_amount) { |
|
| 86 | - if(!in_array($ship_id, sn_get_groups('fleet')) || (string)floatval($ship_amount) != $ship_amount || $ship_amount < 1) { |
|
| 87 | - $debug->warning('Supplying wrong ship in ship list on fleet page', 'Hack attempt', 302, array('base_dump' => true)); |
|
| 88 | - die(); |
|
| 89 | - } |
|
| 90 | - $ship_amount = floatval($ship_amount); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - $UsedPlanet = false; |
|
| 94 | - $YourPlanet = false; |
|
| 95 | - $missiontype = array(); |
|
| 96 | - if ($planet > classSupernova::$config->game_maxPlanet) { |
|
| 97 | - $target_mission = MT_EXPLORE; |
|
| 98 | - $missiontype[MT_EXPLORE] = $lang['type_mission'][MT_EXPLORE]; |
|
| 99 | - } elseif ($galaxy && $system && $planet) { |
|
| 100 | - $check_type = $planet_type == PT_MOON ? PT_MOON : PT_PLANET; |
|
| 101 | - |
|
| 102 | - $TargetPlanet = DBStaticPlanet::db_planet_by_gspt($galaxy, $system, $planet, $check_type); |
|
| 103 | - |
|
| 104 | - if ($TargetPlanet['id_owner']) { |
|
| 105 | - $UsedPlanet = true; |
|
| 106 | - if ($TargetPlanet['id_owner'] == $user['id']) { |
|
| 107 | - $YourPlanet = true; |
|
| 85 | + foreach($fleetarray as $ship_id => &$ship_amount) { |
|
| 86 | + if(!in_array($ship_id, sn_get_groups('fleet')) || (string)floatval($ship_amount) != $ship_amount || $ship_amount < 1) { |
|
| 87 | + $debug->warning('Supplying wrong ship in ship list on fleet page', 'Hack attempt', 302, array('base_dump' => true)); |
|
| 88 | + die(); |
|
| 108 | 89 | } |
| 90 | + $ship_amount = floatval($ship_amount); |
|
| 109 | 91 | } |
| 110 | 92 | |
| 111 | - if (!$UsedPlanet) { |
|
| 112 | - if ($fleetarray[SHIP_COLONIZER]) { |
|
| 113 | - $missiontype[MT_COLONIZE] = $lang['type_mission'][MT_COLONIZE]; |
|
| 114 | - $target_mission = MT_COLONIZE; |
|
| 115 | - $planet_type = PT_PLANET; |
|
| 116 | - } else { |
|
| 117 | - messageBox ("<font color=\"red\"><b>". $lang['fl_no_planet_type'] ."</b></font>", $lang['fl_error']); |
|
| 118 | - } |
|
| 119 | - } else { |
|
| 120 | - $recyclers = 0; |
|
| 121 | - foreach(sn_get_groups('flt_recyclers') as $recycler_id) { |
|
| 122 | - $recyclers += $fleetarray[$recycler_id]; |
|
| 93 | + $UsedPlanet = false; |
|
| 94 | + $YourPlanet = false; |
|
| 95 | + $missiontype = array(); |
|
| 96 | + if ($planet > classSupernova::$config->game_maxPlanet) { |
|
| 97 | + $target_mission = MT_EXPLORE; |
|
| 98 | + $missiontype[MT_EXPLORE] = $lang['type_mission'][MT_EXPLORE]; |
|
| 99 | + } elseif ($galaxy && $system && $planet) { |
|
| 100 | + $check_type = $planet_type == PT_MOON ? PT_MOON : PT_PLANET; |
|
| 101 | + |
|
| 102 | + $TargetPlanet = DBStaticPlanet::db_planet_by_gspt($galaxy, $system, $planet, $check_type); |
|
| 103 | + |
|
| 104 | + if ($TargetPlanet['id_owner']) { |
|
| 105 | + $UsedPlanet = true; |
|
| 106 | + if ($TargetPlanet['id_owner'] == $user['id']) { |
|
| 107 | + $YourPlanet = true; |
|
| 108 | + } |
|
| 123 | 109 | } |
| 124 | - if ($recyclers > 0 && $planet_type == PT_DEBRIS) { |
|
| 125 | - $target_mission = MT_RECYCLE; |
|
| 126 | - $missiontype[MT_RECYCLE] = $lang['type_mission'][MT_RECYCLE]; |
|
| 127 | - } elseif ($planet_type == PT_PLANET || $planet_type == PT_MOON) { |
|
| 128 | - if ($YourPlanet) { |
|
| 129 | - $missiontype[MT_RELOCATE] = $lang['type_mission'][MT_RELOCATE]; |
|
| 130 | - $missiontype[MT_TRANSPORT] = $lang['type_mission'][MT_TRANSPORT]; |
|
| 110 | + |
|
| 111 | + if (!$UsedPlanet) { |
|
| 112 | + if ($fleetarray[SHIP_COLONIZER]) { |
|
| 113 | + $missiontype[MT_COLONIZE] = $lang['type_mission'][MT_COLONIZE]; |
|
| 114 | + $target_mission = MT_COLONIZE; |
|
| 115 | + $planet_type = PT_PLANET; |
|
| 131 | 116 | } else { |
| 132 | - // Not Your Planet |
|
| 133 | - if ($fleetarray[SHIP_SPY]) { |
|
| 134 | - // Only spy missions if any spy |
|
| 135 | - $missiontype[MT_SPY] = $lang['type_mission'][MT_SPY]; |
|
| 117 | + messageBox ("<font color=\"red\"><b>". $lang['fl_no_planet_type'] ."</b></font>", $lang['fl_error']); |
|
| 118 | + } |
|
| 119 | + } else { |
|
| 120 | + $recyclers = 0; |
|
| 121 | + foreach(sn_get_groups('flt_recyclers') as $recycler_id) { |
|
| 122 | + $recyclers += $fleetarray[$recycler_id]; |
|
| 123 | + } |
|
| 124 | + if ($recyclers > 0 && $planet_type == PT_DEBRIS) { |
|
| 125 | + $target_mission = MT_RECYCLE; |
|
| 126 | + $missiontype[MT_RECYCLE] = $lang['type_mission'][MT_RECYCLE]; |
|
| 127 | + } elseif ($planet_type == PT_PLANET || $planet_type == PT_MOON) { |
|
| 128 | + if ($YourPlanet) { |
|
| 129 | + $missiontype[MT_RELOCATE] = $lang['type_mission'][MT_RELOCATE]; |
|
| 130 | + $missiontype[MT_TRANSPORT] = $lang['type_mission'][MT_TRANSPORT]; |
|
| 136 | 131 | } else { |
| 137 | - // If no spies... |
|
| 138 | - if ($fleet_group_mr) { |
|
| 139 | - $missiontype[MT_AKS] = $lang['type_mission'][MT_AKS]; |
|
| 132 | + // Not Your Planet |
|
| 133 | + if ($fleetarray[SHIP_SPY]) { |
|
| 134 | + // Only spy missions if any spy |
|
| 135 | + $missiontype[MT_SPY] = $lang['type_mission'][MT_SPY]; |
|
| 140 | 136 | } else { |
| 141 | - $missiontype[MT_ATTACK] = $lang['type_mission'][MT_ATTACK]; |
|
| 142 | - $missiontype[MT_TRANSPORT] = $lang['type_mission'][MT_TRANSPORT]; |
|
| 143 | - |
|
| 144 | - $missiontype[MT_HOLD] = $lang['type_mission'][MT_HOLD]; |
|
| 145 | - |
|
| 146 | - if($planet_type == PT_MOON && $fleetarray[SHIP_HUGE_DEATH_STAR]) { |
|
| 147 | - $missiontype[MT_DESTROY] = $lang['type_mission'][MT_DESTROY]; |
|
| 137 | + // If no spies... |
|
| 138 | + if ($fleet_group_mr) { |
|
| 139 | + $missiontype[MT_AKS] = $lang['type_mission'][MT_AKS]; |
|
| 140 | + } else { |
|
| 141 | + $missiontype[MT_ATTACK] = $lang['type_mission'][MT_ATTACK]; |
|
| 142 | + $missiontype[MT_TRANSPORT] = $lang['type_mission'][MT_TRANSPORT]; |
|
| 143 | + |
|
| 144 | + $missiontype[MT_HOLD] = $lang['type_mission'][MT_HOLD]; |
|
| 145 | + |
|
| 146 | + if($planet_type == PT_MOON && $fleetarray[SHIP_HUGE_DEATH_STAR]) { |
|
| 147 | + $missiontype[MT_DESTROY] = $lang['type_mission'][MT_DESTROY]; |
|
| 148 | + } |
|
| 148 | 149 | } |
| 149 | 150 | } |
| 150 | 151 | } |
| 151 | 152 | } |
| 152 | 153 | } |
| 153 | 154 | } |
| 154 | - } |
|
| 155 | - |
|
| 156 | - if (!$target_mission && is_array($missiontype)) { |
|
| 157 | - $target_mission = MT_ATTACK; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | -// $sn_group_missions = sn_get_groups('missions'); |
|
| 161 | -// foreach($sn_group_missions as $mission_id => $cork) { |
|
| 162 | -// $missiontype[$mission_id] = $lang['type_mission'][$mission_id]; |
|
| 163 | -// } |
|
| 164 | -// |
|
| 165 | -// |
|
| 166 | - ksort($missiontype); |
|
| 167 | - |
|
| 168 | - $speed_percent = sys_get_param_int('speed', 10); |
|
| 169 | - $travel_data = flt_travel_data($user, $planetrow, array('galaxy' => $galaxy, 'system' => $system, 'planet' => $planet), $fleetarray, $speed_percent); |
|
| 170 | - |
|
| 171 | -// $fleet_speed = flt_fleet_speed($user, $fleetarray); |
|
| 172 | - $fleet_speed = $travel_data['fleet_speed']; |
|
| 173 | - $distance = $travel_data['distance']; |
|
| 174 | - $duration = $travel_data['duration']; |
|
| 175 | - $consumption = $travel_data['consumption']; |
|
| 176 | - // No Break |
|
| 177 | - |
|
| 178 | - case 1: |
|
| 179 | - if ($galaxy && $system && $planet) { |
|
| 180 | - $check_type = $planet_type == PT_MOON ? PT_MOON : PT_PLANET; |
|
| 181 | - |
|
| 182 | - $TargetPlanet = DBStaticPlanet::db_planet_by_gspt($galaxy, $system, $planet, $check_type); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - case 0: |
|
| 186 | - $template_result += array( |
|
| 187 | - 'thisgalaxy' => $planetrow['galaxy'], |
|
| 188 | - 'thissystem' => $planetrow['system'], |
|
| 189 | - 'thisplanet' => $planetrow['planet'], |
|
| 190 | - 'thisplanet_type' => $planetrow['planet_type'], |
|
| 191 | - ); |
|
| 192 | - // no break |
|
| 155 | + |
|
| 156 | + if (!$target_mission && is_array($missiontype)) { |
|
| 157 | + $target_mission = MT_ATTACK; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + // $sn_group_missions = sn_get_groups('missions'); |
|
| 161 | + // foreach($sn_group_missions as $mission_id => $cork) { |
|
| 162 | + // $missiontype[$mission_id] = $lang['type_mission'][$mission_id]; |
|
| 163 | + // } |
|
| 164 | + // |
|
| 165 | + // |
|
| 166 | + ksort($missiontype); |
|
| 167 | + |
|
| 168 | + $speed_percent = sys_get_param_int('speed', 10); |
|
| 169 | + $travel_data = flt_travel_data($user, $planetrow, array('galaxy' => $galaxy, 'system' => $system, 'planet' => $planet), $fleetarray, $speed_percent); |
|
| 170 | + |
|
| 171 | + // $fleet_speed = flt_fleet_speed($user, $fleetarray); |
|
| 172 | + $fleet_speed = $travel_data['fleet_speed']; |
|
| 173 | + $distance = $travel_data['distance']; |
|
| 174 | + $duration = $travel_data['duration']; |
|
| 175 | + $consumption = $travel_data['consumption']; |
|
| 176 | + // No Break |
|
| 177 | + |
|
| 178 | + case 1: |
|
| 179 | + if ($galaxy && $system && $planet) { |
|
| 180 | + $check_type = $planet_type == PT_MOON ? PT_MOON : PT_PLANET; |
|
| 181 | + |
|
| 182 | + $TargetPlanet = DBStaticPlanet::db_planet_by_gspt($galaxy, $system, $planet, $check_type); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + case 0: |
|
| 186 | + $template_result += array( |
|
| 187 | + 'thisgalaxy' => $planetrow['galaxy'], |
|
| 188 | + 'thissystem' => $planetrow['system'], |
|
| 189 | + 'thisplanet' => $planetrow['planet'], |
|
| 190 | + 'thisplanet_type' => $planetrow['planet_type'], |
|
| 191 | + ); |
|
| 192 | + // no break |
|
| 193 | 193 | |
| 194 | 194 | } |
| 195 | 195 | |
@@ -211,35 +211,35 @@ discard block |
||
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | switch($fleet_page) { |
| 214 | - case 1: |
|
| 215 | - require('includes/includes/flt_page1.inc'); |
|
| 216 | - break; |
|
| 217 | - |
|
| 218 | - case 2: |
|
| 219 | - require_once('includes/includes/flt_page2.inc'); |
|
| 220 | - sn_fleet_page2(); |
|
| 221 | - break; |
|
| 222 | - |
|
| 223 | - case 3: |
|
| 224 | - require_once('includes/includes/flt_page3.inc'); |
|
| 225 | - sn_fleet_page3(); |
|
| 226 | - break; |
|
| 227 | - |
|
| 228 | - case 4: |
|
| 229 | - require('includes/includes/flt_page4.inc'); |
|
| 230 | - break; |
|
| 231 | - |
|
| 232 | - case 5: |
|
| 233 | - $template = gettemplate('fleet5', true); |
|
| 234 | - $pageFleet5Gathering = new \Deprecated\PageFleet5Gathering(); |
|
| 235 | - $pageFleet5Gathering->modelFleet5Gathering($user, $planetrow, $template); |
|
| 236 | - // Building list of own planets & moons |
|
| 237 | - $pageFleet5Gathering->viewPage5Gathering($user, $planetrow, $template); |
|
| 238 | - break; |
|
| 239 | - |
|
| 240 | - default: |
|
| 241 | - define('SN_RENDER_NAVBAR_PLANET', true); |
|
| 242 | - |
|
| 243 | - require('includes/includes/flt_page0.inc'); |
|
| 244 | - break; |
|
| 214 | + case 1: |
|
| 215 | + require('includes/includes/flt_page1.inc'); |
|
| 216 | + break; |
|
| 217 | + |
|
| 218 | + case 2: |
|
| 219 | + require_once('includes/includes/flt_page2.inc'); |
|
| 220 | + sn_fleet_page2(); |
|
| 221 | + break; |
|
| 222 | + |
|
| 223 | + case 3: |
|
| 224 | + require_once('includes/includes/flt_page3.inc'); |
|
| 225 | + sn_fleet_page3(); |
|
| 226 | + break; |
|
| 227 | + |
|
| 228 | + case 4: |
|
| 229 | + require('includes/includes/flt_page4.inc'); |
|
| 230 | + break; |
|
| 231 | + |
|
| 232 | + case 5: |
|
| 233 | + $template = gettemplate('fleet5', true); |
|
| 234 | + $pageFleet5Gathering = new \Deprecated\PageFleet5Gathering(); |
|
| 235 | + $pageFleet5Gathering->modelFleet5Gathering($user, $planetrow, $template); |
|
| 236 | + // Building list of own planets & moons |
|
| 237 | + $pageFleet5Gathering->viewPage5Gathering($user, $planetrow, $template); |
|
| 238 | + break; |
|
| 239 | + |
|
| 240 | + default: |
|
| 241 | + define('SN_RENDER_NAVBAR_PLANET', true); |
|
| 242 | + |
|
| 243 | + require('includes/includes/flt_page0.inc'); |
|
| 244 | + break; |
|
| 245 | 245 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | if (!defined('IN_PHPBB')) |
| 18 | 18 | { |
| 19 | - exit; |
|
| 19 | + exit; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -24,227 +24,227 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | class phpbb_hook |
| 26 | 26 | { |
| 27 | - /** |
|
| 28 | - * Registered hooks |
|
| 29 | - */ |
|
| 30 | - var $hooks = array(); |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Results returned by functions called |
|
| 34 | - */ |
|
| 35 | - var $hook_result = array(); |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * internal pointer |
|
| 39 | - */ |
|
| 40 | - var $current_hook = NULL; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Initialize hook class. |
|
| 44 | - * |
|
| 45 | - * @param array $valid_hooks array containing the hookable functions/methods |
|
| 46 | - */ |
|
| 47 | - function phpbb_hook($valid_hooks) |
|
| 48 | - { |
|
| 49 | - foreach ($valid_hooks as $_null => $method) |
|
| 50 | - { |
|
| 51 | - $this->add_hook($method); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - if (function_exists('phpbb_hook_register')) |
|
| 55 | - { |
|
| 56 | - phpbb_hook_register($this); |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Register function/method to be called within hook |
|
| 62 | - * This function is normally called by the modification/application to attach/register the functions. |
|
| 63 | - * |
|
| 64 | - * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__) |
|
| 65 | - * @param mixed $hook The replacement function/method to be called. Passing function name or array with object/class definition |
|
| 66 | - * @param string $mode Specify the priority/chain mode. 'normal' -> hook gets appended to the chain. 'standalone' -> only the specified hook gets called - later hooks are not able to overwrite this (E_NOTICE is triggered then). 'first' -> hook is called as the first one within the chain. 'last' -> hook is called as the last one within the chain. |
|
| 67 | - */ |
|
| 68 | - function register($definition, $hook, $mode = 'normal') |
|
| 69 | - { |
|
| 70 | - $class = (!is_array($definition)) ? '__global' : $definition[0]; |
|
| 71 | - $function = (!is_array($definition)) ? $definition : $definition[1]; |
|
| 72 | - |
|
| 73 | - // Method able to be hooked? |
|
| 74 | - if (isset($this->hooks[$class][$function])) |
|
| 75 | - { |
|
| 76 | - switch ($mode) |
|
| 77 | - { |
|
| 78 | - case 'standalone': |
|
| 79 | - if (!isset($this->hooks[$class][$function]['standalone'])) |
|
| 80 | - { |
|
| 81 | - $this->hooks[$class][$function] = array('standalone' => $hook); |
|
| 82 | - } |
|
| 83 | - else |
|
| 84 | - { |
|
| 85 | - trigger_error('Hook not able to be called standalone, previous hook already standalone.', E_NOTICE); |
|
| 86 | - } |
|
| 87 | - break; |
|
| 88 | - |
|
| 89 | - case 'first': |
|
| 90 | - case 'last': |
|
| 91 | - $this->hooks[$class][$function][$mode][] = $hook; |
|
| 92 | - break; |
|
| 93 | - |
|
| 94 | - case 'normal': |
|
| 95 | - default: |
|
| 96 | - $this->hooks[$class][$function]['normal'][] = $hook; |
|
| 97 | - break; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Calling all functions/methods attached to a specified hook. |
|
| 104 | - * Called by the function allowing hooks... |
|
| 105 | - * |
|
| 106 | - * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__) |
|
| 107 | - * @return bool False if no hook got executed, true otherwise |
|
| 108 | - */ |
|
| 109 | - function call_hook($definition) |
|
| 110 | - { |
|
| 111 | - $class = (!is_array($definition)) ? '__global' : $definition[0]; |
|
| 112 | - $function = (!is_array($definition)) ? $definition : $definition[1]; |
|
| 113 | - |
|
| 114 | - if (!empty($this->hooks[$class][$function])) |
|
| 115 | - { |
|
| 116 | - // Developer tries to call a hooked function within the hooked function... |
|
| 117 | - if ($this->current_hook !== NULL && $this->current_hook['class'] === $class && $this->current_hook['function'] === $function) |
|
| 118 | - { |
|
| 119 | - return false; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - // Call the hook with the arguments attached and store result |
|
| 123 | - $arguments = func_get_args(); |
|
| 124 | - $this->current_hook = array('class' => $class, 'function' => $function); |
|
| 125 | - $arguments[0] = &$this; |
|
| 126 | - |
|
| 127 | - // Call the hook chain... |
|
| 128 | - if (isset($this->hooks[$class][$function]['standalone'])) |
|
| 129 | - { |
|
| 130 | - $this->hook_result[$class][$function] = call_user_func_array($this->hooks[$class][$function]['standalone'], $arguments); |
|
| 131 | - } |
|
| 132 | - else |
|
| 133 | - { |
|
| 134 | - foreach (array('first', 'normal', 'last') as $mode) |
|
| 135 | - { |
|
| 136 | - if (!isset($this->hooks[$class][$function][$mode])) |
|
| 137 | - { |
|
| 138 | - continue; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - foreach ($this->hooks[$class][$function][$mode] as $hook) |
|
| 142 | - { |
|
| 143 | - $this->hook_result[$class][$function] = call_user_func_array($hook, $arguments); |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - $this->current_hook = NULL; |
|
| 149 | - return true; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - $this->current_hook = NULL; |
|
| 153 | - return false; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Get result from previously called functions/methods for the same hook |
|
| 158 | - * |
|
| 159 | - * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__) |
|
| 160 | - * @return mixed False if nothing returned if there is no result, else array('result' => ... ) |
|
| 161 | - */ |
|
| 162 | - function previous_hook_result($definition) |
|
| 163 | - { |
|
| 164 | - $class = (!is_array($definition)) ? '__global' : $definition[0]; |
|
| 165 | - $function = (!is_array($definition)) ? $definition : $definition[1]; |
|
| 166 | - |
|
| 167 | - if (!empty($this->hooks[$class][$function]) && isset($this->hook_result[$class][$function])) |
|
| 168 | - { |
|
| 169 | - return array('result' => $this->hook_result[$class][$function]); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - return false; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Check if the called functions/methods returned something. |
|
| 177 | - * |
|
| 178 | - * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__) |
|
| 179 | - * @return bool True if results are there, false if not |
|
| 180 | - */ |
|
| 181 | - function hook_return($definition) |
|
| 182 | - { |
|
| 183 | - $class = (!is_array($definition)) ? '__global' : $definition[0]; |
|
| 184 | - $function = (!is_array($definition)) ? $definition : $definition[1]; |
|
| 185 | - |
|
| 186 | - if (!empty($this->hooks[$class][$function]) && isset($this->hook_result[$class][$function])) |
|
| 187 | - { |
|
| 188 | - return true; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return false; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Give actual result from called functions/methods back. |
|
| 196 | - * |
|
| 197 | - * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__) |
|
| 198 | - * @return mixed The result |
|
| 199 | - */ |
|
| 200 | - function hook_return_result($definition) |
|
| 201 | - { |
|
| 202 | - $class = (!is_array($definition)) ? '__global' : $definition[0]; |
|
| 203 | - $function = (!is_array($definition)) ? $definition : $definition[1]; |
|
| 204 | - |
|
| 205 | - if (!empty($this->hooks[$class][$function]) && isset($this->hook_result[$class][$function])) |
|
| 206 | - { |
|
| 207 | - $result = $this->hook_result[$class][$function]; |
|
| 208 | - unset($this->hook_result[$class][$function]); |
|
| 209 | - return $result; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - return; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Add new function to the allowed hooks. |
|
| 217 | - * |
|
| 218 | - * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__) |
|
| 219 | - */ |
|
| 220 | - function add_hook($definition) |
|
| 221 | - { |
|
| 222 | - if (!is_array($definition)) |
|
| 223 | - { |
|
| 224 | - $definition = array('__global', $definition); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - $this->hooks[$definition[0]][$definition[1]] = array(); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * Remove function from the allowed hooks. |
|
| 232 | - * |
|
| 233 | - * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__) |
|
| 234 | - */ |
|
| 235 | - function remove_hook($definition) |
|
| 236 | - { |
|
| 237 | - $class = (!is_array($definition)) ? '__global' : $definition[0]; |
|
| 238 | - $function = (!is_array($definition)) ? $definition : $definition[1]; |
|
| 239 | - |
|
| 240 | - if (isset($this->hooks[$class][$function])) |
|
| 241 | - { |
|
| 242 | - unset($this->hooks[$class][$function]); |
|
| 243 | - |
|
| 244 | - if (isset($this->hook_result[$class][$function])) |
|
| 245 | - { |
|
| 246 | - unset($this->hook_result[$class][$function]); |
|
| 247 | - } |
|
| 248 | - } |
|
| 249 | - } |
|
| 27 | + /** |
|
| 28 | + * Registered hooks |
|
| 29 | + */ |
|
| 30 | + var $hooks = array(); |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Results returned by functions called |
|
| 34 | + */ |
|
| 35 | + var $hook_result = array(); |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * internal pointer |
|
| 39 | + */ |
|
| 40 | + var $current_hook = NULL; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Initialize hook class. |
|
| 44 | + * |
|
| 45 | + * @param array $valid_hooks array containing the hookable functions/methods |
|
| 46 | + */ |
|
| 47 | + function phpbb_hook($valid_hooks) |
|
| 48 | + { |
|
| 49 | + foreach ($valid_hooks as $_null => $method) |
|
| 50 | + { |
|
| 51 | + $this->add_hook($method); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + if (function_exists('phpbb_hook_register')) |
|
| 55 | + { |
|
| 56 | + phpbb_hook_register($this); |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Register function/method to be called within hook |
|
| 62 | + * This function is normally called by the modification/application to attach/register the functions. |
|
| 63 | + * |
|
| 64 | + * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__) |
|
| 65 | + * @param mixed $hook The replacement function/method to be called. Passing function name or array with object/class definition |
|
| 66 | + * @param string $mode Specify the priority/chain mode. 'normal' -> hook gets appended to the chain. 'standalone' -> only the specified hook gets called - later hooks are not able to overwrite this (E_NOTICE is triggered then). 'first' -> hook is called as the first one within the chain. 'last' -> hook is called as the last one within the chain. |
|
| 67 | + */ |
|
| 68 | + function register($definition, $hook, $mode = 'normal') |
|
| 69 | + { |
|
| 70 | + $class = (!is_array($definition)) ? '__global' : $definition[0]; |
|
| 71 | + $function = (!is_array($definition)) ? $definition : $definition[1]; |
|
| 72 | + |
|
| 73 | + // Method able to be hooked? |
|
| 74 | + if (isset($this->hooks[$class][$function])) |
|
| 75 | + { |
|
| 76 | + switch ($mode) |
|
| 77 | + { |
|
| 78 | + case 'standalone': |
|
| 79 | + if (!isset($this->hooks[$class][$function]['standalone'])) |
|
| 80 | + { |
|
| 81 | + $this->hooks[$class][$function] = array('standalone' => $hook); |
|
| 82 | + } |
|
| 83 | + else |
|
| 84 | + { |
|
| 85 | + trigger_error('Hook not able to be called standalone, previous hook already standalone.', E_NOTICE); |
|
| 86 | + } |
|
| 87 | + break; |
|
| 88 | + |
|
| 89 | + case 'first': |
|
| 90 | + case 'last': |
|
| 91 | + $this->hooks[$class][$function][$mode][] = $hook; |
|
| 92 | + break; |
|
| 93 | + |
|
| 94 | + case 'normal': |
|
| 95 | + default: |
|
| 96 | + $this->hooks[$class][$function]['normal'][] = $hook; |
|
| 97 | + break; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Calling all functions/methods attached to a specified hook. |
|
| 104 | + * Called by the function allowing hooks... |
|
| 105 | + * |
|
| 106 | + * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__) |
|
| 107 | + * @return bool False if no hook got executed, true otherwise |
|
| 108 | + */ |
|
| 109 | + function call_hook($definition) |
|
| 110 | + { |
|
| 111 | + $class = (!is_array($definition)) ? '__global' : $definition[0]; |
|
| 112 | + $function = (!is_array($definition)) ? $definition : $definition[1]; |
|
| 113 | + |
|
| 114 | + if (!empty($this->hooks[$class][$function])) |
|
| 115 | + { |
|
| 116 | + // Developer tries to call a hooked function within the hooked function... |
|
| 117 | + if ($this->current_hook !== NULL && $this->current_hook['class'] === $class && $this->current_hook['function'] === $function) |
|
| 118 | + { |
|
| 119 | + return false; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + // Call the hook with the arguments attached and store result |
|
| 123 | + $arguments = func_get_args(); |
|
| 124 | + $this->current_hook = array('class' => $class, 'function' => $function); |
|
| 125 | + $arguments[0] = &$this; |
|
| 126 | + |
|
| 127 | + // Call the hook chain... |
|
| 128 | + if (isset($this->hooks[$class][$function]['standalone'])) |
|
| 129 | + { |
|
| 130 | + $this->hook_result[$class][$function] = call_user_func_array($this->hooks[$class][$function]['standalone'], $arguments); |
|
| 131 | + } |
|
| 132 | + else |
|
| 133 | + { |
|
| 134 | + foreach (array('first', 'normal', 'last') as $mode) |
|
| 135 | + { |
|
| 136 | + if (!isset($this->hooks[$class][$function][$mode])) |
|
| 137 | + { |
|
| 138 | + continue; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + foreach ($this->hooks[$class][$function][$mode] as $hook) |
|
| 142 | + { |
|
| 143 | + $this->hook_result[$class][$function] = call_user_func_array($hook, $arguments); |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + $this->current_hook = NULL; |
|
| 149 | + return true; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + $this->current_hook = NULL; |
|
| 153 | + return false; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Get result from previously called functions/methods for the same hook |
|
| 158 | + * |
|
| 159 | + * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__) |
|
| 160 | + * @return mixed False if nothing returned if there is no result, else array('result' => ... ) |
|
| 161 | + */ |
|
| 162 | + function previous_hook_result($definition) |
|
| 163 | + { |
|
| 164 | + $class = (!is_array($definition)) ? '__global' : $definition[0]; |
|
| 165 | + $function = (!is_array($definition)) ? $definition : $definition[1]; |
|
| 166 | + |
|
| 167 | + if (!empty($this->hooks[$class][$function]) && isset($this->hook_result[$class][$function])) |
|
| 168 | + { |
|
| 169 | + return array('result' => $this->hook_result[$class][$function]); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + return false; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Check if the called functions/methods returned something. |
|
| 177 | + * |
|
| 178 | + * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__) |
|
| 179 | + * @return bool True if results are there, false if not |
|
| 180 | + */ |
|
| 181 | + function hook_return($definition) |
|
| 182 | + { |
|
| 183 | + $class = (!is_array($definition)) ? '__global' : $definition[0]; |
|
| 184 | + $function = (!is_array($definition)) ? $definition : $definition[1]; |
|
| 185 | + |
|
| 186 | + if (!empty($this->hooks[$class][$function]) && isset($this->hook_result[$class][$function])) |
|
| 187 | + { |
|
| 188 | + return true; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return false; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Give actual result from called functions/methods back. |
|
| 196 | + * |
|
| 197 | + * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__) |
|
| 198 | + * @return mixed The result |
|
| 199 | + */ |
|
| 200 | + function hook_return_result($definition) |
|
| 201 | + { |
|
| 202 | + $class = (!is_array($definition)) ? '__global' : $definition[0]; |
|
| 203 | + $function = (!is_array($definition)) ? $definition : $definition[1]; |
|
| 204 | + |
|
| 205 | + if (!empty($this->hooks[$class][$function]) && isset($this->hook_result[$class][$function])) |
|
| 206 | + { |
|
| 207 | + $result = $this->hook_result[$class][$function]; |
|
| 208 | + unset($this->hook_result[$class][$function]); |
|
| 209 | + return $result; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + return; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Add new function to the allowed hooks. |
|
| 217 | + * |
|
| 218 | + * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__) |
|
| 219 | + */ |
|
| 220 | + function add_hook($definition) |
|
| 221 | + { |
|
| 222 | + if (!is_array($definition)) |
|
| 223 | + { |
|
| 224 | + $definition = array('__global', $definition); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + $this->hooks[$definition[0]][$definition[1]] = array(); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * Remove function from the allowed hooks. |
|
| 232 | + * |
|
| 233 | + * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__) |
|
| 234 | + */ |
|
| 235 | + function remove_hook($definition) |
|
| 236 | + { |
|
| 237 | + $class = (!is_array($definition)) ? '__global' : $definition[0]; |
|
| 238 | + $function = (!is_array($definition)) ? $definition : $definition[1]; |
|
| 239 | + |
|
| 240 | + if (isset($this->hooks[$class][$function])) |
|
| 241 | + { |
|
| 242 | + unset($this->hooks[$class][$function]); |
|
| 243 | + |
|
| 244 | + if (isset($this->hook_result[$class][$function])) |
|
| 245 | + { |
|
| 246 | + unset($this->hook_result[$class][$function]); |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | 250 | } |