r20151116

Signed-off-by: Flashwave <me@flash.moe>
This commit is contained in:
Pachira 2015-11-16 23:05:45 +01:00
parent 1eb2f04f10
commit bc36d74bba
12 changed files with 116 additions and 43 deletions

View file

@ -78,7 +78,7 @@ class Forum
public function getThreads() public function getThreads()
{ {
// Get all rows with the forum id for this forum // Get all rows with the forum id for this forum
$threadRows = Database::fetch('topics', true, ['forum_id' => [$this->id, '=']]); $threadRows = Database::fetch('topics', true, ['forum_id' => [$this->id, '=']], ['topic_last_reply', true]);
// Create a storage array // Create a storage array
$threads = []; $threads = [];
@ -129,4 +129,18 @@ class Forum
{ {
return Database::count('posts', ['forum_id' => [$this->id, '=']])[0]; return Database::count('posts', ['forum_id' => [$this->id, '=']])[0];
} }
// Read status
public function unread($user)
{
// Check each thread
foreach ($this->threads as $thread) {
if ($thread->unread($user)) {
return true;
}
}
// Return false if negative
return false;
}
} }

View file

@ -266,10 +266,8 @@ class Forums
// Switch between modes // Switch between modes
switch ($mode) { switch ($mode) {
case 1: case 1:
return Main::bbParse($text);
case 2: case 2:
return Main::mdParse($text); return Main::bbParse($text);
case 0: case 0:
default: default:
@ -340,6 +338,16 @@ class Forums
'post_id' => [Database::lastInsertID(), '='], 'post_id' => [Database::lastInsertID(), '='],
]); ]);
// Update the topic with the last details
Database::update('topics', [
[
'topic_last_reply' => time(),
],
[
'topic_id' => [$getPost['topic_id'], '='],
],
]);
// Return success // Return success
return [1, 'SUCCESS', $getPost['forum_id'], $getPost['topic_id'], $getPost['post_id']]; return [1, 'SUCCESS', $getPost['forum_id'], $getPost['topic_id'], $getPost['post_id']];
} }

View file

@ -53,7 +53,8 @@ class Post
} }
// Parse the markup // Parse the markup
$this->parsed = Forums::parseMarkUp($this->text, $this->parse, $this->emotes); $this->parsed = $this->parse ? Main::bbParse($this->text) : $this->text;
$this->parsed = $this->emotes ? Main::parseEmotes($this->parsed) : $this->parsed;
} }
// Time elapsed since creation // Time elapsed since creation

View file

@ -91,4 +91,65 @@ class Thread
{ {
return Main::timeElapsed($this->statusChange); return Main::timeElapsed($this->statusChange);
} }
// Read status
public function unread($user)
{
// Attempt to get track row from the database
$track = Database::fetch('topics_track', false, ['user_id' => [$user, '='], 'topic_id' => [$this->id, '=']]);
// If nothing was returned it's obvious that the status is unread
if (!$track) {
return true;
}
// Check if the last time the user has been here is less than the creation timestamp of the latest post
if ($track['mark_time'] < $this->lastPost->time) {
return true;
}
// Else just return false meaning everything is read
return false;
}
// Update read status
public function trackUpdate($user)
{
// Check if we already have a track record
$track = Database::fetch('topics_track', false, ['user_id' => [$user, '='], 'topic_id' => [$this->id, '='], 'forum_id' => [$this->forum, '=']]);
// If so update it
if ($track) {
Database::update('topics_track', [
[
'mark_time' => time(),
],
[
'user_id' => [$user, '='],
'topic_id' => [$this->id, '='],
],
]);
} else {
// If not create a new record
Database::insert('topics_track', [
'user_id' => $user,
'topic_id' => $this->id,
'forum_id' => $this->forum,
'mark_time' => time(),
]);
}
}
// Update views
public function viewsUpdate()
{
Database::update('topics', [
[
'topic_views' => $this->views + 1,
],
[
'topic_id' => [$this->id, '='],
],
]);
}
} }

View file

@ -8,7 +8,7 @@
namespace Sakura; namespace Sakura;
// Define Sakura version // Define Sakura version
define('SAKURA_VERSION', '20151115'); define('SAKURA_VERSION', '20151116');
define('SAKURA_VLABEL', 'Eminence'); define('SAKURA_VLABEL', 'Eminence');
define('SAKURA_COLOUR', '#6C3082'); define('SAKURA_COLOUR', '#6C3082');
define('SAKURA_STABLE', false); define('SAKURA_STABLE', false);

View file

@ -2,13 +2,19 @@
{% set paginationPage = get.page|default(1) %} {% set paginationPage = get.page|default(1) %}
<div class="pagination{% if paginationClass %} {{ paginationClass }}{% endif %}"> <div class="pagination{% if paginationClass %} {{ paginationClass }}{% endif %}">
{% if paginationPage > 1 %} {% if paginationPages|length > 1 %}
<a href="{{ paginationUrl }}{{ paginationSeparator }}page={{ paginationPage - 1 }}"><span class="fa fa-step-backward"></span></a> {% if paginationPage > 1 %}
{% endif %} <a href="{{ paginationUrl }}{{ paginationSeparator }}page=1"><span class="fa fa-fast-backward"></span></a>
{% for id,page in paginationPages %} <a href="{{ paginationUrl }}{{ paginationSeparator }}page={{ paginationPage - 1 }}"><span class="fa fa-step-backward"></span></a>
<a href="{{ paginationUrl }}{{ paginationSeparator }}page={{ id + 1 }}"{% if id == paginationPage - 1 %} class="current"{% endif %}>{{ id + 1 }}</a> {% endif %}
{% endfor %} {% for id,page in paginationPages %}
{% if paginationPage < paginationPages|length %} {% if (id + 1) > (paginationPage - 3) and (id + 1) < (paginationPage + 3) %}
<a href="{{ paginationUrl }}{{ paginationSeparator }}page={{ paginationPage + 1 }}"><span class="fa fa-step-forward"></span></a> <a href="{{ paginationUrl }}{{ paginationSeparator }}page={{ id + 1 }}"{% if id == paginationPage - 1 %} class="current"{% endif %}>{{ id + 1 }}</a>
{% endif %}
{% endfor %}
{% if paginationPage < paginationPages|length %}
<a href="{{ paginationUrl }}{{ paginationSeparator }}page={{ paginationPage + 1 }}"><span class="fa fa-step-forward"></span></a>
<a href="{{ paginationUrl }}{{ paginationSeparator }}page={{ paginationPages|length }}"><span class="fa fa-fast-forward"></span></a>
{% endif %}
{% endif %} {% endif %}
</div> </div>

View file

@ -1,5 +1,5 @@
<div class="forumForum"> <div class="forumForum">
<div class="forumIcon read fa fa-3x {% if forum.icon %}{{ forum.icon }}{% else %}{% if forum.type == 2 %}fa-chevron-circle-right{% elseif forum.type == 1 %}fa-folder{% else %}fa-comments{% endif %}{% endif %}"></div> <div class="forumIcon {% if forum.unread(user.id) %}unread {% endif %}fa fa-3x {% if forum.icon %}{{ forum.icon }}{% else %}{% if forum.type == 2 %}fa-chevron-circle-right{% elseif forum.type == 1 %}fa-folder{% else %}fa-comments{% endif %}{% endif %}"></div>
<div class="forumTitle"> <div class="forumTitle">
<div class="name"><a href="{% if forum.type == 2 %}{{ forum.link }}{% else %}{{ urls.format('FORUM_SUB', [forum.id]) }}{% endif %}" class="default">{{ forum.name }}</a></div> <div class="name"><a href="{% if forum.type == 2 %}{{ forum.link }}{% else %}{{ urls.format('FORUM_SUB', [forum.id]) }}{% endif %}" class="default">{{ forum.name }}</a></div>
<div class="desc"> <div class="desc">

View file

@ -41,14 +41,9 @@
<div> <div>
<input type="checkbox" id="enableEmotes" checked="checked" /> <label for="enableEmotes">Parse emoticons</label> <input type="checkbox" id="enableEmotes" checked="checked" /> <label for="enableEmotes">Parse emoticons</label>
</div> </div>
</div> <div>
<div> <input type="checkbox" id="enableBBcode" checked="checked" /> <label for="enableBBcode">Parse BBcodes</label>
<label for="parseMode">Parsing Mode:</label> </div>
<select id="parseMode" name="parseMode">
<option value="0">None</option>
<option value="1" selected="selected">BBCode</option>
<option value="2">Markdown</option>
</select>
</div> </div>
<div class="clear"></div> <div class="clear"></div>
</div> </div>

View file

@ -1,5 +1,5 @@
<tr> <tr>
<td class="topicIcon read"> <td class="topicIcon{% if thread.unread(user.id) %} unread{% endif %}">
<div class="fa fa-2x fa-{% if thread.status == 1 %}lock{% elseif thread.type == 2 %}exclamation{% elseif thread.type == 1 %}thumb-tack{% else %}navicon{% endif %}"></div> <div class="fa fa-2x fa-{% if thread.status == 1 %}lock{% elseif thread.type == 2 %}exclamation{% elseif thread.type == 1 %}thumb-tack{% else %}navicon{% endif %}"></div>
</td> </td>
<td class="topicTitle"> <td class="topicTitle">

View file

@ -1902,9 +1902,6 @@ textarea.inputStyling {
.forum .topicList tbody .topicIcon { .forum .topicList tbody .topicIcon {
width: 40px; width: 40px;
text-align: center; text-align: center;
}
.forum .topicList tbody .topicIcon.read {
color: #444; color: #444;
text-shadow: 0 0 5px #444; text-shadow: 0 0 5px #444;
} }

View file

@ -172,23 +172,8 @@ if ($mode != 'f') {
// Check if a post is being made // Check if a post is being made
if (isset($_POST['post'])) { if (isset($_POST['post'])) {
// Set post mode
switch ($_POST['parseMode']) {
// BBcode
case '1':
$parse = '1';
break;
// Markdown
case '2':
$parse = '2';
break;
// Raw
default:
$parse = '0';
}
// Attempt to make the post // Attempt to make the post
$makePost = Forums::createPost($currentUser->id(), $_POST['subject'], $_POST['text'], $forumId, $topicId, $parse, 1, 1); $makePost = Forums::createPost($currentUser->id(), $_POST['subject'], $_POST['text'], $forumId, $topicId, 1, 1, 1);
// Add page specific things // Add page specific things
$renderData['page'] = [ $renderData['page'] = [

View file

@ -40,6 +40,12 @@ if (!$thread) {
exit; exit;
} }
// Update the tracking status
$thread->trackUpdate($currentUser->id());
// Update views
$thread->viewsUpdate();
// Set additional render data // Set additional render data
$renderData = array_merge($renderData, [ $renderData = array_merge($renderData, [
'thread' => $thread, 'thread' => $thread,