Rev 27 | Rev 35 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
33 | freddie | 1 | <<<<<<< .mine |
2 | <?php |
||
3 | |||
4 | require '_config.php'; |
||
5 | |||
6 | class Taios_Page |
||
7 | { |
||
8 | function __construct($title, $url = "") |
||
9 | { |
||
10 | $this->title = $title; |
||
11 | $this->url = $url; |
||
12 | |||
13 | $this->drawnHeader = false; |
||
14 | $this->drawnMiddle = false; |
||
15 | $this->drawnFooter = false; |
||
16 | |||
17 | $this->db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD); |
||
18 | if (!$this->db) |
||
19 | { |
||
20 | $this->drawError('Failed to connect to database: ' . mysql_error()); |
||
21 | } |
||
22 | |||
23 | if (!mysql_select_db('Tim32')) |
||
24 | { |
||
25 | $this->drawError('Failed to select database: ' . mysql_error()); |
||
26 | } |
||
27 | } |
||
28 | |||
29 | function drawHeader() |
||
30 | { |
||
31 | if (!$this->drawnHeader) |
||
32 | { |
||
33 | write('<!DOCTYPE html>'); |
||
34 | write('<html>'); |
||
35 | write('<head>'); |
||
36 | write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8">'); |
||
37 | write('<title>Tim32 · ' . $this->title . '</title>'); |
||
38 | write('<link href="' . $this->url . 'styles.css" rel="stylesheet" type="text/css" media="screen">'); |
||
39 | write('</head>'); |
||
40 | write('<body>'); |
||
41 | write('<div class="sidebar">'); |
||
42 | write('<div class="sidebar-header">'); |
||
43 | write('<h1>Tim32</h1>'); |
||
44 | write('</div>'); |
||
45 | write('<div class="sidebar-menu">'); |
||
46 | $this->drawMenuItem('Home', 'index.php'); |
||
47 | $this->drawMenuItem('Blog', 'blog/'); |
||
48 | $this->drawMenuItem('Projects', 'projects/'); |
||
49 | $this->drawMenuItem('Forums', 'forums/'); |
||
50 | $this->drawMenuItem('Wiki', 'wiki/'); |
||
51 | $this->drawMenuItem('Photos', 'photos/'); |
||
52 | write('<br />'); |
||
53 | if ($this->isLoggedIn()) |
||
54 | { |
||
55 | $this->drawMenuItem('Manage Account', 'admin/account.php?id=' . $this->getLoggedInUser()->ID); |
||
56 | $this->drawMenuItem('Logout', 'logout-do.php'); |
||
57 | } |
||
58 | else |
||
59 | { |
||
60 | $this->drawMenuItem('Login', 'login.php'); |
||
61 | $this->drawMenuItem('Register', 'register.php'); |
||
62 | } |
||
63 | write('<br />'); |
||
64 | |||
65 | $this->drawnHeader = true; |
||
66 | } |
||
67 | } |
||
68 | |||
69 | function drawMenuItem($t, $u) |
||
70 | { |
||
71 | write('<p><a href="' . $this->url . $u . '"</a>' . $t . '</a></p>'); |
||
72 | } |
||
73 | |||
74 | function drawMiddle() |
||
75 | { |
||
76 | if (!$this->drawnMiddle) |
||
77 | { |
||
78 | write('<br />'); |
||
79 | write('</div>'); |
||
80 | write('</div>'); |
||
81 | write('<div class="content">'); |
||
82 | write('<h2>' . $this->title . '</h2>'); |
||
83 | |||
84 | $this->drawnMiddle = true; |
||
85 | } |
||
86 | } |
||
87 | |||
88 | function drawFooter() |
||
89 | { |
||
90 | if (!$this->drawnFooter) |
||
91 | { |
||
92 | write('</div>'); |
||
93 | write('</body>'); |
||
94 | write('</html>'); |
||
95 | |||
96 | $this->drawnFooter = true; |
||
97 | } |
||
98 | |||
99 | // die(); |
||
100 | } |
||
101 | |||
102 | function drawError($text, $die = true) |
||
103 | { |
||
104 | $this->drawHeader(); |
||
105 | $this->drawMiddle(); |
||
106 | |||
107 | write('<h4 style="color: red;">Error: ' . $text . '</h4>'); |
||
108 | |||
109 | if ($die) |
||
110 | { |
||
111 | $this->drawFooter(); |
||
112 | die(); |
||
113 | } |
||
114 | } |
||
115 | |||
116 | function drawBlogPostTree($id) |
||
117 | { |
||
118 | $post = $this->getBlogPost($id); |
||
119 | write('<h3>' . $post->title. '</h3>'); |
||
120 | write('<h5 style="color: #666666;">Posted On ' . date('l j F Y', $post->datePosted) . ' by ' . $post->user->name . ' (' . $post->user->username . ')</h5>'); |
||
121 | write('<p>' . $post->content . '</p>'); |
||
122 | |||
123 | $ids = $page->findIDs('BlogPosts', 'WHERE ParentID = ' . $id); |
||
124 | for ($i = 0; $i < count($ids); $i++) |
||
125 | { |
||
126 | write('<p class="indent">'); |
||
127 | $this->drawBlogPostTree($i); |
||
128 | write('</p>'); |
||
129 | } |
||
130 | |||
131 | } |
||
132 | |||
133 | function redirect($url) |
||
134 | { |
||
135 | header('Location: ' . $url); |
||
136 | die(); |
||
137 | } |
||
138 | |||
139 | function isLoggedIn() |
||
140 | { |
||
141 | $cookie = $_COOKIE['Tim32_Login']; |
||
142 | if (!empty($cookie)) |
||
143 | { |
||
144 | $clist = explode('|~|', $cookie); |
||
145 | $user = $this->getUserByUsername($clist[0]); |
||
146 | if ($user) |
||
147 | { |
||
148 | if ($user->password == $clist[1]) |
||
149 | { |
||
150 | return true; |
||
151 | } |
||
152 | } |
||
153 | } |
||
154 | |||
155 | return false; |
||
156 | } |
||
157 | |||
158 | function isUserAdmin() |
||
159 | { |
||
160 | if ($this->isLoggedIn()) |
||
161 | { |
||
162 | if ($this->getLoggedInUser()->accessID <= 0) |
||
163 | { |
||
164 | return true; |
||
165 | } |
||
166 | } |
||
167 | |||
168 | return false; |
||
169 | } |
||
170 | |||
171 | function isUserGM() |
||
172 | { |
||
173 | if ($this->isLoggedIn()) |
||
174 | { |
||
175 | if ($this->getLoggedInUser()->accessID <= 1) |
||
176 | { |
||
177 | return true; |
||
178 | } |
||
179 | } |
||
180 | |||
181 | return false; |
||
182 | } |
||
183 | |||
184 | function isUserNormal() |
||
185 | { |
||
186 | if ($this->isLoggedIn()) |
||
187 | { |
||
188 | if ($this->getLoggedInUser()->accessID <= 2) |
||
189 | { |
||
190 | return true; |
||
191 | } |
||
192 | } |
||
193 | |||
194 | return false; |
||
195 | } |
||
196 | |||
197 | function checkLoggedIn() |
||
198 | { |
||
199 | if (!$this->isLoggedIn()) |
||
200 | { |
||
201 | $this->drawError('You need to be logged in.'); |
||
202 | } |
||
203 | } |
||
204 | |||
205 | function query($query) |
||
206 | { |
||
207 | $result = mysql_query($query); |
||
208 | if (!$result) |
||
209 | { |
||
210 | $this->drawError('MySQL Error: ' . mysql_error()); |
||
211 | } |
||
212 | |||
213 | return $result; |
||
214 | } |
||
215 | |||
216 | function findIDs($table, $query = '') |
||
217 | { |
||
218 | $array = array(); |
||
219 | |||
220 | $result = $this->query('SELECT ID FROM ' . $table . ' ' . $query); |
||
221 | while ($row = mysql_fetch_array($result)) |
||
222 | { |
||
223 | array_push($array, $row['ID']); |
||
224 | } |
||
225 | |||
226 | return $array; |
||
227 | } |
||
228 | |||
229 | function getUserByID($id) |
||
230 | { |
||
231 | $result = $this->query('SELECT * FROM Users WHERE ID = ' . $id); |
||
232 | while ($row = mysql_fetch_array($result)) |
||
233 | { |
||
234 | $user = new User; |
||
235 | $user->ID = $row['ID']; |
||
236 | $user->accessID = $row['AccessID']; |
||
237 | $user->username = $row['Username']; |
||
238 | $user->password = $row['Password']; |
||
239 | $user->emailAddress = $row['EmailAddress']; |
||
240 | $user->name = $row['Name']; |
||
241 | $user->challengeID = $row['ChallengeID']; |
||
242 | |||
243 | return $user; |
||
244 | } |
||
245 | |||
246 | return false; |
||
247 | } |
||
248 | |||
249 | function getUserByUsername($username) |
||
250 | { |
||
251 | $result = $this->query('SELECT * FROM Users WHERE Username = "' . $username . '"'); |
||
252 | while ($row = mysql_fetch_array($result)) |
||
253 | { |
||
254 | return $this->getUserByID($row['ID']); |
||
255 | } |
||
256 | |||
257 | return false; |
||
258 | } |
||
259 | |||
260 | function getLoggedInUser() |
||
261 | { |
||
262 | if ($this->isLoggedIn()) |
||
263 | { |
||
264 | $clist = explode('|~|', $_COOKIE['Tim32_Login']); |
||
265 | return $this->getUserByUsername($clist[0]); |
||
266 | } |
||
267 | |||
268 | return false; |
||
269 | } |
||
270 | |||
271 | function getBlogPost($id) |
||
272 | { |
||
273 | $result = $this->query('SELECT * FROM BlogPosts WHERE ID = ' . $id); |
||
274 | while ($row = mysql_fetch_array($result)) |
||
275 | { |
||
276 | $post = new BlogPost; |
||
277 | $post->ID = $row['ID']; |
||
278 | if ($row['ParentID'] == -1) |
||
279 | { |
||
280 | $post->parent = -1; |
||
281 | } |
||
282 | else |
||
283 | { |
||
284 | $post->parent = $this->getBlogPost($row['ParentID']); |
||
285 | } |
||
286 | $post->user = $this->getUserByID($row['AuthorID']); |
||
287 | $post->title = $row['Title']; |
||
288 | $post->content = $row['Content']; |
||
289 | $post->datePosted = strtotime($row['DatePosted']); |
||
290 | $post->category = $row['Category']; |
||
291 | $post->spam = $row['Spam']; |
||
292 | |||
293 | return $post; |
||
294 | } |
||
295 | |||
296 | $this->drawError('Cannot find blog post, #' . $id); |
||
297 | } |
||
298 | |||
299 | function getGetID() |
||
300 | { |
||
301 | $id = $_GET['id']; |
||
302 | if (empty($id)) |
||
303 | { |
||
304 | $id = 1; |
||
305 | } |
||
306 | |||
307 | return $id; |
||
308 | } |
||
309 | |||
310 | function getPostID() |
||
311 | { |
||
312 | $id = $_POSt['id']; |
||
313 | if (empty($id)) |
||
314 | { |
||
315 | $id = 1; |
||
316 | } |
||
317 | |||
318 | return $id; |
||
319 | } |
||
320 | |||
321 | } |
||
322 | |||
323 | class User |
||
324 | { |
||
325 | public $ID; |
||
326 | public $accessID; |
||
327 | public $username; |
||
328 | public $password; |
||
329 | public $emailAddress; |
||
330 | public $name; |
||
331 | public $challengeID; |
||
332 | } |
||
333 | |||
334 | class BlogPost |
||
335 | { |
||
336 | public $ID; |
||
337 | public $parent; |
||
338 | public $author; |
||
339 | public $title; |
||
340 | public $content; |
||
341 | public $datePosted; |
||
342 | public $category; |
||
343 | public $spam; |
||
344 | } |
||
345 | |||
346 | function write($str) |
||
347 | { |
||
348 | echo $str; |
||
349 | echo "\n"; |
||
350 | } |
||
351 | |||
352 | ?> |
||
353 | ======= |
||
1 | tom | 354 | <?php |
355 | |||
4 | tom | 356 | require '_config.php'; |
3 | tom | 357 | |
1 | tom | 358 | class Taios_Page |
359 | { |
||
360 | function __construct($title, $url = "") |
||
361 | { |
||
362 | $this->title = $title; |
||
363 | $this->url = $url; |
||
364 | |||
365 | $this->drawnHeader = false; |
||
366 | $this->drawnMiddle = false; |
||
367 | $this->drawnFooter = false; |
||
368 | |||
5 | tom | 369 | $this->db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD); |
1 | tom | 370 | if (!$this->db) |
371 | { |
||
372 | $this->drawError('Failed to connect to database: ' . mysql_error()); |
||
373 | } |
||
374 | |||
375 | if (!mysql_select_db('Tim32')) |
||
376 | { |
||
377 | $this->drawError('Failed to select database: ' . mysql_error()); |
||
378 | } |
||
379 | } |
||
380 | |||
381 | function drawHeader() |
||
382 | { |
||
383 | if (!$this->drawnHeader) |
||
384 | { |
||
385 | write('<!DOCTYPE html>'); |
||
386 | write('<html>'); |
||
387 | write('<head>'); |
||
388 | write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8">'); |
||
389 | write('<title>Tim32 · ' . $this->title . '</title>'); |
||
390 | write('<link href="' . $this->url . 'styles.css" rel="stylesheet" type="text/css" media="screen">'); |
||
391 | write('</head>'); |
||
392 | write('<body>'); |
||
393 | write('<div class="sidebar">'); |
||
394 | write('<div class="sidebar-header">'); |
||
395 | write('<h1>Tim32</h1>'); |
||
396 | write('</div>'); |
||
397 | write('<div class="sidebar-menu">'); |
||
398 | $this->drawMenuItem('Home', 'index.php'); |
||
399 | $this->drawMenuItem('Blog', 'blog/'); |
||
400 | $this->drawMenuItem('Projects', 'projects/'); |
||
401 | $this->drawMenuItem('Forums', 'forums/'); |
||
402 | $this->drawMenuItem('Wiki', 'wiki/'); |
||
403 | $this->drawMenuItem('Photos', 'photos/'); |
||
404 | write('<br />'); |
||
405 | if ($this->isLoggedIn()) |
||
406 | { |
||
9 | tom | 407 | $this->drawMenuItem('Manage Account', 'admin/account.php?id=' . $this->getLoggedInUser()->ID); |
1 | tom | 408 | $this->drawMenuItem('Logout', 'logout-do.php'); |
409 | } |
||
410 | else |
||
411 | { |
||
412 | $this->drawMenuItem('Login', 'login.php'); |
||
413 | $this->drawMenuItem('Register', 'register.php'); |
||
414 | } |
||
415 | write('<br />'); |
||
416 | |||
417 | $this->drawnHeader = true; |
||
418 | } |
||
419 | } |
||
420 | |||
421 | function drawMenuItem($t, $u) |
||
422 | { |
||
423 | write('<p><a href="' . $this->url . $u . '"</a>' . $t . '</a></p>'); |
||
424 | } |
||
425 | |||
426 | function drawMiddle() |
||
427 | { |
||
428 | if (!$this->drawnMiddle) |
||
429 | { |
||
430 | write('<br />'); |
||
431 | write('</div>'); |
||
432 | write('</div>'); |
||
433 | write('<div class="content">'); |
||
434 | write('<h2>' . $this->title . '</h2>'); |
||
435 | |||
436 | $this->drawnMiddle = true; |
||
437 | } |
||
438 | } |
||
439 | |||
440 | function drawFooter() |
||
441 | { |
||
442 | if (!$this->drawnFooter) |
||
443 | { |
||
444 | write('</div>'); |
||
445 | write('</body>'); |
||
446 | write('</html>'); |
||
447 | |||
448 | $this->drawnFooter = true; |
||
449 | } |
||
450 | |||
2 | tom | 451 | // die(); |
1 | tom | 452 | } |
453 | |||
454 | function drawError($text, $die = true) |
||
455 | { |
||
456 | $this->drawHeader(); |
||
457 | $this->drawMiddle(); |
||
458 | |||
459 | write('<h4 style="color: red;">Error: ' . $text . '</h4>'); |
||
460 | |||
461 | if ($die) |
||
462 | { |
||
463 | $this->drawFooter(); |
||
464 | die(); |
||
465 | } |
||
466 | } |
||
467 | |||
468 | function redirect($url) |
||
469 | { |
||
470 | header('Location: ' . $url); |
||
471 | die(); |
||
472 | } |
||
473 | |||
474 | function isLoggedIn() |
||
475 | { |
||
476 | $cookie = $_COOKIE['Tim32_Login']; |
||
477 | if (!empty($cookie)) |
||
478 | { |
||
479 | $clist = explode('|~|', $cookie); |
||
480 | $user = $this->getUserByUsername($clist[0]); |
||
481 | if ($user) |
||
482 | { |
||
483 | if ($user->password == $clist[1]) |
||
484 | { |
||
485 | return true; |
||
486 | } |
||
487 | } |
||
488 | } |
||
489 | |||
490 | return false; |
||
491 | } |
||
492 | |||
493 | function isUserAdmin() |
||
494 | { |
||
495 | if ($this->isLoggedIn()) |
||
496 | { |
||
497 | if ($this->getLoggedInUser()->accessID <= 0) |
||
498 | { |
||
499 | return true; |
||
500 | } |
||
501 | } |
||
502 | |||
503 | return false; |
||
504 | } |
||
505 | |||
506 | function isUserGM() |
||
507 | { |
||
508 | if ($this->isLoggedIn()) |
||
509 | { |
||
510 | if ($this->getLoggedInUser()->accessID <= 1) |
||
511 | { |
||
512 | return true; |
||
513 | } |
||
514 | } |
||
515 | |||
516 | return false; |
||
517 | } |
||
518 | |||
519 | function isUserNormal() |
||
520 | { |
||
521 | if ($this->isLoggedIn()) |
||
522 | { |
||
523 | if ($this->getLoggedInUser()->accessID <= 2) |
||
524 | { |
||
525 | return true; |
||
526 | } |
||
527 | } |
||
528 | |||
529 | return false; |
||
530 | } |
||
531 | |||
6 | tom | 532 | function checkLoggedIn() |
533 | { |
||
534 | if (!$this->isLoggedIn()) |
||
535 | { |
||
536 | $this->drawError('You need to be logged in.'); |
||
537 | } |
||
538 | } |
||
539 | |||
1 | tom | 540 | function query($query) |
541 | { |
||
542 | $result = mysql_query($query); |
||
543 | if (!$result) |
||
544 | { |
||
545 | $this->drawError('MySQL Error: ' . mysql_error()); |
||
546 | } |
||
547 | |||
548 | return $result; |
||
549 | } |
||
550 | |||
551 | function findIDs($table, $query = '') |
||
552 | { |
||
553 | $array = array(); |
||
554 | |||
555 | $result = $this->query('SELECT ID FROM ' . $table . ' ' . $query); |
||
556 | while ($row = mysql_fetch_array($result)) |
||
557 | { |
||
558 | array_push($array, $row['ID']); |
||
559 | } |
||
560 | |||
561 | return $array; |
||
562 | } |
||
563 | |||
564 | function getUserByID($id) |
||
565 | { |
||
566 | $result = $this->query('SELECT * FROM Users WHERE ID = ' . $id); |
||
567 | while ($row = mysql_fetch_array($result)) |
||
568 | { |
||
569 | $user = new User; |
||
570 | $user->ID = $row['ID']; |
||
571 | $user->accessID = $row['AccessID']; |
||
572 | $user->username = $row['Username']; |
||
573 | $user->password = $row['Password']; |
||
574 | $user->emailAddress = $row['EmailAddress']; |
||
575 | $user->name = $row['Name']; |
||
576 | $user->challengeID = $row['ChallengeID']; |
||
577 | |||
578 | return $user; |
||
579 | } |
||
580 | |||
581 | return false; |
||
582 | } |
||
583 | |||
584 | function getUserByUsername($username) |
||
585 | { |
||
586 | $result = $this->query('SELECT * FROM Users WHERE Username = "' . $username . '"'); |
||
587 | while ($row = mysql_fetch_array($result)) |
||
588 | { |
||
589 | return $this->getUserByID($row['ID']); |
||
590 | } |
||
591 | |||
592 | return false; |
||
593 | } |
||
594 | |||
595 | function getLoggedInUser() |
||
596 | { |
||
597 | if ($this->isLoggedIn()) |
||
598 | { |
||
599 | $clist = explode('|~|', $_COOKIE['Tim32_Login']); |
||
600 | return $this->getUserByUsername($clist[0]); |
||
601 | } |
||
602 | |||
603 | return false; |
||
604 | } |
||
605 | |||
606 | function getBlogPost($id) |
||
607 | { |
||
608 | $result = $this->query('SELECT * FROM BlogPosts WHERE ID = ' . $id); |
||
609 | while ($row = mysql_fetch_array($result)) |
||
610 | { |
||
611 | $post = new BlogPost; |
||
612 | $post->ID = $row['ID']; |
||
20 | tom | 613 | if ($row['ParentID'] == -1) |
614 | { |
||
615 | $post->parent = -1; |
||
616 | } |
||
617 | else |
||
618 | { |
||
619 | $post->parent = $this->getBlogPost($row['ParentID']); |
||
620 | } |
||
1 | tom | 621 | $post->user = $this->getUserByID($row['AuthorID']); |
622 | $post->title = $row['Title']; |
||
623 | $post->content = $row['Content']; |
||
624 | $post->datePosted = strtotime($row['DatePosted']); |
||
625 | $post->category = $row['Category']; |
||
20 | tom | 626 | $post->spam = $row['Spam']; |
1 | tom | 627 | |
628 | return $post; |
||
629 | } |
||
630 | |||
631 | $this->drawError('Cannot find blog post, #' . $id); |
||
27 | tom | 632 | return false; |
1 | tom | 633 | } |
12 | tom | 634 | |
635 | function getGetID() |
||
636 | { |
||
637 | $id = $_GET['id']; |
||
638 | if (empty($id)) |
||
639 | { |
||
640 | $id = 1; |
||
641 | } |
||
642 | |||
643 | return $id; |
||
644 | } |
||
645 | |||
646 | function getPostID() |
||
647 | { |
||
648 | $id = $_POSt['id']; |
||
649 | if (empty($id)) |
||
650 | { |
||
651 | $id = 1; |
||
652 | } |
||
653 | |||
654 | return $id; |
||
655 | } |
||
1 | tom | 656 | } |
657 | |||
658 | class User |
||
659 | { |
||
660 | public $ID; |
||
661 | public $accessID; |
||
662 | public $username; |
||
663 | public $password; |
||
664 | public $emailAddress; |
||
665 | public $name; |
||
666 | public $challengeID; |
||
667 | } |
||
668 | |||
669 | class BlogPost |
||
670 | { |
||
671 | public $ID; |
||
20 | tom | 672 | public $parent; |
1 | tom | 673 | public $author; |
674 | public $title; |
||
675 | public $content; |
||
676 | public $datePosted; |
||
677 | public $category; |
||
20 | tom | 678 | public $spam; |
1 | tom | 679 | } |
680 | |||
681 | function write($str) |
||
682 | { |
||
683 | echo $str; |
||
684 | echo "\n"; |
||
685 | } |
||
686 | |||
687 | ?> |
||
33 | freddie | 688 | >>>>>>> .r31 |