PHP PROJECT

README.md

Comments php class with replies and like buttons

It can display forms and buttons using the Bootstrap framework to let the user enter comments, replies to comments and click to like or dislike a comment.

Files


NameTypeSizeLast Modified
config.php phpfile icon 617 08 December 2015 10:24:30
badwordslist.txt textfile icon 2213 08 December 2015 10:24:30
comment.php phpfile icon 3693 08 December 2015 10:24:30
like-dislike.php phpfile icon 1751 08 December 2015 10:24:30
comment-template.php phpfile icon 1705 08 December 2015 10:24:30
comment.sql sqlfile icon 468 01 February 2017 04:13:02
bootstrapcomment.php phpfile icon 7061 08 December 2015 10:24:30

Source

  1. <?
  2. /**
  3.  * PHP Comment Class
  4.  * @author vishv23@yahoo.com - http://v23.in
  5.  * @version 1.0.0
  6.  * @date November 17, 2015
  7. */
  8. include "config.php";
  9. include "bootstrapcomment.php";
  10. //----------edit if require-------------------------------
  11. $fieldRequire=array("name"=>"","comment"=>"");
  12. //-----------------------------------------
  13. $co = new bootstrapcomment("localhost",$dbuser$dbpass,$dbname);
  14. //------------------Save Comment---------------
  15. if(isset($_POST['uri']) && $_POST['uri'] == $_SERVER['REQUEST_URI']){
  16. $co->save($_POST['comment'],$_POST['name'],$_SERVER['REQUEST_URI'],time(),$_SERVER['REMOTE_ADDR'],$_POST['id']);
  17. }
  18. //-----------------------------------
  19. $totalRow=$co->totalRows($_SERVER['REQUEST_URI']);
  20. if($totalRow $perPageDisplay )
  21. $tgroup=round($totalRow $perPageDisplay );
  22. else
  23. $tgroup=1;
  24. $output['script'] = '<script>
  25.   $(".replyin").hide();
  26.     
  27.       $(".rreply").click(function(){
  28.         var id = $(this).attr("aria-value");
  29.         
  30.             if($(".replyin").is(":visible")){
  31.                 $(".replyin").hide();
  32.                 $("#id").val(0);
  33.                  $("#freply").show();
  34.             } else {
  35.             $("#id").val(id);
  36.                 $(".replyin").show();
  37.                   $("#freply").hide();
  38.                   $("#name").focus();
  39.             }
  40.            
  41.             return false;
  42.         });
  43.         
  44. $(document).ready(function() {
  45. $(".glyphicon-thumbs-up").one("click",function(){
  46. var id = $(this).attr("aria-value");
  47. $.post("/comment/like-dislike.php",{"type":"like","id":id}, function(data){
  48.   
  49.    
  50.                     $("#UP"+id).text(" " +data);
  51.                 })
  52. });
  53. $(".glyphicon-thumbs-down").one("click",function(){
  54. var id = $(this).attr("aria-value");
  55.  $.ajax({
  56.     url : "/comment/like-dislike.php",
  57.     type: "POST",
  58.     data : {"type": "dislike","id":id},
  59.     success: function(data)
  60.     {
  61.        $("#DOWN"+id).text(" " +data);
  62.     }
  63. });
  64. $(this).text(d + "v");
  65. });    
  66. });    
  67. </script>
  68. ';
  69. $output['maincontent'] ='
  70. <p>ALL COMMENTS '.$totalRow.'</p>
  71. <div class="form-group rreply" id="freply">
  72.       <input type="text" class="form-control ">
  73.   </div>
  74.  
  75. <div class="form-group replyin">
  76.  <form method="post" action="'.$_SERVER['REQUEST_URI'].'" id="foo">
  77. <input type="hidden" name="tm" value="'.time().'"/>
  78. <input type="hidden" name="uri" value="'.$_SERVER['REQUEST_URI'].'"/>
  79. <input type="hidden" name="id" id="id" value="0"/>
  80.  <div class="form-group">
  81.       <input type="text" class="form-control" id="name" name="name"  placeholder="Name...">
  82.   </div>
  83.   
  84.    <div class="form-group">
  85.       <textarea class="form-control" id="comment" name="comment" row="5" placeholder="Add a public comment..."></textarea>
  86.   </div>
  87.   <div class="form-group">
  88.       <button type="submit" class="btn btn-info" id="submit">Comment</button>
  89.   </div>
  90. </form>
  91.   </div>
  92. ';
  93. $output['maincontent'] .='<ul>';
  94. $res=$co->fetchCategoryTree(0,$_SERVER['REQUEST_URI'],3," LIMIT 20");
  95.   foreach ($res as $r) {
  96.     $output['maincontent'] .=  $r;
  97.   }
  98. $output['maincontent'] .= '</ul>';
  99. $output['title']="Demo COMMENT";
  100. $output['style']='
  101. <style>
  102. .showmore{padding: 10px;width: 80%; border: 1px solid #777;}
  103. .showmore:hover{background-color: #ddd;}
  104. .bg-info{padding: 10px;border: 1px solid #6CA6CD;font-weight: 700;}
  105. #fo{
  106. background-color: #e5f1ff;
  107. border: 1px solid #b2d7ff;
  108. padding-top: 10px;
  109. margin-bottom: 10px;
  110. }
  111. .panel-body{padding: 10px; color: #777;}
  112. span{
  113. margin-right: 12px;
  114. cursor: pointer;
  115. }
  116. span:hover{
  117. opacity: .2;
  118. }
  119. glyphicon{
  120. }
  121. </style>';
  122. if(is_file"comment-template.php"))
  123. echo $co->render_temp(   "comment-template.php",array("output"=>$output));
  124. unset($output);
  125. ?>

Demo

You can find a demo available here: bootstrap comment

Requirment

  • mySql
  • PHP >= 5.4
  • Apache Server

Contribute

  • Vishv Sahdev

Example

>>

Download