Issues (393)

web/public/comment_ajax.php (1 issue)

1
<?php require_once($_SERVER['DOCUMENT_ROOT'] . "/s/classes/config.inc.php"); ?>
2
<?php require_once($_SERVER['DOCUMENT_ROOT'] . "/s/classes/db_helper.php"); ?>
3
<?php require_once($_SERVER['DOCUMENT_ROOT'] . "/s/classes/time_manip.php"); ?>
4
<?php require_once($_SERVER['DOCUMENT_ROOT'] . "/s/classes/user_helper.php"); ?>
5
<?php require_once($_SERVER['DOCUMENT_ROOT'] . "/s/classes/video_helper.php"); ?>
6
<?php require_once($_SERVER['DOCUMENT_ROOT'] . "/s/classes/user_update.php"); ?><?php $__video_h = new video_helper($__db); ?>
7
<?php $__user_h = new user_helper($__db); ?>
8
<?php $__user_u = new user_update($__db); ?>
9
<?php $__db_h = new db_helper(); ?>
10
<?php $__time_h = new time_helper(); ?>
11
<?php if(!$__video_h->video_exists($_GET['v'])) { header("Location: /?error=This video doesn't exist!"); } ?>
12
<?php $_video = $__video_h->fetch_video_rid($_GET['v']); ?>
13
<?php $_video['comments'] = $__video_h->get_comments_from_video($_video['rid']); ?>
14
<?php
15
    if($_SERVER['REQUEST_METHOD'] == 'POST') {
16
        $error = array();
17
        $request = (object) [
18
            "status" => "success"
19
        ];
20
21
        if(!isset($_SESSION['siteusername'])){ $error['message'] = "you are not logged in"; $error['status'] = true; }
22
        if(!$_POST['comment']){ $error['message'] = "your comment cannot be blank"; $error['status'] = true; }
23
        if(strlen($_POST['comment']) > 1000){ $error['message'] = "your comment must be shorter than 1000 characters"; $error['status'] = true; }
24
        if($__user_h->if_cooldown($_SESSION['siteusername'])) { $error['message'] = "You are on a cooldown! Wait for a minute before posting another comment."; $error['status'] = true; }
25
26
        if(!isset($error['message'])) {
27
			$text = $_POST['comment'];
28
            $stmt = $__db->prepare("INSERT INTO comments (toid, author, comment) VALUES (:v, :username, :comment)");
29
            $stmt->bindParam(":v", $_GET['v']);
30
			$stmt->bindParam(":username", $_SESSION['siteusername']);
31
			$stmt->bindParam(":comment", $text);
32
            $stmt->execute();
33
34
			$__user_u->update_cooldown_time($_SESSION['siteusername'], "cooldown_comment");
35
        }
36
37
        die(json_encode($request));
38
    }
39
?>
0 ignored issues
show
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...