Advertisement
Guest User

Untitled

a guest
Nov 20th, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.34 KB | None | 0 0
  1. <?php
  2.  
  3. $id = $_GET['id'];
  4. $DBprofile = getProfile($db, $id); //profile info from database
  5.  
  6. //insert new status/post
  7. if(isset($_GET['isStatus'])){
  8.     $user_ID = $_POST['user_ID'];
  9.     $status = $_POST['status'];
  10.     $filename = basename ($_FILES["uploadImage"]["name"]);
  11. //     $target = "img/$filename";
  12. //     $fileType = pathinfo($filename, PATHINFO_EXTENSION);
  13.     insertStatus($db, $user_ID, $status, $filename);
  14.  }
  15.  
  16. //likes
  17. if(isset($_GET['like'])){
  18.   $post_ID = $_GET['post_ID'];
  19.   $sql = "UPDATE post
  20.      SET likes=likes+1
  21.      WHERE post_ID = $post_ID";
  22.   $statement = $db->query($sql);
  23. }
  24.  
  25. //insert new comments
  26. if(isset($_GET['isComment'])){
  27.     $post_ID = $_POST['post_ID'];
  28.     $comment_text = $_POST['comment_text'];
  29.     insertComments($db, $id, $post_ID, $comment_text);
  30.  }
  31.  
  32.  
  33. //SHOW profile image
  34. $profile = "
  35.     <div class='profile_image'>
  36.         <img class='postimg' src = 'img/$DBprofile->image' alt = 'my portrait' />
  37.     </div>
  38.     <p>$DBprofile->name</p>
  39. ";
  40.  
  41. //insert Status
  42. $insertStatus = "
  43.     <form method='post' action='?page=profile&id=$id&isStatus=1' enctype='multipart/form-data'><br />
  44.         <label for='status_text'>Status</label><br />
  45.         <textarea id='status_text' name='status'></textarea><br />
  46.         <img src='img/graphics/cloud.svg' alt='cloud upload' />
  47.         <input type='file' id='uploadImage' name='uploadImage'>
  48.         <input type='submit' id='submit_status' value='Submit status'>
  49.         <input type='hidden' name='user_ID' value='$id'>
  50.    </form>
  51. ";
  52.  
  53. //SHOW posts
  54. $posts = ""; //initialisation
  55. $allPosts = getAllPosts($db, $id); //all posts from database
  56. while( $aPost = $allPosts->fetchObject() ) {
  57.     //begin a post
  58.     $posts.= "<li  class='apost'>";
  59.     //timestamp
  60.     $posts.= "<p class='timestamp'>$aPost->name $aPost->time";
  61.     //delete button    
  62.     if($id == $aPost->user_ID) {
  63.     $posts.= "<a href='?page=deletePost&post_ID=$aPost->post_ID&id=$id'>delete post </a>";
  64.     }
  65.     $posts.= "</p>";
  66.     //image in the post
  67.     if($aImagePost = $aPost->image){
  68.         $posts .= "<img class='postimg' src='img/$aImagePost' alt='image post' />";
  69.     }  
  70.     //status text
  71.     $posts .= "<p>$aPost->status</p>"; 
  72.    
  73.     //likes
  74.     $posts .= "
  75.      <div class='likes'>
  76.        <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>
  77.        $aPost->likes persons like this
  78.      </div>";
  79.    
  80.     //comments
  81.     //form
  82.     $posts.= "<p>
  83.         <form method='post' action='?page=profile&id=$id&isComment=1' class='comment_form'>
  84.             <label for='status_text'>Comment</label><br />
  85.            <textarea class='comment_text' name='comment_text'></textarea><br />
  86.            <input type='submit' class='submit_comment' value='Submit'>
  87.            <input type='hidden' name='post_ID' value='$aPost->post_ID'>
  88.        </form>
  89.    </p>";
  90.     //show all comments from a post
  91.     $allComments = getComments($db, $aPost->post_ID);
  92.     if ($allComments) {
  93.       $posts .="<ul class='comment'>";
  94.       while($aComment = $allComments->fetchObject()){
  95.         $posts .= "<li>$aComment->name $aComment->date: $aComment->comment_text</li>";
  96.       }
  97.       $posts .="</ul>";
  98.     }
  99.    
  100.    
  101.     $posts.= "</li>";
  102.     //end a post
  103. }
  104.  
  105. //put all the content together
  106. $content = "
  107.     <section>
  108.         <article id='profile'>
  109.             $profile
  110.         </article>
  111.         <article id='status'>
  112.             $insertStatus
  113.             <ul id='posts'>
  114.                 $posts
  115.             </ul>
  116.         </article>
  117.     </section>
  118. ";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement