Thread: [Phpcms-plugins-cvs] admin4phpCMS/modules/statistic class.module_statistic.php,NONE,1.1 .cvsignore,N
Brought to you by:
mjahn
Update of /cvsroot/phpcms-plugins/admin4phpCMS/modules/statistic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15012/modules/statistic Added Files: class.module_statistic.php .cvsignore ua.dat import_phpcms.php class.statistic_phpcms.php handbook.php class.statistic_database.php Log Message: Commit as backup during development --- NEW FILE: .cvsignore --- jpgraph* fonts stat.txt logs* input* class.apache.logs.reader.php class.stat_phpcms.php class.statistic_apache.php pie3d_csimex1.php test.png test.php useragents --- NEW FILE: class.statistic_database.php --- <?php /** * project_name * * <b>License</b> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * @author Martin Jahn <mj...@us...> * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @copyright Copyright (c) 2005, Martin Jahn * @version $Id: class.statistic_database.php,v 1.1 2005/04/07 14:09:07 mjahn Exp $ * @package project_name */ /* * $Log: class.statistic_database.php,v $ * Revision 1.1 2005/04/07 14:09:07 mjahn * Commit as backup during development * */ class statistic_database { var $statdir = ''; var $ip = array (); var $uri = array (); var $ua = array (); var $ref = array (); var $session = array (); function statistic_database ($statdir = '') { return $this->__construct ($statdir); } function __construct ($statdir) { if (!file_exists ($statdir) || !is_dir ($statdir)) { return false; } $this->statdir = $statdir; if (substr ($this->statdir, -1) !== '/') { $this->statdir .= '/'; } return true; } function read ($day) { if (!file_exists ($this->statdir.$day)) { return array (); } return unserialize (file_get_contents ($this->statdir.$day)); } function getDays () { $dh = dir ($this->statdir); $ret = array (); while (false !== ($entry = $dh->read ())) { if ($entry{4} != '-' || $entry{7} != '-') { continue; } $ret [] = $entry; } $dh->close (); return $ret; } /** * import data from an assoziative array into a simpler final system */ function import ($data) { $times = array_keys ($data); sort ($times); // import old data from backupfile $filename = strftime ('%Y-%m-%d', $times [0]); if (file_exists ($this->statdir.'/backup/'.$filename)) { if (false !== ($_data = unserialize (file_get_contents ($this->statdir.'/backup/'.$filename)))) { $data = array_merge ($_data, $data); } } for ($i = 0; $i < count ($times); $i++) { if (strftime ('%Y-%m-%d', $times [$i]) > $filename) { if ($this->_saveData ($filename) === false) { return false; } $this->ip = array (); $this->uri = array (); $this->ua = array (); $this->ref = array (); $this->session = array (); $filename = strftime ('%Y-%m-%d', $times [$i]); } $this->_addTime ($times [$i]); $this->_addIp ($data [$times [$i]]); $this->_addRef ($data [$times [$i]]); $this->_addUa ($data [$times [$i]]); $this->_addUri ($data [$times [$i]]); $this->_addSession ($data [$times [$i]]); } if ($this->_saveData ($filename) === false) { return false; } return true; } function rebuild () { $days = $this->getDays (); sort ($days); $current = 0; for ($i = 0; $i < count ($days); $i++) { if (!file_exists ($this->statdir.'/'.$days [$i])) { continue; } if ($current != substr ($days [$i], 0, 7)) { // save data monthly into files if ($current != 0) { $this->_saveMonthData ($current, $data); } // goto next day and reset data array $data = array (); $current = substr ($days [$i], 0, 7); } // include data into monthly statistic $_data = unserialize (file_get_contents ($this->statdir.'/'.$days [$i])); foreach ($_data as $type=>$values) { foreach ($values as $id=>$value) { if (!isset ($data [$type] [$id])) { $data [$type] [$id] = 0; } $data [$type] [$id] += $value; } } } if ($current != 0) { $this->_saveMonthData ($current, $data); } } function _saveMonthData ($month, $data) { $fh = fopen ($this->statdir.'/'.$month, 'wb'); if (function_exists ('flock')) { flock ($fh, LOCK_EX); } fwrite ($fh, serialize ($data)); if (function_exists ('flock')) { flock ($fh, LOCK_UN); } fclose ($fh); } function _saveData ($filename) { $data = array ('ref'=>$this->ref, 'uri'=>$this->uri, 'ua'=>$this->ua, 'ip'=>$this->ip, 'session'=>$this->session, 'time'=>$this->time); $fh = fopen ($this->statdir.$filename, 'wb'); if ($fh === false) { @fclose ($fh); return false; } if (function_exists ('flock')) { flock ($fh, LOCK_EX); } fwrite ($fh, serialize ($data)); if (function_exists ('flock')) { flock ($fh, LOCK_UN); } fclose ($fh); return true; } /** * adds the ip to the internal referrer-list * @access private * @param array data set of data to add to the IP-list */ function _addTime ($time) { $t = strftime ('%H', $time); if (!isset ($this->time [$t])) { $this->time [$t] = 0; } $this->time [$t]++; } /** * adds the ip to the internal referrer-list * @access private * @param array data set of data to add to the IP-list */ function _addIp ($data) { if (!isset ($this->ip [$data ['ip']])) { $this->ip [$data ['ip']] = 0; } $this->ip [$data ['ip']]++; } /** * adds the referrer to the internal referrer-list * @access private * @param array data set of data to add to the Referrer-list */ function _addRef ($data) { if (!isset ($this->ref [$data ['ref']])) { $this->ref [$data ['ref']] = 0; } $this->ref [$data ['ref']]++; } /** * adds the ua and decode them to the internal ua-list * @access private * @param array data set of data to add to the UA-list */ function _addUa ($data) { if (!isset ($this->ua_dat) || !is_array ($this->ua_dat)) { $this->ua_dat = unserialize (file_get_contents (dirname (__FILE__).'/ua.dat')); } $ua = $data ['ua']; if (isset ($this->ua_dat [$data ['ua']])) { $ua = $this->ua_dat [$data ['ua']]; } else { //$ua = 'unknown'; } if (!isset ($this->ua [$ua])) { $this->ua [$ua] = 0; } $this->ua [$ua]++; } /** * adds the ip to the internal referrer-list * @access private * @param array data set of data to add to the URI-list */ function _addUri ($data) { if (!isset ($this->uri [$data ['uri']])) { $this->uri [$data ['uri']] = 0; } $this->uri [$data ['uri']]++; } /** * parses the logdata into user-sessions * @access private * @param array data set of data to add to the Session-list */ function _addSession ($data) { return true; } } ?> --- NEW FILE: class.statistic_phpcms.php --- <?php /** * Admin4phpCMS - module Statistic * * <b>License</b> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * @author Martin Jahn <mj...@us...> * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @copyright Copyright (c) 2005, Martin Jahn * @version $Id: class.statistic_phpcms.php,v 1.1 2005/04/07 14:09:07 mjahn Exp $ * @package admin4phpCMS * @subpackage module_statistic */ /* * $Log: class.statistic_phpcms.php,v $ * Revision 1.1 2005/04/07 14:09:07 mjahn * Commit as backup during development * */ class statistic_phpcms { var $loaded = false; var $filename = ''; var $data = array (); var $times = array (); function statistic_phpcms ($filename) { return $this->__construct ($filename); } function __construct ($filename) { if (!file_exists ($filename) || !is_readable ($filename)) { return false; } $this->filename = $filename; $temp = @file ($filename); if (!is_array ($temp)) { return false; } if (count ($temp) < 1) { return false; } // time;ip;proto;method;ref;ua;uri foreach ($temp as $log) { $data = array (); $logentry = explode (';', trim ($log)); $data = array ('ip'=>'', 'proto'=>'', 'ref'=>'', 'ua'=>'', 'uri'=>''); if (isset ($logentry [0])) { $id = $logentry [0]; } if (isset ($logentry [1])) { $data ['ip'] = $logentry [1]; } if (isset ($logentry [2])) { $data ['proto'] = $logentry [2]; } if (isset ($logentry [3])) { $data ['method'] = $logentry [3]; } if (isset ($logentry [4])) { $data ['ref'] = $logentry [4]; } if (isset ($logentry [5])) { $data ['ua'] = $logentry [5]; } if (isset ($logentry [6])) { $data ['uri'] = $logentry [6]; } if (isset ($this->data [$id])) { $this->data [$id] [] = $data; } else { $this->data [$id] = $data; } } $this->loaded = true; } function read ($from = 0, $till = 0) { if (DEBUG) echo '---- read ('.$from.' - '.$till.') ----'; if ($from == 0 && $till == 0) { return $this->data; } $ret = array (); $ids = array_keys ($this->data); $max = count ($ids); for ($i = 0; $i < $max; $i++) { if (!isset ($ids [$i])) { continue; } if ($ids [$i] < $from || $ids [$i] > $till) { continue; } $ret [$ids [$i]] =& $this->data [$ids [$i]]; } return $ret; } function readAllIds () { return array_keys ($this->data);; } function del ($from, $till) { $ids = array_keys ($this->data); $max = count ($ids); if (DEBUG) echo '---- del ('.$from.' - '.$till.' = '.$max.') ----'; for ($i = 0; $i < $max; $i++) { if ($ids [$i] < $from) { if (DEBUG) echo "\n".'<!-- '.$ids [$i].' < '.$from.' -->'; continue; } if ($till != 0 && $ids [$i] > $till) { if (DEBUG) echo "\n".'<!-- '.$ids [$i].' > '.$till.' -->'; continue; } if (DEBUG) echo "\n".'<!-- '.$ids [$i].' del -->'; unset ($this->data [$ids [$i]]); } } function write () { $tempname = $this->filename.time (); if (DEBUG) echo '---- write ('.$tempname.')----'; $fh = fopen ($tempname, 'wb'); if ($fh === false) { return false; } if (function_exists ('flock')) { flock ($fh, LOCK_UN); } $ids = array_keys ($this->data); $max = count ($ids); for ($i = 0; $i < $max; $i++) { if (!isset ($ids [$i]) || !is_array ($this->data [$ids [$i]])) { continue; } if (isset ($this->data [$ids [$i]] [0])) { for ($j = 0; $j < count ($this->data [$ids [$i]]); $j++) { fwrite ($fh, $ids [$i].';'. $this->data [$ids [$i]] [$j] ['ip'].';'. $this->data [$ids [$i]] [$j] ['proto'].';'. $this->data [$ids [$i]] [$j] ['method'].';'. $this->data [$ids [$i]] [$j] ['ref'].';'. $this->data [$ids [$i]] [$j] ['ua'].';'. $this->data [$ids [$i]] [$j] ['uri']."\n"); } } else { fwrite ($fh, $ids [$i].';'. $this->data [$ids [$i]] ['ip'].';'. $this->data [$ids [$i]] ['proto'].';'. $this->data [$ids [$i]] ['method'].';'. $this->data [$ids [$i]] ['ref'].';'. $this->data [$ids [$i]] ['ua'].';'. $this->data [$ids [$i]] ['uri']."\n"); } } if (function_exists ('flock')) { flock ($fh, LOCK_UN); } fclose ($fh); copy ($tempname, $this->filename); unlink ($tempname); } } ?> --- NEW FILE: class.module_statistic.php --- <?php /** * statistic-module * * This module displays the follwoing statistic-data about the website * <ul> * <li>listing of all Referrer</li> * <li>monthly, weekly and daily view of sites and users</li> * <li>Visitsin relation to the menu-data (LINK, CLASS) in monthly, weekly and * daily view</li> * </ul> * * <b>License</b> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * @author Martin Jahn <mj...@us...> * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @copyright Copyright (c) 2004, Martin Jahn * @version $Id: class.module_statistic.php,v 1.1 2005/04/07 14:09:07 mjahn Exp $ * @package admin4phpCMS * @subpackage module_statistic **/ /* * $Log: class.module_statistic.php,v $ * Revision 1.1 2005/04/07 14:09:07 mjahn * Commit as backup during development * */ include_once (dirname (__FILE__).'/class.statistic_database.php'); /** * Class for statistic interface * * You can define several data-sources in this class. They will be displayed * via a selection to the user and he can choice, which datasource he wants * to see. * * @package admin4phpCMS * @subpackage module_statistic * @todo Get the class work completly **/ class module_statistic extends module { var $_CONF = array ('statdir'=>'/parser/stat/'); var $jpgraphdir = ''; /** * Initialization of the module * * The module registers its own events and connects his methods to some actions **/ function init () { $this->jpgraphdir = dirname (__FILE__).'/../../../jpgraph/'; // connect to actions $this->_registerAction('doParseParam', 'parseParam'); $this->_registerAction('doGetMenu', 'getMenu'); return true; } /** * Parse the URI-params * @param array $actiondata $actiondata contains the URI-param-arrays */ function parseParam (&$actiondata) { $this->display = (isset ($actiondata ['request'] ['moduleid']) && $actiondata ['request'] ['moduleid'] == 'stat'); if ($this->display) { $this->_registerAction('doGetData', 'getData'); $this->_registerAction('doGetLanguage', 'getLanguageData'); $this->action = ''; if (isset ($actiondata ['request'] ['action'])) { $this->action = $actiondata ['request'] ['action']; } $this->viewyear = ''; if (isset ($actiondata ['request'] ['viewyear'])) { $this->viewyear = $actiondata ['request'] ['viewyear']; } $this->viewmonth = 0; if (isset ($actiondata ['request'] ['viewmonth'])) { $this->viewmonth = $actiondata ['request'] ['viewmonth']; } } $actiondata1 = array (); $this->_callEvent ('USER_GET_STATUS', $actiondata1); $this->_USER = $actiondata1; return true; } // function parseParam () /** * Get content for menu * @param array $actiondata */ function getMenu (&$actiondata) { if (!$this->_USER['isLoggedIn']) { return true; } $data = array ('name'=>'Statistik', 'module'=>'stat', 'action'=>''); $_data = array (); if ($this->display) { $data ['extra'] = 'class="current"'; /** **/ $data1 = array ('name' => 'Content', 'module' => 'stat', 'action' => 'content'); if (substr ($this->action, 0, 7) == 'content') { $data1 ['extra'] = 'class="current"'; $data2 = array ('name' => 'Pages / Directories', 'module' => 'stat', 'action' => 'content-pagesdir'); if ($this->action == 'content-pagesdir') { $data2 ['extra'] = 'class="current"'; } $__data [] = $data2; $data2 = array ('name' => 'Content pages', 'module' => 'stat', 'action' => 'content-pages'); if ($this->action == 'content-pages') { $data2 ['extra'] = 'class="current"'; } $__data [] = $data2; $data2 = array ('name' => 'File types', 'module' => 'stat', 'action' => 'content-filetypes', 'extra'=>'class="last"'); if ($this->action == 'content-filetypes') { $data2 ['extra'] = 'class="current last"'; } $__data [] = $data2; $data1 ['_sub_'] = $__data; } $_data [] = $data1; /** **/ $data1 = array ('name' => 'Visitors', 'module' => 'stat', 'action' => 'visitor'); if (substr ($this->action, 0, 7) == 'visitor') { $data1 ['extra'] = 'class="current"'; $data2 = array ('name' => 'Hostnames', 'module' => 'stat', 'action' => 'visitor-hostnames'); if ($this->action == 'visitor-hostnames') { $data2 ['extra'] = 'class="current"'; } $__data [] = $data2; $data2 = array ('name' => 'TLDs', 'module' => 'stat', 'action' => 'visitor-tld'); if ($this->action == 'visitor-tld') { $data2 ['extra'] = 'class="current"'; } $__data [] = $data2; $data2 = array ('name' => 'Locator', 'module' => 'stat', 'action' => 'visitor-locator'); if ($this->action == 'visitor-locator') { $data2 ['extra'] = 'class="current"'; } $__data [] = $data2; $data2 = array ('name' => 'Browser', 'module' => 'stat', 'action' => 'visitor-browsers'); if ($this->action == 'visitor-browsers') { $data2 ['extra'] = 'class="current"'; } $__data [] = $data2; $data2 = array ('name' => 'Operating systems', 'module' => 'stat', 'action' => 'visitor-os', 'extra'=>'class="last"'); if ($this->action == 'visitor-os') { $data2 ['extra'] = 'class="current last"'; } $__data [] = $data2; $data1 ['_sub_'] = $__data; } $_data [] = $data1; /** **/ $data1 = array ('name' => 'Referrers', 'module' => 'stat', 'action' => 'referrer'); if (substr ($this->action, 0, 8) == 'referrer') { $data1 ['extra'] = 'class="current"'; $data2 = array ('name' => 'Hostnames', 'module' => 'stat', 'action' => 'referrer-hostnames'); if ($this->action == 'referrer-hostnames') { $data2 ['extra'] = 'class="current"'; } $__data [] = $data2; $data2 = array ('name' => 'TLDs', 'module' => 'stat', 'action' => 'referrer-tld'); if ($this->action == 'referrer-tld') { $data2 ['extra'] = 'class="current"'; } $__data [] = $data2; $data2 = array ('name' => 'Search engines', 'module' => 'stat', 'action' => 'referrer-searchengines'); if ($this->action == 'referrer-searchengines') { $data2 ['extra'] = 'class="current"'; } $__data [] = $data2; $data2 = array ('name' => 'Search phrases', 'module' => 'stat', 'action' => 'referrer-searchterms'); if ($this->action == 'referrer-searchterms') { $data2 ['extra'] = 'class="current"'; } $__data [] = $data2; $data2 = array ('name' => 'Search phrases by search engine', 'module' => 'stat', 'action' => 'referrer-searchenginesterms', 'extra'=>'class="last"'); if ($this->action == 'referrer-searchenginesterms') { $data2 ['extra'] = 'class="current last"'; } $__data [] = $data2; $data1 ['_sub_'] = $__data; } $_data [] = $data1; /** ** $data1 = array ('name' => 'Visitor demographics', 'module' => 'stat', 'action' => 'visitor'); if (substr ($this->action, 0, 7) == 'visitor') { $data1 ['extra'] = 'class="current"'; $data2 = array ('name' => 'Hostnames', 'module' => 'stat', 'action' => 'visitor-hostnames'); if ($this->action == 'visitor-hostnames') { $data2 ['extra'] = 'class="current"'; } $__data [] = $data2; $data2 = array ('name' => 'TLDs', 'module' => 'stat', 'action' => 'visitor-tld'); if ($this->action == 'visitor-tld') { $data2 ['extra'] = 'class="current"'; } $__data [] = $data2; $data2 = array ('name' => 'Locator', 'module' => 'stat', 'action' => 'visitor-locator'); if ($this->action == 'visitor-locator') { $data2 ['extra'] = 'class="current"'; } $__data [] = $data2; $data1 ['_sub_'] = $__data; } $_data [] = $data1; /** **/ $data1 = array ('name' => 'Sessions', 'module' => 'stat', 'action' => 'session'); if (substr ($this->action, 0, 7) == 'session') { $data1 ['extra'] = 'class="current"'; $data2 = array ('name' => 'Overview', 'module' => 'stat', 'action' => 'session-overview'); if ($this->action == 'session-overview') { $data2 ['extra'] = 'class="current"'; } $__data [] = $data2; $data2 = array ('name' => 'Entry pages', 'module' => 'stat', 'action' => 'session-entry'); if ($this->action == 'session-entry') { $data2 ['extra'] = 'class="current"'; } $__data [] = $data2; $data2 = array ('name' => 'Exit pages', 'module' => 'stat', 'action' => 'session-exit'); if ($this->action == 'session-exit') { $data2 ['extra'] = 'class="current"'; } $__data [] = $data2; $data2 = array ('name' => 'Pathes', 'module' => 'stat', 'action' => 'session-path', 'extra'=>'class="last"'); if ($this->action == 'session-path') { $data2 ['extra'] = 'class="current last"'; } $__data [] = $data2; /* $data2 = array ('name' => 'Hostnames', 'module' => 'stat', 'action' => 'visitor-hostnames'); if ($this->action == 'visitor-hostnames') { $data2 ['extra'] = 'class="current"'; } $__data [] = $data2; $data2 = array ('name' => 'TLDs', 'module' => 'stat', 'action' => 'visitor-tld'); if ($this->action == 'visitor-tld') { $data2 ['extra'] = 'class="current"'; } $__data [] = $data2; $data2 = array ('name' => 'Hostnames', 'module' => 'stat', 'action' => 'visitor-hostnames'); if ($this->action == 'visitor-hostnames') { $data2 ['extra'] = 'class="current"'; } $__data [] = $data2; $data2 = array ('name' => 'TLDs', 'module' => 'stat', 'action' => 'visitor-tld'); if ($this->action == 'visitor-tld') { $data2 ['extra'] = 'class="current"'; } $__data [] = $data2; */ $data1 ['_sub_'] = $__data; } $_data [] = $data1; /** **/ $data ['_sub_'] = $_data; } $actiondata [$actiondata ['tag']] ['statistic'] = array ($data); } // function getMenu () /** * Presentation of the statistic data */ function getData (&$actiondata) { if (!$this->_USER['isLoggedIn']) { return true; } if (!$this->display) { return true; } $actiondata1 = array ('module' => 'stat'); $this->_callEvent('CONFIG_GET', $actiondata1); $this->_CONF = array_merge ($this->_CONF, $actiondata1['config']); $data = array ('action'=>$this->action, 'stat'=>1); $actiondata2 = array ('id'=>'STATS', 'value'=>''); $this->_callEvent ('PHPCMS_GET_DEFAULTS_VALUE', $actiondata2); if (strtoupper ($actiondata2 ['value']) == 'OFF') { $data ['stat'] = 0; $actiondata [$actiondata ['tag']] ['statistic'] = $data; return true; } switch ($this->action) { case 'referrer': case 'referrer-hostnames': case 'referrer-tld': case 'referrer-searchengines': case 'referrer-searchterms': case 'referrer-searchengineterms': $data ['referrer'] = $this->getReferrerData (); break; case 'content': case 'content-pagesdir': case 'content-pages': case 'content-filetypes': $data ['access'] = $this->getContentData (); break; case 'session': case 'session-overview': case 'session-entry': case 'session-exit': case 'session-path': $data ['session'] = $this->getSessionData (); break; case 'import': $data ['import'] = $this->getImportData (); break; case 'visitor': case 'visitor-hostnames': case 'visitor-tld': case 'visitor-browsers': case 'visitor-os': $data ['visitor'] = $this->getVisitorData (); break; default:; } $actiondata [$actiondata ['tag']] ['statistic'] = $data; return true; } function getLanguageData (&$actiondata) { $langAvailable = array ('de', 'en'); $data = $actiondata [$actiondata ['tag']]; foreach ($langAvailable as $lang) { if (!file_exists (dirname (__FILE__).'/module_statistic_'.$lang.'.lng')) { continue; } if (isset ($data [$lang])) { $data [$lang] = array_merge ($data [$lang], parse_ini_file (dirname (__FILE__).'/module_statistic_'.$lang.'.lng')); } else { $data [$lang] = parse_ini_file (dirname (__FILE__).'/module_statistic_'.$lang.'.lng', true); } } $actiondata [$actiondata ['tag']] = $data; return true; } function getReferrerData () { $actiondata = array ('id'=>'REFERRER'); $this->_callEvent ('PHPCMS_GET_DEFAULTS_VALUE', $actiondata); if (strtoupper ($actiondata ['value']) == 'OFF') { return array (''); } $actiondata = array ('id'=>'REFERRER_DIR'); $this->_callEvent ('PHPCMS_GET_DEFAULTS_VALUE', $actiondata); $datafile = $_SERVER ['DOCUMENT_ROOT'].$actiondata ['value']; $actiondata = array ('id'=>'REFERRER_FILE'); $this->_callEvent ('PHPCMS_GET_DEFAULTS_VALUE', $actiondata); $datafile .= '/'.$actiondata ['value']; if (!file_exists ($datafile)) { return array (''); } return unserialize (file_get_contents ($datafile)); } function getContentData ($year = 0, $month = 0) { $actiondata = array ('id'=>'STATSDIR', 'value'=>'/cms/parser/stat/'); $this->_callEvent ('PHPCMS_GET_DEFAULTS_VALUE', $actiondata); $statdir = $_SERVER ['DOCUMENT_ROOT'].$actiondata ['value']; $this->db = new statistic_database ($statdir); echo $current_month = (int) strftime ('%m', time ()); $current_year = strftime ('%Y', time ()); for ($i = 1; $i <= $current_month; $i++) { $data = $this->db->read ($current_year.'-0'.$i); } //print_r ($data); return $data; } function getVisitorData () { $actiondata = array ('id'=>'REFERRER'); $this->_callEvent ('PHPCMS_GET_DEFAULTS_VALUE', $actiondata); if (strtoupper ($actiondata ['value']) == 'OFF') { return array (''); } $actiondata = array ('id'=>'REFERRER_DIR'); $this->_callEvent ('PHPCMS_GET_DEFAULTS_VALUE', $actiondata); $datafile = $_SERVER ['DOCUMENT_ROOT'].$actiondata ['value']; $actiondata = array ('id'=>'REFERRER_FILE'); $this->_callEvent ('PHPCMS_GET_DEFAULTS_VALUE', $actiondata); $datafile .= '/'.$actiondata ['value']; if (!file_exists ($datafile)) { return array (''); } return unserialize (file_get_contents ($datafile)); } function getSessionData () { $actiondata = array ('id'=>'REFERRER'); $this->_callEvent ('PHPCMS_GET_DEFAULTS_VALUE', $actiondata); if (strtoupper ($actiondata ['value']) == 'OFF') { return array (''); } $actiondata = array ('id'=>'REFERRER_DIR'); $this->_callEvent ('PHPCMS_GET_DEFAULTS_VALUE', $actiondata); $datafile = $_SERVER ['DOCUMENT_ROOT'].$actiondata ['value']; $actiondata = array ('id'=>'REFERRER_FILE'); $this->_callEvent ('PHPCMS_GET_DEFAULTS_VALUE', $actiondata); $datafile .= '/'.$actiondata ['value']; if (!file_exists ($datafile)) { return array (''); } return unserialize (file_get_contents ($datafile)); } } ?> --- NEW FILE: import_phpcms.php --- <?php /** * Import-script for phpCMS statistic-data * * <b>License</b> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * @author Martin Jahn <mj...@us...> * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @copyright Copyright (c) 2005, Martin Jahn * @version $Id: import_phpcms.php,v 1.1 2005/04/07 14:09:07 mjahn Exp $ * @package admin4phpCMS * @subpackage module_statistic * * @todo implement the registration of command line parameters for PHP-CLI */ /* * $Log: import_phpcms.php,v $ * Revision 1.1 2005/04/07 14:09:07 mjahn * Commit as backup during development * */ define ('DEBUG', false); /** * include the class for accessing the phpCMS-statfile */ include_once (dirname (__FILE__).'/class.statistic_phpcms.php'); /** * include the class for accessing the database */ include_once (dirname (__FILE__).'/class.statistic_database.php'); /** * import the statistic data from the datasource into the statistic-module * database */ function import_phpcms ($statfile, $statdir) { // initialize phpCMS-statistic $phpcms = new statistic_phpcms ($statfile); $db = new statistic_database ($statdir); $times = $phpcms->readAllIds (); // is there any data to import? if (!isset ($times [0]) || !is_array ($times) || count ($times) == 0) { echo '<p>No data to import ..... done</p>'; return true; } echo '<p>Importing data into database .....'; $data = $phpcms->read (); //print_r ($data); if ($db->import ($data)) { $phpcms->del ($times [0], $times [count ($times) - 1]); $phpcms->write (); $db->rebuild (); echo 'done</p>'; } else { echo 'failed</p>'; } return true; } /** * prints out an error-message and displays the general help-page * @param string text contains the error-message */ function error ($text) { } //define the document-root $docroot = $_SERVER ['DOCUMENT_ROOT']; // get the path to the statfile from URI-parameter if (isset ($_REQUEST ['statfile'])) { $statfile = $docroot.strip_tags (urldecode ($_REQUEST ['statfile'])); } // get the path to the destination directory from URI-parameter if (isset ($_REQUEST ['statdir'])) { $statdir = $docroot.strip_tags (urldecode ($_REQUEST ['statdir'])); } if (true !== ($error = import_phpcms ($statfile, $statdir))) { error ($error); } ?> --- NEW FILE: ua.dat --- (This appears to be a binary file; contents omitted.) --- NEW FILE: handbook.php --- <?php /** * Handbook for the statistic-module * * <b>Introduction</b> * * Import der Daten in die Statistik * - Aufteilen der Daten in tageweise Dateien -> kleine DateigröÃe * - Erstellen spezieller Dateien mit zusammengefaÃten Daten (i.e. * IP/month, Visits/month Pages/moth) * - der Import geschieht über ein externes Skript, welches auch mittels Cronjob * ausgeführt werden kann * - die notwendigen Parameter werden übergeben (auch per Kommandozeile möglich) * * Der Zugriff auf die DB erfolgt über eine eigene Klasse, die auch von den * Importskripten verwendet wird, um auf die DB zuzugreifen (MVC-Konzept) * * * * day.ip ip;anzahl * * day.ref ref:anzahl * * day.uri uri:anzahl * * day.ua ua:anzahl * * day.session * * <b>License</b> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * @author Martin Jahn <mj...@us...> * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @copyright Copyright (c) 2005, Martin Jahn * @version $Id: handbook.php,v 1.1 2005/04/07 14:09:07 mjahn Exp $ * @package admin4phpCMS * @subpackage module_statistic * */ /* * $Log: handbook.php,v $ * Revision 1.1 2005/04/07 14:09:07 mjahn * Commit as backup during development * */ ?> |