microblog.inc 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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> '.$microblogtitle;
  25. //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
  26. $tdtime = new DateTime(null, new DateTimeZone($timezone));
  27. $oldtime = clone $tdtime;
  28. //limit results of directory read to first entry
  29. function &oldtimer($timezone, $basedir, $microblogdir) {
  30. if ($handle = opendir($_SERVER["DOCUMENT_ROOT"].'/'.$basedir.$microblogdir)) {
  31. while (false !== ($entry = readdir($handle))) {
  32. if ($entry != "." && $entry != "..") {
  33. $oldtime = DateTime::createFromFormat('m.d.y', $entry, new DateTimeZone ($timezone));
  34. closedir($handle);
  35. return($oldtime);
  36. }
  37. }
  38. }
  39. };
  40. $oldtime = &oldtimer($timezone, $basedir, $microblogdir);
  41. $oldtime->sub(new DateInterval('P1D'));
  42. //$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
  43. //error indicates whether you supplied a bogus GET param for date.
  44. $tmrw = 0;
  45. $error = 0;
  46. $today = clone $tdtime;
  47. if ($_GET["date"] != "") {
  48. $today = DateTime::createFromFormat('m.d.y', $_GET["date"], new DateTimeZone ($timezone));
  49. //Catch bogus input, set $tmwr to TRUE if $today was set to something other than today's date
  50. 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/")))) {
  51. echo "</p>That's a funny looking date you provided there, mister.\n";
  52. $error=1;
  53. }
  54. else if ($today > $tdtime) { //catch if day supplied by GET is IN THE FUTURE
  55. 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";
  56. $error=1;
  57. }
  58. else if ($today < $tdtime) {
  59. $tmrw = 1;
  60. }
  61. }
  62. //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)
  63. if (!$error) {
  64. while (empty($todaysnews)) {
  65. $yesterday = clone $today;
  66. $yesterday->sub(new DateInterval('P1D'));
  67. //Detect if We're at the end of postings
  68. if ($yesterday < $oldtime) {
  69. echo " (".$today->format('m.d.y')."):</p><hr />";
  70. echo "For me, it was a beginning, but for you it is the end of the road.<br /><hr />\n";
  71. if ($oldtime != $tdtime) {
  72. $tomorrow = clone $oldtime;
  73. $tomorrow->add(new DateInterval('P1D'));
  74. $tomorrow = $tomorrow->format('m.d.y');
  75. }
  76. $todaysnews = "end";
  77. }
  78. if ($todaysnews != "end") {
  79. //Get news from directory if any exists for that day
  80. $todaysnews = glob($_SERVER["DOCUMENT_ROOT"].'/'.$basedir.$microblogdir.$today->format('m.d.y')."/*");
  81. //Set display date for today's news, set $today to be yesterday in order to get while loop to recurse correctly
  82. $realtime = $today->format('m.d.y');
  83. $today = clone $yesterday;
  84. //Finish by setting times for Yesterday and Tomorrow so that they can be used in links below
  85. $tomorrow = clone $yesterday;
  86. $tomorrow->add(new DateInterval('P2D'));
  87. $tomorrow = $tomorrow->format('m.d.y');
  88. $yesterday = $yesterday->format('m.d.y');
  89. }
  90. }
  91. if ($todaysnews != "end") {
  92. echo " (".$realtime."):</p><hr />\n";
  93. foreach ($todaysnews as $i) {
  94. $fh = fopen($i,'r');
  95. $fc = fread($fh,10000); //If a microblog item is more than 1kb, you are doing something wrong.
  96. fclose($fh);
  97. $json = json_decode($fc);
  98. if(is_null($json)) {
  99. echo $fc;
  100. } elseif (isset($json->title) && isset($json->url) && isset($json->poster)) {
  101. $out = '<h3 class="blogtitles">
  102. <a href="'.$json->url.'">'.$json->title.'</a>
  103. <a class="usericon '.$json->poster.'" title="Posted by '.$json->poster.'"></a>
  104. </h3>';
  105. if(isset($json->image)) {
  106. $out .= '<img class="mblogimg" src="'.$json->image.'" />';
  107. }
  108. if(isset($json->audio)) {
  109. $out .= '<audio src="'.$json->audio.'" controls>
  110. Download Audio
  111. <a href="'.$json->audio.'">Here</a><br />
  112. </audio>';
  113. }
  114. if(isset($json->video)) {
  115. $out .= '<video src="'.$json->video.'" controls>
  116. Download Video
  117. <a href="'.$json->video.'">Here</a><br />
  118. </video>';
  119. }
  120. if(isset($json->comment)) {
  121. $out .= $json->comment;
  122. }
  123. $out .= '<hr />';
  124. echo $out;
  125. } #Note that if nothing works out here, I'm just opting not to show anything.
  126. if ($editable) {
  127. $id=basename($i);
  128. echo "
  129. <a style=\"display: inline-block;\" onclick=\"switchMenu('$id');\">[Edit]</a>
  130. <div style=\"display: none;\" id=\"$id\">
  131. <form style=\"display: inline\" method=\"POST\">
  132. <input type=\"hidden\" name=\"id\" value=\"$i\" />
  133. <input type='hidden' name='action' value='Edit' />
  134. <textarea class=\"mbedit_text\" name=\"content\">$fc</textarea>
  135. <input class=\"coolbutton mbedit_button\" type=\"submit\" Value=\"Edit\" />
  136. </form>
  137. <form style=\"display: inline\" method=\"POST\">
  138. <input type=\"hidden\" name=\"id\" value=\"$i\" />
  139. <input type='hidden' name='action' value='Delete' />
  140. <input class=\"coolbutton mbedit_button\" type=\"submit\" value=\"Delete\" />
  141. </form>
  142. </div>
  143. <hr class=\"clear\" />";
  144. }
  145. echo "\n";
  146. }
  147. echo "<a style=\"float: left;\" title=\"skips empty days\" href=\"".$_SERVER["PHP_SELF"]."?nav=2&date=".$yesterday."\">Yesterday's News</a>\n";
  148. }
  149. if ($tmrw) {
  150. echo "<a style=\"float: right;\" href=\"".$_SERVER["PHP_SELF"]."?nav=2&date=".$tomorrow."\">Tomorrow's News</a>\n";
  151. }
  152. }
  153. ?>