-
Notifications
You must be signed in to change notification settings - Fork 2
/
addComment.php
67 lines (49 loc) · 2.39 KB
/
addComment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
if(isset($_POST["author"]) && isset($_POST["content"]) && isset($_POST["id"])){
$id = $_POST["id"];
$author = $_POST["author"];
$content = $_POST["content"];
$json = file_get_contents("ids/" . $id . ".json");
$jsonD = json_decode($json, true);
$cdata = $jsonD["comments"];
$cid = count($jsonD["comments"]) + 1;
$comArr = ["comments" =>["poster"=>$author, "content"=>$content, "likes"=>0, "dislikes"=>0, "cid"=>$cid]];
// var_dump($comArr);
// Need to push the ["comments"] to the other comments
$commentFixed = $comArr["comments"];
array_push($jsonD["comments"], $commentFixed);
// These DO work!
// var_dump($jsonD["comments"]);
$commentFix = json_encode($jsonD, true);
// That's SNAXOR!
header("Location: view.php?id=" . $_POST["id"]);
// echo "<br>Could not submit your comment. The code in our system simply doesn't work at the moment! Just look at the data above.<br /><a href='view.php?id=" . $_POST["id"] . "'>Go back to the video</a>";
file_put_contents("ids/" . $_POST["id"]. ".json", $commentFix);
} else {
session_start();
if(isset($_POST["content"]) && isset($_POST["id"]) && !isset($_POST["author"]) && isset($_SESSION["username"])){
// session_start();
$id = $_POST["id"];
$author = $_SESSION["username"];
$content = $_POST["content"];
$json = file_get_contents("ids/" . $id . ".json");
$jsonD = json_decode($json, true);
$cdata = $jsonD["comments"];
$cid = count($jsonD["comments"]) + 1;
$comArr = ["comments" =>["poster"=>$author, "content"=>$content, "likes"=>0, "dislikes"=>0, "cid"=>$cid]];
// var_dump($comArr);
// Need to push the ["comments"] to the other comments
$commentFixed = $comArr["comments"];
array_push($jsonD["comments"], $commentFixed);
// These DO work!
// var_dump($jsonD["comments"]);
$commentFix = json_encode($jsonD, true);
// That's SNAXOR!
header("Location: view.php?id=" . $_POST["id"]);
// echo "<br>Could not submit your comment. The code in our system simply doesn't work at the moment! Just look at the data above.<br /><a href='view.php?id=" . $_POST["id"] . "'>Go back to the video</a>";
file_put_contents("ids/" . $_POST["id"]. ".json", $commentFix);
} else {
echo "Error";
}
}
?>