<?php
/**
* Copyright (c) 2007-2014, Jos de Ruijter <jos@dutnie.nl>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* Class for creating the main stats page.
*/
final class html extends base
{
/**
* Default settings for this script, which can be overridden in the configuration file. These variables should
* all appear in $settings_list[] along with their type.
*/
private $addhtml_foot = '';
private $addhtml_head = '';
private $channel = '';
private $cid = '';
private $history = false;
private $maxrows = 5;
private $maxrows_people2 = 10;
private $maxrows_people_alltime = 30;
private $maxrows_people_month = 10;
private $maxrows_people_timeofday = 10;
private $maxrows_people_year = 10;
private $maxrows_recenturls = 25;
private $minrows = 3;
private $recenturls_type = 1;
private $rows_domains_tlds = 10;
private $sectionbits = 255;
private $settings_list = array(
'addhtml_foot' => 'string',
'addhtml_head' => 'string',
'channel' => 'string',
'cid' => 'string',
'history' => 'bool',
'maxrows' => 'int',
'maxrows_people2' => 'int',
'maxrows_people_alltime' => 'int',
'maxrows_people_month' => 'int',
'maxrows_people_timeofday' => 'int',
'maxrows_people_year' => 'int',
'maxrows_recenturls' => 'int',
'minrows' => 'int',
'outputbits' => 'int',
'recenturls_type' => 'int',
'rows_domains_tlds' => 'int',
'sectionbits' => 'int',
'stylesheet' => 'string',
'userstats' => 'bool');
private $stylesheet = 'sss.css';
private $userstats = false;
/**
* Variables that shouldn't be tampered with.
*/
private $color = array(
'night' => 'b',
'morning' => 'g',
'afternoon' => 'y',
'evening' => 'r');
private $datetime = array();
private $estimate = false;
private $l_total = 0;
private $output = '';
public function __construct($settings)
{
/**
* If set, override variables listed in $settings_list[].
*/
foreach ($this->settings_list as $key => $type) {
if (!array_key_exists($key, $settings)) {
continue;
}
if ($type === 'string') {
$this->$key = $settings[$key];
} elseif ($type === 'int') {
$this->$key = (int) $settings[$key];
} elseif ($type === 'bool') {
if (strtolower($settings[$key]) === 'true') {
$this->$key = true;
} elseif (strtolower($settings[$key]) === 'false') {
$this->$key = false;
}
}
}
/**
* If $cid has no value set it to $channel.
*/
if ($this->cid === '') {
$this->cid = $this->channel;
}
}
/**
* Calculate how many days ago a given $datetime is.
*/
private function daysago($datetime)
{
$daysago = round((strtotime('today') - strtotime(substr($datetime, 0, 10))) / 86400);
if (($daysago / 365) >= 1) {
$daysago = str_replace('.0', '', number_format($daysago / 365, 1));
$daysago .= ' Year'.((float) $daysago > 1 ? 's' : '').' Ago';
} elseif (($daysago / 30.42) >= 1) {
$daysago = str_replace('.0', '', number_format($daysago / 30.42, 1));
$daysago .= ' Month'.((float) $daysago > 1 ? 's' : '').' Ago';
} elseif ($daysago > 1) {
$daysago .= ' Days Ago';
} elseif ($daysago === (float) 1) {
$daysago = 'Yesterday';
} elseif ($daysago === (float) 0) {
$daysago = 'Today';
}
return $daysago;
}
/**
* Generate the HTML page.
*/
public function make_html($sqlite3)
{
$this->output('notice', 'make_html(): creating stats page');
if (($this->l_total = $sqlite3->querySingle('SELECT SUM(l_total) FROM channel_activity')) === false) {
$this->output('critical', basename(__FILE__).':'.__LINE__.', sqlite3 says: '.$sqlite3->lastErrorMsg());
}
/**
* All queries from this point forward require a non empty database.
*/
if (is_null($this->l_total)) {
$this->output('warning', 'make_html(): database is empty');
return '<!DOCTYPE html>'."\n\n".'<html><head><meta charset="utf-8"><title>seriously?</title><link rel="stylesheet" href="sss.css"></head><body><div id="container"><div class="error">There is not enough data to create statistics, yet.</div></div></body></html>'."\n";
}
if (($result = $sqlite3->querySingle('SELECT MIN(date) AS date_first, MAX(date) AS date_last FROM channel_activity', true)) === false) {
$this->output('critical', basename(__FILE__).':'.__LINE__.', sqlite3 says: '.$sqlite3->lastErrorMsg());
}
$date_first = $result['date_first'];
$date_last = $result['date_last'];
if (($result = $sqlite3->querySingle('SELECT COUNT(*) AS dayslogged, MAX(date) AS date FROM parse_history', true)) === false) {
$this->output('critical', basename(__FILE__).':'.__LINE__.', sqlite3 says: '.$sqlite3->lastErrorMsg());
}
$date_lastlogparsed = $result['date'];
$dayslogged = $result['dayslogged'];
$l_avg = $this->l_total / $dayslogged;
/**
* Date and time variables used throughout the script. These are based on the date of the last logfile
* parsed, and are used to define our scope.
*/
$this->datetime['currentyear'] = (int) date('Y');
$this->datetime['dayofmonth'] = (int) date('j', strtotime($date_lastlogparsed));
$this->datetime['firstyearmonth'] = substr($date_first, 0, 7);
$this->datetime['month'] = (int) date('n', strtotime($date_lastlogparsed));
$this->datetime['monthname'] = date('F', strtotime($date_lastlogparsed));
$this->datetime['year'] = (int) date('Y', strtotime($date_lastlogparsed));
$this->datetime['years'] = $this->datetime['year'] - (int) date('Y', strtotime($date_first)) + 1;
$this->datetime['daysleft'] = (int) date('z', strtotime('last day of December '.$this->datetime['year'])) - (int) date('z', strtotime($date_lastlogparsed));
/**
* Show a minimum of 3 columns in the Activity by Year table.
*/
if ($this->datetime['years'] < 3) {
$this->datetime['years'] = 3;
}
/**
* If there are one or more days to come until the end of the year, display an additional column in the
* Activity by Year table with an estimated line count for the current year.
*/
if ($this->datetime['daysleft'] !== 0 && $this->datetime['year'] === $this->datetime['currentyear']) {
/**
* Base the estimation on the activity in the last 90 days logged, if there is any.
*/
if (($activity = $sqlite3->querySingle('SELECT COUNT(*) FROM channel_activity WHERE date > \''.date('Y-m-d', mktime(0, 0, 0, $this->datetime['month'], $this->datetime['dayofmonth'] - 90, $this->datetime['year'])).'\'')) === false) {
$this->output('critical', basename(__FILE__).':'.__LINE__.', sqlite3 says: '.$sqlite3->lastErrorMsg());
}
if ($activity !== 0) {
$this->estimate = true;
}
}
/**
* HTML Head.
*/
if (($result = $sqlite3->querySingle('SELECT MIN(date) AS date, l_total FROM channel_activity WHERE l_total = (SELECT MAX(l_total) FROM channel_activity)', true)) === false) {
$this->output('critical', basename(__FILE__).':'.__LINE__.', sqlite3 says: '.$sqlite3->lastErrorMsg());
}
$date_max = $result['date'];
$l_max = $result['l_total'];
$this->output = '<!DOCTYPE html>'."\n\n"
. '<html>'."\n\n"
. '<head>'."\n"
. '<meta charset="utf-8">'."\n"
. '<title>'.htmlspecialchars($this->channel).', seriously.</title>'."\n"
. '<link rel="stylesheet" href="'.$this->stylesheet.'">'."\n"
. '<style type="text/css">'."\n"
. ' .act-year { width:'.(2 + (($this->datetime['years'] + ($this->estima
SuperSeriousStats(IRC日志分析工具).7z
133 浏览量
2023-03-18
18:53:06
上传
评论
收藏 38KB 7Z 举报
BryanDing
- 粉丝: 297
- 资源: 5587
最新资源
- 微软常用运行库 游戏运行库 VC++各个版本
- 微信小程序开发教程.pptx
- MyBatis动态SQL是一种强大的特性,它允许我们在SQL语句中根据条件动态地添加或删除某些部分,从而实现更加灵活和高效的数据
- 锐捷网络认证中心网络管理.pdf
- MyBatis动态SQL是一种强大的特性,它允许我们在SQL语句中根据条件动态地添加或删除某些部分,从而实现更加灵活和高效的数据
- SD8233LF是一款用于单按键触摸及接近感应开关,其用途是替代传统的机械型开关芯片IC
- 基于YOLOv5的烟雾火焰检测算法研究
- 基于STM32的联合调试侦听设备解决方案原理图PCB源文件调试工具视频(大赛作品)
- MyBatis动态SQL是一种强大的特性,它允许我们在SQL语句中根据条件动态地添加或删除某些部分,从而实现更加灵活和高效的数据
- MyBatis动态SQL是一种强大的特性,它允许我们在SQL语句中根据条件动态地添加或删除某些部分,从而实现更加灵活和高效的数据
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