13,17 → 13,13 |
$this->drawnMiddle = false; |
$this->drawnFooter = false; |
|
$this->db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD); |
if (!$this->db) |
{ |
$this->drawError('Failed to connect to database: ' . mysql_error()); |
try { |
$this->db = new PDO("mysql:dbname=Tim32;host=" . MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, |
array( PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'" )); |
} catch (PDOException $e) { |
$this->drawError("Failed to connect to database!"); |
} |
|
if (!mysql_select_db('Tim32')) |
{ |
$this->drawError('Failed to select database: ' . mysql_error()); |
} |
} |
|
function drawHeader() |
{ |
36,6 → 32,8 |
write('<title>Tim32 · ' . $this->title . '</title>'); |
write('<link href="' . $this->url . 'styles.css" rel="stylesheet" type="text/css" media="screen" />'); |
write('<link rel="shortcut icon" href="' . $this->url . 'data/favicon.png" />'); |
write('<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.0.min.js"></script>'); |
write('<script type="text/javascript" src="' . $this->url . 'tcp.js"></script>'); |
write('</head>'); |
write('<body>'); |
write('<div class="sidebar">'); |
50,37 → 48,32 |
$this->drawMenuItem('Wiki', 'wiki/'); |
$this->drawMenuItem('Photos', 'photos/'); |
write('<br />'); |
if ($this->isLoggedIn() && $this->isUserNormal($this->getLoggedInUser())) |
{ |
|
if ($this->isLoggedIn() && $this->isUserNormal($this->getLoggedInUser())) { |
$this->drawMenuItem('Administration', 'admin/'); |
$this->drawMenuItem('Logout', 'logout-do.php'); |
} |
else if ($this->isLoggedIn()) |
{ |
} else if ($this->isLoggedIn()) { |
$this->drawMenuItem('Logout', 'logout-do.php'); |
if ($this->getLoggedInUser()->username != "cake") |
|
if ($this->getLoggedInUser()->username != "cake") { |
$this->drawMenuItem('You are banned', NULL); |
else |
} else { |
$this->drawMenuItem('<span style="color:#032865">#undefined</span>', '/challenge/cakefolder'); |
} |
else |
{ |
} else { |
$this->drawMenuItem('Login', 'login.php'); |
$this->drawMenuItem('Register', 'register.php'); |
} |
|
write('<br />'); |
$this->drawnHeader = true; |
} |
} |
|
function drawMenuItem($t, $u) |
{ |
if($u == NULL) |
{ |
function drawMenuItem($t, $u) { |
if ($u == NULL) { |
write('<p style="color:red">' . $t . '</p>'); |
} |
else |
{ |
} else { |
write('<p><a href="' . $this->url . $u . '">' . $t . '</a></p>'); |
} |
} |
87,9 → 80,7 |
|
function drawMiddle() |
{ |
if (!$this->drawnMiddle) |
{ |
write('<br />'); |
if (!$this->drawnMiddle) { |
write('</div>'); |
write('</div>'); |
write('<div class="content">'); |
103,7 → 94,6 |
{ |
if (!$this->drawnFooter) |
{ |
write('<br /><p class="copyright">Tim32</p>'); |
write('</div>'); |
write('</body>'); |
write('</html>'); |
185,18 → 175,6 |
|
function replaceBBCode($str) |
{ |
/*$newstrarray = explode("\n", $str); |
$newstr = ""; |
foreach ($newstrarray as $line) |
{ |
if ($line == "\n" || $line == " \n" || $line == "\n " || $line == "\n\r") |
{ |
$line = "</p><p>"; |
} |
|
$newstr .= ($line . "\n"); |
}*/ |
|
$newstr = $str; |
$newstr = str_replace("<", "<", $newstr); |
$newstr = str_replace(">", ">", $newstr); |
204,18 → 182,6 |
$newstr = str_replace("\\'", "'", $newstr); |
$newstr = str_replace("\\\"",'"', $newstr); |
$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', |
222,13 → 188,16 |
'/\[i\](.+?)\[\/i\]/is', |
'/\[u\](.+?)\[\/u\]/is', |
'/\[url\](.+?)\[\/url\]/is', |
'/\[url="?(.+?)"?\](.+?)\[\/url\]/is', |
'/\[w\](.+?)\[\/w\]/is', |
'/\[url=(?:")?(.+?)(?:")?\](.+?)\[\/url\]/is', |
'/\[w=(?:")?(.+?)(?:")?\](.+?)\[\/w\]/is', |
'/\[code\](.+?)\[\/code\]/is', |
'/\[img\](.+?)\[\/img\]/is', |
'/\[ul\](.+?)\[\/ul\]/is', |
'/\[ol\](.+?)\[\/ol\]/is', |
'/\[li\](.+?)\[\/li\]/is', |
'/\[mono\](.+?)\[\/mono\]/is' |
'/\[mono\](.+?)\[\/mono\]/is', |
'/\[tcp\](.+?)\[\/tcp\]/is' |
); |
|
$html = array( |
236,13 → 205,16 |
'<i>$1</i>', |
'<u>$1</u>', |
'<a href="$1">$1</a>', |
'<a href="/wiki/index.php?page=$1">$1</a>', |
'<a href="$1">$2</a>', |
'<a href="/wiki/index.php?page=$1">$2</a>', |
'</p><div class="code">$1</div><p>', |
'<img src="$1" />', |
'<img src="$1" alt="BBCode-included image" />', |
'<ul>$1</ul>', |
'<ol>$1</ol>', |
'<li>$1</li>', |
'<span style="font-family: Droid Sans Mono, monospace, fixed; margin-left: 1em; margin-right: 1em;">$1</span>', |
'<span class="tcp" data-status="closed" data-text="$1">$1<img title="Open TCP Editor" class="tcp_button" src="http://tim32.org/~freddie/timlan/goTCP.png" alt="Open TCP Editor" /></span>' |
); |
|
$newstr = preg_replace($bbcode, $html, $newstr); |
353,15 → 325,14 |
} |
} |
|
function query($query) |
function query($query, $args = [ ]) |
{ |
$result = mysql_query($query); |
if (!$result) |
{ |
$this->drawError('Query Failed: ' . $query . "\n" . 'MySQL Error: ' . mysql_error()); |
$statement = $this->db->prepare($query); |
if (!$statement->execute($args)) { |
$this->drawError("Query Failed! MySQL Error: " . $statement->errorInfo()); |
} |
|
return $result; |
return $statement->fetchAll(); |
} |
|
function findIDs($table, $query = '') |
368,9 → 339,8 |
{ |
$array = array(); |
|
$result = $this->query('SELECT ID FROM ' . $table . ' ' . $query); |
while ($row = mysql_fetch_array($result)) |
{ |
$results = $this->query('SELECT ID FROM ' . $table . ' ' . $query); |
foreach ($results as $row) { |
array_push($array, $row['ID']); |
} |
|
379,9 → 349,8 |
|
function getUserByID($id) |
{ |
$result = $this->query('SELECT * FROM Users WHERE ID = "' . $id . '"'); |
while ($row = mysql_fetch_array($result)) |
{ |
$results = $this->query('SELECT * FROM Users WHERE ID = "' . $id . '"'); |
foreach ($results as $row) { |
$user = new User; |
$user->ID = $row['ID']; |
$user->accessID = $row['AccessID']; |
399,9 → 368,8 |
|
function getUserByUsername($username) |
{ |
$result = $this->query('SELECT * FROM Users WHERE Username = "' . $username . '"'); |
while ($row = mysql_fetch_array($result)) |
{ |
$results = $this->query('SELECT * FROM Users WHERE Username = "' . $username . '"'); |
foreach ($results as $row) { |
return $this->getUserByID($row['ID']); |
} |
|
421,9 → 389,8 |
|
function getBlogPost($id) |
{ |
$result = $this->query('SELECT * FROM BlogPosts WHERE ID = "' . $id . '"'); |
while ($row = mysql_fetch_array($result)) |
{ |
$results = $this->query('SELECT * FROM BlogPosts WHERE ID = "' . $id . '"'); |
foreach ($results as $row) { |
$post = new BlogPost; |
$post->ID = $row['ID']; |
if ($row['ParentID'] == -1) |
436,8 → 403,8 |
} |
$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->title = htmlspecialchars($row['Title']); |
$post->content = htmlspecialchars($row['Content']); |
$post->datePosted = strtotime($row['DatePosted']); |
$post->category = $row['Category']; |
$post->spam = $row['Spam']; |
450,9 → 417,8 |
|
function getProject($id) |
{ |
$result = $this->query('SELECT * FROM Projects WHERE ID = "' . $id . '"'); |
while ($row = mysql_fetch_array($result)) |
{ |
$results = $this->query('SELECT * FROM Projects WHERE ID = "' . $id . '"'); |
foreach ($results as $row) { |
$project = new Project; |
|
$project->ID = $row['ID']; |
473,9 → 439,8 |
|
function getForumCategory($id) |
{ |
$result = $this->query('SELECT * FROM ForumCategories WHERE ID = "' . $id . '"'); |
while ($row = mysql_fetch_array($result)) |
{ |
$results = $this->query('SELECT * FROM ForumCategories WHERE ID = "' . $id . '"'); |
foreach ($results as $row) { |
$f = new ForumCategory; |
|
$f->ID = $row['ID']; |
491,9 → 456,8 |
|
function getForumPost($id) |
{ |
$result = $this->query('SELECT * FROM ForumPosts WHERE ID = "' . $id . '"'); |
while ($row = mysql_fetch_array($result)) |
{ |
$results = $this->query('SELECT * FROM ForumPosts WHERE ID = "' . $id . '"'); |
foreach ($results as $row) { |
$f = new ForumPost; |
|
$f->ID = $row['ID']; |