-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
151 lines (81 loc) · 3.09 KB
/
index.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
ob_start("ob_gzhandler");
session_start();
$r_c = 0;
require_once "inc/functions.php";
require_once "inc/classes/master.class.php";
require_once "inc/classes/user.class.php";
$twig = twigInit();
use Aptoma\Twig\Extension\MarkdownExtension;
use Aptoma\Twig\Extension\MarkdownEngine;
$engine = new MarkdownEngine\MichelfMarkdownEngine();
$twig->addExtension(new MarkdownExtension($engine));
cookieCheck();
$user = new user((isset($_SESSION["userid"]) ? $_SESSION["userid"] : null));
$someoneIsLive = isAnyoneLive();
try {
$squery = $con->query("SELECT `custompages`.`title`, `custompages`.`stringid` FROM `custompages` WHERE BIN(`custompages`.`live`) = 1");
$pages = array();
while ($srow = $squery->fetch()){
$pages[] = array("title" => $srow["title"], "stringid" => $srow["stringid"]);
$pageids[] = $srow["stringid"];
}
} catch (PDOException $e) {
echo "An error occurred while trying to fetch the custom pages.";
}
$loginReturn = $user->login();
$index_var = array("canonical" => canonical(), "pages" => $pages, "someoneislive" => $someoneIsLive, "loginreturn" => $loginReturn);
if (isset($_GET["p"]) && vf($_GET["p"])) {
$p = strip($_GET["p"]);
if (file_exists("inc/" . $p . ".php") && $p != "functions" && $p != "config") {
require_once "inc/" . $p . ".php";
} else if (in_array($p, $pageids)) {
require_once "inc/custom.php";
} else if ($p != "login" && $p != "logout") {
header("Location: /notfound.php");
}
} else {
require_once "inc/maps.php";
}
function cookieCheck() {
global $con;
if (isset($_COOKIE["userid"]) && !isset($_SESSION["userid"])) {
$cv = $_COOKIE["userid"];
try {
$squery = $con->prepare("SELECT `users`.`id` FROM `users` WHERE `users`.`cookieh` = :cv");
$squery->bindValue("cv", hash("sha256", $cv), PDO::PARAM_STR);
$squery->execute();
} catch(PDOException $e) {
echo "Failed to fetch cookie info.";
}
if ($squery->rowCount() == 1) {
$srow = $squery->fetch();
$_SESSION["userid"] = $srow["id"];
$cookieh = cookieh();
try {
$uquery = $con->prepare("UPDATE `users` SET `users`.`cookieh` = :cookieh WHERE `users`.`id` = :id");
$uquery->bindValue("cookieh", hash("sha256", $cookieh), PDO::PARAM_STR);
$uquery->bindValue("id", $srow["id"], PDO::PARAM_INT);
$uquery->execute();
} catch (PDOException $e) {
echo "Failed to update cookie info.";
}
setcookie("userid", $cookieh, time() + 2592000, "/");
}
}
}
function isAnyoneLive() {
global $con;
try {
$squery = $con->query("SELECT `streams`.`title` FROM `streams`");
while ($srow = $squery->fetch()) {
if (vf($srow["title"])) {
return true;
}
}
} catch (PDOException $e) {
echo "An error occurred while trying to fetch the streams.";
}
return false;
}
ob_end_flush();