diff --git a/e107_plugins/log/admin_config.php b/e107_plugins/log/admin_config.php index ccd256012..c0a335392 100644 --- a/e107_plugins/log/admin_config.php +++ b/e107_plugins/log/admin_config.php @@ -11,23 +11,23 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/log/admin_config.php,v $ -| $Revision: 1.1.1.1 $ -| $Date: 2006-12-02 04:35:27 $ -| $Author: mcfly_e107 $ +| $Revision: 1.2 $ +| $Date: 2007-11-01 20:28:20 $ +| $Author: e107steved $ +----------------------------------------------------------------------------+ + +To do: +1. Admin log for changes */ + + require_once("../../class2.php"); -if (!getperms("P")) { +if (!getperms("P")) +{ header("location:../index.php"); exit; } -if (isset($_POST['updateStats'])) -{ - header("location: ".e_PLUGIN."log/admin_updateroutine.php"); - exit; -} - require_once(e_ADMIN."auth.php"); require_once(e_HANDLER."userclass_class.php"); @@ -35,17 +35,122 @@ define("LOGPATH", e_PLUGIN."log/"); include_lan(LOGPATH."languages/admin/".e_LANGUAGE.".php"); +if (e_QUERY) +{ + $sl_qs = explode(".", e_QUERY); +} +$action = varset($sl_qs[0],'config'); +$params = varset($sl_qs[1],''); + +// 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'=>ADSTAT_L6,'statOs'=>ADSTAT_L7,'statScreen'=>ADSTAT_L8,'statDomain'=>ADSTAT_L9,'statReferer'=>ADSTAT_L10,'statQuery'=>ADSTAT_L11); + +$separator_list = array(1 => ADSTAT_L57, 2 => ADSTAT_L58); +$separator_char = array(1 => ',', 2 => '|'); +$quote_list = array(1 => ADSTAT_L50, 2 => ADSTAT_L55, 3 => ADSTAT_L56); +$quote_char = array(1 => '', 2 => "'", 3 => '"'); + + +//--------------------------------------------- +// Export data file +//--------------------------------------------- +$export_filter = ''; // can be 'LIKE', 'REGEX', or simple equality +$export_type = $tp->toDB(varset($_POST['export_type'],'page')); // Page data or one of the other bits of info +$export_date = intval(varset($_POST['export_date'],1)); +$export2_date = intval(varset($_POST['export2_date'],3)); +$export_year = intval(varset($_POST['export_year'],date('Y'))); +$export_month = intval(varset($_POST['export_month'],date('m'))); +$export_day = intval(varset($_POST['export_day'],date('j'))); +$export_char = varset($_POST['export_char'], 1); +$export_quote = varset($_POST['export_quote'], 1); +$export_stripurl = varset($_POST['export_stripurl'], 0); + +if (isset($_POST['create_export']) && (($action == 'export') || ($action == 'datasets'))) +{ + $first_date = 0; + $last_date = 0; + $date_error = FALSE; + if ($export_type == 'page') + { + switch ($export_date) + { + case '1' : // Single day + $first_date = gmmktime(0,0,0,$export_month,$export_day,$export_year); + $last_date = $first_date+86399; + $export_filter = " `log_id`='".date("Y-m-j",$first_date)."'"; + break; + case '2' : // Daily for a month + $first_date = gmmktime(0,0,0,$export_month,1,$export_year); + $last_date = gmmktime(0,0,0,$export_month+1,1,$export_year) - 1; + $export_filter = " LEFT(`log_id`,8)='".gmstrftime("%Y-%m-",$first_date)."'"; + break; + case '3' : // Monthly for a Year + $first_date = gmmktime(0,0,0,1,1,$export_year); + $last_date = gmmktime(0,0,0,1,1,$export_year+1) - 1; + $export_filter = " LENGTH(`log_id`)=7 AND LEFT(`log_id`,5)='".gmstrftime("%Y-",$first_date)."'"; + break; + case '4' : // Accumulated + case '5' : + $export_filter = "`log_id`='pageTotal'"; + $date_error = 'ignore'; + break; + } + } + else + { // Calculate strings for non-page sources + $prefix_len = 0; + $export_date = $export2_date; + if (isset($stats_list[$export_type])) + { + $prefix_len = strlen($export_type) + 1; + switch ($export2_date) + { + case '3' : // Monthly for a Year + if ($prefix_len > 0) + { + $first_date = gmmktime(0,0,0,1,1,$export_year); + $last_date = gmmktime(0,0,0,1,1,$export_year+1) - 1; + $export_filter = " LENGTH(`log_id`)='".($prefix_len + 7)."' AND LEFT(`log_id`,".($prefix_len + 5).")='".$export_type.":".gmstrftime("%Y-",$first_date)."'"; + } + break; + case '4' : // Accumulated + $export_filter = " `log_id`='".$export_type."'"; + $date_error = 'ignore'; + break; + } + } + else + { + $message = ADSTAT_L54; + } + } + if (($date_error != 'ignore') && (($first_date == 0) || ($last_date == 0) || $date_error)) + { + $message = ADSTAT_L47; + } +} + + + +//--------------------------------------------- +// Remove page entries +//--------------------------------------------- if(isset($_POST['openRemPageD'])) { - rempage(); + $action = 'rempage'; } + if(isset($_POST['remSelP'])) { - rempagego(); + $action = 'rempage'; + rempagego(); // Do the deletions - then redisplay the list of pages } +//--------------------------------------------- +// Wipe accumulated stats +//--------------------------------------------- if(IsSet($_POST['wipeSubmit'])) { foreach($_POST['wipe'] as $key => $wipe) @@ -82,92 +187,110 @@ if(IsSet($_POST['wipeSubmit'])) -if(!is_writable(LOGPATH."logs")) { - $message = "You must set the permissions of the e107_plugins/log/logs folder to 777 (chmod 777)"; +if(!is_writable(LOGPATH."logs")) +{ + $message = "".ADSTAT_L38.""; } -if (isset($_POST['updatesettings'])) { - $pref['statActivate'] = $_POST['statActivate']; +if (isset($_POST['updatesettings'])) +{ + $pref['statActivate'] = $_POST['statActivate']; $pref['statCountAdmin'] = $_POST['statCountAdmin']; - $pref['statUserclass'] = $_POST['statUserclass']; - $pref['statBrowser'] = $_POST['statBrowser']; - $pref['statOs'] = $_POST['statOs']; - $pref['statScreen'] = $_POST['statScreen']; - $pref['statDomain'] = $_POST['statDomain']; - $pref['statRefer'] = $_POST['statRefer']; - $pref['statQuery'] = $_POST['statQuery']; - $pref['statRecent'] = $_POST['statRecent']; + $pref['statUserclass'] = $_POST['statUserclass']; + $pref['statBrowser'] = intval($_POST['statBrowser']); + $pref['statOs'] = intval($_POST['statOs']); + $pref['statScreen'] = intval($_POST['statScreen']); + $pref['statDomain'] = intval($_POST['statDomain']); + $pref['statRefer'] = intval($_POST['statRefer']); + $pref['statQuery'] = intval($_POST['statQuery']); + $pref['statRecent'] = intval($_POST['statRecent']); $pref['statDisplayNumber'] = $_POST['statDisplayNumber']; + $pref['statPrevMonth'] = intval($_POST['statPrevMonth']); save_prefs(); $message = ADSTAT_L17; } -if (isset($message)) { - $ns->tablerender("", "
".$message."
"); +if (isset($message)) +{ + $ns->tablerender("", "
".$message."
"); } -$text = "
+ +function gen_select($prompt,$name,$value) +{ + $ret = "
".$prompt."  "."\n
"; + return $ret; +} + + +function data_type_select($name,$value) +{ + global $stats_list; + $ret = "\n"; + return $ret; +} + + +switch ($action) +{ + case 'config' : + $text = "
+ + + + - - + - - + + - - + - - + - - - + - - + + + + + - - + - "; $text .= " - - - - + - + "; } @@ -273,6 +742,9 @@ function rempage() } +//--------------------------------------------- +// Remove page entries - action +//--------------------------------------------- function rempagego() { global $sql; @@ -326,11 +798,41 @@ function rempagego() $data .= "\n);\n\n?". chr(62); - if ($handle = fopen($logfile, 'w')) { - fwrite($handle, $data); + if ($handle = fopen($logfile, 'w')) + { + fwrite($handle, $data); } fclose($handle); - - } + + + +function admin_config_adminmenu() +{ + if (e_QUERY) + { + $tmp = explode(".", e_QUERY); + $action = $tmp[0]; + } + if (!isset($action) || ($action == "")) $action = "config"; + + $var['config']['text'] = ADSTAT_L35; + $var['config']['link'] = 'admin_config.php'; + + $var['export']['text'] = ADSTAT_L36; + $var['export']['link'] ='admin_config.php?export'; + +// $var['datasets']['text'] = ADSTAT_L63; +// $var['datasets']['link'] ='admin_config.php?datasets'; + + $var['rempage']['text'] = ADSTAT_L26; + $var['rempage']['link'] ='admin_config.php?rempage'; + + $var['history']['text'] = ADSTAT_L69; + $var['history']['link'] ='admin_config.php?history'; + + show_admin_menu(ADSTAT_L39, $action, $var); +} + + ?> diff --git a/e107_plugins/log/consolidate.php b/e107_plugins/log/consolidate.php index e10c6d955..24f218d72 100644 --- a/e107_plugins/log/consolidate.php +++ b/e107_plugins/log/consolidate.php @@ -11,18 +11,19 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/log/consolidate.php,v $ -| $Revision: 1.9 $ -| $Date: 2007-02-10 15:54:47 $ +| $Revision: 1.10 $ +| $Date: 2007-11-01 20:28:21 $ | $Author: e107steved $ +----------------------------------------------------------------------------+ */ /* first thing to do is check if the log file is out of date ... */ + $pathtologs = e_PLUGIN."log/logs/"; $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"); // Current month's date for monthly 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 @@ -38,7 +39,7 @@ 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("blank"); + createLog($pathtologs); return FALSE; } // ... if we've got files @@ -47,19 +48,47 @@ else if(!file_exists($pathtologs.$pfileprev)) +// 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 -> 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'")) { - $infoArray = array(); +//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)) +{ // That's read in all the stats we need to modify while($row = $sql -> db_Fetch()) { - $$row[1] = unserialize($row[2]); // $row[1] is the stats type - save in a variable - if($row[1] == "statUnique") $statUnique = $row[2]; - if($row[1] == "statTotal") $statTotal = $row[2]; + 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 ... */ +} +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', ''"); @@ -76,36 +105,58 @@ if($sql -> db_Select("logstats", "*", "log_id='statBrowser' OR log_id='statOs' O $statQuery =array(); } -require_once($pathtologs.$pfileprev); -require_once($pathtologs.$ifileprev); -foreach($browserInfo as $name => $amount) { +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) { +foreach($osInfo as $name => $amount) +{ $statOs[$name] += $amount; + $mon_statOs[$name] += $amount; } -foreach($screenInfo as $name => $amount) { +foreach($screenInfo as $name => $amount) +{ $statScreen[$name] += $amount; + $mon_statScreen[$name] += $amount; } -foreach($domainInfo as $name => $amount) { - if(!is_numeric($name)) { +foreach($domainInfo as $name => $amount) +{ + if(!is_numeric($name)) + { $statDomain[$name] += $amount; + $mon_statDomain[$name] += $amount; } } -foreach($refInfo as $name => $info) { +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) { +foreach($searchInfo as $name => $amount) +{ $statQuery[$name] += $amount; + $mon_statQuery[$name] += $amount; } $browser = serialize($statBrowser); @@ -118,18 +169,37 @@ $squery = serialize($statQuery); $statTotal += $siteTotal; $statUnique += $siteUnique; -$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'"); +// 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'"); -/* get monthly info from db */ -if($sql -> db_Select("logstats", "*", "log_id='$date3' ")) { +// 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 -> db_Update("logstats", "log_data='".$$destvar."' WHERE log_id='".$s.":".$date3."'")) + { + $sql -> db_Insert("logstats", "0, '".$s.":".$date3."', '".$$destvar."'"); + } + } +} + + + +/* get page access monthly info from db */ +if($sql -> db_Select("logstats", "*", "log_id='{$date3}' ")) +{ $tmp = $sql -> db_Fetch(); $monthlyInfo = unserialize($tmp['log_data']); unset($tmp); @@ -146,10 +216,13 @@ foreach($pageInfo as $key => $info) $monthlyinfo = serialize($monthlyInfo); -if($MonthlyExistsFlag) { - $sql -> db_Update("logstats", "log_data='$monthlyinfo' WHERE log_id='$date3'"); -} else { - $sql->db_Insert("logstats", "0, '$date3', '$monthlyinfo'"); +if($MonthlyExistsFlag) +{ + $sql -> db_Update("logstats", "log_data='{$monthlyinfo}' WHERE log_id='{$date3}'"); +} +else +{ + $sql->db_Insert("logstats", "0, '{$date3}', '{$monthlyinfo}'"); } @@ -174,9 +247,9 @@ foreach($pageInfo as $key => $info) $pagetotal = serialize($pageTotal); -if(!$sql -> db_Update("logstats", "log_data='$pagetotal' WHERE log_id='pageTotal' ")) +if(!$sql -> db_Update("logstats", "log_data='{$pagetotal}' WHERE log_id='pageTotal' ")) { - $sql -> db_Insert("logstats", "0, 'pageTotal', '$pagetotal' "); + $sql -> db_Insert("logstats", "0, 'pageTotal', '{$pagetotal}' "); } @@ -215,16 +288,17 @@ if(!unlink($pathtologs.$ifileprev)) } /* and finally, we need to create new logfiles for today ... */ -createLog(); +createLog($pathtologs); /* done! */ -function createLog($mode="default") +function createLog($pathtologs) { - global $pathtologs, $statTotal, $statUnique, $pfile, $ifile; + global $statTotal, $statUnique, $pfile, $ifile; if(!is_writable($pathtologs)) { echo "Log directory is not writable - please CHMOD ".e_PLUGIN."log/logs to 777"; + echo '
Path to logs: '.$pathtologs; return FALSE; } diff --git a/e107_plugins/log/languages/English.php b/e107_plugins/log/languages/English.php index b080a600b..0ccea04dd 100644 --- a/e107_plugins/log/languages/English.php +++ b/e107_plugins/log/languages/English.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/log/languages/English.php,v $ -| $Revision: 1.3 $ -| $Date: 2007-08-14 19:27:22 $ +| $Revision: 1.4 $ +| $Date: 2007-11-01 20:28:22 $ | $Author: e107steved $ +----------------------------------------------------------------------------+ */ @@ -43,7 +43,7 @@ define("ADSTAT_L21", "Total"); define("ADSTAT_L22", "Unique"); define("ADSTAT_L23", "Total Visits"); define("ADSTAT_L24", "Total Unique Visits"); -define("ADSTAT_L25", "No statistics yet."); +define("ADSTAT_L25", "No statistics available."); define("ADSTAT_L26", "Browser"); define("ADSTAT_L27", "Operating System"); define("ADSTAT_L28", "Countries / Domains"); @@ -67,8 +67,18 @@ define("ADSTAT_L44", "All-time page errors"); define("ADSTAT_L45", "Stats deleted for: "); define("ADSTAT_L46", "Note: any stats for today will not be deleted"); define("ADSTAT_L47", "No stats found for: "); -define("ADSTAT_L48", ""); -define("ADSTAT_L49", ""); -define("ADSTAT_L50", ""); +define("ADSTAT_L48", "sort by total"); +define("ADSTAT_L49", "sort alphabetically"); +define("ADSTAT_L50", "All-time stats"); +define("ADSTAT_L51", "Current month stats"); +define("ADSTAT_L52", "Previous month stats"); +define("ADSTAT_L53", ""); +define("ADSTAT_L54", ""); +define("ADSTAT_L55", ""); +define("ADSTAT_L56", ""); +define("ADSTAT_L57", ""); +define("ADSTAT_L58", ""); +define("ADSTAT_L59", ""); +define("ADSTAT_L60", ""); ?> \ No newline at end of file diff --git a/e107_plugins/log/languages/admin/English.php b/e107_plugins/log/languages/admin/English.php index ba949ea14..34c8d0301 100644 --- a/e107_plugins/log/languages/admin/English.php +++ b/e107_plugins/log/languages/admin/English.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/log/languages/admin/English.php,v $ -| $Revision: 1.3 $ -| $Date: 2007-05-30 20:49:13 $ +| $Revision: 1.4 $ +| $Date: 2007-11-01 20:28:22 $ | $Author: e107steved $ +----------------------------------------------------------------------------+ */ @@ -31,7 +31,7 @@ define("ADSTAT_L9", "Countries/domains visited from"); define("ADSTAT_L10", "Referrers"); define("ADSTAT_L11", "Search queries"); define("ADSTAT_L12", "Reset stats"); -define("ADSTAT_L13", "this will erase stats - careful!"); +define("ADSTAT_L13", "this will erase the all-time stats - careful!
There is a separate menu option to delete selected historical data"); define("ADSTAT_L14", "Page counts"); define("ADSTAT_L15", "Update Statistic Settings"); define("ADSTAT_L16", "Site Statistic Settings"); @@ -53,6 +53,52 @@ define("ADSTAT_L31", "Remove selected pages"); define("ADSTAT_L32", "Page Tidy"); define("ADSTAT_L33", "Configure Statistics Logging"); define("ADSTAT_L34", "Site Stats"); +define ('ADSTAT_L35', 'Options'); +define ('ADSTAT_L36', 'Data Export'); +define ('ADSTAT_L37', 'Create export file'); +define ('ADSTAT_L38', "You must set the permissions of the e107_plugins/log/logs folder to 777 (chmod 777)"); +define ('ADSTAT_L39', 'Stats Logging Functions'); +define ('ADSTAT_L40', 'Export log data'); +define ('ADSTAT_L41', 'Date selection'); +define ('ADSTAT_L42', 'Single Day'); +define ('ADSTAT_L43', 'Daily for a month'); +define ('ADSTAT_L44', 'Monthly for a year'); +define ('ADSTAT_L45', 'All-time'); +define ('ADSTAT_L46', 'Date:'); +define ('ADSTAT_L47', 'Invalid date chosen'); +define ('ADSTAT_L48', 'Monthly and All-time'); +define ('ADSTAT_L49', 'All-time Only'); +define ('ADSTAT_L50', 'None'); +define ('ADSTAT_L51', 'Output Data'); +define ('ADSTAT_L52', 'Page Data'); +define ('ADSTAT_L53', 'No selection possible'); +define ('ADSTAT_L54', 'Invalid type selection'); +define ('ADSTAT_L55', 'Single quote'); +define ('ADSTAT_L56', 'Double quote'); +define ('ADSTAT_L57', 'Comma'); +define ('ADSTAT_L58', 'Pipe (|)'); +define ('ADSTAT_L59', 'CSV separator, quotes'); +define ('ADSTAT_L60', 'Strip site address from URLs'); +define ('ADSTAT_L61', '(if checked, just gives page reference)'); +define ('ADSTAT_L62', 'All-time (detailed)'); +define ('ADSTAT_L63', 'Available Datasets'); +define ('ADSTAT_L64', 'Database records found:'); +define ('ADSTAT_L65', 'DB filter string:'); +define ('ADSTAT_L66', 'Show Datasets'); +define ('ADSTAT_L67', 'Generate a CSV (Comma Separated Variable) file of historical statistics which meets the specified criteria'); +define ('ADSTAT_L68', 'Show the statistics database entries which actually exist and meet the selection criteria'); +define ('ADSTAT_L69', 'Delete historical data'); +define ('ADSTAT_L70', 'Delete data older than:'); +define ('ADSTAT_L71', 'Delete Data'); +define ('ADSTAT_L72', 'Confirm deletion of data older than first day of:'); +define ('ADSTAT_L73', 'Confirm'); +define ('ADSTAT_L74', '(List of data entries which will be deleted below)'); +define ('ADSTAT_L75', 'Records for deletion'); +define ('ADSTAT_L76', 'Caution! Once deleted, the data cannot be recovered. Backup or export your database first'); +define ('ADSTAT_L77', 'Records deleted:'); +define ('ADSTAT_L78', 'Show previous month as well as current month for non-page access stats'); +define ('ADSTAT_L79', '(Only used if monthly stats collected)'); +define ('ADSTAT_L80', ''); ?> \ No newline at end of file diff --git a/e107_plugins/log/log.php b/e107_plugins/log/log.php index 69f63d716..898c62907 100644 --- a/e107_plugins/log/log.php +++ b/e107_plugins/log/log.php @@ -10,11 +10,9 @@ | Released under the terms and conditions of the | GNU General Public License (http://gnu.org). | -| File locking, modified getip() 18.01.07 -| | $Source: /cvs_backup/e107_0.8/e107_plugins/log/log.php,v $ -| $Revision: 1.3 $ -| $Date: 2007-08-14 19:27:22 $ +| $Revision: 1.4 $ +| $Date: 2007-11-01 20:28:21 $ | $Author: e107steved $ +----------------------------------------------------------------------------+ */ @@ -25,27 +23,12 @@ // color= colord // eself= eself // res= res -// err_direct - optional error flag -// err_referer - referrer if came via error page define("log_INIT", TRUE); - - $colour = strip_tags((isset($_REQUEST['color']) ? $_REQUEST['color'] : '')); $res = strip_tags((isset($_REQUEST['res']) ? $_REQUEST['res'] : '')); $self = strip_tags((isset($_REQUEST['eself']) ? $_REQUEST['eself'] : '')); $ref = addslashes(strip_tags((isset($_REQUEST['referer']) ? $_REQUEST['referer'] : ''))); $date = date("z.Y", time()); -$logPfile = "logs/logp_".$date.".php"; - -if ($err_code = strip_tags((isset($_REQUEST['err_direct']) ? $_REQUEST['err_direct'] : ''))) -{ - $ref = addslashes(strip_tags(isset($_REQUEST['err_referer']) ? $_REQUEST['err_referer'] : '')); - $log_string = $err_code.",".$self.",".$ref; -// Uncomment the next two lines to create a separate CSV format log of invalid accesses - error code, entered URL, referrer -// $logname = "logs/errpages.csv"; -// $logfp = fopen($logname, 'a+'); fwrite($logfp, $log_string."\n\r"); fclose($logfp); - $err_code .= ':'; -} if(strstr($ref, "admin")) { @@ -75,29 +58,24 @@ $pageName = substr($match[1], (strrpos($match[1], "/")+1)); $PN = $pageName; $pageName = preg_replace("/".$tagRemove."/si", "", $pageName); if($pageName == "") $pageName = "index"; - -$pageName = $err_code.$pageName; // Add the error code at the beginning, so its treated uniquely - if(preg_match("/".$pageDisallow."/i", $pageName)) return; -$p_handle = fopen($logPfile, 'r+'); -if($p_handle && flock( $p_handle, LOCK_EX ) ) +$logPfile = "logs/logp_".$date.".php"; +$handle = fopen($logPfile, 'r+'); +if($handle && flock( $handle, LOCK_EX ) ) { - $log_file_contents = ''; - 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



"; + $log_file_contents = get_file_contents($handle); + $log_file_contents = str_replace(array('<'.'?php','?>'),'',$log_file_contents); + if (eval($log_file_contents) === FALSE) echo "error in log file contents
"; } else { - echo "Couldn't log data



"; + echo "Couldn't log data
"; exit; } +//require_once($logPfile); $flag = FALSE; if(array_key_exists($pageName, $pageInfo)) @@ -139,12 +117,13 @@ $data = ""; -if ($p_handle) +if ($handle) { - ftruncate( $p_handle, 0 ); - fseek( $p_handle, 0 ); - fwrite($p_handle, $data); - fclose($p_handle); + ftruncate( $handle, 0 ); +// fwrite( $handle, $part_one ); +// sleep( 10 ); // for test purpose, assume the whole writing process takes 10 seconds + fwrite($handle, $data); + fclose($handle); } @@ -154,15 +133,16 @@ function getip($mode=TRUE) if (getenv('HTTP_X_FORWARDED_FOR')) { $ip = $_SERVER['REMOTE_ADDR']; - if (preg_match("#^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})#", getenv('HTTP_X_FORWARDED_FOR'), $ip3)) + // Shouldn't this be: "#((?:\d{1,3}\.){3}\d{1,3})#" or "#(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})#" + if (preg_match("/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/", getenv('HTTP_X_FORWARDED_FOR'), $ip3)) { - $ip2 = array('#^0\..*#', + $ip2 = array('#^0\..*#', '#^127\..*#', // Local loopbacks - '#^192\.168\..*#', // RFC1918 - Private Network - '#^172\.(?:1[6789]|2\d|3[01])\..*#', // RFC1918 - Private network - '#^10\..*#', // RFC1918 - Private Network + '#^192\.168\..*#', // Private Network + '#^172\.(?:1[6789]|2\d|3[01])\..*#', // Private network + '#^10\..*#', // Private Network '#^169\.254\..*#', // RFC3330 - Link-local, auto-DHCP - '#^2(?:2[456789]|[345][0-9])\..*#' // Single check for Class D and Class E + '#^2[45][0-9]\..*#' // Single check for Class D and Class E ); $ip = preg_replace($ip2, $ip, $ip3[1]); } diff --git a/e107_plugins/log/plugin.php b/e107_plugins/log/plugin.php index 9879bda45..f2414959a 100644 --- a/e107_plugins/log/plugin.php +++ b/e107_plugins/log/plugin.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/log/plugin.php,v $ -| $Revision: 1.3 $ -| $Date: 2007-05-30 20:49:13 $ +| $Revision: 1.4 $ +| $Date: 2007-11-01 20:28:21 $ | $Author: e107steved $ +----------------------------------------------------------------------------+ */ @@ -24,7 +24,7 @@ if (!defined('e107_INIT')) { exit; } // Plugin info ------------------------------------------------------------------------------------------------------- $eplug_name = ADSTAT_L3; -$eplug_version = "2.0"; +$eplug_version = "2.1"; $eplug_author = "jalist"; $eplug_url = "http://e107.org"; $eplug_email = "jalist@e107.org"; @@ -52,14 +52,14 @@ $eplug_prefTable = "menu_pref"; $eplug_prefs = array( "statActivate" => 0, "statUserclass" => "", - "statClass" => 0, "statBrowser" => 1, "statOs" => 1, "statScreen" => 1, "statDomain" => 1, "statRefer" => 1, "statQuery" => 1, - "statRecent" => 1 + "statRecent" => 1, + "statPrevMonth" => 0 ); // List of table names ----------------------------------------------------------------------------------------------- @@ -84,6 +84,9 @@ $eplug_link_url = e_PLUGIN."log/stats.php?1"; // Text to display after plugin successfully installed ------------------------------------------------------------------ $eplug_done = ADSTAT_L2; - + +$upgrade_add_prefs = array("statPrevMonth" => 0); +$upgrade_remove_prefs = array("statClass"); + ?> \ No newline at end of file diff --git a/e107_plugins/log/stats.php b/e107_plugins/log/stats.php index 8f1b63946..50b0d21d0 100644 --- a/e107_plugins/log/stats.php +++ b/e107_plugins/log/stats.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_plugins/log/stats.php,v $ -| $Revision: 1.4 $ -| $Date: 2007-08-14 19:27:22 $ +| $Revision: 1.5 $ +| $Date: 2007-11-01 20:28:21 $ | $Author: e107steved $ +----------------------------------------------------------------------------+ */ @@ -21,7 +21,6 @@ require_once("../../class2.php"); @include_once(e_PLUGIN."log/languages/".e_LANGUAGE.".php"); @include_once(e_PLUGIN."log/languages/English.php"); -$stat = new siteStats(); function core_head() { $bar = (file_exists(THEME."images/bar.png") ? THEME."images/bar.png" : e_IMAGE."generic/bar.png"); @@ -52,11 +51,13 @@ if (!$pref['statActivate']) { $qs = explode('.', e_QUERY, 3); $action = varset($qs[0],1); $sec_action = varset($qs[1],FALSE); -$order = varset($qs[2],0); +$order = varset($qs[1],0); // Sort order -$toremove = $order; +$toremove = varset($qs[2],''); $order = intval($order); +$stat = new siteStats(); + if($stat -> error) { $ns->tablerender(ADSTAT_L6, $stat -> error); @@ -393,6 +394,19 @@ $country["zw"] = "Zimbabwe"; 8: search engine strings */ +function display_pars($rec_pars, $disp_pars = '*') +{ + global $pref; + switch ($rec_pars) + { + case 1 : return array(1); + case 2 : if (varset($pref['statPrevMonth'],0)) return array(2,3,1); else return array(2,1); + case 3 : return array(2,3,1); + default : return array(); + } +} + + $text = ''; if ((ADMIN == TRUE) && ($sec_action == "rem")) { @@ -425,61 +439,83 @@ switch($action) if (ADMIN == TRUE) $text .= $stat -> renderAlltimeVisits(TRUE); break; - case 3: - if($pref['statBrowser']) { - $text .= $stat -> renderBrowsers(); - } else { + case 3 : + case 14 : + if($pref['statBrowser']) + { + $text .= $stat -> renderBrowsers(display_pars($pref['statBrowser']), $action==3); + } + else + { $text .= ADSTAT_L7; - } - break; + } + break; case 4: - if($pref['statOs']) { - $text .= $stat -> renderOses(); - } else { + if($pref['statOs']) + { + $text .= $stat -> renderOses(display_pars($pref['statOs'])); + } + else + { $text .= ADSTAT_L7; - } - break; + } + break; case 5: - if($pref['statDomain']) { - $text .= $stat -> renderDomains(); - } else { + if($pref['statDomain']) + { + $text .= $stat -> renderDomains(display_pars($pref['statDomain'])); + } + else + { $text .= ADSTAT_L7; - } - break; + } + break; case 6: - if($pref['statScreen']) { - $text .= $stat -> renderScreens(); - } else { + if($pref['statScreen']) + { + $text .= $stat -> renderScreens(display_pars($pref['statScreen'])); + } + else + { $text .= ADSTAT_L7; - } - break; + } + break; case 7: - if($pref['statRefer']) { - $text .= $stat -> renderRefers(); - } else { + if ($pref['statRefer']) + { + $text .= $stat -> renderRefers(display_pars($pref['statRefer'])); + } + else + { $text .= ADSTAT_L7; - } - break; + } + break; case 8: - if($pref['statQuery']) { - $text .= $stat -> renderQueries(); - } else { + if ($pref['statQuery']) + { + $text .= $stat -> renderQueries(display_pars($pref['statQuery'])); + } + else + { $text .= ADSTAT_L7; - } - break; + } + break; case 9: - if($pref['statRecent']) { + if ($pref['statRecent']) + { $text .= $stat -> recentVisitors(); - } else { + } + else + { $text .= ADSTAT_L7; - } - break; + } + break; case 10: - $text .= $stat -> renderDaily(); - break; + $text .= $stat -> renderDaily(); + break; case 11: - $text .= $stat -> renderMonthly(); - break; + $text .= $stat -> renderMonthly(); + break; default : $text .= $stat -> renderTodaysVisits(FALSE); } @@ -500,6 +536,7 @@ switch($action) 11 - Monthly stats 12 - Today's error page visits 13 - All-time error page visits +14 - Consolidated browser view (not listed as a menu option) */ $path = e_PLUGIN."log/stats.php"; @@ -527,7 +564,40 @@ $links .= "

