Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once '../vendor/autoload.php';
- include "../lib/Database.php";
- include "../config/config.php";
- include "../helpers/Format.php";
- $db = new Database();
- $fm = new Format();
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- $name = mysqli_real_escape_string($db->link, $fm->validation($_POST['sender']));
- $postComment = mysqli_real_escape_string($db->link, $fm->validation($_POST['comment']));
- $commentId = mysqli_real_escape_string($db->link, $fm->validation($_POST['commentId']));
- if (!empty($name) && !empty($postComment)) {
- $commentQuery = "INSERT INTO `comment`(parent_id,comment,sender) VALUES('$commentId','$postComment','$name')";
- $commentsResult = $db->insert($commentQuery);
- if ($commentsResult) {
- $msg = "<p class='alert alert-success'><span class='fa-layers fa-fw'><i class='fas fa-check-circle fa-2x'></i></span>success</p>";
- $status = array(
- 'error' => 0,
- 'message' => $msg
- );
- } else {
- $msg = "<p class='alert alert-danger'><i class='fas fa-times-circle fa-2x'></i>deny</p>";
- $status = array(
- 'error' => 1,
- 'message' => $msg
- );
- }
- } else {
- $msg = "<p class='alert alert-warning'><i class='fas fa-bell fa-2x'> </i>empty field</p>";
- $status = array(
- 'error' => 2,
- 'message' => $msg
- );
- }
- echo json_encode($status);
- }
- <?php
- ini_set('memory_limit', '1024M');
- require_once __DIR__.'/../vendor/autoload.php';
- include __DIR__.'/../lib/Database.php';
- include __DIR__.'/../config/config.php';
- include __DIR__.'/../lib/Session.php';
- include __DIR__.'/../helpers/Format.php';
- $db = new Database();
- $fm = new Format();
- $commentQuery = "SELECT * FROM `comment` WHERE `parent_id`='0' ORDER BY `id` DESC";
- $result = $db->select($commentQuery);
- $commentReply = '';
- if ($result) {
- while ($cmResult = $result->fetch_assoc()) {
- $commentReply .= ' <div class="panel panel-default">
- <div class="panel-heading">
- <div class="fa-2x text-right" style="border: none;">
- <button class=" btn btn-default delClick" id=" '.$cmResult['id'].'">
- <span class="fa-layers fa-fw" style="background:Mistyrose; border: none;">
- <i class="fa-inverse fas fa-times-circle" style="color: black;" data-fa-transform="shrink-3"> </i>
- </span>
- </button>
- </div>
- <h4>
- <span class= "fa-layers fa-fw">
- <i class="fa-inverse fas fa-user-graduate fa-3x" style=" background:MistyRose" >
- </i> </span> ' . $cmResult["sender"] . '
- </h4>
- <p class="date">' . $fm->DateFormat($cmResult["date"]) . '</p>
- </div>
- <div class="panel-body">
- <p class="comment">' . $fm->textShorten($cmResult["comment"], 70) . '</p>
- <button type="button" class="btn btn-warning reply" id="' . $cmResult["id"] . '">REPLY</button>
- </div>
- </div>';
- $commentReply .= getReply($db, $fm, $cmResult['id']);
- }
- echo $commentReply;
- }
- function getReply($db, $fm, $parentId = 0, $margin = 0) {
- //$fm = new Format();
- //$db = new Database();
- $commentReply = '';
- $getQuery = "SELECT * FROM `comment` WHERE `parent_id`='$parentId'";
- $result = $db->select($getQuery);
- // $count = mysqli_num_rows($result);
- if ($parentId == 0) {
- $margin = 0;
- } else {
- $margin = $margin + 28;
- }
- if (!empty($result) || $result > 0) {
- while ($cmResult = $result->fetch_assoc()) {
- // $fm =new Format();
- $cmDate = $fm->DateFormat($cmResult['date']);
- $shorten = $fm->textShorten($cmResult['comment'], 70);
- $commentReply .= ' <div class="panel_wrapper">
- <div class="panel panel-default" style="margin-left: '. $margin. 'px">
- <div class="panel-heading">
- <div class="fa-2x text-right" style="border: none;">
- <button class=" btn btn-default delClick" id=" '.$cmResult['id'].'">
- <span class="fa-layers fa-fw" style="background:Mistyrose; border: none;">
- <i class="fa-inverse fas fa-times-circle" style="color: black;" data-fa-transform="shrink-3">
- </i>
- </span>
- </button>
- </div>
- <h4>
- <span class="fa-layers fa-fw">
- <i class="fa-inverse fas fa-user-graduate fa-3x"
- data-fa-transform="shrink-8"
- style="background:MistyRose">
- </i>
- </span>
- '. $cmResult["sender"].'
- </h4>
- <p class="date">'.$cmDate.'</p>
- </div>
- <div class="panel-body">
- <p class="comment">'. $shorten.'</p>
- <button type="button" class="btn btn-warning reply" id="'. $cmResult['id'].'">
- REPLY
- </button>
- </div>
- </div>
- </div>';
- $commentReply .= getReply($db, $fm, $cmResult['id'], $margin);
- }
- }
- return $commentReply;
- }
- $(document).ready(function(){
- //$('#all-comments').hide();
- showComments();
- $('#commentForm').on('submit', function(e){
- e.preventDefault();
- //showComments().disable();
- var formData = $(this).serialize();
- // var message = $('#Messages').val();
- $.ajax({
- url: "../scripts/comment.php",
- method: "POST",
- data:
- formData,
- dataType: "JSON",
- success:function(response) {
- if(!response.error) {
- $('#commentForm')[0].reset();
- $('#commentId').val('0');
- showComments();
- $('#message').show().fadeIn('500').html(response.message);
- $('#message').show().fadeOut('500').html(response.message);
- $('#message').show().fadeIn('500').html(response.message);
- $('#message').show().fadeOut('500').html(response.message);
- }else if (response.error) {
- $('#message').show().fadeIn("500").html(response.message);
- $('#message').show().fadeOut("500").html(response.message);
- $('#message').show().fadeIn("500").html(response.message);
- $('#message').show().fadeOut("500").html(response.message);
- }
- }
- });
- //return false;
- });
- $(document).on('click','.reply', function(){
- var commentId = $(this).attr('id');
- $('#commentId').val(commentId);
- $('#name').focus();
- });
- });
- function showComments() {
- $.ajax({
- url:"../scripts/disqus.php",
- type:"POST",
- //dataType: "JSON",
- success:function(response) {
- // $('#all-comments').show();
- $('#showComments').html(response);
- }
- })
- }
- <?php
- //include __DIR__.'/../lib/Session.php';
- include __DIR__.'/../vendor/autoload.php';
- include __DIR__.'/../config/config.php';
- include __DIR__.'/../lib/Database.php';
- $db = new Database();
- $delQuery = "DELETE FROM comment WHERE parent_id= 0";
- $dResult = $db->delete($delQuery);
- /*echo "<pre>";
- var_dump($dResult);
- echo "</pre>";
- die();*/
- if ($dResult) {
- $msg = "<p class='alert alert-success'>
- <i class='fas fa-times-circle fa-2x'>
- </i>Comment deleted Successfully!!
- </p>";
- $status = array(
- 'error' => 3,
- 'message' => $msg
- );
- } else {
- $msg = "<p class='alert alert-info'>
- <i class='fas fa-warning-circle fa-2x'>
- </i>Comment cannot delete.
- </p>";
- $status = array(
- 'error' => 4,
- 'message' => $msg
- );
- }
- echo json_encode($status);
- $(document).on('click','.delClick',function (e) {
- e.preventDefault();
- // var delId = $(this).attr('id');
- deleteComment();
- window.location='../Template/Excellent.php';
- });
- function deleteComment()
- {
- // var data = $(this).attr('id');
- $.ajax({
- url:"../scripts/disqus_template.php",
- type: "POST",
- // data: data,
- dataType: "JSON",
- success: function (response) {
- if(!response.error) {
- $('#delmessage').html(response);
- $('#delmessage').fadeIn('slow').html(response.message);
- }
- }
- });
- return false;
- }
Add Comment
Please, Sign In to add comment