diff --git a/html/forum/forum.inc b/html/forum/forum.inc new file mode 100644 index 0000000000..b946a6b418 --- /dev/null +++ b/html/forum/forum.inc @@ -0,0 +1,205 @@ + $value) + $this->$var = $$var; + } + + function getForums() { + $sql = 'SELECT * FROM forum WHERE category = '.$this->id.' ORDER BY orderID ASC'; + return sql_query($sql); + } +} + +class Forum { + var $id; + var $category; + var $orderID; + var $title; + var $description; + var $timestamp; + var $threads; + var $posts; + + function Forum($id = -1, $category = -1, $orderID = -1, $title = '', $description = '', $timestamp = 0, $threads = 0, $posts = 0) { + $vars = get_class_vars('Forum'); + foreach ($vars as $var => $value) + $this->$var = $$var; + } + + function getThreads($min = -1, $nRec = -1) { + $sql = 'SELECT * FROM thread WHERE forum = '.$this->id.' ORDER BY timestamp DESC'; + if ($min > -1) { + $sql .= ' LIMIT '.$min; + if ($nRec > -1) + $sql .= ', '.$nRec; + } elseif ($nRec > -1) + $sql .= ' LIMIT '.$nRec; + return sql_query($sql); + } +} + +class Thread { + var $id; + var $forum; + var $owner; + + var $title; + + var $timestamp; + var $views; + var $replies; + + function Thread($id = -1, $forum = -1, $owner = -1, $title = '', $timestamp = 0, $views = 0, $replies = 0) { + $vars = get_class_vars('Thread'); + foreach ($vars as $var => $value) + $this->$var = $$var; + } + + function getPosts($min = -1, $nRec = -1) { + $sql = 'SELECT * FROM post WHERE thread = '.$this->id.' ORDER BY id ASC'; + if ($min > -1) { + $sql .= ' LIMIT '.$min; + if ($nRec > -1) + $sql .= ', '.$nRec; + } elseif ($nRec > -1) + $sql .= ' LIMIT '.$nRec; + return sql_query($sql); + } + + function post($content) { + $title = addslashes(htmlentities($this->title)); + $content = addslashes(htmlentities($content)); + + $sql = "INSERT INTO thread (forum, owner, title, timestamp) VALUES (".$this->forum.", ".$this->owner.", '".$title."', UNIX_TIMESTAMP())"; + $result = sql_query($sql); + if (!$result) + return false; + $this->id = sql_insert_id(); + + $post = new Post(); + $post->thread = $this->id; + $post->user = $this->owner; + $post->content = $content; + $postID = $post->insert(); + + $sql = "UPDATE user SET posts = posts + 1 WHERE id = ".$this->owner." LIMIT 1"; + sql_query($sql); + + $sql = "UPDATE forum SET threads = threads + 1, posts = posts + 1, timestamp = UNIX_TIMESTAMP() WHERE id = ".$this->forum." LIMIT 1"; + sql_query($sql); + + return $thread->id; + } + + function reply($user = -1, $content = "") { + $content = addslashes(htmlentities($content)); + + $post = new Post(); + $post->thread = $this->id; + $post->user = $user; + $post->content = $content; + $postID = $post->insert(); + + $sql = "UPDATE user SET posts = posts + 1 WHERE id = ".$user." LIMIT 1"; + sql_query($sql); + + $sql = "UPDATE thread SET replies = replies + 1, timestamp = UNIX_TIMESTAMP() WHERE id = ".$this->id." LIMIT 1"; + sql_query($sql); + + $sql = "UPDATE forum SET posts = posts + 1, timestamp = UNIX_TIMESTAMP() WHERE id = ".$this->forum." LIMIT 1"; + sql_query($sql); + } + + function incView() { + $sql = "UPDATE thread SET views = views + 1 WHERE id = ".$this->id." LIMIT 1"; + sql_query($sql); + } +} + +class Post { + var $id; + var $thread; + var $user; + var $timestamp; + var $content; + + function Post($id = -1, $thread = -1, $user = -1, $timestamp = 0, $content = "") { + $vars = get_class_vars('Post'); + foreach ($vars as $var => $value) + $this->$var = $$var; + } + + function insert() { + $sql = "INSERT INTO post (thread, user, timestamp, content) VALUES (".$this->thread.", ".$this->user.", UNIX_TIMESTAMP(), '".$this->content."')"; + $result = sql_query($sql); + if (!$result) + return false; + return ($this->id = sql_insert_id()); + } +} + +/* group database functions */ + +function getCategories() { + $langID = (!empty($_SESSION['lang']['id']))?$_SESSION['lang']['id']:1; + $sql = "SELECT * FROM category WHERE lang = ".$langID." ORDER BY orderID ASC"; + return sql_query($sql); +} + +function getNextCategory($result) { + $category = sql_fetch_array($result); + if (!$category) + return false; + foreach ($category as $var => $value) + $category[$var] = stripslashes($value); + return new Category($category['id'], $category['name']); +} + +function getNextForum($result) { + $forum = sql_fetch_array($result); + if (!$forum) + return false; + foreach ($forum as $var => $value) + $forum[$var] = stripslashes($value); + return new Forum($forum['id'], $forum['category'], $forum['orderID'], $forum['title'], $forum['description'], $forum['timestamp'], $forum['threads'], $forum['posts']); +} + +function getNextThread($result) { + $thread = sql_fetch_array($result); + if (!$thread) + return false; + foreach ($thread as $var => $value) + $thread[$var] = stripslashes($value); + return new Thread($thread['id'], $thread['forum'], $thread['owner'], $thread['title'], $thread['timestamp'], $thread['views'], $thread['replies']); +} + +function getNextPost($result) { + $post = sql_fetch_array($result); + if (!$post) + return false; + foreach ($post as $var => $value) + $post[$var] = stripslashes($value); + return new Post($post['id'], $post['thread'], $post['user'], $post['timestamp'], $post['content']); +} + +/* specific database functions */ + +function getForum($forumID) { + $sql = "SELECT * FROM forum WHERE id = ".$forumID; + return getNextForum(sql_query($sql)); +} + +function getThread($threadID) { + $sql = "SELECT * FROM thread WHERE id = ".$threadID; + return getNextThread(sql_query($sql)); +} + +?> \ No newline at end of file diff --git a/html/forum/forum.php b/html/forum/forum.php new file mode 100644 index 0000000000..d417c87e78 --- /dev/null +++ b/html/forum/forum.php @@ -0,0 +1,101 @@ + + +

+ title ?> +
Forum +

+

Post a New Thread / Question

+ +threads > $n): + $totalPages = floor($forum->threads / $n); + $curPage = floor($_GET['start'] / $n); + + $pages = array(0, 1, 2); + for ($i = -1 ; $i <= 1 ; $i++) + if ($curPage + $i > 0 && $curPage + $i < $totalPages - 1) + array_push($pages, $curPage + $i); + for ($i = -3 ; $i <= -1 ; $i++) + if ($totalPages + $i > 0) + array_push($pages, $totalPages + $i); + $pages = array_unique($pages); + natsort($pages); + $pages = array_values($pages); + + $gotoStr = '

Goto page '; + + if ($curPage == 0) + $gotoStr .= '1'; + else + $gotoStr .= 'Previous 1'; + + for ($i = 1 ; $i < count($pages)-1 ; $i++) { + if ($curPage == $pages[$i]) { + $gotoStr .= ($i > 0 && $pages[$i-1] == $pages[$i] - 1)?', ':' ... '; + $gotoStr .= ''.($pages[$i]+1).''; + } else { + $gotoStr .= ($i > 0 && $pages[$i-1] == $pages[$i] - 1)?', ':' ... '; + $gotoStr .= ''.($pages[$i]+1).''; + } + } + + if ($curPage == $totalPages-1) + $gotoStr .= ', '.$totalPages.''; + else + $gotoStr .= ', '.$totalPages.' Next'; + + $gotoStr .= '

'; + + echo $gotoStr; +endif; +?> + +

+ + + + + + + + + getThreads($_GET['start'], $n); + while($thread = getNextThread($threads)): + $user = getUser($thread->owner); + ?> + + + + + + + + +
TitlesRepliesAuthorViewsLast Post
title) ?>replies ?>name ?>views ?>timestamp) ?>
+

+ +threads > $n) + echo $gotoStr; +?> + + \ No newline at end of file diff --git a/html/forum/index.php b/html/forum/index.php new file mode 100644 index 0000000000..272dde479c --- /dev/null +++ b/html/forum/index.php @@ -0,0 +1,71 @@ + + +

Forum

+

+

+ Language filter: + + +
+

+

+ + + + + + + + + + + + getForums(); + while ($forum = getNextForum($forums)): + ?> + + + + + + + +
ForumThreadsPostsLast Post
name ?>
+ title ?> +
description ?> +
threads ?>posts ?>timestamp) ?>
+

