microblog.inc 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <!--Scripts below allow audio player JS to show up with fancy little player-->
  2. <script type="text/javascript" src="sys/fileshare/include/audio-player.js"></script>
  3. <script type="text/javascript">
  4. AudioPlayer.setup("sys/fileshare/include/player.swf", {
  5. width: 290,
  6. transparentpagebg: "yes",
  7. });
  8. </script>
  9. <?php
  10. if ($editable) {
  11. echo "
  12. <script type=\"text/javascript\">
  13. function switchMenu(obj) {
  14. var el = document.getElementById(obj);
  15. if ( el.style.display != 'none' ) {
  16. el.style.display = 'none';
  17. }
  18. else {
  19. el.style.display = '';
  20. }
  21. }
  22. </script>\n";
  23. }
  24. echo '<p class="title"><a title="RSS" class="rss" href="/'.$basedir.$rssdir.'microblog.php"></a>';
  25. echo $microblogtitle;
  26. //Set important times - $tdtime is today's date, $oldtime is the oldest known date a tCMS install had nuze for - defaults to today then searches microblog dir for entries to set date
  27. $tdtime = new DateTime(null, new DateTimeZone($timezone));
  28. $oldtime = clone $tdtime;
  29. //limit results of directory read to first entry
  30. function &oldtimer($timezone, $basedir, $microblogdir) {
  31. if ($handle = opendir($_SERVER["DOCUMENT_ROOT"].'/'.$basedir.$microblogdir)) {
  32. while (false !== ($entry = readdir($handle))) {
  33. if ($entry != "." && $entry != "..") {
  34. $oldtime = DateTime::createFromFormat('m.d.y', $entry, new DateTimeZone ($timezone));
  35. closedir($handle);
  36. return($oldtime);
  37. }
  38. }
  39. }
  40. };
  41. $oldtime = &oldtimer($timezone, $basedir, $microblogdir);
  42. $oldtime->sub(new DateInterval('P1D'));
  43. //$today and $tmrw refer to times relative to what is passed by GET params - $today is the date requested by GET, $tmrw is bool designating whether $today is something other than $tdtime
  44. //error indicates whether you supplied a bogus GET param for date.
  45. $tmrw = 0;
  46. $error = 0;
  47. $today = clone $tdtime;
  48. if ($_GET["date"] != "") {
  49. $today = DateTime::createFromFormat('m.d.y', $_GET["date"], new DateTimeZone ($timezone));
  50. //Catch bogus input, set $tmwr to TRUE if $today was set to something other than today's date
  51. if (!filter_var($_GET["date"],FILTER_VALIDATE_REGEXP,array('options' => array('regexp' => "/^(0[1-9]|1[012])[.](0[1-9]|[12][0-9]|3[01])[.]\d\d/")))) {
  52. echo "</p>That's a funny looking date you provided there, mister.\n";
  53. $error=1;
  54. }
  55. else if ($today > $tdtime) { //catch if day supplied by GET is IN THE FUTURE
  56. echo "</p>Welcome to the future<br /><img style=\"max-width:100%; padding-left: auto; padding-right: auto;\" src=\"http://gunshowcomic.com/comics/20090930.png\" />\n";
  57. $error=1;
  58. }
  59. else if ($today < $tdtime) {
  60. $tmrw = 1;
  61. }
  62. }
  63. //Catch if day in question has no news - If not, display day before (or before that if still no news. $oldtime used here to tell when to stop looping back)
  64. if (!$error) {
  65. while (empty($todaysnews)) {
  66. $yesterday = clone $today;
  67. $yesterday->sub(new DateInterval('P1D'));
  68. //Detect if We're at the end of postings
  69. if ($yesterday < $oldtime) {
  70. echo " (".$today->format('m.d.y')."):</p><hr />";
  71. echo "For me, it was a beginning, but for you it is the end of the road.<br /><hr />\n";
  72. if ($oldtime != $tdtime) {
  73. $tomorrow = clone $oldtime;
  74. $tomorrow->add(new DateInterval('P1D'));
  75. $tomorrow = $tomorrow->format('m.d.y');
  76. }
  77. $todaysnews = "end";
  78. }
  79. if ($todaysnews != "end") {
  80. //Get news from directory if any exists for that day
  81. $todaysnews = glob($_SERVER["DOCUMENT_ROOT"].'/'.$basedir.$microblogdir.$today->format('m.d.y')."/*");
  82. //Set display date for today's news, set $today to be yesterday in order to get while loop to recurse correctly
  83. $realtime = $today->format('m.d.y');
  84. $today = clone $yesterday;
  85. //Finish by setting times for Yesterday and Tomorrow so that they can be used in links below
  86. $tomorrow = clone $yesterday;
  87. $tomorrow->add(new DateInterval('P2D'));
  88. $tomorrow = $tomorrow->format('m.d.y');
  89. $yesterday = $yesterday->format('m.d.y');
  90. }
  91. }
  92. if ($todaysnews != "end") {
  93. echo " (".$realtime."):</p><hr />\n";
  94. foreach ($todaysnews as $i) {
  95. $fh = fopen($i,'r');
  96. $fc = fread($fh,10000); //If a microblog item is more than 1kb, you are doing something wrong.
  97. fclose($fh);
  98. echo $fc;
  99. if ($editable) {
  100. $id=basename($i);
  101. echo "
  102. <a style=\"display: inline-block;\" onclick=\"switchMenu('$id');\">[Edit]</a>
  103. <div style=\"display: none;\" id=\"$id\">
  104. <form style=\"display: inline\" method=\"POST\">
  105. <input type=\"hidden\" name=\"id\" value=\"$i\" />
  106. <input type='hidden' name='action' value='Edit' />
  107. <textarea class=\"mbedit_text\" name=\"content\">$fc</textarea>
  108. <input class=\"coolbutton mbedit_button\" type=\"submit\" Value=\"Edit\" />
  109. </form>
  110. <form style=\"display: inline\" method=\"POST\">
  111. <input type=\"hidden\" name=\"id\" value=\"$i\" />
  112. <input type='hidden' name='action' value='Delete' />
  113. <input class=\"coolbutton mbedit_button\" type=\"submit\" value=\"Delete\" />
  114. </form>
  115. </div>
  116. <hr class=\"clear\" />";
  117. }
  118. echo "\n";
  119. }
  120. echo "<a style=\"float: left;\" title=\"skips empty days\" href=\"".$_SERVER["PHP_SELF"]."?nav=2&date=".$yesterday."\">Yesterday's News</a>\n";
  121. }
  122. if ($tmrw) {
  123. echo "<a style=\"float: right;\" href=\"".$_SERVER["PHP_SELF"]."?nav=2&date=".$tomorrow."\">Tomorrow's News</a>\n";
  124. }
  125. } else {
  126. //Do nothing - errors thrown above
  127. }
  128. ?>