diff --git a/e107_plugins/log/consolidate.php b/e107_plugins/log/consolidate.php
index a3e5af734..cfbf8e2ab 100644
--- a/e107_plugins/log/consolidate.php
+++ b/e107_plugins/log/consolidate.php
@@ -2,21 +2,15 @@
/*
* e107 website system
*
- * Copyright (C) 2008-2009 e107 Inc (e107.org)
+ * Copyright (C) 2008-2015 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
- *
- *
- *
- * $Source: /cvs_backup/e107_0.8/e107_plugins/log/consolidate.php,v $
- * $Revision$
- * $Date$
- * $Author$
+
*/
/* first thing to do is check if the log file is out of date ... */
-// $pathtologs = e_PLUGIN."log/logs/";
+
if (!defined('e107_INIT')){ exit; }
@@ -31,15 +25,392 @@ $pfile = "logp_".$date.".php"; // Today's log file
$ifileprev = "logi_".$yesterday.".php";
$ifile = "logi_".$date.".php";
+// Begin v2.x cleanup.
+class logConsolidate
+{
+
+ function ___construct()
+ {
+
+ }
+
+ function createLog($pathtologs, $statTotal='', $statUnique='')
+ {
+ global $pfile, $ifile;
+
+ if(!is_writable($pathtologs))
+ {
+ echo "Log directory is not writable - please CHMOD ".e_LOG." to 777";
+ echo '
Path to logs: '.$pathtologs;
+ return FALSE;
+ }
+
+ $varStart = chr(36);
+ $quote = chr(34);
+
+ $data = chr(60)."?php\n". chr(47)."* e107 website system: Log file: ".date("z:Y", time())." *". chr(47)."\n\n".
+ $varStart."refererData = ".$quote.$quote.";\n".
+ $varStart."ipAddresses = ".$quote.$quote.";\n".
+ $varStart."hosts = ".$quote.$quote.";\n".
+ $varStart."siteTotal = ".$quote."0".$quote.";\n".
+ $varStart."siteUnique = ".$quote."0".$quote.";\n".
+ $varStart."screenInfo = array();\n".
+ $varStart."browserInfo = array();\n".
+ $varStart."osInfo = array();\n".
+ $varStart."pageInfo = array(\n";
+
+ $data .= "\n);\n\n?". chr(62);
+
+ if(!touch($pathtologs.$pfile)) {
+ return FALSE;
+ }
+
+ if(!touch($pathtologs.$ifile)) {
+ return FALSE;
+ }
+
+ if(!is_writable($pathtologs.$pfile)) {
+ $old = umask(0);
+ chmod($pathtologs.$pfile, 0777);
+ umask($old);
+ // return FALSE;
+ }
+
+ if(!is_writable($pathtologs.$ifile)) {
+ $old = umask(0);
+ chmod($pathtologs.$ifile, 0777);
+ umask($old);
+ // return FALSE;
+ }
+
+ if ($handle = fopen($pathtologs.$pfile, 'w'))
+ {
+ fwrite($handle, $data);
+ }
+ fclose($handle);
+
+
+ $data = "";
+
+ if ($handle = fopen($pathtologs.$ifile, 'w'))
+ {
+ fwrite($handle, $data);
+ }
+ fclose($handle);
+ return;
+ }
+
+
+
+
+ /**
+ * 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
+ * Otherwise return a string of relevant information
+ * @param $pathtologs
+ * @return bool|string
+ */
+ function check_for_old_files($pathtologs)
+ {
+ $no_files = TRUE;
+ if ($dir_handle = opendir($pathtologs))
+ {
+ while (false !== ($file = readdir($dir_handle)))
+ {
+ // Do match on #^logp_(\d{1,3})\.php$#i
+ if (preg_match('#^logp_(\d{1,3}\.\d{4})\.php$#i',$file,$match) == 1)
+ { // got a matching file
+ $yesterday = $match[1]; // Day of year - zero is 1st Jan
+ $pfileprev = "logp_".$yesterday.".php"; // Yesterday's log file
+ $ifileprev = "logi_".$yesterday.".php";
+ list($day,$year) = explode('.',$yesterday);
+ $tstamp = mktime(0,0,0,1,1,$year) + ($day*86400);
+ $date2 = date("Y-m-j", $tstamp); // Yesterday's date for the database summary
+ $temp = array($pfileprev,$ifileprev,$date2,$tstamp);
+ return implode('|',$temp);
+ }
+ }
+ }
+ return FALSE;
+ }
+
+
+
+
+
+ // for future use.
+ function collate($pfile)
+ {
+ if(is_readable(e_LOG.$pfile))
+ {
+ require(e_LOG.$pfile); // contains $pageInfo;
+ }
+ else
+ {
+ return false;
+ }
+
+ }
+
+ /**
+ * @param $url
+ * @param bool $logQry
+ * @param string $err_code
+ * @return bool|mixed|string
+ */
+ function getPageKey($url,$logQry=false,$err_code='')
+ {
+ $pageDisallow = "cache|file|eself|admin";
+ $tagRemove = "(\\\)|(\s)|(\')|(\")|(eself)|( )|(\.php)|(\.html)";
+ $tagRemove2 = "(\\\)|(\s)|(\')|(\")|(eself)|( )";
+
+ preg_match("#/(.*?)(\?|$)(.*)#si", $url, $match);
+ $match[1] = isset($match[1]) ? $match[1] : '';
+ $pageName = substr($match[1], (strrpos($match[1], "/")+1));
+ $PN = $pageName;
+
+ $pageName = preg_replace("/".$tagRemove."/si", "", $pageName);
+
+ if($pageName == "")
+ {
+ return "index";
+ }
+
+ if(preg_match("/".$pageDisallow."/i", $pageName))
+ {
+ return false;
+ }
+
+ if ($logQry)
+ {
+ $pageName .= '+'.$match[3]; // All queries match
+ }
+
+ $pageName = $err_code.$pageName; // Add the error code at the beginning, so its treated uniquely
+
+
+ return $pageName;
+ }
+
+
+
+
+ /**
+ * Fix corrupted page data.
+ * Re-calculate all page totals from all existing database information and save to DB as 'pageTotal'. .
+ */
+ function collatePageTotalDB()
+ {
+ $sql = e107::getDb();
+
+ $qry = "SELECT * FROM `#logstats` WHERE `log_id` REGEXP '^[0-9]' AND `log_data` LIKE '%http%'";
+ $data = $sql->retrieve($qry,true);
+
+ $pageTotal = array();
+
+ foreach($data as $values)
+ {
+ $tmp = explode(chr(1),$values['log_data']);
+ unset($tmp[0],$tmp[1]);
+ $thisTotal = array();
+
+ foreach($tmp as $val)
+ {
+ if(!empty($val))
+ {
+ list($url,$ttl,$unq) = explode("|",$val);
+ $key = $this->getPageKey($url);
+
+ $thisTotal[$key]['url'] = $url;
+ $thisTotal[$key]['ttlv'] += $ttl;
+ $thisTotal[$key]['unqv'] += $unq;
+
+ $pageTotal[$key]['url'] = $url;
+ $pageTotal[$key]['ttlv'] += $ttl;
+ $pageTotal[$key]['unqv'] += $unq;
+ }
+
+ }
+
+ // echo "
".$values['log_id']."
";
+ // print_a($thisTotal);
+
+ }
+
+ if(empty($pageTotal))
+ {
+ return false;
+ }
+
+ $id = $sql->retrieve('logstats','log_uniqueid', "log_id='pageTotal'");
+
+ $insertData = array(
+ 'log_uniqueid' => intval($id),
+ 'log_id'=> 'pageTotal',
+ 'log_data'=> serialize($pageTotal)
+ );
+
+ // echo "Total
";
+ // print_a($pageTotal);
+
+ return $sql->replace('logstats', $insertData);
+
+ }
+
+
+ /**
+ * collate page total information using today's data and totals stored in DB.
+ * @param $pageInfo - from today's file.
+ */
+ function collatePageTotal($pageInfo=array())
+ {
+ $sql = e107::getDb();
+
+ if($sql->select("logstats", "*", "log_id='pageTotal' "))
+ {
+ $tmp = $sql->fetch();
+ $pageTotal = unserialize($tmp['log_data']);
+ $uniqueID = $tmp['log_uniqueid'];
+ unset($tmp);
+
+ }
+ else
+ {
+ $pageTotal = array();
+ $uniqueID = 0;
+ }
+
+ // echo "DB Totals
";
+ // print_a($pageTotal);
+
+ // echo "From File
";
+ // print_a($pageInfo);
+
+ foreach($pageInfo as $key => $info)
+ {
+ $pageTotal[$key]['url'] = $info['url'];
+ $pageTotal[$key]['ttlv'] += $info['ttl'];
+ $pageTotal[$key]['unqv'] += $info['unq'];
+ }
+
+ // echo "Consilidated
";
+ // print_a($pageTotal);
+
+ if(empty($pageTotal))
+ {
+ return false;
+ }
+
+ $insertData = array(
+ 'log_uniqueid' => intval($uniqueID),
+ 'log_id' => 'pageTotal',
+ 'log_data' => serialize($pageTotal)
+ );
+
+ return $sql->replace('logstats', $insertData);
+
+ }
+
+
+ /**
+ * Collate individual page information into an array
+ * @param $pageInfo
+ */
+ function collatePageInfo($pageInfo)
+ {
+
+ global $date2;
+
+ $sql = e107::getDb();
+ $tp = e107::getParser();
+
+ $data = "";
+ $dailytotal = 0;
+ $uniquetotal = 0;
+
+ foreach($pageInfo as $key => $value)
+ {
+ $data .= $value['url']."|".$value['ttl']."|".$value['unq'].chr(1);
+ $dailytotal += $value['ttl'];
+ $uniquetotal += $value['unq'];
+ }
+
+ $data = $dailytotal.chr(1).$uniquetotal.chr(1) . $data;
+ $sql->insert("logstats", "0, '$date2', '".$tp -> toDB($data, true)."'");
+ }
+
+
+ /**
+ * Reset (empty) yesterday's log files.
+ * @return bool
+ */
+ function resetLogFiles()
+ {
+
+ global $pathtologs, $pfileprev, $ifileprev;
+
+ if(empty($pfileprev) || empty($ifileprev))
+ {
+ return false;
+ }
+
+ /* ok, we're finished with the log file now, we can empty it ... */
+ if(!unlink($pathtologs.$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'))
+ {
+ fwrite($handle, $data);
+ }
+
+ fclose($handle);
+ }
+
+
+ if(!unlink($pathtologs.$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'))
+ {
+ fwrite($handle, $data);
+ }
+
+ fclose($handle);
+ }
+
+
+
+ }
+}
+
+
+$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 = check_for_old_files($pathtologs)) === FALSE) /* no logfile found at all - create - this will only ever happen once ... */
+ if (($retvalue = $lgc->check_for_old_files($pathtologs)) === FALSE) /* no logfile found at all - create - this will only ever happen once ... */
{
- createLog($pathtologs);
+ $lgc->createLog($pathtologs);
return FALSE;
}
@@ -228,178 +599,20 @@ else
}
-/* collate page total information */
-if($sql->select("logstats", "*", "log_id='pageTotal' "))
-{
- $tmp = $sql->fetch();
- $pageTotal = unserialize($tmp['log_data']);
- unset($tmp);
-}
-else
-{
- $pageTotal = array();
-}
-
-foreach($pageInfo as $key => $info)
-{
- $pageTotal[$key]['url'] = $info['url'];
- $pageTotal[$key]['ttlv'] += $info['ttl'];
- $pageTotal[$key]['unqv'] += $info['unq'];
-}
-
-$pagetotal = serialize($pageTotal);
-
-$insertPageTotal = array('log_data'=> $pageTotal, 'WHERE' => "log_id='pageTotal'");
-$sql->replace('logstats', $insertPageTotal);
-
-/*
-if(!$sql->update("logstats", "log_data='{$pagetotal}' WHERE log_id='pageTotal' "))
-{
- $sql->insert("logstats", "0, 'pageTotal', '{$pagetotal}' ");
-}*/
-/* now we need to collate the individual page information into an array ... */
-$data = "";
-$dailytotal = 0;
-$uniquetotal = 0;
-foreach($pageInfo as $key => $value)
-{
- $data .= $value['url']."|".$value['ttl']."|".$value['unq'].chr(1);
- $dailytotal += $value['ttl'];
- $uniquetotal += $value['unq'];
-}
-$data = $dailytotal.chr(1).$uniquetotal.chr(1) . $data;
-$sql->insert("logstats", "0, '$date2', '".$tp -> toDB($data, true)."'");
+$lgc->collatePageTotal($pageInfo);
+
+$lgc->collatePageInfo($pageInfo);
+
+$lgc->resetLogFiles();
-
-/* ok, we're finished with the log file now, we can empty it ... */
-if(!unlink($pathtologs.$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')) {
- fwrite($handle, $data);
- }
- fclose($handle);
-}
-if(!unlink($pathtologs.$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')) {
- fwrite($handle, $data);
- }
- fclose($handle);
-}
/* and finally, we need to create new logfiles for today ... */
-createLog($pathtologs);
-/* done! */
+$lgc->createLog($pathtologs,$statTotal,$statUnique);
-function createLog($pathtologs)
-{
- global $statTotal, $statUnique, $pfile, $ifile;
- if(!is_writable($pathtologs))
- {
- echo "Log directory is not writable - please CHMOD ".e_LOG." to 777";
- echo '
Path to logs: '.$pathtologs;
- return FALSE;
- }
-
- $varStart = chr(36);
- $quote = chr(34);
-
- $data = chr(60)."?php\n". chr(47)."* e107 website system: Log file: ".date("z:Y", time())." *". chr(47)."\n\n".
- $varStart."refererData = ".$quote.$quote.";\n".
- $varStart."ipAddresses = ".$quote.$quote.";\n".
- $varStart."hosts = ".$quote.$quote.";\n".
- $varStart."siteTotal = ".$quote."0".$quote.";\n".
- $varStart."siteUnique = ".$quote."0".$quote.";\n".
- $varStart."screenInfo = array();\n".
- $varStart."browserInfo = array();\n".
- $varStart."osInfo = array();\n".
- $varStart."pageInfo = array(\n";
-
- $data .= "\n);\n\n?". chr(62);
-
- if(!touch($pathtologs.$pfile)) {
- return FALSE;
- }
-
- if(!touch($pathtologs.$ifile)) {
- return FALSE;
- }
-
- if(!is_writable($pathtologs.$pfile)) {
- $old = umask(0);
- chmod($pathtologs.$pfile, 0777);
- umask($old);
- // return FALSE;
- }
-
- if(!is_writable($pathtologs.$ifile)) {
- $old = umask(0);
- chmod($pathtologs.$ifile, 0777);
- umask($old);
- // return FALSE;
- }
-
- if ($handle = fopen($pathtologs.$pfile, 'w'))
- {
- fwrite($handle, $data);
- }
- fclose($handle);
-
-
-$data = "";
-
- if ($handle = fopen($pathtologs.$ifile, 'w'))
- {
- fwrite($handle, $data);
- }
- fclose($handle);
- return;
-}
-
-// 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
-// Otherwise return a string of relevant information
-function check_for_old_files($pathtologs)
-{
- $no_files = TRUE;
- if ($dir_handle = opendir($pathtologs))
- {
- while (false !== ($file = readdir($dir_handle)))
- {
- // Do match on #^logp_(\d{1,3})\.php$#i
- if (preg_match('#^logp_(\d{1,3}\.\d{4})\.php$#i',$file,$match) == 1)
- { // got a matching file
- $yesterday = $match[1]; // Day of year - zero is 1st Jan
- $pfileprev = "logp_".$yesterday.".php"; // Yesterday's log file
- $ifileprev = "logi_".$yesterday.".php";
- list($day,$year) = explode('.',$yesterday);
- $tstamp = mktime(0,0,0,1,1,$year) + ($day*86400);
- $date2 = date("Y-m-j", $tstamp); // Yesterday's date for the database summary
- $temp = array($pfileprev,$ifileprev,$date2,$tstamp);
- return implode('|',$temp);
- }
- }
- }
- return FALSE;
-}
?>
\ No newline at end of file
diff --git a/e107_plugins/log/e_shortcode.php b/e107_plugins/log/e_shortcode.php
index 84a2151dc..b76409dd6 100644
--- a/e107_plugins/log/e_shortcode.php
+++ b/e107_plugins/log/e_shortcode.php
@@ -12,12 +12,14 @@ class log_shortcodes extends e_shortcode
private $dbPageInfo;
- function __construct($order)
+ function __construct()
{
$sql = e107::getDB();
$logfile = e_LOG.'logp_'.date('z.Y', time()).'.php'; /* get today's logfile ... */
- if(is_readable($logfile))
+ $pageInfo = array();
+
+ if(is_readable($logfile)) // populate $pageInfo
{
require($logfile);
}
@@ -27,6 +29,7 @@ class log_shortcodes extends e_shortcode
if(is_readable($logfile))
{
require($logfile);
+ // e107::getMessage()->addDebug("Loading Log File: ".$logfile);
}
@@ -34,6 +37,7 @@ class log_shortcodes extends e_shortcode
{
$row = $sql->fetch();
$this->dbPageInfo = unserialize($row['log_data']);
+ // e107::getMessage()->addDebug("Loading Logstats from DB: ".print_a($this->dbPageInfo,true));
}
else
{
diff --git a/e107_plugins/log/log.php b/e107_plugins/log/log.php
index 2a730d92a..24d9e8462 100644
--- a/e107_plugins/log/log.php
+++ b/e107_plugins/log/log.php
@@ -186,25 +186,52 @@ if($ref && !strstr($ref, $_SERVER['HTTP_HOST']))
}
-$pageDisallow = "cache|file|eself|admin";
-$tagRemove = "(\\\)|(\s)|(\')|(\")|(eself)|( )|(\.php)|(\.html)";
-$tagRemove2 = "(\\\)|(\s)|(\')|(\")|(eself)|( )";
-
-preg_match("#/(.*?)(\?|$)(.*)#si", $self, $match);
-$match[1] = isset($match[1]) ? $match[1] : '';
-$pageName = substr($match[1], (strrpos($match[1], "/")+1));
-$PN = $pageName;
-$pageName = preg_replace("/".$tagRemove."/si", "", $pageName);
-if($pageName == "") $pageName = "index";
-
-if(preg_match("/".$pageDisallow."/i", $pageName)) return;
-if ($logQry)
+
+function logGetPageKey($url,$logQry=false,$err_code='')
{
- $pageName .= '+'.$match[3]; // All queries match
+ $pageDisallow = "cache|file|eself|admin";
+ $tagRemove = "(\\\)|(\s)|(\')|(\")|(eself)|( )|(\.php)|(\.html)";
+ $tagRemove2 = "(\\\)|(\s)|(\')|(\")|(eself)|( )";
+
+ preg_match("#/(.*?)(\?|$)(.*)#si", $url, $match);
+ $match[1] = isset($match[1]) ? $match[1] : '';
+ $pageName = substr($match[1], (strrpos($match[1], "/")+1));
+ $PN = $pageName;
+
+ $pageName = preg_replace("/".$tagRemove."/si", "", $pageName);
+ if($pageName == "")
+ {
+ return "index";
+ }
+
+ if(preg_match("/".$pageDisallow."/i", $pageName))
+ {
+ return false;
+ }
+
+ if ($logQry)
+ {
+ $pageName .= '+'.$match[3]; // All queries match
+ }
+
+ $pageName = $err_code.$pageName; // Add the error code at the beginning, so its treated uniquely
+
+
+ return $pageName;
}
-$pageName = $err_code.$pageName; // Add the error code at the beginning, so its treated uniquely
+
+
+
+
+if(!$pageName = logGetPageKey($self,$logQry,$err_code))
+{
+ return;
+}
+
+
+
//$logfp = fopen(e_LOG.'rcvstring.txt', 'a+'); fwrite($logfp, $pageName."\n"); fclose($logfp);
$p_handle = fopen($logPfile, 'r+');
diff --git a/e107_plugins/log/stats.php b/e107_plugins/log/stats.php
index 1001684dc..de2bcc4e7 100644
--- a/e107_plugins/log/stats.php
+++ b/e107_plugins/log/stats.php
@@ -1964,7 +1964,7 @@ class siteStats
*
* @return string text to be displayed
*/
- function bar($percen, $val,$name)
+ function bar($percen, $val,$name='')
{
if(deftrue('BOOTSTRAP'))
{