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

album_entry()   F
last analyzed

Complexity

Conditions 21
Paths > 20000

Size

Total Lines 174
Code Lines 121

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 21
eloc 121
c 1
b 0
f 0
nc 24578
nop 1
dl 0
loc 174
rs 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php declare(strict_types=1);
2
3
use Smr\Database;
4
5
function main_page(): void {
6
	$db = Database::getInstance();
7
	$session = Smr\Session::getInstance();
8
9
	// list of all first letter nicks
10
	create_link_list();
11
12
	// news
13
	echo('<p><u>Space Merchant Realms Photo Album Rules</u>');
14
	echo('<ol>');
15
	echo('<li>500 x 500 pixel maximum photo size.</li>');
16
	echo('<li>Only .jpg, .png, or .gif files will be accepted.</li>');
17
	echo('<li>No derogatory or vulgar pictures will be accepted.</li>');
18
	echo('<li>Pictures MUST depict the real you. No anime, fictional, or otherwise \'fake\' pictures are allowed.</li>');
19
	echo('<li>Please watch your language while posting within the album. Same general rules apply here as in SMR chat rooms.</li>');
20
	echo('<li>Please respect all members in this area. Treat them as you would want to be treated. Do not post cruel or otherwise unneeded comments about someone or their property.</li>');
21
	echo('<li>You must be logged into your account to post within this album. Therefore, if you break any of these rules, your account may be subject to disablement.</li>');
22
	echo('</ol>');
23
	echo('<small><b>Please Note:</b> This is your only warning! All rule violations (even first time offenders) will be subject to a 1-day ban. Repeat offenders may incur longer bans.</small>');
24
	echo('</p>');
25
26
	echo('<p>&nbsp;</p>');
27
28
	// most hits
29
	echo('<p><u>Top 5 Pictures</u><br /><br />');
30
	$dbResult = $db->read('SELECT *
31
				FROM album
32
				WHERE approved = \'YES\'
33
				ORDER BY page_views DESC
34
				LIMIT 5');
35
	foreach ($dbResult->records() as $dbRecord) {
36
		$page_views = $dbRecord->getInt('page_views');
37
		$nick = get_album_nick($dbRecord->getInt('account_id'));
38
39
		echo('<a href="?nick=' . urlencode($nick) . '">' . $nick . '</a> (' . $page_views . ')<br />');
40
	}
41
42
	// latest picture
43
	$dateFormat = $session->hasAccount() ? $session->getAccount()->getDateTimeFormat() : DEFAULT_DATE_TIME_FORMAT;
44
	echo('<p><u>Latest Picture</u><br /><br />');
45
	$dbResult = $db->read('SELECT *
46
				FROM album
47
				WHERE approved = \'YES\'
48
				ORDER BY created DESC
49
				LIMIT 5');
50
	if ($dbResult->hasRecord()) {
51
		foreach ($dbResult->records() as $dbRecord) {
52
			$created = $dbRecord->getInt('created');
53
			$nick = get_album_nick($dbRecord->getInt('account_id'));
54
55
			echo('<span style="font-size:85%;"><b>[' . date($dateFormat, $created) . ']</b> Picture of <a href="?nick=' . urlencode($nick) . '">' . $nick . '</a> added</span><br />');
56
		}
57
	} else {
58
		echo('<span style="font-size:85%;">no entries</span>');
59
	}
60
	echo('</p>');
61
}
62
63
function album_entry(int $album_id): void {
64
	$db = Database::getInstance();
65
	$session = Smr\Session::getInstance();
66
67
	// list of all first letter nicks
68
	create_link_list();
69
70
	if ($session->hasAccount() && $album_id != $session->getAccountID()) {
71
		$db->write('UPDATE album
72
				SET page_views = page_views + 1
73
				WHERE account_id = ' . $db->escapeNumber($album_id) . ' AND
74
					approved = \'YES\'');
75
	}
76
77
	$dbResult = $db->read('SELECT *
78
				FROM album
79
				WHERE account_id = ' . $db->escapeNumber($album_id) . ' AND
80
					approved = \'YES\'');
81
	if ($dbResult->hasRecord()) {
82
		$dbRecord = $dbResult->record();
83
		$location = $dbRecord->getNullableString('location');
84
		$email = $dbRecord->getNullableString('email');
85
		$website = $dbRecord->getNullableString('website');
86
		$day = $dbRecord->getInt('day');
87
		$month = $dbRecord->getInt('month');
88
		$year = $dbRecord->getInt('year');
89
		$other = nl2br($dbRecord->getString('other'));
90
		$page_views = $dbRecord->getInt('page_views');
91
		$disabled = $dbRecord->getBoolean('disabled');
92
	} else {
93
		echo('<h1>Error</h1>');
94
		echo('This user doesn\'t have an entry in our album!');
95
		return;
96
	}
97
98
	// get this user's nick
99
	$nick = get_album_nick($album_id);
100
101
	echo('<table border="0" cellpadding="5" cellspacing="0">');
102
	echo('<tr>');
103
	echo('<td colspan="2">');
104
	echo '<div style="margin-left: auto; margin-right: auto; width: 50%">';
105
	echo('<table style="width: 100%">');
106
	echo('<tr>');
107
108
	$dbResult = $db->read('SELECT hof_name
109
				FROM album JOIN account USING(account_id)
110
				WHERE hof_name < ' . $db->escapeString($nick) . ' AND
111
					approved = \'YES\'
112
				ORDER BY hof_name DESC
113
				LIMIT 1');
114
	echo '<td class="center" style="width: 30%" valign="middle">';
115
	if ($dbResult->hasRecord()) {
116
		$priv_nick = $dbResult->record()->getString('hof_name');
117
		echo '<a href="?nick=' . urlencode($priv_nick) . '"><img src="/images/album/rew.jpg" alt="' . $priv_nick . '" border="0"></a>&nbsp;&nbsp;&nbsp;';
118
	}
119
	echo '</td>';
120
	echo('<td class="center" valign="middle"><span style="font-size:150%;">' . $nick . '</span><br /><span style="font-size:75%;">Views: ' . $page_views . '</span></td>');
121
122
	$dbResult = $db->read('SELECT hof_name
123
				FROM album JOIN account USING(account_id)
124
				WHERE hof_name > ' . $db->escapeString($nick) . ' AND
125
					approved = \'YES\'
126
				ORDER BY hof_name
127
				LIMIT 1');
128
	echo '<td class="center" style="width: 30%" valign="middle">';
129
	if ($dbResult->hasRecord()) {
130
		$next_nick = $dbResult->record()->getString('hof_name');
131
		echo '&nbsp;&nbsp;&nbsp;<a href="?nick=' . urlencode($next_nick) . '"><img src="/images/album/fwd.jpg" alt="' . $next_nick . '" border="0"></a>';
132
	}
133
	echo '</td>';
134
135
	echo('</tr>');
136
	echo('</table>');
137
	echo '</div>';
138
	echo('</td>');
139
	echo('</tr>');
140
	echo('<tr>');
141
	echo('<td colspan="2" class="center" valign="middle">');
142
143
	if ($disabled === false) {
144
		echo('<img src="../upload/' . $album_id . '">');
145
	} else {
146
		echo('<img src="../images/album/disabled.jpg">');
147
	}
148
149
	echo('</td>');
150
	echo('</tr>');
151
152
	if (empty($location)) {
153
		$location = 'N/A';
154
	}
155
	echo('<tr>');
156
	echo('<td class="right bold" width="10%">Location:</td><td>' . $location . '</td>');
157
	echo('</tr>');
158
159
	if (empty($email)) {
160
		$email = 'N/A';
161
	}
162
	echo('<tr>');
163
	echo('<td class="right bold" width="10%">E-mail:</td><td>' . $email . '</td>');
164
	echo('</tr>');
165
166
	if (empty($website)) {
167
		$website = 'N/A';
168
	} else {
169
		$website = '<a href="' . $website . '" target="_new">' . $website . '</a>';
170
	}
171
	echo('<tr>');
172
	echo('<td class="right bold" width="10%">Website:</td><td>' . $website . '</td>');
173
	echo('</tr>');
174
175
	echo('<tr>');
176
	if (!empty($day) && !empty($month) && !empty($year)) {
177
		$birthdate = $month . ' / ' . $day . ' / ' . $year;
178
	}
179
	if (empty($birthdate) && !empty($year)) {
180
		$birthdate = 'Year ' . $year;
181
	}
182
	if (empty($birthdate)) {
183
		$birthdate = 'N/A';
184
	}
185
	echo('<td class="right bold" width="10%">Birthdate:</td><td>' . $birthdate . '</td>');
186
	echo('</tr>');
187
188
	if (empty($other)) {
189
		$other = 'N/A';
190
	}
191
	echo('<tr>');
192
	echo('<td class="right bold" valign="top" width="10%">Other&nbsp;Info:</td><td>' . $other . '</td>');
193
	echo('</tr>');
194
195
	echo('<tr>');
196
	echo('<td colspan="2">');
197
	echo('<u>Comments</u><br /><br />');
198
199
	$dateFormat = $session->hasAccount() ? $session->getAccount()->getDateTimeFormat() : DEFAULT_DATE_TIME_FORMAT;
200
	$dbResult = $db->read('SELECT *
201
				FROM album_has_comments
202
				WHERE album_id = ' . $db->escapeNumber($album_id));
203
	foreach ($dbResult->records() as $dbRecord) {
204
		$time = $dbRecord->getInt('time');
205
		$postee = get_album_nick($dbRecord->getInt('post_id'));
206
		$msg = $dbRecord->getString('msg');
207
208
		echo('<span style="font-size:85%;">[' . date($dateFormat, $time) . '] &lt;' . $postee . '&gt; ' . $msg . '</span><br />');
209
	}
210
211
	if ($session->hasAccount()) {
212
		echo('<form action="album_comment_processing.php">');
213
		echo('<input type="hidden" name="album_id" value="' . $album_id . '">');
214
		echo('<table>');
215
		echo('<tr>');
216
		echo('<td style="color:green; font-size:70%;">Nick:<br /><input type="text" size="10" name="nick" value="' . htmlspecialchars(get_album_nick($session->getAccountID())) . '" readonly></td>');
217
		echo('<td style="color:green; font-size:70%;">Comment:<br /><input type="text" size="50" name="comment" required></td>');
218
		echo('<td style="color:green; font-size:70%;"><br /><input type="submit" name="action" value="Send"></td>');
219
		$dbResult = $db->read('SELECT 1
220
					FROM account_has_permission
221
					WHERE account_id = ' . $db->escapeNumber($session->getAccountID()) . ' AND
222
						permission_id = ' . $db->escapeNumber(PERMISSION_MODERATE_PHOTO_ALBUM));
223
		if ($dbResult->hasRecord()) {
224
			echo('<td style="color:green; font-size:70%;"><br /><input type="submit" name="action" value="Moderate"></td>');
225
		}
226
227
		echo('</tr>');
228
		echo('</table>');
229
		echo('</form>');
230
	} else {
231
		echo('<p>Please <a href="/login.php?return_page=/album/?nick=' . urlencode($nick) . '"><u>login</u></a> if you want comment on this picture!</p>');
232
	}
233
234
	echo('</td>');
235
	echo('</tr>');
236
	echo('</table>');
237
238
}
239
240
/**
241
 * @param array<int> $album_ids
242
 */
243
function search_result(array $album_ids): void {
244
245
	// list of all first letter nicks
246
	create_link_list();
247
248
	echo('<div class="center big">Please make a selection!</div>');
249
250
	echo('<table border="0" class="center" cellpadding="5" cellspacing="0">');
251
252
	$count = 0;
253
	echo('<tr><td class="left" width="25%" valign="top">');
254
255
	foreach ($album_ids as $album_id) {
256
		$count++;
257
258
		$nick = get_album_nick($album_id);
259
260
		echo('<a href="?nick=' . urlencode($nick) . '" style="font-size:80%;">' . $nick . '</a><br />');
261
262
		if (floor(count($album_ids) / 4) > 0 && $count % floor(count($album_ids) / 4) == 0) {
263
			echo('</td><td width="25%" valign="top">');
264
		}
265
	}
266
	echo('</td></tr>');
267
	echo('</table>');
268
}
269
270
function create_link_list(): void {
271
	echo('<div class="center" style="font-size:80%;">[ ');
272
	echo('<a href="?nick=%">All</a> | ');
273
	echo('<a href="?nick=A">A</a> | ');
274
	echo('<a href="?nick=B">B</a> | ');
275
	echo('<a href="?nick=C">C</a> | ');
276
	echo('<a href="?nick=D">D</a> | ');
277
	echo('<a href="?nick=E">E</a> | ');
278
	echo('<a href="?nick=F">F</a> | ');
279
	echo('<a href="?nick=G">G</a> | ');
280
	echo('<a href="?nick=H">H</a> | ');
281
	echo('<a href="?nick=I">I</a> | ');
282
	echo('<a href="?nick=J">J</a> | ');
283
	echo('<a href="?nick=K">K</a> | ');
284
	echo('<a href="?nick=L">L</a> | ');
285
	echo('<a href="?nick=M">M</a> | ');
286
	echo('<a href="?nick=N">N</a> | ');
287
	echo('<a href="?nick=O">O</a> | ');
288
	echo('<a href="?nick=P">P</a> | ');
289
	echo('<a href="?nick=Q">Q</a> | ');
290
	echo('<a href="?nick=R">R</a> | ');
291
	echo('<a href="?nick=S">S</a> | ');
292
	echo('<a href="?nick=T">T</a> | ');
293
	echo('<a href="?nick=U">U</a> | ');
294
	echo('<a href="?nick=V">V</a> | ');
295
	echo('<a href="?nick=W">W</a> | ');
296
	echo('<a href="?nick=X">X</a> | ');
297
	echo('<a href="?nick=Y">Y</a> | ');
298
	echo('<a href="?nick=Z">Z</a> ]</div>');
299
	echo('<hr class="center">');
300
}
301
302
303
304
function get_album_nick(int $album_id): string {
305
	if ($album_id == 0) {
306
		return 'System';
307
	}
308
309
	return SmrAccount::getAccount($album_id)->getHofName();
310
}
311
312
/*
313
AddHandler catch-all-handler .php
314
Action catch-all-handler /home/mrspock/smrealms.de/beta/www/album/index.php
315
*/
316