Преглед на файлове

RSS now reads JSON as well

teo greenwood преди 10 години
родител
ревизия
7bf3bd76c7
променени са 2 файла, в които са добавени 58 реда и са изтрити 33 реда
  1. 15 8
      sys/microblog.inc
  2. 43 25
      sys/rss/microblog.php

+ 15 - 8
sys/microblog.inc

@@ -98,22 +98,29 @@
         if(is_null($json)) {
           echo $fc;
         } elseif (isset($json->title) && isset($json->url) && isset($json->poster)) {
-          $out = '<h3 class="blogtitles">';
-          $out = $out.'<a href="'.$json->url.'">'.$json->title.'</a>';
-          $out = $out.'<a class="usericon '.$json->poster.'" title="Posted by '.$json->poster.'"></a></h3>';
+          $out = '<h3 class="blogtitles">
+                    <a href="'.$json->url.'">'.$json->title.'</a>
+                    <a class="usericon '.$json->poster.'" title="Posted by '.$json->poster.'"></a>
+                  </h3>';
           if(isset($json->image)) {
-            $out = $out.'<img class="mblogimg" src="'.$json->image.'" />';
+            $out .= '<img class="mblogimg" src="'.$json->image.'" />';
           }
           if(isset($json->audio)) {
-            $out = $out.'<audio src="'.$json->audio.'" controls>Download Audio <a href="'.$json->audio.'">Here</a><br /></audio>';
+            $out .= '<audio src="'.$json->audio.'" controls>
+                       Download Audio 
+                       <a href="'.$json->audio.'">Here</a><br />
+                     </audio>';
           }
           if(isset($json->video)) {
-            $out = $out.'<video src="'.$json->video.'" controls>Download Video <a href="'.$json->video.'">Here</a><br /></video>';
+            $out .= '<video src="'.$json->video.'" controls>
+                       Download Video
+                       <a href="'.$json->video.'">Here</a><br />
+                     </video>';
           }
           if(isset($json->comment)) {
-            $out = $out.$json->comment;
+            $out .= $json->comment;
           }
-          $out = $out.'<hr />';
+          $out .= '<hr />';
           echo $out;
         } #Note that if nothing works out here, I'm just opting not to show anything.
         if ($editable) {

+ 43 - 25
sys/rss/microblog.php

@@ -1,4 +1,4 @@
-<?php
+<?php 
   //Import your config, set some stuff up, then construct the mining laser
   extract(json_decode(file_get_contents('../admin/config/main.json'),true));
   extract(json_decode(file_get_contents('../admin/config/users.json'),true));
@@ -21,34 +21,52 @@
   foreach ($files as $shitpost) {
     $storyPubDate =  date(DATE_RSS, strtotime(basename($shitpost)));
     $contents = file_get_contents($shitpost);
-    //HAHAHA You thought you needed an XML parser, didn't you?
-    $theRipper = explode("<",$contents);
-    $theRipper = explode(">",$theRipper[2]);
-    $storyTitle = $theRipper[1];
-    $theRipper = explode('"',$theRipper[0]);
-    $storyLink = htmlspecialchars($theRipper[1]);
-    $theRipper = explode("</h3>",$contents);
-    $theRipper = explode("<hr />",$theRipper[1]);
-    $storyText = $theRipper[0];
-    $theRipper = explode("title=\"Posted by ",$contents);
-    $theRipper = explode('"',$theRipper[1]);
-    $poster = $theRipper[0];
+    #Set some sane defaults for cases where no user exists
     $email = "null@example.com";
     $author = "X";
-    if(isset($tcmsUsers[$poster])) {
-        $email = $tcmsUsers[$poster]["email"];
-        $author = $tcmsUsers[$poster]["fullName"]; 
+    #Check the format, do needful based on what's here
+    $json = json_decode($contents);
+    if(is_null($json)) {
+      //HAHAHA You thought you needed an XML parser, didn't you?
+      $theRipper = explode("<",$contents);
+      $theRipper = explode(">",$theRipper[2]);
+      $storyTitle = $theRipper[1];
+      $theRipper = explode('"',$theRipper[0]);
+      $storyLink = htmlspecialchars($theRipper[1]);
+      $theRipper = explode("</h3>",$contents);
+      $theRipper = explode("<hr />",$theRipper[1]);
+      $storyText = $theRipper[0];
+      $theRipper = explode("title=\"Posted by ",$contents);
+      $theRipper = explode('"',$theRipper[1]);
+      $poster = $theRipper[0];
+      if(isset($tcmsUsers[$poster])) {
+          $email = $tcmsUsers[$poster]["email"];
+          $author = $tcmsUsers[$poster]["fullName"]; 
+      }
+      $feed .= '<item>
+                 <title>'.$storyTitle.'</title>
+                 <description><![CDATA['.$storyText.']]></description>
+                 <link>'.$storyLink.'</link>
+                 <guid isPermaLink="false">'.basename($shitpost).'-'.$_SERVER["SERVER_NAME"].'</guid>
+                 <pubDate>'.$storyPubDate.'</pubDate>
+                 <author>'.$email.' ('.$author.')</author>
+                </item>';
+    } elseif (isset($json->title) && isset($json->url) && isset($json->poster)) {
+        if(isset($tcmsUsers[$json->poster])) {
+            $email = $tcmsUsers[$json->poster]["email"];
+            $author = $tcmsUsers[$json->poster]["fullName"]; 
+        }
+        $feed .= '<item>
+                   <title>'.$json->title.'</title>
+                   <description><![CDATA['.$json->comment.']]></description>
+                   <link>'.$json->url.'</link>
+                   <guid isPermaLink="false">'.basename($shitpost).'-'.$_SERVER["SERVER_NAME"].'</guid>
+                   <pubDate>'.$storyPubDate.'</pubDate>
+                   <author>'.$email.' ('.$author.')</author>
+                  </item>';
     }
-    $feed .= '<item>
-               <title>'.$storyTitle.'</title>
-               <description><![CDATA['.$storyText.']]></description>
-               <link>'.$storyLink.'</link>
-               <guid isPermaLink="false">'.basename($shitpost).'-'.$_SERVER["SERVER_NAME"].'</guid>
-               <pubDate>'.$storyPubDate.'</pubDate>
-               <author>'.$email.' ('.$author.')</author>
-              </item>';
   }
   $feed .= ' </channel>
             </rss>';
   print_r($feed);
-?>
+ ?>