1 | <?php
|
---|
2 |
|
---|
3 | require_once('Config/Config.php');
|
---|
4 | require_once('Global.php');
|
---|
5 | require_once('Packages/Common/Common.php');
|
---|
6 | require_once('View.php');
|
---|
7 |
|
---|
8 | require_once('Modules/Meet/Meet.php');
|
---|
9 | require_once('Modules/Meet/MeetPage.php');
|
---|
10 | require_once('Modules/Dance/Dance.php');
|
---|
11 | require_once('Modules/Movie/Movie.php');
|
---|
12 | require_once('Modules/School/School.php');
|
---|
13 | require_once('Modules/Club/Club.php');
|
---|
14 | require_once('Modules/Event/Event.php');
|
---|
15 | require_once('Modules/Event/EventPage.php');
|
---|
16 |
|
---|
17 | if (isset($_SERVER['REMOTE_ADDR'])) session_start();
|
---|
18 |
|
---|
19 | class Core extends System
|
---|
20 | {
|
---|
21 | public array $Config;
|
---|
22 | public array $PathItems;
|
---|
23 | public bool $ShowPage;
|
---|
24 | public array $MainMenu;
|
---|
25 | public array $PageHeaders;
|
---|
26 | public array $Bars;
|
---|
27 |
|
---|
28 | function __construct()
|
---|
29 | {
|
---|
30 | parent::__construct();
|
---|
31 | $this->ShowPage = true;
|
---|
32 | $this->MainMenu = array();
|
---|
33 | $this->PageHeaders = array();
|
---|
34 | $this->Bars = array();
|
---|
35 | }
|
---|
36 |
|
---|
37 | function IsAdmin(): bool
|
---|
38 | {
|
---|
39 | return array_key_exists('IsAdmin', $_SESSION) and ($_SESSION['IsAdmin'] == 1);
|
---|
40 | }
|
---|
41 |
|
---|
42 | function Link(string $URL): string
|
---|
43 | {
|
---|
44 | return $this->Config['BaseURL'].$URL;
|
---|
45 | }
|
---|
46 |
|
---|
47 | function AbsoluteLink(string $URL): string
|
---|
48 | {
|
---|
49 | return $this->Config['HostName'].$this->Config['BaseURL'].$URL;
|
---|
50 | }
|
---|
51 |
|
---|
52 | function ShowMenu(): string
|
---|
53 | {
|
---|
54 | $Output = '<div>';
|
---|
55 | foreach ($this->MainMenu as $MenuItem)
|
---|
56 | {
|
---|
57 | $Output .= '<a href="'.$this->Link($MenuItem['Link']).'">'.$MenuItem['Title'].'</a> ';
|
---|
58 | }
|
---|
59 | $Output .= '</div>';
|
---|
60 | return $Output;
|
---|
61 | }
|
---|
62 |
|
---|
63 | function ProcessURL(): array
|
---|
64 | {
|
---|
65 | if (array_key_exists('REDIRECT_QUERY_STRING', $_SERVER))
|
---|
66 | $PathString = $_SERVER['REDIRECT_QUERY_STRING'];
|
---|
67 | else $PathString = '';
|
---|
68 | if (substr($PathString, -1, 1) == '/') $PathString = substr($PathString, 0, -1);
|
---|
69 | $PathItems = explode('/', $PathString);
|
---|
70 | if (array_key_exists('REQUEST_URI', $_SERVER) and (strpos($_SERVER['REQUEST_URI'], '?') !== false))
|
---|
71 | $_SERVER['QUERY_STRING'] = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], '?') + 1);
|
---|
72 | else $_SERVER['QUERY_STRING'] = '';
|
---|
73 | parse_str($_SERVER['QUERY_STRING'], $_GET);
|
---|
74 | return $PathItems;
|
---|
75 | }
|
---|
76 |
|
---|
77 | function RegisterPage($Path, $Handler): void
|
---|
78 | {
|
---|
79 | if (is_array($Path))
|
---|
80 | {
|
---|
81 | $Page = &$this->Pages;
|
---|
82 | $LastKey = array_pop($Path);
|
---|
83 | foreach ($Path as $PathItem)
|
---|
84 | {
|
---|
85 | $Page = &$Page[$PathItem];
|
---|
86 | }
|
---|
87 | if (!is_array($Page)) $Page = array('' => $Page);
|
---|
88 | $Page[$LastKey] = $Handler;
|
---|
89 | } else $this->Pages[$Path] = $Handler;
|
---|
90 | }
|
---|
91 |
|
---|
92 | function RegisterMenuItem(string $Link, string $Title): void
|
---|
93 | {
|
---|
94 | $this->MainMenu[] = array('Link' => $Link, 'Title' => $Title);
|
---|
95 | }
|
---|
96 |
|
---|
97 | function RegisterPageHeader(string $Name, array $Callback): void
|
---|
98 | {
|
---|
99 | $this->PageHeaders[$Name] = $Callback;
|
---|
100 | }
|
---|
101 |
|
---|
102 | function RegisterPageBar(string $Name): void
|
---|
103 | {
|
---|
104 | $this->Bars[$Name] = array();
|
---|
105 | }
|
---|
106 |
|
---|
107 | function UnregisterPageBar(string $Name): void
|
---|
108 | {
|
---|
109 | unset($this->Bars[$Name]);
|
---|
110 | }
|
---|
111 |
|
---|
112 | function SearchPage(array $PathItems, array $Pages): ?string
|
---|
113 | {
|
---|
114 | if (count($PathItems) > 0) $PathItem = $PathItems[0];
|
---|
115 | else $PathItem = '';
|
---|
116 | if (array_key_exists($PathItem, $Pages))
|
---|
117 | {
|
---|
118 | if (is_array($Pages[$PathItem]))
|
---|
119 | {
|
---|
120 | array_shift($PathItems);
|
---|
121 | return $this->SearchPage($PathItems, $Pages[$PathItem]);
|
---|
122 | } else return $Pages[$PathItem];
|
---|
123 | } else return '';
|
---|
124 | }
|
---|
125 |
|
---|
126 | function PageNotFound(): string
|
---|
127 | {
|
---|
128 | return 'Page '.implode('/', $this->PathItems).' not found.';
|
---|
129 | }
|
---|
130 |
|
---|
131 | function ShowPage(): void
|
---|
132 | {
|
---|
133 | $this->BaseView = new BaseView($this);
|
---|
134 |
|
---|
135 | $ClassName = $this->SearchPage($this->PathItems, $this->Pages);
|
---|
136 | if ($ClassName != '')
|
---|
137 | {
|
---|
138 | $Page = new $ClassName($this);
|
---|
139 | } else
|
---|
140 | {
|
---|
141 | $Page = new PageMissing($this);
|
---|
142 | }
|
---|
143 | echo($this->BaseView->GetOutput($Page));
|
---|
144 | }
|
---|
145 |
|
---|
146 | function Run(): void
|
---|
147 | {
|
---|
148 | $this->RunCommon();
|
---|
149 | if ($this->ShowPage)
|
---|
150 | {
|
---|
151 | $this->PathItems = ProcessURL();
|
---|
152 | $this->ShowPage();
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 | function RunCommon(): void
|
---|
157 | {
|
---|
158 | global $Config;
|
---|
159 |
|
---|
160 | $this->Config = $Config;
|
---|
161 | $this->Database = new Database();
|
---|
162 | $this->Database->Connect($this->Config['Database']['Host'], $this->Config['Database']['User'],
|
---|
163 | $this->Config['Database']['Password'], $this->Config['Database']['Database']);
|
---|
164 | $this->Database->Prefix = $this->Config['Database']['Prefix'];
|
---|
165 | $this->Database->charset($this->Config['Database']['Charset']);
|
---|
166 | $this->Database->ShowSQLError = false;
|
---|
167 | $this->Database->ShowSQLQuery = false;
|
---|
168 | $this->PathItems = $this->ProcessURL();
|
---|
169 |
|
---|
170 | $this->RegisterPageBar('Top');
|
---|
171 | $this->Name = 'Tanec';
|
---|
172 | }
|
---|
173 |
|
---|
174 | static function Cast(System $System): Core
|
---|
175 | {
|
---|
176 | if ($System instanceof Core)
|
---|
177 | {
|
---|
178 | return $System;
|
---|
179 | }
|
---|
180 | throw new Exception('Expected Core type but '.gettype($System));
|
---|
181 | }
|
---|
182 | }
|
---|
183 |
|
---|
184 | class PageMissing extends Page
|
---|
185 | {
|
---|
186 | function __construct($System)
|
---|
187 | {
|
---|
188 | parent::__construct($System);
|
---|
189 | $this->Title = 'Stránka nenalezena';
|
---|
190 | $this->ParentClass = 'PagePortal';
|
---|
191 | }
|
---|
192 |
|
---|
193 | function Show(): string
|
---|
194 | {
|
---|
195 | Header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
|
---|
196 | return '<h3 align="center">Požadovaná stránka neexistuje.</h3>';
|
---|
197 | }
|
---|
198 | }
|
---|
199 |
|
---|
200 | class PageRobots extends Page
|
---|
201 | {
|
---|
202 | function __construct($System)
|
---|
203 | {
|
---|
204 | parent::__construct($System);
|
---|
205 | }
|
---|
206 |
|
---|
207 | function Show(): string
|
---|
208 | {
|
---|
209 | $this->RawPage = true;
|
---|
210 | $Result = 'User-agent: *'."\n".
|
---|
211 | 'Disallow: /*?'."\n".
|
---|
212 | 'Sitemap: '.$this->System->AbsoluteLink('/sitemap.xml');
|
---|
213 | return $Result;
|
---|
214 | }
|
---|
215 | }
|
---|
216 |
|
---|
217 | class PageSiteMap extends Page
|
---|
218 | {
|
---|
219 | function Show(): string
|
---|
220 | {
|
---|
221 | $this->RawPage = true;
|
---|
222 | $Urls = array(
|
---|
223 | '/seznamka/',
|
---|
224 | '/skoly/',
|
---|
225 | '/tance/',
|
---|
226 | '/filmy/',
|
---|
227 | '/udalosti/',
|
---|
228 | );
|
---|
229 | $Result = '<?xml version="1.0" encoding="UTF-8"?>'."\n".
|
---|
230 | '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\n";
|
---|
231 | foreach ($Urls as $Url)
|
---|
232 | {
|
---|
233 | $Result .= '<url>'."\n".
|
---|
234 | ' <loc>'.$this->System->AbsoluteLink($Url).'</loc>'."\n".
|
---|
235 | //'<lastmod>'..'</lastmod>'."\n".
|
---|
236 | '</url>'."\n";
|
---|
237 | }
|
---|
238 |
|
---|
239 | // Meets
|
---|
240 | $DbResult = $this->Database->query('SELECT `Id`,`Time` FROM `MeetItem` WHERE '.GetDefaultMeetFilter());
|
---|
241 | while ($DbRow = $DbResult->fetch_array())
|
---|
242 | {
|
---|
243 | $Url = '/seznamka/inzerat/'.$DbRow['Id'];
|
---|
244 | $Time = MysqlDateTimeToTime($DbRow['Time']);
|
---|
245 | $Result .= '<url>'."\n".
|
---|
246 | ' <loc>'.$this->System->AbsoluteLink($Url).'</loc>'."\n".
|
---|
247 | ' <lastmod>'.date('c', $Time).'</lastmod>'."\n".
|
---|
248 | '</url>'."\n";
|
---|
249 | }
|
---|
250 |
|
---|
251 | // Events
|
---|
252 | $DbResult = $this->Database->query('SELECT `Id`,`TimeFrom` FROM `Event` WHERE '.GetDefaultEventFilter());
|
---|
253 | while ($DbRow = $DbResult->fetch_array())
|
---|
254 | {
|
---|
255 | $Url = '/udalosti/udalost/'.$DbRow['Id'];
|
---|
256 | $Time = MysqlDateTimeToTime($DbRow['TimeFrom']);
|
---|
257 | $Result .= '<url>'."\n".
|
---|
258 | ' <loc>'.$this->System->AbsoluteLink($Url).'</loc>'."\n".
|
---|
259 | ' <lastmod>'.date('c', $Time).'</lastmod>'."\n".
|
---|
260 | '</url>'."\n";
|
---|
261 | }
|
---|
262 |
|
---|
263 | $Result .= '</urlset>';
|
---|
264 | return $Result;
|
---|
265 | }
|
---|
266 | }
|
---|
267 |
|
---|
268 | class PageLogin extends Page
|
---|
269 | {
|
---|
270 | function __construct($System)
|
---|
271 | {
|
---|
272 | parent::__construct($System);
|
---|
273 | $this->Title = 'Přihlášení';
|
---|
274 | $this->ParentClass = 'PagePortal';
|
---|
275 | }
|
---|
276 |
|
---|
277 | function Show(): string
|
---|
278 | {
|
---|
279 | global $Config;
|
---|
280 |
|
---|
281 | $Output = '';
|
---|
282 | if (array_key_exists('login', $_GET))
|
---|
283 | {
|
---|
284 | if (array_key_exists('password', $_POST))
|
---|
285 | {
|
---|
286 | if ($_POST['password'] == $Config['Web']['AdminPassword'])
|
---|
287 | {
|
---|
288 | $_SESSION['IsAdmin'] = 1;
|
---|
289 | $Output .= 'Úspěšně přihlášen jako správce.';
|
---|
290 | } else {
|
---|
291 | $_SESSION['IsAdmin'] = 0;
|
---|
292 | $Output .= 'Heslo není správné.';
|
---|
293 | $Output .= $this->ShowLoginForm();
|
---|
294 | }
|
---|
295 | } else {
|
---|
296 | $Output .= 'Chybí heslo.';
|
---|
297 | $Output .= $this->ShowLoginForm();
|
---|
298 | }
|
---|
299 | } else
|
---|
300 | if (array_key_exists('logoff', $_GET))
|
---|
301 | {
|
---|
302 | $_SESSION['IsAdmin'] = 0;
|
---|
303 | $Output .= 'Odhlášení úspěšné';
|
---|
304 | $Output .= $this->ShowLoginForm();
|
---|
305 | } else {
|
---|
306 | $Output .= $this->ShowLoginForm();
|
---|
307 | }
|
---|
308 | if(Core::Cast($this->System)->IsAdmin()) $Output .= '<div>Jsi přihlášen jako správce. <a href="?logoff">Odhlásit</a></div>';
|
---|
309 | return $Output;
|
---|
310 | }
|
---|
311 |
|
---|
312 | function ShowLoginForm(): string
|
---|
313 | {
|
---|
314 | return '<form method="post" action="?login">'.
|
---|
315 | 'Heslo: <input type="password" name="password" value=""/><br/>'.
|
---|
316 | '<input type="submit" value="Přihlásit"/>'.
|
---|
317 | '</form>';
|
---|
318 | }
|
---|
319 | }
|
---|
320 |
|
---|
321 | $Revision = 63; // Subversion revision
|
---|
322 | $DatabaseRevision = 51; // SQL structure revision
|
---|
323 | $ReleaseTime = strtotime('2021-08-03');
|
---|
324 |
|
---|
325 | $Application = new Core();
|
---|
326 | $Application->ModuleManager->LoadModulesFromDir(dirname(__FILE__).'/Modules');
|
---|
327 | $Application->Modules = $Application->ModuleManager->Modules;
|
---|
328 | $Application->ModuleManager->InstallAll();
|
---|
329 | $Application->ModuleManager->StartAll();
|
---|
330 | $Application->RegisterPage([''], 'PageDanceList');
|
---|
331 | $Application->RegisterPage(['robots.txt'], 'PageRobots');
|
---|
332 | $Application->RegisterPage(['sitemap.xml'], 'PageSiteMap');
|
---|
333 | $Application->RegisterPage(['admin'], 'PageLogin');
|
---|
334 | $Application->Run();
|
---|