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; namespace Sakura\Controllers;
use Sakura\Comment; use Sakura\Comment;
use Sakura\Template;
/** /**
* Handles comment stuff. * Handles comment stuff.
@ -21,7 +22,26 @@ class CommentsController extends Controller
{ {
global $currentUser; global $currentUser;
// todo: make not shit // Set json content type
header('Content-Type: application/json; charset=utf-8');
// 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'] : ''; $text = isset($_POST['text']) ? $_POST['text'] : '';
@ -34,5 +54,22 @@ class CommentsController extends Controller
$comment->text = $text; $comment->text = $text;
$comment->save(); $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 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 // Set json content type
header('Content-Type: application/json; charset=utf-8'); header('Content-Type: application/json; charset=utf-8');
return json_encode( return $this->json($currentUser->notifications());
$currentUser->notifications(),
JSON_FORCE_OBJECT | JSON_NUMERIC_CHECK | JSON_BIGINT_AS_STRING
);
} }
/** /**