mirror of
https://github.com/e107inc/e107.git
synced 2025-05-01 17:57:56 +02:00
Cleaned up stats logging class. Added options in admin area to rebuild monthly and all-time stats from raw Log files. Admin language file definitions were renamed to match v2.x standards. (was missing "LAN"). Frontend language-file correction pending.
This commit is contained in:
parent
24939cec54
commit
6ec85f5c0f
File diff suppressed because it is too large
Load Diff
@ -14,35 +14,291 @@
|
||||
|
||||
if (!defined('e107_INIT')){ exit; }
|
||||
|
||||
$pathtologs = e_LOG;
|
||||
$date = date("z.Y", time());
|
||||
$yesterday = date("z.Y",(time() - 86400)); // This makes sure year wraps round OK
|
||||
$date2 = date("Y-m-j", (time() -86400)); // Yesterday's date for the database summary
|
||||
$date3 = date("Y-m", (time() -86400)); // Current month's date for monthly summary (we're working with yesterday's data)
|
||||
|
||||
$pfileprev = "logp_".$yesterday.".php"; // Yesterday's log file
|
||||
$pfile = "logp_".$date.".php"; // Today's log file
|
||||
$ifileprev = "logi_".$yesterday.".php";
|
||||
$ifile = "logi_".$date.".php";
|
||||
|
||||
// Begin v2.x cleanup.
|
||||
class logConsolidate
|
||||
{
|
||||
|
||||
function ___construct()
|
||||
{
|
||||
protected $pathtologs;
|
||||
protected $date;
|
||||
protected $yesterday;
|
||||
protected $date2;
|
||||
protected $date3;
|
||||
|
||||
protected $pfileprev;
|
||||
protected $pfile;
|
||||
protected $ifileprev;
|
||||
protected $ifile;
|
||||
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->pathtologs = e_LOG;
|
||||
$this->date = date("z.Y", time());
|
||||
$this->yesterday = date("z.Y",(time() - 86400)); // This makes sure year wraps round OK
|
||||
$this->date2 = date("Y-m-j", (time() -86400)); // Yesterday's date for the database summary
|
||||
$this->date3 = date("Y-m", (time() -86400)); // Current month's date for monthly summary (we're working with yesterday's data)
|
||||
|
||||
$this->pfileprev = "logp_".$this->yesterday.".php"; // Yesterday's log file
|
||||
$this->pfile = "logp_".$this->date.".php"; // Today's log file
|
||||
$this->ifileprev = "logi_".$this->yesterday.".php";
|
||||
$this->ifile = "logi_".$this->date.".php";
|
||||
}
|
||||
|
||||
function createLog($pathtologs, $statTotal='', $statUnique='')
|
||||
{
|
||||
global $pfile, $ifile;
|
||||
|
||||
if(!is_writable($pathtologs))
|
||||
function run()
|
||||
{
|
||||
|
||||
$sql = e107::getDb();
|
||||
$pref = e107::pref('core');
|
||||
|
||||
$pageInfo = array();
|
||||
$domainInfo = array();
|
||||
$screenInfo = array();
|
||||
$browserInfo = array();
|
||||
$osInfo = array();
|
||||
$refInfo = array();
|
||||
$searchInfo = array();
|
||||
|
||||
$monthlyInfo = array();
|
||||
$mon_statBrowser = array();
|
||||
$mon_statOs = array();
|
||||
$mon_statScreen = array();
|
||||
$mon_statDomain = array();
|
||||
$mon_statQuery = array();
|
||||
$statBrowser = array();
|
||||
$statOs = array();
|
||||
$statScreen = array();
|
||||
$statDomain = array();
|
||||
$statQuery = array();
|
||||
$statReferer = array();
|
||||
|
||||
$statTotal = 0;
|
||||
$statUnique = 0;
|
||||
$siteTotal = 0;
|
||||
$siteUnique = 0;
|
||||
|
||||
$MonthlyExistsFlag = false;
|
||||
|
||||
if(file_exists($this->pathtologs.$this->pfile)) /* log file is up to date, no consolidation required */
|
||||
{
|
||||
echo "Log directory is not writable - please CHMOD ".e_LOG." to 777";
|
||||
echo '<br />Path to logs: '.$pathtologs;
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
else if(!file_exists($this->pathtologs.$this->pfileprev)) // See if any older log files
|
||||
{
|
||||
if (($retvalue = $this->check_for_old_files($this->pathtologs)) === false) /* no logfile found at all - create - this will only ever happen once ... */
|
||||
{
|
||||
$this->createLog();
|
||||
return false;
|
||||
}
|
||||
|
||||
list($this->pfileprev,$this->ifileprev,$this->date2,$tstamp) = explode('|',$retvalue); // ... if we've got files
|
||||
}
|
||||
|
||||
unset($tstamp);
|
||||
|
||||
// List of the non-page-based info which is gathered - historically only 'all-time' stats, now we support monthly as well
|
||||
$stats_list = array('statBrowser','statOs','statScreen','statDomain','statReferer','statQuery');
|
||||
|
||||
$qry = "`log_id` IN ('statTotal','statUnique'";
|
||||
foreach ($stats_list as $s)
|
||||
{
|
||||
$qry .= ",'{$s}'"; // Always read the all-time stats
|
||||
if ($pref[$s] == 2) $qry .= ",'{$s}:{$this->date3}'"; // Look for monthlys as well as cumulative
|
||||
}
|
||||
$qry .= ")";
|
||||
|
||||
/* log file is out of date - consolidation required */
|
||||
|
||||
/* get existing stats ... */
|
||||
//if($sql->select("logstats", "*", "log_id='statBrowser' OR log_id='statOs' OR log_id='statScreen' OR log_id='statDomain' OR log_id='statTotal' OR log_id='statUnique' OR log_id='statReferer' OR log_id='statQuery'"))
|
||||
if($sql->select("logstats", "*", $qry))
|
||||
{ // That's read in all the stats we need to modify
|
||||
while($row = $sql->fetch())
|
||||
{
|
||||
if($row['log_id'] == "statUnique")
|
||||
{
|
||||
$statUnique = $row['log_data'];
|
||||
}
|
||||
elseif ($row['log_id'] == "statTotal")
|
||||
{
|
||||
$statTotal = $row['log_data'];
|
||||
}
|
||||
elseif (($pos = strpos($row['log_id'],':')) === false)
|
||||
{ // Its all-time stats
|
||||
$$row['log_id'] = unserialize($row['log_data']); // $row['log_id'] is the stats type - save in a variable
|
||||
}
|
||||
else
|
||||
{ // Its monthly stats
|
||||
$row['log_id'] = 'mon_'.substr($row['log_id'],0,$pos); // Create a generic variable for each monthly stats
|
||||
$$row['log_id'] = unserialize($row['log_data']); // $row['log_id'] is the stats type - save in a variable
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// this must be the first time a consolidation has happened - this will only ever happen once ...
|
||||
$sql->insert("logstats", "0, 'statBrowser', ''");
|
||||
$sql->insert("logstats", "0, 'statOs', ''");
|
||||
$sql->insert("logstats", "0, 'statScreen', ''");
|
||||
$sql->insert("logstats", "0, 'statDomain', ''");
|
||||
$sql->insert("logstats", "0, 'statReferer', ''");
|
||||
$sql->insert("logstats", "0, 'statQuery', ''");
|
||||
$sql->insert("logstats", "0, 'statTotal', '0'");
|
||||
$sql->insert("logstats", "0, 'statUnique', '0'");
|
||||
|
||||
$statBrowser =array();
|
||||
$statOs =array();
|
||||
$statScreen =array();
|
||||
$statDomain =array();
|
||||
$statReferer =array();
|
||||
$statQuery =array();
|
||||
}
|
||||
|
||||
|
||||
foreach ($stats_list as $s)
|
||||
{
|
||||
$varname = 'mon_'.$s;
|
||||
if (!isset($$varname)) $$varname = array(); // Create monthly arrays if they don't exist
|
||||
}
|
||||
|
||||
require($this->pathtologs.$this->pfileprev); // Yesterday's page accesses - $pageInfo array
|
||||
require($this->pathtologs.$this->ifileprev); // Yesterdays browser accesses etc
|
||||
|
||||
foreach($browserInfo as $name => $amount)
|
||||
{
|
||||
$statBrowser[$name] += $amount;
|
||||
$mon_statBrowser[$name] += $amount;
|
||||
}
|
||||
|
||||
foreach($osInfo as $name => $amount)
|
||||
{
|
||||
$statOs[$name] += $amount;
|
||||
$mon_statOs[$name] += $amount;
|
||||
}
|
||||
|
||||
foreach($screenInfo as $name => $amount)
|
||||
{
|
||||
$statScreen[$name] += $amount;
|
||||
$mon_statScreen[$name] += $amount;
|
||||
}
|
||||
|
||||
|
||||
foreach($domainInfo as $name => $amount)
|
||||
{
|
||||
if(!is_numeric($name))
|
||||
{
|
||||
$statDomain[$name] += $amount;
|
||||
$mon_statDomain[$name] += $amount;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($refInfo as $name => $info)
|
||||
{
|
||||
$statReferer[$name]['url'] = $info['url'];
|
||||
$statReferer[$name]['ttl'] += $info['ttl'];
|
||||
$mon_statReferer[$name]['url'] = $info['url'];
|
||||
$mon_statReferer[$name]['ttl'] += $info['ttl'];
|
||||
}
|
||||
|
||||
|
||||
foreach($searchInfo as $name => $amount)
|
||||
{
|
||||
$statQuery[$name] += $amount;
|
||||
$mon_statQuery[$name] += $amount;
|
||||
}
|
||||
|
||||
$browser = serialize($statBrowser);
|
||||
$os = serialize($statOs);
|
||||
$screen = serialize($statScreen);
|
||||
$domain = serialize($statDomain);
|
||||
$refer = serialize($statReferer);
|
||||
$squery = serialize($statQuery);
|
||||
|
||||
$statTotal += $siteTotal;
|
||||
$statUnique += $siteUnique;
|
||||
|
||||
// Save cumulative results - always keep track of these, even if the $pref doesn't display them
|
||||
$sql->update("logstats", "log_data='{$browser}' WHERE log_id='statBrowser'");
|
||||
$sql->update("logstats", "log_data='{$os}' WHERE log_id='statOs'");
|
||||
$sql->update("logstats", "log_data='{$screen}' WHERE log_id='statScreen'");
|
||||
$sql->update("logstats", "log_data='{$domain}' WHERE log_id='statDomain'");
|
||||
$sql->update("logstats", "log_data='{$refer}' WHERE log_id='statReferer'");
|
||||
$sql->update("logstats", "log_data='{$squery}' WHERE log_id='statQuery'");
|
||||
$sql->update("logstats", "log_data='".intval($statTotal)."' WHERE log_id='statTotal'");
|
||||
$sql->update("logstats", "log_data='".intval($statUnique)."' WHERE log_id='statUnique'");
|
||||
|
||||
|
||||
// Now save the relevant monthly results - only where enabled
|
||||
foreach ($stats_list as $s)
|
||||
{
|
||||
if (isset($pref[$s]) && ($pref[$s] > 1))
|
||||
{ // Value 2 requires saving of monthly stats
|
||||
$srcvar = 'mon_'.$s;
|
||||
$destvar = 'smon_'.$s;
|
||||
$$destvar = serialize($$srcvar);
|
||||
|
||||
if (!$sql->update("logstats", "log_data='".$$destvar."' WHERE log_id='".$s.":".$this->date3."'"))
|
||||
{
|
||||
$sql->insert("logstats", "0, '".$s.":".$this->date3."', '".$$destvar."'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* get page access monthly info from db */
|
||||
if($sql->select("logstats", "*", "log_id='{$this->date3}' "))
|
||||
{
|
||||
$tmp = $sql->fetch();
|
||||
$monthlyInfo = unserialize($tmp['log_data']);
|
||||
unset($tmp);
|
||||
$MonthlyExistsFlag = TRUE;
|
||||
}
|
||||
|
||||
foreach($pageInfo as $key => $info)
|
||||
{
|
||||
$monthlyInfo['TOTAL']['ttlv'] += $info['ttl'];
|
||||
$monthlyInfo['TOTAL']['unqv'] += $info['unq'];
|
||||
$monthlyInfo[$key]['ttlv'] += $info['ttl'];
|
||||
$monthlyInfo[$key]['unqv'] += $info['unq'];
|
||||
}
|
||||
|
||||
$monthlyinfo = serialize($monthlyInfo);
|
||||
|
||||
if($MonthlyExistsFlag)
|
||||
{
|
||||
$sql->update("logstats", "log_data='{$monthlyinfo}' WHERE log_id='{$this->date3}'");
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql->insert("logstats", "0, '{$this->date3}', '{$monthlyinfo}'");
|
||||
}
|
||||
|
||||
|
||||
$this->collatePageTotal($pageInfo);
|
||||
$this->collatePageInfo($pageInfo, $this->date2);
|
||||
$this->resetLogFiles();
|
||||
|
||||
/* and finally, we need to create new logfiles for today ... */
|
||||
$this->createLog();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function createLog()
|
||||
{
|
||||
|
||||
if(!is_writable($this->pathtologs))
|
||||
{
|
||||
echo "<div class='alert alert-error'>Log directory is not writable - please CHMOD ".e_LOG." to 777";
|
||||
echo '<br />Path to logs: '.$this->pathtologs;
|
||||
echo "</div>";
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$varStart = chr(36);
|
||||
@ -61,37 +317,42 @@ class logConsolidate
|
||||
|
||||
$data .= "\n);\n\n?". chr(62);
|
||||
|
||||
if(!touch($pathtologs.$pfile)) {
|
||||
return FALSE;
|
||||
if(!touch($this->pathtologs.$this->pfile))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!touch($pathtologs.$ifile)) {
|
||||
return FALSE;
|
||||
if(!touch($this->pathtologs.$this->ifile))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!is_writable($pathtologs.$pfile)) {
|
||||
if(!is_writable($this->pathtologs.$this->pfile))
|
||||
{
|
||||
$old = umask(0);
|
||||
chmod($pathtologs.$pfile, 0777);
|
||||
chmod($this->pathtologs.$this->pfile, 0777);
|
||||
umask($old);
|
||||
// return FALSE;
|
||||
// return false;
|
||||
}
|
||||
|
||||
if(!is_writable($pathtologs.$ifile)) {
|
||||
if(!is_writable($this->pathtologs.$this->ifile))
|
||||
{
|
||||
$old = umask(0);
|
||||
chmod($pathtologs.$ifile, 0777);
|
||||
chmod($this->pathtologs.$this->ifile, 0777);
|
||||
umask($old);
|
||||
// return FALSE;
|
||||
// return false;
|
||||
}
|
||||
|
||||
if ($handle = fopen($pathtologs.$pfile, 'w'))
|
||||
if ($handle = fopen($this->pathtologs.$this->pfile, 'w'))
|
||||
{
|
||||
fwrite($handle, $data);
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
|
||||
|
||||
$data = "<?php
|
||||
|
||||
$data = "<?php";
|
||||
$data .= "
|
||||
/* e107 website system: Log info file: ".date("z:Y", time())." */
|
||||
|
||||
";
|
||||
@ -104,12 +365,13 @@ class logConsolidate
|
||||
$data .= '$visitInfo'." = array();\n\n";
|
||||
$data .= "?>";
|
||||
|
||||
if ($handle = fopen($pathtologs.$ifile, 'w'))
|
||||
if ($handle = fopen($this->pathtologs.$this->ifile, 'w'))
|
||||
{
|
||||
fwrite($handle, $data);
|
||||
}
|
||||
fclose($handle);
|
||||
return;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -117,14 +379,14 @@ class logConsolidate
|
||||
|
||||
/**
|
||||
* Called if both today's and yesterday's log files missing, to see
|
||||
* if there are any older files we could process. Return FALSE if nothing
|
||||
* if there are any older files we could process. Return false if nothing
|
||||
* Otherwise return a string of relevant information
|
||||
* @param $pathtologs
|
||||
* @return bool|string
|
||||
*/
|
||||
function check_for_old_files($pathtologs)
|
||||
{
|
||||
$no_files = TRUE;
|
||||
// $no_files = TRUE;
|
||||
if ($dir_handle = opendir($pathtologs))
|
||||
{
|
||||
while (false !== ($file = readdir($dir_handle)))
|
||||
@ -143,7 +405,7 @@ class logConsolidate
|
||||
}
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -178,7 +440,7 @@ class logConsolidate
|
||||
{
|
||||
$pageDisallow = "cache|file|eself|admin";
|
||||
$tagRemove = "(\\\)|(\s)|(\')|(\")|(eself)|( )|(\.php)|(\.html)";
|
||||
$tagRemove2 = "(\\\)|(\s)|(\')|(\")|(eself)|( )";
|
||||
// $tagRemove2 = "(\\\)|(\s)|(\')|(\")|(eself)|( )";
|
||||
|
||||
preg_match("#/(.*?)(\?|$)(.*)#si", $url, $match);
|
||||
$match[1] = isset($match[1]) ? $match[1] : '';
|
||||
@ -215,15 +477,19 @@ class logConsolidate
|
||||
* Process Raw Backup Log File. e. e_LOG."log/2015-09-24_SiteStats.log
|
||||
* This method can be used in the case of a database corruption to restore stats to the database.
|
||||
* @param string $file
|
||||
* @param bool $savetoDB
|
||||
* @return bool
|
||||
* @example processRawBackupLog('2015-09-24_SiteStats.log', false);
|
||||
*/
|
||||
function processRawBackupLog($file, $savetoDB=false)
|
||||
{
|
||||
$path = e_LOG."log/".$file;
|
||||
|
||||
$mes = e107::getMessage();
|
||||
|
||||
if(!is_readable($path))
|
||||
{
|
||||
echo "File Not Found: ".$path;
|
||||
$mes->addError( "File Not Found: ".$path);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -279,18 +545,22 @@ class logConsolidate
|
||||
|
||||
if (!feof($handle))
|
||||
{
|
||||
echo "Error: unexpected fgets() fail\n";
|
||||
$mes->addError( "Error: unexpected fgets() fail.");
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
|
||||
echo "<h3>".$file."</h3>";
|
||||
print_a($pageTotal);
|
||||
|
||||
if(e_DEBUG)
|
||||
{
|
||||
$mes->addDebug("<h3>".$file."</h3>");
|
||||
$mes->addDebug(print_a($pageTotal,true));
|
||||
}
|
||||
}
|
||||
|
||||
if($savetoDB === false)
|
||||
{
|
||||
echo "Saving mode is off";
|
||||
$mes->addInfo( "Saving mode is off");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -299,6 +569,8 @@ class logConsolidate
|
||||
{
|
||||
list($date,$name) = explode("_", $file, 2);
|
||||
|
||||
unset($name);
|
||||
|
||||
$unix = strtotime($date);
|
||||
|
||||
$datestamp = date("Y-m-j", $unix);
|
||||
@ -314,15 +586,17 @@ class logConsolidate
|
||||
|
||||
if($this->collatePageInfo($pageTotal, $datestamp))
|
||||
{
|
||||
echo "<br />Data saved to database with id: ".$datestamp;
|
||||
$mes->addSuccess( "Data saved to database with id: ".$datestamp);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "<br />Couldn't save data to database with id: ".$datestamp;
|
||||
$mes->addError( "Couldn't save data to database with id: ".$datestamp);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -338,6 +612,8 @@ class logConsolidate
|
||||
return $vars;
|
||||
}
|
||||
|
||||
unset($datestamp, $bla); // remove editor warnings.
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -494,19 +770,17 @@ class logConsolidate
|
||||
function resetLogFiles()
|
||||
{
|
||||
|
||||
global $pathtologs, $pfileprev, $ifileprev;
|
||||
|
||||
if(empty($pfileprev) || empty($ifileprev))
|
||||
if(empty($this->pfileprev) || empty($this->ifileprev))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/* ok, we're finished with the log file now, we can empty it ... */
|
||||
if(!unlink($pathtologs.$pfileprev))
|
||||
if(!unlink($this->pathtologs.$this->pfileprev))
|
||||
{
|
||||
$data = chr(60)."?php\n". chr(47)."* e107 website system: Log file: ".date("z:Y", time())." *". chr(47)."\n\n\n\n".chr(47)."* THE INFORMATION IN THIS LOG FILE HAS BEEN CONSOLIDATED INTO THE DATABASE - YOU CAN SAFELY DELETE IT. *". chr(47)."\n\n\n?". chr(62);
|
||||
|
||||
if($handle = fopen($pathtologs.$pfileprev, 'w'))
|
||||
if($handle = fopen($this->pathtologs.$this->pfileprev, 'w'))
|
||||
{
|
||||
fwrite($handle, $data);
|
||||
}
|
||||
@ -515,11 +789,11 @@ class logConsolidate
|
||||
}
|
||||
|
||||
|
||||
if(!unlink($pathtologs.$ifileprev))
|
||||
if(!unlink($this->pathtologs.$this->ifileprev))
|
||||
{
|
||||
$data = chr(60)."?php\n". chr(47)."* e107 website system: Log file: ".date("z:Y", time())." *". chr(47)."\n\n\n\n".chr(47)."* THE INFORMATION IN THIS LOG INFO FILE HAS BEEN CONSOLIDATED INTO THE DATABASE - YOU CAN SAFELY DELETE IT. *". chr(47)."\n\n\n?". chr(62);
|
||||
|
||||
if($handle = fopen($pathtologs.$ifileprev, 'w'))
|
||||
if($handle = fopen($this->pathtologs.$this->ifileprev, 'w'))
|
||||
{
|
||||
fwrite($handle, $data);
|
||||
}
|
||||
@ -528,225 +802,14 @@ class logConsolidate
|
||||
}
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$lgc = new logConsolidate();
|
||||
|
||||
|
||||
|
||||
if(file_exists($pathtologs.$pfile)) /* log file is up to date, no consolidation required */
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if(!file_exists($pathtologs.$pfileprev)) // See if any older log files
|
||||
{
|
||||
if (($retvalue = $lgc->check_for_old_files($pathtologs)) === FALSE) /* no logfile found at all - create - this will only ever happen once ... */
|
||||
{
|
||||
$lgc->createLog($pathtologs);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
list($pfileprev,$ifileprev,$date2,$tstamp) = explode('|',$retvalue); // ... if we've got files
|
||||
}
|
||||
|
||||
|
||||
|
||||
// List of the non-page-based info which is gathered - historically only 'all-time' stats, now we support monthly as well
|
||||
$stats_list = array('statBrowser','statOs','statScreen','statDomain','statReferer','statQuery');
|
||||
|
||||
$qry = "`log_id` IN ('statTotal','statUnique'";
|
||||
foreach ($stats_list as $s)
|
||||
{
|
||||
$qry .= ",'{$s}'"; // Always read the all-time stats
|
||||
if ($pref[$s] == 2) $qry .= ",'{$s}:{$date3}'"; // Look for monthlys as well as cumulative
|
||||
}
|
||||
$qry .= ")";
|
||||
|
||||
/* log file is out of date - consolidation required */
|
||||
|
||||
/* get existing stats ... */
|
||||
//if($sql->select("logstats", "*", "log_id='statBrowser' OR log_id='statOs' OR log_id='statScreen' OR log_id='statDomain' OR log_id='statTotal' OR log_id='statUnique' OR log_id='statReferer' OR log_id='statQuery'"))
|
||||
if($sql->select("logstats", "*", $qry))
|
||||
{ // That's read in all the stats we need to modify
|
||||
while($row = $sql->fetch())
|
||||
{
|
||||
if($row['log_id'] == "statUnique")
|
||||
{
|
||||
$statUnique = $row['log_data'];
|
||||
}
|
||||
elseif ($row['log_id'] == "statTotal")
|
||||
{
|
||||
$statTotal = $row['log_data'];
|
||||
}
|
||||
elseif (($pos = strpos($row['log_id'],':')) === FALSE)
|
||||
{ // Its all-time stats
|
||||
$$row['log_id'] = unserialize($row['log_data']); // $row['log_id'] is the stats type - save in a variable
|
||||
}
|
||||
else
|
||||
{ // Its monthly stats
|
||||
$row['log_id'] = 'mon_'.substr($row['log_id'],0,$pos); // Create a generic variable for each monthly stats
|
||||
$$row['log_id'] = unserialize($row['log_data']); // $row['log_id'] is the stats type - save in a variable
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// this must be the first time a consolidation has happened - this will only ever happen once ...
|
||||
$sql->insert("logstats", "0, 'statBrowser', ''");
|
||||
$sql->insert("logstats", "0, 'statOs', ''");
|
||||
$sql->insert("logstats", "0, 'statScreen', ''");
|
||||
$sql->insert("logstats", "0, 'statDomain', ''");
|
||||
$sql->insert("logstats", "0, 'statReferer', ''");
|
||||
$sql->insert("logstats", "0, 'statQuery', ''");
|
||||
$sql->insert("logstats", "0, 'statTotal', '0'");
|
||||
$sql->insert("logstats", "0, 'statUnique', '0'");
|
||||
|
||||
$statBrowser =array();
|
||||
$statOs =array();
|
||||
$statScreen =array();
|
||||
$statDomain =array();
|
||||
$statReferer =array();
|
||||
$statQuery =array();
|
||||
}
|
||||
|
||||
|
||||
foreach ($stats_list as $s)
|
||||
{
|
||||
$varname = 'mon_'.$s;
|
||||
if (!isset($$varname)) $$varname = array(); // Create monthly arrays if they don't exist
|
||||
}
|
||||
|
||||
|
||||
require_once($pathtologs.$pfileprev); // Yesterday's page accesses - $pageInfo array
|
||||
require_once($pathtologs.$ifileprev); // Yesterdays browser accesses etc
|
||||
|
||||
foreach($browserInfo as $name => $amount)
|
||||
{
|
||||
$statBrowser[$name] += $amount;
|
||||
$mon_statBrowser[$name] += $amount;
|
||||
}
|
||||
|
||||
foreach($osInfo as $name => $amount)
|
||||
{
|
||||
$statOs[$name] += $amount;
|
||||
$mon_statOs[$name] += $amount;
|
||||
}
|
||||
|
||||
foreach($screenInfo as $name => $amount)
|
||||
{
|
||||
$statScreen[$name] += $amount;
|
||||
$mon_statScreen[$name] += $amount;
|
||||
}
|
||||
|
||||
|
||||
foreach($domainInfo as $name => $amount)
|
||||
{
|
||||
if(!is_numeric($name))
|
||||
{
|
||||
$statDomain[$name] += $amount;
|
||||
$mon_statDomain[$name] += $amount;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($refInfo as $name => $info)
|
||||
{
|
||||
$statReferer[$name]['url'] = $info['url'];
|
||||
$statReferer[$name]['ttl'] += $info['ttl'];
|
||||
$mon_statReferer[$name]['url'] = $info['url'];
|
||||
$mon_statReferer[$name]['ttl'] += $info['ttl'];
|
||||
}
|
||||
|
||||
|
||||
foreach($searchInfo as $name => $amount)
|
||||
{
|
||||
$statQuery[$name] += $amount;
|
||||
$mon_statQuery[$name] += $amount;
|
||||
}
|
||||
|
||||
$browser = serialize($statBrowser);
|
||||
$os = serialize($statOs);
|
||||
$screen = serialize($statScreen);
|
||||
$domain = serialize($statDomain);
|
||||
$refer = serialize($statReferer);
|
||||
$squery = serialize($statQuery);
|
||||
|
||||
$statTotal += $siteTotal;
|
||||
$statUnique += $siteUnique;
|
||||
|
||||
// Save cumulative results - always keep track of these, even if the $pref doesn't display them
|
||||
$sql->update("logstats", "log_data='{$browser}' WHERE log_id='statBrowser'");
|
||||
$sql->update("logstats", "log_data='{$os}' WHERE log_id='statOs'");
|
||||
$sql->update("logstats", "log_data='{$screen}' WHERE log_id='statScreen'");
|
||||
$sql->update("logstats", "log_data='{$domain}' WHERE log_id='statDomain'");
|
||||
$sql->update("logstats", "log_data='{$refer}' WHERE log_id='statReferer'");
|
||||
$sql->update("logstats", "log_data='{$squery}' WHERE log_id='statQuery'");
|
||||
$sql->update("logstats", "log_data='".intval($statTotal)."' WHERE log_id='statTotal'");
|
||||
$sql->update("logstats", "log_data='".intval($statUnique)."' WHERE log_id='statUnique'");
|
||||
|
||||
|
||||
// Now save the relevant monthly results - only where enabled
|
||||
foreach ($stats_list as $s)
|
||||
{
|
||||
if (isset($pref[$s]) && ($pref[$s] > 1))
|
||||
{ // Value 2 requires saving of monthly stats
|
||||
$srcvar = 'mon_'.$s;
|
||||
$destvar = 'smon_'.$s;
|
||||
$$destvar = serialize($$srcvar);
|
||||
|
||||
if (!$sql->update("logstats", "log_data='".$$destvar."' WHERE log_id='".$s.":".$date3."'"))
|
||||
{
|
||||
$sql->insert("logstats", "0, '".$s.":".$date3."', '".$$destvar."'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* get page access monthly info from db */
|
||||
if($sql->select("logstats", "*", "log_id='{$date3}' "))
|
||||
{
|
||||
$tmp = $sql->fetch();
|
||||
$monthlyInfo = unserialize($tmp['log_data']);
|
||||
unset($tmp);
|
||||
$MonthlyExistsFlag = TRUE;
|
||||
}
|
||||
|
||||
foreach($pageInfo as $key => $info)
|
||||
{
|
||||
$monthlyInfo['TOTAL']['ttlv'] += $info['ttl'];
|
||||
$monthlyInfo['TOTAL']['unqv'] += $info['unq'];
|
||||
$monthlyInfo[$key]['ttlv'] += $info['ttl'];
|
||||
$monthlyInfo[$key]['unqv'] += $info['unq'];
|
||||
}
|
||||
|
||||
$monthlyinfo = serialize($monthlyInfo);
|
||||
|
||||
if($MonthlyExistsFlag)
|
||||
{
|
||||
$sql->update("logstats", "log_data='{$monthlyinfo}' WHERE log_id='{$date3}'");
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql->insert("logstats", "0, '{$date3}', '{$monthlyinfo}'");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$lgc->collatePageTotal($pageInfo);
|
||||
|
||||
$lgc->collatePageInfo($pageInfo, $date2);
|
||||
|
||||
$lgc->resetLogFiles();
|
||||
|
||||
|
||||
/* and finally, we need to create new logfiles for today ... */
|
||||
$lgc->createLog($pathtologs,$statTotal,$statUnique);
|
||||
|
||||
|
||||
|
||||
|
@ -27,6 +27,9 @@ if (vartrue($pref['statActivate']))
|
||||
if(USER_AREA)
|
||||
{
|
||||
require_once(e_PLUGIN.'log/consolidate.php');
|
||||
$lgc = new logConsolidate();
|
||||
$lgc->run();
|
||||
|
||||
$err_flag = '';
|
||||
if (defined('ERR_PAGE_ACTIVE'))
|
||||
{ // We've got an error - set a flag to log it
|
||||
|
101
e107_plugins/log/languages/English_admin.php
Normal file
101
e107_plugins/log/languages/English_admin.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/*
|
||||
* e107 website system
|
||||
*
|
||||
* Copyright (C) 2008-2013 e107 Inc (e107.org)
|
||||
* Released under the terms and conditions of the
|
||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
||||
*
|
||||
*/
|
||||
|
||||
//define("ADSTAT_ON", "On");
|
||||
//define("ADSTAT_OFF", "Off");
|
||||
define("ADSTAT_LAN_1", "This plugin will log all visits to your site, and build detailed statistic screens based on the information gathered.");
|
||||
define("ADSTAT_LAN_2", "The statistics logger has been successfully installed. To activate, please go to the config screen and click Activate.<br /><b>You must set the permissions of the e107_plugins/log/logs folder to 777 (chmod 777)</b>");
|
||||
define("ADSTAT_LAN_3", "Statistic Logging");
|
||||
define("ADSTAT_LAN_4", "Activate statistic logging");
|
||||
define("ADSTAT_LAN_5", "Statistic types");
|
||||
define("ADSTAT_LAN_6", "Browsers");
|
||||
define("ADSTAT_LAN_7", "Operating Systems");
|
||||
define("ADSTAT_LAN_8", "Screen resolutions / depths");
|
||||
define("ADSTAT_LAN_9", "Countries/domains visited from");
|
||||
define("ADSTAT_LAN_10", "Referrers");
|
||||
define("ADSTAT_LAN_11", "Search queries");
|
||||
define("ADSTAT_LAN_12", "Reset stats");
|
||||
define("ADSTAT_LAN_13", "This will erase the all-time stats - careful! Deletes stats to the end of yesterday. There is a separate menu option to delete selected historical data"); // TODO: Condense this help field (minimize)
|
||||
define("ADSTAT_LAN_14", "Page counts");
|
||||
//define("ADSTAT_LAN_15", "Update Statistic Settings");
|
||||
define("ADSTAT_LAN_16", "Site Statistic Settings");
|
||||
//define("ADSTAT_LAN_17", "Statistic settings updated");
|
||||
define("ADSTAT_LAN_18", "Allow access to main statistics page to ...");
|
||||
define("ADSTAT_LAN_19", "Recent visitors");
|
||||
define("ADSTAT_LAN_20", "Count admin visits");
|
||||
define("ADSTAT_LAN_21", "Maximum records to display on stats page");
|
||||
define("ADSTAT_LAN_22", "Run update routine");
|
||||
define("ADSTAT_LAN_23", "logs from a previous version of e107 have been detected, update them here");
|
||||
define("ADSTAT_LAN_24", "Go to update script");
|
||||
//define("ADSTAT_LAN_25", "Selected stats reset");
|
||||
define("ADSTAT_LAN_26", "Remove page entries");
|
||||
define("ADSTAT_LAN_27", "If your stats have incorrect pages, you can remove them here");
|
||||
define("ADSTAT_LAN_28", "Open page");
|
||||
define("ADSTAT_LAN_29", "Page Name");
|
||||
define("ADSTAT_LAN_30", "Check to remove");
|
||||
define("ADSTAT_LAN_31", "Remove selected pages");
|
||||
define("ADSTAT_LAN_32", "Page Tidy");
|
||||
// define("ADSTAT_LAN_33", "Configure Statistics Logging"); see English_global.php
|
||||
// define("ADSTAT_LAN_34", "Site Stats");
|
||||
define ('ADSTAT_LAN_35', 'Options');
|
||||
define ('ADSTAT_LAN_36', 'Data Export');
|
||||
//define ('ADSTAT_LAN_37', 'Create export file');
|
||||
define ('ADSTAT_LAN_38', "You must set the e107_plugins/log/logs folder to be writable");
|
||||
define ('ADSTAT_LAN_39', 'Stats Logging Functions');
|
||||
define ('ADSTAT_LAN_40', 'Export log data');
|
||||
define ('ADSTAT_LAN_41', 'Date selection');
|
||||
define ('ADSTAT_LAN_42', 'Single Day');
|
||||
define ('ADSTAT_LAN_43', 'Daily for a month');
|
||||
define ('ADSTAT_LAN_44', 'Monthly for a year');
|
||||
define ('ADSTAT_LAN_45', 'All-time');
|
||||
define ('ADSTAT_LAN_46', 'Date:');
|
||||
define ('ADSTAT_LAN_47', 'Invalid date chosen');
|
||||
define ('ADSTAT_LAN_48', 'Monthly and All-time');
|
||||
define ('ADSTAT_LAN_49', 'All-time Only');
|
||||
define ('ADSTAT_LAN_50', 'None');
|
||||
define ('ADSTAT_LAN_51', 'Output Data');
|
||||
define ('ADSTAT_LAN_52', 'Page Data');
|
||||
define ('ADSTAT_LAN_53', 'No selection possible');
|
||||
define ('ADSTAT_LAN_54', 'Invalid type selection');
|
||||
define ('ADSTAT_LAN_55', 'Single quote');
|
||||
define ('ADSTAT_LAN_56', 'Double quote');
|
||||
define ('ADSTAT_LAN_57', 'Comma');
|
||||
define ('ADSTAT_LAN_58', 'Pipe (|)');
|
||||
define ('ADSTAT_LAN_59', 'CSV separator, quotes');
|
||||
define ('ADSTAT_LAN_60', 'Strip site address from URLs');
|
||||
define ('ADSTAT_LAN_61', '(if checked, just gives page reference)');
|
||||
define ('ADSTAT_LAN_62', 'All-time (detailed)');
|
||||
define ('ADSTAT_LAN_63', 'Available Datasets');
|
||||
define ('ADSTAT_LAN_64', 'Database records found:');
|
||||
define ('ADSTAT_LAN_65', 'DB filter string:');
|
||||
define ('ADSTAT_LAN_66', 'Show Datasets');
|
||||
define ('ADSTAT_LAN_67', 'Generate a CSV (Comma Separated Variable) file of historical statistics which meets the specified criteria');
|
||||
define ('ADSTAT_LAN_68', 'Show the statistics database entries which actually exist and meet the selection criteria');
|
||||
define ('ADSTAT_LAN_69', 'Delete historical data');
|
||||
define ('ADSTAT_LAN_70', 'Delete data older than:');
|
||||
define ('ADSTAT_LAN_71', 'Delete Data');
|
||||
define ('ADSTAT_LAN_72', 'Confirm deletion of data older than first day of:');
|
||||
//define ('ADSTAT_LAN_73', 'Confirm');
|
||||
define ('ADSTAT_LAN_74', '(List of data entries which will be deleted below)');
|
||||
define ('ADSTAT_LAN_75', 'Records for deletion');
|
||||
define ('ADSTAT_LAN_76', 'Caution! Once deleted, the data cannot be recovered. Backup or export your database first');
|
||||
define ('ADSTAT_LAN_77', 'Records deleted:');
|
||||
define ('ADSTAT_LAN_78', 'Show previous month as well as current month for non-page access stats');
|
||||
define ('ADSTAT_LAN_79', 'Only used if monthly stats collected');
|
||||
define ('ADSTAT_LAN_80', 'The following pages were deleted:');
|
||||
define ('ADSTAT_LAN_81', 'Statistics cleared:');
|
||||
define ('ADSTAT_LAN_82', 'Following values now set:');
|
||||
define ('ADSTAT_LAN_83', 'Following log ID entries removed:');
|
||||
define ('ADSTAT_LAN_84', '');
|
||||
define ('ADSTAT_LAN_85', '');
|
||||
|
||||
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user