Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

5.0

  • Loading branch information...
commit c71d4639bb323d75a77b739292bcc3a16e5d6ba2 1 parent 7dfb505
@tommyrot authored
View
71 base.class.php → base.php
@@ -22,8 +22,7 @@
abstract class base
{
/**
- * Default settings for this script, can be overridden in the config file.
- * These should all appear in $settings_list[] along with their type.
+ * Default settings for this script, can be overridden in the config file. These should all appear in $settings_list[] along with their type.
*/
protected $outputbits = 1;
@@ -38,70 +37,28 @@
}
/**
- * Create part of the mysql insert query containing new data.
+ * Create parts of the mysql query.
*/
- final protected function create_insert_query($columns)
+ final protected function create_query($columns)
{
- $changes = false;
- $query = '';
+ $insert = '';
+ $update = '';
foreach ($columns as $key) {
if (is_int($this->$key) && $this->$key != 0) {
- $query .= ' `'.$key.'` = '.$this->$key.',';
- $changes = true;
+ $insert .= ' `'.$key.'` = '.$this->$key.',';
+ $update .= ' `'.$key.'` = `'.$key.'` + '.$this->$key.',';
} elseif (is_string($this->$key) && $this->$key != '') {
- $query .= ' `'.$key.'` = \''.mysqli_real_escape_string($this->mysqli, $this->$key).'\',';
- $changes = true;
+ $tmp = ' `'.$key.'` = \''.mysqli_real_escape_string($this->mysqli, $this->$key).'\',';
+ $insert .= $tmp;
+ $update .= $tmp;
}
}
- if ($changes) {
- return rtrim($query, ',');
+ if (!empty($insert)) {
+ return rtrim($insert, ',').' on duplicate key update'.rtrim($update, ',');
} else {
- return;
- }
- }
-
- /**
- * Create part of the mysql update query containing new data.
- */
- final protected function create_update_query($columns, $exclude)
- {
- $changes = false;
- $query = '';
-
- foreach ($columns as $key => $value) {
- if (in_array($key, $exclude)) {
- continue;
- }
-
- if ($key == 'firstseen' && $value != '0000-00-00 00:00:00' && strtotime($this->firstseen) >= strtotime($value)) {
- continue;
- } elseif ($key == 'firstused' && $value != '0000-00-00 00:00:00' && strtotime($this->firstused) >= strtotime($value)) {
- continue;
- } elseif ($key == 'lastseen' && $value != '0000-00-00 00:00:00' && strtotime($this->lastseen) <= strtotime($value)) {
- continue;
- } elseif ($key == 'lastused' && $value != '0000-00-00 00:00:00' && strtotime($this->lastused) <= strtotime($value)) {
- continue;
- } elseif ($key == 'lasttalked' && $value != '0000-00-00 00:00:00' && strtotime($this->lasttalked) <= strtotime($value)) {
- continue;
- } elseif ($key == 'topmonologue' && $this->topmonologue <= (int) $value) {
- continue;
- }
-
- if (is_int($this->$key) && $this->$key != 0) {
- $query .= ' `'.$key.'` = '.((int) $value + $this->$key).',';
- $changes = true;
- } elseif (is_string($this->$key) && $this->$key != '') {
- $query .= ' `'.$key.'` = \''.mysqli_real_escape_string($this->mysqli, $this->$key).'\',';
- $changes = true;
- }
- }
-
- if ($changes) {
- return rtrim($query, ',');
- } else {
- return;
+ return null;
}
}
@@ -119,7 +76,7 @@
* Don't output the same thing twice, like mode errors and repeated lines.
*/
if (in_array($msg, $this->prevoutput)) {
- return;
+ return null;
}
$this->prevoutput[] = $msg;
View
142 empty_database_v4.sql → empty_database_v5.sql
@@ -1,8 +1,8 @@
--- MySQL dump 10.13 Distrib 5.1.48, for unknown-openbsd4.8 (i386)
+-- MySQL dump 10.13 Distrib 5.1.60, for unknown-openbsd5.1 (i386)
--
-- Host: localhost Database: sss
-- ------------------------------------------------------
--- Server version 5.1.48-log
+-- Server version 5.1.60
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
@@ -59,6 +59,21 @@ CREATE TABLE `channel` (
/*!40101 SET character_set_client = @saved_cs_client */;
--
+-- Table structure for table `fqdns`
+--
+
+DROP TABLE IF EXISTS `fqdns`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `fqdns` (
+ `fid` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `fqdn` varchar(255) NOT NULL DEFAULT '',
+ PRIMARY KEY (`fid`),
+ UNIQUE KEY `fqdn` (`fqdn`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
-- Table structure for table `mv_activedays`
--
@@ -137,7 +152,7 @@ DROP TABLE IF EXISTS `mv_ex_kicked`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `mv_ex_kicked` (
`ruid` int(10) unsigned NOT NULL DEFAULT '0',
- `ex_kicked` varchar(255) NOT NULL DEFAULT '',
+ `ex_kicked` varchar(307) NOT NULL DEFAULT '',
PRIMARY KEY (`ruid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -151,7 +166,7 @@ DROP TABLE IF EXISTS `mv_ex_kicks`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `mv_ex_kicks` (
`ruid` int(10) unsigned NOT NULL DEFAULT '0',
- `ex_kicks` varchar(255) NOT NULL DEFAULT '',
+ `ex_kicks` varchar(307) NOT NULL DEFAULT '',
PRIMARY KEY (`ruid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -375,8 +390,8 @@ CREATE TABLE `q_events` (
`kicked` int(10) unsigned NOT NULL DEFAULT '0',
`nickchanges` int(10) unsigned NOT NULL DEFAULT '0',
`topics` int(10) unsigned NOT NULL DEFAULT '0',
- `ex_kicks` varchar(255) NOT NULL DEFAULT '',
- `ex_kicked` varchar(255) NOT NULL DEFAULT '',
+ `ex_kicks` varchar(307) NOT NULL DEFAULT '',
+ `ex_kicked` varchar(307) NOT NULL DEFAULT '',
PRIMARY KEY (`ruid`),
KEY `m_op` (`m_op`),
KEY `m_opped` (`m_opped`),
@@ -618,7 +633,7 @@ DROP TABLE IF EXISTS `streak_history`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `streak_history` (
- `prevnick` varchar(255) NOT NULL DEFAULT '',
+ `prevnick` varchar(32) NOT NULL DEFAULT '',
`streak` int(10) unsigned NOT NULL DEFAULT '0'
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -702,7 +717,7 @@ DROP TABLE IF EXISTS `t_mv_ex_kicked`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `t_mv_ex_kicked` (
`ruid` int(10) unsigned NOT NULL DEFAULT '0',
- `ex_kicked` varchar(255) NOT NULL DEFAULT '',
+ `ex_kicked` varchar(307) NOT NULL DEFAULT '',
PRIMARY KEY (`ruid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -716,7 +731,7 @@ DROP TABLE IF EXISTS `t_mv_ex_kicks`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `t_mv_ex_kicks` (
`ruid` int(10) unsigned NOT NULL DEFAULT '0',
- `ex_kicks` varchar(255) NOT NULL DEFAULT '',
+ `ex_kicks` varchar(307) NOT NULL DEFAULT '',
PRIMARY KEY (`ruid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -926,8 +941,8 @@ CREATE TABLE `t_q_events` (
`kicked` int(10) unsigned NOT NULL DEFAULT '0',
`nickchanges` int(10) unsigned NOT NULL DEFAULT '0',
`topics` int(10) unsigned NOT NULL DEFAULT '0',
- `ex_kicks` varchar(255) NOT NULL DEFAULT '',
- `ex_kicked` varchar(255) NOT NULL DEFAULT '',
+ `ex_kicks` varchar(307) NOT NULL DEFAULT '',
+ `ex_kicked` varchar(307) NOT NULL DEFAULT '',
PRIMARY KEY (`ruid`),
KEY `m_op` (`m_op`),
KEY `m_opped` (`m_opped`),
@@ -1162,6 +1177,40 @@ CREATE TABLE `t_q_smileys` (
/*!40101 SET character_set_client = @saved_cs_client */;
--
+-- Table structure for table `topics`
+--
+
+DROP TABLE IF EXISTS `topics`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `topics` (
+ `tid` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `topic` varchar(390) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' COMMENT 'This field should be considered unique and case sensitive.',
+ PRIMARY KEY (`tid`),
+ KEY `topic` (`topic`(333))
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `urls`
+--
+
+DROP TABLE IF EXISTS `urls`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `urls` (
+ `lid` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `url` varchar(1024) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' COMMENT 'This field should be considered unique and case sensitive.',
+ `fid` int(10) unsigned DEFAULT NULL,
+ `tld` varchar(64) NOT NULL DEFAULT '',
+ `extension` varchar(8) NOT NULL DEFAULT '',
+ PRIMARY KEY (`lid`),
+ KEY `url` (`url`(333)),
+ KEY `fid` (`fid`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
-- Table structure for table `user_activity`
--
@@ -1176,8 +1225,7 @@ CREATE TABLE `user_activity` (
`l_afternoon` int(10) unsigned NOT NULL DEFAULT '0',
`l_evening` int(10) unsigned NOT NULL DEFAULT '0',
`l_total` int(10) unsigned NOT NULL DEFAULT '0',
- PRIMARY KEY (`uid`,`date`),
- KEY `date` (`date`)
+ PRIMARY KEY (`uid`,`date`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -1190,7 +1238,7 @@ DROP TABLE IF EXISTS `user_details`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `user_details` (
`uid` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `csnick` varchar(30) NOT NULL DEFAULT '',
+ `csnick` varchar(32) NOT NULL DEFAULT '',
`firstseen` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`lastseen` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`uid`),
@@ -1224,8 +1272,8 @@ CREATE TABLE `user_events` (
`kicked` int(10) unsigned NOT NULL DEFAULT '0',
`nickchanges` int(10) unsigned NOT NULL DEFAULT '0',
`topics` int(10) unsigned NOT NULL DEFAULT '0',
- `ex_kicks` varchar(255) NOT NULL DEFAULT '',
- `ex_kicked` varchar(255) NOT NULL DEFAULT '',
+ `ex_kicks` varchar(307) NOT NULL DEFAULT '',
+ `ex_kicked` varchar(307) NOT NULL DEFAULT '',
PRIMARY KEY (`uid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -1301,7 +1349,6 @@ CREATE TABLE `user_lines` (
`characters` int(10) unsigned NOT NULL DEFAULT '0',
`monologues` int(10) unsigned NOT NULL DEFAULT '0',
`topmonologue` int(10) unsigned NOT NULL DEFAULT '0',
- `activedays` int(10) unsigned NOT NULL DEFAULT '0',
`slaps` int(10) unsigned NOT NULL DEFAULT '0',
`slapped` int(10) unsigned NOT NULL DEFAULT '0',
`exclamations` int(10) unsigned NOT NULL DEFAULT '0',
@@ -1406,14 +1453,12 @@ DROP TABLE IF EXISTS `user_topics`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `user_topics` (
- `tid` int(10) unsigned NOT NULL AUTO_INCREMENT,
`uid` int(10) unsigned NOT NULL DEFAULT '0',
- `topic` varchar(1024) NOT NULL DEFAULT '',
- `setdate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
- PRIMARY KEY (`tid`,`uid`,`setdate`),
+ `tid` int(10) unsigned NOT NULL DEFAULT '0',
+ `datetime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
KEY `uid` (`uid`),
- KEY `topic` (`topic`(333)),
- KEY `setdate` (`setdate`)
+ KEY `tid` (`tid`),
+ KEY `datetime` (`datetime`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -1425,33 +1470,12 @@ DROP TABLE IF EXISTS `user_urls`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `user_urls` (
- `lid` int(10) unsigned NOT NULL AUTO_INCREMENT,
`uid` int(10) unsigned NOT NULL DEFAULT '0',
- `url` varchar(1024) NOT NULL DEFAULT '',
- `scheme` varchar(1024) NOT NULL DEFAULT '',
- `authority` varchar(255) NOT NULL DEFAULT '',
- `ipv4address` varchar(1024) NOT NULL DEFAULT '',
- `fqdn` varchar(1024) NOT NULL DEFAULT '',
- `domain` varchar(1024) NOT NULL DEFAULT '',
- `tld` varchar(255) NOT NULL DEFAULT '',
- `port` smallint(5) unsigned NOT NULL DEFAULT '0',
- `path` varchar(1024) NOT NULL DEFAULT '',
- `query` varchar(1024) NOT NULL DEFAULT '',
- `fragment` varchar(1024) NOT NULL DEFAULT '',
- `extension` varchar(255) NOT NULL DEFAULT '',
- `total` int(10) unsigned NOT NULL DEFAULT '0',
- `firstused` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
- `lastused` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
- PRIMARY KEY (`lid`,`uid`),
+ `lid` int(10) unsigned NOT NULL DEFAULT '0',
+ `datetime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
KEY `uid` (`uid`),
- KEY `url` (`url`(333)),
- KEY `authority` (`authority`),
- KEY `fqdn` (`fqdn`(333)),
- KEY `tld` (`tld`),
- KEY `extension` (`extension`),
- KEY `total` (`total`),
- KEY `firstused` (`firstused`),
- KEY `lastused` (`lastused`)
+ KEY `lid` (`lid`),
+ KEY `datetime` (`datetime`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -1593,7 +1617,7 @@ SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
/*!50001 CREATE TABLE `v_ex_kicked` (
`ruid` int(10) unsigned,
- `ex_kicked` varchar(255)
+ `ex_kicked` varchar(307)
) ENGINE=MyISAM */;
SET character_set_client = @saved_cs_client;
@@ -1607,7 +1631,7 @@ SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
/*!50001 CREATE TABLE `v_ex_kicked_1` (
`ruid` int(10) unsigned,
- `ex_kicked` varchar(255)
+ `ex_kicked` varchar(307)
) ENGINE=MyISAM */;
SET character_set_client = @saved_cs_client;
@@ -1621,7 +1645,7 @@ SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
/*!50001 CREATE TABLE `v_ex_kicks` (
`ruid` int(10) unsigned,
- `ex_kicks` varchar(255)
+ `ex_kicks` varchar(307)
) ENGINE=MyISAM */;
SET character_set_client = @saved_cs_client;
@@ -1635,7 +1659,7 @@ SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
/*!50001 CREATE TABLE `v_ex_kicks_1` (
`ruid` int(10) unsigned,
- `ex_kicks` varchar(255)
+ `ex_kicks` varchar(307)
) ENGINE=MyISAM */;
SET character_set_client = @saved_cs_client;
@@ -1889,8 +1913,8 @@ SET character_set_client = utf8;
`kicked` int(10) unsigned,
`nickchanges` int(10) unsigned,
`topics` int(10) unsigned,
- `ex_kicks` varchar(255),
- `ex_kicked` varchar(255)
+ `ex_kicks` varchar(307),
+ `ex_kicked` varchar(307)
) ENGINE=MyISAM */;
SET character_set_client = @saved_cs_client;
@@ -2096,12 +2120,10 @@ DROP TABLE IF EXISTS `words`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `words` (
- `wid` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `word` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
- `length` int(10) unsigned NOT NULL DEFAULT '0',
+ `word` varchar(30) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
+ `length` tinyint(3) unsigned NOT NULL DEFAULT '0',
`total` int(10) unsigned NOT NULL DEFAULT '0',
- PRIMARY KEY (`wid`),
- UNIQUE KEY `word` (`word`),
+ PRIMARY KEY (`word`),
KEY `length` (`length`),
KEY `total` (`total`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
@@ -2648,4 +2670,4 @@ CREATE TABLE `words` (
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
--- Dump completed on 2011-05-17 1:07:00
+-- Dump completed on 2012-09-14 15:26:13
View
41 html.class.php → html.php
@@ -22,8 +22,7 @@
final class html extends base
{
/**
- * Default settings for this script, can be overridden in the config file.
- * These should all appear in $settings_list[] along with their type.
+ * Default settings for this script, can be overridden in the config file. These should all appear in $settings_list[] along with their type.
*/
private $addhtml_foot = '';
private $addhtml_head = '';
@@ -87,6 +86,9 @@
public function __construct($settings)
{
+ /**
+ * The variables that are listed in $settings_list will have their values overridden by those found in the config file.
+ */
foreach ($this->settings_list as $key => $type) {
if (!array_key_exists($key, $settings)) {
continue;
@@ -170,7 +172,7 @@ public function make_html($mysqli)
$this->l_avg = $this->l_total / $this->days;
/**
- * Date and time variables used throughout the script. We take the date of the last logfile parsed. These variables are used to define our scope.
+ * Date and time variables used throughout the script. These are based on the date of the last logfile parsed and used to define our scope.
*/
$this->date_lastlogparsed = $result->date_lastlogparsed;
$this->dayofmonth = (int) date('j', strtotime($this->date_lastlogparsed));
@@ -506,7 +508,7 @@ public function make_html($mysqli)
$t->set_value('key2', 'User');
$t->set_value('key3', 'Topic');
$t->set_value('minrows', $this->minrows);
- $t->set_value('query_main', 'select `setdate` as `v1`, `csnick` as `v2`, `topic` as `v3` from `user_topics` join `user_status` on `user_topics`.`uid` = `user_status`.`uid` join `user_details` on `user_details`.`uid` = `user_status`.`ruid` order by `v1` desc, `v2` asc limit 5');
+ $t->set_value('query_main', 'select `datetime` as `v1`, `csnick` as `v2`, `topic` as `v3` from `user_topics` join `topics` on `user_topics`.`tid` = `topics`.`tid` join `user_status` on `user_topics`.`uid` = `user_status`.`uid` join `user_details` on `user_status`.`ruid` = `user_details`.`uid` order by `v1` desc limit 5');
$t->set_value('type', 'topics');
$output .= $t->make_table($this->mysqli);
@@ -606,13 +608,13 @@ public function make_html($mysqli)
if ($this->sectionbits & 32) {
$output = '';
- $t = new table('Most Referenced Domains');
+ $t = new table('Most Referenced Domain Names');
$t->set_value('key1', 'Total');
$t->set_value('key2', 'Domain');
$t->set_value('key3', 'First Used');
$t->set_value('maxrows', 10);
$t->set_value('minrows', 10);
- $t->set_value('query_main', 'select sum(`total`) as `v1`, concat(\'http://\', `authority`) as `v2`, min(`firstused`) as `v3` from `user_urls` group by `authority` order by `v1` desc, `v3` asc limit 10');
+ $t->set_value('query_main', 'select count(*) as `v1`, (select concat(\'http://\', `fqdn`) from `fqdns` where `fid` = `urls`.`fid`) as `v2`, min(`datetime`) as `v3` from `user_urls` join `urls` on `user_urls`.`lid` = `urls`.`lid` where `fid` is not null group by `fid` order by `v1` desc, `v3` asc limit 10');
$t->set_value('type', 'domains');
$output .= $t->make_table($this->mysqli);
@@ -621,7 +623,7 @@ public function make_html($mysqli)
$t->set_value('key2', 'TLD');
$t->set_value('maxrows', 10);
$t->set_value('minrows', 10);
- $t->set_value('query_main', 'select sum(`total`) as `v1`, `tld` as `v2` from `user_urls` where `tld` != \'\' group by `v2` order by `v1` desc, `v2` asc limit 10');
+ $t->set_value('query_main', 'select count(*) as `v1`, `tld` as `v2` from `user_urls` join `urls` on `user_urls`.`lid` = `urls`.`lid` where `tld` != \'\' group by `tld` order by `v1` desc, `v2` asc limit 10');
$output .= $t->make_table($this->mysqli);
$t = new table('Recent URLs');
@@ -630,7 +632,7 @@ public function make_html($mysqli)
$t->set_value('key3', 'URL');
$t->set_value('maxrows', $this->maxrows_recenturls);
$t->set_value('minrows', 5);
- $t->set_value('query_main', 'select `lastused` as `v1`, `csnick` as `v2`, `url` as `v3` from `user_urls` join `user_status` on `user_urls`.`uid` = `user_status`.`uid` join `user_details` on `user_details`.`uid` = `user_status`.`ruid` order by `v1` desc limit '.$this->maxrows_recenturls);
+ $t->set_value('query_main', 'select `datetime` as `v1`, `csnick` as `v2`, `url` as `v3` from `user_urls` join `urls` on `user_urls`.`lid` = `urls`.`lid` join `user_status` on `user_urls`.`uid` = `user_status`.`uid` join `user_details` on `user_status`.`ruid` = `user_details`.`uid` order by `v1` desc limit '.$this->maxrows_recenturls);
$t->set_value('type', 'urls');
$output .= $t->make_table($this->mysqli);
@@ -694,7 +696,7 @@ private function make_table_activity($type)
{
if ($type == 'day') {
$class = 'act';
- $cols = 24;
+ $columns = 24;
for ($i = 23; $i >= 0; $i--) {
$dates[] = date('Y-m-d', mktime(0, 0, 0, $this->month, $this->dayofmonth - $i, $this->year));
@@ -704,7 +706,7 @@ private function make_table_activity($type)
$query = @mysqli_query($this->mysqli, 'select `date`, `l_total`, `l_night`, `l_morning`, `l_afternoon`, `l_evening` from `channel` where `date` > \''.date('Y-m-d', mktime(0, 0, 0, $this->month, $this->dayofmonth - 24, $this->year)).'\'') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
} elseif ($type == 'month') {
$class = 'act';
- $cols = 24;
+ $columns = 24;
for ($i = 23; $i >= 0; $i--) {
$dates[] = date('Y-m', mktime(0, 0, 0, $this->month - $i, 1, $this->year));
@@ -714,7 +716,7 @@ private function make_table_activity($type)
$query = @mysqli_query($this->mysqli, 'select date_format(`date`, \'%Y-%m\') as `date`, sum(`l_total`) as `l_total`, sum(`l_night`) as `l_night`, sum(`l_morning`) as `l_morning`, sum(`l_afternoon`) as `l_afternoon`, sum(`l_evening`) as `l_evening` from `channel` where date_format(`date`, \'%Y-%m\') > \''.date('Y-m', mktime(0, 0, 0, $this->month - 24, 1, $this->year)).'\' group by year(`date`), month(`date`)') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
} elseif ($type == 'year') {
$class = 'act-year';
- $cols = $this->years;
+ $columns = $this->years;
for ($i = $this->years - 1; $i >= 0; $i--) {
$dates[] = $this->year - $i;
@@ -730,7 +732,7 @@ private function make_table_activity($type)
* The queries above will either return one or more rows with activity, or no rows at all.
*/
if (empty($rows)) {
- return;
+ return null;
}
$high_date = '';
@@ -749,7 +751,7 @@ private function make_table_activity($type)
}
}
- $tr1 = '<tr><th colspan="'.$cols.'">'.$head.'</th></tr>';
+ $tr1 = '<tr><th colspan="'.$columns.'">'.$head.'</th></tr>';
$tr2 = '<tr class="bars">';
$tr3 = '<tr class="sub">';
@@ -951,7 +953,7 @@ private function make_table_people($type, $maxrows)
}
if (empty($result->l_total)) {
- return;
+ return null;
}
$total = (int) $result->l_total;
@@ -1027,7 +1029,7 @@ private function make_table_people2($offset, $maxrows)
$rows = mysqli_num_rows($query);
if (empty($rows) || $rows < $maxrows * 4) {
- return;
+ return null;
}
$current_column = 1;
@@ -1077,7 +1079,7 @@ private function make_table_people_timeofday($maxrows)
}
if (empty($result->l_total)) {
- return;
+ return null;
}
$high_value = 0;
@@ -1157,14 +1159,14 @@ public function __construct($head)
public function make_table($mysqli)
{
if (empty($this->query_main)) {
- return;
+ return null;
}
$query = @mysqli_query($mysqli, $this->query_main) or $this->output('critical', 'mysqli: '.mysqli_error($mysqli));
$rows = mysqli_num_rows($query);
if (empty($rows) || $rows < $this->minrows) {
- return;
+ return null;
}
/**
@@ -1247,7 +1249,8 @@ public function make_table($mysqli)
$topic = '';
/**
- * Check if there are URLs in the topic and make hyperlinks out of them. Use htmlspecialchars() here since we skipped doing it before.
+ * Check if there are URLs in the topic and make hyperlinks out of them. Use htmlspecialchars() here since we skipped doing it
+ * before.
*/
foreach ($words as $word) {
if (preg_match('/^(www\.|https?:\/\/)/i', $word) && ($urldata = $urltools->get_elements($word)) !== false) {
View
19 maintenance.class.php → maintenance.php
@@ -29,6 +29,9 @@
public function __construct($settings)
{
+ /**
+ * The variables that are listed in $settings_list will have their values overridden by those found in the config file.
+ */
foreach ($this->settings_list as $key => $type) {
if (!array_key_exists($key, $settings)) {
continue;
@@ -104,7 +107,8 @@ private function fix_user_status_errors()
}
/**
- * Every alias must have their ruid set to the uid of a registered nick, which in turn has uid = ruid and status = 1 or 3. Unlink aliases pointing to non ruids.
+ * Every alias must have their ruid set to the uid of a registered nick, which in turn has uid = ruid and status = 1 or 3. Unlink aliases
+ * pointing to non ruids.
*/
$query = @mysqli_query($this->mysqli, 'select `ruid` from `user_status` where `status` in (1,3) order by `uid` asc') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
$rows = mysqli_num_rows($query);
@@ -128,9 +132,8 @@ private function fix_user_status_errors()
}
/**
- * Make materialized views, which are stored copies of dynamic views.
- * Query tables are top level materialized views based on various sub views and contain accumulated stats per ruid.
- * Legend: mv_ materialized view, q_ query table, t_ template, v_ view. Combinations do exist.
+ * Make materialized views, which are stored copies of dynamic views. Query tables are top level materialized views based on various sub views and
+ * contain accumulated stats per ruid. Legend: mv_ materialized view, q_ query table, t_ template, v_ view. Combinations do exist.
*/
private function make_materialized_views()
{
@@ -173,7 +176,7 @@ private function register_most_active_alias()
$rows = mysqli_num_rows($query);
if (empty($rows)) {
- return;
+ return null;
}
while ($result = mysqli_fetch_object($query)) {
@@ -190,8 +193,10 @@ private function register_most_active_alias()
/**
* Update records:
- * - Make the alias (uid) the new registered nick for the user or bot by setting ruid = uid. The status will be set to either 1 or 3, identical to previous value.
- * - Update the ruid field of all records that still point to the old registered nick (ruid) and set it to the new one (uid). Explicitly set the status to 2 so all records including the old registered nick are marked as alias.
+ * - Make the alias (uid) the new registered nick for the user or bot by setting ruid = uid. The status will be set to either
+ * 1 or 3, identical to previous value.
+ * - Update the ruid field of all records that still point to the old registered nick (ruid) and set it to the new one (uid).
+ * Explicitly set the status to 2 so all records including the old registered nick are marked as alias.
*/
@mysqli_query($this->mysqli, 'update `user_status` set `ruid` = '.$result->uid.', `status` = '.$result->status.' where `uid` = '.$result->uid) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
@mysqli_query($this->mysqli, 'update `user_status` set `ruid` = '.$result->uid.', `status` = 2 where `ruid` = '.$result->ruid) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
View
383 nick.class.php
@@ -1,383 +0,0 @@
-<?php
-
-/**
- * Copyright (c) 2007-2012, 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 handling user data.
- */
-final class nick extends base
-{
- /**
- * Variables that shouldn't be tampered with.
- */
- private $ex_actions_stack = array();
- private $ex_exclamations_stack = array();
- private $ex_questions_stack = array();
- private $ex_uppercased_stack = array();
- private $quote_stack = array();
- private $topics_list = array();
- private $uid = 0;
- private $urls_objs = array();
- protected $actions = 0;
- protected $characters = 0;
- protected $csnick = '';
- protected $date = '';
- protected $ex_actions = '';
- protected $ex_exclamations = '';
- protected $ex_kicked = '';
- protected $ex_kicks = '';
- protected $ex_questions = '';
- protected $ex_uppercased = '';
- protected $exclamations = 0;
- protected $firstseen = '';
- protected $joins = 0;
- protected $kicked = 0;
- protected $kicks = 0;
- protected $l_00 = 0;
- protected $l_01 = 0;
- protected $l_02 = 0;
- protected $l_03 = 0;
- protected $l_04 = 0;
- protected $l_05 = 0;
- protected $l_06 = 0;
- protected $l_07 = 0;
- protected $l_08 = 0;
- protected $l_09 = 0;
- protected $l_10 = 0;
- protected $l_11 = 0;
- protected $l_12 = 0;
- protected $l_13 = 0;
- protected $l_14 = 0;
- protected $l_15 = 0;
- protected $l_16 = 0;
- protected $l_17 = 0;
- protected $l_18 = 0;
- protected $l_19 = 0;
- protected $l_20 = 0;
- protected $l_21 = 0;
- protected $l_22 = 0;
- protected $l_23 = 0;
- protected $l_afternoon = 0;
- protected $l_evening = 0;
- protected $l_fri_afternoon = 0;
- protected $l_fri_evening = 0;
- protected $l_fri_morning = 0;
- protected $l_fri_night = 0;
- protected $l_mon_afternoon = 0;
- protected $l_mon_evening = 0;
- protected $l_mon_morning = 0;
- protected $l_mon_night = 0;
- protected $l_morning = 0;
- protected $l_night = 0;
- protected $l_sat_afternoon = 0;
- protected $l_sat_evening = 0;
- protected $l_sat_morning = 0;
- protected $l_sat_night = 0;
- protected $l_sun_afternoon = 0;
- protected $l_sun_evening = 0;
- protected $l_sun_morning = 0;
- protected $l_sun_night = 0;
- protected $l_thu_afternoon = 0;
- protected $l_thu_evening = 0;
- protected $l_thu_morning = 0;
- protected $l_thu_night = 0;
- protected $l_total = 0;
- protected $l_tue_afternoon = 0;
- protected $l_tue_evening = 0;
- protected $l_tue_morning = 0;
- protected $l_tue_night = 0;
- protected $l_wed_afternoon = 0;
- protected $l_wed_evening = 0;
- protected $l_wed_morning = 0;
- protected $l_wed_night = 0;
- protected $lastseen = '';
- protected $lasttalked = '';
- protected $m_deop = 0;
- protected $m_deopped = 0;
- protected $m_devoice = 0;
- protected $m_devoiced = 0;
- protected $m_op = 0;
- protected $m_opped = 0;
- protected $m_voice = 0;
- protected $m_voiced = 0;
- protected $monologues = 0;
- protected $mysqli;
- protected $nickchanges = 0;
- protected $parts = 0;
- protected $questions = 0;
- protected $quits = 0;
- protected $quote = '';
- protected $s_01 = 0;
- protected $s_02 = 0;
- protected $s_03 = 0;
- protected $s_04 = 0;
- protected $s_05 = 0;
- protected $s_06 = 0;
- protected $s_07 = 0;
- protected $s_08 = 0;
- protected $s_09 = 0;
- protected $s_10 = 0;
- protected $s_11 = 0;
- protected $s_12 = 0;
- protected $s_13 = 0;
- protected $s_14 = 0;
- protected $s_15 = 0;
- protected $s_16 = 0;
- protected $s_17 = 0;
- protected $s_18 = 0;
- protected $s_19 = 0;
- protected $s_20 = 0;
- protected $s_21 = 0;
- protected $s_22 = 0;
- protected $s_23 = 0;
- protected $s_24 = 0;
- protected $s_25 = 0;
- protected $s_26 = 0;
- protected $s_27 = 0;
- protected $s_28 = 0;
- protected $s_29 = 0;
- protected $s_30 = 0;
- protected $s_31 = 0;
- protected $s_32 = 0;
- protected $s_33 = 0;
- protected $s_34 = 0;
- protected $s_35 = 0;
- protected $s_36 = 0;
- protected $s_37 = 0;
- protected $s_38 = 0;
- protected $s_39 = 0;
- protected $s_40 = 0;
- protected $s_41 = 0;
- protected $s_42 = 0;
- protected $s_43 = 0;
- protected $s_44 = 0;
- protected $s_45 = 0;
- protected $s_46 = 0;
- protected $s_47 = 0;
- protected $s_48 = 0;
- protected $s_49 = 0;
- protected $s_50 = 0;
- protected $slapped = 0;
- protected $slaps = 0;
- protected $topics = 0;
- protected $topmonologue = 0;
- protected $uppercased = 0;
- protected $urls = 0;
- protected $words = 0;
-
- public function __construct($csnick)
- {
- $this->csnick = $csnick;
- }
-
- /**
- * Keep a stack of the 100 most recent quotes of each type along with their lengths.
- */
- public function add_quote($type, $line, $length)
- {
- $this->{$type.'_stack'}[] = array(
- 'length' => $length,
- 'line' => $line);
-
- if (count($this->{$type.'_stack'}) > 100) {
- /**
- * Shift the first (oldest) entry off the stack.
- */
- array_shift($this->{$type.'_stack'});
- }
- }
-
- public function add_topic($topic, $datetime)
- {
- $this->topics_list[] = array(
- 'topic' => $topic,
- 'setdate' => $datetime);
- }
-
- public function add_url($urldata, $datetime)
- {
- $url = strtolower($urldata['url']);
-
- if (!array_key_exists($url, $this->urls_objs)) {
- $this->urls_objs[$url] = new url($urldata);
- } else {
- /**
- * The last used case will be stored for a URL.
- * E.g. "www.example.com/readme.txt" could be corrected in a followup by "www.example.com/README.txt".
- */
- $this->urls_objs[$url]->set_value('url', $urldata['url']);
- }
-
- $this->urls_objs[$url]->add_value('total', 1);
- $this->urls_objs[$url]->set_lastused($datetime);
- }
-
- public function write_data($mysqli)
- {
- $this->mysqli = $mysqli;
-
- /**
- * Write data to database tables "user_details" and "user_status".
- */
- $query = @mysqli_query($this->mysqli, 'select * from `user_details` where `csnick` = \''.mysqli_real_escape_string($this->mysqli, $this->csnick).'\'') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
- $rows = mysqli_num_rows($query);
-
- if (empty($rows)) {
- $insertquery = $this->create_insert_query(array('csnick', 'firstseen', 'lastseen'));
- @mysqli_query($this->mysqli, 'insert into `user_details` set `uid` = 0,'.$insertquery) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
- $this->uid = mysqli_insert_id($this->mysqli);
- @mysqli_query($this->mysqli, 'insert into `user_status` set `uid` = '.$this->uid.', `ruid` = '.$this->uid.', `status` = 0') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
- } else {
- $result = mysqli_fetch_object($query);
- $this->uid = (int) $result->uid;
-
- /**
- * Explicitly not update $csnick if "seen" data hasn't changed. Prevents lowercase $prevnick from becoming new $csnick.
- */
- $updatequery = $this->create_update_query($result, array('uid', 'csnick'));
-
- if (!is_null($updatequery)) {
- @mysqli_query($this->mysqli, 'update `user_details` set `csnick` = \''.mysqli_real_escape_string($this->mysqli, $this->csnick).'\','.$updatequery.' where `uid` = '.$this->uid) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
- }
- }
-
- /**
- * Write data to database table "user_activity".
- */
- if ($this->l_total != 0) {
- $query = @mysqli_query($this->mysqli, 'select * from `user_activity` where `uid` = '.$this->uid.' and `date` = \''.mysqli_real_escape_string($this->mysqli, $this->date).'\'') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
- $rows = mysqli_num_rows($query);
-
- if (empty($rows)) {
- $insertquery = $this->create_insert_query(array('l_night', 'l_morning', 'l_afternoon', 'l_evening', 'l_total'));
- @mysqli_query($this->mysqli, 'insert into `user_activity` set `uid` = '.$this->uid.', `date` = \''.mysqli_real_escape_string($this->mysqli, $this->date).'\','.$insertquery) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
- } else {
- $result = mysqli_fetch_object($query);
- $updatequery = $this->create_update_query($result, array('uid', 'date'));
-
- if (!is_null($updatequery)) {
- @mysqli_query($this->mysqli, 'update `user_activity` set'.$updatequery.' where `uid` = '.$this->uid.' and `date` = \''.mysqli_real_escape_string($this->mysqli, $this->date).'\'') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
- }
- }
- }
-
- /**
- * Write data to database table "user_events".
- */
- $insertquery = $this->create_insert_query(array('m_op', 'm_opped', 'm_voice', 'm_voiced', 'm_deop', 'm_deopped', 'm_devoice', 'm_devoiced', 'joins', 'parts', 'quits', 'kicks', 'kicked', 'nickchanges', 'topics', 'ex_kicks', 'ex_kicked'));
-
- if (!is_null($insertquery)) {
- $query = @mysqli_query($this->mysqli, 'select * from `user_events` where `uid` = '.$this->uid) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
- $rows = mysqli_num_rows($query);
-
- if (empty($rows)) {
- @mysqli_query($this->mysqli, 'insert into `user_events` set `uid` = '.$this->uid.','.$insertquery) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
- } else {
- $result = mysqli_fetch_object($query);
- $updatequery = $this->create_update_query($result, array('uid'));
-
- if (!is_null($updatequery)) {
- @mysqli_query($this->mysqli, 'update `user_events` set'.$updatequery.' where `uid` = '.$this->uid) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
- }
- }
- }
-
- /**
- * Pick a random line from each of the quote stacks.
- * Long quotes are preferred since these look better on the statspage and give away more about the subject.
- */
- $types = array('ex_actions', 'ex_exclamations', 'ex_questions', 'ex_uppercased', 'quote');
-
- foreach ($types as $type) {
- if (!empty($this->{$type.'_stack'})) {
- rsort($this->{$type.'_stack'});
- $this->$type = $this->{$type.'_stack'}[mt_rand(0, ceil(count($this->{$type.'_stack'}) / 2) - 1)]['line'];
- }
- }
-
- /**
- * Write data to database table "user_lines".
- */
- $insertquery = $this->create_insert_query(array('l_00', 'l_01', 'l_02', 'l_03', 'l_04', 'l_05', 'l_06', 'l_07', 'l_08', 'l_09', 'l_10', 'l_11', 'l_12', 'l_13', 'l_14', 'l_15', 'l_16', 'l_17', 'l_18', 'l_19', 'l_20', 'l_21', 'l_22', 'l_23', 'l_night', 'l_morning', 'l_afternoon', 'l_evening', 'l_total', 'l_mon_night', 'l_mon_morning', 'l_mon_afternoon', 'l_mon_evening', 'l_tue_night', 'l_tue_morning', 'l_tue_afternoon', 'l_tue_evening', 'l_wed_night', 'l_wed_morning', 'l_wed_afternoon', 'l_wed_evening', 'l_thu_night', 'l_thu_morning', 'l_thu_afternoon', 'l_thu_evening', 'l_fri_night', 'l_fri_morning', 'l_fri_afternoon', 'l_fri_evening', 'l_sat_night', 'l_sat_morning', 'l_sat_afternoon', 'l_sat_evening', 'l_sun_night', 'l_sun_morning', 'l_sun_afternoon', 'l_sun_evening', 'urls', 'words', 'characters', 'monologues', 'topmonologue', 'slaps', 'slapped', 'exclamations', 'questions', 'actions', 'uppercased', 'quote', 'ex_exclamations', 'ex_questions', 'ex_actions', 'ex_uppercased', 'lasttalked'));
-
- if (!is_null($insertquery)) {
- $query = @mysqli_query($this->mysqli, 'select * from `user_lines` where `uid` = '.$this->uid) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
- $rows = mysqli_num_rows($query);
-
- if (empty($rows)) {
- @mysqli_query($this->mysqli, 'insert into `user_lines` set `uid` = '.$this->uid.','.$insertquery) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
- } else {
- $result = mysqli_fetch_object($query);
- $updatequery = $this->create_update_query($result, array('uid'));
-
- if (!is_null($updatequery)) {
- @mysqli_query($this->mysqli, 'update `user_lines` set'.$updatequery.' where `uid` = '.$this->uid) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
- }
- }
- }
-
- /**
- * Write data to database table "user_smileys".
- */
- $insertquery = $this->create_insert_query(array('s_01', 's_02', 's_03', 's_04', 's_05', 's_06', 's_07', 's_08', 's_09', 's_10', 's_11', 's_12', 's_13', 's_14', 's_15', 's_16', 's_17', 's_18', 's_19', 's_20', 's_21', 's_22', 's_23', 's_24', 's_25', 's_26', 's_27', 's_28', 's_29', 's_30', 's_31', 's_32', 's_33', 's_34', 's_35', 's_36', 's_37', 's_38', 's_39', 's_40', 's_41', 's_42', 's_43', 's_44', 's_45', 's_46', 's_47', 's_48', 's_49', 's_50'));
-
- if (!is_null($insertquery)) {
- $query = @mysqli_query($this->mysqli, 'select * from `user_smileys` where `uid` = '.$this->uid) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
- $rows = mysqli_num_rows($query);
-
- if (empty($rows)) {
- @mysqli_query($this->mysqli, 'insert into `user_smileys` set `uid` = '.$this->uid.','.$insertquery) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
- } else {
- $result = mysqli_fetch_object($query);
- $updatequery = $this->create_update_query($result, array('uid'));
-
- if (!is_null($updatequery)) {
- @mysqli_query($this->mysqli, 'update `user_smileys` set'.$updatequery.' where `uid` = '.$this->uid) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
- }
- }
- }
-
- /**
- * Write data to database table "user_topics".
- */
- foreach ($this->topics_list as $topic) {
- $query = @mysqli_query($this->mysqli, 'select `tid` from `user_topics` where `topic` = \''.mysqli_real_escape_string($this->mysqli, $topic['topic']).'\' group by `topic`') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
- $rows = mysqli_num_rows($query);
-
- if (empty($rows)) {
- @mysqli_query($this->mysqli, 'insert into `user_topics` set `tid` = 0, `uid` = '.$this->uid.', `topic` = \''.mysqli_real_escape_string($this->mysqli, $topic['topic']).'\', `setdate` = \''.mysqli_real_escape_string($this->mysqli, $topic['setdate']).'\'') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
- } else {
- $result = mysqli_fetch_object($query);
- $query = @mysqli_query($this->mysqli, 'select * from `user_topics` where `tid` = '.$result->tid.' and `uid` = '.$this->uid.' and `setdate` = \''.mysqli_real_escape_string($this->mysqli, $topic['setdate']).'\'') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
- $rows = mysqli_num_rows($query);
-
- if (empty($rows)) {
- @mysqli_query($this->mysqli, 'insert into `user_topics` set `tid` = '.$result->tid.', `uid` = '.$this->uid.', `topic` = \''.mysqli_real_escape_string($this->mysqli, $topic['topic']).'\', `setdate` = \''.mysqli_real_escape_string($this->mysqli, $topic['setdate']).'\'') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
- }
- }
- }
-
- /**
- * Write data to database table "user_urls".
- */
- foreach ($this->urls_objs as $url) {
- $url->write_data($this->mysqli, $this->uid);
- }
- }
-}
-
-?>
View
449 nick.php
@@ -0,0 +1,449 @@
+<?php
+
+/**
+ * Copyright (c) 2007-2012, 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 handling user data.
+ */
+final class nick extends base
+{
+ /**
+ * Variables that shouldn't be tampered with.
+ */
+ private $ex_actions_stack = array();
+ private $ex_exclamations_stack = array();
+ private $ex_questions_stack = array();
+ private $ex_uppercased_stack = array();
+ private $quote_stack = array();
+ private $topics_objs = array();
+ private $urls_objs = array();
+ protected $actions = 0;
+ protected $characters = 0;
+ protected $csnick = '';
+ protected $date = '';
+ protected $ex_actions = '';
+ protected $ex_exclamations = '';
+ protected $ex_kicked = '';
+ protected $ex_kicks = '';
+ protected $ex_questions = '';
+ protected $ex_uppercased = '';
+ protected $exclamations = 0;
+ protected $firstseen = '';
+ protected $joins = 0;
+ protected $kicked = 0;
+ protected $kicks = 0;
+ protected $l_00 = 0;
+ protected $l_01 = 0;
+ protected $l_02 = 0;
+ protected $l_03 = 0;
+ protected $l_04 = 0;
+ protected $l_05 = 0;
+ protected $l_06 = 0;
+ protected $l_07 = 0;
+ protected $l_08 = 0;
+ protected $l_09 = 0;
+ protected $l_10 = 0;
+ protected $l_11 = 0;
+ protected $l_12 = 0;
+ protected $l_13 = 0;
+ protected $l_14 = 0;
+ protected $l_15 = 0;
+ protected $l_16 = 0;
+ protected $l_17 = 0;
+ protected $l_18 = 0;
+ protected $l_19 = 0;
+ protected $l_20 = 0;
+ protected $l_21 = 0;
+ protected $l_22 = 0;
+ protected $l_23 = 0;
+ protected $l_afternoon = 0;
+ protected $l_evening = 0;
+ protected $l_fri_afternoon = 0;
+ protected $l_fri_evening = 0;
+ protected $l_fri_morning = 0;
+ protected $l_fri_night = 0;
+ protected $l_mon_afternoon = 0;
+ protected $l_mon_evening = 0;
+ protected $l_mon_morning = 0;
+ protected $l_mon_night = 0;
+ protected $l_morning = 0;
+ protected $l_night = 0;
+ protected $l_sat_afternoon = 0;
+ protected $l_sat_evening = 0;
+ protected $l_sat_morning = 0;
+ protected $l_sat_night = 0;
+ protected $l_sun_afternoon = 0;
+ protected $l_sun_evening = 0;
+ protected $l_sun_morning = 0;
+ protected $l_sun_night = 0;
+ protected $l_thu_afternoon = 0;
+ protected $l_thu_evening = 0;
+ protected $l_thu_morning = 0;
+ protected $l_thu_night = 0;
+ protected $l_total = 0;
+ protected $l_tue_afternoon = 0;
+ protected $l_tue_evening = 0;
+ protected $l_tue_morning = 0;
+ protected $l_tue_night = 0;
+ protected $l_wed_afternoon = 0;
+ protected $l_wed_evening = 0;
+ protected $l_wed_morning = 0;
+ protected $l_wed_night = 0;
+ protected $lastseen = '';
+ protected $lasttalked = '';
+ protected $m_deop = 0;
+ protected $m_deopped = 0;
+ protected $m_devoice = 0;
+ protected $m_devoiced = 0;
+ protected $m_op = 0;
+ protected $m_opped = 0;
+ protected $m_voice = 0;
+ protected $m_voiced = 0;
+ protected $monologues = 0;
+ protected $mysqli;
+ protected $nickchanges = 0;
+ protected $parts = 0;
+ protected $questions = 0;
+ protected $quits = 0;
+ protected $quote = '';
+ protected $s_01 = 0;
+ protected $s_02 = 0;
+ protected $s_03 = 0;
+ protected $s_04 = 0;
+ protected $s_05 = 0;
+ protected $s_06 = 0;
+ protected $s_07 = 0;
+ protected $s_08 = 0;
+ protected $s_09 = 0;
+ protected $s_10 = 0;
+ protected $s_11 = 0;
+ protected $s_12 = 0;
+ protected $s_13 = 0;
+ protected $s_14 = 0;
+ protected $s_15 = 0;
+ protected $s_16 = 0;
+ protected $s_17 = 0;
+ protected $s_18 = 0;
+ protected $s_19 = 0;
+ protected $s_20 = 0;
+ protected $s_21 = 0;
+ protected $s_22 = 0;
+ protected $s_23 = 0;
+ protected $s_24 = 0;
+ protected $s_25 = 0;
+ protected $s_26 = 0;
+ protected $s_27 = 0;
+ protected $s_28 = 0;
+ protected $s_29 = 0;
+ protected $s_30 = 0;
+ protected $s_31 = 0;
+ protected $s_32 = 0;
+ protected $s_33 = 0;
+ protected $s_34 = 0;
+ protected $s_35 = 0;
+ protected $s_36 = 0;
+ protected $s_37 = 0;
+ protected $s_38 = 0;
+ protected $s_39 = 0;
+ protected $s_40 = 0;
+ protected $s_41 = 0;
+ protected $s_42 = 0;
+ protected $s_43 = 0;
+ protected $s_44 = 0;
+ protected $s_45 = 0;
+ protected $s_46 = 0;
+ protected $s_47 = 0;
+ protected $s_48 = 0;
+ protected $s_49 = 0;
+ protected $s_50 = 0;
+ protected $slapped = 0;
+ protected $slaps = 0;
+ protected $topics = 0;
+ protected $topmonologue = 0;
+ protected $uppercased = 0;
+ protected $urls = 0;
+ protected $words = 0;
+
+ public function __construct($csnick)
+ {
+ $this->csnick = $csnick;
+ }
+
+ /**
+ * Keep a stack of the 100 most recent quotes of each type along with their lengths.
+ */
+ public function add_quote($type, $line, $length)
+ {
+ $this->{$type.'_stack'}[] = array(
+ 'length' => $length,
+ 'line' => $line);
+
+ if (count($this->{$type.'_stack'}) > 100) {
+ /**
+ * Shift the first (oldest) entry off the stack.
+ */
+ array_shift($this->{$type.'_stack'});
+ }
+ }
+
+ /**
+ * Keep track of every single topic set. These are handled (and stored) while preserving case.
+ */
+ public function add_topic($topic, $datetime)
+ {
+ if (!array_key_exists($topic, $this->topics_objs)) {
+ $this->topics_objs[$topic] = new topic($topic);
+ }
+
+ $this->topics_objs[$topic]->add_datetime($datetime);
+ }
+
+ /**
+ * We keep track of every single URL. These are handled (and stored) while preserving case.
+ */
+ public function add_url($urldata, $datetime)
+ {
+ $url = $urldata['url'];
+
+ if (!array_key_exists($url, $this->urls_objs)) {
+ $this->urls_objs[$url] = new url($urldata);
+ }
+
+ $this->urls_objs[$url]->add_datetime($datetime);
+ }
+
+ public function write_data($mysqli)
+ {
+ $this->mysqli = $mysqli;
+
+ /**
+ * Write data to database tables "user_details" and "user_status".
+ */
+ $query = @mysqli_query($this->mysqli, 'select `uid`, `firstseen` from `user_details` where `csnick` = \''.mysqli_real_escape_string($this->mysqli, $this->csnick).'\'') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
+ $rows = mysqli_num_rows($query);
+
+ if (empty($rows)) {
+ @mysqli_query($this->mysqli, 'insert into `user_details` set `uid` = 0, `csnick` = \''.mysqli_real_escape_string($this->mysqli, $this->csnick).'\''.($this->firstseen != '' ? ', `firstseen` = \''.$this->firstseen.'\', `lastseen` = \''.$this->lastseen.'\'' : '')) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
+ $uid = mysqli_insert_id($this->mysqli);
+ @mysqli_query($this->mysqli, 'insert into `user_status` set `uid` = '.$uid.', `ruid` = '.$uid) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
+ } else {
+ $result = mysqli_fetch_object($query);
+ $uid = (int) $result->uid;
+
+ /**
+ * Only update $firstseen if the value stored in the database is zero. We're parsing logs in chronological order so the stored value of
+ * $firstseen can never be lower and the value of $lastseen can never be higher than the parsed values. (We are not going out of our way
+ * to deal with possible DST nonsense.) Secondly, only update $csnick if the nick was seen. We want to avoid it from being overwritten
+ * by a lowercase $prevnick (streak code) or weirdly cased nick due to a slap.
+ */
+ if ($this->firstseen != '') {
+ @mysqli_query($this->mysqli, 'update `user_details` set `csnick` = \''.mysqli_real_escape_string($this->mysqli, $this->csnick).'\''.($result->firstseen == '0000-00-00 00:00:00' ? ', `firstseen` = \''.$this->firstseen.'\'' : '').', `lastseen` = \''.$this->lastseen.'\' where `uid` = '.$uid) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
+ }
+ }
+
+ /**
+ * Write data to database table "user_activity".
+ */
+ if ($this->l_total != 0) {
+ $createdquery = $this->create_query(array('l_night', 'l_morning', 'l_afternoon', 'l_evening', 'l_total'));
+ @mysqli_query($this->mysqli, 'insert into `user_activity` set `uid` = '.$uid.', `date` = \''.mysqli_real_escape_string($this->mysqli, $this->date).'\','.$createdquery) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
+ }
+
+ /**
+ * Write data to database table "user_events".
+ */
+ $createdquery = $this->create_query(array('m_op', 'm_opped', 'm_voice', 'm_voiced', 'm_deop', 'm_deopped', 'm_devoice', 'm_devoiced', 'joins', 'parts', 'quits', 'kicks', 'kicked', 'nickchanges', 'topics', 'ex_kicks', 'ex_kicked'));
+
+ if (!is_null($createdquery)) {
+ @mysqli_query($this->mysqli, 'insert into `user_events` set `uid` = '.$uid.','.$createdquery) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
+ }
+
+ /**
+ * Pick a random line from each of the quote stacks. Long quotes are preferred since these look better on the statspage and give away more about
+ * the subject.
+ */
+ $types = array('ex_actions', 'ex_exclamations', 'ex_questions', 'ex_uppercased', 'quote');
+
+ foreach ($types as $type) {
+ if (!empty($this->{$type.'_stack'})) {
+ rsort($this->{$type.'_stack'});
+ $this->$type = $this->{$type.'_stack'}[mt_rand(0, ceil(count($this->{$type.'_stack'}) / 2) - 1)]['line'];
+ }
+ }
+
+ /**
+ * Write data to database table "user_lines".
+ */
+ $createdquery = $this->create_query(array('l_00', 'l_01', 'l_02', 'l_03', 'l_04', 'l_05', 'l_06', 'l_07', 'l_08', 'l_09', 'l_10', 'l_11', 'l_12', 'l_13', 'l_14', 'l_15', 'l_16', 'l_17', 'l_18', 'l_19', 'l_20', 'l_21', 'l_22', 'l_23', 'l_night', 'l_morning', 'l_afternoon', 'l_evening', 'l_total', 'l_mon_night', 'l_mon_morning', 'l_mon_afternoon', 'l_mon_evening', 'l_tue_night', 'l_tue_morning', 'l_tue_afternoon', 'l_tue_evening', 'l_wed_night', 'l_wed_morning', 'l_wed_afternoon', 'l_wed_evening', 'l_thu_night', 'l_thu_morning', 'l_thu_afternoon', 'l_thu_evening', 'l_fri_night', 'l_fri_morning', 'l_fri_afternoon', 'l_fri_evening', 'l_sat_night', 'l_sat_morning', 'l_sat_afternoon', 'l_sat_evening', 'l_sun_night', 'l_sun_morning', 'l_sun_afternoon', 'l_sun_evening', 'urls', 'words', 'characters', 'monologues', 'slaps', 'slapped', 'exclamations', 'questions', 'actions', 'uppercased', 'quote', 'ex_exclamations', 'ex_questions', 'ex_actions', 'ex_uppercased', 'lasttalked'));
+
+ if (!is_null($createdquery)) {
+ @mysqli_query($this->mysqli, 'insert into `user_lines` set `uid` = '.$uid.','.$createdquery) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
+
+ /**
+ * Update $topmonologue separately as we want to keep the highest value instead of the sum. Note that $createdquery can't be null when
+ * $topmonologue is non zero because, at the very least, $monologues will have a value of 1.
+ */
+ if ($this->topmonologue != 0) {
+ $query = @mysqli_query($this->mysqli, 'select `topmonologue` from `user_lines` where `uid` = '.$uid) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
+ $result = mysqli_fetch_object($query);
+
+ if ($this->topmonologue > (int) $result->topmonologue) {
+ @mysqli_query($this->mysqli, 'update `user_lines` set `topmonologue` = '.$this->topmonologue.' where `uid` = '.$uid) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
+ }
+ }
+ }
+
+ /**
+ * Write data to database table "user_smileys".
+ */
+ $createdquery = $this->create_query(array('s_01', 's_02', 's_03', 's_04', 's_05', 's_06', 's_07', 's_08', 's_09', 's_10', 's_11', 's_12', 's_13', 's_14', 's_15', 's_16', 's_17', 's_18', 's_19', 's_20', 's_21', 's_22', 's_23', 's_24', 's_25', 's_26', 's_27', 's_28', 's_29', 's_30', 's_31', 's_32', 's_33', 's_34', 's_35', 's_36', 's_37', 's_38', 's_39', 's_40', 's_41', 's_42', 's_43', 's_44', 's_45', 's_46', 's_47', 's_48', 's_49', 's_50'));
+
+ if (!is_null($createdquery)) {
+ @mysqli_query($this->mysqli, 'insert into `user_smileys` set `uid` = '.$uid.','.$createdquery) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
+ }
+
+ /**
+ * Write topic data to the database.
+ */
+ foreach ($this->topics_objs as $topic) {
+ $topic->write_data($this->mysqli, $uid);
+ }
+
+ /**
+ * Write URL data to the database.
+ */
+ foreach ($this->urls_objs as $url) {
+ $url->write_data($this->mysqli, $uid);
+ }
+ }
+}
+
+/**
+ * Class for handling URL data.
+ */
+final class url extends base
+{
+ /**
+ * Variables that shouldn't be tampered with.
+ */
+ private $datetime = array();
+ private $extension = '';
+ private $fqdn = '';
+ private $tld = '';
+ private $url = '';
+
+ public function __construct($urldata)
+ {
+ $this->fqdn = $urldata['fqdn'];
+ $this->tld = $urldata['tld'];
+ $this->url = $urldata['url'];
+
+ /**
+ * Attempt to get a file extension from the path. This is by no means 100% accurate but rather a cheap way of indexing content.
+ */
+ if (preg_match('/(?<extension>\.[a-z0-9]{1,7})$/i', $urldata['path'], $matches)) {
+ $this->extension = strtolower($matches['extension']);
+ }
+ }
+
+ public function add_datetime($datetime)
+ {
+ $this->datetime[] = $datetime;
+ }
+
+ public function write_data($mysqli, $uid)
+ {
+ /**
+ * Write data to database table "fqdns".
+ */
+ if ($this->fqdn != '') {
+ $query = @mysqli_query($mysqli, 'select `fid` from `fqdns` where `fqdn` = \''.$this->fqdn.'\'') or $this->output('critical', 'mysqli: '.mysqli_error($mysqli));
+ $rows = mysqli_num_rows($query);
+
+ if (empty($rows)) {
+ @mysqli_query($mysqli, 'insert into `fqdns` set `fid` = 0, `fqdn` = \''.$this->fqdn.'\'') or $this->output('critical', 'mysqli: '.mysqli_error($mysqli));
+ $fid = mysqli_insert_id($mysqli);
+ } else {
+ $result = mysqli_fetch_object($query);
+ $fid = (int) $result->fid;
+ }
+ }
+
+ /**
+ * Write data to database tables "urls" and "user_urls".
+ */
+ $query = @mysqli_query($mysqli, 'select `lid` from `urls` where `url` = \''.mysqli_real_escape_string($mysqli, $this->url).'\'') or $this->output('critical', 'mysqli: '.mysqli_error($mysqli));
+ $rows = mysqli_num_rows($query);
+
+ if (empty($rows)) {
+ @mysqli_query($mysqli, 'insert into `urls` set `lid` = 0, `url` = \''.mysqli_real_escape_string($mysqli, $this->url).'\''.($this->fqdn != '' ? ', `fid` = \''.$fid.'\', `tld` = \''.$this->tld.'\'' : '').($this->extension != '' ? ', `extension` = \''.$this->extension.'\'' : '')) or $this->output('critical', 'mysqli: '.mysqli_error($mysqli));
+ $lid = mysqli_insert_id($mysqli);
+ } else {
+ $result = mysqli_fetch_object($query);
+ $lid = (int) $result->lid;
+ }
+
+ foreach ($this->datetime as $datetime) {
+ @mysqli_query($mysqli, 'insert into `user_urls` set `uid` = '.$uid.', `lid` = '.$lid.', `datetime` = \''.$datetime.'\'') or $this->output('critical', 'mysqli: '.mysqli_error($mysqli));
+ }
+ }
+}
+
+/**
+ * Class for handling topic data.
+ */
+final class topic extends base
+{
+ /**
+ * Variables that shouldn't be tampered with.
+ */
+ private $datetime = array();
+ private $topic = '';
+
+ public function __construct($topic)
+ {
+ $this->topic = $topic;
+ }
+
+ public function add_datetime($datetime)
+ {
+ $this->datetime[] = $datetime;
+ }
+
+ /**
+ * Write data to database tables "topics" and "user_topics".
+ */
+ public function write_data($mysqli, $uid)
+ {
+ $query = @mysqli_query($mysqli, 'select `tid` from `topics` where `topic` = \''.mysqli_real_escape_string($mysqli, $this->topic).'\'') or $this->output('critical', 'mysqli: '.mysqli_error($mysqli));
+ $rows = mysqli_num_rows($query);
+
+ if (empty($rows)) {
+ @mysqli_query($mysqli, 'insert into `topics` set `tid` = 0, `topic` = \''.mysqli_real_escape_string($mysqli, $this->topic).'\'') or $this->output('critical', 'mysqli: '.mysqli_error($mysqli));
+ $tid = mysqli_insert_id($mysqli);
+ } else {
+ $result = mysqli_fetch_object($query);
+ $tid = (int) $result->tid;
+ }
+
+ foreach ($this->datetime as $datetime) {
+ @mysqli_query($mysqli, 'insert into `user_topics` set `uid` = '.$uid.', `tid` = '.$tid.', `datetime` = \''.$datetime.'\'') or $this->output('critical', 'mysqli: '.mysqli_error($mysqli));
+ }
+ }
+}
+
+?>
View
207 parser.class.php → parser.php
@@ -22,8 +22,7 @@
abstract class parser extends base
{
/**
- * Default settings for this script, can be overridden in the config file.
- * These should all appear in $settings_list[] along with their type.
+ * Default settings for this script, can be overridden in the config file. These should all appear in $settings_list[] along with their type.
*/
private $nick_maxlen = 30;
private $nick_minlen = 1;
@@ -136,6 +135,9 @@
{
$this->urltools = new urltools();
+ /**
+ * The variables that are listed in $settings_list will have their values overridden by those found in the config file.
+ */
foreach ($this->settings_list as $key => $type) {
if (!array_key_exists($key, $settings)) {
continue;
@@ -156,8 +158,8 @@
}
/**
- * Create an object of the nick if it doesn't already exist.
- * Return the lowercase nick for further referencing by the calling function.
+ * Create an object of the nick if it doesn't already exist. If it does already exist, update $csnick. Return the lowercase nick for further referencing
+ * by the calling function.
*/
final private function add_nick($csnick, $datetime)
{
@@ -181,8 +183,21 @@
return $nick;
}
- final private function add_word($word, $length)
+ /**
+ * Words are stored in lower case. Since they can contain UTF-8 encoded characters we should be careful on how to convert words to lower case.
+ */
+ final private function add_word($csword, $length)
{
+ /**
+ * The multibyte strtolower function is significantly slower than its single-byte counterpart so we throw in a little if-else statement to check
+ * if its use is needed.
+ */
+ if (preg_match('/^[\x00-\x7F]+$/', $csword)) {
+ $word = strtolower($csword);
+ } else {
+ $word = mb_strtolower($csword, 'UTF-8');
+ }
+
if (!array_key_exists($word, $this->words_objs)) {
$this->words_objs[$word] = new word($word);
$this->words_objs[$word]->set_value('length', $length);
@@ -192,7 +207,7 @@
}
/**
- * Parser function for gzipped logs.
+ * Parser function for gzipped logs. The zlib extension must be loaded for this function to work (see sss.php).
*/
final public function gzparse_log($logfile, $firstline)
{
@@ -213,8 +228,8 @@
$line = $this->normalize_line($line);
/**
- * Pass on the normalized line to the logfile format specific parser class extending this class. Empty lines are ignored.
- * Remember the line number of the last non empty line so we can store the correct parse history instead of guessing.
+ * Pass on the normalized line to the logfile format specific parser class extending this class. Empty lines are ignored. Remember the
+ * line number of the last non empty line so we can store the correct parse history instead of guessing.
*/
if (!empty($line)) {
$this->parse_line($line);
@@ -227,8 +242,8 @@
$this->output('notice', 'gzparse_log(): parsing completed');
/**
- * The $newdata variable can be used outside of the parser class to decide whether we want to run additional routines or skip them.
- * Whenever the $nicks_objs count is zero there won't be any new data because the data we are interested in is always related to one or more valid nicks.
+ * The $newdata variable can be used outside of the parser class to decide whether we want to run additional routines or skip them. Whenever the
+ * $nicks_objs count is zero there won't be any new data because the data we are interested in is always related to one or more valid nicks.
*/
if (!empty($this->nicks_objs)) {
$this->newdata = true;
@@ -245,9 +260,9 @@
while ($line != '') {
/**
- * Match the first valid multibyte character or otherwise a single byte;
- * Pass it on to rebuild_line() and replace the character with an empty string (making $line shorter);
- * Continue until $line is zero bytes in length.
+ * 1. Match the first valid multibyte character or otherwise a single byte.
+ * 2. Pass it on to rebuild_line() and replace the character with an empty string effectively making $line shorter.
+ * 3. Continue until $line is zero bytes in length.
*/
$line = preg_replace('/^('.$this->hex_validutf8.'|.)/es', '$this->rebuild_line(\'$0\')', $line);
}
@@ -290,8 +305,8 @@
$line = $this->normalize_line($line);
/**
- * Pass on the normalized line to the logfile format specific parser class extending this class. Empty lines are ignored.
- * Remember the line number of the last non empty line so we can store the correct parse history instead of guessing.
+ * Pass on the normalized line to the logfile format specific parser class extending this class. Empty lines are ignored. Remember the
+ * line number of the last non empty line so we can store the correct parse history instead of guessing.
*/
if (!empty($line)) {
$this->parse_line($line);
@@ -304,8 +319,8 @@
$this->output('notice', 'parse_log(): parsing completed');
/**
- * The $newdata variable can be used outside of the parser class to decide whether we want to run additional routines or skip them.
- * Whenever the $nicks_objs count is zero there won't be any new data because the data we are interested in is always related to one or more valid nicks.
+ * The $newdata variable can be used outside of the parser class to decide whether we want to run additional routines or skip them. Whenever the
+ * $nicks_objs count is zero there won't be any new data because the data we are interested in is always related to one or more valid nicks.
*/
if (!empty($this->nicks_objs)) {
$this->newdata = true;
@@ -343,9 +358,13 @@
} else {
$nick = $this->add_nick($csnick, $datetime);
$this->nicks_objs[$nick]->add_value('actions', 1);
+ $line_length = mb_strlen($line, 'UTF-8');
- if (strlen($line) <= 255) {
- $this->nicks_objs[$nick]->add_quote('ex_actions', $line, mb_strlen($line, 'UTF-8'));
+ /**
+ * Track quotes/example lines of up to a sensible limit of 255 characters in length.
+ */
+ if ($line_length <= 255) {
+ $this->nicks_objs[$nick]->add_quote('ex_actions', $line, $line_length);
}
}
}
@@ -372,7 +391,10 @@
$this->nicks_objs[$nick_performing]->add_value('kicks', 1);
$this->nicks_objs[$nick_undergoing]->add_value('kicked', 1);
- if (strlen($line) <= 255) {
+ /**
+ * Track kick messages of up to a limit of 307 characters in length. The majority of IRC servers are within this limit.
+ */
+ if (mb_strlen($line, 'UTF-8') <= 307) {
$this->nicks_objs[$nick_performing]->set_value('ex_kicks', $line);
$this->nicks_objs[$nick_undergoing]->set_value('ex_kicked', $line);
}
@@ -428,14 +450,10 @@
if (!$this->validate_nick($csnick)) {
$this->output('warning', 'set_normal(): invalid nick: \''.$csnick.'\' on line '.$this->linenum);
} else {
- $line_length_bytes = strlen($line);
- $line_length_chars = mb_strlen($line, 'UTF-8');
$nick = $this->add_nick($csnick, $datetime);
- $this->nicks_objs[$nick]->add_value('characters', $line_length_chars);
-
- if ($this->nicks_objs[$nick]->get_value('lasttalked') == '') {
- $this->nicks_objs[$nick]->set_value('lasttalked', $datetime);
- }
+ $line_length = mb_strlen($line, 'UTF-8');
+ $this->nicks_objs[$nick]->add_value('characters', $line_length);
+ $this->nicks_objs[$nick]->set_value('lasttalked', $datetime);
/**
* Keeping track of monologues.
@@ -444,14 +462,14 @@
$this->streak++;
} else {
/**
- * Ohno! Someone else typed a line and the previous streak is interrupted. Check if the streak qualifies as a monologue and store it.
+ * Someone else typed a line and the previous streak is interrupted. Check if the streak qualifies as a monologue and store it.
*/
if ($this->streak >= 5) {
/**
- * If the current line count is 0 then $prevnick is not known to us yet (only seen in previous parse run).
- * It's safe to assume that $prevnick is a valid nick since it was set by set_normal().
- * We will create an object for it here so we can add the monologue data. Don't worry about $prevnick being lowercase,
- * we won't update "user_details" if $prevnick isn't seen plus $csnick will get a refresh on any other activity.
+ * If the current line count is 0 then $prevnick is not known to us yet (only seen in previous parse run). It's safe to
+ * assume that $prevnick is a valid nick since it was set by set_normal(). We will create an object for it here so we
+ * can add the monologue data. Don't worry about $prevnick being lowercase, we won't update "user_details" if $prevnick
+ * isn't seen plus $csnick will get a refresh on any other activity.
*/
if ($this->l_total == 0) {
$this->add_nick($this->prevnick, null);
@@ -491,6 +509,8 @@
$this->{'l_'.($hour < 10 ? '0'.$hour : $hour)}++;
$this->l_total++;
+ $this->nicks_objs[$nick]->add_value('l_'.($hour < 10 ? '0'.$hour : $hour), 1);
+ $this->nicks_objs[$nick]->add_value('l_total', 1);
/**
* "Words" are simply character groups separated by whitespace.
@@ -507,22 +527,22 @@
$this->nicks_objs[$nick]->add_value($this->smileys[strtolower($csword)], 1);
/**
- * Only catch URLs which were intended to be clicked on; most clients can handle URLs that begin with "www." or "http://" and such.
- * If we would apply a more liberal approach we are likely to run into filenames (e.g. .py .com), libraries (e.g. .so) and other words that validate as a URL.
+ * Only catch URLs which were intended to be clicked on; most clients can handle URLs that begin with "www." or "http://" and
+ * such. If we would apply a more liberal approach we are likely to run into filenames (e.g. .py .com), libraries (e.g. .so) and
+ * other words that validate as a URL.
*/
} elseif (preg_match('/^(www\.|https?:\/\/)/i', $csword)) {
/**
- * Regardless of it being a valid URL or not we set $skipquote to true. This variable enables us to exclude quotes that have
- * a URL (or something that looks like it) in them. This is to safeguard a tidy presentation on the statspage.
+ * Regardless of it being a valid URL or not we set $skipquote to true. This variable enables us to exclude quotes that
+ * have a URL (or something similar looking) in them. This is to safeguard a tidy presentation on the statspage.
*/
$skipquote = true;
if (($urldata = $this->urltools->get_elements($csword)) !== false) {
- if (strlen($urldata['url']) > 1024) {
- $this->output('debug', 'set_normal(): skipping url on line '.$this->linenum.': exceeds column length of `url` (1024)');
- } elseif (strlen($urldata['authority']) > 255) {
- $this->output('debug', 'set_normal(): skipping url on line '.$this->linenum.': exceeds column length of `authority` (255)');
- } else {
+ /**
+ * Track URLs of up to a (more than) sensible limit of 1024 characters in length.
+ */
+ if (strlen($urldata['url']) <= 1024) {
$this->nicks_objs[$nick]->add_url($urldata, $datetime);
$this->nicks_objs[$nick]->add_value('urls', 1);
}
@@ -531,9 +551,11 @@
}
/**
- * We keep track of all character groups composed of the letters found in the Basic Latin and Latin-1 Supplement character sets, the Hyphen (used properly), and any multibyte characters beyond those two sets (found in UTF-8) regardless of their meaning.
- * The regexp checks for any characters we don't want in our words - from the aforementioned Latin sets. Keep in mind that normalize_line() already took all the dirt out.
- * Note that this method of finding words is not 100% accurate - possibly not even 50% - but it serves our purpose.
+ * We keep track of all character groups composed of the letters found in the Basic Latin and Latin-1 Supplement character sets,
+ * the Hyphen (used properly), and any multibyte characters beyond those two sets (found in UTF-8) regardless of their meaning.
+ * The regexp checks for any characters we don't want in our words - from the aforementioned Latin sets. Keep in mind that
+ * normalize_line() already took all the dirt out. Note that this method of finding words is not 100% accurate - possibly not
+ * even 50% - but it serves our purpose.
*/
} elseif ($this->wordtracking && !preg_match('/^-|-$|--|[\x21-\x2C\x2E-\x40\x5B-\x60\x7B-\x7E]|\xC2[\xA1-\xBF]|\xC3\x97|\xC3\xB7|\xEF\xBF\xBD/', $csword)) {
$word_length = mb_strlen($csword, 'UTF-8');
@@ -542,55 +564,41 @@
* Words consisting of 30+ characters are most likely not real words so we skip those.
*/
if ($word_length <= 30) {
- /**
- * The multibyte strtolower is significantly slower than its single-byte counterpart so we throw in a little if-else statement to check if its use is needed.
- */
- if (preg_match('/^[\x00-\x7F]+$/', $csword)) {
- /**
- * Single-byte characters only.
- */
- $word = strtolower($csword);
- } else {
- /**
- * Multibyte characters present so we use the appropriate function.
- */
- $word = mb_strtolower($csword, 'UTF-8');
- }
-
- $this->add_word($word, $word_length);
+ $this->add_word($csword, $word_length);
}
}
}
- $this->nicks_objs[$nick]->add_value('l_'.($hour < 10 ? '0'.$hour : $hour), 1);
- $this->nicks_objs[$nick]->add_value('l_total', 1);
-
- if (!$skipquote && $line_length_bytes <= 255) {
- $this->nicks_objs[$nick]->add_quote('quote', $line, $line_length_chars);
+ /**
+ * Track quotes/example lines of up to a sensible limit of 255 characters in length. This applies to all of the types seen below.
+ */
+ if (!$skipquote && $line_length <= 255) {
+ $this->nicks_objs[$nick]->add_quote('quote', $line, $line_length);
}
/**
- * Uppercased lines should consist of 2 or more characters, be completely uppercased, and have less than 50% non letter characters from the Basic Latin and Latin-1 Supplement character sets in them.
+ * Uppercased lines should consist of 2 or more characters, be completely uppercased, and have less than 50% non letter characters from
+ * the Basic Latin and Latin-1 Supplement character sets in them.
*/
- if ($line_length_chars >= 2 && mb_strtoupper($line, 'UTF-8') == $line && mb_strlen(preg_replace('/[\x21-\x40\x5B-\x60\x7B-\x7E]|\xC2[\xA1-\xBF]|\xC3\x97|\xC3\xB7|\xEF\xBF\xBD/', '', $line), 'UTF-8') * 2 > $line_length_chars) {
+ if ($line_length >= 2 && mb_strtoupper($line, 'UTF-8') == $line && mb_strlen(preg_replace('/[\x21-\x40\x5B-\x60\x7B-\x7E]|\xC2[\xA1-\xBF]|\xC3\x97|\xC3\xB7|\xEF\xBF\xBD/', '', $line), 'UTF-8') * 2 > $line_length) {
$this->nicks_objs[$nick]->add_value('uppercased', 1);
- if (!$skipquote && $line_length_bytes <= 255) {
- $this->nicks_objs[$nick]->add_quote('ex_uppercased', $line, $line_length_chars);
+ if (!$skipquote && $line_length <= 255) {
+ $this->nicks_objs[$nick]->add_quote('ex_uppercased', $line, $line_length);
}
}
if (preg_match('/!$/', $line)) {
$this->nicks_objs[$nick]->add_value('exclamations', 1);
- if (!$skipquote && $line_length_bytes <= 255) {
- $this->nicks_objs[$nick]->add_quote('ex_exclamations', $line, $line_length_chars);
+ if (!$skipquote && $line_length <= 255) {
+ $this->nicks_objs[$nick]->add_quote('ex_exclamations', $line, $line_length);
}
} elseif (preg_match('/\?$/', $line)) {
$this->nicks_objs[$nick]->add_value('questions', 1);