microblog.php 3.5 KB

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