microblog.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. //Import your config, set some stuff up, then construct the mining laser
  3. extract(json_decode(file_get_contents('../admin/config/main.json'),true));
  4. extract(json_decode(file_get_contents('../admin/config/users.json'),true));
  5. date_default_timezone_set($timezone);
  6. $tiem = date(DATE_RSS);
  7. $today = date("m.d.y");
  8. $atomlink = "http://".$_SERVER["SERVER_NAME"]."/".$basedir.$rssdir."microblog.php";
  9. $newsdir = $_SERVER["DOCUMENT_ROOT"]."/".$basedir.$microblogdir;
  10. $files = glob($newsdir.$today."/*");
  11. $slen = count($files);
  12. $feed = '<?xml version="1.0" encoding="UTF-8"?>
  13. <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  14. <channel>
  15. <atom:link href="'.$atomlink.'" rel="self" type="application/rss+xml" />
  16. <title>'.$htmltitle.'</title>
  17. <description>'.$microblogtitle.' RSS Feed</description>
  18. <link>http://'.$_SERVER['SERVER_NAME'].'/'.$basedir.'</link>
  19. <lastBuildDate>'.$tiem.'</lastBuildDate>
  20. <pubDate>'.$tiem.'</pubDate>';
  21. foreach ($files as $shitpost) {
  22. $storyPubDate = date(DATE_RSS, strtotime(basename($shitpost)));
  23. $contents = file_get_contents($shitpost);
  24. #Set some sane defaults for cases where no user exists
  25. $email = "null@example.com";
  26. $author = "X";
  27. #Check the format, do needful based on what's here
  28. $json = json_decode($contents);
  29. if(is_null($json)) {
  30. //HAHAHA You thought you needed an XML parser, didn't you?
  31. $theRipper = explode("<",$contents);
  32. $theRipper = explode(">",$theRipper[2]);
  33. $storyTitle = $theRipper[1];
  34. $theRipper = explode('"',$theRipper[0]);
  35. $storyLink = htmlspecialchars($theRipper[1]);
  36. $theRipper = explode("</h3>",$contents);
  37. $theRipper = explode("<hr />",$theRipper[1]);
  38. $storyText = $theRipper[0];
  39. $theRipper = explode("title=\"Posted by ",$contents);
  40. $theRipper = explode('"',$theRipper[1]);
  41. $poster = $theRipper[0];
  42. if(isset($tcmsUsers[$poster])) {
  43. $email = $tcmsUsers[$poster]["email"];
  44. $author = $tcmsUsers[$poster]["fullName"];
  45. }
  46. $feed .= '<item>
  47. <title>'.$storyTitle.'</title>
  48. <description><![CDATA['.$storyText.']]></description>
  49. <link>'.$storyLink.'</link>
  50. <guid isPermaLink="false">'.basename($shitpost).'-'.$_SERVER["SERVER_NAME"].'</guid>
  51. <pubDate>'.$storyPubDate.'</pubDate>
  52. <author>'.$email.' ('.$author.')</author>
  53. </item>';
  54. } elseif (isset($json->title) && isset($json->url) && isset($json->poster)) {
  55. if(isset($tcmsUsers[$json->poster])) {
  56. $email = $tcmsUsers[$json->poster]["email"];
  57. $author = $tcmsUsers[$json->poster]["fullName"];
  58. }
  59. $feed .= '<item>
  60. <title>'.$json->title.'</title>
  61. <description><![CDATA['.$json->comment.']]></description>
  62. <link>'.$json->url.'</link>
  63. <guid isPermaLink="false">'.basename($shitpost).'-'.$_SERVER["SERVER_NAME"].'</guid>
  64. <pubDate>'.$storyPubDate.'</pubDate>
  65. <author>'.$email.' ('.$author.')</author>
  66. </item>';
  67. }
  68. }
  69. $feed .= ' </channel>
  70. </rss>';
  71. print_r($feed);
  72. ?>