Advertisement
kevin_neven

Untitled

Jun 16th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.27 KB | None | 0 0
  1. <?php
  2. require_once('core/init.php');
  3. if(!isset($_GET["board_link"]) || !isset($_GET["post"])){
  4. header('Location: error.php');
  5. exit;
  6. }
  7. $board_rows = Database::getInstance()->select(
  8. array(
  9. "board" => array("board_name", "board_link", "board_ID")
  10. ),
  11. array(
  12. array("`board`.`board_link`", "=", $_GET["board_link"])
  13. )
  14. )->fetchAll(PDO::FETCH_ASSOC);
  15.  
  16. $post_rows = Database::getInstance()->select(
  17. array(
  18. "post" => array("post_ID")
  19. ),
  20. array(
  21. array("`post`.`post_ID`", "=", $_GET["post"])
  22. )
  23. )->fetchAll(PDO::FETCH_ASSOC);
  24.  
  25. if(count($board_rows) != 1 || count($post_rows) != 1) {
  26. header('Location: 404.php');
  27. exit;
  28. } else{
  29. $row_board = $board_rows[0];
  30. }
  31.  
  32.  
  33. if(isset($_POST["post"])) {
  34. if(User::getInstance()->isLoggedin() === false) {
  35. $_SESSION['errorarray']["post"]["logged"] = "You have to be logged in";
  36. }
  37. if($_FILES["post_image"]["name"] == ""){
  38. $_SESSION['errorarray']["post"]["image"] = "You have to select a image";
  39. }
  40. if(!isset($_SESSION['errorarray']["post"]["image"]) && $_FILES["post_image"]["error"] != 0) {
  41. $_SESSION['errorarray']["post"]["image-error"] = "There was an error with uploading the image";
  42. }
  43. if (!isset($_SESSION['errorarray']["post"])) {
  44. Database::getInstance()->insert(
  45. "post", array(
  46. "message" => $_POST["message"],
  47. "user_ID" => User::getInstance()->getID(),
  48. "board_ID" => $row_board["board_ID"],
  49. "post_ID_REF" => $_GET["post"]));
  50. }
  51. }
  52.  
  53. ?>
  54. <!DOCTYPE html>
  55. <html>
  56. <?php include('Include/head.php');?>
  57. <body onload="load_replys(<?php echo $row_board["board_ID"]; ?>, <?php echo $_GET["post"]; ?>)">
  58. <div class="site">
  59. <?php include('Include/menu.php');?>
  60. <div class="container-fluid page">
  61. <div class="row">
  62. <?php include('Include/add.php');?>
  63. <div class="col-md-10 main">
  64. <div class="col-md-10 col-md-offset-1 whatisthis"><?php echo $row_boards["board_name"]; ?></div>
  65.  
  66. <h2>Post/Comment</h2>
  67. <?php display_errors("post"); ?>
  68. <form class="col-md-10" action="<?php echo get_full_url(); ?>" method='post' enctype="multipart/form-data">
  69. <label class="btn btn-default btn-file">Upload<input type="file" name='post_image' style="display: none;"/></label>
  70. Message<textarea name="message"></textarea>
  71. <input type="submit" name="post" value='Post'/>
  72. </form>
  73. <section class="row" id="posts">
  74. <input type='hidden' name='post_ID' value='69' />
  75. </section>
  76. </div>
  77. <?php include('Include/add.php');?>
  78. </div>
  79. </div>
  80.  
  81. <?php include('Include/footer.php');?>
  82. </div>
  83. </body>
  84.  
  85. </html>
  86.  
  87.  
  88.  
  89. php file for the ajax call...
  90. <?php
  91. require_once('../core/init.php');
  92. /*
  93. RenderASSOC::getInstance()->element(
  94. Database::getInstance()->query("
  95. SELECT
  96. board.board_link,
  97. post.*,
  98. image.image_path_thumb,
  99. image.name,
  100. user.user_username
  101. FROM
  102. post
  103. LEFT JOIN
  104. image ON post.post_image_ID = image.image_ID
  105. LEFT JOIN
  106. user ON post.user_ID = user.user_ID
  107. LEFT JOIN
  108. board ON post.board_ID = board.board_ID
  109. WHERE
  110. post.board_ID = ? AND `post`.`post_ID` = ? AND `post`.`post_ID_REF` IS NULL
  111. ORDER BY `time_of_post` DESC", array($_POST["board_ID"], $_POST["post_ID"]))->fetch(PDO::FETCH_ASSOC),
  112. "<article class='col-lg-12 col-md-12 col-xs-12 container-fluid top-post'>
  113. <h1>:post_name:</h1>
  114. <div class='col-md-3 col-s-2'>
  115. <a class='thumbnail' href='#'>
  116. <img class='img-responsive' src=':image_path_thumb:' alt=':name:'/>
  117. </a>
  118. </div>
  119. <small>By: </small><strong><a href='./profile.php?username=:user_username:'>:user_username:</a></strong>
  120. <p>:message:</p>
  121. <input type='hidden' value=':post_ID:' />
  122. </article>"
  123. );*/
  124. $rows_reply = Database::getInstance()->query("
  125. SELECT
  126. board.board_link,
  127. post.*,
  128. image.image_path_thumb,
  129. image.name,
  130. user.user_username
  131. FROM
  132. post
  133. LEFT JOIN
  134. image ON post.post_image_ID = image.image_ID
  135. LEFT JOIN
  136. user ON post.user_ID = user.user_ID
  137. LEFT JOIN
  138. board ON post.board_ID = board.board_ID
  139. WHERE
  140. post.board_ID =? AND `post`.`post_ID_REF` = ? AND `post`.`post_ID` > ?
  141. ORDER BY `time_of_post` DESC", array($_POST["board_ID"], $_POST["post_ID"], $_POST["start_at"]))->fetchAll(PDO::FETCH_ASSOC);
  142. foreach($rows_reply as $row_reply) {
  143. if($row_reply["post_image_ID"] != NULL){
  144. RenderASSOC::getInstance()->element($row_reply,
  145. "<article class='col-lg-8 col-md-8 col-xs-8 container-fluid'>
  146. <div class='col-md-3 col-s-2'>
  147. <a class='thumbnail' href='#'>
  148. <img class='img-responsive' src=':image_path_thumb:' alt=':name:'/>
  149. </a>
  150. </div>
  151. <small>By: </small><strong><a href='./profile.php?username=:user_username:'>:user_username:</a></strong>
  152. <p>:message:</p>
  153. </article>");
  154. } else {
  155. RenderASSOC::getInstance()->element($row_reply,
  156. "<article class='col-lg-8 col-md-8 col-xs-8 container-fluid'>
  157. <small>By: </small><strong><a href='./profile.php?username=:user_username:'>:user_username:</a></strong>
  158. <p>:message:</p>
  159. <input type='hidden' name='post_ID' value=':post_ID:' />
  160. </article>");
  161. }
  162. }
  163. /*RenderASSOC::getInstance()->elements(
  164. $rows_replys,
  165. "<article class='col-lg-8 col-md-8 col-xs-8 container-fluid'>
  166. <div class='col-md-3 col-s-2'>
  167. <a class='thumbnail' href='#'>
  168. <img class='img-responsive' src=':image_path_thumb:' alt=':name:'/>
  169. </a>
  170. </div>
  171. <small>By: </small><strong><a href='./profile.php?username=:user_username:'>:user_username:</a></strong>
  172. <p>:message:</p>
  173. </article>"
  174. );*/
  175.  
  176.  
  177. js function
  178. function load_replys(board_ID, post_ID){
  179. setInterval(
  180. function () {
  181. $.post("ajax/replys.php", {
  182. board_ID: board_ID,
  183. post_ID: post_ID,
  184. start_at: $('input[name=post_ID]').val()
  185. },
  186. function(data,status){
  187. $("#posts").append(data);
  188. });
  189. }, 2000);
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement