Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.88 KB | None | 0 0
  1. <?php
  2. //include SSI for SMF auth and stuff
  3. //require_once('./SSI.php');
  4. function opstimer() {
  5. //pull in globals from SSI.php
  6. global $smcFunc, $user_info;
  7. //forum URL
  8. $forumurl = 'https://fearlessdot.com';
  9. //check to see if current user is member of allowed group
  10. $token = False;
  11. $allowed_groups = array(1,2,3,9,10);
  12. foreach ($allowed_groups as $allowed) {
  13. if (in_array($allowed, $user_info['groups'])) {
  14. //success user is allowed
  15. $token = True;
  16. }
  17. }
  18. if ($token == True) {
  19. $allops = array();
  20. $result = $smcFunc['db_query']('', 'SELECT poster_time,subject,id_topic FROM `simplemachines`.smf_messages WHERE id_board = 5');
  21. while ($row = $smcFunc['db_fetch_assoc']($result)) {
  22. //var_dump($row);
  23. $thisone = array(
  24. 'timestamp' => $row['poster_time'],
  25. 'subject' => $row['subject'],
  26. 'id_topic' => $row['id_topic']
  27. );
  28. array_push($allops,$thisone);
  29. }
  30. //data is loaded do some validation
  31. $filtops = array();
  32. foreach($allops as $row) {
  33. //subject syntax ANNOUNCEMENT | 2014-07-29 0300 | name of op
  34. $subject = explode('|',$row['subject']);
  35. $optype = rtrim($subject[0]);
  36. $opdatetimestring = ltrim(rtrim($subject[1]));
  37. $timezone = new datetimezone('UTC');
  38. $opdatetime = DateTime::createFromFormat('Y-m-d Hi', $opdatetimestring, $timezone);
  39. $opname = ltrim($subject[2]);
  40. //check to see if the date is still valid
  41. if($opdatetime) {
  42. $optimestamp = $opdatetime->getTimestamp();
  43. if($optimestamp > time()) {
  44. //if its valid add it to array
  45. $thisone = array(
  46. 'datetime' => $opdatetime,
  47. 'type' => $optype,
  48. 'name' => $opname,
  49. 'url' => $forumurl.'/index.php?topic='.($row['id_topic']),
  50. 'id' => $row['id_topic']
  51. );
  52. array_push($filtops,$thisone);
  53. }
  54. }
  55. //time isnt valid check to see if an annoucement
  56. elseif($optype == 'ANNOUNCEMENT') {
  57. $opdatetime = new DateTime('1970-01-01');
  58. $opname = ltrim($subject[1]);
  59. $thisone = array(
  60. 'datetime' => $opdatetime,
  61. 'type' => $optype,
  62. 'name' => $opname,
  63. 'url' => $forumurl.'/index.php?topic='.($row['id_topic']),
  64. 'id' => $row['id_topic']
  65. );
  66. array_push($filtops,$thisone);
  67. }
  68. }
  69. //check if filtops != null
  70. if($filtops) {
  71. //sort the array - annoucements on top
  72. usort($filtops, function($a, $b) {
  73. return $a['datetime']->format('U') - $b['datetime']->format('U');
  74. });
  75. //echo out the table
  76. echo('
  77. <table class="table_list">
  78. <tbody class="header">
  79. <tr>
  80. <td colspan="4">
  81. <div class="cat_bar">
  82. <h3 class="catbg">Upcoming Events</h3>
  83. </div>
  84. </td>
  85. </tr>
  86. </tbody>
  87. ');
  88. //echo out the rows
  89. foreach($filtops as $row) {
  90. $id = $row['id'];
  91. $optype = $row['type'];
  92. $optime = $row['datetime']->format('Y-m-d Hi');
  93. //create the countdown
  94. $optimestamp = $row['datetime']->getTimestamp();
  95. $secondsuntil = $optimestamp - time();
  96. $days = floor($secondsuntil / 86400);
  97. $secondsuntil -= $days * 86400;
  98. $hours = floor($secondsuntil / 3600);
  99. $secondsuntil -= $hours * 3600;
  100. $minutes = floor($secondsuntil /60);
  101. $secondsuntil -= $minutes * 60;
  102. //echo the output
  103. if($optype == 'ANNOUNCEMENT') {
  104. echo('
  105. <tbody class="content">
  106. <tr class="windowbg2" >
  107. <td class="info" style="width:12%">ONGOING</td>
  108. <td class="info" style="width:8%; font-weight:bold;">ANNOUNCEMENT:</td>
  109. <td class="info" colspan="2"><a class="subject" style="font-weight:bold; font-size:110%;" href='.$row['url'].'>'.$row['name'].'</a></td>
  110. ');
  111. }
  112. else {
  113. //deterimne the op type - valid types are PUBLIC ROAM, ROAM, RED PEN
  114. if($optype == 'PUBLIC ROAM') { $optypehtml = '<td class="info" style="width:12%; font-weight:bold; color:pink;">PUBLIC ROAM:</td>'; }
  115. elseif($optype == 'ROAM') { $optypehtml = '<td class="info" style="width:12%; font-weight:bold; color:blue;">ROAM:</td>'; }
  116. elseif($optype == 'RED PEN') { $optypehtml = '<td class="info" style="width:12%; font-weight:bold; color:red;">RED PEN:</td>'; }
  117. elseif($optype == 'STRATEGIC OP') { $optypehtml = '<td class="info" style="width:12%; font-weight:bold; color:orange;">STRATEGIC OP:</td>'; }
  118. else { $optypehtml = '<td class="info" style="width:8%; font-weight:bold;">'.$optype.':</td>'; }
  119. echo('
  120. <tbody class="content">
  121. <tr class="windowbg2" >
  122. <td class="info" style="width:13%">'.$optime.'</td>
  123. '.$optypehtml.'
  124. <td class="info"><a class="subject" style="font-weight:bold; font-size:110%;" href='.$row['url'].'>'.$row['name'].'</a></td>
  125. <td class="info" style="font-weight:bold; width:15%;">('.$days.'D '.$hours.'H '.$minutes.'M '.$secondsuntil.'S)</td>
  126. ');
  127. }
  128. echo('
  129. </tr>
  130. </tbody>
  131. ');
  132. }
  133. echo('
  134. </table>
  135. ');
  136. }
  137. }
  138. }
  139. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement