Skip to content

Commit

Permalink
Update Whosonline
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex300 committed Mar 12, 2024
1 parent b0f99c8 commit c7f2a08
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 147 deletions.
12 changes: 12 additions & 0 deletions plugins/whosonline/setup/patch_1.3.6.inc
@@ -0,0 +1,12 @@
<?php
/**
* Update to v. 1.3.6
*/

if (!Cot::$db->fieldExists(Cot::$db->online, 'online_url')) {
Cot::$db->query(
'ALTER TABLE ' . Cot::$db->quoteTableName(Cot::$db->online)
. ' ADD ' . Cot::$db->quoteC('online_url') . " varchar(500) NOT NULL DEFAULT '' AFTER "
. Cot::$db->quoteC('online_subloc')
);
}
1 change: 1 addition & 0 deletions plugins/whosonline/setup/whosonline.install.sql
Expand Up @@ -7,6 +7,7 @@ CREATE TABLE `cot_online` (
`online_lastseen` int UNSIGNED NOT NULL default '0',
`online_location` varchar(128) NOT NULL default '',
`online_subloc` varchar(255) NOT NULL default '',
`online_url` varchar(500) NOT NULL default '',
`online_userid` int NOT NULL default '0', -- using '-1' value for guests
`online_shield` int NOT NULL default '0',
`online_action` varchar(64) NOT NULL default '',
Expand Down
111 changes: 71 additions & 40 deletions plugins/whosonline/tpl/whosonline.tpl
@@ -1,45 +1,76 @@
<!-- BEGIN: MAIN -->
<div class="block">
<h2 class="users"><a href="{PHP|cot_url('plug','e=whosonline')}">{PHP.L.WhosOnline}</a></h2>

<div class="block">
<h2 class="users"><a href="{PHP|cot_url('plug','e=whosonline')}">{PHP.L.WhosOnline}</a></h2>
<!-- IF {WHO_TOTALPAGES} > 1 -->
<p class="paging"><span>{PHP.L.Page} {WHO_CURRENTPAGE} {PHP.L.Of} {WHO_TOTALPAGES}</span>{WHO_PAGEPREV}{WHO_PAGINATION}{WHO_PAGENEXT}</p>
<table class="cells">
<thead>
<tr>
<th>{PHP.L.User}</th>
<th>{PHP.L.Group}</th>
<th>{PHP.L.Type}</th>
<th>{PHP.L.Location}</th>
<th>{PHP.L.LastSeen}</th>
<!-- IF {PHP.usr.isadmin} -->
<th>{PHP.L.Ip}</th><!-- ENDIF -->
</tr>
</thead>
<tbody>
<!-- BEGIN: USERS -->
<tr>
<td>{USER_LINK}</td>
<td>{USER_MAIN_GROUP}</td>
<td>
<!-- IF {PHP.usr.isadmin} AND {USER_URL} != '' --><a href="{USER_URL}"><!-- ENDIF -->
{USER_LOCATION}
<!-- IF {PHP.usr.isadmin} AND {USER_URL} != '' --></a><!-- ENDIF -->
</td>
<td>
<!-- IF {USER_SUBLOCATION} -->
<!-- IF {PHP.usr.isadmin} AND {USER_URL} != '' --><a href="{USER_URL}"><!-- ENDIF -->
{USER_SUBLOCATION}
<!-- IF {PHP.usr.isadmin} AND {USER_URL} != '' --></a><!-- ENDIF -->
<!-- ENDIF -->
</td>
<td>{USER_LASTSEEN} {PHP.L.Ago}</td>
<!-- IF {PHP.usr.isadmin} -->
<td>{USER_IP}</td>
<!-- ENDIF -->
<table class="cells">
<thead>
<tr>
<th>{PHP.L.User}</th>
<th>{PHP.L.Group}</th>
<th>{PHP.L.Type}</th>
<th>{PHP.L.Location}</th>
<th>{PHP.L.LastSeen}</th>
<!-- IF {PHP.usr.isadmin} --><th>{PHP.L.Ip}</th><!-- ENDIF -->
</tr>
</thead>
<tbody>
<!-- BEGIN: USERS -->
<tr>
<td>{USER_LINK}</td>
<td>{USER_MAIN_GROUP}</td>
<td>{USER_LOCATION}</td>
<td>{USER_SUBLOCATION}</td>
<td>{USER_LASTSEEN} {PHP.L.Ago}</td>
<!-- IF {PHP.usr.isadmin} --><td>{USER_IP}</td><!-- ENDIF -->
</tr>
<!-- END: USERS -->
<!-- BEGIN: GUESTS -->
<tr>
<td colspan="2">{PHP.L.Guest} #{GUEST_NUMBER}</td>
<td>{GUEST_LOCATION}</td>
<td>{GUEST_SUBLOCATION}</td>
<td>{GUEST_LASTSEEN} {PHP.L.Ago}</td>
<!-- IF {PHP.usr.isadmin} --><td>{GUEST_IP}</td><!-- ENDIF -->
</tr>
<!-- END: GUESTS -->
</tbody>
</table>
<p><strong>{PHP.L.NowOnline}:</strong> {STAT_COUNT_USERS} {USERS}<!-- IF !{PHP.cfg.plugin.whosonline.disable_guests} -->, {STAT_COUNT_GUESTS} {GUESTS}<!-- ENDIF --></p>
<!-- IF {STAT_MAXUSERS} --><p><strong>{PHP.L.MostOnline}:</strong> {STAT_MAXUSERS}</p><!-- ENDIF -->
</div>
</tr>
<!-- END: USERS -->
<!-- BEGIN: GUESTS -->
<tr>
<td colspan="2">{PHP.L.Guest} #{GUEST_NUMBER}</td>
<td>
<!-- IF {PHP.usr.isadmin} AND {GUEST_URL} != '' --><a href="{GUEST_URL}"><!-- ENDIF -->
{GUEST_LOCATION}
<!-- IF {PHP.usr.isadmin} AND {GUEST_URL} != '' --></a><!-- ENDIF -->
</td>
<td>
<!-- IF {GUEST_SUBLOCATION} -->
<!-- IF {PHP.usr.isadmin} AND {GUEST_URL} != '' --><a href="{GUEST_URL}"><!-- ENDIF -->
{GUEST_SUBLOCATION}
<!-- IF {PHP.usr.isadmin} AND {GUEST_URL} != '' --></a><!-- ENDIF -->
<!-- ENDIF -->
</td>
<td>{GUEST_LASTSEEN} {PHP.L.Ago}</td>
<!-- IF {PHP.usr.isadmin} -->
<td>{GUEST_IP}</td>
<!-- ENDIF -->
</tr>
<!-- END: GUESTS -->
</tbody>
</table>

<!-- IF {TOTAL_PAGES} > 1 -->
<p class="paging">
<span>{PHP.L.Page} {CURRENT_PAGE} {PHP.L.Of} {TOTAL_PAGES}</span>{PREVIOUS_PAGE}{PAGINATION}{NEXT_PAGE}
</p>
<!-- ENDIF -->

<p>
<strong>{PHP.L.NowOnline}:</strong> {STAT_COUNT_USERS}
{USERS}<!-- IF !{PHP.cfg.plugin.whosonline.disable_guests} -->, {STAT_COUNT_GUESTS} {GUESTS}<!-- ENDIF -->
</p>
<!-- IF {STAT_MAXUSERS} --><p><strong>{PHP.L.MostOnline}:</strong> {STAT_MAXUSERS}</p><!-- ENDIF -->
</div>
<!-- END: MAIN -->
96 changes: 61 additions & 35 deletions plugins/whosonline/whosonline.header.main.php
Expand Up @@ -22,50 +22,76 @@
$subLocation = isset(Cot::$sys['sublocation']) ? Cot::$sys['sublocation'] : null;
$location = isset(Cot::$env['location']) ? Cot::$env['location'] : null;

// $_SERVER['HTTP_HOST'] and $_SERVER['REQUEST_URI'] are shows real url
$currentUrl = Cot::$sys['scheme'] . '://' . $_SERVER['HTTP_HOST'] . '/' . ltrim($_SERVER['REQUEST_URI'], '/');
if (mb_strlen($currentUrl) > 500) {
$currentUrl = '';
}

if ($location != $onlineLocation || $subLocation != Cot::$sys['online_subloc']) {
$locationToSave = mb_substr((string) $location, 0, 128);
$subLocationToSave = mb_substr((string) $subLocation, 0, 255);

if (Cot::$usr['id'] > 0) {
if (empty($sys['online_location'])) {
Cot::$db->insert($db_online, array(
'online_ip' => Cot::$usr['ip'],
'online_name' => Cot::$usr['name'],
'online_lastseen' => (int) Cot::$sys['now'],
'online_location' => $location,
'online_subloc' => (string) $subLocation,
'online_userid' => (int) Cot::$usr['id'],
'online_shield' => 0,
'online_hammer' => 0
));
if (empty(Cot::$sys['online_location'])) {
Cot::$db->insert(
Cot::$db->online,
[
'online_ip' => Cot::$usr['ip'],
'online_name' => Cot::$usr['name'],
'online_lastseen' => (int) Cot::$sys['now'],
'online_location' => $locationToSave,
'online_subloc' => $subLocationToSave,
'online_url' => $currentUrl,
'online_userid' => (int) Cot::$usr['id'],
'online_shield' => 0,
'online_hammer' => 0,
]
);

} else {
$onlineHummer = isset(Cot::$sys['online_hammer']) ? (int) Cot::$sys['online_hammer'] : 0;
Cot::$db->update($db_online, array(
'online_lastseen' => Cot::$sys['now'],
'online_location' => $location,
'online_subloc' => (string) $subLocation,
'online_hammer' => $onlineHummer
), "online_userid=".Cot::$usr['id']);
Cot::$db->update(
Cot::$db->online,
[
'online_lastseen' => Cot::$sys['now'],
'online_location' => $locationToSave,
'online_subloc' => $subLocationToSave,
'online_url' => $currentUrl,
'online_hammer' => $onlineHummer
],
'online_userid = ' . Cot::$usr['id']
);
}

} elseif(!Cot::$cfg['plugin']['whosonline']['disable_guests']) {
} elseif (!Cot::$cfg['plugin']['whosonline']['disable_guests']) {
if (empty($sys['online_location'])) {
Cot::$db->insert($db_online, array(
'online_ip' => Cot::$usr['ip'],
'online_name' => 'v',
'online_lastseen' => (int) Cot::$sys['now'],
'online_location' => $location,
'online_subloc' => isset(Cot::$sys['sublocation']) ? (string) Cot::$sys['sublocation'] : '',
'online_userid' => -1,
'online_shield' => 0,
'online_hammer' => 0
));

Cot::$db->insert(
Cot::$db->online,
[
'online_ip' => Cot::$usr['ip'],
'online_name' => 'v',
'online_lastseen' => (int) Cot::$sys['now'],
'online_location' => $locationToSave,
'online_subloc' => $subLocationToSave,
'online_url' => $currentUrl,
'online_userid' => -1,
'online_shield' => 0,
'online_hammer' => 0,
]
);
} else {
Cot::$db->update($db_online, array(
'online_lastseen' => Cot::$sys['now'],
'online_location' => $location,
'online_subloc' => isset(Cot::$sys['sublocation']) ? (string) Cot::$sys['sublocation'] : '',
'online_hammer' => isset(Cot::$sys['online_hammer']) ? (int) Cot::$sys['online_hammer'] : 0
), "online_ip='".Cot::$usr['ip']."' AND online_userid < 0");
Cot::$db->update(
Cot::$db->online,
[
'online_lastseen' => Cot::$sys['now'],
'online_location' => $locationToSave,
'online_subloc' => $subLocationToSave,
'online_url' => $currentUrl,
'online_hammer' => isset(Cot::$sys['online_hammer']) ? (int) Cot::$sys['online_hammer'] : 0,
],
"online_ip = '" . Cot::$usr['ip'] . "' AND online_userid < 0"
);
}
}
}
Expand Down

0 comments on commit c7f2a08

Please sign in to comment.