aboutsummaryrefslogtreecommitdiff
path: root/_classes/Comment.php
diff options
context:
space:
mode:
authorChristian Cleberg <hello@cleberg.net>2023-05-22 15:18:52 -0500
committerChristian Cleberg <hello@cleberg.net>2023-05-22 15:18:52 -0500
commitdeb20fdfca35c64066fe4e375099350dc77ea408 (patch)
tree8be0f7541652e4e8f89fc4dd603fae7accf4ee24 /_classes/Comment.php
downloadphp-blog-deb20fdfca35c64066fe4e375099350dc77ea408.tar.gz
php-blog-deb20fdfca35c64066fe4e375099350dc77ea408.tar.bz2
php-blog-deb20fdfca35c64066fe4e375099350dc77ea408.zip
initial commit
Diffstat (limited to '_classes/Comment.php')
-rw-r--r--_classes/Comment.php26
1 files changed, 26 insertions, 0 deletions
diff --git a/_classes/Comment.php b/_classes/Comment.php
new file mode 100644
index 0000000..6d4fd48
--- /dev/null
+++ b/_classes/Comment.php
@@ -0,0 +1,26 @@
+<?php
+
+
+class Comment
+{
+ function __construct(string $comment, string $postURL, string $username = 'Anonymous')
+ {
+ $this->timestamp = date('Y-m-d H:i:s');
+ $this->username = $username;
+ $this->comment = $comment;
+ $this->postURL = $postURL;
+ }
+
+ function saveComment(string $fileName)
+ {
+ if (file_exists($fileName)) {
+ $sourceData = file_get_contents($fileName);
+ $tempArray = json_decode($sourceData);
+ array_push($tempArray, $this);
+ $jsonData = json_encode($tempArray, JSON_PRETTY_PRINT);
+ file_put_contents($fileName, $jsonData);
+ } else {
+ die('Error: The ' . $fileName . ' file does not exist.');
+ }
+ }
+} \ No newline at end of file