PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/Stats2Site.php

https://github.com/iantearle/Facebook-Status-Expanse-Plugin
PHP | 206 lines | 121 code | 38 blank | 47 comment | 34 complexity | 579a77659e85d773af87e8166e46277e MD5 | raw file
  1. <?php
  2. /*
  3. Plugin Name: Facebook Status
  4. Plugin URI: http://blog.iantearle.com/
  5. Description: Displays your Facebook Status updates on your web site.
  6. Author: Ian Tearle
  7. Version: 1.1
  8. Author URI: http://www.iantearle.com/
  9. */
  10. /*
  11. Stats2Site is a PHP function that parses your Facebook Status RSS feed so it can be displayed on any website. No need to be running Wordpress or Drupal!
  12. Created By: Blake Brannon http://www.blakebrannon.com
  13. Date: 11/18/2007
  14. Usage: Just include this file in your page and then call: <?php if(function_exists('put_Stats2Site')){put_Stats2Site();} ?>
  15. You will need to configure the first section of the file below to add your credentials. To get your Facebook RSS feed URL, see instructions at http://www.blakebrannon.com/2007/11/18/stats2site-add-facebook-status-to-your-website/
  16. If you are having issues with the function working, check and make sure your FB privacy credentials allow your status feed to be viewed.
  17. */
  18. if(!class_exists('SimpleXMLObject')){include_once('simplexml.class.php');}
  19. ozone_action('preferences_menu','s2s_config_menu');
  20. function s2s_config_menu()
  21. {
  22. // if (function_exists("add_submenu_page"))
  23. // ozone_action("plugins.php", __("Reinvigorate"), __("Reinvigorate"), "manage_options", "config-re_", "re_config");
  24. ?>
  25. <!-- /* Stats 2 Site Menu //===============================*/ -->
  26. <h3 class="stretchToggle" title="Facebook Status"><a href="#FacebookStatus"><span>Facebook Status</span></a></h3>
  27. <div class="stretch" id="FacebookStatus">
  28. <label for="s2s_rss_uri">Facebook Status RSS</label>
  29. <input type="text" name="s2s_rss_uri" id="s2s_rss_uri" value="<?php echo getOption('s2s_rss_uri'); ?>">
  30. <?php tooltip('Facebook Status RSS', 'To obtain your status RSS, simply visit http://www.facebook.com/minifeed.php and select Status Feed from the left hand menu.');
  31. ?>
  32. <label for="s2s_name">Facebook Status Name</label>
  33. <input type="text" name="s2s_name" id="s2s_name" value="<?php echo getOption('s2s_name'); ?>">
  34. <?php tooltip('Facebook Status Name', 'Enter the name you would like to prefix your statuses with.');
  35. ?>
  36. <label for="s2s_numofupdates">Number of Facebook Status Updates</label>
  37. <input type="text" name="s2s_numofupdates" id="s2s_numofupdates" value="<?php echo getOption('s2s_numofupdates'); ?>">
  38. <?php tooltip('Number of Facebook Status', 'Enter the number of updates you would like to show.');
  39. ?>
  40. <label for="s2s_rmnameis">Remove Name</label>
  41. <input type="hidden" value="false" name="s2s_rmnameis" />
  42. <input type="checkbox" name="s2s_rmnameis" value="true" <?php echo getOption('s2s_rmnameis') == 'true' ? 'checked="checked"' : ''; ?> class="cBox" id="s2s_rmnameis" />
  43. <?php tooltip('Remove Name', 'If checked, this option will remove the "Name" before your updates.');
  44. ?>
  45. <label for="s2s_showtimestamp">Show Timestamp</label>
  46. <input type="hidden" value="false" name="s2s_showtimestamp" />
  47. <input type="checkbox" name="s2s_showtimestamp" value="true" <?php echo getOption('s2s_showtimestamp') == 'true' ? 'checked="checked"' : ''; ?> class="cBox" id="s2s_showtimestamp" />
  48. <?php tooltip('Show Timestamp', 'If checked, this option will show the time of the status update.');
  49. ?>
  50. <label for="s2s_showfeedback">Show Feedback</label>
  51. <input type="hidden" value="false" name="s2s_showfeedback" />
  52. <input type="checkbox" name="s2s_showfeedback" value="true" <?php echo getOption('s2s_showfeedback') == 'true' ? 'checked="checked"' : ''; ?> class="cBox" id="s2s_showfeedback" />
  53. <?php tooltip('Show Feedback', 'If checked, this option will show the feeback link at the end.');
  54. ?>
  55. </div>
  56. <?php
  57. }
  58. function put_Stats2Site() {
  59. if(getOption('s2s_rss_uri') == ''){
  60. $uri = 'http://www.facebook.com/feeds/status.php?id=900005295&viewer=900005295&key=a3a410bf20&format=rss20';
  61. }else{
  62. $uri = getOption('s2s_rss_uri');
  63. }
  64. // Please edit the variables below. All 8 variables should be specified.
  65. $url = $uri; // Your Facebook RSS Feed (http://www.facebook.com/feeds/status.php?id=900005295&viewer=900005295&key=a3a410bf20&format=rss20)
  66. $fbname = getOption('s2s_name'); // Facebook name (that matches the above feed).
  67. $rmnameis = getOption('s2s_rmnameis'); // Boolean that dictates if you would like to remove the "Name is" before your updates (true or false).
  68. $prefix = '<p>'; // HTML Tags to go before your Facebook status. ex. <p>, <ul><li>,...
  69. $suffix = '</em>'; // HTML Tags to go after your Facebook status. ex. </p>, </li></ul>,...
  70. $numofupdates = getOption('s2s_numofupdates'); // Number of updates you want to display, (1, 2, 3, 4,...).
  71. $showtimestamp = getOption('s2s_showtimestamp'); // Show the time of the status update (true or false).
  72. $showfeedback = getOption('s2s_showfeedback'); // Show the feeback link at the end (true or false).
  73. // ********************************************************************************************************************************
  74. // Starting The Code
  75. // Variable needed for the algorithm.
  76. $firstpass = true; // Identifies the first loop.
  77. // Fix numofupdates because it is indexed from zero
  78. $numofupdates--;
  79. // Setup curl
  80. $ch = curl_init();
  81. curl_setopt ($ch, CURLOPT_URL, $url);
  82. curl_setopt ($ch, 'CULROPT_HEADER', 0);
  83. // Spoof Firefox
  84. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.1) Gecko/20061223 Firefox/2.0.0.1");
  85. // Begin output buffering  
  86. ob_start();
  87. curl_exec ($ch);
  88. curl_close ($ch);
  89. // Save buffer to string
  90. $xmlstr = ob_get_contents();
  91. ob_end_clean();
  92. // Convert string to xml object
  93. $xml = new SimpleXMLElement($xmlstr);
  94. // Create Facebook prefix
  95. $fbprefix = "<p>". $fbname . "is ";
  96. // Start the loop
  97. for ($count = 0; $count <= $numofupdates; $count++) {
  98. // If you want to remove the "Name is"
  99. if ($rmnameis == 'true') {
  100. // Remove prefix from facebook status message
  101. $message = htmlspecialchars(str_replace($fbprefix,null,$xml->channel->item[$count]->title));
  102. }else{
  103. $message = htmlspecialchars($xml->channel->item[$count]->title);
  104. }
  105. //mixed search, mixed replace, mixed subject [, int &count]
  106. $message = str_replace("Ian","",str_replace('http://', 'http&#58;//',$xml->channel->item[$count]->title));
  107. // If you want to place the timestamp on the update.
  108. if ($showtimestamp == 'true' && $message != '') {
  109. $timestamp = strtotime($xml->channel->item[$count]->pubDate); // Get the timestamp for the post update.
  110. // Calculate how long it's been since the status was updated (relative).
  111. $currenttime = time();
  112. $delta = $currenttime - $timestamp;
  113. // Display how long it's been since the last update.
  114. $timestampdisplay = "</p><em>Updated ";
  115. // Show days if it's been more than a day.
  116. if(floor($delta / 84600) > 0) {
  117. $timestampdisplay .= floor($delta / 84600);
  118. if(floor($delta / 84600) == 1) { $timestampdisplay .= ' day, '; } else { $timestampdisplay .= ' days, '; }
  119. $delta -= 84600 * floor($delta / 84600);
  120. }
  121. // Show hours if it's been more than an hour.
  122. if(floor($delta / 3600) > 0) {
  123. $timestampdisplay .= floor($delta / 3600);
  124. if(floor($delta / 3600) == 1) { $timestampdisplay .= ' hour, '; } else { $timestampdisplay .= ' hours, '; }
  125. $delta -= 3600 * floor($delta / 3600);
  126. }
  127. // Show minutes if it's been more than a minute.
  128. if(floor($delta / 60) > 0) {
  129. $timestampdisplay .= floor($delta / 60);
  130. if(floor($delta / 60) == 1) { $timestampdisplay .= ' minute ago'; } else { $timestampdisplay .= ' minutes ago'; }
  131. $delta -= 60 * floor($delta / 60);
  132. }else{
  133. $timestampdisplay .= $delta;
  134. if($delta == 1) { $timestampdisplay .= ' second ago'; } else { $timestampdisplay .= ' seconds ago'; }
  135. }
  136. $message .= $timestampdisplay;
  137. }// End of Timestamp
  138. $echo = "";
  139. // If no updates are available.
  140. if ($message == '' && $firstpass) {
  141. $message = $fbname . ' has no recent status updates.';
  142. $echo.= $prefix . $message . $suffix;
  143. break;
  144. }
  145. // Set the value of $firstpass to know that at least one update has been posted
  146. $firstpass = false;
  147. // Capitalize first letter
  148. $message = ucfirst($message);
  149. // Echo out the status update.
  150. $echo.= $prefix . $message . $suffix;
  151. }// end of Loop
  152. // Add feedback link.
  153. if ($showfeedback == 'true'){
  154. $echo.= '<p>Media by <a href="http://www.iantearle.com/">Ian Tearle</a></p>';
  155. }else{
  156. $echo.= '<!-- Media by <a href="http://www.iantearle.com/">Ian Tearle</a> -->';
  157. }
  158. return $echo;
  159. }
  160. $putStats2Site = put_Stats2Site();
  161. $putStats2Site = preg_replace('/:/', '&#58;', $putStats2Site);
  162. if(function_exists('add_variable')){
  163. add_variable('status:'.$putStats2Site, 'header');
  164. }
  165. ?>