diff --git a/config/config.example.ini b/config/config.example.ini index 28d9702..808b027 100644 --- a/config/config.example.ini +++ b/config/config.example.ini @@ -29,3 +29,6 @@ show_errors = true ; Show a small version of the changelog loaded from sakura.flash.moe show_changelog = true + +; Host for the mahou serve command +host = localhost:8000 diff --git a/libraries/Console/Command/ServeCommand.php b/libraries/Console/Command/ServeCommand.php index 0b44ad2..accb78c 100644 --- a/libraries/Console/Command/ServeCommand.php +++ b/libraries/Console/Command/ServeCommand.php @@ -8,6 +8,7 @@ namespace Sakura\Console\Command; use CLIFramework\Command; +use Sakura\Config; class ServeCommand extends Command { @@ -18,6 +19,11 @@ class ServeCommand extends Command public function execute() { - exec(PHP_BINDIR . '/php -S localhost:8000 -t ' . addslashes(ROOT . 'public/') . ' ' . addslashes(ROOT . 'server.php')); + $document_root = addslashes(ROOT . 'public/'); + $router_proxy = addslashes(ROOT . 'server.php'); + $php_dir = PHP_BINDIR; + $host = Config::local('dev', 'host'); + + exec("{$php_dir}/php -S {$host} -t {$document_root} {$router_proxy}"); } } diff --git a/libraries/Controllers/ForumController.php b/libraries/Controllers/ForumController.php index 542e94a..43e7c03 100644 --- a/libraries/Controllers/ForumController.php +++ b/libraries/Controllers/ForumController.php @@ -274,10 +274,7 @@ class ForumController extends Controller $thread->viewsUpdate(); // Set parse variables - Template::vars([ - 'thread' => $thread, - 'forum' => $forum, - ]); + Template::vars(compact('forum', 'thread')); // Print page contents return Template::render('forum/viewtopic'); @@ -463,4 +460,175 @@ class ForumController extends Controller return header("Location: {$threadLink}#p{$post->id}"); } + + public function threadReply($id = 0) + { + global $currentUser; + + $text = isset($_POST['text']) ? $_POST['text'] : null; + + // Attempt to get the forum + $thread = new Thread($id); + + // And attempt to get the forum + $forum = new Forum($thread->forum); + + // Check if the thread exists + if ($thread->id == 0 + || $forum->type !== 0 + || !$forum->permission(ForumPerms::VIEW, $currentUser->id) + || !$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'); + + Template::vars(['page' => compact('message', 'redirect')]); + + return Template::render('global/information'); + } + + // Length + $length = strlen($text); + $minLen = Config::get('forum_text_min'); + $maxLen = Config::get('forum_text_max'); + $tooShort = $length < $minLen; + $tooLong = $length > $maxLen; + + // Check requirments + if ($tooShort + || $tooLong) { + $route = Router::route('forums.thread', $thread->id); + + $message = "Your post is " . ( + $tooShort + ? "too short, add some more text!" + : "too long, you're gonna have to cut a little!" + ); + $redirect = "{$route}#reply"; + + Template::vars(['page' => compact('message', 'redirect')]); + + if (!isset($_SESSION['replyText'])) { + $_SESSION['replyText'] = []; + } + + $_SESSION['replyText']["t{$thread->id}"] = $text; + + return Template::render('global/information'); + } + + unset($_SESSION['replyText']["t{$thread->id}"]); + + // Create the post + $post = Post::create( + "Re: {$thread->title}", + $text, + $currentUser, + $thread->id, + $forum->id + ); + + // Go to the post + $postLink = Router::route('forums.post', $post->id); + + // Head to the post + return header("Location: {$postLink}"); + } + + public function createThread($id = 0) + { + global $currentUser; + + $title = isset($_POST['title']) ? $_POST['title'] : null; + $text = isset($_POST['text']) ? $_POST['text'] : null; + + // And attempt to get the forum + $forum = new Forum($id); + + // Check if the forum exists + if ($forum->id === 0 + || $forum->type !== 0 + || !$forum->permission(ForumPerms::VIEW, $currentUser->id) + || !$forum->permission(ForumPerms::REPLY, $currentUser->id) + || !$forum->permission(ForumPerms::CREATE_THREADS, $currentUser->id)) { + $message = "This forum 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 ($text && $title) { + // 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 = $titleLength < $titleMin; + $titleTooLong = $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.new', $forum->id); + + Template::vars(['page' => compact('message', 'redirect')]); + + if (!isset($_SESSION['replyText'])) { + $_SESSION['replyText'] = []; + } + + $_SESSION['replyText']["f{$forum->id}"]["title"] = $title; + $_SESSION['replyText']["f{$forum->id}"]["text"] = $text; + + return Template::render('global/information'); + } + + unset($_SESSION['replyText']["f{$forum->id}"]); + + // Create the post + $post = Post::create( + $title, + $text, + $currentUser, + 0, + $forum->id + ); + + // Go to the post + $postLink = Router::route('forums.post', $post->id); + + // Head to the post + return header("Location: {$postLink}"); + } + + Template::vars(compact('forum')); + + return Template::render('forum/viewtopic'); + } } diff --git a/libraries/Controllers/HelperController.php b/libraries/Controllers/HelperController.php new file mode 100644 index 0000000..1297f2f --- /dev/null +++ b/libraries/Controllers/HelperController.php @@ -0,0 +1,28 @@ + + */ +class HelperController extends Controller +{ + public function bbcodeParse() + { + $text = isset($_POST['text']) ? $_POST['text'] : null; + + $text = BBcode::toHTML($text); + + return $text; + } +} diff --git a/libraries/Controllers/MetaController.php b/libraries/Controllers/MetaController.php index 1b2e367..66ba153 100644 --- a/libraries/Controllers/MetaController.php +++ b/libraries/Controllers/MetaController.php @@ -34,7 +34,10 @@ class MetaController extends Controller 'news' => new News(Config::get('site_news_category')), 'newsCount' => Config::get('front_page_news_posts'), 'stats' => [ - 'userCount' => DB::table('users')->where('password_algo', '!=', 'disabled')->whereNotIn('rank_main', [1, 10])->count(), + 'userCount' => DB::table('users') + ->where('password_algo', '!=', 'disabled') + ->whereNotIn('rank_main', [1, 10]) + ->count(), 'newestUser' => User::construct(Users::getNewestUserId()), 'lastRegDate' => date_diff( date_create(date('Y-m-d', User::construct(Users::getNewestUserId())->registered)), diff --git a/libraries/Forum/Post.php b/libraries/Forum/Post.php index 0e08ac1..831e21a 100644 --- a/libraries/Forum/Post.php +++ b/libraries/Forum/Post.php @@ -150,14 +150,6 @@ class Post */ public static function create($subject, $text, User $poster, $thread = 0, $forum = 0) { - // Check if the data meets the requirements - if (strlen($subject) < Config::get('forum_title_min') - || strlen($subject) > Config::get('forum_title_max') - || strlen($text) < Config::get('forum_text_min') - || strlen($text) > Config::get('forum_text_max')) { - return null; - } - // If no thread is specified create a new one if ($thread) { $thread = new Thread($thread); diff --git a/public/content/data/yuuno/css/yuuno.css b/public/content/data/yuuno/css/yuuno.css index 45ec906..69d1ee2 100644 --- a/public/content/data/yuuno/css/yuuno.css +++ b/public/content/data/yuuno/css/yuuno.css @@ -2256,50 +2256,51 @@ textarea.inputStyling { vertical-align: middle; } -.forum.posting .posting-subject { +.posting-subject { padding: 3px 0 2px; } -.forum.posting .posting-subject input { +.posting-subject input { width: calc(100% - 10px); } -.forum.posting .posting-bbcodes { +.posting-bbcodes { padding: 4px 0 2px; } -.forum.posting .posting-bbcode-description { +.posting-bbcode-description { font: .9em/1.2em "SegoeUI", "Segoe UI", sans-serif; padding: 2px 0 3px; } -.forum.posting .posting-text { +.posting-text { padding: 2px 0 0; margin: 0 0 -1px; } -.forum.posting .posting-emotes { +.posting-emotes { text-align: center; padding: 10px 0; } -.forum.posting .posting-emotes img { +.posting-emotes img { vertical-align: middle; cursor: pointer; margin: 0 3px; } -.forum.posting .posting-text textarea { - width: calc(100% - 10px); - min-height: 300px; +.posting-text textarea { + min-width: calc(100% - 10px); + max-width: calc(100% - 10px); + min-height: 200px; } -.forum.posting .posting-options > div { +.posting-options > div { float: left; padding: 10px 10px 0; } -.forum.posting .posting-buttons { +.posting-buttons { text-align: center; } diff --git a/public/posting.php b/public/posting.php index 0bcfa48..1020004 100644 --- a/public/posting.php +++ b/public/posting.php @@ -30,7 +30,7 @@ if ($topicId) { $forumId = isset($_GET['f']) ? $_GET['f'] : -$thread->forum; +($topicId ? $thread->forum : 0); // Creare forum class $forum = new Forum($forumId); @@ -84,14 +84,6 @@ $mode = isset($_GET['f']) ) ); -$emotes = DB::table('emoticons') - ->get(); - -// Include emotes and bbcodes -$posting = [ - 'emoticons' => $emotes, -]; - // Check if we're in reply mode if ($mode != 'f') { // Attempt to get the topic @@ -129,22 +121,6 @@ if ($mode != 'f') { // Print page contents echo Template::render('global/information'); exit; - } - - // Check if we're in quote mode - if ($mode == 'p' - && isset($_GET['quote']) - && $_GET['quote'] == $_GET['p'] - && array_key_exists($_GET['p'], $thread->posts())) { - - // Reassign post for ease - $post = $thread->posts()[$_GET['p']]; - - // Add subject to render data - $quotedPost = BBcode::toEditor($post->text); - $posting['text'] = "[quote={$post->poster->username}]{$quotedPost}[/quote]"; - - // Post editing } elseif ($mode == 'p' && isset($_GET['edit']) && $_GET['edit'] == $_GET['p'] @@ -285,16 +261,13 @@ if ($mode != 'f') { echo Template::render('global/confirm'); exit; } - - // Add subject to render data - if (!isset($posting['subject'])) { - $posting['subject'] = "Re: {$thread->title}"; - } } // 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']); @@ -310,9 +283,6 @@ if (isset($_POST['post'])) { } else { $post = null; } - } else { - // Attempt to make the post - $post = Post::create($_POST['subject'], $_POST['text'], $currentUser, $topicId, $forumId); } // Add page specific things @@ -337,13 +307,5 @@ if (isset($_POST['post'])) { exit; } -// Set additional render data -$renderData = array_merge($renderData, [ - 'posting' => $posting, -]); - -// Set parse variables -Template::vars($renderData); - -// Print page contents -echo Template::render('forum/posting'); +$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 2374897..879bbab 100644 --- a/routes.php +++ b/routes.php @@ -36,7 +36,6 @@ 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 @@ -50,7 +49,8 @@ Router::group(['prefix' => 'forum'], function () { 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'); + Router::get('/{id:i}/new', 'ForumController@createThread', 'forums.new'); + Router::post('/{id:i}/new', 'ForumController@createThread', 'forums.new'); }); // Members @@ -73,6 +73,14 @@ Router::group(['prefix' => 'support'], function () { Router::get('/tracker', 'PremiumController@tracker', 'premium.tracker'); }); +// Helpers +Router::group(['prefix' => 'helper'], function () { + // BBcode + Router::group(['prefix' => 'bbcode'], function () { + Router::post('/parse', 'HelperController@bbcodeParse', 'helper.bbcode.parse'); + }); +}); + // Settings /* * General diff --git a/sakura.php b/sakura.php index b77199a..8dac73a 100644 --- a/sakura.php +++ b/sakura.php @@ -8,7 +8,7 @@ namespace Sakura; // Define Sakura version -define('SAKURA_VERSION', 20160324); +define('SAKURA_VERSION', 20160325); // Define Sakura Path define('ROOT', __DIR__ . '/'); @@ -156,6 +156,11 @@ if (!defined('SAKURA_NO_TPL')) { 'minPwdEntropy' => Config::get('min_entropy'), 'minUsernameLength' => Config::get('username_min_length'), 'maxUsernameLength' => Config::get('username_max_length'), + + 'forumTitleMaxLength' => Config::get('forum_title_max'), + 'forumTitleMinLength' => Config::get('forum_title_min'), + 'forumTextMaxLength' => Config::get('forum_text_max'), + 'forumTextMinLength' => Config::get('forum_text_min'), ], 'php' => [ 'sessionid' => \session_id(), @@ -163,17 +168,18 @@ if (!defined('SAKURA_NO_TPL')) { 'self' => $_SERVER['PHP_SELF'], ], - 'session' => [ + 'session' => array_merge([ 'checkLogin' => $authCheck, 'sessionId' => $authCheck[1], 'userId' => $authCheck[0], - ], + ], $_SESSION), 'user' => $currentUser, 'urls' => $urls, 'get' => $_GET, 'post' => $_POST, + 'request' => $_REQUEST, 'server' => $_SERVER, ]); diff --git a/templates/yuuno/forum/posting.twig b/templates/yuuno/forum/posting.twig deleted file mode 100644 index bb717b3..0000000 --- a/templates/yuuno/forum/posting.twig +++ /dev/null @@ -1,17 +0,0 @@ -{% extends 'global/master.twig' %} - -{% set bbcode = {'b': ['Bold', 'bold'], 'i': ['Italic', 'italic'], 'u': ['Underline', 'underline'], 's': ['Strikethrough', 'strikethrough'], 'header': ['Header', 'header'], 'url': ['URL', 'chain'], 'code': ['Code', 'code'], 'spoiler': ['Spoiler', 'minus'], 'box': ['Spoiler box', 'folder', true], 'list': ['List', 'list-ul'], 'img': ['Image', 'picture-o'], 'youtube': ['YouTube video', 'youtube-play']} %} - -{% set cancelTarget = 'history.go(-1);' %} - -{% set editorFormId = 'forumPostingForm' %} - -{% block title %}Posting{% endblock %} - -{% block content %} -
- {% if not post.poster.permission(constant('Sakura\\Perms\\Site::DEACTIVATED')) or post.poster.permission(constant('Sakura\\Perms\\Site::RESTRICTED')) %}{{ post.poster.username }}
-
- {% else %}
- [deleted user]
- {% endif %}
-
- {{ post.poster.title }}
- {% if post.poster.id == (thread.posts|first).poster.id %} {% endif %}
- {% 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 %}
-
+ {% if thread is defined %}
+ {% set textCache = session.replyText['t' ~ thread.id] %}
+ {% set postingAction = route('forums.thread.reply', thread.id) %}
+
+ {% for post in posts[get.page|default(1) - 1] %}
+
+ {% if not post.poster.permission(constant('Sakura\\Perms\\Site::DEACTIVATED')) or post.poster.permission(constant('Sakura\\Perms\\Site::RESTRICTED')) %}{{ post.poster.username }}
+
+ {% else %}
+ [deleted user]
+ {% endif %}
+ |
+
+
+ {{ post.poster.title }}
+ {% if post.poster.id == (thread.posts|first).poster.id %} {% endif %}
+ {% 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 %}
+
+ {% endif %}
+
+
+ {% endif %}
+
+
{% endif %}
-
+
+ |
-
+
+
+
+ #{{ post.id }} -
+
+
+
+ {{ post.parsed|raw }}
+
+ {% if post.poster.signature and post.poster.permission(constant('Sakura\\Perms\\Site::CHANGE_SIGNATURE')) %}
+
+
+ {{ post.poster.signature()|raw|nl2br }}
{% endif %}
-
-
- |
+
-
-
-
- #{{ post.id }} -
-
-
-
- {{ post.parsed|raw }}
-
- {% if post.poster.signature and post.poster.permission(constant('Sakura\\Perms\\Site::CHANGE_SIGNATURE')) %}
+ |
+