forked from if-itb/IF3110-01-Simple-Blog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_comment.php
57 lines (46 loc) · 1.22 KB
/
load_comment.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
<?php
include_once("assets/php/module/PostDataManager.php");
include_once("assets/php/module/CommentDataManager.php");
if(empty($_GET)) {
$title = $_POST["title"];
$sender = $_POST["sender"];
$email = $_POST["email"];
$date = $_POST["date"];
$comment = $_POST["comment"];
$post = new PostDataManager("assets/data", "assets/data");
$id = $post->get_id($title, $date);
$data_mgr = new CommentDataManager("assets/data", $id);
$comment = str_replace("\r\n", "<p>", $comment);
$retval = $data_mgr->add_comment($sender, $email, $date, $comment);
if($retval === false) {
print("");
} else {
$response = array(
"sender" => $sender,
"email" => $email,
"date" => $date,
"comment" => $comment
);
$json_text = json_encode($response);
print($json_text);
}
} else {
$date = $_GET["date"];
$title = $_GET["title"];
$cmnt_id = $_GET["count"];
$post = new PostDataManager("assets/data", "assets/data");
$id = $post->get_id($title, $date);
if(strcmp($id, "") === 0) {
print("");
} else {
$data_mgr = new CommentDataManager("assets/data", $id);
$data = $data_mgr->get_comment($cmnt_id);
if($data !== "") {
$json_text = json_encode($data);
print($json_text);
} else {
print("");
}
}
}
?>