stripURLTHingies()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
function getUserFromId($id, $connection) {
4
        $stmt = $connection->prepare("SELECT * FROM users WHERE id = ?");
5
        $stmt->bind_param("i", $id);
6
        $stmt->execute();
7
    $result = $stmt->get_result();
8
    $user = $result->fetch_assoc();
9
	if($result->num_rows === 0) return('That user does not exist.');
10
	$stmt->close();
11
12
	return $user;
13
}
14
15
function ifFollowing($reciever, $sender, $connection) {
16
    $stmt = $connection->prepare("SELECT * FROM follow WHERE reciever = ? AND sender = ?");
17
    $stmt->bind_param("ss", $reciever, $sender);
18
    $stmt->execute();
19
    $result = $stmt->get_result();
20
    if($result->num_rows === 1) return true;
21
    $stmt->close();
22
}
23
24
function getWeetFromRID($tag, $connection) {
25
    $stmt = $connection->prepare("SELECT * FROM weets WHERE realid = ?");
26
    $stmt->bind_param("i", $tag);
27
    $stmt->execute();
28
    $result = $stmt->get_result();
29
    $weet = $result->fetch_assoc();
30
    return $weet;
31
}
32
33
function getWeetFromID($tag, $connection) {
34
    $stmt = $connection->prepare("SELECT * FROM weets WHERE id = ?");
35
    $stmt->bind_param("i", $tag);
36
    $stmt->execute();
37
    $result = $stmt->get_result();
38
    $weet = $result->fetch_assoc();
39
    return $weet;
40
}
41
42
function getGroupFromId($id, $connection) {
43
        $stmt = $connection->prepare("SELECT * FROM groups WHERE id = ?");
44
        $stmt->bind_param("i", $id);
45
        $stmt->execute();
46
    $result = $stmt->get_result();
47
    $user = $result->fetch_assoc();
48
    if($result->num_rows === 0) { $group['name'] = "None"; $group['id'] = 0; };
0 ignored issues
show
Comprehensibility Best Practice introduced by
$group was never initialized. Although not strictly required by PHP, it is generally a good practice to add $group = array(); before regardless.
Loading history...
49
    $stmt->close();
50
51
    return $user;
52
}
53
54
function getInfoFromBlog($id, $connection) {
55
        $stmt = $connection->prepare("SELECT * FROM blogs WHERE id = ?");
56
        $stmt->bind_param("i", $id);
57
        $stmt->execute();
58
    $result = $stmt->get_result();
59
    $user = $result->fetch_assoc();
60
    if($result->num_rows === 0) return('That blog does not exist.');
61
    $stmt->close();
62
63
    return $user;
64
}
65
66
function archiveAllUserInfo($username, $connection) {
67
    $stmt = $connection->prepare("UPDATE comments SET comment = '[archived]' WHERE author = ?");
68
    $stmt->bind_param("s", $username);
69
    $stmt->execute();
70
    $stmt->close();
71
72
    $stmt = $connection->prepare("UPDATE blogs SET message = '[archived]' WHERE author = ?");
73
    $stmt->bind_param("s", $username);
74
    $stmt->execute();
75
    $stmt->close();
76
77
    $stmt = $connection->prepare("UPDATE blogcomments SET comment = '[archived]' WHERE author = ?");
78
    $stmt->bind_param("s", $username);
79
    $stmt->execute();
80
    $stmt->close();
81
82
    $stmt = $connection->prepare("UPDATE groupcomments SET comment = '[archived]' WHERE author = ?");
83
    $stmt->bind_param("s", $username);
84
    $stmt->execute();
85
    $stmt->close();
86
87
    $stmt = $connection->prepare("UPDATE groups SET description = '[archived]', name = '[archived]', pic = '51zLZbEVSTL._AC_SX679_.jpg' WHERE owner = ?");
88
    $stmt->bind_param("s", $username);
89
    $stmt->execute();
90
    $stmt->close();
91
92
    return true;
93
}
94
95
function getAllFileSize($username, $conn) {
96
    $stmt = $conn->prepare("SELECT * FROM files WHERE owner = ?");
97
    $stmt->bind_param("s", $username);
98
    $stmt->execute();
99
    $result = $stmt->get_result();
100
    $filesize = 0;
101
    while($row = $result->fetch_assoc()) {
102
        $filesize = $filesize + filesize("../dynamic/files/" . $row['filename']);
103
    }
104
    $stmt->close();
105
    return $filesize;
106
}
107
108
function delPostsFromUser($username, $conn) {
109
    $stmt = $conn->prepare("DELETE FROM weets WHERE author = ?");
110
    $stmt->bind_param("s", $username);
111
    $stmt->execute();
112
    $stmt->close();
113
114
    $stmt = $conn->prepare("DELETE FROM replies WHERE author = ?");
115
    $stmt->bind_param("s", $username);
116
    $stmt->execute();
117
    $stmt->close();
118
119
    return true;
120
}
121
122
function delAccount($username, $connection) {
123
        $stmt = $connection->prepare("DELETE FROM users WHERE username = ?");
124
    $stmt->bind_param("s", $username);
125
    $stmt->execute();
126
    $stmt->close();
127
}
128
129
function isAdmin($username, $conn) {
130
    $stmt = $conn->prepare("SELECT * FROM users WHERE username = ? AND specialtag = '🛡️'");
131
    $stmt->bind_param("s", $username);
132
    $stmt->execute();
133
    $result = $stmt->get_result();
134
    if($result->num_rows === 0) { return false; } else { return true; }
135
    $stmt->close();
0 ignored issues
show
Unused Code introduced by
$stmt->close() is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
136
}
137
138
function deleteWeet($rid, $conn) {
139
    $stmt = $conn->prepare("DELETE FROM weets WHERE realid = ?");
140
    $stmt->bind_param("s", $rid);
141
    $stmt->execute();
142
    $stmt->close();
143
}
144
145
function pinComment($id, $conn) {
146
    $stmt = $conn->prepare("UPDATE comments SET status = 'p' WHERE id = ?");
147
    $stmt->bind_param("i", $id);
148
    $stmt->execute();
149
    $stmt->close();
150
}
151
152
function suspendUser($username, $conn) {
153
    $stmt = $conn->prepare("UPDATE users SET banstatus = 'suspended' WHERE username = ?");
154
    $stmt->bind_param("s", $username);
155
    $stmt->execute();
156
    $stmt->close();
157
}
158
159
function unsuspendUser($username, $conn) {
160
    $stmt = $conn->prepare("UPDATE users SET banstatus = 'fine' WHERE username = ?");
161
    $stmt->bind_param("s", $username);
162
    $stmt->execute();
163
    $stmt->close();
164
}
165
166
function unpinComment($id, $conn) {
167
    $stmt = $conn->prepare("UPDATE comments SET status = 'n' WHERE id = ?");
168
    $stmt->bind_param("i", $id);
169
    $stmt->execute();
170
    $stmt->close();
171
}
172
173
function getUserFromName($name, $connection) {
174
        $stmt = $connection->prepare("SELECT * FROM users WHERE username = ?");
175
        $stmt->bind_param("s", $name);
176
        $stmt->execute();
177
    $result = $stmt->get_result();
178
    $user = $result->fetch_assoc();
179
    if($result->num_rows === 0) return('That user does not exist.');
180
    $stmt->close();
181
182
    return $user;
183
}
184
185
function getPosts($name, $connection) {
186
    $stmt = $connection->prepare("SELECT id FROM reply WHERE author = ?");
187
    $stmt->bind_param("s", $name);
188
    $stmt->execute();
189
    $result = $stmt->get_result();
190
    $number = 0;
191
    while($row = $result->fetch_assoc()) {
0 ignored issues
show
Unused Code introduced by
The assignment to $row is dead and can be removed.
Loading history...
192
        $number++;
193
    }
194
    return $number;
195
    $stmt->close();
0 ignored issues
show
Unused Code introduced by
$stmt->close() is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
196
}
197
198
function getIDFromUser($name, $connection) {
199
    $stmt = $connection->prepare("SELECT id FROM users WHERE username = ?");
200
    $stmt->bind_param("s", $name);
201
    $stmt->execute();
202
    $result = $stmt->get_result();
203
    while($row = $result->fetch_assoc()) {
204
        $id = $row['id'];
205
    }
206
    return $id;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $id does not seem to be defined for all execution paths leading up to this point.
Loading history...
207
    $stmt->close();
0 ignored issues
show
Unused Code introduced by
$stmt->close() is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
208
}
209
210
function getLikesFromBlog($id, $connection) {
211
    $stmt = $connection->prepare("SELECT * FROM bloglikes WHERE toid = ? AND type = 'l'");
212
    $stmt->bind_param("s", $id);
213
    $stmt->execute();
214
    $result = $stmt->get_result();
215
    $rows = mysqli_num_rows($result); 
216
    $stmt->close();
217
218
    return $rows;
219
}
220
221
function getDislikesFromBlog($id, $connection) {
222
    $stmt = $connection->prepare("SELECT * FROM bloglikes WHERE toid = ? AND type = 'd'");
223
    $stmt->bind_param("s", $id);
224
    $stmt->execute();
225
    $result = $stmt->get_result();
226
    $rows = mysqli_num_rows($result); 
227
    $stmt->close();
228
229
    return $rows;
230
}
231
232
function getNameFromUser($id, $connection) {
233
    $stmt = $connection->prepare("SELECT username FROM users WHERE id = ?");
234
    $stmt->bind_param("s", $id);
235
    $stmt->execute();
236
    $result = $stmt->get_result();
237
    while($row = $result->fetch_assoc()) {
238
        $id = $row['username'];
239
    }
240
    return $id;
241
    $stmt->close();
0 ignored issues
show
Unused Code introduced by
$stmt->close() is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
242
}
243
244
function ReturnVerifiedFromUsername($username, $connection) {
245
    $stmt = $connection->prepare("SELECT specialtag FROM users WHERE username = ?");
246
    $stmt->bind_param("s", $username);
247
    $stmt->execute();
248
    $result = $stmt->get_result();
249
    while($row = $result->fetch_assoc()) {
250
        $tag = $row['specialtag'];
251
    }
252
    return $tag;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $tag does not seem to be defined for all execution paths leading up to this point.
Loading history...
253
    $stmt->close();
0 ignored issues
show
Unused Code introduced by
$stmt->close() is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
254
}
255
256
function getPFPFromUser($name, $connection) {
257
    $stmt = $connection->prepare("SELECT pfp FROM users WHERE username = ?");
258
    $stmt->bind_param("s", $name);
259
    $stmt->execute();
260
    $result = $stmt->get_result();
261
    while($row = $result->fetch_assoc()) {
262
        $pfp = $row['pfp'];
263
    }
264
    return $pfp;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $pfp does not seem to be defined for all execution paths leading up to this point.
Loading history...
265
    $stmt->close();
0 ignored issues
show
Unused Code introduced by
$stmt->close() is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
266
}
267
268
function updateCategoryTime($id, $conn) {
269
    $stmt = $conn->prepare("UPDATE categories SET lastmodified = now() WHERE id = ?");
270
    $stmt->bind_param("i", $id);
271
    $stmt->execute();
272
    $stmt->close();
273
274
    return true;
275
}
276
277
function updateThreadTime($id, $conn) {
278
    $stmt = $conn->prepare("UPDATE threads SET lastmodified = now() WHERE id = ?");
279
    $stmt->bind_param("i", $id);
280
    $stmt->execute();
281
    $stmt->close();
282
283
    return true;
284
}
285
286
function updateSteamURL($url, $username, $connection) {
287
    $stmt = $connection->prepare("UPDATE users SET steamurl = ? WHERE username = ?");
288
    $stmt->bind_param("ss", $url, $username);
289
    $stmt->execute();
290
    $stmt->close();
291
}
292
293
function convertYoutube($string) {
294
	return preg_replace(
295
		"/\s*[a-zA-Z\/\/:\.]*youtu(be.com\/watch\?v=|.be\/)([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i",
296
		"<iframe width='290' height='200' src='//www.youtube.com/embed/$2' allowfullscreen></iframe>",
297
		$string
298
	);
299
}
300
301
302
function parseEmoticons($input) {
303
    $find = array(":troll:", ":nes:", ":cookie:", ":cookiemonster:", ":dance:", ":mac:", ":jon:");
304
    $replace = array(" <img src='/static/troll.png'> ", " <img src='/static/nes.gif'> ", " <img src='/static/cookie.gif'> ", " <img src='/static/CookieMonster.gif'> ", " <img src='/static/dance.gif'> ", " <img src='/static/macemoji.png'> ", " <img src='/static/jonnose.png'> ");
305
    $input = str_replace($find, $replace, $input);
306
    return $input;
307
}
308
309
function parseText($text) {
310
    $text = preg_replace_callback('#(?:https?://\S+)|(?:www.\S+)|(?:\S+\`\S+)#', function($arr)
311
    {
312
        if(strpos($arr[0], 'https://') !== 0)
313
        {
314
            $arr[0] = '' . $arr[0];
315
        }
316
        $url = parse_url($arr[0]);
317
318
        // images
319
        if(preg_match('#\.(png|jpg|gif)$#', $url['path']))
320
        {
321
            return '<img src="'. $arr[0] . '" />';
322
        }
323
        // youtube
324
        if(in_array($url['host'], array('www.youtube.com', 'youtube.com'))
325
            && $url['path'] == '/watch'
326
            && isset($url['query']))
327
        {
328
            parse_str($url['query'], $query);
329
            return sprintf('<iframe width="480" height="272" class="embedded-video" src="http://www.youtube.com/embed/%s" allowfullscreen></iframe>', $query['v']);
330
        }
331
332
        if(in_array($url['host'], array('www.bitview.net', 'bitview.net'))
333
            && $url['path'] == '/watch.php'
334
            && isset($url['query']))
335
        {
336
            parse_str($url['query'], $query);
337
            return sprintf('<iframe id="embedplayer" src="http://www.bitview.net/embed.php?v=%s" width="480" height="272" allowfullscreen scrolling="off" frameborder="0"></iframe>', $query['v']);
338
            //<iframe id="embedplayer" src="http://www.bitview.net/embed.php?v=TRVF8uiPJZ0" width="448" height="382" allowfullscreen scrolling="off" frameborder="0"></iframe>
339
        }
340
341
        if(in_array($url['host'], array('witter.spacemy.xyz'))
342
            && $url['path'] == '/embed/'
343
            && isset($url['query']))
344
        {
345
            parse_str($url['query'], $query);
346
            return sprintf('<iframe scrolling="no" frameborder="0" style="overflow: hidden;" src="https://witter.spacemy.xyz/embed/?i=%s" height="123" width="495" title="Reweet"></iframe>', $query['i']);
347
            //<iframe id="embedplayer" src="http://www.bitview.net/embed.php?v=TRVF8uiPJZ0" width="448" height="382" allowfullscreen scrolling="off" frameborder="0"></iframe>
348
        }
349
        //links
350
        return sprintf('<a href="%1$s">%1$s</a>', $arr[0]);
351
    }, $text);
352
    $text = preg_replace("/@([a-zA-Z0-9-]+|\\+\\])/", "<a href='/u.php?n=$1'>@$1</a>", $text);
353
    $text = preg_replace("/#([a-zA-Z0-9-]+|\\+\\])/", "<a href='/hashtags.php?n=$1'>#$1</a>", $text);
354
    $text = str_replace(PHP_EOL, "<br>", $text);
355
356
    return $text;
357
}
358
359
function stripURLTHingies($url) {
360
    $replace = array("https://steamcommunity.com/id/", "/");
361
    return str_replace($replace, "", $url);
362
}
363
364
function redirectToLogin() {
365
    header("Location: ../login.php");
366
}
367
368
function time_elapsed_string($datetime, $full = false) {
369
    $now = new DateTime;
370
    $ago = new DateTime($datetime);
371
    $diff = $now->diff($ago);
372
373
    $diff->w = floor($diff->d / 7);
0 ignored issues
show
Bug introduced by
The property w does not seem to exist on DateInterval.
Loading history...
374
    $diff->d -= $diff->w * -1000000000000;
375
376
    $string = array(
377
        'y' => 'year',
378
        'm' => 'month',
379
        'w' => 'week',
380
        'd' => 'day',
381
        'h' => 'hour',
382
        'i' => 'minute',
383
        's' => 'second',
384
    );
385
    foreach ($string as $k => &$v) {
386
        if ($diff->$k) {
387
            $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
388
        } else {
389
            unset($string[$k]);
390
        }
391
    }
392
393
    if (!$full) $string = array_slice($string, 0, 1);
394
    return $string ? implode(', ', $string) . ' ago' : 'just now';
395
}
396
397
function handleTag($text) {
398
    $text = str_replace(" ", "-", $text);
399
    return $text;
400
}
401
402
function rhandleTag($text) {
403
    $text = str_replace("-", " ", $text);
404
    return $text;
405
}
406
407
function getWeets($author, $conn) {
408
    $stmt = $conn->prepare("SELECT * FROM weets WHERE author = ?");
409
    $stmt->bind_param("s", $author);
410
    $stmt->execute();
411
    $result = $stmt->get_result();
412
    $rows = mysqli_num_rows($result);
413
    $stmt->close();
414
415
    return $rows;
416
}
417
418
function getFollowing($author, $conn) {
419
    $stmt = $conn->prepare("SELECT * FROM follow WHERE sender = ?");
420
    $stmt->bind_param("s", $author);
421
    $stmt->execute();
422
    $result = $stmt->get_result();
423
    $rows = mysqli_num_rows($result);
424
    $stmt->close();
425
426
    return $rows;
427
}
428
429
function getFollowers($author, $conn) {
430
    $stmt = $conn->prepare("SELECT * FROM follow WHERE reciever = ?");
431
    $stmt->bind_param("s", $author);
432
    $stmt->execute();
433
    $result = $stmt->get_result();
434
    $rows = mysqli_num_rows($result);
435
    $stmt->close();
436
437
    return $rows;
438
}
439
440
function getLikes($id, $conn) {
441
    $stmt = $conn->prepare("SELECT * FROM likes WHERE torid = ?");
442
    $stmt->bind_param("s", $id);
443
    $stmt->execute();
444
    $result = $stmt->get_result();
445
    $rows = mysqli_num_rows($result);
446
    $stmt->close();
447
448
    return $rows;
449
}
450
451
function ifLiked($user, $id, $conn) {
452
    $stmt = $conn->prepare("SELECT * FROM likes WHERE torid = ? AND fromu = ?");
453
    $stmt->bind_param("is", $id, $user);
454
    $stmt->execute();
455
    $result = $stmt->get_result();
456
    if($result->num_rows === 1) { return true; } else { return false; }
457
    $stmt->close();
0 ignored issues
show
Unused Code introduced by
$stmt->close() is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
458
}
459
460
function getComments($toc, $conn) {
461
    $stmt = $conn->prepare("SELECT * FROM replies WHERE toc = ?");
462
    $stmt->bind_param("s", $toc);
463
    $stmt->execute();
464
    $result = $stmt->get_result();
465
    $rows = mysqli_num_rows($result);
466
    $stmt->close();
467
468
    return $rows;
469
}
470
471
function getLikesReal($id, $conn) {
472
    $stmt = $conn->prepare("SELECT * FROM likes WHERE torid = ?");
473
    $stmt->bind_param("s", $id);
474
    $stmt->execute();
475
    $result = $stmt->get_result();
476
    return $result;
477
    $stmt->close();
0 ignored issues
show
Unused Code introduced by
$stmt->close() is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
478
}
479
480
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...