• We just launched and are currently in beta. Join us as we build and grow the community.

Facebook Wall Script Clone (What’s On Your Mind)

qrzba

Anime Culture Researcher
Q Rep
0
0
0
Rep
0
Q Vouches
0
0
0
Vouches
0
Posts
139
Likes
197
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
In this tutorial I’m going to show you how to add a Facebook-like Activity Stream or commonly known as “What’s on your mind?”. This will application will allow the user to enter their thoughts or and post it into the site wall. To start in this tutorial, we’re going to set up first our database table. And this table name comment, and here’s the table structure.

  1. CREATE

    TABLE

    IF

    NOT

    EXISTS

    `comments`

    (
  2. `id`

    INT

    (

    11

    )

    NOT

    NULL

    AUTO_INCREMENT

    ,
  3. `comment_id`

    INT

    (

    11

    )

    NOT

    NULL

    ,
  4. `content`

    text NOT

    NULL

    ,
  5. `author`

    VARCHAR

    (

    255

    )

    NOT

    NULL

    ,
  6. `to`

    INT

    (

    11

    )

    NOT

    NULL

    ,
  7. `created`

    datetime NOT

    NULL

    ,
  8. PRIMARY

    KEY

    (

    `id`

    )
  9. )

    ENGINE=

    MyISAM DEFAULT

    CHARSET=

    latin1 AUTO_INCREMENT

    =

    20

    ;

Next, open the home.php file. Then under the Navigation Tab, and inside the well class. Add the following code:

This code will display the panel with accordion that extend the panel component. This will be available when the user click the Update Status link. And this panel also holds our form and text area for the some comment or share post of the user.

  1. input type="hidden" name="comment_id" value="<?php

    echo

    $_SESSION

    [

    'member_id'

    ]

    ;

    ?>

    ">
  2. <input type="hidden" name="author" value="<?php

    echo

    $_SESSION

    [

    'fName'

    ]

    .

    ' '

    .

    $_SESSION

    [

    'lName'

    ]

    ;

    ?>

    ">
  3. <input type="hidden" name="to" value="<?php

    echo

    $_SESSION

    [

    'member_id'

    ]

    ;

    ?>

    ">
  4. <textarea class="form-control" name="content" placeholder="What's on your mind?"></textarea>

  5. </div>
  6. <div class="panel-footer" align="right">
  7. <button class="btn btn-primary btn-sm" type="submit" name="share">Share</button>
  8. </div>
  9. </div>
  10. </form>
  11. </div>
  12. </div>

After adding the code inside the well class, we will test it using our browser. And it should look like as shown below.

untitled_4.png


Next, we’re going to create a new PHP file called “save_post.php”. And this file will process the submitted data of the user and save it to the database. And the following code:

  1. <?php
  2. require_once

    (

    "includes/initialize.php"

    )

    ;

  3. $comment_id

    =

    $_POST

    [

    'comment_id'

    ]

    ;
  4. $content

    =

    $_POST

    [

    'content'

    ]

    ;
  5. $author

    =

    $_POST

    [

    'author'

    ]

    ;
  6. $destination

    =

    $_POST

    [

    'to'

    ]

    ;
  7. $created

    =

    strftime

    (

    "%Y-%m-%d

    %H:%M:%S"

    ,

    time

    (

    )

    )

    ;


  8. global

    $mydb

    ;
  9. $mydb

    ->

    setQuery

    (

    "INSERT INTO `philsocialdb`.`comments` (`id`, `comment_id`, `content`, `author`, `to`, `created`)
  10. VALUES (NULL, '{$comment_id}

    ', '{$content}

    ', '{$author}

    ', '{$destination}

    ', '{$created}

    ');"

    )

    ;
  11. $mydb

    ->

    executeQuery

    (

    )

    ;

  12. if

    (

    $mydb

    ->

    affected_rows

    (

    )

    ==

    1

    )

    {

  13. echo

    "<script type=\"

    text/javascript\"

    >
  14. //alert(\"

    );
  15. window.location='home.php';
  16. </script>"

    ;

  17. }

    else

    {
  18. echo

    "<script type=\"

    text/javascript\"

    >
  19. alert(\"

    );
  20. </script>"

    ;
  21. }


  22. ?>

At this time, we will now add code for listing the user post on the social networking site wall. And here’s the following code:

  1. <?php
  2. global

    $mydb

    ;
  3. $mydb

    ->

    setQuery

    (

    "SELECT * from comments where comment_id="

    .

    $_SESSION

    [

    'member_id'

    ]

    .

    " ORDER BY created DESC"

    )

    ;
  4. $cur

    =

    $mydb

    ->

    loadResultList

    (

    )

    ;

  5. echo

    '<div class="table table-responsive" border="0">'

    ;
  6. echo

    '<table>'

    ;
  7. echo

    '<tr>'

    ;

  8. foreach

    (

    $cur

    as

    $comm

    )

    {
  9. $mydb

    ->

    setQuery

    (

    "SELECT * FROM photos WHERE `member_id`='{$_SESSION['member_id']}

    '"

    )

    ;
  10. $propic

    =

    $mydb

    ->

    loadResultList

    (

    )

    ;
  11. if

    (

    $mydb

    ->

    affected_rows

    (

    )

    ==

    0

    )

    {
  12. echo

    '<td rowspan="2" width="70px" height="70px"><img src="./uploads/p.jpg" class="img-object" width="50px" height=50px" /></td>'

    ;

  13. }
  14. foreach

    (

    $propic

    as

    $obj

    )

    {
  15. echo

    '<td rowspan="2" width="70px" height="70px">'

    ;
  16. echo

    '<img src="./uploads/'

    .

    $obj

    ->

    filename

    .

    '" class="img-object" width="50px" height="50px" />'

    ;
  17. echo

    '</td>'

    ;
  18. }
  19. echo

    '</tr>'

    ;

  20. echo

    '<tr>'

    ;
  21. echo

    '<td><strong><a href="home.php?id='

    .

    $_SESSION

    [

    'member_id'

    ]

    .

    '">'

    .

    $comm

    ->

    author

    .

    '</a></strong>'

    ;
  22. echo

    '<br/>'

    .

    $comm

    ->

    content

    .

    '</td>'

    ;
  23. echo

    '</tr>'

    ;

  24. }
  25. echo

    '</table>'

    ;
  26. ?>

When you finish adding the code above, you can test it and it will look like as shown below:

s2_0.png


