Advertisement
Guest User

Untitled

a guest
Aug 10th, 2015
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.54 KB | None | 0 0
  1. <?php
  2. /**
  3.  *  Copyright © 2006-2008 CraKteR, crakter [at] gmail [dot] com
  4.  *
  5.  *  This program is free software: you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation, either version 3 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17.  *
  18.  *  @version $Id: onlinetoday.php 29 2008-08-14 19:00:36Z CraKteR $
  19.  *  @copyright $LastChangedDate: 2008-08-14 21:00:36 +0200 (to, 14 aug 2008) $
  20.  *  @author CraKteR <crakter@gmail.com>
  21.  */
  22.  
  23. if(!defined("IN_MYBB"))
  24. {
  25.     die("This file cannot be accessed directly.");
  26. }
  27.  
  28. $plugins->add_hook('index_start', 'add_onlinetoday', 1000000);
  29.  
  30. function onlinetoday_info()
  31. {
  32.     return array(
  33.         "name"          =>  "Show the users that has been online today",
  34.         "description"   =>  "Shows the users that has been online within 24 hours.",
  35.         "website"       =>  "",
  36.         "author"        =>  "CraKteR",
  37.         "authorsite"    =>  "mailto:crakter@gmail.com",
  38.         "version"       =>  "2.0",
  39.         "guid"          =>  "c2f1dd8db9b4f3898cb58f5ed02f9b53",
  40.         "compatibility" =>  "18*",
  41.     );
  42. }
  43.  
  44. function onlinetoday_activate()
  45. {
  46.     global $db;
  47.     $template = array(
  48.         "tid"       => NULL,
  49.         "title"     => "online_today_index",
  50.         "template"  => "<tr>
  51.     <td class=\"tcat\"><strong><span class=\"smalltext\">{\$lang->whos_online_today}</span></strong> [<a href=\"online.php?action=today\">{\$lang->complete_list}</a>]</td>
  52. </tr>
  53. <tr>
  54.     <td class=\"trow1\"><span class=\"smalltext\">{\$lang->online_note_today}<br />{\$onlinemembers}</span></td>
  55. </tr>",
  56.         "sid"       => "-1"
  57.     );
  58.     $db->insert_query("templates", $template);
  59.  
  60.     require MYBB_ROOT."/inc/adminfunctions_templates.php";
  61.     find_replace_templatesets('index_boardstats', '#{\$whosonline}#', "{\$whosonline}\n{\$online_today}");
  62. }
  63.  
  64. function onlinetoday_deactivate()
  65. {
  66.     global $db;
  67.     $db->query("DELETE FROM ".TABLE_PREFIX."templates WHERE title='online_today_index'");
  68.  
  69.     require MYBB_ROOT."/inc/adminfunctions_templates.php";
  70.  
  71.     find_replace_templatesets('index_boardstats', '#(\n?){\$online_today}#', '', 0);
  72. }
  73.  
  74. function add_onlinetoday()
  75. {
  76.     global $db, $mybb, $templates, $online_today, $lang, $theme;
  77.     $online_today = '';
  78.  
  79.     if($mybb->settings['showwol'] != 0 && $mybb->usergroup['canviewonline'] != 0)
  80.     {
  81.         $lang->load("onlinetoday");
  82.         $lang->load("index");
  83.         $timesearch = time() - 24*60*60;
  84.         $queries = array();
  85.         $queries[] = $db->simple_select(
  86.             "users u LEFT JOIN ".TABLE_PREFIX."sessions s ON (u.uid=s.uid)",
  87.             "s.sid, s.ip, s.time, s.location, u.uid, u.username, u.invisible, u.usergroup, u.displaygroup",
  88.             "u.lastactive > $timesearch ORDER BY u.username ASC, s.time DESC"
  89.         );
  90.         $queries[] = $db->simple_select(
  91.             "sessions s LEFT JOIN ".TABLE_PREFIX."users u ON (s.uid=u.uid)",
  92.             "s.sid, s.ip, s.uid, s.time, s.location, u.username, u.invisible, u.usergroup, u.displaygroup",
  93.             "s.time>'$timesearch' ORDER BY u.username ASC, s.time DESC"
  94.         );
  95.         $comma = $onlinemembers = '';
  96.         $membercount = $guestcount = $anoncount = 0;
  97.         $doneusers = $ips = array();
  98.         foreach($queries as $query)
  99.         {
  100.             while($user = $db->fetch_array($query))
  101.             {
  102.                 if(isset($user['sid']))
  103.                 {
  104.                     $botkey = strtolower(str_replace("bot=", '', $user['sid']));
  105.                 }
  106.  
  107.                 if($user['uid'] > 0)
  108.                 {
  109.                     if($doneusers[$user['uid']] < $user['time'] || !$doneusers[$user['uid']])
  110.                     {
  111.                         if($user['invisible'] == 1)
  112.                         {
  113.                             ++$anoncount;
  114.                         }
  115.                         ++$membercount;
  116.                         if($user['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1 || $user['uid'] == $mybb->user['uid'])
  117.                         {
  118.                             $invisiblemark = ($user['invisible'] == 1) ? "*" : "";
  119.                             $user['username'] = format_name($user['username'], $user['usergroup'], $user['displaygroup']);
  120.                             $user['profilelink'] = build_profile_link($user['username'], $user['uid']);
  121.                             eval("\$onlinemembers .= \"".$templates->get("index_whosonline_memberbit", 1, 0)."\";");
  122.                             $comma = ", ";
  123.                         }
  124.  
  125.                         if(isset($user['time']))
  126.                         {
  127.                             $doneusers[$user['uid']] = $user['time'];
  128.                         }
  129.                         else
  130.                         {
  131.                             $doneusers[$user['uid']] = $user['lastactive'];
  132.                         }
  133.                     }
  134.                 }
  135.                 else if(strstr($user['sid'], "bot=") !== false && $session->bots[$botkey] && !in_array($user['ip'], $ips))
  136.                 {
  137.                     $onlinemembers .= $comma.format_name($session->bots[$botkey], $session->botgroup);
  138.                     $comma = ", ";
  139.                     ++$botcount;
  140.                 }
  141.                 else
  142.                 {
  143.                     ++$guestcount;
  144.                     $guests[] = $user['ip'];
  145.                 }
  146.             }
  147.         }
  148.  
  149.         $onlinecount = $membercount + $guestcount;
  150.         $onlinebit = ($onlinecount != 1) ? $lang->online_online_plural : $lang->online_online_singular;
  151.         $memberbit = ($membercount != 1) ? $lang->online_member_plural : $lang->online_member_singular;
  152.         $anonbit = ($anoncount != 1) ? $lang->online_anon_plural : $lang->online_anon_singular;
  153.         $guestbit = ($guestcount != 1) ? $lang->online_guest_plural : $lang->online_guest_singular;
  154.         $lang->online_note_today = $lang->sprintf($lang->online_note_today, my_number_format($onlinecount), $onlinebit, 24, my_number_format($membercount), $memberbit, my_number_format($anoncount), $anonbit, my_number_format($guestcount), $guestbit);
  155.         eval("\$online_today = \"".$templates->get("online_today_index")."\";");
  156.     }
  157. }
  158. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement