Added direct post linking back.

This commit is contained in:
flash 2016-03-20 17:37:59 +01:00
parent 9279173528
commit f5483f4269
10 changed files with 131 additions and 15 deletions

View file

@ -7,9 +7,9 @@
namespace Sakura;
use JBBCode\Parser;
use JBBCode\DefaultCodeDefinitionSet;
use JBBCode\CodeDefinitionBuilder;
use JBBCode\DefaultCodeDefinitionSet;
use JBBCode\Parser;
/**
* Sakura wrapper for JBBCode.
@ -102,9 +102,6 @@ class BBcode
// Add special definitions (PHP files MUST have the same name as the definition class
foreach (glob(ROOT . 'libraries/BBcodeDefinitions/*.php') as $ext) {
// Include the class
require_once $ext;
// Clean the file path
$ext = str_replace(ROOT . 'libraries/', '', $ext);
$ext = str_replace('.php', '', $ext);

View file

@ -10,6 +10,7 @@ namespace Sakura\Controllers;
use Sakura\Config;
use Sakura\DB;
use Sakura\Forum\Forum;
use Sakura\Forum\Post;
use Sakura\Forum\Thread;
use Sakura\Perms\Forum as ForumPerms;
use Sakura\Router;
@ -355,4 +356,56 @@ class ForumController extends Controller
// Print page contents
return Template::render('global/information');
}
public function post($id = 0)
{
global $currentUser;
// Attempt to get the post
$post = new Post($id);
// And attempt to get the forum
$thread = new Thread($post->thread);
// And attempt to get the forum
$forum = new Forum($thread->forum);
// Check if the forum exists
if ($post->id == 0 || $thread->id == 0 || !$forum->permission(ForumPerms::VIEW, $currentUser->id)) {
// Set render data
Template::vars([
'page' => [
'message' => 'This post doesn\'t exist or you don\'t have access to it!',
'redirect' => Router::route('forums.index'),
],
]);
// Print page contents
return Template::render('global/information');
}
// Generate link
$threadLink = Router::route('forums.thread', $thread->id);
// Get all post ids from the database
$postIds = DB::table('posts')
->where('topic_id', $thread->id)
->get(['post_id']);
$postIds = array_column($postIds, 'post_id');
// Find in array
$postAt = ceil(array_search($post->id, $postIds) / 10);
// Only append the page variable if it's more than 1
if ($postAt > 1) {
$threadLink .= "?page={$postAt}";
}
return header("Location: {$threadLink}#p{$post->id}");
}
protected function postingBase($title, $text, $forum, $thread = 0, $post = 0)
{
}
}

View file

@ -7,11 +7,11 @@
namespace Sakura\Forum;
use Sakura\DB;
use Sakura\User;
use Sakura\BBcode;
use Sakura\Config;
use Sakura\DB;
use Sakura\Net;
use Sakura\User;
/**
* Used to serve, create and update posts.
@ -116,7 +116,7 @@ class Post
$postRow = DB::table('posts')
->where('post_id', $postId)
->get();
// Assign data if a row was returned
if ($postRow) {
$postRow = $postRow[0];
@ -226,4 +226,11 @@ class Post
// Return a new post object
return new Post($this->id);
}
public function delete()
{
DB::table('posts')
->where('post_id', $this->id)
->delete();
}
}

View file

@ -229,8 +229,7 @@ if ($mode != 'f') {
exit;
// Return to previous page
} else {
// (haven't (re)implemented post linking yet)
header('Location: ' . $urls->format('FORUM_POST', [$_POST['post_id']]));
header('Location: ' . Router::route('forums.post', $_POST['post_id']));
exit;
}
}
@ -282,7 +281,7 @@ if (isset($_POST['post'])) {
// Add page specific things
$renderData['page'] = [
'redirect' => $post ? $urls->format('FORUM_POST', [$post->id]) . '#p' . $post->id : '',
'redirect' => $post ? Router::route('forums.post', $post->id) : '',
'message' => $post ? 'Made the post!' : 'Something is wrong with your post!',
'success' => $post ? 1 : 0,
];

View file

@ -33,16 +33,24 @@ Router::group(['prefix' => 'news'], function () {
// Forum
Router::group(['prefix' => 'forum'], function () {
// Post
Router::group(['prefix' => 'post'], function () {
Router::get('/{id:i}', 'ForumController@post', 'forums.post');
Router::get('/{id:i}/reply', 'ForumController@postReply', 'forums.post.reply');
});
// Thread
Router::group(['prefix' => 'thread'], function () {
Router::get('/{id:i}', 'ForumController@thread', 'forums.thread');
Router::post('/{id:i}/mod', 'ForumController@threadModerate', 'forums.thread.mod');
Router::post('/{id:i}/reply', 'ForumController@threadReply', 'forums.thread.reply');
});
// Forum
Router::get('/', 'ForumController@index', 'forums.index');
Router::get('/{id:i}', 'ForumController@forum', 'forums.forum');
Router::get('/{id:i}/mark', 'ForumController@markForumRead', 'forums.mark');
Router::get('/{id:i}/new', 'ForumController@newThread', 'forums.new');
});
// Members

View file

@ -8,7 +8,7 @@
namespace Sakura;
// Define Sakura version
define('SAKURA_VERSION', '20160319');
define('SAKURA_VERSION', '20160320');
// Define Sakura Path
define('ROOT', __DIR__ . '/');

View file

@ -24,7 +24,7 @@
<div>
{% if forum.lastPost.id %}
<a href="{{ route('forums.thread', forum.lastPost.thread) }}" class="default">{{ forum.lastPost.subject|slice(0, 30) }}{% if forum.lastPost.subject|length > 30 %}...{% endif %}</a><br />
<time>{{ forum.lastPost.time|date(sakura.dateFormat) }}</time> by {% if forum.lastPost.poster.id %}<a href="{{ route('user.profile', forum.lastPost.poster.id) }}" class="default" style="color: {{ forum.lastPost.poster.colour }}; text-shadow: 0 0 5px {% if forumlastPost.poster.colour != 'inherit' %}{{ forum.lastPost.poster.colour }}{% else %}#222{% endif %};">{{ forum.lastPost.poster.username }}</a>{% else %}[deleted user]{% endif %} <a href="{{ urls.format('FORUM_POST', [forum.lastPost.id]) }}#p{{ forum.lastPost.id }}" class="default fa fa-tag"></a>
<time>{{ forum.lastPost.time|date(sakura.dateFormat) }}</time> by {% if forum.lastPost.poster.id %}<a href="{{ route('user.profile', forum.lastPost.poster.id) }}" class="default" style="color: {{ forum.lastPost.poster.colour }}; text-shadow: 0 0 5px {% if forumlastPost.poster.colour != 'inherit' %}{{ forum.lastPost.poster.colour }}{% else %}#222{% endif %};">{{ forum.lastPost.poster.username }}</a>{% else %}[deleted user]{% endif %} <a href="{{ route('forums.post', forum.lastPost.id) }}" class="default fa fa-tag"></a>
{% else %}
There are no posts in this forum.<br />&nbsp;
{% endif %}

View file

@ -21,7 +21,7 @@
<a href="{{ route('user.profile', thread.lastPost.poster.id) }}" class="default" style="color: {{ thread.lastPost.poster.colour }}; text-shadow: 0 0 5px {% if thread.lastPost.poster.colour != 'inherit' %}{{ thread.lastPost.poster.colour }}{% else %}#222{% endif %};">{{ thread.lastPost.poster.username }}</a>
{% else %}
[deleted user]
{% endif %} <a href="{{ urls.format('FORUM_POST', [thread.lastPost.id]) }}#p{{ thread.lastPost.id }}" class="default fa fa-tag"></a><br />
{% endif %} <a href="{{ route('forums.post', thread.lastPost.id) }}" class="default fa fa-tag"></a><br />
<time>{{ thread.lastPost.time|date(sakura.dateFormat) }}</time>
</td>
</tr>

View file

@ -101,7 +101,7 @@
<a href="#p{{ post.id }}" class="clean">{{ post.subject|slice(0, 50) }}{% if post.subject|length > 50 %}...{% endif %}</a>
</div>
<div class="date">
#{{ post.id }} - <time>{{ post.time|date(sakura.dateFormat) }}</time>
<a href="{{ route('forums.post', post.id) }}" class="clean">#{{ post.id }} - <time>{{ post.time|date(sakura.dateFormat) }}</time></a>
</div>
<div class="clear"></div>
</div>

View file

@ -0,0 +1,52 @@
{% extends 'global/master.twig' %}
{% block title %}Reset Password{% endblock %}
{% block content %}
{% if sakura.lockAuth %}
<h1 class="stylised" style="line-height: 1.8em; text-align: center;">Resetting password is disabled because of security checkups!</h1>
{% else %}
<div class="loginPage">
<div class="passwordForm">
<div class="head">
Reset Password
</div>
<form method="post" action="{{ route('auth.resetpassword') }}" id="passwordForm">
<input type="hidden" name="session" value="{{ php.sessionid }}" />
{% if get.u is defined and get.k is defined %}
<input type="hidden" name="user" value="{{ get.u }}" />
<input type="hidden" name="key" value="{{ get.k }}" />
<div class="leftAlign">
<label for="forgotUserName">Password:</label>
</div>
<div class="centreAlign">
<input class="inputStyling" type="password" id="resetPassword" name="password" />
</div>
<div class="centreAlign">
<button class="inputStyling">Save Password</button>
</div>
{% else %}
<div class="leftAlign">
<label for="forgotUserName">Username:</label>
</div>
<div class="centreAlign">
<input class="inputStyling" type="text" id="forgotUserName" name="username" />
</div>
<div class="leftAlign">
<label for="forgotEmail">E-mail:</label>
</div>
<div class="centreAlign">
<input class="inputStyling" type="text" id="forgotEmail" name="email" />
</div>
<div class="centreAlign">
<button class="inputStyling">Request Change</button>
</div>
<div class="subLinks centreAlign">
<a href="{{ route('main.infopage', 'contact') }}" class="default">Contact us</a> if you lost access to your e-mail address!
</div>
{% endif %}
</form>
</div>
</div>
{% endif %}
{% endblock %}