Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $id = $_GET['id'];
- $DBprofile = getProfile($db, $id); //profile info from database
- //insert new status/post
- if(isset($_GET['isStatus'])){
- $user_ID = $_POST['user_ID'];
- $status = $_POST['status'];
- $filename = basename ($_FILES["uploadImage"]["name"]);
- // $target = "img/$filename";
- // $fileType = pathinfo($filename, PATHINFO_EXTENSION);
- insertStatus($db, $user_ID, $status, $filename);
- }
- //likes
- if(isset($_GET['like'])){
- $post_ID = $_GET['post_ID'];
- $sql = "UPDATE post
- SET likes=likes+1
- WHERE post_ID = $post_ID";
- $statement = $db->query($sql);
- }
- //insert new comments
- if(isset($_GET['isComment'])){
- $post_ID = $_POST['post_ID'];
- $comment_text = $_POST['comment_text'];
- insertComments($db, $id, $post_ID, $comment_text);
- }
- //SHOW profile image
- $profile = "
- <div class='profile_image'>
- <img class='postimg' src = 'img/$DBprofile->image' alt = 'my portrait' />
- </div>
- <p>$DBprofile->name</p>
- ";
- //insert Status
- $insertStatus = "
- <form method='post' action='?page=profile&id=$id&isStatus=1' enctype='multipart/form-data'><br />
- <label for='status_text'>Status</label><br />
- <textarea id='status_text' name='status'></textarea><br />
- <img src='img/graphics/cloud.svg' alt='cloud upload' />
- <input type='file' id='uploadImage' name='uploadImage'>
- <input type='submit' id='submit_status' value='Submit status'>
- <input type='hidden' name='user_ID' value='$id'>
- </form>
- ";
- //SHOW posts
- $posts = ""; //initialisation
- $allPosts = getAllPosts($db, $id); //all posts from database
- while( $aPost = $allPosts->fetchObject() ) {
- //begin a post
- $posts.= "<li class='apost'>";
- //timestamp
- $posts.= "<p class='timestamp'>$aPost->name $aPost->time";
- //delete button
- if($id == $aPost->user_ID) {
- $posts.= "<a href='?page=deletePost&post_ID=$aPost->post_ID&id=$id'>delete post </a>";
- }
- $posts.= "</p>";
- //image in the post
- if($aImagePost = $aPost->image){
- $posts .= "<img class='postimg' src='img/$aImagePost' alt='image post' />";
- }
- //status text
- $posts .= "<p>$aPost->status</p>";
- //likes
- $posts .= "
- <div class='likes'>
- <a href='?page=profile&post_ID=$aPost->post_ID&id=$id&like=1'><img class='icon' src='img/graphics/like.svg' alt='heart'/>Like</a>
- $aPost->likes persons like this
- </div>";
- //comments
- //form
- $posts.= "<p>
- <form method='post' action='?page=profile&id=$id&isComment=1' class='comment_form'>
- <label for='status_text'>Comment</label><br />
- <textarea class='comment_text' name='comment_text'></textarea><br />
- <input type='submit' class='submit_comment' value='Submit'>
- <input type='hidden' name='post_ID' value='$aPost->post_ID'>
- </form>
- </p>";
- //show all comments from a post
- $allComments = getComments($db, $aPost->post_ID);
- if ($allComments) {
- $posts .="<ul class='comment'>";
- while($aComment = $allComments->fetchObject()){
- $posts .= "<li>$aComment->name $aComment->date: $aComment->comment_text</li>";
- }
- $posts .="</ul>";
- }
- $posts.= "</li>";
- //end a post
- }
- //put all the content together
- $content = "
- <section>
- <article id='profile'>
- $profile
- </article>
- <article id='status'>
- $insertStatus
- <ul id='posts'>
- $posts
- </ul>
- </article>
- </section>
- ";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement