if (isset($_GET['p_id'])) { $p_id = $_GET['p_id']; } else { header("Location:blog.php"); } include_once "includes/functions.php"; include_once "classes/DbConnection.class.php"; $db = new DbConnection(); //a new DbConnection object $all_posts_sql = "SELECT * FROM blog_post WHERE post_id={$p_id}"; $all_posts = $db->getRows($all_posts_sql); foreach ($all_posts as $one_post) { $post = $one_post['post']; $post_id = $one_post['post_id']; $out = edit_post_form($p_id, $post); } //end foreach ?> <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <title>Edit a post in the blog</title> </head> <body> <div id="main"> <div id="blog"> <?php echo $out; ?>
function get_all_posts($db, $posts, $db) { // checking likes $ret_text = ""; foreach ($posts as $single_post) { $user_id = file_exists("images/ava/" . $single_post["users_id"] . ".png") ? $single_post["users_id"] : "unknown"; $img = ""; $tmp_img = get_image($single_post["id"]); if ($tmp_img) { $img = '<div class="post_pictures"><img src="' . $tmp_img . '" class="with_shadow2 img_post" ></div>'; } $tmp_arr = $db->DBSelectOne("users", "name, email", array("id" => $single_post["users_id"])); $tmp_username = $tmp_arr ? $tmp_arr["name"] : "Unknown user"; $check_like = check_post_likes($single_post["id"], $_SESSION["user_id"], $db); $like_part = get_like($single_post["id"], $check_like); if (isset($_POST["edit_post_id"]) && $_POST["edit_post_id"] == $single_post["id"]) { $edit_form = edit_post_form($single_post["id"], $db); } else { $edit_form = ""; } $ret_text .= '<div class="single_post"> ' . $edit_form . ' <div class="post_avatar"><img src="images/ava/' . $user_id . '.png" class="img-circle"></div> <div class="post_text"> <div style="float:left;"><h2><a href="index.php?web=profile&email=' . $tmp_arr["email"] . '">' . $tmp_username . '</a></h2></div> <div style="float:right;"> ' . check_rights($single_post["users_id"], $_SESSION["user_id"], $single_post["id"]) . ' </div> <div class="post_time clear_panel">' . get_time(time() - $single_post["time"]) . '</div> <div>' . $single_post["text"] . '<br><br></div> ' . $img . ' <div class="like_counter"> <form method="POST" class="form_nonstyle"> ' . $like_part . ' </form></div>'; $all_comments_arr = $db->DBSelectAll("comments", "id, text, time, posts_id, users_id", array("posts_id" => $single_post["id"])); foreach ($all_comments_arr as $single_comment) { $commentator = $db->DBSelectOne("users", "id, name, email", array("id" => $single_comment["users_id"])); $ret_text .= ' <div class="post_comment"> <div class="comment_avatar"><img src="' . get_ava($commentator["id"]) . '" class="img-circle"></div> <div class="comment_text"> <div style="float:left; font-weight:bold;"><a href="index.php?web=profile&email=' . $commentator["email"] . '">' . $commentator["name"] . '</a></div> <div class="post_time" style="float:right;">' . get_time(time() - $single_comment["time"]) . '</div> <div style="clear:both;"></div> ' . $single_comment["text"] . ' </div> <div class="clear_panel min_size"></div> </div>'; } $ret_text .= '</div> <div class="clear_panel min_size"></div> <div class="new_comment"> <form method="POST" class="new_comment_form" name="new_comment_form" onsubmit="return validate_textarea_newcomment()"> <textarea rows="2" cols="90" maxlength="300" name="comment_textarea" class="form-control" placeholder="Write a comment..."></textarea> <input type="hidden" value="' . $single_post["id"] . '" name="post_id"> <input type="submit" value="Comment" class="btn btn-primary"> </form> </div> <div class="clear_panel"></div></div>'; // end single_post, } return $ret_text; }