Simple Facebook Wall

In this tutorial, we are going to create our own version of Simple Facebook Wall. Using jQuery and PHP. I will explain how I added code behind the “Share button” so that when clicked, it will post the content of the text area as wall post. Sample Code PHP and Html Form
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Simple Facebook Wall</title>
  5. <link rel="stylesheet" href="css/style.css" type="text/css"/>
  6. <link rel="stylesheet" href="css/wall.css" type="text/css"/>
  7. <link type="text/css" rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
  8. <script src="js/jquery.min.js"></script>
  9. <script type="text/javascript" src="js/jquery.livequery.js"></script>
  10. <body>
  11. <nav class="navbar navbar-default">
  12. <d iv class="container-fluid">
  13. <div class="navbar-header">
  14. <a class="navbar-brand" href="index.php"><a><img src="image/icontexto-inside-facebook.png" width="50px" height="50px"></a>&nbspFacebook</a>
  15. </div>
  16. </div>
  17. </nav>
  18. <div id="wrapper">
  19. <form>
  20. <input name="current_img" id="current_img" type="hidden"/>
  21. <input name="ajax_flag" id="ajax_flag" type="hidden"/>
  22. </form>
  23. <div>
  24. <div id="fetched_data">
  25. <div id="loader"> </div>
  26. <div id="ajax_content"></div>
  27. </div>
  28. </div>
  29. <div id="textareaWrap">
  30. <textarea id="wall"></textarea>
  31. <div id="sharebtn"> <a class="button Share" style="" id="shareButton"> Share</a> </div>
  32. </div>
  33. <div id="wallz" class="fb_wall">
  34. <ul id="posts">
  35. <li> <img src="image/avatar.png" class="avatar">
  36. <div class="status">
  37. <h2><a href="#" target="_blank">Sourcecodester</a></h2>
  38. <p class="message">The Use of a New Bootstrap Modal</p>
  39. <div class="img_attachment"> <img class="external_pic" src="image/cover.jpg">
  40. <div class="data">
  41. <p class="name"><a href="http://www.sourcecodester.com/tutorials/other/10617/how-use-modal-bootstrap.html"_blank">How to use Modal Bootstrap</a></p>
  42. <p class="caption">www.sourcecodester.com</p>
  43. <p class="description">Good day everyone, today, we are going to tackle about Bootstrap Modals. It is the front-end designing purpose whatever you want to use it. You can use it to any confirmation, to add, edit, delete data, to view data in the modal form, and to maximize the space of your page when you using it...<a href="http://www.sourcecodester.com/tutorials/other/10617/how-use-modal-bootstrap.html">See More!</a></p>
  44. </div>
  45. </div>
  46. </div>
  47. <p class="likes"><a>25k Likes</a> - 1 hour ago</p>
  48. </li>
  49. <li> <img src="image/avatar.png" class="avatar">
  50. <div class="status">
  51. <h2><a href="#" target="_blank">Sourcecodester</a></h2>
  52. <p class="message">Linux Making The Computer Use Easier</p>
  53. <div class="img_attachment"> <img class="external_pic" src="image/linux.gif">
  54. <div class="data">
  55. <p class="name"><a href="http://www.sourcecodester.com/blog/10619/linux-making-computer-use-lot-easier.html" target="_blank">Linux On Making Computer Use A Lot Easier</a></p>
  56. <p class="caption">www.sourcecodester.com</p>
  57. <p class="description">Computer usage is like counting 1,2,3 for some while for others it's a whole new thing to be learned. Most especially to those who were not used to it, it's going to be a crack on the nutshell that a friendly operating system would really be a big help.
  58. Linux has recently been reported as a system that provides freedom, security, and easy access. Way back in 1991, mixed-up with the GNU software of Richard Stallman, a man named Linus Torvalds made this free operating system come to possibility...<a href="http://www.sourcecodester.com/blog/10619/linux-making-computer-use-lot-easier.html">See More!</a></p>
  59. </div>
  60. </div>
  61. </div>
  62. <p class="likes"><a>11k Likes</a> - 5 hour ago</p>
  63. </li>
  64. </ul>
  65. </div>
  66. </div>
  67. </body>
  68. </html>
For the Function of the message in the content.
  1. $(document).ready(function () {
  2. $('#shareButton').livequery("click", function () {
  3. var textarea_content = $('textarea#wall').val();
  4. if (textarea_content != '') {
  5. var sitetitle = $('label.title').html();
  6. if (sitetitle == null) {
  7. sitetitle = ' ';
  8. }
  9. var siteurl = $('label.url').html();
  10. if (siteurl == null) {
  11. siteurl = ' ';
  12. }
  13. var sitedesc = $('label.desc').html();
  14. if (sitedesc == null) {
  15. sitedesc = ' ';
  16. }
  17. var current_image_id = $('input#current_img').val();
  18. if (current_image_id != '') {
  19. var current_image_url = $("img#" + current_image_id).attr("src");
  20. if (current_image_url != '') {
  21. var image_html = '<div class="img_attachment"> <img class="external_pic" width="90" height="67" src="' + current_image_url + '">';
  22. } else {
  23. var image_html = '';
  24. }
  25. } else {
  26. var image_html = '';
  27. }
  28. var wall_post = '<li> <img src="image/avatar.png" class="avatar"><div class="status"><h2><a href="#" target="_blank">Sourcecodester</a></h2><p class="message">' + textarea_content + '</p> ' + image_html + '<div class="data"><p class="name"><a href="' + siteurl + '" target="_blank">' + sitetitle + '</a></p><p class="caption">' + siteurl + '</p><p class="description">' + sitedesc + '</p></div></div> </div><p class="likes"><a>Like</a> - 1 second ago</p></li>';
  29. var message_wall = $('#message_wall').attr('value');
  30. $.ajax({
  31. type: "GET",
  32. data: "message_wall=" + wall_post,
  33. success: function () {
  34. $('ul#posts').prepend(wall_post);
  35. }
  36. });
  37. $('textarea#wall').val('');
  38. $('#ajax_content').empty();
  39. $('#fetched_data').hide();
  40. } else {
  41. alert('Enter some text ! ');
  42. }
  43. });
  44. });
For the Image and Title to display in the Content.
  1. <?php
  2. if (!empty($images_url)) {
  3. echo '<div class="images">';
  4. for ($i = 0; $i < count($images_url); $i++) {
  5. $y = $i + 1;
  6. echo '<img style="display: none;" src="' . $images_url[$i] . '" id="' . $y .
  7. '" width="100"/>';
  8. }
  9. echo '<input name="total_images" id="total_images" value="' . count($images_url) .'" type="hidden"/>';
  10. echo '</div>';
  11. }
  12. echo '<div class="info">';
  13. if (!empty($title)) {
  14. echo ' <label class="title"> ' . $title . ' </label>';
  15. }
  16. echo ' <br clear="all"/>';
  17. echo '<label class="url"> ' . $url . ' </label>';
  18. echo '<br clear="all"/>';
  19. if (!empty($description)) {
  20. echo ' <label class="desc"> ' . substr($description, 0, 200) . ' </label>';
  21. }
  22. echo ' <br clear="all"/>';
  23. echo '</div>';
  24. ?>
resultHope that you learn in this project and enjoy coding. Don't forget to LIKE & SHARE this website.

Add new comment