15.05.2016, 19:57
1 Edycja pluginu
Otwieramy plik pluginu (/inc/plugins/dvz_shoutbox.php) i szukamy dodanego w poprzednim poradniku hooka (~ 9 linijka):
$plugins->add_hook('chat_start', ['dvz_shoutbox', 'load_window']);
Następnie wklejamy pod nim:
$plugins->add_hook('chat_start', 'dvz_shoutbox_stats');
$plugins->add_hook('global_start', 'dvz_shoutbox_users_on_sb');
Teraz zchodzimy na sam dół pliku i wklejamy:
function dvz_shoutbox_stats()
{
global $db, $mybb, $templates, $theme, $wpisy, $users, $top_spamer, $users_online_o, $top_spamer_noformatted, $shshshs, $our_shouts, $timesearch, $shouts, $username, $user, $users_online, $anon_online, $invisiblemark, $onlinemembers, $guests_online, $spiders, $cache, $bots_online;
// Użytkownicy online
$timesearch = TIME_NOW - $mybb->settings['wolcutoff'];
$comma = '';
$query3 = $db->query("
SELECT s.sid, s.ip, s.uid, s.time, s.location, s.location1, u.username, u.invisible, u.usergroup, u.displaygroup
FROM ".TABLE_PREFIX."sessions s
LEFT JOIN ".TABLE_PREFIX."users u ON (s.uid=u.uid)
WHERE location LIKE '%shoutbox.php%' && s.time>'".$timesearch."'
ORDER BY u.username ASC, s.time DESC
");
$spiders = $cache->read("spiders");
$users_online = 0;
$anon_online = 0;
$guests_online = 0;
$bots_online = 0;
$onlinemembers = '';
while($user = $db->fetch_array($query3))
{
if($user['uid'] > 0)
{
if($user['invisible'] == 1)
{
++$anon_online;
}
if($user['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1 || $user['uid'] == $mybb->user['uid'])
{
if($user['invisible'] == 1)
{
$invisiblemark = "*";
}
else
{
$invisiblemark = '';
}
++$anon_online;
$username = build_profile_link(format_name($user['username'], $user['usergroup'], $user['displaygroup']), $user['uid']);
$onlinemembers .= ''.$comma.' '.$username.''.$invisiblemark.'';
$comma = " ,";
}
++$users_online;
}
elseif(my_strpos($user['sid'], "bot=") !== false && $spiders[$botkey])
{
// The user is a search bot.
$onlinemembers .= $comma.format_name($spiders[$botkey]['name'], $spiders[$botkey]['usergroup']);
$comma = ", ";
++$bots_online;
}
else
{
// The user is a guest.
++$guests_online;
}
$users_online_o = $users_online + $guests_online;
}
// Statystyki
$query = $db->query("SELECT count(id) as id FROM ".TABLE_PREFIX."dvz_shoutbox");
$row = $db->fetch_array($query);
$wpisy = $row['id'];
$query3 = $db->query("SELECT d.uid, u.username, u.usergroup, u.displaygroup, u.uid, u.avatar, count(*) as shouters
FROM ".TABLE_PREFIX."dvz_shoutbox d
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=d.uid)
GROUP BY d.uid
ORDER BY shouters
DESC LIMIT 1");
$row3 = $db->fetch_array($query3);
$shouts = $row3['shouters'];
$top_spamer_noformatted = $row3['username'];
$top_spamer = build_profile_link(format_name($row3['username'], $row3['usergroup'], $row3['displaygroup']), $row3['uid']);
$query4 = $db->query("SELECT count(id) as id, uid FROM ".TABLE_PREFIX."dvz_shoutbox WHERE uid='".$mybb->user['uid']."'");
$our_shouts = $db->fetch_field($query4, "id");
}
function dvz_shoutbox_users_on_sb()
{
global $db, $mybb, $templates, $theme, $users_o_sb, $timesearch;
$timesearch = TIME_NOW - $mybb->settings['wolcutoff'];
$query = $db->query("SELECT count(*) as guid, time FROM ".TABLE_PREFIX."sessions WHERE location LIKE '%shoutbox.php%' && uid!=0 && time>".$timesearch."");
$users_o_sb = $db->fetch_field($query, 'guid');
}
Zapisujemy plik.
2 Edycja szablonu
Otwieramy nasz szablon stworzony w poprzednim poradniku (ACP - Style i Szablony - Szablony Globalne - dvz_shoutbox_page) i nad {$footer} wklejamy:
<div class="shoutbox-stats">
<span class="stat">Twoich shoutów: <span class="block">{$our_shouts}</span></span>
<span class="stat">Wszystkich shoutów: <span class="block">{$wpisy}</span></span>
<span class="stat">Największy spamer: <span class="block">{$top_spamer_noformatted} ({$shouts})</span></span>
</div>
<strong>Kto jest na shoutboxie ({$users_online_o}):</strong><br />
{$onlinemembers}
Oraz css (oczywiście przykładowy):
.shoutbox-stats {
margin: 20px;
text-align: center;
}
.shoutbox-stats .stat {
margin: 10px;
}
.shoutbox-stats .block {
background: #212121;
padding: 6px;
border-radius: 2px;
font-weight: bold;
color: #FFF;
}
Poradnik został stworzony dzięki informacjom zawartym w tym wątku: Dvz shoutbox na podstronie