diff --git a/e107_handlers/admin_log_class.php b/e107_handlers/admin_log_class.php
index fa0df0bff..2fa992824 100644
--- a/e107_handlers/admin_log_class.php
+++ b/e107_handlers/admin_log_class.php
@@ -664,7 +664,19 @@ class e_admin_log
$date = ($append == true) ? date('Y-m-d') : date('Y-m-d_H-i-s').'_'.crc32($text);
- $fileName = e_LOG.$date."_".$this->logFile.".log";
+ $dir = e_LOG;
+
+ if(e_CURRENT_PLUGIN) // If it's a plugin, create a subfolder.
+ {
+ $dir = e_LOG.e_CURRENT_PLUGIN."/";
+
+ if(!is_dir($dir))
+ {
+ mkdir($dir,0755);
+ }
+ }
+
+ $fileName = $dir.$date."_".$this->logFile.".log";
if($append == true)
{
@@ -679,11 +691,15 @@ class e_admin_log
$app = null;
$text = $head . $text;
}
-
+
if(file_put_contents($fileName, $text, $app))
{
$this->_allMessages = array();
return $this->logFile;
+ }
+ elseif(getperms('0') && E107_DEBUG_LEVEL > 0)
+ {
+ echo "Could Save to Log File: ".$fileName;
}
return false;
@@ -701,7 +717,7 @@ class e_admin_log
*/
public function toFile($name,$logTitle='',$append=false)
{
-
+
$this->logFile = $name;
$this->saveToFile($logTitle,$append);
$this->logFile = null;
diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php
index f76d0db79..36a779a1e 100644
--- a/e107_handlers/e107_class.php
+++ b/e107_handlers/e107_class.php
@@ -2588,7 +2588,7 @@ class e107
if(isset($GLOBALS['_E107']['minimal']) || e_AJAX_REQUEST || deftrue('e_MINIMAL'))
{
$_e107vars = array('forceuserupdate', 'online', 'theme', 'menus', 'prunetmp');
-
+ $GLOBALS['_E107']['minimal'] = true;
// lame but quick - allow online when ajax request only, additonal checks are made in e_online class
if(e_AJAX_REQUEST && !isset($GLOBALS['_E107']['online']) && !isset($GLOBALS['_E107']['minimal'])) unset($_e107vars[1]);
diff --git a/e107_plugins/log/consolidate.php b/e107_plugins/log/consolidate.php
index c17b46faa..148605b21 100644
--- a/e107_plugins/log/consolidate.php
+++ b/e107_plugins/log/consolidate.php
@@ -20,31 +20,30 @@
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)
+$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";
+$pfileprev = "logp_".$yesterday.".php"; // Yesterday's log file
+$pfile = "logp_".$date.".php"; // Today's log file
+$ifileprev = "logi_".$yesterday.".php";
+$ifile = "logi_".$date.".php";
-if(file_exists($pathtologs.$pfile))
+if(file_exists($pathtologs.$pfile)) /* log file is up to date, no consolidation required */
{
- /* 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 ... */
+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 ... */
+ {
createLog($pathtologs);
return FALSE;
}
- // ... if we've got files
- list($pfileprev,$ifileprev,$date2,$tstamp) = explode('|',$retvalue);
+
+ list($pfileprev,$ifileprev,$date2,$tstamp) = explode('|',$retvalue); // ... if we've got files
}
@@ -63,10 +62,10 @@ $qry .= ")";
/* log file is out of date - consolidation required */
/* get existing stats ... */
-//if($sql -> db_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 -> db_Select("logstats", "*", $qry))
+//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 -> db_Fetch())
+ while($row = $sql->fetch())
{
if($row['log_id'] == "statUnique")
{
@@ -90,20 +89,21 @@ if($sql -> db_Select("logstats", "*", $qry))
else
{
// this must be the first time a consolidation has happened - this will only ever happen once ...
- $sql -> db_Insert("logstats", "0, 'statBrowser', ''");
- $sql -> db_Insert("logstats", "0, 'statOs', ''");
- $sql -> db_Insert("logstats", "0, 'statScreen', ''");
- $sql -> db_Insert("logstats", "0, 'statDomain', ''");
- $sql -> db_Insert("logstats", "0, 'statReferer', ''");
- $sql -> db_Insert("logstats", "0, 'statQuery', ''");
- $sql -> db_Insert("logstats", "0, 'statTotal', '0'");
- $sql -> db_Insert("logstats", "0, 'statUnique', '0'");
- $statBrowser =array();
- $statOs =array();
- $statScreen =array();
- $statDomain =array();
- $statReferer =array();
- $statQuery =array();
+ $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();
}
@@ -160,25 +160,25 @@ foreach($searchInfo as $name => $amount)
$mon_statQuery[$name] += $amount;
}
-$browser = serialize($statBrowser);
-$os = serialize($statOs);
-$screen = serialize($statScreen);
-$domain = serialize($statDomain);
-$refer = serialize($statReferer);
-$squery = serialize($statQuery);
+$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 -> db_Update("logstats", "log_data='{$browser}' WHERE log_id='statBrowser'");
-$sql -> db_Update("logstats", "log_data='{$os}' WHERE log_id='statOs'");
-$sql -> db_Update("logstats", "log_data='{$screen}' WHERE log_id='statScreen'");
-$sql -> db_Update("logstats", "log_data='{$domain}' WHERE log_id='statDomain'");
-$sql -> db_Update("logstats", "log_data='{$refer}' WHERE log_id='statReferer'");
-$sql -> db_Update("logstats", "log_data='{$squery}' WHERE log_id='statQuery'");
-$sql -> db_Update("logstats", "log_data='".intval($statTotal)."' WHERE log_id='statTotal'");
-$sql -> db_Update("logstats", "log_data='".intval($statUnique)."' WHERE log_id='statUnique'");
+$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
@@ -189,9 +189,10 @@ foreach ($stats_list as $s)
$srcvar = 'mon_'.$s;
$destvar = 'smon_'.$s;
$$destvar = serialize($$srcvar);
- if (!$sql -> db_Update("logstats", "log_data='".$$destvar."' WHERE log_id='".$s.":".$date3."'"))
+
+ if (!$sql->update("logstats", "log_data='".$$destvar."' WHERE log_id='".$s.":".$date3."'"))
{
- $sql -> db_Insert("logstats", "0, '".$s.":".$date3."', '".$$destvar."'");
+ $sql->insert("logstats", "0, '".$s.":".$date3."', '".$$destvar."'");
}
}
}
@@ -199,9 +200,9 @@ foreach ($stats_list as $s)
/* get page access monthly info from db */
-if($sql -> db_Select("logstats", "*", "log_id='{$date3}' "))
+if($sql->select("logstats", "*", "log_id='{$date3}' "))
{
- $tmp = $sql -> db_Fetch();
+ $tmp = $sql->fetch();
$monthlyInfo = unserialize($tmp['log_data']);
unset($tmp);
$MonthlyExistsFlag = TRUE;
@@ -219,18 +220,18 @@ $monthlyinfo = serialize($monthlyInfo);
if($MonthlyExistsFlag)
{
- $sql -> db_Update("logstats", "log_data='{$monthlyinfo}' WHERE log_id='{$date3}'");
+ $sql->update("logstats", "log_data='{$monthlyinfo}' WHERE log_id='{$date3}'");
}
else
{
- $sql->db_Insert("logstats", "0, '{$date3}', '{$monthlyinfo}'");
+ $sql->insert("logstats", "0, '{$date3}', '{$monthlyinfo}'");
}
/* collate page total information */
-if($sql -> db_Select("logstats", "*", "log_id='pageTotal' "))
+if($sql->select("logstats", "*", "log_id='pageTotal' "))
{
- $tmp = $sql -> db_Fetch();
+ $tmp = $sql->fetch();
$pageTotal = unserialize($tmp['log_data']);
unset($tmp);
}
@@ -248,9 +249,9 @@ foreach($pageInfo as $key => $info)
$pagetotal = serialize($pageTotal);
-if(!$sql -> db_Update("logstats", "log_data='{$pagetotal}' WHERE log_id='pageTotal' "))
+if(!$sql->update("logstats", "log_data='{$pagetotal}' WHERE log_id='pageTotal' "))
{
- $sql -> db_Insert("logstats", "0, 'pageTotal', '{$pagetotal}' ");
+ $sql->insert("logstats", "0, 'pageTotal', '{$pagetotal}' ");
}
@@ -267,7 +268,7 @@ foreach($pageInfo as $key => $value)
}
$data = $dailytotal.chr(1).$uniquetotal.chr(1) . $data;
-$sql -> db_Insert("logstats", "0, '$date2', '".$tp -> toDB($data, true)."'");
+$sql->insert("logstats", "0, '$date2', '".$tp -> toDB($data, true)."'");
/* ok, we're finished with the log file now, we can empty it ... */
diff --git a/e107_plugins/log/e_meta.php b/e107_plugins/log/e_meta.php
index ede383e21..32823135d 100644
--- a/e107_plugins/log/e_meta.php
+++ b/e107_plugins/log/e_meta.php
@@ -17,11 +17,12 @@ if (!defined('e107_INIT')) { exit; }
if (vartrue($pref['statActivate']))
{
- if(!$pref['statCountAdmin'] && ADMIN)
+
+ if(!$pref['statCountAdmin'] && ADMIN) // don't count admin visits
{
- /* don't count admin visits */
return;
}
+
// Page to log here
if(USER_AREA)
@@ -34,6 +35,7 @@ if (vartrue($pref['statActivate']))
if (is_numeric(e_QUERY)) $err_flag .= '/'.substr(e_QUERY,0,10); // This should pick up the error code - and limit numeric length to upset the malicious
$err_flag .= "&err_referer=".$_SERVER['HTTP_REFERER'];
}
+
}
/*
$logJS = "
@@ -107,8 +109,11 @@ $(function() {
type: 'get',
url: url,
data: {'lv' :logString},
- success: function() {
- //alert(logString);
+ success: function(e) {
+ if(e)
+ {
+ alert(e);
+ }
}
});
});
@@ -118,8 +123,7 @@ $(function() {
if(USER_AREA)
{
- $e107 = e107::getInstance();
- $e107->getJs()->headerInline($logJS, 5);
+ e107::js('footer-inline', $logJS, 'jquery');
}
}
diff --git a/e107_plugins/log/log.php b/e107_plugins/log/log.php
index c5d0e03bd..0281355a5 100644
--- a/e107_plugins/log/log.php
+++ b/e107_plugins/log/log.php
@@ -2,15 +2,12 @@
/*
* e107 website system
*
-* Copyright 2001-2010 e107 Inc (e107.org)
+* Copyright 2001-2013 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* Site access logging - 'receiver'
-*
-* $URL$
-* $Id$
-*
+
*/
/* File to log page accesses - called with
@@ -26,13 +23,22 @@
// Normally the file is 'silent' - if any errors occur, any error message appears in the page header.
*/
//error_reporting(0);
-error_reporting(E_ALL);
+// error_reporting(E_ALL);
+define('e_MINIMAL',true);
+require_once("../../class2.php"); // More secure to include it.
+header('Cache-Control: no-cache, must-revalidate'); // See if this discourages browser caching
+header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
+if (!vartrue($pref['statActivate']))
+{
+ exit();
+}
/**
* Set up path to log files.
* The log file directory contains a flag file which defines whether logging is enabled.
*/
+ /*
function setLogPath()
{
$siteRoot = realpath(dirname(__FILE__).'./../../').'/';
@@ -47,10 +53,10 @@ function setLogPath()
define('e_LOG', $logDir);
return $logEnable;
}
+*/
-
-if (!setLogPath()) exit(); // Could be logging disabled, missing files, all sorts of things. Just do nothing.
-
+// if (!setLogPath()) exit(); // Could be logging disabled, missing files, all sorts of things. Just do nothing.
+//print_r(base64_decode($_GET['lv']));
define('log_INIT', TRUE);
@@ -64,35 +70,31 @@ $pageUnique = array('page' => 1, 'content' => array('content'));
//$logVals = urldecode(base64_decode($_SERVER['QUERY_STRING']));
$logVals = urldecode(base64_decode($_GET['lv']));
-
-//file_put_contents(e_LOG."test.log",print_r($logVals,true)); // , FILE_APPEND | LOCK_EX
+$lg = e107::getAdminLog();
+$lg->addDebug(print_r($logVals, true));
+$lg->toFile('SiteStats','Statistics Log', true);
parse_str($logVals, $vals);
// We MUST have a timezone set in PHP >= 5.3. This should work for PHP >= 5.1:
// @todo may be able to remove this check once minimum PHP version finalised
-if (function_exists('date_default_timezone_get'))
+if (function_exists('date_default_timezone_get'))
{
- // Just set a default - it should default to UTC if no timezone set
- date_default_timezone_set(@date_default_timezone_get());
+ date_default_timezone_set(@date_default_timezone_get()); // Just set a default - it should default to UTC if no timezone set
}
-header('Cache-Control: no-cache, must-revalidate'); // See if this discourages browser caching
-header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
-
//$logfp = fopen(e_LOG.'rcvstring.txt', 'a+'); fwrite($logfp, $logVals."\n"); fclose($logfp);
//$logfp = fopen(e_LOG.'rcvstring.txt', 'a+'); fwrite($logfp, print_r($vals, TRUE)."\n"); fclose($logfp);
-$colour = strip_tags((isset($vals['colour']) ? $vals['colour'] : ''));
-$res = strip_tags((isset($vals['res']) ? $vals['res'] : ''));
-$self = strip_tags((isset($vals['eself']) ? $vals['eself'] : ''));
-$ref = addslashes(strip_tags((isset($vals['referer']) ? $vals['referer'] : '')));
-$logQry = isset($vals['qry']) && $vals['qry'];
-
-$date = date('z.Y', time());
-$logPfile = e_LOG.'logp_'.$date.'.php';
+$colour = strip_tags((isset($vals['colour']) ? $vals['colour'] : ''));
+$res = strip_tags((isset($vals['res']) ? $vals['res'] : ''));
+$self = strip_tags((isset($vals['eself']) ? $vals['eself'] : ''));
+$ref = addslashes(strip_tags((isset($vals['referer']) ? $vals['referer'] : '')));
+$logQry = isset($vals['qry']) && $vals['qry'];
+$date = date('z.Y', time());
+$logPfile = e_LOG.'logp_'.$date.'.php';
//$logString = "Colour: {$colour} Res: {$res} Self: {$self} Referrer: {$ref} ErrCode: {$vals['err_direct']}\n";
//$logfp = fopen(e_LOG.'rcvstring.txt', 'a+'); fwrite($logfp, $logString); fclose($logfp);
@@ -171,16 +173,19 @@ $p_handle = fopen($logPfile, 'r+');
if($p_handle && flock( $p_handle, LOCK_EX ) )
{
$log_file_contents = '';
- while (!feof($p_handle))
- { // Assemble a string of data
+ while (!feof($p_handle)) // Assemble a string of data
+ {
$log_file_contents.= fgets($p_handle,1000);
}
$log_file_contents = str_replace(array('<'.'?php','?'.'>'),'',$log_file_contents);
- if (eval($log_file_contents) === FALSE) echo "error in log file contents
";
+ if (eval($log_file_contents) === FALSE && getperms('0'))
+ {
+ echo "Error in log file contents: ".$logPfile;
+ }
}
-else
+elseif(getperms('0'))
{
- echo "Couldn't log data
";
+ echo "Couldn't log data to: ".$logPfile; // returned to js popup.
exit;
}
@@ -236,6 +241,7 @@ if ($p_handle)
// Get current IP address - return as a hex-encoded string
+/*
function getip()
{
$ip = $_SERVER['REMOTE_ADDR'];
@@ -293,6 +299,6 @@ function getip()
return $ret;
}
}
-
+*/
?>
\ No newline at end of file
diff --git a/e107_plugins/log/stats.php b/e107_plugins/log/stats.php
index 26856b7a4..326c8bba4 100644
--- a/e107_plugins/log/stats.php
+++ b/e107_plugins/log/stats.php
@@ -713,7 +713,7 @@ class siteStats
$this -> fileRecent = vartrue($visitInfo);
/* get main stat info from database */
- if($sql -> db_Select('logstats', 'log_data', "log_id='pageTotal'"))
+ if($sql->select('logstats', 'log_data', "log_id='pageTotal'"))
{
$row = $sql -> db_Fetch();
$this -> dbPageInfo = unserialize($row['log_data']);
@@ -881,7 +881,7 @@ class siteStats
$sql = e107::getDB();
$text = '';
- $sql -> db_Select("logstats", "*", "log_id='pageTotal' ");
+ $sql->select("logstats", "*", "log_id='pageTotal' ");
$row = $sql -> db_Fetch();
$pageTotal = unserialize($row['log_data']);
$total = 0;
@@ -917,8 +917,12 @@ class siteStats
".ADSTAT_L18." | -Information | +".ADSTAT_L18." | +Information | ".ADSTAT_L34." | \n"; - foreach($monthTotal as $date => $total) { - + foreach($monthTotal as $date => $total) + { list($year, $month) = explode("-", $date); $date = strftime ("%B %Y", mktime (0,0,0,$month,1,$year)); $barWidth = round(($total['totalv']/$mtotal) * 100, 2); @@ -1910,7 +1915,8 @@ class siteStats".ADSTAT_L34." | \n"; - foreach($monthTotal as $date => $total) { + foreach($monthTotal as $date => $total) + { $barWidth = round(($total['uniquev']/$utotal) * 100, 2); list($year, $month) = explode("-", $date); $date = strftime ("%B %Y", mktime (0,0,0,$month,1,$year)); @@ -1997,7 +2003,7 @@ class siteStats function remove_entry($toremove) { // Note - only removes info from the database - not from the current page file $sql = e107::getDB(); - if ($sql -> db_Select("logstats", "*", "log_id='pageTotal'")) + if ($sql->select("logstats", "*", "log_id='pageTotal'")) { $row = $sql -> db_Fetch(); $dbPageInfo = unserialize($row[2]);
---|