diff --git a/libraries/BBcode.php b/libraries/BBcode.php index 64c479e..1a686dd 100644 --- a/libraries/BBcode.php +++ b/libraries/BBcode.php @@ -70,35 +70,28 @@ class BBcode // Add the standard definitions self::$bbcode->addCodeDefinitionSet(new DefaultCodeDefinitionSet()); - // Header tag - $builder = new CodeDefinitionBuilder('header', '

{param}

'); - self::$bbcode->addCodeDefinition($builder->build()); + $simpleCodes = [ + ['header', '

{param}

'], + ['s', '{param}'], + ['spoiler', '{param}'], + ['box', '
+
+ Click to open
', ], + ['box', '
{option}
+
', ], + ['quote', '
Quote
{param}
'], + ]; - // Strike tag - $builder = new CodeDefinitionBuilder('s', '{param}'); - self::$bbcode->addCodeDefinition($builder->build()); + foreach ($simpleCodes as $code) { + $builder = new CodeDefinitionBuilder($code[0], $code[1]); - // Spoiler tag - $builder = new CodeDefinitionBuilder('spoiler', '{param}'); - self::$bbcode->addCodeDefinition($builder->build()); + if (strstr($code[1], '{option}')) { + $builder->setUseOption(true); + } - // Box tag - $builder = new CodeDefinitionBuilder('box', '
Click to open
'); - self::$bbcode->addCodeDefinition($builder->build()); - - // Box tag - $builder = new CodeDefinitionBuilder('box', '
{option}
'); - $builder->setUseOption(true); - self::$bbcode->addCodeDefinition($builder->build()); - - // Quote tag - $builder = new CodeDefinitionBuilder('quote', '
Quote
{param}
'); - self::$bbcode->addCodeDefinition($builder->build()); - - // Quote tag - $builder = new CodeDefinitionBuilder('quote', '
{option} wrote
{param}
'); - $builder->setUseOption(true); - self::$bbcode->addCodeDefinition($builder->build()); + self::$bbcode->addCodeDefinition($builder->build()); + } // Add special definitions (PHP files MUST have the same name as the definition class foreach (glob(ROOT . 'libraries/BBcodeDefinitions/*.php') as $ext) { diff --git a/libraries/BBcodeDefinitions/Quote.php b/libraries/BBcodeDefinitions/Quote.php new file mode 100644 index 0000000..55de29e --- /dev/null +++ b/libraries/BBcodeDefinitions/Quote.php @@ -0,0 +1,77 @@ + + */ +class Quote extends CodeDefinition +{ + /** + * Constructor. + */ + public function __construct() + { + parent::__construct(); + $this->setTagName("quote"); + $this->setUseOption(true); + $this->setParseContent(true); + } + + /** + * Compiles the user bbcode to HTML + * + * @param ElementNode $el The JBBCode element node. + * + * @return string The compiled HTML. + */ + public function asHtml(ElementNode $el) + { + global $currentUser; + + $attr = $el->getAttribute()['quote']; + + if (substr($attr, 0, 1) === '#') { + $postId = substr($attr, 1); + $post = new Post($postId); + $forum = new Forum($post->forum); + + if ($post->id !== 0 + && $forum->permission(ForumPerms::VIEW, $currentUser->id)) { + $postLink = Router::route('forums.post', $post->id); + + $content = "
" + . "" + . "{$post->poster->username} wrote
" + . "
{$post->parsed}
"; + + return $content; + } + } + + $content = ""; + + foreach ($el->getChildren() as $child) { + $content .= $child->getAsHTML(); + } + + return "
{$attr} wrote
+
{$content}
"; + } +} diff --git a/libraries/Controllers/AuthController.php b/libraries/Controllers/AuthController.php index 09fc7e6..745a9a1 100644 --- a/libraries/Controllers/AuthController.php +++ b/libraries/Controllers/AuthController.php @@ -67,7 +67,7 @@ class AuthController extends Controller public function loginGet() { - return Template::render('main/login'); + return Template::render('auth/login'); } public function loginPost() @@ -204,7 +204,7 @@ class AuthController extends Controller ]); } - return Template::render('main/register'); + return Template::render('auth/register'); } public function registerPost() @@ -428,7 +428,7 @@ class AuthController extends Controller public function reactivateGet() { - return Template::render('main/reactivate'); + return Template::render('auth/reactivate'); } public function reactivatePost() @@ -500,7 +500,7 @@ class AuthController extends Controller public function resetPasswordGet() { - return Template::render('main/resetpassword'); + return Template::render('auth/resetpassword'); } public function resetPasswordPost() diff --git a/libraries/Controllers/ForumController.php b/libraries/Controllers/ForumController.php index 43e7c03..0f6a054 100644 --- a/libraries/Controllers/ForumController.php +++ b/libraries/Controllers/ForumController.php @@ -12,6 +12,7 @@ use Sakura\DB; use Sakura\Forum\Forum; use Sakura\Forum\Post; use Sakura\Forum\Thread; +use Sakura\Perms; use Sakura\Perms\Forum as ForumPerms; use Sakura\Router; use Sakura\Template; @@ -428,16 +429,14 @@ class ForumController extends Controller $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'), - ], - ]); + if ($post->id == 0 + || $thread->id == 0 + || !$forum->permission(ForumPerms::VIEW, $currentUser->id)) { + $message = "This post doesn't exist or you don't have access to it!"; + $redirect = Router::route('forums.index'); + + Template::vars(['page' => compact('message', 'redirect')]); - // Print page contents return Template::render('global/information'); } @@ -461,6 +460,29 @@ class ForumController extends Controller return header("Location: {$threadLink}#p{$post->id}"); } + public function postRaw($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)) { + return ""; + } + + return $post->text; + } + public function threadReply($id = 0) { global $currentUser; @@ -476,14 +498,23 @@ class ForumController extends Controller // Check if the thread exists if ($thread->id == 0 || $forum->type !== 0 - || !$forum->permission(ForumPerms::VIEW, $currentUser->id) - || !$forum->permission(ForumPerms::REPLY, $currentUser->id) + || !$forum->permission(ForumPerms::VIEW, $currentUser->id)) { + $message = "This post doesn't exist or you don't have access to it!"; + $redirect = Router::route('forums.index'); + + Template::vars(['page' => compact('message', 'redirect')]); + + return Template::render('global/information'); + } + + // Check if the thread exists + if (!$forum->permission(ForumPerms::REPLY, $currentUser->id) || ( $thread->status === 1 && !$forum->permission(ForumPerms::LOCK, $currentUser->id) )) { - $message = "This post doesn't exist or you don't have access to it!"; - $redirect = Router::route('forums.index'); + $message = "You are not allowed to post in this thread!"; + $redirect = Router::route('forums.thread', $thread->id); Template::vars(['page' => compact('message', 'redirect')]); @@ -631,4 +662,202 @@ class ForumController extends Controller return Template::render('forum/viewtopic'); } + + public function editPost($id = 0) + { + global $currentUser; + + $title = isset($_POST['title']) ? $_POST['title'] : null; + $text = isset($_POST['text']) ? $_POST['text'] : null; + + // Attempt to get the post + $post = new Post($id); + + // Attempt to get the thread + $thread = new Thread($post->thread); + + // And attempt to get the forum + $forum = new Forum($thread->forum); + + // Check permissions + $noAccess = $post->id == 0 + || $thread->id == 0 + || !$forum->permission(ForumPerms::VIEW, $currentUser->id); + + $noEdit = ( + $post->poster->id === $currentUser->id + ? !$currentUser->permission(ForumPerms::EDIT_OWN, Perms::FORUM) + : !$forum->permission(ForumPerms::EDIT_ANY, $currentUser->id) + ) || ( + $thread->status === 1 + && !$forum->permission(ForumPerms::LOCK, $currentUser->id) + ); + + // Check if the forum exists + if ($noAccess || $noEdit) { + if ($noDelete) { + $message = "You aren't allowed to edit posts in this thread!"; + $redirect = Router::route('forums.post', $post->id); + } else { + $message = "This post doesn't exist or you don't have access to it!"; + $redirect = Router::route('forums.index'); + } + + Template::vars(['page' => compact('message', 'redirect')]); + + return Template::render('global/information'); + } + + // Length + $titleLength = strlen($title); + $textLength = strlen($text); + $titleMin = Config::get('forum_title_min'); + $titleMax = Config::get('forum_title_max'); + $textMin = Config::get('forum_text_min'); + $textMax = Config::get('forum_text_max'); + + // Checks + $titleTooShort = $title !== null + && $post->id === $thread->firstPost()->id + && $titleLength < $titleMin; + $titleTooLong = $title !== null + && $post->id === $thread->firstPost()->id + && $titleLength > $titleMax; + $textTooShort = $textLength < $textMin; + $textTooLong = $textLength > $textMax; + + // Check requirments + if ($titleTooShort + || $titleTooLong + || $textTooShort + || $textTooLong) { + + $message = ""; + + if ($titleTooShort) { + $message = "This title is too short!"; + } elseif ($titleTooLong) { + $message = "This title is too long!"; + } elseif ($textTooShort) { + $message = "Please make your post a little bit longer!"; + } elseif ($textTooLong) { + $message = "Your post is too long, you're gonna have to cut a little!"; + } + + $redirect = Router::route('forums.post', $post->id); + + Template::vars(['page' => compact('message', 'redirect')]); + + if (!isset($_SESSION['replyText'])) { + $_SESSION['replyText'] = []; + } + + $_SESSION['replyText']["t{$forum->id}"] = $text; + + return Template::render('global/information'); + } + + unset($_SESSION['replyText']["t{$forum->id}"]); + + if ($post->id !== $thread->firstPost()->id || $title === null) { + $title = "Re: {$thread->title}"; + } else { + $thread->title = $title; + $thread->update(); + } + + // Create the post + $post->subject = $title; + $post->text = $text; + $post->editTime = time(); + $post->editReason = ''; + $post->editUser = $currentUser; + $post = $post->update(); + + // Go to the post + $postLink = Router::route('forums.post', $post->id); + + // Head to the post + return header("Location: {$postLink}"); + } + + public function deletePost($id = 0) + { + global $currentUser; + + $action = isset($_POST['yes']) && isset($_POST['sessionid']) + ? $_POST['sessionid'] === session_id() + : null; + + // 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 permissions + $noAccess = $post->id == 0 + || $thread->id == 0 + || !$forum->permission(ForumPerms::VIEW, $currentUser->id); + + $noDelete = ( + $post->poster->id === $currentUser->id + ? !$currentUser->permission(ForumPerms::DELETE_OWN, Perms::FORUM) + : !$forum->permission(ForumPerms::DELETE_ANY, $currentUser->id) + ) || ( + $thread->status === 1 + && !$forum->permission(ForumPerms::LOCK, $currentUser->id) + ); + + // Check if the forum exists + if ($noAccess || $noDelete) { + if ($noDelete) { + $message = "You aren't allowed to delete posts in this thread!"; + $redirect = Router::route('forums.post', $post->id); + } else { + $message = "This post doesn't exist or you don't have access to it!"; + $redirect = Router::route('forums.index'); + } + + Template::vars(['page' => compact('message', 'redirect')]); + + return Template::render('global/information'); + } + + if ($action !== null) { + if ($action) { + // Set message + $message = "Deleted the post!"; + + // Check if the thread only has 1 post + if ($thread->replyCount() === 1) { + // Delete the entire thread + $thread->delete(); + + $redirect = Router::route('forums.forum', $forum->id); + } else { + // Just delete the post + $post->delete(); + + $redirect = Router::route('forums.thread', $thread->id); + } + + Template::vars(['page' => compact('message', 'redirect')]); + + return Template::render('global/information'); + } + + $postLink = Router::route('forums.post', $post->id); + return header("Location: {$postLink}"); + } + + $message = "Are you sure?"; + + Template::vars(compact('message')); + + return Template::render('global/confirm'); + } } diff --git a/public/posting.php b/public/posting.php deleted file mode 100644 index 1020004..0000000 --- a/public/posting.php +++ /dev/null @@ -1,311 +0,0 @@ -thread : - 0 -); - -// Get the topic -if ($topicId) { - $thread = new Thread($topicId); -} - -$forumId = isset($_GET['f']) ? -$_GET['f'] : -($topicId ? $thread->forum : 0); - -// Creare forum class -$forum = new Forum($forumId); - -// Check if the user has access to the forum -if (!$forum->permission(ForumPerms::VIEW, $currentUser->id) - || !$forum->permission(ForumPerms::REPLY, $currentUser->id)) { - // Set render data - $renderData['page'] = [ - 'title' => 'Information', - 'message' => 'You do not have access to this forum.', - ]; - - // Set parse variables - Template::vars($renderData); - - // Print page contents - echo Template::render('global/information'); - exit; -} - -// Check if the user has access to the forum -if (!isset($thread) - && !$forum->permission(ForumPerms::CREATE_THREADS, $currentUser->id)) { - // Set render data - $renderData['page'] = [ - 'title' => 'Information', - 'message' => 'You are not allowed to create threads in this forum.', - ]; - - // Set parse variables - Template::vars($renderData); - - // Print page contents - echo Template::render('global/information'); - exit; -} - -$mode = isset($_GET['f']) -// New thread - ? 'f' -: ( - isset($_GET['t']) - // Reply to thread - ? 't' - : ( - isset($_GET['p']) - // Quoting a post - ? 'p' - : null - ) -); - -// Check if we're in reply mode -if ($mode != 'f') { - // Attempt to get the topic - $thread = $thread ? $thread : new Thread($topicId); - - // Prompt an error if the topic doesn't exist - if (!$thread->id) { - // Add page specific things - $renderData['page'] = [ - 'redirect' => (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : Router::route('forums.index')), - 'message' => 'The requested post does not exist.', - ]; - - // Set parse variables - Template::vars($renderData); - - // Print page contents - echo Template::render('global/information'); - exit; - } - - // Prompt an error if the topic doesn't exist - if ($thread->status == 1 - && !$forum->permission(ForumPerms::LOCK, $currentUser->id)) { - - // Add page specific things - $renderData['page'] = [ - 'redirect' => (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : Router::route('forums.index')), - 'message' => 'The thread you tried to reply to is locked.', - ]; - - // Set parse variables - Template::vars($renderData); - - // Print page contents - echo Template::render('global/information'); - exit; - } elseif ($mode == 'p' - && isset($_GET['edit']) - && $_GET['edit'] == $_GET['p'] - && array_key_exists($_GET['p'], $thread->posts())) { - - // Permissions - if (!$currentUser->permission(ForumPerms::EDIT_OWN, Perms::FORUM)) { - // Add page specific things - $renderData['page'] = [ - 'redirect' => (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : Router::route('forums.index')), - 'message' => 'You are not allowed to edit posts!', - ]; - - // Set parse variables - Template::vars($renderData); - - // Print page contents - echo Template::render('global/information'); - exit; - } - - // Checks - if ($thread->posts()[$_GET['p']]->poster->id != $currentUser->id - && !$forum->permission(ForumPerms::EDIT_ANY, $currentUser->id)) { - - // Add page specific things - $renderData['page'] = [ - 'redirect' => (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : Router::route('forums.index')), - 'message' => 'You can only edit your own posts!', - ]; - - // Set parse variables - Template::vars($renderData); - - // Print page contents - echo Template::render('global/information'); - exit; - } - - // Reassign post for ease - $post = $thread->posts()[$_GET['p']]; - - // Set variables - $posting = array_merge($posting, [ - 'subject' => $post->subject, - 'text' => BBcode::toEditor($post->text), - 'id' => $post->id, - ]); - // Post deletion - } elseif ($mode == 'p' - && isset($_GET['delete']) - && $_GET['delete'] == $_GET['p'] - && array_key_exists($_GET['p'], $thread->posts())) { - - // Permissions - if (!$currentUser->permission(ForumPerms::DELETE_OWN, Perms::FORUM)) { - // Add page specific things - $renderData['page'] = [ - 'redirect' => (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : Router::route('forums.index')), - 'message' => 'You are not allowed to delete posts!', - ]; - - // Set parse variables - Template::vars($renderData); - - // Print page contents - echo Template::render('global/information'); - exit; - } - - // Checks - if ($thread->posts()[$_GET['p']]->poster->id != $currentUser->id - && !$forum->permission(ForumPerms::DELETE_ANY, $currentUser->id)) { - // Add page specific things - $renderData['page'] = [ - 'redirect' => (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : Router::route('forums.index')), - 'message' => 'You can only delete your own posts!', - ]; - - // Set parse variables - Template::vars($renderData); - - // Print page contents - echo Template::render('global/information'); - exit; - } - - // Submit mode - if (isset($_POST['timestamp'], $_POST['sessionid'], $_POST['post_id'])) { - // Post deletion code - if (isset($_POST['yes'])) { - // Delete the post - DB::table('posts') - ->where('post_id', $_POST['post_id']) - ->delete(); - - // Reload the topic - $thread = new Thread($topicId); - - // If there's no more posts left in the topic delete it as well - if (!$thread->replyCount()) { - DB::table('topics') - ->where('topic_id', $thread->id) - ->delete(); - } - - // Add page specific things - $renderData['page'] = [ - 'redirect' => ($thread->replyCount() ? Router::route('forums.thread', $thread->id) : Router::route('forums.index')), - 'message' => 'Your post has been deleted!', - ]; - - // Set parse variables - Template::vars($renderData); - - // Print page contents - echo Template::render('global/information'); - exit; - // Return to previous page - } else { - header('Location: ' . Router::route('forums.post', $_POST['post_id'])); - exit; - } - } - - // Form mode - $renderData = array_merge($renderData, [ - 'message' => "Are you sure you want to delete your reply to {$thread->title}?", - 'conditions' => [ - 'post_id' => $thread->posts()[$_GET['p']]->id, - ], - ]); - - // Set parse variables - Template::vars($renderData); - - // Print page contents - echo Template::render('global/confirm'); - exit; - } -} - -// Check if a post is being made -if (isset($_POST['post'])) { - // Check if an ID is set - $post = null; - - if (isset($_POST['id'])) { - // Attempt to create a post object - $post = new Post($_POST['id']); - - // Check if the post israel - if ($post->id == $_POST['id']) { - $post->subject = $_POST['subject']; - $post->text = $_POST['text']; - $post->editTime = time(); - $post->editReason = ''; - $post->editUser = $currentUser; - $post = $post->update(); - } else { - $post = null; - } - } - - // Add page specific things - $renderData['page'] = [ // Why does fail just kind of not redirect to anywhere - 'redirect' => $post ? Router::route('forums.post', $post->id) : '', - 'message' => $post ? 'Made the post!' : 'Something is wrong with your post!', - 'success' => $post ? 1 : 0, - ]; - - // Print page contents or if the AJAX request is set only display the render data - if (isset($_REQUEST['ajax'])) { - echo $renderData['page']['message'] . '|' . - $renderData['page']['success'] . '|' . - $renderData['page']['redirect']; - } else { - // Set parse variables - Template::vars($renderData); - - // Print page contents - echo Template::render('global/information'); - } - exit; -} - -$route = isset($thread) ? Router::route('forums.thread', $thread->id) : Router::route('forums.new', $forum->id); -header("Location: {$route}#reply"); diff --git a/routes.php b/routes.php index 879bbab..d59ab03 100644 --- a/routes.php +++ b/routes.php @@ -36,6 +36,10 @@ Router::group(['prefix' => 'forum'], function () { // Post Router::group(['prefix' => 'post'], function () { Router::get('/{id:i}', 'ForumController@post', 'forums.post'); + Router::get('/{id:i}/raw', 'ForumController@postRaw', 'forums.post.raw'); + Router::get('/{id:i}/delete', 'ForumController@deletePost', 'forums.post.delete'); + Router::post('/{id:i}/delete', 'ForumController@deletePost', 'forums.post.delete'); + Router::post('/{id:i}/edit', 'ForumController@editPost', 'forums.post.edit'); }); // Thread diff --git a/templates/misaki/forum/forum.twig b/templates/misaki/forum/forum.twig index d7f6772..d2abae9 100644 --- a/templates/misaki/forum/forum.twig +++ b/templates/misaki/forum/forum.twig @@ -4,7 +4,7 @@ {% if forum.forums|length %}
-
{% if forum.type != 1 %}Subforums{% else %}{{ forum.name }}{% endif %}
+
{% if forum.type != 1 %}Subforums{% else %}{{ forum.name }}{% endif %}
{{ forum.description }}
{% for forum in forum.forums %} diff --git a/templates/yuuno/main/login.twig b/templates/yuuno/auth/login.twig similarity index 76% rename from templates/yuuno/main/login.twig rename to templates/yuuno/auth/login.twig index e6bdcad..978e5a9 100644 --- a/templates/yuuno/main/login.twig +++ b/templates/yuuno/auth/login.twig @@ -30,10 +30,12 @@
- +
- diff --git a/templates/yuuno/main/reactivate.twig b/templates/yuuno/auth/reactivate.twig similarity index 100% rename from templates/yuuno/main/reactivate.twig rename to templates/yuuno/auth/reactivate.twig diff --git a/templates/yuuno/main/register.twig b/templates/yuuno/auth/register.twig similarity index 100% rename from templates/yuuno/main/register.twig rename to templates/yuuno/auth/register.twig diff --git a/templates/yuuno/main/resetpassword.twig b/templates/yuuno/auth/resetpassword.twig similarity index 100% rename from templates/yuuno/main/resetpassword.twig rename to templates/yuuno/auth/resetpassword.twig diff --git a/templates/yuuno/elements/comment.twig b/templates/yuuno/elements/comment.twig index a518cac..2f2ceaa 100644 --- a/templates/yuuno/elements/comment.twig +++ b/templates/yuuno/elements/comment.twig @@ -10,7 +10,7 @@ {% else %}
  • {% endif %} -
  • +
  • {{ comment.comment_likes }}
  • {{ comment.comment_dislikes }}
  • diff --git a/templates/yuuno/elements/editor.twig b/templates/yuuno/elements/editor.twig deleted file mode 100644 index 52700f1..0000000 --- a/templates/yuuno/elements/editor.twig +++ /dev/null @@ -1,37 +0,0 @@ -
    -
    Forum / Posting
    -
    - -
    -
    -
    - {% for code,meta in bbcode %} - - {% endfor %} -
    -
    -
    - -
    -
    -
    - {% for emoticon in posting.emoticons %} - {{ emoticon.emote_string }} - {% endfor %} -
    -
    -
    - - -
    - {% if posting.id %} - - {% endif %} - - - -
    diff --git a/templates/yuuno/forum/replyForm.twig b/templates/yuuno/forum/replyForm.twig index 0cf7a2e..9933932 100644 --- a/templates/yuuno/forum/replyForm.twig +++ b/templates/yuuno/forum/replyForm.twig @@ -15,11 +15,9 @@
    - {% if titleCache is defined %} -
    - -
    - {% endif %} +
    @@ -30,6 +28,7 @@ {% endfor %}
    +
    @@ -44,15 +43,21 @@ textMin = {{ sakura.forumTextMinLength }}, preview = document.getElementById('postingPreview'), pTitle = document.getElementById('postingTitle'), + pTitleCont = document.getElementById('postingTitleContainer'), pText = document.getElementById('postingText'), pForm = document.getElementById('postingForm'), + pStopEdit = document.getElementById('postingStopEditing'), + pMode = document.getElementById('previewMode'), tTitle = document.getElementById('threadTitle'), rTitle = document.getElementById('previewTitle'), rText = document.getElementById('previewText'), lastParsed = Date.now(), lastKeystroke = Date.now(), parser = new AJAX(), - parserActive = false; + postFetch = new AJAX(), + parserActive = false, + op = {{ thread is defined ? thread.firstPost.id : 0 }}, + threadName = "{{ thread is defined ? thread.firstPost.subject : '' }}"; parser.setUrl("{{ route('helper.bbcode.parse') }}"); parser.contentType("application/x-www-form-urlencoded"); @@ -61,6 +66,12 @@ preview.style.display = null; }); + pText.addEventListener("blur", function () { + if (op && pText.value.length < 1) { + preview.style.display = 'none'; + } + }); + setInterval(function () { if (lastParsed < Date.now() - 1000 && lastKeystroke > Date.now() - 1000 @@ -102,31 +113,74 @@ pText.addEventListener("keydown", function (e) { lastKeystroke = Date.now(); + if (e.keyCode == 9) { + e.preventDefault(); + insertText('postingText', ' '); + } + if (e.keyCode == 13 && e.ctrlKey) { pForm.submit(); } }); - {% if titleCache is defined %} - pTitle.addEventListener("keyup", function (e) { - var title = pTitle.value; + pTitle.addEventListener("keyup", function (e) { + var title = pTitle.value; - if (title.length == 0) { - title = ""; - } else if (title.length < titleMin) { - title = "Too short!"; - tTitle.innerHTML = title; - rTitle.innerHTML = title; - return; - } else if (title.length > titleMax) { - title = "Too long!"; - tTitle.innerHTML = title; - rTitle.innerHTML = title; - return; + if (title.length == 0) { + title = ""; + } else if (title.length < titleMin) { + title = "Too short!"; + tTitle.innerHTML = title; + rTitle.innerHTML = title; + return; + } else if (title.length > titleMax) { + title = "Too long!"; + tTitle.innerHTML = title; + rTitle.innerHTML = title; + return; + } + + tTitle.innerText = title; + rTitle.innerText = title; + }); + + function quotePost(id) { + pText.value = pText.value + "[quote=#" + id + "][/quote]"; + pText.focus(); + } + + function editPost(id) { + pText.disabled = true; + pTitleCont.style.display = 'none'; + rTitle.innerText = 'Re: ' + threadName; + + url = "{{ route('forums.post.raw', '1') }}".replace('1', id); + + postFetch.setUrl(url); + + postFetch.addCallback(200, function () { + pText.value = postFetch.response(); + pStopEdit.style.display = null; + pForm.action = "{{ route('forums.post.edit', '1') }}".replace('1', id); + pMode.innerText = 'Editing #' + id; + if (id === op) { + pTitleCont.style.display = null; + pTitle.value = threadName; + rTitle.innerText = threadName; } - - tTitle.innerText = title; - rTitle.innerText = title; + pText.disabled = false; + pText.focus(); }); - {% endif %} + + postFetch.start(HTTPMethods.GET); + } + + function stopEdit() { + pText.value = ""; + pForm.action = "{{ postingAction }}"; + pStopEdit.style.display = 'none'; + pTitleCont.style.display = 'none'; + pMode.innerText = 'Preview'; + preview.style.display = 'none'; + } diff --git a/templates/yuuno/forum/viewtopic.twig b/templates/yuuno/forum/viewtopic.twig index f3808e9..6b0bc86 100644 --- a/templates/yuuno/forum/viewtopic.twig +++ b/templates/yuuno/forum/viewtopic.twig @@ -5,9 +5,11 @@ {% block title %}{% if thread is defined %}{{ thread.title }}{% else %}Creating thread in {{ forum.name }}{% endif %}{% endblock %} {% if thread is defined %} - {% if thread.status != 1 + {% if forum.permission(constant('Sakura\\Perms\\Forum::REPLY'), user.id) + and ( + thread.status != 1 or forum.permission(constant('Sakura\\Perms\\Forum::LOCK'), user.id) - or forum.permission(constant('Sakura\\Perms\\Forum::REPLY')) %} + ) %} {% set forumReplyLink %}#reply{% endset %} {% endif %} @@ -59,13 +61,15 @@ {% block js %} - + {% endblock %} {% block content %}
    - +
    {{ forum.name }} / {{ thread.title }}
    {% include 'forum/forumBtns.twig' %} {% if thread is defined %} @@ -86,10 +90,10 @@ {% if session.checkLogin %}
    {% if (user.id == post.poster.id and forum.permission(constant('Sakura\\Perms\\Forum::EDIT_OWN'), user.id)) or forum.permission(constant('Sakura\\Perms\\Forum::EDIT_ANY'), user.id) %} - + {% endif %} {% if (user.id == post.poster.id and forum.permission(constant('Sakura\\Perms\\Forum::DELETE_OWN'), user.id)) or forum.permission(constant('Sakura\\Perms\\Forum::DELETE_ANY'), user.id) %} - + {% endif %} {% if not (post.poster.permission(constant('Sakura\\Perms\\Site::DEACTIVATED')) or post.poster.permission(constant('Sakura\\Perms\\Site::RESTRICTED')) or user.id == post.poster.id) %} {% if user.isFriends(post.poster.id) != 0 %} @@ -98,7 +102,7 @@ {% endif %} - +
    {% endif %} @@ -130,30 +134,32 @@ {% set textCache = session.replyText['f' ~ forum.id].text %} {% set postingAction = route('forums.new', forum.id) %} {% endif %} - - - + - + + + + {% endif %}
    +
    +
    {% if titleCache is not defined %}Re: {{ thread.title }}{% endif %}
    +
    Preview
    +
    +
    +
    + {% if user.signature and user.permission(constant('Sakura\\Perms\\Site::CHANGE_SIGNATURE')) %} +
    +
    + {{ user.signature()|raw|nl2br }} +
    + {% endif %} +
    {% if forumReplyLink is defined or thread is not defined %} {% include 'forum/replyForm.twig' %} diff --git a/templates/yuuno/global/master.twig b/templates/yuuno/global/master.twig index 29cb96f..f15f22c 100644 --- a/templates/yuuno/global/master.twig +++ b/templates/yuuno/global/master.twig @@ -151,7 +151,7 @@