Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('core/init.php');
- if(!isset($_GET["board_link"]) || !isset($_GET["post"])){
- header('Location: error.php');
- exit;
- }
- $board_rows = Database::getInstance()->select(
- array(
- "board" => array("board_name", "board_link", "board_ID")
- ),
- array(
- array("`board`.`board_link`", "=", $_GET["board_link"])
- )
- )->fetchAll(PDO::FETCH_ASSOC);
- $post_rows = Database::getInstance()->select(
- array(
- "post" => array("post_ID")
- ),
- array(
- array("`post`.`post_ID`", "=", $_GET["post"])
- )
- )->fetchAll(PDO::FETCH_ASSOC);
- if(count($board_rows) != 1 || count($post_rows) != 1) {
- header('Location: 404.php');
- exit;
- } else{
- $row_board = $board_rows[0];
- }
- if(isset($_POST["post"])) {
- if(User::getInstance()->isLoggedin() === false) {
- $_SESSION['errorarray']["post"]["logged"] = "You have to be logged in";
- }
- if($_FILES["post_image"]["name"] == ""){
- $_SESSION['errorarray']["post"]["image"] = "You have to select a image";
- }
- if(!isset($_SESSION['errorarray']["post"]["image"]) && $_FILES["post_image"]["error"] != 0) {
- $_SESSION['errorarray']["post"]["image-error"] = "There was an error with uploading the image";
- }
- if (!isset($_SESSION['errorarray']["post"])) {
- Database::getInstance()->insert(
- "post", array(
- "message" => $_POST["message"],
- "user_ID" => User::getInstance()->getID(),
- "board_ID" => $row_board["board_ID"],
- "post_ID_REF" => $_GET["post"]));
- }
- }
- ?>
- <!DOCTYPE html>
- <html>
- <?php include('Include/head.php');?>
- <body onload="load_replys(<?php echo $row_board["board_ID"]; ?>, <?php echo $_GET["post"]; ?>)">
- <div class="site">
- <?php include('Include/menu.php');?>
- <div class="container-fluid page">
- <div class="row">
- <?php include('Include/add.php');?>
- <div class="col-md-10 main">
- <div class="col-md-10 col-md-offset-1 whatisthis"><?php echo $row_boards["board_name"]; ?></div>
- <h2>Post/Comment</h2>
- <?php display_errors("post"); ?>
- <form class="col-md-10" action="<?php echo get_full_url(); ?>" method='post' enctype="multipart/form-data">
- <label class="btn btn-default btn-file">Upload<input type="file" name='post_image' style="display: none;"/></label>
- Message<textarea name="message"></textarea>
- <input type="submit" name="post" value='Post'/>
- </form>
- <section class="row" id="posts">
- <input type='hidden' name='post_ID' value='69' />
- </section>
- </div>
- <?php include('Include/add.php');?>
- </div>
- </div>
- <?php include('Include/footer.php');?>
- </div>
- </body>
- </html>
- php file for the ajax call...
- <?php
- require_once('../core/init.php');
- /*
- RenderASSOC::getInstance()->element(
- Database::getInstance()->query("
- SELECT
- board.board_link,
- post.*,
- image.image_path_thumb,
- image.name,
- user.user_username
- FROM
- post
- LEFT JOIN
- image ON post.post_image_ID = image.image_ID
- LEFT JOIN
- user ON post.user_ID = user.user_ID
- LEFT JOIN
- board ON post.board_ID = board.board_ID
- WHERE
- post.board_ID = ? AND `post`.`post_ID` = ? AND `post`.`post_ID_REF` IS NULL
- ORDER BY `time_of_post` DESC", array($_POST["board_ID"], $_POST["post_ID"]))->fetch(PDO::FETCH_ASSOC),
- "<article class='col-lg-12 col-md-12 col-xs-12 container-fluid top-post'>
- <h1>:post_name:</h1>
- <div class='col-md-3 col-s-2'>
- <a class='thumbnail' href='#'>
- <img class='img-responsive' src=':image_path_thumb:' alt=':name:'/>
- </a>
- </div>
- <small>By: </small><strong><a href='./profile.php?username=:user_username:'>:user_username:</a></strong>
- <p>:message:</p>
- <input type='hidden' value=':post_ID:' />
- </article>"
- );*/
- $rows_reply = Database::getInstance()->query("
- SELECT
- board.board_link,
- post.*,
- image.image_path_thumb,
- image.name,
- user.user_username
- FROM
- post
- LEFT JOIN
- image ON post.post_image_ID = image.image_ID
- LEFT JOIN
- user ON post.user_ID = user.user_ID
- LEFT JOIN
- board ON post.board_ID = board.board_ID
- WHERE
- post.board_ID =? AND `post`.`post_ID_REF` = ? AND `post`.`post_ID` > ?
- ORDER BY `time_of_post` DESC", array($_POST["board_ID"], $_POST["post_ID"], $_POST["start_at"]))->fetchAll(PDO::FETCH_ASSOC);
- foreach($rows_reply as $row_reply) {
- if($row_reply["post_image_ID"] != NULL){
- RenderASSOC::getInstance()->element($row_reply,
- "<article class='col-lg-8 col-md-8 col-xs-8 container-fluid'>
- <div class='col-md-3 col-s-2'>
- <a class='thumbnail' href='#'>
- <img class='img-responsive' src=':image_path_thumb:' alt=':name:'/>
- </a>
- </div>
- <small>By: </small><strong><a href='./profile.php?username=:user_username:'>:user_username:</a></strong>
- <p>:message:</p>
- </article>");
- } else {
- RenderASSOC::getInstance()->element($row_reply,
- "<article class='col-lg-8 col-md-8 col-xs-8 container-fluid'>
- <small>By: </small><strong><a href='./profile.php?username=:user_username:'>:user_username:</a></strong>
- <p>:message:</p>
- <input type='hidden' name='post_ID' value=':post_ID:' />
- </article>");
- }
- }
- /*RenderASSOC::getInstance()->elements(
- $rows_replys,
- "<article class='col-lg-8 col-md-8 col-xs-8 container-fluid'>
- <div class='col-md-3 col-s-2'>
- <a class='thumbnail' href='#'>
- <img class='img-responsive' src=':image_path_thumb:' alt=':name:'/>
- </a>
- </div>
- <small>By: </small><strong><a href='./profile.php?username=:user_username:'>:user_username:</a></strong>
- <p>:message:</p>
- </article>"
- );*/
- js function
- function load_replys(board_ID, post_ID){
- setInterval(
- function () {
- $.post("ajax/replys.php", {
- board_ID: board_ID,
- post_ID: post_ID,
- start_at: $('input[name=post_ID]').val()
- },
- function(data,status){
- $("#posts").append(data);
- });
- }, 2000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement