Rev 345 | Rev 362 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 297 | freddie | 1 | <?php |
| 2 | |||
| 3 | require '_config.php'; |
||
| 4 | |||
| 5 | class Taios_Page |
||
| 6 | { |
||
| 7 | function __construct($title, $url = "") |
||
| 8 | { |
||
| 9 | $this->title = $title; |
||
| 10 | $this->url = $url; |
||
| 11 | |||
| 12 | $this->drawnHeader = false; |
||
| 13 | $this->drawnMiddle = false; |
||
| 14 | $this->drawnFooter = false; |
||
| 15 | |||
| 16 | $this->db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD); |
||
| 17 | if (!$this->db) |
||
| 18 | { |
||
| 19 | $this->drawError('Failed to connect to database: ' . mysql_error()); |
||
| 20 | } |
||
| 21 | |||
| 22 | if (!mysql_select_db('Tim32')) |
||
| 23 | { |
||
| 24 | $this->drawError('Failed to select database: ' . mysql_error()); |
||
| 25 | } |
||
| 26 | } |
||
| 27 | |||
| 28 | function drawHeader() |
||
| 29 | { |
||
| 30 | if (!$this->drawnHeader) |
||
| 31 | { |
||
| 32 | write('<!DOCTYPE html>'); |
||
| 33 | write('<html>'); |
||
| 34 | write('<head>'); |
||
| 35 | write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8">'); |
||
| 36 | write('<title>Tim32 · ' . $this->title . '</title>'); |
||
| 37 | write('<link href="' . $this->url . 'styles.css" rel="stylesheet" type="text/css" media="screen">'); |
||
| 38 | write('</head>'); |
||
| 39 | write('<body>'); |
||
| 40 | write('<div class="sidebar">'); |
||
| 41 | write('<div class="sidebar-header">'); |
||
| 42 | write('<h1>Tim32</h1>'); |
||
| 43 | write('</div>'); |
||
| 44 | write('<div class="sidebar-menu">'); |
||
| 45 | $this->drawMenuItem('Home', 'index.php'); |
||
| 46 | $this->drawMenuItem('Blog', 'blog/'); |
||
| 47 | $this->drawMenuItem('Projects', 'projects/'); |
||
| 48 | $this->drawMenuItem('Forums', 'forums/'); |
||
| 49 | $this->drawMenuItem('Wiki', 'wiki/'); |
||
| 50 | $this->drawMenuItem('Photos', 'photos/'); |
||
| 51 | write('<br />'); |
||
| 52 | if ($this->isLoggedIn()) |
||
| 53 | { |
||
| 54 | $this->drawMenuItem('Administration', 'admin/'); |
||
| 55 | $this->drawMenuItem('Logout', 'logout-do.php'); |
||
| 56 | } |
||
| 57 | else |
||
| 58 | { |
||
| 59 | $this->drawMenuItem('Login', 'login.php'); |
||
| 60 | $this->drawMenuItem('Register', 'register.php'); |
||
| 61 | } |
||
| 62 | write('<br />'); |
||
| 63 | |||
| 64 | $this->drawnHeader = true; |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | function drawMenuItem($t, $u) |
||
| 69 | { |
||
| 70 | write('<p><a href="' . $this->url . $u . '">' . $t . '</a></p>'); |
||
| 71 | } |
||
| 72 | |||
| 73 | function drawMiddle() |
||
| 74 | { |
||
| 75 | if (!$this->drawnMiddle) |
||
| 76 | { |
||
| 77 | write('<br />'); |
||
| 78 | write('</div>'); |
||
| 79 | write('</div>'); |
||
| 80 | write('<div class="content">'); |
||
| 81 | write('<h2>' . $this->title . '</h2>'); |
||
| 82 | |||
| 83 | $this->drawnMiddle = true; |
||
| 84 | } |
||
| 85 | } |
||
| 86 | |||
| 87 | function drawFooter() |
||
| 88 | { |
||
| 89 | if (!$this->drawnFooter) |
||
| 90 | { |
||
| 91 | write('</div>'); |
||
| 92 | write('</body>'); |
||
| 93 | write('</html>'); |
||
| 94 | |||
| 95 | $this->drawnFooter = true; |
||
| 96 | } |
||
| 97 | |||
| 98 | die(); |
||
| 99 | } |
||
| 100 | |||
| 101 | function drawError($text, $die = true) |
||
| 102 | { |
||
| 103 | $this->drawHeader(); |
||
| 104 | $this->drawMiddle(); |
||
| 105 | |||
| 106 | write('<h4 style="color: red;">Error: ' . $text . '</h4>'); |
||
| 107 | |||
| 108 | if ($die) |
||
| 109 | { |
||
| 110 | $this->drawFooter(); |
||
| 111 | die(); |
||
| 112 | } |
||
| 113 | } |
||
| 114 | |||
| 115 | function drawBlogPostTree($id, $first = false) |
||
| 116 | { |
||
| 117 | $post = $this->getBlogPost($id); |
||
| 118 | if ($first) |
||
| 119 | { |
||
| 120 | write('<h3><a href="post.php?id=' . $id . '">' . $post->title. '</a> <a href="post.php?id=' . $post->parent->ID . '">^</a></h3>'); |
||
| 121 | } |
||
| 122 | else |
||
| 123 | { |
||
| 124 | write('<a href="post.php?id=' . $id . '"><h3>' . $post->title. '</h3></a>'); |
||
| 125 | } |
||
| 126 | write('<h5 style="color: #666666;">Posted On ' . date('l j F Y', $post->datePosted) . ' by ' . $post->user->name . ' (' . $post->user->username . ')</h5>'); |
||
| 127 | write('<p>' . $this->replaceBBCode($post->content) . '</p>'); |
||
| 128 | |||
| 129 | if ($this->isUserNormal($this->getLoggedInUser())) |
||
| 130 | { |
||
| 131 | echo '<p class="bold"><a href="add-post.php?id=' . $id . '">Add Comment</a>'; |
||
| 132 | if ($this->isUserAdmin($this->getLoggedInUser()) || $this->getLoggedInUser()->ID == $post->author->ID) |
||
| 133 | { |
||
| 134 | echo ' · <a href="edit-post.php?id=' . $id . '">Edit Post</a>'; |
||
| 135 | echo ' · <a href="del-post.php?id=' . $id . '">Delete Post</a>'; |
||
| 136 | } |
||
| 137 | write('</p><br />'); |
||
| 138 | } |
||
| 139 | |||
| 140 | $ids = $this->findIDs('BlogPosts', 'WHERE ParentID=' . $id); |
||
| 141 | for ($i = 0; $i < count($ids); $i++) |
||
| 142 | { |
||
| 143 | write('<div class="indent">'); |
||
| 144 | $this->drawBlogPostTree($ids[$i]); |
||
| 145 | write('</div>'); |
||
| 146 | } |
||
| 147 | } |
||
| 148 | |||
| 149 | function drawBlogCategoriesMenu() |
||
| 150 | { |
||
| 151 | $cats = array(); |
||
| 152 | |||
| 153 | $ids = $this->findIDs('BlogPosts', 'WHERE ParentID = -1'); |
||
| 154 | for ($i = 0; $i < count($ids); $i++) |
||
| 155 | { |
||
| 156 | $cat = $this->getBlogPost($ids[$i])->category; |
||
| 157 | if (!in_array($cat, $cats)) |
||
| 158 | { |
||
| 159 | array_push($cats, $cat); |
||
| 160 | } |
||
| 161 | } |
||
| 162 | |||
| 163 | write('<h3>Categories</h3>'); |
||
| 164 | for ($i = 0; $i < count($cats); $i++) |
||
| 165 | { |
||
| 166 | $this->drawMenuItem($cats[$i], 'blog/index.php?cat=' . $cats[$i]); |
||
| 167 | } |
||
| 168 | } |
||
| 169 | |||
| 170 | function replaceBBCode($str) |
||
| 171 | { |
||
| 308 | tom | 172 | $newstr = str_replace("<", "[", $str); |
| 173 | $newstr = str_replace(">", "]", $newstr); |
||
| 332 | tom | 174 | $newstr = str_replace("\n", '</p><p>', $newstr); |
| 297 | freddie | 175 | $newstr = str_replace(' ', ' ', $newstr); |
| 176 | $newstr = str_replace(' :)', ' <img src="' . $this->url . 'data/smilies/face-smile.png" class="smiley" />', $newstr); |
||
| 177 | $newstr = str_replace(' :p', ' <img src="' . $this->url . 'data/smilies/face-raspberry.png" class="smiley" />', $newstr); |
||
| 178 | $newstr = str_replace(' :P', ' <img src="' . $this->url . 'data/smilies/face-raspberry.png" class="smiley" />',$newstr); |
||
| 179 | $newstr = str_replace(' :|', ' <img src="' . $this->url . 'data/smilies/face-plain.png" class="smiley" />',$newstr); |
||
| 180 | $newstr = str_replace(' :D', ' <img src="' . $this->url . 'data/smilies/face-laugh.png" class="smiley" />',$newstr); |
||
| 181 | $newstr = str_replace(' =D', ' <img src="' . $this->url . 'data/smilies/face-laugh.png" class="smiley" />',$newstr); |
||
| 182 | $newstr = str_replace(' :(', ' <img src="' . $this->url . 'data/smilies/face-sad.png" class="smiley" />',$newstr); |
||
| 183 | $newstr = str_replace(' :0', ' <img src="' . $this->url . 'data/smilies/face-surprise.png" class="smiley" />',$newstr); |
||
| 184 | $newstr = str_replace(' :o', ' <img src="' . $this->url . 'data/smilies/face-surprise.png" class="smiley" />',$newstr); |
||
| 185 | $newstr = str_replace(' :O', ' <img src="' . $this->url . 'data/smilies/face-surprise.png" class="smiley" />',$newstr); |
||
| 186 | $newstr = str_replace(' :/', ' <img src="' . $this->url . 'data/smilies/face-uncertain.png" class="smiley" />',$newstr); |
||
| 187 | $newstr = str_replace(' ;)', ' <img src="' . $this->url . 'data/smilies/face-wink.png" class="smiley" />',$newstr); |
||
| 188 | |||
| 189 | $bbcode = array( |
||
| 190 | '/\[b\](.+?)\[\/b\]/is', |
||
| 191 | '/\[i\](.+?)\[\/i\]/is', |
||
| 192 | '/\[u\](.+?)\[\/u\]/is', |
||
| 193 | '/\[url\](.+?)\[\/url\]/is', |
||
| 360 | tom | 194 | '/\[url=(.+?)\](.+?)\[\/url\]/is', |
| 297 | freddie | 195 | '/\[code\](.+?)\[\/code\]/is', |
| 196 | '/\[img\](.+?)\[\/img\]/is' |
||
| 197 | ); |
||
| 198 | |||
| 199 | $html = array( |
||
| 200 | '<b>$1</b>', |
||
| 201 | '<i>$1</i>', |
||
| 202 | '<u>$1</u>', |
||
| 203 | '<a href="$1">$1</a>', |
||
| 360 | tom | 204 | '<a href="$1">$2</a>', |
| 297 | freddie | 205 | '<div class="code">$1</div>', |
| 206 | '<img src="$1" />' |
||
| 207 | ); |
||
| 208 | |||
| 209 | $newstr = preg_replace($bbcode, $html, $newstr); |
||
| 210 | |||
| 211 | return $newstr; |
||
| 212 | } |
||
| 213 | |||
| 214 | function redirect($u) |
||
| 215 | { |
||
| 216 | header('Location: ' . $u); |
||
| 217 | die(); |
||
| 218 | } |
||
| 219 | |||
| 220 | function isLoggedIn() |
||
| 221 | { |
||
| 222 | $cookie = $_COOKIE['Tim32_Login']; |
||
| 223 | if (!empty($cookie)) |
||
| 224 | { |
||
| 225 | $clist = explode('|~|', $cookie); |
||
| 226 | $user = $this->getUserByUsername($clist[0]); |
||
| 227 | if ($user) |
||
| 228 | { |
||
| 229 | if ($user->password == $clist[1]) |
||
| 230 | { |
||
| 231 | return true; |
||
| 232 | } |
||
| 233 | } |
||
| 234 | } |
||
| 235 | |||
| 236 | return false; |
||
| 237 | } |
||
| 238 | |||
| 239 | function isUserAdmin() |
||
| 240 | { |
||
| 241 | if ($this->isLoggedIn()) |
||
| 242 | { |
||
| 243 | if ($this->getLoggedInUser()->accessID <= 0) |
||
| 244 | { |
||
| 245 | return true; |
||
| 246 | } |
||
| 247 | } |
||
| 248 | |||
| 249 | return false; |
||
| 250 | } |
||
| 251 | |||
| 252 | function isUserGM() |
||
| 253 | { |
||
| 254 | if ($this->isLoggedIn()) |
||
| 255 | { |
||
| 256 | if ($this->getLoggedInUser()->accessID <= 1) |
||
| 257 | { |
||
| 258 | return true; |
||
| 259 | } |
||
| 260 | } |
||
| 261 | |||
| 262 | return false; |
||
| 263 | } |
||
| 264 | |||
| 265 | function isUserNormal() |
||
| 266 | { |
||
| 267 | if ($this->isLoggedIn()) |
||
| 268 | { |
||
| 269 | if ($this->getLoggedInUser()->accessID <= 2) |
||
| 270 | { |
||
| 271 | return true; |
||
| 272 | } |
||
| 273 | } |
||
| 274 | |||
| 275 | return false; |
||
| 276 | } |
||
| 277 | |||
| 278 | function checkLoggedIn() |
||
| 279 | { |
||
| 280 | if (!$this->isLoggedIn()) |
||
| 281 | { |
||
| 282 | $this->drawError('You need to be logged in.'); |
||
| 283 | } |
||
| 284 | } |
||
| 285 | |||
| 286 | function query($query) |
||
| 287 | { |
||
| 288 | $result = mysql_query($query); |
||
| 289 | if (!$result) |
||
| 290 | { |
||
| 291 | $this->drawError('Query Failed: ' . $query . "\n" . 'MySQL Error: ' . mysql_error()); |
||
| 292 | } |
||
| 293 | |||
| 294 | return $result; |
||
| 295 | } |
||
| 296 | |||
| 297 | function findIDs($table, $query = '') |
||
| 298 | { |
||
| 299 | $array = array(); |
||
| 300 | |||
| 301 | $result = $this->query('SELECT ID FROM ' . $table . ' ' . $query); |
||
| 302 | while ($row = mysql_fetch_array($result)) |
||
| 303 | { |
||
| 304 | array_push($array, $row['ID']); |
||
| 305 | } |
||
| 306 | |||
| 307 | return $array; |
||
| 308 | } |
||
| 309 | |||
| 310 | function getUserByID($id) |
||
| 311 | { |
||
| 312 | $result = $this->query('SELECT * FROM Users WHERE ID = ' . $id); |
||
| 313 | while ($row = mysql_fetch_array($result)) |
||
| 314 | { |
||
| 315 | $user = new User; |
||
| 316 | $user->ID = $row['ID']; |
||
| 317 | $user->accessID = $row['AccessID']; |
||
| 318 | $user->username = $row['Username']; |
||
| 319 | $user->password = $row['Password']; |
||
| 320 | $user->emailAddress = $row['EmailAddress']; |
||
| 321 | $user->name = $row['Name']; |
||
| 322 | $user->challengeID = $row['ChallengeID']; |
||
| 323 | |||
| 324 | return $user; |
||
| 325 | } |
||
| 326 | |||
| 327 | return false; |
||
| 328 | } |
||
| 329 | |||
| 330 | function getUserByUsername($username) |
||
| 331 | { |
||
| 332 | $result = $this->query('SELECT * FROM Users WHERE Username = "' . $username . '"'); |
||
| 333 | while ($row = mysql_fetch_array($result)) |
||
| 334 | { |
||
| 335 | return $this->getUserByID($row['ID']); |
||
| 336 | } |
||
| 337 | |||
| 338 | return false; |
||
| 339 | } |
||
| 340 | |||
| 341 | function getLoggedInUser() |
||
| 342 | { |
||
| 343 | if ($this->isLoggedIn()) |
||
| 344 | { |
||
| 345 | $clist = explode('|~|', $_COOKIE['Tim32_Login']); |
||
| 346 | return $this->getUserByUsername($clist[0]); |
||
| 347 | } |
||
| 348 | |||
| 349 | return false; |
||
| 350 | } |
||
| 351 | |||
| 352 | function getBlogPost($id) |
||
| 353 | { |
||
| 354 | $result = $this->query('SELECT * FROM BlogPosts WHERE ID = ' . $id); |
||
| 355 | while ($row = mysql_fetch_array($result)) |
||
| 356 | { |
||
| 357 | $post = new BlogPost; |
||
| 358 | $post->ID = $row['ID']; |
||
| 359 | if ($row['ParentID'] == -1) |
||
| 360 | { |
||
| 361 | $post->parent = -1; |
||
| 362 | } |
||
| 363 | else |
||
| 364 | { |
||
| 365 | $post->parent = $this->getBlogPost($row['ParentID']); |
||
| 366 | } |
||
| 367 | $post->author = $this->getUserByID($row['AuthorID']); |
||
| 368 | $post->user = $this->getUserByID($row['AuthorID']); // For some older pages |
||
| 369 | $post->title = $row['Title']; |
||
| 370 | $post->content = $row['Content']; |
||
| 371 | $post->datePosted = strtotime($row['DatePosted']); |
||
| 372 | $post->category = $row['Category']; |
||
| 373 | $post->spam = $row['Spam']; |
||
| 374 | |||
| 375 | return $post; |
||
| 376 | } |
||
| 377 | |||
| 378 | $this->drawError('Cannot find blog post, #' . $id); |
||
| 379 | } |
||
| 380 | |||
| 381 | function getProject($id) |
||
| 382 | { |
||
| 383 | $result = $this->query('SELECT * FROM Projects WHERE ID = ' . $id); |
||
| 384 | while ($row = mysql_fetch_array($result)) |
||
| 385 | { |
||
| 386 | $project = new Project; |
||
| 387 | |||
| 388 | $project->ID = $row['ID']; |
||
| 389 | $project->author = $this->getUserByID($row['AuthorID']); |
||
| 390 | $project->title = $row['Title']; |
||
| 391 | $project->description = $row['Description']; |
||
| 392 | $project->logoURL = $row['LogoURL']; |
||
| 393 | $project->downloadURL = $row['DownloadURL']; |
||
| 394 | $project->websiteURL = $row['WebsiteURL']; |
||
| 395 | $project->latestVersion = $row['LatestVersion']; |
||
| 396 | $project->lastUpdate = strtotime($row['LastUpdate']); |
||
| 397 | |||
| 398 | return $project; |
||
| 399 | } |
||
| 400 | |||
| 401 | return false; |
||
| 402 | } |
||
| 403 | |||
| 404 | function getForumCategory($id) |
||
| 405 | { |
||
| 406 | $result = $this->query('SELECT * FROM ForumCategories WHERE ID = ' . $id); |
||
| 407 | while ($row = mysql_fetch_array($result)) |
||
| 408 | { |
||
| 409 | $f = new ForumCategory; |
||
| 410 | |||
| 411 | $f->ID = $row['ID']; |
||
| 412 | $f->parent = $this->getForumCategory($row['ParentID']); |
||
| 413 | $f->title = $row['Title']; |
||
| 414 | $f->description = $row['Description']; |
||
| 415 | |||
| 416 | return $f; |
||
| 417 | } |
||
| 418 | |||
| 419 | return false; |
||
| 420 | } |
||
| 421 | |||
| 422 | function getForumPost($id) |
||
| 423 | { |
||
| 424 | $result = $this->query('SELECT * FROM ForumPosts WHERE ID = ' . $id); |
||
| 425 | while ($row = mysql_fetch_array($result)) |
||
| 426 | { |
||
| 427 | $f = new ForumPost; |
||
| 428 | |||
| 429 | $f->ID = $row['ID']; |
||
| 430 | $f->author = $this->getUserByID($row['AuthorID']); |
||
| 431 | $f->category = $this->getForumCategory($row['CategoryID']); |
||
| 432 | $f->parent = $this->getForumPost($row['ParentID']); |
||
| 433 | $f->title = $row['Title']; |
||
| 434 | $f->content = $row['Content']; |
||
| 435 | $f->datePosted = strtotime($row['DatePosted']); |
||
| 436 | $f->spam = $row['Spam']; |
||
| 437 | |||
| 438 | return $f; |
||
| 439 | } |
||
| 440 | |||
| 441 | return false; |
||
| 442 | } |
||
| 443 | |||
| 444 | function delBlogPost($id) |
||
| 445 | { |
||
| 446 | $ids = $this->findIDs('BlogPosts', 'WHERE ParentID=' . $id); |
||
| 447 | for ($i = 0; $i < count($ids); $i++) |
||
| 448 | { |
||
| 449 | $this->delBlogPost($ids[$i]); |
||
| 450 | } |
||
| 451 | |||
| 452 | $this->query('DELETE FROM BlogPosts WHERE ID=' . $id); |
||
| 453 | } |
||
| 454 | |||
| 455 | function getGetID() |
||
| 456 | { |
||
| 457 | $id = $_GET['id']; |
||
| 458 | if (empty($id)) |
||
| 459 | { |
||
| 460 | $id = 1; |
||
| 461 | } |
||
| 462 | |||
| 463 | return $id; |
||
| 464 | } |
||
| 465 | |||
| 466 | function getPostID() |
||
| 467 | { |
||
| 468 | $id = $_POST['id']; |
||
| 469 | if (empty($id)) |
||
| 470 | { |
||
| 471 | $id = 1; |
||
| 472 | } |
||
| 473 | |||
| 474 | return $id; |
||
| 475 | } |
||
| 476 | |||
| 477 | } |
||
| 478 | |||
| 479 | class User |
||
| 480 | { |
||
| 481 | public $ID; |
||
| 482 | public $accessID; |
||
| 483 | public $username; |
||
| 484 | public $password; |
||
| 485 | public $emailAddress; |
||
| 486 | public $name; |
||
| 487 | public $challengeID; |
||
| 488 | } |
||
| 489 | |||
| 490 | class BlogPost |
||
| 491 | { |
||
| 492 | public $ID; |
||
| 493 | public $parent; |
||
| 494 | public $author; |
||
| 495 | public $title; |
||
| 496 | public $content; |
||
| 497 | public $datePosted; |
||
| 498 | public $category; |
||
| 499 | public $spam; |
||
| 500 | } |
||
| 501 | |||
| 502 | class Project |
||
| 503 | { |
||
| 504 | public $ID; |
||
| 505 | public $author; |
||
| 506 | public $title; |
||
| 507 | public $description; |
||
| 508 | public $logoURL; |
||
| 509 | public $downloadURL; |
||
| 510 | public $websiteURL; |
||
| 511 | public $latestVersion; |
||
| 512 | public $lastUpdate; |
||
| 513 | } |
||
| 514 | |||
| 515 | class ForumCategory |
||
| 516 | { |
||
| 517 | public $ID; |
||
| 518 | public $parent; |
||
| 519 | public $title; |
||
| 520 | public $description; |
||
| 521 | } |
||
| 522 | |||
| 523 | class ForumPost |
||
| 524 | { |
||
| 525 | public $id; |
||
| 526 | public $author; |
||
| 527 | public $category; |
||
| 528 | public $parent; |
||
| 529 | public $title; |
||
| 530 | public $content; |
||
| 531 | public $datePosted; |
||
| 532 | public $spam; |
||
| 533 | } |
||
| 534 | |||
| 535 | function write($str) |
||
| 536 | { |
||
| 537 | echo $str; |
||
| 538 | echo "\n"; |
||
| 539 | } |
||
| 540 | |||
| 541 | ?> |