blog.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. header('Content-Type: application/rss+xml');
  3. if (!empty($_SERVER["HTTPS"])) {
  4. $protocol = "http";
  5. } else {
  6. $protocol = "https";
  7. }
  8. extract(json_decode(file_get_contents('../admin/config/main.json'),true));
  9. echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
  10. echo "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n";
  11. echo "<channel>\n";
  12. $atomlink = "$protocol://".$_SERVER["SERVER_NAME"]."/".$basedir.$rssdir."blog.php";
  13. echo "<atom:link href=\"".$atomlink."\" rel=\"self\" type=\"application/rss+xml\" />";
  14. echo "\t<title>".$htmltitle."</title>\n";
  15. echo "\t<description>".$blogtitle."</description>\n";
  16. echo "\t<link>http://".$_SERVER["SERVER_NAME"]."/".$basedir."</link>\n";
  17. $tiem = date(DATE_RFC2822, time());
  18. echo "\t<lastBuildDate>$tiem</lastBuildDate>\n";
  19. echo "\t<pubDate>$tiem</pubDate>\n";
  20. $files = glob($_SERVER["DOCUMENT_ROOT"]."/".$basedir.$blogdir."*.post");
  21. $guid = count($files);
  22. //sort by filename
  23. //initialize an array to house sort results
  24. $files2 = array();
  25. $files2 = array_pad($files2,$guid,0);
  26. for ($i=0; $i<$guid; $i++) {
  27. $j = explode('-',basename($files[$i]));
  28. $j = $j[0];
  29. $j = (int)$j;
  30. $j--;
  31. $files2[$j] = $files[$i];
  32. }
  33. $slen = count($files2)-1;
  34. $ctr = 0;
  35. for ($i=$slen; $i>-1; $i--) {
  36. $shitpost=$files2[$i];
  37. if ($ctr > 9) {break;};
  38. $ctr++;
  39. $statz = stat($shitpost);
  40. $uid = $statz['uid'];
  41. $udata = posix_getpwuid($uid);
  42. $user = $udata['name'];
  43. $date = date(DATE_RFC2822, filemtime($shitpost));
  44. $title = substr(strstr(basename($shitpost),'-'),1,-5);
  45. $contents = file_get_contents($shitpost);
  46. echo "\t<item>\n";
  47. echo "\t\t<title>$title</title>\n";
  48. echo "\t\t<description><![CDATA[".$contents."]]>\t\t</description>\n";
  49. echo "\t\t<link>http://teodesian.net/index.php?nav=8&amp;post=".$shitpost."</link>\n";
  50. echo "\t\t<guid isPermaLink=\"false\">$guid-teodesian.net</guid>\n";
  51. echo "\t\t<pubDate>".$date."</pubDate>\n";
  52. echo "\t\t<author>".$user."</author>\n";
  53. echo "\t</item>\n";
  54. $guid--;
  55. }
  56. echo "</channel>\n";
  57. echo "</rss>";
  58. ?>