[Phpcms-plugins-cvs] admin4phpCMS/modules/statistik config.statistic.xml,NONE,1.1 class.statistic_co
Brought to you by:
mjahn
From: Martin J. <mj...@us...> - 2004-09-29 20:11:23
|
Update of /cvsroot/phpcms-plugins/admin4phpCMS/modules/statistik In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19438/modules/statistik Modified Files: class.module_statistik.php .cvsignore Added Files: config.statistic.xml class.statistic_common.php class.statistic_phpcms.php Log Message: completed phpCMS-config-part began the statistic part --- NEW FILE: class.statistic_common.php --- <?php /** * statistic-module - analysis of phpCMS-logfile * * <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.statistic_common.php,v 1.1 2004/09/29 20:10:43 mjahn Exp $ * @package admin4phpCMS * @subpackage module_statistic **/ /* * $Log: class.statistic_common.php,v $ * Revision 1.1 2004/09/29 20:10:43 mjahn * completed phpCMS-config-part * began the statistic part * */ include_once (PATH_TO_PEAR.'Cache.php'); /** * Class for statistic analysis * * Interface for parsing the phpcms-logfile and divide into monthly sections * saved in separated files. * Create the data-arrays and save them as serialized files, they can be used * for presenting the data to the user. * * A basic class creates the interface and implements the analytical part and * the extended classes define the specific parsing function. * * The basic class also takes care of the caching of the parsed data. * * <b>What is interesting?</b> * * <ul> * <li>which IPs, browsers, referrer, files appear how much times?</li> * <li>time-based view of amount of called sites (monthly, weekly, daily, hourly)</li> * <li></li> * </ul> * * This class also renders the tables. For diagramm rendering use another file, * that is called as image-generator. It creates a diagramm according to the parameters * it got. It uses PEAR::Cache for saving server-load. * * @package admin4phpCMS * @subpackage module_statistic * @todo Get the class work completly **/ class statistic_common { /** * flag, if the data is parsed **/ var $parsed = false; var $_parsed = array (); var $_parser_time = array (); function statistic_common () { return $this->__construct (); } function __construct () { return true; } function getCountedFiles ($start, $end) { } } ?> Index: .cvsignore =================================================================== RCS file: /cvsroot/phpcms-plugins/admin4phpCMS/modules/statistik/.cvsignore,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- .cvsignore 25 Aug 2004 21:21:00 -0000 1.2 +++ .cvsignore 29 Sep 2004 20:10:43 -0000 1.3 @@ -1,3 +1,10 @@ jpgraph* fonts stat.txt +logs* +input* +class.apache.logs.reader.php +class.stat_phpcms.php +class.statistic_apache.php +pie3d_csimex1.php +test.png --- NEW FILE: config.statistic.xml --- <?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?> <config> <source id="apache"> </source> </config> --- NEW FILE: class.statistic_phpcms.php --- <?php /** * statistic-module - analysis of phpCMS-logfile * * <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.statistic_phpcms.php,v 1.1 2004/09/29 20:10:43 mjahn Exp $ * @package admin4phpCMS * @subpackage module_statistic **/ /* * $Log: class.statistic_phpcms.php,v $ * Revision 1.1 2004/09/29 20:10:43 mjahn * completed phpCMS-config-part * began the statistic part * */ /** * include file with parental class **/ include_once (dirname (__FILE__).'/class.statistic_common.php'); define ('LOGDIR', dirname (__FILE__).'/logs/'); /** * Class for statistic analysis * * @package admin4phpCMS * @subpackage module_statistic * @todo Get the class work completly **/ class statistic_phpcms extends statistic_common { /** * set the path to the phpCMS-logdir **/ function load ($path = '/home/martin/devel/admin4phpCMS/modules/statistik/stat.txt') { $this->_logfile = $path; } /** * parse the logfile and sclice it into daily files (to reduce the single filesize) **/ function import () { $fh = fopen ($this->_logfile, 'rb'); if (function_exists ('flock')) { flock ($fh, LOCK_EX); } $date = ''; // get start time // while (!feof ($fh)) { // && $time - $starttime < 10 sec) { $entry = trim (fgets ($fh)); // empty entry -> go if ($entry == '') { continue; } // extract timestamp from entry $time = substr ($entry, 0, strpos ($entry, ';')); $act_date = strftime ('%Y-%m-%d', $time); // check for new date entry if ($act_date != $date) { // close the last statfile, wether it was opened or not @fclose ($temp); // check if the statfile for the actual date exists if (file_exists (LOGDIR.$act_date)) { $temp = fopen (LOGDIR.$act_date.'.log', 'ab'); } else { $temp = fopen (LOGDIR.$act_date.'.log', 'wb'); } } fwrite ($temp, $entry."\n"); } fclose ($temp); if (function_exists ('flock')) { flock ($fh, LOCK_UN); } fclose ($fh); @unlink ($this->_logfile); } /** * parse the splited stat-files **/ function parse ($from_time, $to_time) { $min = strftime ('%Y-%m-%d', $from_time); $max = strftime ('%Y-%m-%d', $to_time); $dh = opendir (LOGDIR); $this->_parsed = array(); while (false !== ($filename = readdir ($dh))) { if (!preg_match ('%\d\d\d\d-\d\d-\d\d\.log%', $filename)) { continue; } $filetime = substr ($filename, 0, 10); if ($filetime < $min || $filetime > $max) { continue; } $this->_parsed [$filetime] = array (); $data = file (LOGDIR.$filename); foreach ($data as $entry) { $entry = explode (';', trim ($entry)); $entry = array ( 'time'=>$entry [0], 'ip'=>$entry [1], 'ref'=>$entry [4], 'ua'=>$entry [5], 'file'=>$entry [6]); $this->_parsed [$filetime] [] = $entry; } } closedir ($dh); $this->parsed = true; } } ?> Index: class.module_statistik.php =================================================================== RCS file: /cvsroot/phpcms-plugins/admin4phpCMS/modules/statistik/class.module_statistik.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- class.module_statistik.php 25 Aug 2004 21:16:44 -0000 1.2 +++ class.module_statistik.php 29 Sep 2004 20:10:43 -0000 1.3 @@ -28,16 +28,23 @@ /* * $Log$ -* Revision 1.2 2004/08/25 21:16:44 mjahn -* step 1 is taken +* Revision 1.3 2004/09/29 20:10:43 mjahn +* completed phpCMS-config-part +* began the statistic part * */ -include_once (PATH_TO_PEAR.'Cache.php'); +include_once (dirname (__FILE__).'/class.statistic_phpcms.php'); + +define ('JPGRAPH', '/home/martin/devel/jpgraph/'); /** * 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 @@ -63,7 +70,6 @@ * @param array $actiondata $actiondata contains the URI-param-arrays **/ function parseParam (&$actiondata) { -// print_r ($actiondata); $this->display = (isset ($actiondata ['request'] ['moduleid']) && $actiondata ['request'] ['moduleid'] == 'statistik'); $this->action = ''; @@ -74,11 +80,25 @@ $actiondata1 = array (); $this->_callEvent ('USER_GET_STATUS', $actiondata1); $this->_USER = $actiondata1; + $this->_STAT = new statistic_phpcms (); + + if ($this->display) { + $this->_registerAction ('doParseContent', 'getStatContent'); + } return true; } // function parseParam () + + + /** + * process the import process + **/ + function processImport (&$actiondata) { + $this->_STAT->load(); + $this->_STAT->import(); + } /** * Get content for mainmenu @@ -124,15 +144,55 @@ } // function getMenuSub () + + /** + * presentation of the statistic data + **/ + function getStatContent (&$actiondata) { + if (!$this->_USER['isLoggedIn']) { + return true; + } + + if (!$this->display) { + return true; + } + + include_once (JPGRAPH.'jpgraph.php'); + include_once (JPGRAPH.'jpgraph_bar.php'); + + $this->_STAT->parse (mktime(0, 0, 0, strftime ('%m', time ()), 1, strftime ('%Y', time())), time ()); - function parseStatFile () { - // open statfile + $keys = array_keys ($this->_STAT->_parsed); + $num = count ($keys); - // walk through statfile + for ($i = 0; $i < $num; $i++) { + $data [$i] = count ($this->_STAT->_parsed [$keys [$i]]); + } + + // Create the Pie Graph. + $graph = new Graph(600,200,'auto'); + $graph->img->SetImgFormat ('png'); + $graph->SetShadow(); + + // Set A title for the plot + $graph->title->Set("Gesamtübersicht"); + $graph->title->SetFont(FF_FONT1,FS_BOLD); + $graph->SetScale ('textlin'); + //$graph->xaxis->SetTickLabels ($labels); + + // Create + $p1 = new BarPlot($data); + $p1->SetColor ('black'); + $p1->SetFillColor ('orange'); + + $graph->Add($p1); + + $graph->Stroke(dirname (__FILE__).'/test.png'); + + $actiondata1 = array ('_root'=>$actiondata ['_root'], '_id'=>'test_diagramm', '_type'=>'image', 'src'=>'/test/modules/statistik/test.png', 'width'=>'600', 'height'=>'200'); + $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata1); - // create stat-arrays - // } } ?> \ No newline at end of file |