school commit
This commit is contained in:
parent
1962ff99a6
commit
53e5116cff
3 changed files with 46 additions and 5 deletions
|
@ -8,6 +8,7 @@
|
|||
namespace Sakura\Controllers;
|
||||
|
||||
use Sakura\Comment;
|
||||
use Sakura\Template;
|
||||
|
||||
/**
|
||||
* Handles comment stuff.
|
||||
|
@ -21,7 +22,26 @@ class CommentsController extends Controller
|
|||
{
|
||||
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'] : '';
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Reference in a new issue