source: trunk/index.php@ 61

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