summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchange_passw.php1
-rwxr-xr-xincludes/error.php4
-rwxr-xr-xincludes/model/Category.php4
-rwxr-xr-xincludes/model/Post.php7
-rw-r--r--[-rwxr-xr-x]includes/model/Thread.php288
-rwxr-xr-xincludes/model/User.php4
-rwxr-xr-xincludes/templates/404.php4
-rwxr-xr-xincludes/templates/head.php4
-rwxr-xr-xincludes/templates/header.php4
-rwxr-xr-xindex.php2
-rwxr-xr-xmoderate.php4
-rwxr-xr-xsignin.php5
-rwxr-xr-xstyles/style.css89
-rwxr-xr-xviewthread.php2
14 files changed, 166 insertions, 256 deletions
diff --git a/change_passw.php b/change_passw.php
index 82db6d3..a9a216f 100755
--- a/change_passw.php
+++ b/change_passw.php
@@ -1,7 +1,6 @@
<?php
include_once './includes/Session.php';
include_once './includes/model/User.php';
-include_once './includes/functions_user.php';
session_start();
diff --git a/includes/error.php b/includes/error.php
index 1450a28..ba236ac 100755
--- a/includes/error.php
+++ b/includes/error.php
@@ -3,7 +3,7 @@ function user_notice($message) {
echo '<p class="error">'. $message .'</p>';
}
-function handle_error($errno, $errstr, $errfile, $errline) {
+function handle_error($errno, $errstr) {
if (!(error_reporting() & $errno)) {
// This error code is not included in error_reporting, so let it fall
// through to the standard PHP error handler
@@ -22,4 +22,4 @@ function handle_error($errno, $errstr, $errfile, $errline) {
}
$old_error_handler = set_error_handler('handle_error');
-?>
+
diff --git a/includes/model/Category.php b/includes/model/Category.php
index 37ad4f8..fb57918 100755
--- a/includes/model/Category.php
+++ b/includes/model/Category.php
@@ -34,8 +34,8 @@ class Category
}
// Returns true if this object was successfully fetched from the database
- public function has_value()
- {
+ public function has_value(): bool
+ {
return $this->has_value;
}
diff --git a/includes/model/Post.php b/includes/model/Post.php
index 1b64490..46a0af0 100755
--- a/includes/model/Post.php
+++ b/includes/model/Post.php
@@ -78,8 +78,8 @@ class Post
$this->has_value = true;
}
- public function has_value()
- {
+ public function has_value(): bool
+ {
return $this->has_value;
}
@@ -175,8 +175,7 @@ class Post
$posts = array();
foreach ($result as $row) {
- $post = new Post();
- $post->get_from_database($row['post_id']);
+ $post = new Post($row['post_id']);
array_push($posts, $post);
}
diff --git a/includes/model/Thread.php b/includes/model/Thread.php
index e02b4b2..628a325 100755..100644
--- a/includes/model/Thread.php
+++ b/includes/model/Thread.php
@@ -1,144 +1,144 @@
-<?php
-include_once './includes/Database.php';
-include_once './includes/Session.php';
-include_once 'Category.php';
-include_once 'User.php';
-include_once 'Post.php';
-
-class Thread
-{
- public $id;
- public $subject;
- public $date_created = 0;
- public $date_lastpost = 0;
- public $category;
- public $author;
-
- private $has_value = false;
-
- function __construct($id)
- {
- $sql = "SELECT thread_subject, thread_date_created, thread_date_lastpost, thread_category, thread_author FROM threads WHERE thread_id = ?;";
- $result = Database::get()->query($sql, "i", $id);
-
- if (empty($result)) {
- return;
- }
-
- $this->id = $id;
- $this->subject = $result[0]['thread_subject'];
- $this->date_created = $result[0]['thread_date_created'];
- $this->date_lastpost = $result[0]['thread_date_lastpost'];
- $this->category = new Category($result[0]['thread_category']);
-
- $this->author = new User();
- $this->author->get_by_id($result[0]['thread_author']);
-
- $this->has_value = true;
- }
-
- public static function create($subject, $category): int
- {
- if (!Session::get()->is_signed_in()) {
- trigger_error('You must be signed in to create a thread');
- return 0;
- }
-
- $user = Session::get()->get_current_user();
-
- // Insert the new thread into the database
- $sql = "INSERT INTO threads(thread_subject, thread_date_created, thread_date_lastpost, thread_category, thread_author) VALUES (?, CONVERT_TZ(NOW(), 'SYSTEM', '+00:00'), CONVERT_TZ(NOW(), 'SYSTEM', '+00:00'), ?, ?);";
- Database::get()->query($sql, "sii", $subject, $category, $user->id);
-
- // Get the ID of the thread we just created
- $thread_id = Database::get()->get_last_id();
-
- // Increment the category's thread count
- $sql = "UPDATE categories SET `cat_thread_count` = `cat_thread_count` + '1' WHERE cat_id = ?;";
- Database::get()->query($sql, "i", $category);
-
- return $thread_id;
- }
-
- public static function delete($thread)
- {
- // User must be signed in
- if (!Session::get()->is_signed_in()) {
- trigger_error('You must be signed in to delete a thread.');
- return;
- }
-
- // User must be a moderator to delete a thread
- $current_user = Session::get()->get_current_user();
- if ($current_user->level != USER_LEVEL_MODERATOR) {
- trigger_error("You must be a moderator to delete this post.");
- return;
- }
-
- // Delete the thread from the database
- Database::get()->query("DELETE FROM threads WHERE thread_id = ?", "i", $thread->id);
-
- // Decrement the thread count of the category
- Database::get()->query("UPDATE categories SET `cat_thread_count` = `cat_thread_count` - '1' WHERE cat_id = ?", "i", $thread->category->id);
- }
-
- public function has_value()
- {
- return $this->has_value;
- }
-
- public static function get_all(): array
- {
- $sql = "SELECT thread_id FROM threads";
- $result = Database::get()->query($sql);
-
- $threads = array();
-
- foreach ($result as $row) {
- $thread = new Thread($row['thread_id']);
- if ($thread->has_value())
- array_push($threads, $thread);
- }
-
- return $threads;
- }
-
- public static function get_latest(): array
- {
- $sql = "SELECT thread_id FROM threads ORDER BY thread_date_lastpost DESC LIMIT 10";
- $result = Database::get()->query($sql);
-
- $threads = array();
-
- foreach ($result as $row) {
- $thread = new Thread($row['thread_id']);
- if ($thread->has_value())
- array_push($threads, $thread);
- }
-
- return $threads;
- }
-
- public function get_posts(): array
- {
- $sql = "SELECT post_id FROM posts WHERE post_thread = ?";
- $result = Database::get()->query($sql, "i", $this->id);
-
- $posts = array();
-
- foreach ($result as $row) {
- $post = new Post($row['post_id']);
- if ($post->has_value())
- array_push($posts, $post);
- }
-
- return $posts;
- }
-
- public function get_latest_post(): Post
- {
- $sql = "SELECT post_id FROM posts WHERE post_thread = ? ORDER BY post_date_created DESC LIMIT 1";
- $result = Database::get()->query($sql, "i", $this->id);
- return new Post($result[0]['post_id']);
- }
-}
+<?php
+include_once './includes/Database.php';
+include_once './includes/Session.php';
+include_once 'Category.php';
+include_once 'User.php';
+include_once 'Post.php';
+
+class Thread
+{
+ public $id;
+ public $subject;
+ public $date_created = 0;
+ public $date_lastpost = 0;
+ public $category;
+ public $author;
+
+ private $has_value = false;
+
+ function __construct($id)
+ {
+ $sql = "SELECT thread_subject, thread_date_created, thread_date_lastpost, thread_category, thread_author FROM threads WHERE thread_id = ?;";
+ $result = Database::get()->query($sql, "i", $id);
+
+ if (empty($result)) {
+ return;
+ }
+
+ $this->id = $id;
+ $this->subject = $result[0]['thread_subject'];
+ $this->date_created = $result[0]['thread_date_created'];
+ $this->date_lastpost = $result[0]['thread_date_lastpost'];
+ $this->category = new Category($result[0]['thread_category']);
+
+ $this->author = new User();
+ $this->author->get_by_id($result[0]['thread_author']);
+
+ $this->has_value = true;
+ }
+
+ public static function create($subject, $category): int
+ {
+ if (!Session::get()->is_signed_in()) {
+ trigger_error('You must be signed in to create a thread');
+ return 0;
+ }
+
+ $user = Session::get()->get_current_user();
+
+ // Insert the new thread into the database
+ $sql = "INSERT INTO threads(thread_subject, thread_date_created, thread_date_lastpost, thread_category, thread_author) VALUES (?, CONVERT_TZ(NOW(), 'SYSTEM', '+00:00'), CONVERT_TZ(NOW(), 'SYSTEM', '+00:00'), ?, ?);";
+ Database::get()->query($sql, "sii", $subject, $category, $user->id);
+
+ // Get the ID of the thread we just created
+ $thread_id = Database::get()->get_last_id();
+
+ // Increment the category's thread count
+ $sql = "UPDATE categories SET `cat_thread_count` = `cat_thread_count` + '1' WHERE cat_id = ?;";
+ Database::get()->query($sql, "i", $category);
+
+ return $thread_id;
+ }
+
+ public static function delete($thread)
+ {
+ // User must be signed in
+ if (!Session::get()->is_signed_in()) {
+ trigger_error('You must be signed in to delete a thread.');
+ return;
+ }
+
+ // User must be a moderator to delete a thread
+ $current_user = Session::get()->get_current_user();
+ if ($current_user->level != USER_LEVEL_MODERATOR) {
+ trigger_error("You must be a moderator to delete this post.");
+ return;
+ }
+
+ // Delete the thread from the database
+ Database::get()->query("DELETE FROM threads WHERE thread_id = ?", "i", $thread->id);
+
+ // Decrement the thread count of the category
+ Database::get()->query("UPDATE categories SET `cat_thread_count` = `cat_thread_count` - '1' WHERE cat_id = ?", "i", $thread->category->id);
+ }
+
+ public function has_value(): bool
+ {
+ return $this->has_value;
+ }
+
+ public static function get_all(): array
+ {
+ $sql = "SELECT thread_id FROM threads";
+ $result = Database::get()->query($sql);
+
+ $threads = array();
+
+ foreach ($result as $row) {
+ $thread = new Thread($row['thread_id']);
+ if ($thread->has_value())
+ array_push($threads, $thread);
+ }
+
+ return $threads;
+ }
+
+ public static function get_latest(): array
+ {
+ $sql = "SELECT thread_id FROM threads ORDER BY thread_date_lastpost DESC LIMIT 10";
+ $result = Database::get()->query($sql);
+
+ $threads = array();
+
+ foreach ($result as $row) {
+ $thread = new Thread($row['thread_id']);
+ if ($thread->has_value())
+ array_push($threads, $thread);
+ }
+
+ return $threads;
+ }
+
+ public function get_posts(): array
+ {
+ $sql = "SELECT post_id FROM posts WHERE post_thread = ?";
+ $result = Database::get()->query($sql, "i", $this->id);
+
+ $posts = array();
+
+ foreach ($result as $row) {
+ $post = new Post($row['post_id']);
+ if ($post->has_value())
+ array_push($posts, $post);
+ }
+
+ return $posts;
+ }
+
+ public function get_latest_post(): Post
+ {
+ $sql = "SELECT post_id FROM posts WHERE post_thread = ? ORDER BY post_date_created DESC LIMIT 1";
+ $result = Database::get()->query($sql, "i", $this->id);
+ return new Post($result[0]['post_id']);
+ }
+}
diff --git a/includes/model/User.php b/includes/model/User.php
index 7d3c1e4..ba475c7 100755
--- a/includes/model/User.php
+++ b/includes/model/User.php
@@ -51,8 +51,8 @@ class User
$this->has_value = true;
}
- public function has_value()
- {
+ public function has_value(): bool
+ {
return $this->has_value;
}
diff --git a/includes/templates/404.php b/includes/templates/404.php
index 8815b91..db1171d 100755
--- a/includes/templates/404.php
+++ b/includes/templates/404.php
@@ -1,8 +1,8 @@
<!DOCTYPE html>
-<html>
+<html lang="en">
<head>
<title>cflip.net forum</title>
- <link rel="stylesheet" href="styles/style.css">
+ <link rel="stylesheet" href="/styles/style.css">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
diff --git a/includes/templates/head.php b/includes/templates/head.php
index d7c5758..07b6e80 100755
--- a/includes/templates/head.php
+++ b/includes/templates/head.php
@@ -1,4 +1,4 @@
-<link rel="stylesheet" href="styles/style.css">
-<link rel="icon" href="img/favicon.png">
+<link rel="stylesheet" href="/styles/style.css">
+<link rel="icon" href="/img/favicon.png">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> \ No newline at end of file
diff --git a/includes/templates/header.php b/includes/templates/header.php
index 45ec7e6..8187cb8 100755
--- a/includes/templates/header.php
+++ b/includes/templates/header.php
@@ -10,9 +10,9 @@
if (Session::get()->is_signed_in()) {
$user = Session::get()->get_current_user();
- echo '[<a href="viewuser.php?id=' . $user->id . '">' . $user->name . '\'s Profile</a>] [<a href="signout.php">Log out</a>]';
+ echo '[<a href="/viewuser.php?id=' . $user->id . '">' . $user->name . '\'s Profile</a>] [<a href="signout.php">Log out</a>]';
} else {
- echo '[<a href="signin.php">Sign in</a>] or [<a href="register.php">Register an account</a>]';
+ echo '[<a href="/signin.php">Sign in</a>] or [<a href="/register.php">Register an account</a>]';
}
?>
</span>
diff --git a/index.php b/index.php
index 3b3f21b..0c8409c 100755
--- a/index.php
+++ b/index.php
@@ -16,7 +16,7 @@
<?php foreach (Category::get_all_categories() as $category): ?>
<tr>
<td>
- <a style="font-size: larger;" href="viewcategory.php?id=<?= $category->id ?>"><?= $category->name ?></a></h4>
+ <a style="font-size: larger;" href="viewcategory.php?id=<?= $category->id ?>"><?= $category->name ?></a>
<br><?= $category->description ?>
</td>
<?php $latest_thread = $category->get_latest_thread(); if ($latest_thread->has_value()): ?>
diff --git a/moderate.php b/moderate.php
index 5a181ac..21951f6 100755
--- a/moderate.php
+++ b/moderate.php
@@ -34,8 +34,6 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (strcasecmp($action, "delete") == 0) $post->delete();
}
}
-} else {
-
}
?>
<!DOCTYPE html>
@@ -46,7 +44,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
</head>
<body>
<?php include_once 'includes/templates/header.php'; ?>
-<?php if (Session::get()->is_signed_in() and $user->level == USER_LEVEL_MODERATOR): ?>
+<?php if (Session::get()->is_signed_in() and Session::get()->get_current_user()->level == USER_LEVEL_MODERATOR): ?>
<?php if ($is_post): ?>
<h2>Moderate post</h2>
<?php echo $post->get_content(); ?>
diff --git a/signin.php b/signin.php
index 195895a..c2ee5a6 100755
--- a/signin.php
+++ b/signin.php
@@ -18,12 +18,11 @@
<?php
include_once 'includes/error.php';
-function validate($data)
+function validate($data): string
{
$data = trim($data);
$data = stripslashes($data);
- $data = htmlspecialchars($data);
- return $data;
+ return htmlspecialchars($data);
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
diff --git a/styles/style.css b/styles/style.css
index f849fc2..ea2e15b 100755
--- a/styles/style.css
+++ b/styles/style.css
@@ -1,63 +1,16 @@
-body {
- font-family: Arial, sans-serif;
- font-size: 10pt;
- margin: 24px 10%;
- background-image: linear-gradient(#eff, #fff);
- background-repeat: no-repeat;
-}
-
-@media only screen and (max-width: 600px) {
- body {
- margin: 24px 6px;
- }
-
- .image-embed {
- width: 100%;
- }
-}
-
a {
- color: seagreen;
+ color: blue;
}
a:hover {
- color: #333;
text-decoration: none;
}
-small {
- font-size: 8pt;
- color: #333;
-}
-
table {
width: 100%;
- border-collapse: collapse;
- border: 1px solid seagreen;
-}
-
-th, .header {
- background-color: seagreen;
- color: #eee;
- padding: 4px;
-}
-
-th, .header a {
- color: #eee;
- font-weight: bold;
-}
-
-td {
- border: 1px solid seagreen;
- margin: none;
- padding: 4px;
}
-tr:nth-child(even) { background: #eee; }
-tr:nth-child(odd) { background: #fff; }
-
blockquote {
- background-color: #ffd;
margin: 8px 40px 14px 18px;
padding: 12px;
border: 1px solid #aa6;
@@ -67,45 +20,7 @@ blockquote {
textarea {
width: 100%;
height: 200px;
- margin-right: 0px;
+ margin-right: 0;
overflow: scroll;
resize: none;
}
-
-.header > small {
- color: #dde;
-}
-
-.post-content {
- overflow: auto;
- background-color: white;
- padding: 12px 8px;
- border: 1px solid seagreen;
- display: block;
-}
-
-.image-embed {
- max-height: 80vh;
-}
-
-.success {
- background-color: #efe;
- margin: 8px 40px 14px 18px;
- padding: 12px;
- border: 1px solid #aea;
- overflow: hidden;
- border-radius: 5px;
-}
-
-.error {
- background-color: #fee;
- margin: 8px 40px 14px 18px;
- padding: 12px;
- border: 1px solid #eaa;
- overflow: hidden;
- border-radius: 5px;
-}
-
-.info {
- color: #666;
-} \ No newline at end of file
diff --git a/viewthread.php b/viewthread.php
index 85f1813..06debe8 100755
--- a/viewthread.php
+++ b/viewthread.php
@@ -50,7 +50,7 @@ include_once 'includes/error.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (!Session::get()->is_signed_in()) {
- trigger_error('You must be <a href="signin.php">signed in</a> to reply to this thread.', E_USER_NOTICE);
+ trigger_error('You must be <a href="signin.php">signed in</a> to reply to this thread.');
return;
}