rocksolid-light/Rocksolid_Light/rslight/scripts/count_users.php

50 lines
1.4 KiB
PHP
Raw Normal View History

2021-04-30 01:16:32 +02:00
<?php
include "config.inc.php";
include ("$file_newsportal");
if(trim($CONFIG['tac'] == '')) {
if(is_file($spooldir.'/sessions.dat')) {
unlink($spooldir.'/sessions.dat');
}
exit(0);
}
count_users();
function count_articles() {
GLOBAL $CONFIG, $spooldir;
$database = $spooldir.'/articles-overview.db3';
$dbh = rslight_db_open($database);
$count = $dbh->query('SELECT COUNT(DISTINCT msgid) FROM overview')->fetchColumn();
$dbh = null;
return $count;
}
2021-04-30 01:16:32 +02:00
function count_users() {
GLOBAL $CONFIG, $spooldir;
2021-05-03 11:11:37 +02:00
$session_age = 600;
2021-04-30 01:16:32 +02:00
$session_save_file = $spooldir.'/sessions.dat';
$session_dir = $CONFIG['tac'];
$session_files = scandir($session_dir);
$count = 0;
foreach($session_files as $session_file) {
if(filemtime($session_dir.'/'.$session_file) < time() - $session_age) {
continue;
}
if(strpos($session_file, 'sess_') === 0) {
$contents = file_get_contents($session_dir.'/'.$session_file);
2021-05-03 11:11:37 +02:00
if(strpos($contents, 'rsactive') !== false) {
2021-04-30 01:16:32 +02:00
$count++;
}
}
}
if($count == 1) {
$are = 'is';
$users = 'user';
} else {
$are = 'are';
$users = 'users';
}
$session_info = '<h1 class="np_thread_headline">There '.$are.' currently '.$count.' '. $users.' online <br />Total messages: '.number_format(count_articles()).'</h1>'."\r\n";
2021-04-30 01:16:32 +02:00
file_put_contents($session_save_file, $session_info);
}
?>