Advertisement
guitarsrkewl08

Untitled

Feb 11th, 2013
1,158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.71 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. </head>
  5.  
  6. <body>
  7.  
  8. <?php
  9. $FBid = '238799632921950';
  10.  
  11. //Get the contents of a Facebook page
  12. $FBpage = file_get_contents('https://graph.facebook.com/238799632921950/feed?access_token=126910474151671|oa9TChRco3kJHss6f9tSFDNbppI');
  13.  
  14. //Interpret data with JSON
  15. $FBdata = json_decode($FBpage);
  16. //Set the page name or ID
  17.  
  18. //Ttime stamp function
  19. function timeSince($original) {
  20. // Array of time period
  21. $chunks = array(
  22. array(60 * 60 * 24 * 365 , 'year'),
  23. array(60 * 60 * 24 * 30 , 'month'),
  24. array(60 * 60 * 24 * 7, 'week'),
  25. array(60 * 60 * 24 , 'day'),
  26. array(60 * 60 , 'hour'),
  27. array(60 , 'minute'),
  28. );
  29.  
  30. // Current time
  31. $today = time();
  32. $since = $today - $original;
  33.  
  34.  
  35. // $j saves performing the count function each time around the loop
  36. for ($i = 0, $j = count($chunks); $i < $j; $i++) {
  37.  
  38. $seconds = $chunks[$i][0];
  39. $name = $chunks[$i][1];
  40.  
  41. // finding the biggest chunk (if the chunk fits, break)
  42. if (($count = floor($since / $seconds)) != 0) {
  43. break;
  44. }
  45. }
  46.  
  47. $print = ($count == 1) ? '1 '.$name : "$count {$name}s";
  48.  
  49. if ($i + 1 < $j) {
  50. // now getting the second item
  51. $seconds2 = $chunks[$i + 1][0];
  52. $name2 = $chunks[$i + 1][1];
  53.  
  54. // add second item if it's greater than 0
  55. if (($count2 = floor(($since - ($seconds * $count)) / $seconds2)) != 0) {
  56. $print .= ($count2 == 1) ? ', 1 '.$name2 : ", $count2 {$name2}s";
  57. }
  58. }
  59. return $print;
  60. }
  61.  
  62. echo '<h1>Facebook News Feed</h1>';
  63.  
  64. //Loop through data for each news item
  65. foreach ($FBdata->data as $news )
  66. {
  67. //Explode News and Page ID's into 2 values
  68. $StatusID = explode("_", $news->id);
  69.  
  70. echo '<div class="news-item">';
  71.  
  72. //Text/title/description/date
  73. if (!empty($news->story)) { echo '<h3>' . $news->story . '</h3>'; }
  74. if (!empty($news->message)) { echo '<h3>' . $news->message . '</h3>'; }
  75. if (!empty($news->description)) { echo '<p>' . $news->description . '</p>'; }
  76. echo '<p class="date">Posted '. timeSince(strtotime($news->created_time)) . ' ago</p>';
  77.  
  78. //Check for rich media
  79. if ($news->type == 'link') {
  80. echo '<a href="'.$news->link.'"><img src="'. $news->picture .'" border="0" style="padding-right:10px;" /></a>';
  81.  
  82. //Display link name and description
  83. if (!empty($news->description)) {
  84. echo '<a href="'.$news->link.'">'. '<b>' . $news->name . '</b></a>';
  85. }
  86. }
  87. else if ($news->type == 'photo') {
  88. echo '<a class="photo" href="'.$news->link.'"><img src="'. $news->picture .'" border="0" /></a>';
  89. }
  90. else if ($news->type == 'swf') {
  91. echo '<a href="http://www.facebook.com/permalink.php?story_fbid='.$StatusID['1'].'&id='.$StatusID['0'].'" target="_blank"><img src="'. $news->picture .'" border="0" /></a>';
  92. }
  93. else if ($news->type == 'video') {
  94. //Show play button over video thumbnail
  95. echo '<a class="vidLink" href="' . $news->source . '"><img class="playBtn" src="images/facebook-playBtn.png" /><img class="poster" src="' . $news->picture . '" alt="' . $news->description . '" /></a>';
  96. }
  97.  
  98. //Check for likes/comments/share counts
  99. echo '<ul class="meta"><li>Likes: ';
  100.  
  101. if (empty($news->likes->count)) { echo '0'; }
  102. else { echo $news->likes->count; }
  103.  
  104. echo '</li><li>Comments: ';
  105.  
  106. if (empty($news->comments->count)) { echo '0'; }
  107. else { echo $news->comments->count; }
  108.  
  109. echo '</li><li>Shares: ';
  110.  
  111. if (empty($news->shares->count)) { echo '0'; }
  112. else { echo $news->shares->count . '<br />'; }
  113.  
  114. echo '</li></ul>';
  115.  
  116. if (!empty($news->link)) { echo '<a class="viewpost" href="' . $news->link . '">View this post on Facebook</a>'; }
  117.  
  118. echo '</div> <!-- end .news-item -->';
  119. }
  120.  
  121. ?>
  122.  
  123. <div class="likebox"><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like-box href="http://www.facebook.com/<?php echo $FBid ?>"  show_faces="false" stream="false" header="true"></fb:like-box></div>
  124.  
  125. </body>
  126. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement