-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
52 lines (45 loc) · 1.42 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
function message($message, $die = false, $return = false) {
if(is_array($message)) $message = '<pre style="text-align:left">'.print_r($message,true).'</pre>';
elseif(is_null($message)) $message = '<pre style="font-style:italic">NULL</pre>';
elseif(is_bool($message)) $message = '<pre style="text-align:left">Boolean: '.($message == true ? 'true' : 'false').'</pre>';
else $message = "<pre>{$message}</pre>";
if($return) return($message);
else {
ob_clean();
echo $message;
if($die) exit;
}
}
function redirect(string $uri, string $httpMessage = null) {
if(is_null($httpMessage)) $httpMessage = 'HTTP/1.1 302 Found';
header($httpMessage);
header("Location: {$uri}");
exit;
}
function loggedIn(): bool {
if(isset($_SESSION['profile']) && count($_SESSION['profile']) > 0) return(true);
else return(false);
}
function tagNest(array &$tagList, int $parentId = 0, int $level = 0) {
$output = array();
foreach($tagList as $k => $t) {
if($t['parent_id'] == $parentId) {
$output[$t['tag']] = array(
'id' => $t['id'],
'parent' => $t['parent_id'],
'children' => tagNest($tagList, $t['id'], $level + 1)
);
}
}
return $output;
}
function printTags($tags) {
foreach($tags as $p => $t) { // p = parent, c = children
$class = $t['parent'] == 0 ? ' class="tag-parent"' : '';
echo "<div{$class}>".htmlspecialchars($p);
if(count($t['children']) > 0) printTags($t['children']);
echo '</div>';
}
}
?>