Completed
Push — trunk ( c7e339...34029c )
by SuperNova.WS
04:10
created

ali_render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
if(!defined('SN_IN_ALLY') || SN_IN_ALLY !== true)
4
{
5
  $debug->error("Attempt to call ALLIANCE page mode {$mode} directly - not from alliance.php", 'Forbidden', 403);
6
}
7
8
$template = gettemplate('ali_info', true);
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type null|template expected by parameter $template of gettemplate(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

8
$template = gettemplate('ali_info', /** @scrutinizer ignore-type */ true);
Loading history...
9
10
if($mode == 'exit')
11
{
12
  if ($ally['ally_owner'] == $user['id'])
13
  {
14
    messageBox($lang['Owner_cant_go_out'], $lang['Alliance']);
15
  }
16
17
  if (sys_get_param_int('ali_info_leave_confirm'))
18
  {
19
    sn_db_transaction_start();
20
    db_user_set_by_id($user['id'], "`ally_id` = null, `ally_name` = null, `ally_tag` = null, `ally_register_time` = 0, `ally_rank_id` = 0");
0 ignored issues
show
Deprecated Code introduced by
The function db_user_set_by_id() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

20
    /** @scrutinizer ignore-deprecated */ db_user_set_by_id($user['id'], "`ally_id` = null, `ally_name` = null, `ally_tag` = null, `ally_register_time` = 0, `ally_rank_id` = 0");
Loading history...
21
    DBStaticAlly::db_ally_list_recalc_counts();
22
    sn_db_transaction_commit();
23
    $lang['Go_out_welldone'] = str_replace("%s", $ally_name, $lang['Go_out_welldone']);
24
    messageBox(sprintf($lang['ali_info_leave_success'], $ally['ally_name']), $lang['sys_alliance']);
25
  }
26
}
27
elseif($mode == 'ainfo')
28
{
29
  $tag = sys_get_param_str('tag');
30
  $id_ally = sys_get_param_id('a');
31
  if($tag)
32
  {
33
    $ally = doquery("SELECT * FROM {{alliance}} WHERE ally_tag='{$tag}' LIMIT 1;", '', true);
34
  }
35
  elseif($id_ally)
36
  {
37
    $ally = doquery("SELECT * FROM {{alliance}} WHERE id='{$id_ally}' LIMIT 1;", '', true);
38
  }
39
40
  if(!$ally)
41
  {
42
    messageBox($lang['ali_sys_notFound'], $lang['Ally_info_1']);
43
  }
44
45
  if(!$ally['ally_description'])
46
  {
47
    $ally['ally_description'] = $lang['Ally_nodescription'];
48
  }
49
50
  $template->assign_vars(array(
51
    'EXTERNAL'     => true,
52
    'USER_ALLY_ID' => $user['ally_id'],
53
  ));
54
  $page_header          = $lang['sys_alliance'];
55
}
56
else
57
{
58
  $page_header = $lang['your_alliance'];
59
60
  if($ally['ally_owner'] == $user['id'])
61
  {
62
    $range = $ally['ally_owner_range'] ? $ally['ally_owner_range'] : $lang['Founder'];
63
  }
64
  elseif($user['ally_rank_id'] != 0 && isset($ranks[$user['ally_rank_id']]['name']))
65
  {
66
    $range = $ranks[$user['ally_rank_id']]['name'];
67
  }
68
  else
69
  {
70
    $range = $lang['member'];
71
  }
72
73
  $request = doquery("SELECT COUNT(*) AS request_count FROM {{alliance_requests}} WHERE `id_ally` ='{$ally['id']}'", '', true);
74
75
  $template->assign_vars(array(
76
    'range' => $range,
77
    'ALLY_REQUESTS' => $request['request_count'],
78
79
    'ALLY_ADMIN' => $user_admin,
80
    'ALLY_CAN_KICK' => $user_can_kick,
81
    'MASS_MAIL' => $user_can_send_mails,
82
    'MANAGE_REQUESTS' => $user_admin_applications,
83
    'ALLY_NEGOTIATE' => $user_can_negotiate,
84
  ));
85
}
86
87
$patterns[] = "#\[fc\]([a-z0-9\#]+)\[/fc\](.*?)\[/f\]#Ssi";
88
$replacements[] = '<font color="\1">\2</font>';
89
$patterns[] = '#\[img\](.*?)\[/img\]#Smi';
90
$replacements[] = '<img src="\1" alt="\1" style="border:0px;" />';
91
$patterns[] = "#\[fc\]([a-z0-9\#\ \[\]]+)\[/fc\]#Ssi";
92
$replacements[] = '<font color="\1">';
93
$patterns[] = "#\[/f\]#Ssi";
94
$replacements[] = '</font>';
95
96
$template->assign_vars(array(
97
  'ALLY_DESCRIPTION' => nl2br(preg_replace($patterns, $replacements, $ally['ally_description'])),
98
  'ALLY_TEXT'        => nl2br(preg_replace($patterns, $replacements, $ally['ally_text'])),
99
  'ally_id'          => $ally['id'],
100
  'ALLY_MEMBERS'     => $ally['ally_members'],
101
  'ally_web'         => $ally['ally_web'],
102
  'ally_tag'         => $ally['ally_tag'],
103
  'ally_image'       => $ally['ally_image'],
104
  'ally_name'        => $ally['ally_name'],
105
));
106
107
$relations = ali_relations($ally['id']);
108
foreach($relations as $relation)
109
{
110
  if($relation['alliance_diplomacy_contr_ally_id'] && $relation['alliance_diplomacy_ally_id'])
111
  {
112
    $template->assign_block_vars('relation', array(
113
      'NAME'     => $relation['alliance_diplomacy_contr_ally_name'],
114
      'RELATION' => $lang['ali_dip_relations'][$relation['alliance_diplomacy_relation']],
115
      'TIME'     => date(FMT_DATE_TIME, $relation['alliance_diplomacy_time']),
116
    ));
117
  }
118
}
119
120
SN::$gc->pimp->allyInfoView();
121
122
display($template, "{$lang['alliance']} [{$ally['ally_name']}]");
123