After completing the code above, here’s all the code for “home.php”.

  1. <?php
  2. require_once

    (

    "includes/initialize.php"

    )

    ;
  3. ?>
  4. <!DOCTYPE html>
  5. <html lang="en">
  6. <head>
  7. <meta charset="utf-8">
  8. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  9. <meta name="description" content="">
  10. <meta name="author" content="">
  11. <link rel="shortcut icon" href="">

  12. <title>Philsocial</title>

  13. <!-- Bootstrap core CSS -->
  14. <link href="css/bootstrap.css" rel="stylesheet">

  15. <!-- Custom styles for this template -->
  16. <link href="jumbotron.css" rel="stylesheet">

  17. <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
  18. <!--[if lt IE 9]>
  19. <script src="../../assets/js/html5shiv.js"></script>
  20. <script src="../../assets/js/respond.min.js"></script>
  21. <![endif]-->
  22. <?php
  23. //login confirmation
  24. confirm_logged_in(

    )

    ;
  25. ?>
  26. </head>

  27. <body>

  28. <div class="navbar navbar-inverse navbar-fixed-top">
  29. <div class="container">
  30. <div class="navbar-header">
  31. <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
  32. <span class="icon-bar"></span>
  33. <span class="icon-bar"></span>
  34. <span class="icon-bar"></span>
  35. </button>
  36. <a class="navbar-brand" href="home.php"><B>Philsocial</B></a>
  37. </div>
  38. <form class="navbar-form navbar-left">
  39. <div class="form-group">
  40. <div class="rows">
  41. <input type="text" placeholder="Email" class="form-control" size="40">
  42. </div>
  43. </div>
  44. </form>
  45. <div class="navbar-collapse collapse">

  46. <form class="navbar-form navbar-right">
  47. <ul class="nav navbar-nav">
  48. <li class="active"><a href="home.php">Home</a></li>
  49. <li class="dropdown">

  50. <a href="#" class="dropdown-toggle" data-toggle="dropdown">
  51. <?php
  52. //retrieve session variable
  53. echo

    $_SESSION

    [

    'fName'

    ]

    ;

    ?>
  54. <b class="caret"></b>
  55. </a>

  56. <ul class="dropdown-menu">
  57. <li><a href="#">My Profile</a></li>
  58. <li><a href="#">Edit profile</a></li>
  59. <li><a href="#">Edit profile Picture</a></li>
  60. <li><a href="#">Customize profile</a></li>
  61. <li><a href="#">Edit Work and Education</a></li>

  62. </ul>
  63. </li>
  64. <li class="dropdown">

  65. <a href="#" class="dropdown-toggle" data-toggle="dropdown">Account<b class="caret"></b></a>

  66. <ul class="dropdown-menu">
  67. <li><a href="#">Account Settings</a></li>
  68. <li><a href="#">Privacy Settings</a></li>
  69. <li><a href="#">Manage Social Accounts</a></li>
  70. <li><a href="#">Manage Credits</a></li>
  71. <li><a href="logout.php">Logout</a></li>

  72. </ul>
  73. </li>
  74. </ul>
  75. </form>
  76. </div><!--/.navbar-collapse -->
  77. </div>
  78. </div>
  79. <div class="container">
  80. <div class="well">

  81. <div class="row">
  82. <div class="col-xs-6 col-md-2">
  83. <a data-target="#myModal" data-toggle="modal" href="" title=
  84. "Click here to Change Image.">
  85. <?php

  86. $mydb

    ->

    setQuery

    (

    "SELECT * FROM photos WHERE `member_id`='{$_SESSION['member_id']}

    '"

    )

    ;
  87. $cur

    =

    $mydb

    ->

    loadResultList

    (

    )

    ;
  88. if

    (

    $mydb

    ->

    affected_rows

    (

    )

    ==

    0

    )

    {
  89. echo

    '<img src="./uploads/p.jpg" class="img-thumbnail" width="200px" height="100px" />'

    ;

  90. }
  91. foreach

    (

    $cur

    as

    $object

    )

    {

  92. echo

    '<img src="./uploads/'

    .

    $object

    ->

    filename

    .

    '" class="img-thumbnail" width="200px" height="100px" />'

    ;

  93. }
  94. ?>
  95. </a>

  96. <!-- Modal -->
  97. <div class="modal fade" id="myModal" tabindex="-1">
  98. <div class="modal-dialog">
  99. <div class="modal-content">
  100. <div class="modal-header">
  101. <button class="close" data-dismiss="modal" type=
  102. "button">×</button>

  103. <h4 class="modal-title" id="myModalLabel">Choose Your best
  104. picture for your Profile.</h4>
  105. </div>

  106. <form action="save_photo.php" enctype="multipart/form-data" method=
  107. "post">
  108. <div class="modal-body">
  109. <div class="form-group">
  110. <div class="rows">
  111. <div class="col-md-12">
  112. <div class="rows">
  113. <div class="col-md-8">
  114. <input name="MAX_FILE_SIZE" type=
  115. "hidden" value="1000000"> <input id=
  116. "upload_file" name="upload_file" type=
  117. "file">
  118. </div>

  119. <div class="col-md-4"></div>
  120. </div>
  121. </div>
  122. </div>
  123. </div>
  124. </div>

  125. <div class="modal-footer">
  126. <button class="btn btn-default" data-dismiss="modal" type=
  127. "button">Close</button> <button class="btn btn-primary"
  128. name="savephoto" type="submit">Save Photo</button>
  129. </div>
  130. </form>
  131. </div><!-- /.modal-content -->
  132. </div><!-- /.modal-dialog -->
  133. </div><!-- /.modal -->
  134. </div>

  135. <div class="col-xs-12 col-sm-6 col-md-8">
  136. <div class="page-header">
  137. <h3><?php

    echo

    $_SESSION

    [

    'fName'

    ]

    .

    ' '

    .

    $_SESSION

    [

    'lName'

    ]

    ;

    ?>

    </h3>
  138. </div>

  139. <ul class="nav nav-tabs">
  140. <li class="active">
  141. <a href="#">Wall</a>
  142. </li>

  143. <li>
  144. <a href="info.php">Info</a>
  145. </li>

  146. <li>
  147. <a href="message.php">Messages</a>
  148. </li>
  149. </ul>
  150. <div class="well">
  151. <div class="panel-group" id="accordion">
  152. <div class="panel panel-primary">
  153. <div class="panel-heading">
  154. <h5 class="panel-title">
  155. <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" title="What's on your mind?">
  156. Update Status
  157. </a>
  158. </h5>
  159. </div>

  160. <form action="save_post.php" method="POST">
  161. <div id="collapseOne" class="panel-collapse collapse">
  162. <div class="panel-body">
  163. <input type="hidden" name="comment_id" value="<?php

    echo

    $_SESSION

    [

    'member_id'

    ]

    ;

    ?>

    ">
  164. <input type="hidden" name="author" value="<?php

    echo

    $_SESSION

    [

    'fName'

    ]

    .

    ' '

    .

    $_SESSION

    [

    'lName'

    ]

    ;

    ?>

    ">
  165. <input type="hidden" name="to" value="<?php

    echo

    $_SESSION

    [

    'member_id'

    ]

    ;

    ?>

    ">
  166. <textarea class="form-control" name="content" placeholder="What's on your mind?"></textarea>

  167. </div>
  168. <div class="panel-footer" align="right">
  169. <button class="btn btn-primary btn-sm" type="submit" name="share">Share</button>
  170. </div>
  171. </div>
  172. </form>
  173. </div>
  174. </div>
  175. <?php
  176. global

    $mydb

    ;
  177. $mydb

    ->

    setQuery

    (

    "SELECT * from comments where comment_id="

    .

    $_SESSION

    [

    'member_id'

    ]

    .

    " ORDER BY created DESC"

    )

    ;
  178. $cur

    =

    $mydb

    ->

    loadResultList

    (

    )

    ;

  179. echo

    '<div class="table table-responsive" border="0">'

    ;
  180. echo

    '<table>'

    ;
  181. echo

    '<tr>'

    ;

  182. foreach

    (

    $cur

    as

    $comm

    )

    {
  183. $mydb

    ->

    setQuery

    (

    "SELECT * FROM photos WHERE `member_id`='{$_SESSION['member_id']}

    '"

    )

    ;
  184. $propic

    =

    $mydb

    ->

    loadResultList

    (

    )

    ;
  185. if

    (

    $mydb

    ->

    affected_rows

    (

    )

    ==

    0

    )

    {
  186. echo

    '<td rowspan="2" width="70px" height="70px"><img src="./uploads/p.jpg" class="img-object" width="50px" height=50px" /></td>'

    ;

  187. }
  188. foreach

    (

    $propic

    as

    $obj

    )

    {
  189. echo

    '<td rowspan="2" width="70px" height="70px">'

    ;
  190. echo

    '<img src="./uploads/'

    .

    $obj

    ->

    filename

    .

    '" class="img-object" width="50px" height="50px" />'

    ;
  191. echo

    '</td>'

    ;
  192. }
  193. echo

    '</tr>'

    ;

  194. echo

    '<tr>'

    ;
  195. echo

    '<td><strong><a href="home.php?id='

    .

    $_SESSION

    [

    'member_id'

    ]

    .

    '">'

    .

    $comm

    ->

    author

    .

    '</a></strong>'

    ;
  196. echo

    '<br/>'

    .

    $comm

    ->

    content

    .

    '</td>'

    ;
  197. echo

    '</tr>'

    ;

  198. }
  199. echo

    '</table>'

    ;
  200. ?>

  201. </div>

  202. </div>
  203. </div>
  204. </div>
  205. </div>



  206. </body>
  207. </html>

  208. <hr>

  209. </div> <!-- /container -->
  210. <footer>
  211. <p align="center">&copy; Philsocial 2013</p>
  212. </footer>
  213. <!-- Bootstrap core JavaScript
  214. ================================================== -->
  215. <!-- Placed at the end of the document so the pages load faster -->
  216. <script src="assets/js/tooltip.js"></script>
  217. <script src="assets/js/jquery.js"></script>
  218. <script src="js/bootstrap.min.js"></script>
  219. </body>
  220. </html>

 

452,496

332,845

332,853

Top