Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Push — master ( 2799eb...63eb51 )
by Dan
04:22
created

AbstractMenu::galactic_post()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
nc 2
nop 0
dl 0
loc 10
rs 10
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
3
/**
4
 * Creates menu navigation bars.
5
 */
6
class AbstractMenu {
7
8
	public static function headquarters() {
9
		global $var;
10
		$menu_items = [];
11
		$container = create_container('skeleton.php');
12
		$container['LocationID'] = $var['LocationID'];
13
14
		$location = SmrLocation::getLocation($var['LocationID']);
15
		if ($location->isHQ()) {
16
			$container['body'] = 'government.php';
17
			$menu_items[] = create_link($container, 'Government', 'nav');
18
			$container['body'] = 'military_payment_claim.php';
19
			$menu_items[] = create_link($container, 'Claim Military Payment', 'nav');
20
		} elseif ($location->isUG()) {
21
			$container['body'] = 'underground.php';
22
			$menu_items[] = create_link($container, 'Underground', 'nav');
23
		} else {
24
			throw new Exception("Location is not HQ or UG: " . $location->getName());
25
		}
26
		$container['body'] = 'bounty_claim.php';
27
		$menu_items[] = create_link($container, 'Claim Bounty', 'nav');
28
		$container['body'] = 'bounty_place.php';
29
		$menu_items[] = create_link($container, 'Place a Bounty', 'nav');
30
		create_menu($menu_items);
31
	}
32
33
	public static function planet_list($alliance_id, $selected_index) {
34
		global $template;
35
36
		$menuItems = array();
37
		$menuItems[] = array('Link'=>Globals::getPlanetListHREF($alliance_id), 'Text'=>'Defense');
38
		$menuItems[] = array('Link'=>Globals::getPlanetListFinancialHREF($alliance_id), 'Text'=>'Financial');
39
		// make the selected index bold
40
		$boldItem =& $menuItems[$selected_index]['Text'];
41
		$boldItem = '<span class="bold">' . $boldItem . '</span>';
42
		$template->assign('MenuItems', $menuItems);
43
	}
44
45
	public static function alliance($alliance_id = null, $alliance_leader_id = FALSE) {
0 ignored issues
show
Unused Code introduced by
The parameter $alliance_leader_id is not used and could be removed. ( Ignorable by Annotation )

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

45
	public static function alliance($alliance_id = null, /** @scrutinizer ignore-unused */ $alliance_leader_id = FALSE) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
46
		global $player, $template, $db;
47
48
		if ($alliance_id) {
49
			$in_alliance = ($alliance_id == $player->getAllianceID());
50
		} else {
51
			$in_alliance = $player->hasAlliance();
52
		}
53
		if (!$in_alliance) {
54
			$db->query('SELECT mb_read, mod_read, planet_land FROM alliance_treaties
55
							WHERE (alliance_id_1 = ' . $db->escapeNumber($alliance_id) . ' OR alliance_id_1 = ' . $db->escapeNumber($player->getAllianceID()) . ')
56
							AND (alliance_id_2 = ' . $db->escapeNumber($alliance_id) . ' OR alliance_id_2 = ' . $db->escapeNumber($player->getAllianceID()) . ')
57
							AND game_id = ' . $db->escapeNumber($player->getGameID()) . '
58
							AND (mb_read = 1 OR mod_read = 1 OR planet_land = 1) AND official = \'TRUE\'');
59
			if ($db->nextRecord()) {
60
				$mbRead = $db->getBoolean('mb_read');
61
				$modRead = $db->getBoolean('mod_read');
62
				$planetLand = $db->getBoolean('planet_land');
63
			} else {
64
				$mbRead = FALSE;
65
				$modRead = FALSE;
66
				$planetLand = FALSE;
67
			}
68
		}
69
70
		$role_id = $player->getAllianceRole($alliance_id);
71
		$db->query('SELECT send_alliance_msg FROM alliance_has_roles WHERE alliance_id = ' . $db->escapeNumber($alliance_id) . ' AND game_id = ' . $db->escapeNumber($player->getGameID()) . ' AND role_id = ' . $db->escapeNumber($role_id));
72
		if ($db->nextRecord()) {
73
			$send_alliance_msg = $db->getBoolean('send_alliance_msg');
74
		} else {
75
			$send_alliance_msg = false;
76
		}
77
78
		$menuItems = array();
79
		if ($in_alliance || in_array($player->getAccountID(), Globals::getHiddenPlayers()) || $modRead) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $modRead does not seem to be defined for all execution paths leading up to this point.
Loading history...
80
			$menuItems[] = array('Link'=>Globals::getAllianceMotdHREF($alliance_id), 'Text'=>'Message of the Day');
81
		}
82
		$menuItems[] = array('Link'=>Globals::getAllianceRosterHREF($alliance_id), 'Text'=>'Roster');
83
		if ($send_alliance_msg || in_array($player->getAccountID(), Globals::getHiddenPlayers())) {
84
			$menuItems[] = array('Link'=>Globals::getAllianceMessageHREF($alliance_id), 'Text'=>'Send Message');
85
		}
86
		if ($in_alliance || in_array($player->getAccountID(), Globals::getHiddenPlayers()) || $mbRead) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $mbRead does not seem to be defined for all execution paths leading up to this point.
Loading history...
87
			$menuItems[] = array('Link'=>Globals::getAllianceMessageBoardHREF($alliance_id), 'Text'=>'Message Board');
88
		}
89
		if ($in_alliance || in_array($player->getAccountID(), Globals::getHiddenPlayers()) || $planetLand) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $planetLand does not seem to be defined for all execution paths leading up to this point.
Loading history...
90
			$menuItems[] = array('Link'=>Globals::getPlanetListHREF($alliance_id), 'Text'=>'Planets');
91
		}
92
		if ($in_alliance || in_array($player->getAccountID(), Globals::getHiddenPlayers())) {
93
			$menuItems[] = array('Link'=>Globals::getAllianceForcesHREF($alliance_id), 'Text'=>'Forces');
94
			$menuItems[] = array('Link'=>Globals::getAllianceOptionsHREF($alliance_id), 'Text'=>'Options');
95
		}
96
		$menuItems[] = array('Link'=>Globals::getAllianceListHREF(), 'Text'=>'List Alliances');
97
		$menuItems[] = array('Link'=>Globals::getAllianceNewsHREF($alliance_id ? $alliance_id : $player->getAllianceID()), 'Text'=>'View News');
98
99
		$template->assign('MenuItems', $menuItems);
100
	}
101
102
	public static function galactic_post() {
103
		global $template, $player;
104
		$menuItems = array();
105
		$menuItems[] = array('Link'=>SmrSession::getNewHREF(create_container('galactic_post_current.php')), 'Text'=>'Current Edition');
106
		$menuItems[] = array('Link'=>SmrSession::getNewHREF(create_container('skeleton.php', 'galactic_post_past.php')), 'Text'=>'Past Editions');
107
		$menuItems[] = array('Link'=>SmrSession::getNewHREF(create_container('skeleton.php', 'galactic_post_write_article.php')), 'Text'=>'Write an article');
108
		if ($player->isGPEditor()) {
109
			$menuItems[] = array('Link'=>SmrSession::getNewHREF(create_container('skeleton.php', 'galactic_post.php')), 'Text'=>'Editor Options');
110
		}
111
		$template->assign('MenuItems', $menuItems);
112
	}
113
114
	public static function history_games($selected_index) {
115
		global $template, $var;
116
		$menuItems = [];
117
		$container = create_container('skeleton.php', 'history_games.php');
118
		$container['HistoryDatabase'] = $var['HistoryDatabase'];
119
		$container['view_game_id'] = $var['view_game_id'];
120
		$container['game_name'] = $var['game_name'];
121
		$menuItems[] = ['Link' => SmrSession::getNewHREF($container),
122
		                'Text' => 'Game Details'];
123
		$container['body'] = 'history_games_detail.php';
124
		$menuItems[] = ['Link' => SmrSession::getNewHREF($container),
125
		                'Text' => 'Extended Stats'];
126
		$container['body'] = 'history_games_hof.php';
127
		$menuItems[] = ['Link' => SmrSession::getNewHREF($container),
128
		                'Text' => 'Hall of Fame'];
129
		$container['body'] = 'history_games_news.php';
130
		$menuItems[] = ['Link' => SmrSession::getNewHREF($container),
131
		                'Text' => 'Game News'];
132
		// make the selected index bold
133
		$boldItem =& $menuItems[$selected_index]['Text'];
134
		$boldItem = '<b>' . $boldItem . '</b>';
135
		$template->assign('MenuItems', $menuItems);
136
	}