"; $ns->tablerender(ADSTAT_L6, $links.$text); require_once(FOOTERF); -class siteStats { + +function make_bits($prefix, $act) +{ + $ret = array(); + $now = getdate(); + $ret['hdg_extra'] = ''; + switch ($act) + { + case 1 : + $ret['query'] = "log_id='{$prefix}'"; + break; + case 2 : + $ret['query'] = "log_id='{$prefix}:".date("Y-m")."'"; + $ret['hdg_extra'] = " (".$now['mon']."-".$now['year'].")"; + break; + case 3 : + $now['mon']--; + if ($now['mon']==0) + { + $now['mon'] = 12; + $now['year']--; + } + $ret['query'] = "log_id='{$prefix}:".sprintf("%04d-%02d",$now['year'],$now['mon'])."'"; + $ret['hdg_extra'] = " (".$now['mon']."-".$now['year'].")"; + break; + default: $ret = "Invalid selection: {$act}
"; + } + return $ret; +} + + +class siteStats +{ + var $browser_headings = array(1 => ADSTAT_L50, 2 => ADSTAT_L51, 3 => ADSTAT_L52); var $dbPageInfo; var $fileInfo; @@ -706,11 +776,12 @@ class siteStats { \n\n - \n\n\n"; + \n\n\n"; foreach($totalArray as $key => $info) { if($info['ttlv']) { + if (!$info['url'] && (($key == 'index') || (strpos($key,':index') !== FALSE))) $info['url'] = e_BASE.'index.php'; // Avoids empty link $percentage = round(($info['ttlv']/$total) * 100, 2); $text .= "\n"; } } - $text .= "\n
".ADSTAT_L4." + ".ADSTAT_L4." ".ADSTAT_ON."   ".ADSTAT_OFF."
".ADSTAT_L18."".r_userclass("statUserclass", $pref['statUserclass'],'off','public, member, admin, classes')."".ADSTAT_L18."".r_userclass("statUserclass", $pref['statUserclass'],'off','public, member, admin, classes')."
".ADSTAT_L20." + ".ADSTAT_L20." ".ADSTAT_ON."   ".ADSTAT_OFF."
".ADSTAT_L21." + ".ADSTAT_L21."
".ADSTAT_L5." - ".ADSTAT_L6."   - ".ADSTAT_ON."   - ".ADSTAT_OFF."
- - ".ADSTAT_L7."   - ".ADSTAT_ON."   - ".ADSTAT_OFF."
- - ".ADSTAT_L8."   - ".ADSTAT_ON."   - ".ADSTAT_OFF."
- - ".ADSTAT_L9."   - ".ADSTAT_ON."   - ".ADSTAT_OFF."
- - ".ADSTAT_L10."   - ".ADSTAT_ON."   - ".ADSTAT_OFF."
- - ".ADSTAT_L11."   - ".ADSTAT_ON."   - ".ADSTAT_OFF."
- - ".ADSTAT_L19."   +
".ADSTAT_L5." + ".gen_select(ADSTAT_L6, 'statBrowser',$pref['statBrowser']) + .gen_select(ADSTAT_L7, 'statOs',$pref['statOs']) + .gen_select(ADSTAT_L8, 'statScreen',$pref['statScreen']) + .gen_select(ADSTAT_L9, 'statDomain',$pref['statDomain']) + .gen_select(ADSTAT_L10, 'statRefer',$pref['statRefer']) + .gen_select(ADSTAT_L11, 'statQuery',$pref['statQuery']) + .ADSTAT_L19."   ".ADSTAT_ON."   ".ADSTAT_OFF."
@@ -175,8 +298,14 @@ $text = "
".ADSTAT_L12."
".ADSTAT_L13."
+ ".ADSTAT_L78."
".ADSTAT_L79."
+ +
".ADSTAT_L12."
".ADSTAT_L13."
".ADSTAT_L14."
".ADSTAT_L6."
".ADSTAT_L7."
@@ -189,17 +318,13 @@ $text = "
".ADSTAT_L26."
".ADSTAT_L27."
+ ".ADSTAT_L26."
".ADSTAT_L27."
@@ -209,12 +334,356 @@ $text = "
"; -$ns->tablerender(ADSTAT_L16, $text); + $ns->tablerender(ADSTAT_L16, $text); + break; // case config + + case 'rempage' : // Remove pages + rempage(); + break; + + + case 'export' : // Export file + case 'datasets' : + //=========================================================== + // EXPORT DATA + //=========================================================== + $text = "
"; + if ($action == 'export') + { + $text .= "
"; + } + else + { + $text .= ""; + } + $text .= " + + + + + "; + + if ($action == 'export') + { + $text .= ""; + } + else + { + $text .= ""; + } + + // Type of output data - page data, browser stats.... + $text .= ""; + + + + $text .= ""; + + + if ($action == 'export') + { + // Separators, quotes + $text .= ""; + + $text .= " + + + "; + } + + + if ($export_filter) + { + if (getperms('0')) $text .= ""; + $sql -> db_Select("logstats", "log_id", "{$export_filter} "); + $text .= ""; + } + + $text .= " + + + +
".ADSTAT_L67."
".ADSTAT_L68."
".ADSTAT_L51."\n".data_type_select('export_type',$export_type); + + // Period selection type for page data + $text .= "
".ADSTAT_L41."\n + "; + + // Period selection type for non-page data + $text .= " + "; + + $text .= "
".ADSTAT_L46."\n"; + + + // Now put the various dropdowns - their visibility is controlled by the export_type dropdown + + $text .= "\n   "; + + + $text .= "\n   "; + + $this_year = date("Y"); + $text .= "\n   "; + + $text .= "\n"; + + $text .= "
".ADSTAT_L59."\n + \n    \n
".ADSTAT_L60."
".ADSTAT_L61."
+ +
".ADSTAT_L65."".$export_filter."
".ADSTAT_L64.""; + while($row = $sql -> db_Fetch()) + { + $text .= $row['log_id']."
"; + } + $text .= "
+ +
+
+
"; + + // Set up the date display boxes + $text .= ""; + + $ns->tablerender(ADSTAT_L40, $text); + break; // case 'export' + + case 'history' : + //=========================================================== + // DELETE HISTORY + //=========================================================== + $text = "
+
+ + + + + "; + $keep_month = varset($_POST['delete_month'],0); + $keep_year = varset($_POST['delete_year'],0); + if (isset($_POST['delete_history'])) + { + $text .= " + "; + $text .= ""; + } + else + { + if (isset($_POST['actually_delete'])) + { + $delete_list = get_for_delete($keep_year,$keep_month); +// $text .= ""; + $text .= ""; + } + $text .= ""; + $text .= " + + "; + } + $text .= "
".ADSTAT_L72."".nl_langinfo(constant('MON_'.$keep_month))." ".$keep_year."
+ + +
".ADSTAT_L74." +
".ADSTAT_L75."".implode("
",get_for_delete($keep_year,$keep_month))."
Data notionally deleted {$keep_month}-{$keep_year}
".ADSTAT_L77.""; + foreach ($delete_list as $k => $v) + { + $sql->db_Delete('logstats',"log_id='{$k}'"); + $text .= $v."
"; + } + $text .= "
".ADSTAT_L70."\n   "; + + $this_year = date("Y"); + $text .= "\n
+ +
".ADSTAT_L76." +
"; + $ns->tablerender(ADSTAT_L69, $text); + break; // case 'history' + +} + + require_once(e_ADMIN."footer.php"); +function headerjs() +{ + $script_js = "\n"; + return $script_js; +} + +function get_for_delete($keep_year,$keep_month = 1, $filter='*') +{ + global $sql, $stats_list; + $ret = array(); + // Its tedious, but the filter criteria are sufficiently tricky that its probably best to read all records and decide what can go + if ($sql->db_Select('logstats','log_id')) + { + while ($row = $sql->db_Fetch()) + { + $can_go = FALSE; + $check = FALSE; + $data_type = 'unknown'; + $date_info = $row['log_id']; + if (($temp = strpos($date_info,':')) !== FALSE) + { // its monthly browser stats and similar +// echo "Checking {$date_info}, posn = {$temp} "; + $data_type = substr($date_info,0,$temp); + $date_info = substr($date_info,$temp+1); + $check = TRUE; +// echo "Date string: {$date_info}, data type: {$data_type}
"; + if (isset($stats_list[$data_type])) $data_type = $stats_list[$data_type]; + } + list($poss_year,$poss_month,$poss_day) = explode('-',$date_info.'--',3); + if (!$check) + { + if (is_numeric($poss_year)) + { + $check = TRUE; + if ($poss_day > 0) $data_type = 'daily'; else $data_type = 'monthly'; + } + } + if ($check) + { + if ($keep_year == $poss_year) + { + if (($poss_month > 0) && ($poss_month < $keep_month)) $can_go = TRUE; + } + elseif ($keep_year > $poss_year) $can_go = TRUE; + } + if ($can_go) + { + $ret[$row['log_id']] = $row['log_id']." - ".$data_type; + } + } + } + return $ret; +} + +//--------------------------------------------- +// Remove page entries - prompt/list +//--------------------------------------------- function rempage() { global $sql, $ns; @@ -250,9 +719,9 @@ function rempage() { $text .= "
$key{$key} ".$page['url']."
".ADSTAT_L19."".ADSTAT_L23."%
".ADSTAT_L23."%
@@ -723,7 +794,7 @@ class siteStats {
".ADSTAT_L21."$total
"; + $text .= "".ADSTAT_L21."{$total}\n"; $uniqueArray = array(); @@ -744,6 +815,7 @@ class siteStats { { if($info['ttlv']) { + if (!$info['url'] && (($key == 'index') || (strpos($key,':index') !== FALSE))) $info['url'] = e_BASE.'index.php'; // Avoids empty link $percentage = round(($info['unqv']/$totalv) * 100, 2); $text .= " ".$key." @@ -758,88 +830,177 @@ class siteStats { /* -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - function renderBrowsers() { - global $sql, $browser_map; + // List browsers. $selection is an array of the info required - '2' = current month's stats, '1' = all-time stats (default) + // If $show_version is FALSE, browsers are consolidated across versions - e.g. 1 line for Firefox + function renderBrowsers($selection, $show_version=TRUE) + { + global $sql, $browser_map; + if (!$selection) $selection = array(1); + if (!is_array($selection)) $selection = array(1); + $text = ''; - if($entries = $sql -> db_Select("logstats", "*", "log_id='statBrowser'")) { + echo "Show browsers; expanded = ".($show_version ? 'TRUE' : 'FALSE')."
"; + foreach ($selection as $act) + { + unset($statBrowser); + $statBrowser = array(); + + $pars = make_bits('statBrowser',$act); // Get the query, plus maybe date for heading + if (!is_array($pars)) return $pars; // Return error if necessary + + if ($entries = $sql -> db_Select("logstats", "*", $pars['query'])) + { $row = $sql -> db_Fetch(); $statBrowser = unserialize($row['log_data']); } /* temp consolidate today's data ... */ - foreach($this -> fileBrowserInfo as $name => $count) { + if (($act == 1) || ($act == 2)) + { + foreach($this -> fileBrowserInfo as $name => $count) + { $statBrowser[$name] += $count; + } + } + + if ($show_version == FALSE) + { + $temp_array = array(); + foreach ($statBrowser as $b_full=>$v) + { + $b_type = ''; + foreach ($browser_map as $name => $file) + { + if(stristr($b_full, $name) === 0) + { // Match here + $b_type = $name; + break; + } + } + if (!$b_type) $b_type = $b_full; // Default is an unsupported browser - use the whole name + + if (array_key_exists($temp_array,$b_type)) + { + $temp_array[$b_type] += $v; + } + else + { + $temp_array[$b_type] = $v; // New browser found + } + } + $statBrowser = $temp_array; + unset($temp_array); } - if(!is_array($statBrowser)) { - return "
".ADSTAT_L25."
"; - } - if(is_array($statBrowser)) { - if($this -> order) { + if ($this -> order) + { ksort($statBrowser); reset ($statBrowser); $browserArray = $statBrowser; - } else { + } + else + { $browserArray = $this -> arraySort($statBrowser, 0); } - $total = array_sum($browserArray); - $text = "\n\n\n\n\n\n"; - foreach($browserArray as $key => $info) { + $total = array_sum($browserArray); + + $text .= "
".ADSTAT_L26."".ADSTAT_L21."%
\n + \n + \n\n + \n\n"; + + if (count($browserArray)) + { + foreach($browserArray as $key => $info) + { $image = ""; - foreach ($browser_map as $name => $file) { - if(strstr($key, $name)) { + foreach ($browser_map as $name => $file) + { + if(strstr($key, $name)) + { $image = "{$file}.png"; break; } } - if($image == "") { + if($image == "") + { $image = "unknown.png"; } $percentage = round(($info/$total) * 100, 2); $text .= " - ". + ". ($entries == 1 ? "" : "")." \n"; + } + $text .= " + \n"; } - $text .= "\n
".$this->browser_headings[$act].$pars['hdg_extra']."
+ ".ADSTAT_L26." + ".ADSTAT_L21."%
".($image ? " " : "").$key."".($image ? " " : "").$key."".$this -> bar($percentage, $info)."".$this -> bar($percentage, $info)."".$percentage."%
".ADSTAT_L21."{$total}
".ADSTAT_L21."$total
"; - } - return $text; + else + { + $text .= "".ADSTAT_L25."\n"; + } + $text .= "
"; + } + return $text; } /* -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - function renderOses() { - global $sql; + function renderOses($selection) + { + global $sql; + if (!$selection) $selection = array(1); + if (!is_array($selection)) $selection = array(1); + $text = ''; - if($entries = $sql -> db_Select("logstats", "*", "log_id='statOs'")) { + $statOs = array(); + foreach ($selection as $act) + { + $pars = make_bits('statOs',$act); // Get the query, plus maybe date for heading + if (!is_array($pars)) return $pars; // Return error if necessary + + if ($entries = $sql -> db_Select("logstats", "*", $pars['query'])) + { $row = $sql -> db_Fetch(); $statOs = unserialize($row['log_data']); } /* temp consolidate today's data ... */ - foreach($this -> fileOsInfo as $name => $count) { + if (($act == 1) || ($act == 2)) + { + foreach($this -> fileOsInfo as $name => $count) + { $statOs[$name] += $count; + } } - if(!is_array($statOs)) { - return "
".ADSTAT_L25.".
"; - } - - if($this -> order) { + if($this -> order) + { ksort($statOs); reset ($statOs); $osArray = $statOs; - } else { - $osArray = $this -> arraySort($statOs, 0); + } + else + { + $osArray = $this -> arraySort($statOs, 0); } $total = array_sum($osArray); - $text = "\n\n\n\n\n\n"; - foreach($osArray as $key => $info) { - + $text .= "
".ADSTAT_L27."".ADSTAT_L21."%
\n + \n + \n\n + \n\n\n"; + + if (count($osArray)) + { + foreach($osArray as $key => $info) + { $image = ""; if(strstr($key, "Windows")) { $image = "windows.png"; } if(strstr($key, "Mac")) { $image = "mac.png"; } @@ -858,42 +1019,73 @@ class siteStats { ($entries == 1 ? "" : "")." \n"; + } + $text .= "\n"; } - $text .= "\n
".$this->browser_headings[$act].$pars['hdg_extra']."
+ ".ADSTAT_L27."".ADSTAT_L21."%
".$this -> bar($percentage, $info)."".$this -> bar($percentage, $info)."".$percentage."%
".ADSTAT_L21."{$total} 
".ADSTAT_L21."$total
"; - return $text; + else + { + $text .= "".ADSTAT_L25."\n"; + } + $text .= "
"; + } + return $text; } /* -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - function renderDomains() { + function renderDomains($selection) + { global $sql; - if($sql -> db_Select("logstats", "*", "log_id='statDomain'")) { + if (!$selection) $selection = array(1); + if (!is_array($selection)) $selection = array(1); + $text = ''; + + $statDom = array(); + foreach ($selection as $act) + { + $pars = make_bits('statDomain',$act); // Get the query, plus maybe date for heading + if (!is_array($pars)) return $pars; // Return error if necessary + + if ($entries = $sql -> db_Select("logstats", "*", $pars['query'])) + { $row = $sql -> db_Fetch(); $statDom = unserialize($row['log_data']); } /* temp consolidate today's data ... */ - foreach($this -> fileDomainInfo as $name => $count) { + if (($act == 1) || ($act == 2)) + { + foreach($this -> fileDomainInfo as $name => $count) + { $statDom[$name] += $count; + } } - if(!count($statDom)) { - return "
".ADSTAT_L25.".
"; - } - - if($this -> order) { + if($this -> order) + { ksort($statDom); reset ($statDom); $domArray = $statDom; - } else { - $domArray = $this -> arraySort($statDom, 0); + } + else + { + $domArray = $this -> arraySort($statDom, 0); } $total = array_sum($domArray); - $text = "\n\n\n\n\n\n"; - foreach($domArray as $key => $info) { - if($key = $this -> getcountry($key)) { + $text .= "
".ADSTAT_L28."".ADSTAT_L21."%
\n + \n + \n\n + \n\n\n"; + + if (count($domArray)) + { + foreach($domArray as $key => $info) + { + if($key = $this -> getcountry($key)) + { $percentage = round(($info/$total) * 100, 2); $text .= " @@ -901,31 +1093,52 @@ class siteStats { \n"; } + } + $text .= "\n"; } - $text .= "\n
".$this->browser_headings[$act].$pars['hdg_extra']."
+ ".ADSTAT_L28."".ADSTAT_L21."%
".$key."".$percentage."%
".ADSTAT_L21."$total
".ADSTAT_L21."$total
"; + else + { + $text .= "".ADSTAT_L25."\n"; + } + $text .= "
"; + } return $text; } /* -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - function renderScreens() { + function renderScreens($selection) + { global $sql; - if($entries = $sql -> db_Select("logstats", "*", "log_id='statScreen'")) { + if (!$selection) $selection = array(1); + if (!is_array($selection)) $selection = array(1); + $text = ''; + + $statScreen = array(); + foreach ($selection as $act) + { + $pars = make_bits('statScreen',$act); // Get the query, plus maybe date for heading + if (!is_array($pars)) return $pars; // Return error if necessary + + if ($entries = $sql -> db_Select("logstats", "*", $pars['query'])) + { $row = $sql -> db_Fetch(); $statScreen = unserialize($row['log_data']); } /* temp consolidate today's data ... */ - foreach($this -> fileScreenInfo as $name => $count) { + if (($act == 1) || ($act == 2)) + { + foreach($this -> fileScreenInfo as $name => $count) + { $statScreen[$name] += $count; + } } - if(!is_array($statScreen)) { - return "
".ADSTAT_L25."
"; - } - if($this -> order) { + if($this -> order) + { $nsarray = array(); foreach($statScreen as $key => $info) { if(preg_match("/(\d+)x/", $key, $match)) { @@ -939,14 +1152,23 @@ class siteStats { $screenArray[$key] = $info['info']; } - } else { + } + else + { $screenArray = $this -> arraySort($statScreen, 0); } $total = array_sum($screenArray); - $text = "\n\n\n\n\n\n"; - foreach($screenArray as $key => $info) { - if(strstr($key, "@") && !strstr($key, "undefined") && preg_match("/(\d+)x(\d+)@(\d+)/", $key)) { + $text .= "
".ADSTAT_L29."".ADSTAT_L21."%
\n + \n + \n\n\n\n\n"; + + if (count($screenArray)) + { + foreach($screenArray as $key => $info) + { + if(strstr($key, "@") && !strstr($key, "undefined") && preg_match("/(\d+)x(\d+)@(\d+)/", $key)) + { $percentage = round(($info/$total) * 100, 2); $text .= "". @@ -954,45 +1176,68 @@ class siteStats { \n"; } + } + $text .= "\n"; } - $text .= "\n
".$this->browser_headings[$act].$pars['hdg_extra']."
".ADSTAT_L29."".ADSTAT_L21."%
".$key."".$percentage."%
".ADSTAT_L21."{$total}
".ADSTAT_L21."$total
"; - return $text; + else + { + $text .= "".ADSTAT_L25."\n"; + } + $text .= "
"; + } + return $text; } /* -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - function renderRefers() { + function renderRefers($selection) + { global $sql, $pref; - if($sql -> db_Select("logstats", "*", "log_id='statReferer'")) { + if (!$selection) $selection = array(1); + if (!is_array($selection)) $selection = array(1); + $text = ''; + + $statRefer = array(); + foreach ($selection as $act) + { + $pars = make_bits('statReferer',$act); // Get the query, plus maybe date for heading + if (!is_array($pars)) return $pars; // Return error if necessary + + if ($entries = $sql -> db_Select("logstats", "*", $pars['query'])) + { $row = $sql -> db_Fetch(); $statRefer = unserialize($row['log_data']); } /* temp consolidate today's data ... */ - foreach($this -> fileReferInfo as $name => $count) { + if (($act == 1) || ($act == 2)) + { + foreach($this -> fileReferInfo as $name => $count) + { $statRefer[$name]['url'] = $count['url']; $statRefer[$name]['ttl'] += $count['ttl']; - } - - //echo "
"; print_r($statRefer); echo "
"; exit; - - if(!is_array($statRefer) || !count($statRefer)) { - return "
".ADSTAT_L25.".
"; + } } $statArray = $this -> arraySort($statRefer, 'ttl'); - $total = 0; - foreach($statArray as $key => $info) { + foreach ($statArray as $key => $info) + { $total += $info['ttl']; } - $text = "\n\n\n\n\n\n"; + $text .= "
".ADSTAT_L30."".ADSTAT_L21."%
\n + \n + \n\n\n\n\n"; $count = 0; - foreach($statArray as $key => $info) { + if (count($statArray)) + { + foreach($statArray as $key => $info) + { $percentage = round(($info['ttl']/$total) * 100, 2); - if (!$this -> order && strlen($key) > 50) { + if (!$this -> order && strlen($key) > 50) + { $key = substr($key, 0, 50)." ..."; } $text .= " @@ -1001,38 +1246,64 @@ class siteStats { \n"; $count++; - if($count == $pref['statDisplayNumber']) { - break; + if($count == $pref['statDisplayNumber']) + { + break; } + } + $text .= "\n"; } - $text .= "\n
".$this->browser_headings[$act].$pars['hdg_extra']."
".ADSTAT_L30."".ADSTAT_L21."%
".$percentage."%
".ADSTAT_L21."{$total}
".ADSTAT_L21."$total
"; - return $text; + else + { + $text .= "".ADSTAT_L25."\n"; + } + $text .= "
"; + } + return $text; } /* -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - function renderQueries() { + function renderQueries($selection) + { global $sql; - if($sql -> db_Select("logstats", "*", "log_id='statQuery'")) { + if (!$selection) $selection = array(1); + if (!is_array($selection)) $selection = array(1); + $text = ''; + + $statQuery = array(); + foreach ($selection as $act) + { + $pars = make_bits('statQuery',$act); // Get the query, plus maybe date for heading + if (!is_array($pars)) return $pars; // Return error if necessary + + if ($entries = $sql -> db_Select("logstats", "*", $pars['query'])) + { $row = $sql -> db_Fetch(); $statQuery = unserialize($row['log_data']); } /* temp consolidate today's data ... */ - foreach($this -> fileQueryInfo as $name => $count) { + if (($act == 1) || ($act == 2)) + { + foreach ($this -> fileQueryInfo as $name => $count) + { $statQuery[$name] += $count; + } } - if(!is_array($statQuery) || !count($statQuery)) { - return "
".ADSTAT_L25."
"; - } $queryArray = $this -> arraySort($statQuery, 0); $total = array_sum($queryArray); - $text = "\n\n\n\n\n\n"; + $text .= "
".ADSTAT_L31."".ADSTAT_L21."%
\n + \n + \n\n\n\n\n"; $count = 1; - foreach($queryArray as $key => $info) { + if (count($queryArray)) + { + foreach ($queryArray as $key => $info) + { $percentage = round(($info/$total) * 100, 2); $key = str_replace("%20", " ", $key); $text .= " @@ -1041,17 +1312,26 @@ class siteStats { \n"; $count ++; - if($count == $pref['statDisplayNumber']) { + if($count == $pref['statDisplayNumber']) + { break; } + } + $text .= "\n"; } - $text .= "\n
".$this->browser_headings[$act].$pars['hdg_extra']."
".ADSTAT_L31."".ADSTAT_L21."%
".$percentage."%
".ADSTAT_L21."{$total}
".ADSTAT_L21."$total
"; - return $text; + else + { + $text .= "".ADSTAT_L25."\n"; + } + $text .= "
"; + } + return $text; } /* -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - function recentVisitors() { + function recentVisitors() + { if(!is_array($this -> fileRecent) || !count($this -> fileRecent)) { return "
".ADSTAT_L25.".
"; } diff --git a/e107_themes/templates/header_default.php b/e107_themes/templates/header_default.php index 476fc68af..2886fe16c 100644 --- a/e107_themes/templates/header_default.php +++ b/e107_themes/templates/header_default.php @@ -6,8 +6,8 @@ | Released under the terms and conditions of the GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_themes/templates/header_default.php,v $ -| $Revision: 1.14 $ -| $Date: 2007-09-27 20:58:11 $ +| $Revision: 1.15 $ +| $Date: 2007-11-01 20:28:29 $ | $Author: e107steved $ +-----------------------------------------------------------------------------------------------+ */ @@ -141,14 +141,14 @@ if (function_exists('headerjs')){echo headerjs(); } if (isset($eplug_css) && $eplug_css) { if(is_array($eplug_css)) { - foreach($eplug_css as $kcss) - { - echo "\n"; - } + foreach($eplug_css as $kcss) + { // Allow inline style definition - but only if $eplug_css is an array (maybe require an array later) + if ('\n"; + } } else { - echo "\n"; + echo "\n"; } } @@ -194,11 +194,9 @@ if(defined("PREVIEWTHEME")) { } } -// -// DEPRECATED!!! This is used in log/stats.php to generate some css. We'll clean this up in a future release. -// +// Deprecated function finally removed +//if(function_exists('core_head')){ echo core_head(); } -if(function_exists('core_head')){ echo core_head(); } // // F: Send Meta Tags and Icon links