r20151114

Signed-off-by: Flashwave <me@flash.moe>
This commit is contained in:
Pachira 2015-11-14 00:11:55 +01:00
parent 79c761c6e3
commit d1ef9d924a
5 changed files with 182 additions and 31 deletions

View file

@ -11,4 +11,73 @@ namespace Sakura;
*/
class Forum
{
// Variables
public $id = 0;
public $name = "Forum";
public $description = "";
public $link = "";
public $category = 0;
public $type = 0;
public $icon = "";
public $firstReply = [];
public $lastReply = [];
// Constructor
public function __construct($forumId)
{
// Get the row from the database
$forumRow = Database::fetch('forums', false, ['forum_id' => [$forumId, '=']]);
// Populate the variables
if (!$forumRow) {
$this->id = $forumRow['forum_id'];
$this->name = $forumRow['forum_name'];
$this->description = $forumRow['forum_desc'];
$this->link = $forumRow['forum_link'];
$this->category = $forumRow['forum_category'];
$this->type = $forumRow['forum_type'];
$this->icon = $forumRow['forum_icon'];
} else {
// Else just set the ID to $forumId and imitate an blank forum
$this->id = $forumId;
}
}
// Subforums
public function forums()
{
// Get all rows with the category id set to the forum id
$forumRows = Database::fetch('forums', true, ['forum_category' => [$this->id, '=']]);
// Get a storage array
$forums = [];
// Create new objects for each forum
foreach ($forumRows as $forum) {
$forums[$forum['forum_id']] = new Forum($forum['forum_id']);
}
// Return the forum objects
return $forums;
}
// Last post
public function lastPost()
{
// Return a post
$postRow = Database::fetch('posts', false, ['forum_id' => [$this->id, '=']], ['post_id', true]);
}
// Thread count
public function threadCount()
{
return Database::count('topics', ['forum_id', [$this->id, '=']])[0];
}
// Post count
public function postCount()
{
return Database::count('posts', ['forum_id', [$this->id, '=']])[0];
}
}

View file

@ -396,16 +396,6 @@ class Forums
'post_id' => [Database::lastInsertID(), '='],
]);
// Update the topic with the last details
Database::update('topics', [
[
'topic_last_reply' => $getPost['post_id'],
],
[
'topic_id' => [$getPost['topic_id'], '='],
],
]);
// Return success
return [1, 'SUCCESS', $getPost['forum_id'], $getPost['topic_id'], $getPost['post_id']];
}

View file

@ -0,0 +1,54 @@
<?php
/*
* Post class
*/
namespace Sakura;
/**
* Class Post
* @package Sakura
*/
class Post
{
// Variables
public $id = 0;
public $thread = 0;
public $forum = 0;
public $poster = [];
public $ip = "";
public $time = 0;
public $parse = 0;
public $signature = 0;
public $emotes = 0;
public $subject = "";
public $text = "";
public $editTime = 0;
public $editReason = "";
public $editUser = [];
// Constructor
public function __construct($postId)
{
// Attempt to get the database row
$postRow = Database::fetch('posts', false, ['post_id' => [$postId, '=']]);
// Assign data if a row was returned
if ($postRow) {
$this->id = $postRow['post_id'];
$this->thread = $postRow['topic_id'];
$this->forum = $postRow['forum_id'];
$this->poster = new User($postRow['poster_id']);
$this->ip = $postRow['poster_ip'];
$this->time = $postRow['post_time'];
$this->parse = $postRow['post_parse'];
$this->signature = $postRow['post_signature'];
$this->emotes = $postRow['post_emotes'];
$this->subject = $postRow['post_subject'];
$this->text = $postRow['post_text'];
$this->editTime = $postRow['post_edit_time'];
$this->editReason = $postRow['post_edit_reason'];
$this->editUser = new User($postRow['post_edit_user']);
}
}
}

View file

@ -0,0 +1,52 @@
<?php
/*
* Thread class
*/
namespace Sakura;
/**
* Class Thread
* @package Sakura
*/
class Thread
{
// Variables
public $id = 0;
public $forum = 0;
public $hidden = 0;
public $title = "";
public $time = 0;
public $timeLimit = 0;
public $views = 0;
public $status = 0;
public $statusChange = 0;
public $type = 0;
// Constructor
public function __construct($threadId)
{
// Attempt to get the database row
$threadRow = Database::fetch('topics', false, ['topic_id' => [$threadId, '=']]);
// Assign data if a row was returned
if ($threadRow) {
$this->id = $threadRow['topic_id'];
$this->forum = $threadRow['forum_id'];
$this->hidden = $threadRow['topic_hidden'];
$this->title = $threadRow['topic_title'];
$this->time = $threadRow['topic_time'];
$this->timeLimit = $threadRow['topic_time_limit'];
$this->views = $threadRow['topic_views'];
$this->status = $threadRow['topic_status'];
$this->statusChange = $threadRow['topic_status_change'];
$this->type = $threadRow['topic_type'];
}
}
// Reply count
public function replyCount()
{
return Database::count('posts', ['topic_id', [$this->id, '=']])[0];
}
}

View file

@ -8,7 +8,7 @@
namespace Sakura;
// Define Sakura version
define('SAKURA_VERSION', '20151112');
define('SAKURA_VERSION', '20151113');
define('SAKURA_VLABEL', 'Eminence');
define('SAKURA_COLOUR', '#6C3082');
define('SAKURA_STABLE', false);
@ -27,27 +27,13 @@ if (version_compare(phpversion(), '5.4.0', '<')) {
die('<h3>Sakura requires at least PHP 5.4.0, please upgrade to a newer PHP version.</h3>');
}
// Include libraries
// Include third-party libraries
require_once ROOT . '_sakura/vendor/autoload.php';
require_once ROOT . '_sakura/components/Main.php';
require_once ROOT . '_sakura/components/Hashing.php';
require_once ROOT . '_sakura/components/Config.php';
require_once ROOT . '_sakura/components/Database.php';
require_once ROOT . '_sakura/components/Urls.php';
require_once ROOT . '_sakura/components/Template.php';
require_once ROOT . '_sakura/components/Permissions.php';
require_once ROOT . '_sakura/components/Session.php';
require_once ROOT . '_sakura/components/User.php';
require_once ROOT . '_sakura/components/Rank.php';
require_once ROOT . '_sakura/components/Users.php';
require_once ROOT . '_sakura/components/Forums.php';
require_once ROOT . '_sakura/components/News.php';
require_once ROOT . '_sakura/components/Comments.php';
require_once ROOT . '_sakura/components/Manage.php';
require_once ROOT . '_sakura/components/Bans.php';
require_once ROOT . '_sakura/components/Whois.php';
require_once ROOT . '_sakura/components/Payments.php';
require_once ROOT . '_sakura/components/Trick.php';
// Include components
foreach (glob(ROOT . '_sakura/components/*.php') as $component) {
require_once $component;
}
// Include database extensions
foreach (glob(ROOT . '_sakura/components/database/*.php') as $driver) {