137
138
	public static function messages() {
139
		global $player, $template;
140
		$menuItems = array();
141
		$menuItems[] = array('Link'=>Globals::getViewMessagesHREF(), 'Text'=>'View Messages');
142
		$menuItems[] = array('Link'=>Globals::getSendGlobalMessageHREF(), 'Text'=>'Send Global Message');
143
		if ($player->isOnCouncil()) {
144
			$menuItems[] = array('Link'=>Globals::getSendCouncilMessageHREF($player->getRaceID()), 'Text'=>'Send Council Message');
145
		}
146
		$menuItems[] = array('Link'=>Globals::getManageBlacklistHREF(), 'Text'=>'Manage Blacklist');
147
148
		$template->assign('MenuItems', $menuItems);
149
	}
150
151
	public static function combat_log() {
152
		global $template;
153
154
		$container = create_container('skeleton.php', 'combat_log_list.php');
155
		$menuItems = array();
156
157
		$container['action'] = COMBAT_LOG_PERSONAL;
158
		$menuItems[] = array('Link'=>SmrSession::getNewHREF($container), 'Text'=>'Personal');
159
		$container['action'] = COMBAT_LOG_ALLIANCE;
160
		$menuItems[] = array('Link'=>SmrSession::getNewHREF($container), 'Text'=>'Alliance');
161
		$container['action'] = COMBAT_LOG_FORCE;
162
		$menuItems[] = array('Link'=>SmrSession::getNewHREF($container), 'Text'=>'Force');
163
		$container['action'] = COMBAT_LOG_PORT;
164
		$menuItems[] = array('Link'=>SmrSession::getNewHREF($container), 'Text'=>'Port');
165
		$container['action'] = COMBAT_LOG_PLANET;
166
		$menuItems[] = array('Link'=>SmrSession::getNewHREF($container), 'Text'=>'Planet');
167
		$container['action'] = COMBAT_LOG_SAVED;
168
		$menuItems[] = array('Link'=>SmrSession::getNewHREF($container), 'Text'=>'Saved');
169
170
		$template->assign('MenuItems', $menuItems);
171
	}
172
173
	public static function trader() {
174
		global $player, $template;
175
		$template->assign('MenuItems', array(
176
						array('Link'=>Globals::getTraderStatusHREF(), 'Text'=>'Trader Status'),
177
						array('Link'=>Globals::getPlanetListHREF($player->getAllianceID()), 'Text'=>'Planets'),
178
						array('Link'=>Globals::getAllianceHREF($player->getAllianceID()), 'Text'=>'Alliance'),
179
						array('Link'=>Globals::getCouncilHREF(), 'Text'=>'Politics'),
180
						array('Link'=>Globals::getTraderRelationsHREF(), 'Text'=>'Relations'),
181
						array('Link'=>Globals::getTraderBountiesHREF(), 'Text'=>'Bounties')));
182
	}
183
184
	public static function planet($planet) {
185
		global $template;
186
187
		$menu_array = array();
188
		$menu_array[] = array('Link'=>Globals::getPlanetMainHREF(), 'Text'=>'Planet Main');
189
		if ($planet->hasMenuOption('CONSTRUCTION')) {
190
			$menu_array[] = array('Link'=>Globals::getPlanetConstructionHREF(), 'Text'=>'Construction');
191
		}
192
		if ($planet->hasMenuOption('DEFENSE')) {
193
			$menu_array[] = array('Link'=>Globals::getPlanetDefensesHREF(), 'Text'=>'Defense');
194
		}
195
		if ($planet->hasMenuOption('OWNERSHIP')) {
196
			$menu_array[] = array('Link'=>Globals::getPlanetOwnershipHREF(), 'Text'=>'Ownership');
197
		}
198
		if ($planet->hasMenuOption('STOCKPILE')) {
199
			$menu_array[] = array('Link'=>Globals::getPlanetStockpileHREF(), 'Text'=>'Stockpile');
200
		}
201
		if ($planet->hasMenuOption('FINANCE')) {
202
			$menu_array[] = array('Link'=>Globals::getPlanetFinancesHREF(), 'Text'=>'Financial');
203
		}
204
205
		$template->assign('MenuItems', $menu_array);
206
	}
207
208
	/*
209
	 * $active_level1 - the id of the active menu on the first level
210
	 * $active_level1 - the id of the active menu on the second level
211
	 */
212
	public static function rankings($active_level1 = 0, $active_level2 = 0) {
213
214
		$menu = array();
215
216
		// player rankings
217
		$menu_item = array();
218
		$menu_item['entry'] = create_link(create_container('skeleton.php', 'rankings_player_experience.php'), 'Player Rankings', 'nav');
219
220
		$menu_subitem = array();
221
		$menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_player_experience.php'), 'Experience', 'nav');
222
		$menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_player_profit.php'), 'Profit', 'nav');
223
		$menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_player_kills.php'), 'Kills', 'nav');
224
		$menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_player_death.php'), 'Deaths', 'nav');
225
		$menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_player_assists.php'), 'Assists', 'nav');
226
227
		$menu_item['submenu'] = $menu_subitem;
228
229
		$menu[] = $menu_item;
230
231
		// alliance rankings
232
		$menu_item = array();
233
		$menu_item['entry'] = create_link(create_container('skeleton.php', 'rankings_alliance_experience.php'), 'Alliance Rankings', 'nav');
234
235
		$menu_subitem = array();
236
		$menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_alliance_experience.php'), 'Experience', 'nav');
237
		$menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_alliance_profit.php'), 'Profit', 'nav');
238
		$menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_alliance_kills.php'), 'Kills', 'nav');
239
		$menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_alliance_death.php'), 'Deaths', 'nav');
240
		$menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_alliance_vs_alliance.php'), 'Versus', 'nav');
241
242
		$menu_item['submenu'] = $menu_subitem;
243
244
		$menu[] = $menu_item;
245
246
		// racial rankings
247
		$menu_item = array();
248
		$menu_item['entry'] = create_link(create_container('skeleton.php', 'rankings_race.php'), 'Racial Standings', 'nav');
249
250
		$menu_subitem = array();
251
		$menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_race.php'), 'Experience', 'nav');
252
		$menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_race_kills.php'), 'Kills', 'nav');
253
		$menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_race_death.php'), 'Deaths', 'nav');
254
255
		$menu_item['submenu'] = $menu_subitem;
256
257
		$menu[] = $menu_item;
258
259
		// sector rankings
260
		$menu_item = array();
261
		$menu_item['entry'] = create_link(create_container('skeleton.php', 'rankings_sector_kill.php'), 'Sector Kills', 'nav');
262
		$menu[] = $menu_item;
263
264
		create_sub_menu($menu, $active_level1, $active_level2);
265
	}
266
267
	public static function bank() {
268
		global $player;
269
270
		$menu_items[] = create_link(create_container('skeleton.php', 'bank_personal.php'),
0 ignored issues
show
Comprehensibility Best Practice introduced by
$menu_items was never initialized. Although not strictly required by PHP, it is generally a good practice to add $menu_items = array(); before regardless.
Loading history...
271
														'Personal Account', 'nav');
272
273
		if ($player->hasAlliance()) {
274
			$menu_items[] = create_link(create_container('skeleton.php', 'bank_alliance.php'),
275
															'Alliance Account', 'nav');
276
		}
277
278
		$menu_items[] = create_link(create_container('skeleton.php', 'bank_anon.php'),
279
														'Anonymous Account', 'nav');
280
		create_menu($menu_items);
281
	}
282
283
	public static function council($race_id) {
284
		global $player;
285
286
		$menu_items[] = create_link(create_container('skeleton.php', 'council_list.php'),
0 ignored issues
show
Comprehensibility Best Practice introduced by
$menu_items was never initialized. Although not strictly required by PHP, it is generally a good practice to add $menu_items = array(); before regardless.
Loading history...
287
														'View Council', 'nav');
288
289
		$container = create_container('skeleton.php');
290
		$container['body'] = 'council_politics.php';
291
		$container['race_id'] = $race_id;
292
		$menu_items[] = create_link($container, 'Political Status', 'nav');
293
294
		$container['body'] = 'council_send_message.php';
295
		$container['race_id'] = $race_id;
296
		$menu_items[] = create_link($container, 'Send Message', 'nav');
297
298
		if ($player->getRaceID() == $race_id) {
299
			if ($player->isOnCouncil()) {
300
				$menu_items[] = create_link(create_container('skeleton.php', 'council_vote.php'),
301
																'Voting Center', 'nav');
302
			}
303
			if ($player->isPresident()) {
304
				$menu_items[] = create_link(create_container('skeleton.php', 'council_embassy.php'),
305
																'Embassy', 'nav');
306
			}
307
		}
308
309
		create_menu($menu_items);
310
	}
311
312
	public static function bar() {
313
		global $template;
314
		$template->assign('MenuItems', array(
315
					array('Link'=>Globals::getBarMainHREF(), 'Text'=>'Bar Main'),
316
					array('Link'=>Globals::getBarLottoPlayHREF(), 'Text'=>'Lotto'),
317
					array('Link'=>Globals::getBarBlackjackHREF(), 'Text'=>'BlackJack')));
318
	}
319
320
	public static function news(Template $template) {
321
		global $var;
322
		$menuItems = array();
323
		if (SmrSession::getGameID() == $var['GameID']) {
324
			$menuItems[] = array('Link'=>SmrSession::getNewHREF(create_container('skeleton.php', 'news_read_current.php', array('GameID'=>$var['GameID']))), 'Text'=>'Read Current News');
325
		}
326
		$menuItems[] = array('Link'=>SmrSession::getNewHREF(create_container('skeleton.php', 'news_read.php', array('GameID'=>$var['GameID']))), 'Text'=>'Read Latest News');
327
		$menuItems[] = array('Link'=>SmrSession::getNewHREF(create_container('skeleton.php', 'news_read_advanced.php', array('GameID'=>$var['GameID']))), 'Text'=>'Advanced News');
328
329
		$template->assign('MenuItems', $menuItems);
330
	}
331
332
	public static function navigation(Template $template, AbstractSmrPlayer $player) {
333
		$menuItems = array();
334
		$menuItems[] = array('Link'=>Globals::getPlotCourseHREF(), 'Text'=>'Plot A Course');
335
		if (!$player->isLandedOnPlanet()) {
336
			$menuItems[] = array('Link'=>Globals::getLocalMapHREF(), 'Text'=>'Local Map');
337
		}
338
		$menuItems[] = array('Link'=>'map_galaxy.php" target="gal_map', 'Text'=>'Galaxy Map');
339
		$template->assign('MenuItems', $menuItems);
340
	}
341
342
}
343
344
function create_menu($menu) {
345
	global $template;
346
	$return = '<span class="noWrap">' . implode('</span> | <span class="noWrap">', $menu) . '</span>';
347
	$template->unassign('MenuItems');
348
	$template->assign('MenuBar', $return);
349
}
350
351
function create_sub_menu($menu, $active_level1, $active_level2) {
352
	global $template;
353
	$return = ('<table class="bar1">');
354
	$return .= ('<tr>');
355
	$return .= ('<td>');
356
	$return .= ('<table class="fullwidth">');
357
	$return .= ('<tr class="bar1">');
358
	$return .= ('<td>');
359
360
	$return .= ('<table class="center">');
361
	$return .= ('<tr>');
362
	foreach ($menu as $number => $entry) {
363
		// insert spacer
364
		if ($number > 0) {
365
			$return .= ('<td>&nbsp;|&nbsp;</td>');
366
		}
367
368
		// if this is the active entry we mark it
369
		if ($number == $active_level1) {
370
			$active = ' class="bold"';
371
		} else {
372
			$active = '';
373
		}
374
375
		// echo entry itself
376
		$return .= ('<td ' . $active . '> ' . $entry['entry'] . '</td>');
377
378
	}
379
	$return .= ('</tr>');
380
381
	$return .= ('<tr>');
382
	foreach ($menu as $number => $entry) {
383
		// if this entry has a submenu and is the active one
384
		if (isset($entry['submenu']) && $number == $active_level1) {
385
			$return .= ('<td><small>');
386
			foreach ($entry['submenu'] as $sub_number => $sub_entry) {
387
				if ($sub_number > 0) {
388
					$return .= (' | ');
389
				}
390
391
				if ($sub_number == $active_level2) {
392
					$return .= ('<span class="bold">' . $sub_entry . '</span>');
393
				} else {
394
					$return .= ($sub_entry);
395
				}
396
			}
397
			$return .= ('</small></td>');
398
		} else {
399
			// if it's not the first entry we have to put
400
			// additional empty cell for the spacer
401
			//if ($number > 0)
402
				//echo ('<td>&nbsp;<td>');
403
404
			// emppty cell (no submenu)
405
			$return .= ('<td>&nbsp;<td>');
406
		}
407
	}
408
	$return .= ('</tr>');
409
410
	$return .= ('</table>');
411
412
	$return .= ('</td>');
413
	$return .= ('</tr>');
414
	$return .= ('</table>');
415
	$return .= ('</td>');
416
	$return .= ('</tr>');
417
	$return .= ('</table>');
418
	$template->unassign('MenuItems');
419
	$template->unassign('MenuBar');
420
	$template->assign('SubMenuBar', $return);
421
}
422