diff --git a/_sakura/changelog.json b/_sakura/changelog.json index 2c67551..614f3e8 100644 --- a/_sakura/changelog.json +++ b/_sakura/changelog.json @@ -2820,6 +2820,22 @@ "user": "Flashwave" } + ], + + "20150918": [ + + "eminence", + { + "type": "UPD", + "change": "Changed report flag to an exclamation thing.", + "user": "Flashwave" + }, + { + "type": "UPD", + "change": "Added more comments stuff.", + "user": "Flashwave" + } + ] } diff --git a/_sakura/components/Comments.php b/_sakura/components/Comments.php index cef71ea..dfd4fd2 100644 --- a/_sakura/components/Comments.php +++ b/_sakura/components/Comments.php @@ -7,9 +7,71 @@ namespace Sakura; class Comments { + public $comments = []; // Array containing comments + private $commenters = []; // Array containing User objects + public $category; // Comment category + public $count = 0; // Amount of comments + // Constructor - public function ___construct() + public function __construct($category) { - // + // Set category + $this->category = $category; + + // Get the comments and assign them to $comments + $comments = Database::fetch( + 'comments', + true, + [ + 'comment_category' => [$this->category, '='], + 'comment_reply_to' => ['0', '='], + ], + ['comment_id', true] + ); + + // Feed them into the sorter + $this->comments = $this->sortComments($comments); + + } + + // Sorting + public function sortComments($comments) + { + + // Create storage array + $layer = []; + + // Sort comments + foreach ($comments as $comment) { + // Check if we already have an object for this user + if (!array_key_exists($comment['comment_poster'], $this->commenters)) { + // Create new object + $this->commenters[$comment['comment_poster']] = new User($comment['comment_poster']); + } + + // Attach the poster + $comment['comment_poster'] = $this->commenters[$comment['comment_poster']]; + + // Add post to posts array + $layer[$comment['comment_id']] = $comment; + + // Up the comment count + $this->count += 1; + + // Attempt to get replies from the database + $replies = Database::fetch('comments', true, [ + 'comment_category' => [$this->category, '='], + 'comment_reply_to' => [$comment['comment_id'], '='], + ]); + + // Check if this was a reply to something + if ($replies) { + // Save the replies + $layer[$comment['comment_id']]['comment_replies'] = $this->sortComments($replies); + } + } + + return $layer; + } } diff --git a/_sakura/components/News.php b/_sakura/components/News.php index 89d68c1..08f6429 100644 --- a/_sakura/components/News.php +++ b/_sakura/components/News.php @@ -11,7 +11,7 @@ class News private $posters = []; // Posters array (so we don't create a new user object every time) // Initialise the news object - public function __construct($category, $comments = true) + public function __construct($category) { // Get the news posts and assign them to $posts @@ -31,9 +31,13 @@ class News // Attach the poster $post['poster'] = $this->posters[$post['uid']]; + // Load comments + $post['comments'] = $this->comments = new Comments('news-' . $category . '-' . $post['id']); + // Add post to posts array $this->posts[$post['id']] = $post; } + } // Get the amount of posts diff --git a/_sakura/components/Session.php b/_sakura/components/Session.php index 7045745..1acecc0 100644 --- a/_sakura/components/Session.php +++ b/_sakura/components/Session.php @@ -12,7 +12,7 @@ class Session public $sessionId; // Initialise new session - public function ___construct() + public function __construct() { // Check if a PHP session was already started and if not start one diff --git a/_sakura/components/Urls.php b/_sakura/components/Urls.php index a23ac91..19da643 100644 --- a/_sakura/components/Urls.php +++ b/_sakura/components/Urls.php @@ -230,6 +230,24 @@ class Urls '/manage/%s/%s', ], + // Comments urls + 'COMMENT_POST' => [ + '/settings.php?comment-action=true', + '/comments', + ], + 'COMMENT_LIKE' => [ + '/settings.php?comment-action=true&id=%u&mode=like&session=%s', + '/comments?id=%u&mode=like&session=%s', + ], + 'COMMENT_DISLIKE' => [ + '/settings.php?comment-action=true&id=%u&mode=dislike&session=%s', + '/comments?id=%u&mode=dislike&session=%s', + ], + 'COMMENT_DELETE' => [ + '/settings.php?comment-action=true&id=%u&mode=delete&session=%s', + '/comments?id=%u&mode=delete&session=%s', + ], + ]; // Get a formatted url diff --git a/_sakura/sakura.php b/_sakura/sakura.php index f090d2d..c6443a7 100644 --- a/_sakura/sakura.php +++ b/_sakura/sakura.php @@ -8,7 +8,7 @@ namespace Sakura; // Define Sakura version -define('SAKURA_VERSION', '20150916'); +define('SAKURA_VERSION', '20150918'); define('SAKURA_VLABEL', 'Eminence'); define('SAKURA_COLOUR', '#6C3082'); define('SAKURA_STABLE', false); diff --git a/_sakura/templates/yuuno/elements/comment.tpl b/_sakura/templates/yuuno/elements/comment.tpl new file mode 100644 index 0000000..bd97cc8 --- /dev/null +++ b/_sakura/templates/yuuno/elements/comment.tpl @@ -0,0 +1,28 @@ +
+- Report
+ - Delete
+ - Reply
+ - {{ comment.comment_likes }}
+ - {{ comment.comment_dislikes }}
+
+ +