1. <?php
  2. /*
  3. A clear news bar plugin for MyBB
  4. * v. 1.0
  5. * Last edit: 5 August 2010
  6. * Shows a clear news bar on your forum pages.
  7. * Copyright (C) 2009 & 2010 Mateusz Grzesiukiewicz also known as Ajdija
  8. * Website: http://www.ajdija.com
  9. This program is free software: you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation, either version 3 of the License, or
  12. (at your option) any later version.
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  17. You should have received a copy of the GNU General Public License
  18. along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. if(!defined("IN_MYBB"))
  21. {
  22. die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
  23. }
  24. $plugins->add_hook('pre_output_page','aclearnewsbar');
  25. function aclearnewsbar_info()
  26. {
  27. return array
  28. (
  29. "name"=>"A clear news bar",
  30. "description"=>"Shows a clear bar with latest news from your portal page.",
  31. "website"=>"http://www.ajdija.com",
  32. "author"=>"Mateusz Grzesiukiewicz",
  33. "authorsite"=> "http://www.ajdija.com",
  34. "version"=>"1.0",
  35. "guid"=>"7dc27e3041bfe6e412f1a9b2f7634db2",
  36. "compatibility"=>"18*"
  37. );
  38. }
  39. function aclearnewsbar($page)
  40. {
  41. global $mybb,$theme, $db;
  42. $announcements = '';
  43. $query = $db->query("
  44. SELECT t.tid,t.subject, t.username AS threadusername, t.dateline as date_p, tp.displaystyle AS D_STYLE
  45. FROM ".TABLE_PREFIX."threads t
  46. LEFT JOIN " .TABLE_PREFIX. "threadprefixes tp ON (t.prefix = tp.pid)
  47. WHERE t.visible='1' AND t.closed NOT LIKE 'moved|%'
  48. ORDER BY t.dateline DESC
  49. LIMIT 0,10 " // 10 is the number of latest threads
  50. );
  51. $news = '';
  52. function getTheDay($date)
  53. {
  54. date_default_timezone_set('Europe/Paris'); // !important set timezone
  55. $curr_date=date("Y-m-d"); // format the date (to remove hours and minutes and secondes)
  56. $curr_date=strtotime($curr_date); // date to integer
  57. if (date('I', time())) // test dst
  58. {
  59. // echo "We are in DST!";
  60. $curr_date=$curr_date - 3600; // correct the DST using local time
  61. $curr_date=date("Y-m-d"); // integer to date again
  62. $curr_date=strtotime($curr_date); //date to integer again (to remove hours and minutes and secondes)
  63. }
  64. $the_date=$date-3600; //mybb use DST by default.
  65. $the_date=date("Y-m-d",$the_date); // integer to date (to remove hours and minutes and secondes)
  66. $the_date=strtotime($the_date); //date to integer again
  67. $diff=$curr_date-$the_date;
  68. $diff=$diff/86400; //1 day = 86400 sec
  69. switch($diff)
  70. {
  71. case 0:
  72. return 'today';
  73. break;
  74. case 1:
  75. return "yesterday";
  76. break;
  77. case 2:
  78. return '2 days ago';
  79. break;
  80. case 3:
  81. return '3 days ago';
  82. break;
  83. default:
  84. return date("Y-m-d",$the_date);
  85. }
  86. }
  87. while($announcement = $db->fetch_array($query))
  88. {
  89. $announcement['threadlink'] = get_thread_link($announcement['tid']);
  90. //$announcement['subject'] = htmlspecialchars_uni($announcement['subject']);
  91. //$announcement['threadusername'] = htmlspecialchars_uni($announcement['threadusername']);
  92. $announcement['date_p']=getTheDay($announcement['date_p']);
  93. $news = $news.'&nbsp;&nbsp;&nbsp;&nbsp;<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;
  94. ">'.$announcement['date_p'].'</span> '.$announcement['D_STYLE'].' '.'<strong><a href="'.$announcement['threadlink'].'">'.$announcement['subject'].'</a> &nbsp;</strong>['.$announcement['threadusername'].']&nbsp;<i class="fa fa-quote-left" aria-hidden="true"></i>
  95. ';
  96. }
  97. $page=preg_replace('#<div class="navigation">(.*)</div>#Usi','<div class="navigation">$1</div><br />
  98. <table border="0" cellspacing="'.$theme["borderwidth"].'" cellpadding="'.$theme["tablespace"].'" class="tborder" style="border-radius: 6px 6px 0 0;">
  99. <thead>
  100. <tr>
  101. <td class="thead" width="100" align="center" style="color: aquamarine; border-radius: 0 6px 0 0"><strong>Latest '.
  102. /* Use below code and set ^^(width) higher if you want board name to be said:
  103. $mybb->settings['bbname']
  104. */
  105. '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>
  106. </tr>
  107. </thead>
  108. </table>',$page);
  109. return $page;
  110. }
  111. ?>

[mybb] latest threads plugin