Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //include SSI for SMF auth and stuff
- //require_once('./SSI.php');
- function opstimer() {
- //pull in globals from SSI.php
- global $smcFunc, $user_info;
- //forum URL
- $forumurl = 'https://fearlessdot.com';
- //check to see if current user is member of allowed group
- $token = False;
- $allowed_groups = array(1,2,3,9,10);
- foreach ($allowed_groups as $allowed) {
- if (in_array($allowed, $user_info['groups'])) {
- //success user is allowed
- $token = True;
- }
- }
- if ($token == True) {
- $allops = array();
- $result = $smcFunc['db_query']('', 'SELECT poster_time,subject,id_topic FROM `simplemachines`.smf_messages WHERE id_board = 5');
- while ($row = $smcFunc['db_fetch_assoc']($result)) {
- //var_dump($row);
- $thisone = array(
- 'timestamp' => $row['poster_time'],
- 'subject' => $row['subject'],
- 'id_topic' => $row['id_topic']
- );
- array_push($allops,$thisone);
- }
- //data is loaded do some validation
- $filtops = array();
- foreach($allops as $row) {
- //subject syntax ANNOUNCEMENT | 2014-07-29 0300 | name of op
- $subject = explode('|',$row['subject']);
- $optype = rtrim($subject[0]);
- $opdatetimestring = ltrim(rtrim($subject[1]));
- $timezone = new datetimezone('UTC');
- $opdatetime = DateTime::createFromFormat('Y-m-d Hi', $opdatetimestring, $timezone);
- $opname = ltrim($subject[2]);
- //check to see if the date is still valid
- if($opdatetime) {
- $optimestamp = $opdatetime->getTimestamp();
- if($optimestamp > time()) {
- //if its valid add it to array
- $thisone = array(
- 'datetime' => $opdatetime,
- 'type' => $optype,
- 'name' => $opname,
- 'url' => $forumurl.'/index.php?topic='.($row['id_topic']),
- 'id' => $row['id_topic']
- );
- array_push($filtops,$thisone);
- }
- }
- //time isnt valid check to see if an annoucement
- elseif($optype == 'ANNOUNCEMENT') {
- $opdatetime = new DateTime('1970-01-01');
- $opname = ltrim($subject[1]);
- $thisone = array(
- 'datetime' => $opdatetime,
- 'type' => $optype,
- 'name' => $opname,
- 'url' => $forumurl.'/index.php?topic='.($row['id_topic']),
- 'id' => $row['id_topic']
- );
- array_push($filtops,$thisone);
- }
- }
- //check if filtops != null
- if($filtops) {
- //sort the array - annoucements on top
- usort($filtops, function($a, $b) {
- return $a['datetime']->format('U') - $b['datetime']->format('U');
- });
- //echo out the table
- echo('
- <table class="table_list">
- <tbody class="header">
- <tr>
- <td colspan="4">
- <div class="cat_bar">
- <h3 class="catbg">Upcoming Events</h3>
- </div>
- </td>
- </tr>
- </tbody>
- ');
- //echo out the rows
- foreach($filtops as $row) {
- $id = $row['id'];
- $optype = $row['type'];
- $optime = $row['datetime']->format('Y-m-d Hi');
- //create the countdown
- $optimestamp = $row['datetime']->getTimestamp();
- $secondsuntil = $optimestamp - time();
- $days = floor($secondsuntil / 86400);
- $secondsuntil -= $days * 86400;
- $hours = floor($secondsuntil / 3600);
- $secondsuntil -= $hours * 3600;
- $minutes = floor($secondsuntil /60);
- $secondsuntil -= $minutes * 60;
- //echo the output
- if($optype == 'ANNOUNCEMENT') {
- echo('
- <tbody class="content">
- <tr class="windowbg2" >
- <td class="info" style="width:12%">ONGOING</td>
- <td class="info" style="width:8%; font-weight:bold;">ANNOUNCEMENT:</td>
- <td class="info" colspan="2"><a class="subject" style="font-weight:bold; font-size:110%;" href='.$row['url'].'>'.$row['name'].'</a></td>
- ');
- }
- else {
- //deterimne the op type - valid types are PUBLIC ROAM, ROAM, RED PEN
- if($optype == 'PUBLIC ROAM') { $optypehtml = '<td class="info" style="width:12%; font-weight:bold; color:pink;">PUBLIC ROAM:</td>'; }
- elseif($optype == 'ROAM') { $optypehtml = '<td class="info" style="width:12%; font-weight:bold; color:blue;">ROAM:</td>'; }
- elseif($optype == 'RED PEN') { $optypehtml = '<td class="info" style="width:12%; font-weight:bold; color:red;">RED PEN:</td>'; }
- elseif($optype == 'STRATEGIC OP') { $optypehtml = '<td class="info" style="width:12%; font-weight:bold; color:orange;">STRATEGIC OP:</td>'; }
- else { $optypehtml = '<td class="info" style="width:8%; font-weight:bold;">'.$optype.':</td>'; }
- echo('
- <tbody class="content">
- <tr class="windowbg2" >
- <td class="info" style="width:13%">'.$optime.'</td>
- '.$optypehtml.'
- <td class="info"><a class="subject" style="font-weight:bold; font-size:110%;" href='.$row['url'].'>'.$row['name'].'</a></td>
- <td class="info" style="font-weight:bold; width:15%;">('.$days.'D '.$hours.'H '.$minutes.'M '.$secondsuntil.'S)</td>
- ');
- }
- echo('
- </tr>
- </tbody>
- ');
- }
- echo('
- </table>
- ');
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement