-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcomments.php
executable file
·51 lines (40 loc) · 1.14 KB
/
comments.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
<?php
if($pagename == "index") {
$file = "content/comments.json";
$fullView = false;
} else {
$file = "../content/comments.json";
$fullView = true;
}
if(file_exists($file) && filesize($file) > 0){
$handle = fopen($file, "a+");
$contents = fread($handle, filesize($file));
$comments = json_decode($contents);
fclose($handle);
$commentsnum = 0;
foreach ($comments as $comment){
if($comment->post_id == $pagename) {
if($commentsnum !== 0) {
echo "<hr>";
}
$commentsnum += 1;
?>
<article class="comment">
<h4><?= $comment->name ?></h4>
<div class="clearfix commentcontent">
<?php
echo(nl2br($comment->body))
?>
</div>
</article>
<?php
}
}
?><hr>
<!-- New comment button -->
<a href="<?php echo $root_path ?>/edit/newcomment.php?post_id=<?php echo $pagename ?>">Write new comment...</a>
<?php
} else {
echo "Something went wrong...";
}
?>