1
|
|
|
<?php |
2
|
|
|
|
3
|
|
View Code Duplication |
if(!defined('SN_IN_ALLY') || SN_IN_ALLY !== true) { |
|
|
|
|
4
|
|
|
classSupernova::$debug->error("Attempt to call ALLIANCE page mode {$mode} directly - not from alliance.php", 'Forbidden', 403); |
5
|
|
|
} |
6
|
|
|
|
7
|
|
|
$template = gettemplate('ali_info', true); |
8
|
|
|
|
9
|
|
|
if($mode == 'exit') { |
10
|
|
|
if($ally['ally_owner'] == $user['id']) { |
11
|
|
|
message(classLocale::$lang['Owner_cant_go_out'], classLocale::$lang['Alliance']); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
if(sys_get_param_int('ali_info_leave_confirm')) { |
15
|
|
|
sn_db_transaction_start(); |
16
|
|
|
db_user_set_by_id($user['id'], "`ally_id` = null, `ally_name` = null, `ally_tag` = null, `ally_register_time` = 0, `ally_rank_id` = 0"); |
17
|
|
|
db_ally_list_recalc_counts(); |
18
|
|
|
sn_db_transaction_commit(); |
19
|
|
|
message(sprintf(classLocale::$lang['ali_info_leave_success'], $ally['ally_name']), classLocale::$lang['sys_alliance']); |
20
|
|
|
} |
21
|
|
|
} elseif($mode == 'ainfo') { |
22
|
|
|
$tag = sys_get_param_str('tag'); |
23
|
|
|
$id_ally = sys_get_param_id('a'); |
24
|
|
|
if($tag) { |
25
|
|
|
$ally = db_ally_get_by_tag($tag); |
26
|
|
|
} elseif($id_ally) { |
27
|
|
|
$ally = db_ally_get_by_id($id_ally); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
if(!$ally) { |
31
|
|
|
message(classLocale::$lang['ali_sys_notFound'], classLocale::$lang['Ally_info_1']); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
if(!$ally['ally_description']) { |
35
|
|
|
$ally['ally_description'] = classLocale::$lang['Ally_nodescription']; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$template->assign_vars(array( |
39
|
|
|
'EXTERNAL' => true, |
40
|
|
|
'USER_ALLY_ID' => $user['ally_id'], |
41
|
|
|
)); |
42
|
|
|
$page_header = classLocale::$lang['sys_alliance']; |
43
|
|
|
} else { |
44
|
|
|
$page_header = classLocale::$lang['your_alliance']; |
45
|
|
|
|
46
|
|
|
if($ally['ally_owner'] == $user['id']) { |
47
|
|
|
$range = $ally['ally_owner_range'] ? $ally['ally_owner_range'] : classLocale::$lang['Founder']; |
48
|
|
|
} elseif($user['ally_rank_id'] != 0 && isset($ranks[$user['ally_rank_id']]['name'])) { |
49
|
|
|
$range = $ranks[$user['ally_rank_id']]['name']; |
50
|
|
|
} else { |
51
|
|
|
$range = classLocale::$lang['member']; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$request = db_ally_request_count_by_id($ally); |
55
|
|
|
|
56
|
|
|
$template->assign_vars(array( |
57
|
|
|
'range' => $range, |
58
|
|
|
'ALLY_REQUESTS' => $request['request_count'], |
59
|
|
|
|
60
|
|
|
'ALLY_ADMIN' => $user_admin, |
61
|
|
|
'ALLY_CAN_KICK' => $user_can_kick, |
62
|
|
|
'MASS_MAIL' => $user_can_send_mails, |
63
|
|
|
'MANAGE_REQUESTS' => $user_admin_applications, |
64
|
|
|
'ALLY_NEGOTIATE' => $user_can_negotiate, |
65
|
|
|
)); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$patterns[] = "#\[fc\]([a-z0-9\#]+)\[/fc\](.*?)\[/f\]#Ssi"; |
69
|
|
|
$replacements[] = '<font color="\1">\2</font>'; |
70
|
|
|
$patterns[] = '#\[img\](.*?)\[/img\]#Smi'; |
71
|
|
|
$replacements[] = '<img src="\1" alt="\1" style="border:0px;" />'; |
72
|
|
|
$patterns[] = "#\[fc\]([a-z0-9\#\ \[\]]+)\[/fc\]#Ssi"; |
73
|
|
|
$replacements[] = '<font color="\1">'; |
74
|
|
|
$patterns[] = "#\[/f\]#Ssi"; |
75
|
|
|
$replacements[] = '</font>'; |
76
|
|
|
|
77
|
|
|
$template->assign_vars(array( |
78
|
|
|
'ALLY_DESCRIPTION' => nl2br(preg_replace($patterns, $replacements, $ally['ally_description'])), |
79
|
|
|
'ALLY_TEXT' => nl2br(preg_replace($patterns, $replacements, $ally['ally_text'])), |
80
|
|
|
'ally_id' => $ally['id'], |
81
|
|
|
'ALLY_MEMBERS' => $ally['ally_members'], |
82
|
|
|
'ally_web' => $ally['ally_web'], |
83
|
|
|
'ALLY_TAG' => $ally['ally_tag'], |
84
|
|
|
'ally_image' => $ally['ally_image'], |
85
|
|
|
'ally_name' => $ally['ally_name'], |
86
|
|
|
)); |
87
|
|
|
|
88
|
|
|
$relations = ali_relations($ally['id']); |
89
|
|
|
foreach($relations as $relation) { |
90
|
|
|
if($relation['alliance_diplomacy_contr_ally_id'] && $relation['alliance_diplomacy_ally_id']) { |
91
|
|
|
$template->assign_block_vars('relation', array( |
92
|
|
|
'NAME' => $relation['alliance_diplomacy_contr_ally_name'], |
93
|
|
|
'RELATION' => classLocale::$lang['ali_dip_relations'][$relation['alliance_diplomacy_relation']], |
94
|
|
|
'TIME' => date(FMT_DATE_TIME, $relation['alliance_diplomacy_time']), |
95
|
|
|
)); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
$template = parsetemplate($template); |
100
|
|
|
|
101
|
|
|
function ali_render() { |
102
|
|
|
$func_args = func_get_args(); |
103
|
|
|
|
104
|
|
|
return sn_function_call(__FUNCTION__, $func_args); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
ali_render(); |
108
|
|
|
|
109
|
|
|
display($template, classLocale::$lang['your_alliance'] . ' [' . $ally['ally_name'] . ']'); |
110
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.