+ + \ No newline at end of file diff --git a/html/forum/lang.php b/html/forum/lang.php new file mode 100644 index 0000000000..fef6885ae5 --- /dev/null +++ b/html/forum/lang.php @@ -0,0 +1,12 @@ + 0) { + $lang = getLanguage($_GET['id']); + $_SESSION['lang']['id'] = $lang->langID; + $_SESSION['lang']['charset'] = $lang->charset; +} + +header('Location: http://'.$_SERVER['HTTP_HOST'].substr($_SERVER['PATH_INFO'], 0, strrpos($_SERVER['PATH_INFO'], '/')).'/index.php'); +?> \ No newline at end of file diff --git a/html/forum/post.php b/html/forum/post.php new file mode 100644 index 0000000000..dea7dc9c0a --- /dev/null +++ b/html/forum/post.php @@ -0,0 +1,61 @@ +forum = $_GET['id']; + $thread->owner = $user->id; + $thread->title = $_POST['title']; + + $thread->post($_POST['content']); + + header('Location: thread.php?id='.$thread->id); +} + +if (empty($_SESSION['authenticator'])) + header('Location: ../login_form.php'); + +doHeader('Forum'); + +$forum = getForum($_GET['id']); +?> + +

+ title ?> +
Forum +

+ +

+

+ + + + + + + + + + + + + + + +
Post a New Thread / Question
Title
Message content
+ +
+
+

+ + \ No newline at end of file diff --git a/html/forum/reply.php b/html/forum/reply.php new file mode 100644 index 0000000000..9fef9cb15b --- /dev/null +++ b/html/forum/reply.php @@ -0,0 +1,87 @@ +reply($user->id, $_POST['content']); + + header('Location: thread.php?id='.$thread->id); +} + +if (empty($_SESSION['authenticator'])) + header('Location: ../login_form.php'); + +doHeader('Forum'); + +$thread = getThread($_GET['id']); +$forum = getForum($thread->forum); +?> + +

+ title ?> +
Forum -> title ?> +

+ +

+

+ + + + + + + + + + + +
Reply to Thread / Question
Message content
+ +
+
+

+ +

+ + + + + + getPosts(); + while ($post = getNextPost($posts)): + $user = getUser($post->user); + ?> + + + + + +
AuthorMessage
+

+ name ?> +

+

+ Joined: create_time) ?> +
Posts: posts ?> +

+
+

Posted: timestamp) ?>

+

content)) ?>

+
+

+ + diff --git a/html/forum/search.php b/html/forum/search.php new file mode 100644 index 0000000000..8c1c9fec6f --- /dev/null +++ b/html/forum/search.php @@ -0,0 +1,43 @@ + + +

+ Search +
Forum +

+ +

+

+ + + + + + + + + + + + + + + +
Search in Forum
Topic
Message content
+ +
+
+

+ + \ No newline at end of file diff --git a/html/forum/thread.php b/html/forum/thread.php new file mode 100644 index 0000000000..d268b67b11 --- /dev/null +++ b/html/forum/thread.php @@ -0,0 +1,61 @@ +incView(); + +$forum = getForum($thread->forum); +?> + +

+ title ?> +
Forum -> title ?> +

+

+ Reply to Thread / Question +

+

+ + + + + + getPosts(); + while ($post = getNextPost($posts)): + $user = getUser($post->user); + ?> + + + + + +
AuthorMessage
+

+ has_profile) { ?> + name ?> + name; }?> +

+

+ Joined: create_time) ?> +
Posts: posts ?> +

+
+

Posted: timestamp) ?>

+

content)) ?>

+
+

+ + \ No newline at end of file diff --git a/html/inc/config.inc b/html/inc/config.inc new file mode 100644 index 0000000000..5c5ba75525 --- /dev/null +++ b/html/inc/config.inc @@ -0,0 +1,11 @@ + \ No newline at end of file diff --git a/html/inc/database.inc b/html/inc/database.inc new file mode 100644 index 0000000000..1c39ebad35 --- /dev/null +++ b/html/inc/database.inc @@ -0,0 +1,26 @@ +MySQL #'.mysql_errno().': '.mysql_error()."\n\nSQL: $sql"); + return $result; +} + +function sql_fetch_array($result) { + return mysql_fetch_array($result); +} + +function sql_num_rows($result) { + return mysql_num_rows($result); +} + +function sql_insert_id() { + return mysql_insert_id(); +} + +?> \ No newline at end of file diff --git a/html/inc/error.inc b/html/inc/error.inc new file mode 100644 index 0000000000..eed7a0d2fa --- /dev/null +++ b/html/inc/error.inc @@ -0,0 +1,15 @@ +'.$msg.'

'; + echo '

The error has been recorded, and the website administrator will investigate the issue as soon as possible. We sincerely apologize for the inconvenience.

'; + + doFooter(); + exit(); +} + +?> \ No newline at end of file diff --git a/html/inc/template.inc b/html/inc/template.inc new file mode 100644 index 0000000000..f16b43c060 --- /dev/null +++ b/html/inc/template.inc @@ -0,0 +1,39 @@ + + + + + + + + <?php echo $GLOBALS['cfg']['sitename'].' - '.$caption ?> + + + + + + + + + + +
+ +

Return to Homepage

+ +
+ + + + + +