<title>Live Comment System</title> <!-- Bootstrap --> <link href="/public/css/bootstrap.min.css" rel="stylesheet"> <link href="/public/css/styles.css" rel="stylesheet"> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> <!--[if lt IE 9]> <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> <![endif]--> </head> <body> <?php $livecomment = new \App\Controllers\LiveComment(); ?> <input type="hidden" id="lt" value="<?php echo $livecomment->getSingleReply()->created_at; ?> "> <div class="container"> <div class="comments-wrap"> <div class="row"> <div class="col-lg-6 col-lg-offset-3"> <div class="comment-post"> <form id="postComment" class="form-horizontal" action="/helpers/comments.php" method="post"> <textarea class="form-control" name="title" id="title" placeholder="What's in your mind ?"></textarea> <button type="submit" name="submit" class="btn btn-primary btn-sm pull-right no-top-border">Comment</button> </form> </div>
<?php require '../vendor/autoload.php'; require '../config/database.php'; $livecomment = new \App\Controllers\LiveComment(); if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { $comment = $livecomment->getLatestComments($_POST['created_at']); if ($comment) { echo '{"id":"' . $comment->id . '", "title":"' . $comment->title . '", "created_at":"' . $comment->created_at . '"}'; } }
<?php require '../vendor/autoload.php'; require '../config/database.php'; $livecomment = new \App\Controllers\LiveComment(); if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { $reply = $livecomment->postReplies(['title' => $_POST['title'], 'comment_id' => $_POST['comment_id']]); echo '{"title":"' . $reply->title . '", "created_at":"' . $reply->created_at . '"}'; } else { if (isset($_POST['submit2'])) { if ($_POST['title'] != "") { $livecomment->postReplies(['title' => $_POST['title'], 'comment_id' => $_POST['comment_id']]); } header('Location: /'); } }
<?php require '../vendor/autoload.php'; require '../config/database.php'; $livecomment = new \App\Controllers\LiveComment(); if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { $reply = $livecomment->getLatestReplies($_POST['created_at']); if ($reply) { echo '{"id":"' . $reply->id . '", "title":"' . $reply->title . '", "created_at":"' . $reply->created_at . '", "comment_id":"' . $reply->comment_id . '"}'; } }
<?php require '../vendor/autoload.php'; require '../config/database.php'; $livecomment = new \App\Controllers\LiveComment(); if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { $comment = $livecomment->postComments(['title' => $_POST['title']]); echo '{"id":"' . $comment->id . '", "title":"' . $comment->title . '", "created_at":"' . $comment->created_at . '"}'; } else { if (isset($_POST['submit'])) { if ($_POST['title'] != "") { $livecomment->postComments(['title' => $_POST['title']]); } header('Location: /'); } }