-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
204 lines (130 loc) · 4 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
ob_start('ob_gzhandler');
session_start();
$dir_level = 0;
require_once 'inc/functions.php';
require_once 'classes/user.class.php';
require_once 'vendor/autoload.php';
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem('templates');
$filters = Array(
new Twig_SimpleFilter('prepareLatexElements', 'prepareLatexElements'),
);
$twig = new Twig_Environment($loader);
foreach ($filters as $filter) {
$twig->addFilter($filter);
}
use Aptoma\Twig\Extension\MarkdownExtension;
use Aptoma\Twig\Extension\MarkdownEngine;
$engine = new MarkdownEngine\GitHubMarkdownEngine('aptoma/twig-markdown', true, '/tmp/markdown-cache');
$twig->addExtension(new MarkdownExtension($engine));
$index_var = array();
if (isset($_COOKIE['remember']) && !isset($_SESSION['userid'])) {
$array = json_decode($_COOKIE['remember'], true);
try {
$get = $con->prepare('select * from logins where session = :session');
$get->bindValue('session', $array['session'], PDO::PARAM_STR);
$get->execute();
} catch (PDOException $e) {
die($config['errors']['database']);
}
while ($session = $get->fetch()) {
if ($session['hash'] === hash('sha256', $array['token'])) {
$_SESSION['userid'] = $session['userid'];
$user = new user($_SESSION['userid']);
}
}
}
try {
$getSubjects = $con->query('select id, name from subjects where mandatory = 1 order by name asc');
} catch (PDOException $e) {
die($config['errors']['database']);
}
$index_var['subjects'] = array();
while ($subject = $getSubjects->fetch()) {
$index_var['subjects'][$subject['id']] = $subject;
$index_var['subjects'][$subject['id']]['categories'] = array();
try {
$getNotesData = $con->prepare('
select notes.id, categories.name
from notes
inner join categories on notes.category = categories.id
where notes.subjectid = :subjectid and notes.live = 1
order by category asc, ordernumber asc, id asc
');
$getNotesData->bindValue(
'subjectid',
$subject['id'],
PDO::PARAM_INT
);
$getNotesData->execute();
} catch (PDOException $e) {
die($config['errors']['database']);
}
while ($notesData = $getNotesData->fetch()) {
if (!isset($index_var['subjects'][$subject['id']]['categories'][$notesData['name']]))
$index_var['subjects'][$subject['id']]['categories'][$notesData['name']] = array('name' => $notesData['name']);
}
}
try {
$getSubjects = $con->query('select id, name from subjects where mandatory = 0 order by name asc');
} catch (PDOException $e) {
die($config['errors']['database']);
}
$index_var['othersubjects'] = array();
while ($subject = $getSubjects->fetch()) {
$index_var['othersubjects'][] = $subject;
}
$index_var['location'] = array();
if (isset($_SESSION['userid'])) {
$user = new user($_SESSION['userid']);
$username = $user->getData()['name'];
}
$index_var['username'] = (isset($_SESSION['userid'])) ? $username : '';
$index_var['css'] = '';
$index_var['mobilecss'] = '';
$index_var['canonical'] = getCanonicalUrl();
if (isset($_SESSION['status'])) {
$status = $_SESSION['status'];
$message = $_SESSION['message'];
unset($_SESSION['status']);
unset($_SESSION['message']);
} else {
$status = 'none';
$message = '';
}
if (isset($_GET['p'])) {
$p = $_GET['p'];
if (file_exists('inc/' . $p . '.php') && $p != 'functions') {
require_once 'inc/' . $p . '.php';
} else {
header('Location: /404/');
die();
}
} else {
/* if (isset($_COOKIE['getting-started'])) {
require_once 'inc/news.php';
} else {
setcookie(
"getting-started",
"true",
time() + (10 * 365 * 24 * 60 * 60)
);
require_once 'inc/getting-started.php';
} */
require_once 'inc/news.php';
}
function getCanonicalUrl() {
$url = 'https://erettsegik.hu/';
if (isset($_GET['p'])) {
$url .= $_GET['p'] . '/';
}
if (isset($_GET['action'])) {
$url .= $_GET['action'] . '/';
}
if (isset($_GET['id'])) {
$url .= $_GET['id'] . '/';
}
return $url;
}
ob_end_flush();