2015-11-13 23:11:55 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* Post class
|
|
|
|
*/
|
|
|
|
|
2015-11-22 22:10:23 +00:00
|
|
|
namespace Sakura\Forum;
|
2015-11-17 19:30:34 +00:00
|
|
|
|
|
|
|
use Sakura\Main;
|
|
|
|
use Sakura\Database;
|
|
|
|
use Sakura\User;
|
2015-11-25 20:18:52 +00:00
|
|
|
use Sakura\BBcode\BBcode;
|
2015-11-13 23:11:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 = "";
|
2015-11-15 14:29:26 +00:00
|
|
|
public $parsed = "";
|
2015-11-13 23:11:55 +00:00
|
|
|
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']);
|
|
|
|
}
|
2015-11-15 14:29:26 +00:00
|
|
|
|
|
|
|
// Parse the markup
|
2015-11-16 22:05:45 +00:00
|
|
|
$this->parsed = $this->parse ? Main::bbParse($this->text) : $this->text;
|
|
|
|
$this->parsed = $this->emotes ? Main::parseEmotes($this->parsed) : $this->parsed;
|
2015-11-15 14:29:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Time elapsed since creation
|
|
|
|
public function timeElapsed()
|
|
|
|
{
|
|
|
|
return Main::timeElapsed($this->time);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Time elapsed since last edit
|
|
|
|
public function editTimeElapsed()
|
|
|
|
{
|
|
|
|
return Main::timeElapsed($this->editTime);
|
2015-11-13 23:11:55 +00:00
|
|
|
}
|
|
|
|
}
|