1,5 → 1,7 |
<?php |
|
require '_config.php'; |
|
class Taios_Page |
{ |
function __construct($title, $url = "") |
11,7 → 13,7 |
$this->drawnMiddle = false; |
$this->drawnFooter = false; |
|
$this->db = mysql_connect('localhost', 'root', 'puppylinux'); |
$this->db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD); |
if (!$this->db) |
{ |
$this->drawError('Failed to connect to database: ' . mysql_error()); |
49,7 → 51,7 |
write('<br />'); |
if ($this->isLoggedIn()) |
{ |
$this->drawMenuItem('Manage Account', 'admim/?id=' . $this->getLoggedInUser()->ID); |
$this->drawMenuItem('Administration', 'admin/'); |
$this->drawMenuItem('Logout', 'logout-do.php'); |
} |
else |
65,7 → 67,7 |
|
function drawMenuItem($t, $u) |
{ |
write('<p><a href="' . $this->url . $u . '"</a>' . $t . '</a></p>'); |
write('<p><a href="' . $this->url . $u . '">' . $t . '</a></p>'); |
} |
|
function drawMiddle() |
110,9 → 112,104 |
} |
} |
|
function redirect($url) |
function drawBlogPostTree($id, $first = false) |
{ |
header('Location: ' . $url); |
$post = $this->getBlogPost($id); |
if ($first) |
{ |
write('<h3><a href="post.php?id=' . $id . '">' . $post->title. '</a> <a href="post.php?id=' . $post->parent->ID . '">^</a></h3>'); |
} |
else |
{ |
write('<a href="post.php?id=' . $id . '"><h3>' . $post->title. '</h3></a>'); |
} |
write('<h5 style="color: #666666;">Posted On ' . date('l j F Y', $post->datePosted) . ' by ' . $post->user->name . ' (' . $post->user->username . ')</h5>'); |
write('<p>' . $this->replaceBBCode($post->content) . '</p>'); |
write('<br />'); |
if ($this->isUserNormal($this->getLoggedInUser())) |
{ |
echo '<p class="bold"><a href="add-post.php?id=' . $id . '">Add Comment</a>'; |
if ($this->isUserAdmin($this->getLoggedInUser()) || $this->getLoggedInUser()->ID == $post->author->ID) |
{ |
echo ' · <a href="edit-post.php?id=' . $id . '">Edit Post</a>'; |
echo ' · <a href="del-post.php?id=' . $id . '">Delete Post</a>'; |
} |
write('</p><br />'); |
} |
|
$ids = $this->findIDs('BlogPosts', 'WHERE ParentID=' . $id); |
for ($i = 0; $i < count($ids); $i++) |
{ |
write('<div class="indent">'); |
$this->drawBlogPostTree($ids[$i]); |
write('</div>'); |
} |
} |
|
function drawBlogCategoriesMenu() |
{ |
$cats = array(); |
|
$ids = $this->findIDs('BlogPosts', 'WHERE ParentID = -1'); |
for ($i = 0; $i < count($ids); $i++) |
{ |
$cat = $this->getBlogPost($ids[$i])->category; |
if (!in_array($cat, $cats)) |
{ |
array_push($cats, $cat); |
} |
} |
|
write('<h3>Categories</h3>'); |
for ($i = 0; $i < count($cats); $i++) |
{ |
$this->drawMenuItem($cats[$i], 'blog/index.php?cat=' . $cats[$i]); |
} |
} |
|
function replaceBBCode($str) |
{ |
$newstr = str_replace("\n", '</p><p>', $str); |
$newstr = str_replace(' ', ' ', $newstr); |
$newstr = str_replace(' :)', ' <img src="' . $this->url . 'data/smilies/face-smile.png" class="smiley" />', $newstr); |
$newstr = str_replace(' :p', ' <img src="' . $this->url . 'data/smilies/face-raspberry.png" class="smiley" />', $newstr); |
$newstr = str_replace(' :P', ' <img src="' . $this->url . 'data/smilies/face-raspberry.png" class="smiley" />',$newstr); |
$newstr = str_replace(' :|', ' <img src="' . $this->url . 'data/smilies/face-plain.png" class="smiley" />',$newstr); |
$newstr = str_replace(' :D', ' <img src="' . $this->url . 'data/smilies/face-laugh.png" class="smiley" />',$newstr); |
$newstr = str_replace(' =D', ' <img src="' . $this->url . 'data/smilies/face-laugh.png" class="smiley" />',$newstr); |
$newstr = str_replace(' :(', ' <img src="' . $this->url . 'data/smilies/face-sad.png" class="smiley" />',$newstr); |
$newstr = str_replace(' :0', ' <img src="' . $this->url . 'data/smilies/face-surprise.png" class="smiley" />',$newstr); |
$newstr = str_replace(' :o', ' <img src="' . $this->url . 'data/smilies/face-surprise.png" class="smiley" />',$newstr); |
$newstr = str_replace(' :O', ' <img src="' . $this->url . 'data/smilies/face-surprise.png" class="smiley" />',$newstr); |
$newstr = str_replace(' :/', ' <img src="' . $this->url . 'data/smilies/face-uncertain.png" class="smiley" />',$newstr); |
$newstr = str_replace(' ;)', ' <img src="' . $this->url . 'data/smilies/face-wink.png" class="smiley" />',$newstr); |
|
$bbcode = array( |
'/\[b\](.+?)\[\/b\]/is', |
'/\[i\](.+?)\[\/i\]/is', |
'/\[u\](.+?)\[\/u\]/is', |
'/\[url\](.+?)\[\/url\]/is', |
'/\[code\](.+?)\[\/code\]/is', |
'/\[img\](.+?)\[\/img\]/is' |
); |
|
$html = array( |
'<b>$1</b>', |
'<i>$1</i>', |
'<u>$1</u>', |
'<a href="$1">$1</a>', |
'<div class="code">$1</div>', |
'<img src="$1" />' |
); |
|
$newstr = preg_replace($bbcode, $html, $newstr); |
|
return $newstr; |
} |
|
function redirect($u) |
{ |
header('Location: ' . $u); |
die(); |
} |
|
174,12 → 271,20 |
return false; |
} |
|
function checkLoggedIn() |
{ |
if (!$this->isLoggedIn()) |
{ |
$this->drawError('You need to be logged in.'); |
} |
} |
|
function query($query) |
{ |
$result = mysql_query($query); |
if (!$result) |
{ |
$this->drawError('MySQL Error: ' . mysql_error()); |
$this->drawError('Query Failed: ' . $query . "\n" . 'MySQL Error: ' . mysql_error()); |
} |
|
return $result; |
247,11 → 352,21 |
{ |
$post = new BlogPost; |
$post->ID = $row['ID']; |
$post->user = $this->getUserByID($row['AuthorID']); |
if ($row['ParentID'] == -1) |
{ |
$post->parent = -1; |
} |
else |
{ |
$post->parent = $this->getBlogPost($row['ParentID']); |
} |
$post->author = $this->getUserByID($row['AuthorID']); |
$post->user = $this->getUserByID($row['AuthorID']); // For some older pages |
$post->title = $row['Title']; |
$post->content = $row['Content']; |
$post->datePosted = strtotime($row['DatePosted']); |
$post->category = $row['Category']; |
$post->spam = $row['Spam']; |
|
return $post; |
} |
258,6 → 373,103 |
|
$this->drawError('Cannot find blog post, #' . $id); |
} |
|
function getProject($id) |
{ |
$result = $this->query('SELECT * FROM Projects WHERE ID = ' . $id); |
while ($row = mysql_fetch_array($result)) |
{ |
$project = new Project; |
|
$project->ID = $row['ID']; |
$project->author = $this->getUserByID($row['AuthorID']); |
$project->title = $row['Title']; |
$project->description = $row['Description']; |
$project->logoURL = $row['LogoURL']; |
$project->downloadURL = $row['DownloadURL']; |
$project->websiteURL = $row['WebsiteURL']; |
$project->latestVersion = $row['LatestVersion']; |
$project->lastUpdate = strtotime($row['LastUpdate']); |
|
return $project; |
} |
|
return false; |
} |
|
function getForumCategory($id) |
{ |
$result = $this->query('SELECT * FROM ForumCategories WHERE ID = ' . $id); |
while ($row = mysql_fetch_array($result)) |
{ |
$f = new ForumCategory; |
|
$f->ID = $row['ID']; |
$f->parentID = $row['ParentID']; |
$f->title = $row['Title']; |
$f->description = $row['Description']; |
|
return $f; |
} |
|
return false; |
} |
|
function getForumPost($id) |
{ |
$result = $this->query('SELECT * FROM ForumPosts WHERE ID = ' . $id); |
while ($row = mysql_fetch_array($result)) |
{ |
$f = new ForumPost; |
|
$f->ID = $row['ID']; |
$f->author = $this->getUserByID($row['AuthorID']); |
$f->category = $this->getForumCategory($row['CategoryID']); |
$f->parent = $this->getForumPost($row['ParentID']); |
$f->title = $row['Title']; |
$f->content = $row['Content']; |
$f->datePosted = strtotime($row['DatePosted']); |
$f->spam = $row['Spam']; |
|
return $f; |
} |
|
return false; |
} |
|
function delBlogPost($id) |
{ |
$ids = $this->findIDs('BlogPosts', 'WHERE ParentID=' . $id); |
for ($i = 0; $i < count($ids); $i++) |
{ |
$this->delBlogPost($ids[$i]); |
} |
|
$this->query('DELETE FROM BlogPosts WHERE ID=' . $id); |
} |
|
function getGetID() |
{ |
$id = $_GET['id']; |
if (empty($id)) |
{ |
$id = 1; |
} |
|
return $id; |
} |
|
function getPostID() |
{ |
$id = $_POST['id']; |
if (empty($id)) |
{ |
$id = 1; |
} |
|
return $id; |
} |
|
} |
|
class User |
274,13 → 486,48 |
class BlogPost |
{ |
public $ID; |
public $parent; |
public $author; |
public $title; |
public $content; |
public $datePosted; |
public $category; |
public $spam; |
} |
|
class Project |
{ |
public $ID; |
public $author; |
public $title; |
public $description; |
public $logoURL; |
public $downloadURL; |
public $websiteURL; |
public $latestVersion; |
public $lastUpdate; |
} |
|
class ForumCategory |
{ |
public $ID; |
public $parentID; |
public $title; |
public $description; |
} |
|
class ForumPost |
{ |
public $id; |
public $author; |
public $category; |
public $parent; |
public $title; |
public $content; |
public $datePosted; |
public $spam; |
} |
|
function write($str) |
{ |
echo $str; |