- <?php
- /*
- A clear news bar plugin for MyBB
- * v. 1.0
- * Last edit: 5 August 2010
- * Shows a clear news bar on your forum pages.
- * Copyright (C) 2009 & 2010 Mateusz Grzesiukiewicz also known as Ajdija
- * Website: http://www.ajdija.com
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- if(!defined("IN_MYBB"))
- {
- die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
- }
- $plugins->add_hook('pre_output_page','aclearnewsbar');
- function aclearnewsbar_info()
- {
- return array
- (
- "name"=>"A clear news bar",
- "description"=>"Shows a clear bar with latest news from your portal page.",
- "website"=>"http://www.ajdija.com",
- "author"=>"Mateusz Grzesiukiewicz",
- "authorsite"=> "http://www.ajdija.com",
- "version"=>"1.0",
- "guid"=>"7dc27e3041bfe6e412f1a9b2f7634db2",
- "compatibility"=>"18*"
- );
- }
- function aclearnewsbar($page)
- {
- global $mybb,$theme, $db;
- $announcements = '';
- $query = $db->query("
- SELECT t.tid,t.subject, t.username AS threadusername, t.dateline as date_p, tp.displaystyle AS D_STYLE
- FROM ".TABLE_PREFIX."threads t
- LEFT JOIN " .TABLE_PREFIX. "threadprefixes tp ON (t.prefix = tp.pid)
- WHERE t.visible='1' AND t.closed NOT LIKE 'moved|%'
- ORDER BY t.dateline DESC
- LIMIT 0,10 " // 10 is the number of latest threads
- );
- $news = '';
- function getTheDay($date)
- {
- date_default_timezone_set('Europe/Paris'); // !important set timezone
- $curr_date=date("Y-m-d"); // format the date (to remove hours and minutes and secondes)
- $curr_date=strtotime($curr_date); // date to integer
- if (date('I', time())) // test dst
- {
- // echo "We are in DST!";
- $curr_date=$curr_date - 3600; // correct the DST using local time
- $curr_date=date("Y-m-d"); // integer to date again
- $curr_date=strtotime($curr_date); //date to integer again (to remove hours and minutes and secondes)
- }
- $the_date=$date-3600; //mybb use DST by default.
- $the_date=date("Y-m-d",$the_date); // integer to date (to remove hours and minutes and secondes)
- $the_date=strtotime($the_date); //date to integer again
- $diff=$curr_date-$the_date;
- $diff=$diff/86400; //1 day = 86400 sec
- switch($diff)
- {
- case 0:
- return 'today';
- break;
- case 1:
- return "yesterday";
- break;
- case 2:
- return '2 days ago';
- break;
- case 3:
- return '3 days ago';
- break;
- default:
- return date("Y-m-d",$the_date);
- }
- }
- while($announcement = $db->fetch_array($query))
- {
- $announcement['threadlink'] = get_thread_link($announcement['tid']);
- //$announcement['subject'] = htmlspecialchars_uni($announcement['subject']);
- //$announcement['threadusername'] = htmlspecialchars_uni($announcement['threadusername']);
- $announcement['date_p']=getTheDay($announcement['date_p']);
- $news = $news.' <span style="background: white;color:black;height: 16px;line-height: 16px;padding: 0px 5px;font-size: 9px;font-weight: bold;border-radius: 4px;vertical-align: middle;
- ">'.$announcement['date_p'].'</span> '.$announcement['D_STYLE'].' '.'<strong><a href="'.$announcement['threadlink'].'">'.$announcement['subject'].'</a> </strong>['.$announcement['threadusername'].'] <i class="fa fa-quote-left" aria-hidden="true"></i>
- ';
- }
- $page=preg_replace('#<div class="navigation">(.*)</div>#Usi','<div class="navigation">$1</div><br />
- <table border="0" cellspacing="'.$theme["borderwidth"].'" cellpadding="'.$theme["tablespace"].'" class="tborder" style="border-radius: 6px 6px 0 0;">
- <thead>
- <tr>
- <td class="thead" width="100" align="center" style="color: aquamarine; border-radius: 0 6px 0 0"><strong>Latest '.
- /* Use below code and set ^^(width) higher if you want board name to be said:
- $mybb->settings['bbname']
- */
- 'threads : </strong></td><td class="thead" style="color: aqua;border-radius: 6px 0 0 0;text-shadow:none;"><marquee direction="left" scrollamount="6" onmouseover="this.stop();" onmouseout="this.start();">'.$news.'</marquee></td>
- </tr>
- </thead>
- </table>',$page);
- return $page;
- }
- ?>
[mybb] latest threads plugin