school commit

This commit is contained in:
flash 2016-03-30 11:09:58 +02:00
parent 1962ff99a6
commit 53e5116cff
3 changed files with 46 additions and 5 deletions

View file

@ -8,6 +8,7 @@
namespace Sakura\Controllers;
use Sakura\Comment;
use Sakura\Template;
/**
* Handles comment stuff.
@ -20,8 +21,27 @@ class CommentsController extends Controller
public function post($category = '', $reply = 0)
{
global $currentUser;
// Set json content type
header('Content-Type: application/json; charset=utf-8');
// todo: make not shit
// Check if the user can comment
if (!$currentUser->permission(Site::CREATE_COMMENTS)) {
$error = "You aren't allowed to make comments!";
return $this->json(compact('error'));
}
// Checks
$length = strlen($content);
$tooShort = $length < Config::get('comment_min_length');
$tooLong = $length > Config::get('comment_max_length');
if ($tooShort || $tooLong) {
$fill = $tooShort ? "short" : "long";
$error = "Your comment is too {$fill}!";
return $this->json(compact('error'));
}
$text = isset($_POST['text']) ? $_POST['text'] : '';
@ -34,5 +54,22 @@ class CommentsController extends Controller
$comment->text = $text;
$comment->save();
return $this->json($comment);
}
public function edit($id = 0)
{
//
}
public function delete($id = 0)
{
//
}
public function vote($id = 0)
{
//
}
}

View file

@ -15,4 +15,11 @@ namespace Sakura\Controllers;
*/
class Controller
{
private function json($object)
{
return json_encode(
$object,
JSON_FORCE_OBJECT | JSON_NUMERIC_CHECK | JSON_BIGINT_AS_STRING
);
}
}

View file

@ -32,10 +32,7 @@ class NotificationsController extends Controller
// Set json content type
header('Content-Type: application/json; charset=utf-8');
return json_encode(
$currentUser->notifications(),
JSON_FORCE_OBJECT | JSON_NUMERIC_CHECK | JSON_BIGINT_AS_STRING
);
return $this->json($currentUser->notifications());
}
/**