Rev 191 | Rev 248 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 169 | tom | 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) |
||
| 175 | tom | 119 | { |
| 169 | tom | 120 | write('<h3><a href="post.php?id=' . $id . '">' . $post->title. '</a> <a href="post.php?id=' . $post->parent->ID . '">^</a></h3>'); |
| 175 | tom | 121 | } |
| 169 | tom | 122 | else |
| 175 | tom | 123 | { |
| 169 | tom | 124 | write('<a href="post.php?id=' . $id . '"><h3>' . $post->title. '</h3></a>'); |
| 175 | tom | 125 | } |
| 169 | tom | 126 | write('<h5 style="color: #666666;">Posted On ' . date('l j F Y', $post->datePosted) . ' by ' . $post->user->name . ' (' . $post->user->username . ')</h5>'); |
| 175 | tom | 127 | write('<p>' . $this->replaceBBCode($post->content) . '</p>'); |
| 169 | tom | 128 | write('<br />'); |
| 129 | if ($this->isUserNormal($this->getLoggedInUser())) |
||
| 130 | { |
||
| 131 | echo '<p class="bold"><a href="add-post.php?id=' . $id . '">Add Comment</a>'; |
||
| 179 | tom | 132 | if ($this->isUserAdmin($this->getLoggedInUser()) || $this->getLoggedInUser()->ID == $post->author->ID) |
| 174 | tom | 133 | { |
| 134 | echo ' · <a href="edit-post.php?id=' . $id . '">Edit Post</a>'; |
||
| 177 | tom | 135 | echo ' · <a href="del-post.php?id=' . $id . '">Delete Post</a>'; |
| 174 | tom | 136 | } |
| 169 | tom | 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 | { |
||
| 172 | $newstr = str_replace("\n", '</p><p>', $str); |
||
| 173 | $newstr = str_replace(' ', ' ', $newstr); |
||
| 174 | $newstr = str_replace(' :)', ' <img src="' . $this->url . 'data/smilies/face-smile.png" class="smiley" />', $newstr); |
||
| 175 | $newstr = str_replace(' :p', ' <img src="' . $this->url . 'data/smilies/face-raspberry.png" class="smiley" />', $newstr); |
||
| 176 | $newstr = str_replace(' :P', ' <img src="' . $this->url . 'data/smilies/face-raspberry.png" class="smiley" />',$newstr); |
||
| 177 | $newstr = str_replace(' :|', ' <img src="' . $this->url . 'data/smilies/face-plain.png" class="smiley" />',$newstr); |
||
| 178 | $newstr = str_replace(' :D', ' <img src="' . $this->url . 'data/smilies/face-laugh.png" class="smiley" />',$newstr); |
||
| 179 | $newstr = str_replace(' =D', ' <img src="' . $this->url . 'data/smilies/face-laugh.png" class="smiley" />',$newstr); |
||
| 180 | $newstr = str_replace(' :(', ' <img src="' . $this->url . 'data/smilies/face-sad.png" class="smiley" />',$newstr); |
||
| 181 | $newstr = str_replace(' :0', ' <img src="' . $this->url . 'data/smilies/face-surprise.png" class="smiley" />',$newstr); |
||
| 182 | $newstr = str_replace(' :o', ' <img src="' . $this->url . 'data/smilies/face-surprise.png" class="smiley" />',$newstr); |
||
| 183 | $newstr = str_replace(' :O', ' <img src="' . $this->url . 'data/smilies/face-surprise.png" class="smiley" />',$newstr); |
||
| 184 | $newstr = str_replace(' :/', ' <img src="' . $this->url . 'data/smilies/face-uncertain.png" class="smiley" />',$newstr); |
||
| 185 | $newstr = str_replace(' ;)', ' <img src="' . $this->url . 'data/smilies/face-wink.png" class="smiley" />',$newstr); |
||
| 186 | |||
| 187 | $bbcode = array( |
||
| 188 | '/\[b\](.+?)\[\/b\]/is', |
||
| 189 | '/\[i\](.+?)\[\/i\]/is', |
||
| 190 | '/\[u\](.+?)\[\/u\]/is', |
||
| 191 | '/\[url\](.+?)\[\/url\]/is', |
||
| 192 | '/\[code\](.+?)\[\/code\]/is', |
||
| 193 | '/\[img\](.+?)\[\/img\]/is' |
||
| 194 | ); |
||
| 195 | |||
| 196 | $html = array( |
||
| 197 | '<b>$1</b>', |
||
| 198 | '<i>$1</i>', |
||
| 199 | '<u>$1</u>', |
||
| 200 | '<a href="$1">$1</a>', |
||
| 201 | '<div class="code">$1</div>', |
||
| 202 | '<img src="$1" />' |
||
| 203 | ); |
||
| 204 | |||
| 205 | $newstr = preg_replace($bbcode, $html, $newstr); |
||
| 206 | |||
| 207 | return $newstr; |
||
| 208 | } |
||
| 209 | |||
| 210 | function redirect($u) |
||
| 211 | { |
||
| 212 | header('Location: ' . $u); |
||
| 213 | die(); |
||
| 214 | } |
||
| 215 | |||
| 216 | function isLoggedIn() |
||
| 217 | { |
||
| 218 | $cookie = $_COOKIE['Tim32_Login']; |
||
| 219 | if (!empty($cookie)) |
||
| 220 | { |
||
| 221 | $clist = explode('|~|', $cookie); |
||
| 222 | $user = $this->getUserByUsername($clist[0]); |
||
| 223 | if ($user) |
||
| 224 | { |
||
| 225 | if ($user->password == $clist[1]) |
||
| 226 | { |
||
| 227 | return true; |
||
| 228 | } |
||
| 229 | } |
||
| 230 | } |
||
| 231 | |||
| 232 | return false; |
||
| 233 | } |
||
| 234 | |||
| 235 | function isUserAdmin() |
||
| 236 | { |
||
| 237 | if ($this->isLoggedIn()) |
||
| 238 | { |
||
| 239 | if ($this->getLoggedInUser()->accessID <= 0) |
||
| 240 | { |
||
| 241 | return true; |
||
| 242 | } |
||
| 243 | } |
||
| 244 | |||
| 245 | return false; |
||
| 246 | } |
||
| 247 | |||
| 248 | function isUserGM() |
||
| 249 | { |
||
| 250 | if ($this->isLoggedIn()) |
||
| 251 | { |
||
| 252 | if ($this->getLoggedInUser()->accessID <= 1) |
||
| 253 | { |
||
| 254 | return true; |
||
| 255 | } |
||
| 256 | } |
||
| 257 | |||
| 258 | return false; |
||
| 259 | } |
||
| 260 | |||
| 261 | function isUserNormal() |
||
| 262 | { |
||
| 263 | if ($this->isLoggedIn()) |
||
| 264 | { |
||
| 265 | if ($this->getLoggedInUser()->accessID <= 2) |
||
| 266 | { |
||
| 267 | return true; |
||
| 268 | } |
||
| 269 | } |
||
| 270 | |||
| 271 | return false; |
||
| 272 | } |
||
| 273 | |||
| 274 | function checkLoggedIn() |
||
| 275 | { |
||
| 276 | if (!$this->isLoggedIn()) |
||
| 277 | { |
||
| 278 | $this->drawError('You need to be logged in.'); |
||
| 279 | } |
||
| 280 | } |
||
| 281 | |||
| 282 | function query($query) |
||
| 283 | { |
||
| 284 | $result = mysql_query($query); |
||
| 285 | if (!$result) |
||
| 286 | { |
||
| 287 | $this->drawError('MySQL Error: ' . mysql_error()); |
||
| 288 | } |
||
| 289 | |||
| 290 | return $result; |
||
| 291 | } |
||
| 292 | |||
| 293 | function findIDs($table, $query = '') |
||
| 294 | { |
||
| 295 | $array = array(); |
||
| 296 | |||
| 297 | $result = $this->query('SELECT ID FROM ' . $table . ' ' . $query); |
||
| 298 | while ($row = mysql_fetch_array($result)) |
||
| 299 | { |
||
| 300 | array_push($array, $row['ID']); |
||
| 301 | } |
||
| 302 | |||
| 303 | return $array; |
||
| 304 | } |
||
| 305 | |||
| 306 | function getUserByID($id) |
||
| 307 | { |
||
| 308 | $result = $this->query('SELECT * FROM Users WHERE ID = ' . $id); |
||
| 309 | while ($row = mysql_fetch_array($result)) |
||
| 310 | { |
||
| 311 | $user = new User; |
||
| 312 | $user->ID = $row['ID']; |
||
| 313 | $user->accessID = $row['AccessID']; |
||
| 314 | $user->username = $row['Username']; |
||
| 315 | $user->password = $row['Password']; |
||
| 316 | $user->emailAddress = $row['EmailAddress']; |
||
| 317 | $user->name = $row['Name']; |
||
| 318 | $user->challengeID = $row['ChallengeID']; |
||
| 319 | |||
| 320 | return $user; |
||
| 321 | } |
||
| 322 | |||
| 323 | return false; |
||
| 324 | } |
||
| 325 | |||
| 326 | function getUserByUsername($username) |
||
| 327 | { |
||
| 328 | $result = $this->query('SELECT * FROM Users WHERE Username = "' . $username . '"'); |
||
| 329 | while ($row = mysql_fetch_array($result)) |
||
| 330 | { |
||
| 331 | return $this->getUserByID($row['ID']); |
||
| 332 | } |
||
| 333 | |||
| 334 | return false; |
||
| 335 | } |
||
| 336 | |||
| 337 | function getLoggedInUser() |
||
| 338 | { |
||
| 339 | if ($this->isLoggedIn()) |
||
| 340 | { |
||
| 341 | $clist = explode('|~|', $_COOKIE['Tim32_Login']); |
||
| 342 | return $this->getUserByUsername($clist[0]); |
||
| 343 | } |
||
| 344 | |||
| 345 | return false; |
||
| 346 | } |
||
| 347 | |||
| 348 | function getBlogPost($id) |
||
| 349 | { |
||
| 350 | $result = $this->query('SELECT * FROM BlogPosts WHERE ID = ' . $id); |
||
| 351 | while ($row = mysql_fetch_array($result)) |
||
| 352 | { |
||
| 353 | $post = new BlogPost; |
||
| 354 | $post->ID = $row['ID']; |
||
| 355 | if ($row['ParentID'] == -1) |
||
| 356 | { |
||
| 357 | $post->parent = -1; |
||
| 358 | } |
||
| 359 | else |
||
| 360 | { |
||
| 361 | $post->parent = $this->getBlogPost($row['ParentID']); |
||
| 362 | } |
||
| 363 | $post->author = $this->getUserByID($row['AuthorID']); |
||
| 364 | $post->user = $this->getUserByID($row['AuthorID']); // For some older pages |
||
| 365 | $post->title = $row['Title']; |
||
| 175 | tom | 366 | $post->content = $row['Content']; |
| 169 | tom | 367 | $post->datePosted = strtotime($row['DatePosted']); |
| 368 | $post->category = $row['Category']; |
||
| 369 | $post->spam = $row['Spam']; |
||
| 370 | |||
| 371 | return $post; |
||
| 372 | } |
||
| 373 | |||
| 374 | $this->drawError('Cannot find blog post, #' . $id); |
||
| 375 | } |
||
| 376 | |||
| 191 | tom | 377 | function getProject($id) |
| 378 | { |
||
| 379 | $result = $this->query('SELECT * FROM Projects WHERE ID = ' . $id); |
||
| 380 | while ($row = mysql_fetch_array($result)) |
||
| 381 | { |
||
| 382 | $project = new Project; |
||
| 383 | |||
| 384 | $project->ID = $row['ID']; |
||
| 385 | $project->author = $this->getUserByID($row['AuthorID']); |
||
| 386 | $project->title = $row['Title']; |
||
| 387 | $project->description = $row['Description']; |
||
| 388 | $project->logoURL = $row['LogoURL']; |
||
| 389 | $project->downloadURL = $row['DownloadURL']; |
||
| 200 | tom | 390 | $project->websiteURL = $row['WebsiteURL']; |
| 191 | tom | 391 | $project->latestVersion = $row['LatestVersion']; |
| 392 | $project->lastUpdate = strtotime($row['LastUpdate']); |
||
| 393 | |||
| 394 | return $project; |
||
| 395 | } |
||
| 396 | |||
| 397 | return false; |
||
| 398 | } |
||
| 399 | |||
| 169 | tom | 400 | function delBlogPost($id) |
| 401 | { |
||
| 402 | $ids = $this->findIDs('BlogPosts', 'WHERE ParentID=' . $id); |
||
| 403 | for ($i = 0; $i < count($ids); $i++) |
||
| 191 | tom | 404 | { |
| 169 | tom | 405 | $this->delBlogPost($ids[$i]); |
| 191 | tom | 406 | } |
| 169 | tom | 407 | |
| 191 | tom | 408 | $this->query('DELETE FROM BlogPosts WHERE ID=' . $id); |
| 169 | tom | 409 | } |
| 410 | |||
| 411 | function getGetID() |
||
| 412 | { |
||
| 413 | $id = $_GET['id']; |
||
| 414 | if (empty($id)) |
||
| 415 | { |
||
| 416 | $id = 1; |
||
| 417 | } |
||
| 418 | |||
| 419 | return $id; |
||
| 420 | } |
||
| 421 | |||
| 422 | function getPostID() |
||
| 423 | { |
||
| 424 | $id = $_POST['id']; |
||
| 425 | if (empty($id)) |
||
| 426 | { |
||
| 427 | $id = 1; |
||
| 428 | } |
||
| 429 | |||
| 430 | return $id; |
||
| 431 | } |
||
| 432 | |||
| 433 | } |
||
| 434 | |||
| 435 | class User |
||
| 436 | { |
||
| 437 | public $ID; |
||
| 438 | public $accessID; |
||
| 439 | public $username; |
||
| 440 | public $password; |
||
| 441 | public $emailAddress; |
||
| 442 | public $name; |
||
| 443 | public $challengeID; |
||
| 444 | } |
||
| 445 | |||
| 446 | class BlogPost |
||
| 447 | { |
||
| 448 | public $ID; |
||
| 449 | public $parent; |
||
| 450 | public $author; |
||
| 451 | public $title; |
||
| 452 | public $content; |
||
| 453 | public $datePosted; |
||
| 454 | public $category; |
||
| 455 | public $spam; |
||
| 456 | } |
||
| 457 | |||
| 191 | tom | 458 | class Project |
| 459 | { |
||
| 460 | public $ID; |
||
| 461 | public $author; |
||
| 462 | public $title; |
||
| 463 | public $description; |
||
| 464 | public $logoURL; |
||
| 465 | public $downloadURL; |
||
| 466 | public $websiteURL; |
||
| 467 | public $latestVersion; |
||
| 468 | public $lastUpdate; |
||
| 469 | } |
||
| 470 | |||
| 169 | tom | 471 | function write($str) |
| 472 | { |
||
| 473 | echo $str; |
||
| 474 | echo "\n"; |
||
| 475 | } |
||
| 476 | |||
| 477 | ?> |