This repository has been archived on 2024-06-26. You can view files and clone it, but cannot push or open issues or pull requests.
sakura/libraries/Controllers/CommentsController.php

76 lines
1.6 KiB
PHP
Raw Normal View History

2016-03-28 14:47:43 +00:00
<?php
/**
* Holds the comments controller.
*
* @package Sakura
*/
namespace Sakura\Controllers;
use Sakura\Comment;
2016-03-30 09:09:58 +00:00
use Sakura\Template;
2016-03-28 14:47:43 +00:00
/**
* Handles comment stuff.
*
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
class CommentsController extends Controller
{
public function post($category = '', $reply = 0)
{
global $currentUser;
2016-03-30 09:09:58 +00:00
// Set json content type
header('Content-Type: application/json; charset=utf-8');
2016-03-28 14:47:43 +00:00
2016-03-30 09:09:58 +00:00
// 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'));
}
2016-03-28 14:47:43 +00:00
$text = isset($_POST['text']) ? $_POST['text'] : '';
$comment = new Comment;
$comment->category = $category;
$comment->time = time();
$comment->reply = (int) $reply;
$comment->user = $currentUser->id;
$comment->text = $text;
$comment->save();
2016-03-30 09:09:58 +00:00
return $this->json($comment);
}
public function edit($id = 0)
{
//
}
public function delete($id = 0)
{
//
}
public function vote($id = 0)
{
//
2016-03-28 14:47:43 +00:00
}
}