diff options
| -rw-r--r-- | Statistics.php | 341 | ||||
| -rw-r--r-- | admin/schema_inc.php | 2 | ||||
| -rw-r--r-- | bit_setup_inc.php | 27 | ||||
| -rw-r--r-- | index.php | 63 | ||||
| -rw-r--r-- | item_chart.php | 9 | ||||
| -rw-r--r-- | pv_chart.php | 12 | ||||
| -rw-r--r-- | referer_stats.php | 73 | ||||
| -rw-r--r-- | stats_lib.php | 452 | ||||
| -rw-r--r-- | templates/referer_stats.tpl | 16 | ||||
| -rw-r--r-- | templates/stats.tpl | 203 | ||||
| -rw-r--r-- | usage_chart.php | 9 | ||||
| -rw-r--r-- | users.php | 17 |
12 files changed, 450 insertions, 774 deletions
diff --git a/Statistics.php b/Statistics.php new file mode 100644 index 0000000..ce09d93 --- /dev/null +++ b/Statistics.php @@ -0,0 +1,341 @@ +<?php +/** + * $Header: /cvsroot/bitweaver/_bit_stats/Statistics.php,v 1.1 2007/06/22 12:35:26 squareing Exp $ + * + * $Id: Statistics.php,v 1.1 2007/06/22 12:35:26 squareing Exp $ + * @package stats + */ + +/** + * @package stats + * @subpackage Stats + */ +class Statistics extends BitBase { + + /** + * Initiate class + */ + function Statistics() { + BitBase::BitBase(); + } + + /** + * getRefererList gets a list of referers + * + * @param array $pListHash + * @access public + * @return array of referers + */ + function getRefererList( &$pListHash ) { + if( empty( $pListHash['sort_mode'] )) { + $pListHash['sort_mode'] = 'hits_desc'; + } + + LibertyContent::prepGetList( $pListHash ); + + $ret = $bindVars = array(); + $selectSql = $joinSql = $whereSql = ""; + + if( !empty( $pListHash['find'] ) && is_string( $pListHash['find'] )) { + $whereSql .= empty( $whereSql ) ? ' WHERE ' : ' AND '; + $whereSql .= " UPPER( `referer` ) LIKE ?"; + $bindVars[] = '%'.strtoupper( $pListHash['find'] ).'%'; + } + + $query = "SELECT * FROM `".BIT_DB_PREFIX."stats_referers` $whereSql ORDER BY ".$this->mDb->convertSortmode( $pListHash['sort_mode'] );; + $ret = $this->mDb->getAll( $query, $bindVars, $pListHash['max_records'], $pListHash['offset'] ); + + $query = "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."stats_referers` $whereSql"; + $pListHash['cant'] = $this->mDb->getOne( $query, $bindVars); + LibertyContent::postGetList( $pListHash ); + + return $ret; + } + + /** + * expungeReferers will remove all referers unconditionally + * + * @access public + * @return TRUE on success, FALSE on failure + */ + function expungeReferers() { + return( $this->mDb->query( "DELETE FROM `".BIT_DB_PREFIX."stats_referers`" )); + } + + /** + * storeReferer will insert new record in referer table + * + * @access public + * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure + */ + function storeReferer() { + global $gBitSystem; + + if( !empty( $_SERVER['HTTP_REFERER'] ) && $parsed = parse_url( $_SERVER['HTTP_REFERER'] )) { + if( !empty( $parsed["host"] ) && !strstr( $_SERVER["HTTP_HOST"], $parsed["host"] )) { + $now = $gBitSystem->getUTCTime(); + + $store = $parsed['scheme'].'://'.$parsed['host']; + + $query = "UPDATE `".BIT_DB_PREFIX."stats_referers` SET `hits`=`hits`+1,`last`=? WHERE `referer`=?"; + $this->mDb->query( $query, array( $now, $store )); + + // if the above didn't affect the db, we know that the entry doesn't exist yet. + if( !$this->mDb->mDb->Affected_Rows() ) { + $query = "INSERT INTO `".BIT_DB_PREFIX."stats_referers`( `last`, `referer`, `hits` ) VALUES( ?, ?, ? )"; + $this->mDb->query( $query, array( $now, $store, 1 )); + } + } + } + return TRUE; + } + + /** + * addPageview to the pageview count + * + * @access public + * @return void + */ + function addPageview() { + $dayzero = mktime( 0, 0, 0, date( "m" ), date( "d" ), date( "Y" )); + $query = "UPDATE `".BIT_DB_PREFIX."stats_pageviews` SET `pageviews`=`pageviews`+1 WHERE `stats_day`=?"; + $this->mDb->query( $query, array( $dayzero )); + + // if the above didn't affect the db, we know that the entry doesn't exist yet. + if( !$this->mDb->mDb->Affected_Rows() ) { + $query = "INSERT INTO `".BIT_DB_PREFIX."stats_pageviews`( `pageviews`, `stats_day` ) VALUES( ?, ? )"; + $this->mDb->query( $query, array( 1, $dayzero )); + } + } + + /** + * registrationStats + * + * @param array $pPeriod + * @access public + * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure + */ + function registrationStats( $pPeriod ) { + global $gBitDbType; + + switch( $pPeriod ) { + case 'year': + $format = 'Y'; + break; + case 'quarter': + $format = 'Y-\QQ'; + break; + case 'day': + $format = 'Y-m-d'; + break; + case 'week': + $format = 'Y \Week W'; + break; + case 'month': + default: + $format = 'Y-m'; + break; + } + + $sqlPeriod = $this->mDb->SQLDate( $format, $this->mDb->SQLIntToTimestamp( 'registration_date' )); + $query = " + SELECT $sqlPeriod AS period, COUNT(`user_id`) + FROM `".BIT_DB_PREFIX."users_users` + GROUP BY( $sqlPeriod ) + ORDER BY COUNT(`user_id`) DESC"; + $ret['per_period'] = $this->mDb->getAssoc( $query ); + $ret['max'] = !empty( $ret['per_period'] ) ? current( $ret['per_period'] ) : 0; + krsort( $ret['per_period'] ); + return $ret; + } + + /** + * getSiteStats will get a brief overview over the site + * + * @access public + * @return array with site stats + */ + function getSiteStats() { + $ret["started"] = $this->mDb->getOne( "SELECT MIN(`stats_day`) FROM `".BIT_DB_PREFIX."stats_pageviews`" ); + $ret["days"] = $this->mDb->getOne( "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."stats_pageviews`" ); + $ret["pageviews"] = $this->mDb->getOne( "SELECT SUM(`pageviews`) FROM `".BIT_DB_PREFIX."stats_pageviews`" ); + $ret["ppd"] = ( $ret["days"] ? $ret["pageviews"] / $ret["days"] : 0 ); + $ret["bestpvs"] = $this->mDb->getOne( "SELECT MAX(`pageviews`) FROM `".BIT_DB_PREFIX."stats_pageviews`" ); + $ret["bestday"] = $this->mDb->getOne( "SELECT `stats_day` FROM `".BIT_DB_PREFIX."stats_pageviews` WHERE `pageviews`=?",array( (int)$ret["bestpvs"] )); + $ret["worstpvs"] = $this->mDb->getOne( "SELECT MIN(`pageviews`) FROM `".BIT_DB_PREFIX."stats_pageviews`" ); + $ret["worstday"] = $this->mDb->getOne( "SELECT `stats_day` FROM `".BIT_DB_PREFIX."stats_pageviews` WHERE `pageviews`=?",array( (int)$ret["worstpvs"] )); + return $ret; + } + + /** + * getContentOverview will get a simple overview based on stats available available in liberty + * + * @param array $pParamHash + * @access public + * @return array with content type stats + */ + function getContentOverview( $pParamHash = NULL ) { + global $gLibertySystem; + + if( empty( $pParamHash['sort_mode'] )) { + $pParamHash['sort_mode'] = 'content_count_desc'; + } + + $query = " + SELECT lc.`content_type_guid` AS `hash_key`, COUNT( lc.`content_id` ) AS `content_count`, SUM( lch.`hits` ) AS `total_hits` + FROM `".BIT_DB_PREFIX."liberty_content` lc + LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content_hits` lch ON( lc.`content_id` = lch.`content_id` ) + GROUP BY lc.`content_type_guid` ORDER BY".$this->mDb->convertSortmode( $pParamHash['sort_mode'] ); + $ret = $this->mDb->getAssoc( $query ); + + return $ret; + } + + /** + * getContentStats will check all available content for the method Object::getStats() and will call and include the data + * + * @access public + * @return array with content-specific stats + */ + function getContentStats() { + global $gLibertySystem; + + $ret = array(); + foreach( $gLibertySystem->mContentTypes as $guid => $type ) { + if( $gLibertySystem->requireHandlerFile( $type )) { + $object = new $type['handler_class'](); + if( method_exists( $object, 'getStats' )) { + $ret[$guid] = $object->getStats(); + } + } + } + + return $ret; + } + + /** + * getPageviewChartData will fetch all data needed to create a graph with PHPlot + * + * @param numeric $pDays Number of days we will use to create a graph + * @access public + * @return array for PHPlot graph + */ + function getPageviewChartData( $pDays = 7 ) { + $now = mktime( 0, 0, 0, date( "m" ), date( "d" ), date( "Y" )); + $dfrom = 0; + if( $pDays != 0 ) $dfrom = $now - ( $pDays * 24 * 60 * 60 ); + + $query = "SELECT `stats_day`, `pageviews` FROM `".BIT_DB_PREFIX."stats_pageviews` WHERE `stats_day`<=? AND `stats_day`>=? ORDER BY `stats_day` ASC"; + $result = $this->mDb->query( $query,array( ( int )$now, ( int )$dfrom )); + $ret = array(); + $n = ceil( $result->numRows() / 20 ); + $i = 0; + + while( $res = $result->fetchRow() ) { + if( $i % $n == 0 ) { + $data = array( + date( "j M Y", $res["stats_day"] ), + $res["pageviews"] + ); + } else { + $data = array( + "", + $res["pageviews"] + ); + } + $ret[] = $data; + $i++; + } + + return $ret; + } + + /** + * getUsageChartData will fetch all data needed to create a graph with PHPlot + * + * @access public + * @return array for PHPlot graph + */ + function getUsageChartData() { + global $gBitSystem, $gLibertySystem; + $ret['data'][0][] = 'a'; + foreach( $gLibertySystem->mContentTypes as $contentType ) { + if( $gBitSystem->isPackageActive( $contentType['handler_package'] )) { + $hits = $this->mDb->getOne( " + SELECT SUM(`hits`) + FROM `".BIT_DB_PREFIX."liberty_content` lc + LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content_hits` liberty_content_hits + ON (lc.`content_id` = liberty_content_hits.`content_id`) + WHERE content_type_guid=?", array( $contentType['content_type_guid'] ) + ); + if( !empty( $hits )) { + $ret['legend'][] = tra( $contentType['content_description'] ); + $ret['data'][0][] = $hits; + } + } + } + return $ret; + } + + /** + * getContentTypeChartData will fetch all data needed to create a graph with PHPlot + * + * @param array $pContentTypeGuid specify the content_type_guid you want to create a graph for + * @access public + * @return array for PHPlot graph + */ + function getContentTypeChartData( $pContentTypeGuid=NULL ) { + global $gLibertySystem; + $ret['data'] = array(); + + if( in_array( $pContentTypeGuid, array_keys( $gLibertySystem->mContentTypes ))) { + $query = " + SELECT `hits`, `title`, `content_type_guid` + FROM `".BIT_DB_PREFIX."liberty_content` lc + LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content_hits` liberty_content_hits + ON (lc.`content_id` = liberty_content_hits.`content_id`) + WHERE `content_type_guid`=? + ORDER BY `hits` DESC"; + $result = $this->mDb->query( $query, array( $pContentTypeGuid ), 159 ); + // this is needed to ensure all arrays have same size + $tmpHash[] = array( NULL, 0 ); + while( $res = $result->fetchRow() ) { + $tmpHash[] = array( + $res['title'], + $res['hits'], + ); + } + $ret['data'][$pContentTypeGuid] = array_chunk( $tmpHash, 40 ); + $ret['title'] = $gLibertySystem->mContentTypes[$pContentTypeGuid]['content_description']; + } else { + foreach( $gLibertySystem->mContentTypes as $contentType ) { + $query = " + SELECT `hits`, `title`, `content_type_guid` + FROM `".BIT_DB_PREFIX."liberty_content` lc + LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content_hits` liberty_content_hits + ON (lc.`content_id` = liberty_content_hits.`content_id`) + WHERE `content_type_guid`=? + ORDER BY `hits` DESC"; + $result = $this->mDb->query( $query, array( $contentType['content_type_guid'] ), 40 ); + // this is needed to ensure all arrays have same size + $ret['data'][$contentType['content_type_guid']] = array_fill( 0, 40, array( NULL, NULL )); + $i = 0; + while( $res = $result->fetchRow() ) { + $ret['data'][$contentType['content_type_guid']][$i++] = array( + $res['title'], + $res['hits'], + ); + } + } + $ret['title'] = 'All Content'; + } + $ret['max'] = $this->mDb->getOne( " + SELECT MAX(`hits`) + FROM `".BIT_DB_PREFIX."liberty_content` lc + LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content_hits` liberty_content_hits + ON (lc.`content_id` = liberty_content_hits.`content_id`) + "); + return $ret; + } +} +?> diff --git a/admin/schema_inc.php b/admin/schema_inc.php index 085f64d..c797733 100644 --- a/admin/schema_inc.php +++ b/admin/schema_inc.php @@ -4,7 +4,7 @@ $tables = array( 'stats_referers' => " referer C(50) NOTNULL, - hits I8, + hits I8, last I8 ", diff --git a/bit_setup_inc.php b/bit_setup_inc.php index c24cc94..7b543a7 100644 --- a/bit_setup_inc.php +++ b/bit_setup_inc.php @@ -7,7 +7,7 @@ $registerHash = array( ); $gBitSystem->registerPackage( $registerHash ); -if( $gBitSystem->isPackageActive( STATS_PKG_NAME ) ) { +if( $gBitSystem->isPackageActive( 'stats' )) { if( $gBitUser->hasPermission( 'p_stats_view' ) || $gBitUser->hasPermission( 'p_stats_view_referer' ) ) { $menuHash = array( 'package_name' => STATS_PKG_NAME, @@ -16,23 +16,14 @@ if( $gBitSystem->isPackageActive( STATS_PKG_NAME ) ) { ); $gBitSystem->registerAppMenu( $menuHash ); } - global $statslib; - require_once( STATS_PKG_PATH.'stats_lib.php' ); - // ********** STATS ************ - if ($gBitSystem->isFeatureActive( 'stats_referers' ) ) { - // Referer tracking - if (isset($_SERVER['HTTP_REFERER'])) { - $pref = parse_url($_SERVER['HTTP_REFERER']); - if( !empty( $pref["host"] ) && !strstr( $_SERVER["HTTP_HOST"], $pref["host"] ) ) { - $statslib->register_referer($pref["host"]); - } - } - } - if( $gBitSystem->isFeatureActive( 'users_count_admin_pageviews' ) && !$gBitUser->isAdmin() ) { - if ( isset($_SERVER["REQUEST_URI"]) && !strstr($_SERVER["REQUEST_URI"], 'chat')) { - $statslib->add_pageview(); - } + + require_once( STATS_PKG_PATH.'Statistics.php' ); + $stats = new Statistics(); + $stats->addPageview(); + + // store referer stats if desired + if( $gBitSystem->isFeatureActive( 'stats_referers' )) { + $stats->storeReferer(); } } - ?> @@ -1,14 +1,8 @@ <?php /** - * $Header: /cvsroot/bitweaver/_bit_stats/index.php,v 1.6 2006/04/11 13:09:28 squareing Exp $ + * $Header: /cvsroot/bitweaver/_bit_stats/index.php,v 1.7 2007/06/22 12:35:26 squareing Exp $ * - * Copyright (c) 2004 bitweaver.org - * Copyright (c) 2003 tikwiki.org - * Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al. - * All Rights Reserved. See copyright.txt for details and a complete list of authors. - * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details - * - * $Id: index.php,v 1.6 2006/04/11 13:09:28 squareing Exp $ + * $Id: index.php,v 1.7 2007/06/22 12:35:26 squareing Exp $ * @package stats * @subpackage functions */ @@ -17,59 +11,16 @@ * required setup */ require_once( '../bit_setup_inc.php' ); - -include_once( STATS_PKG_PATH.'stats_lib.php' ); -global $statslib, $gBitSystem; +include_once( STATS_PKG_PATH.'Statistics.php' ); $gBitSystem->verifyPackage( 'stats' ); - $gBitSystem->verifyPermission( 'p_stats_view' ); -if (!isset($_REQUEST["days"])) { - $_REQUEST["days"] = 7; -} - -$gBitSmarty->assign('pv_chart', 'n'); - -if (isset($_REQUEST["pv_chart"])) { - $gBitSmarty->assign('pv_chart', 'y'); -} - -$gBitSmarty->assign('days', $_REQUEST["days"]); - -$gBitSmarty->assign('usage_chart', 'n'); - -if (isset($_REQUEST["chart"])) { - $gBitSmarty->assign($_REQUEST["chart"] . "_chart", 'y'); -} - -if ($gBitSystem->isPackageActive( 'wiki' ) ) { - $wiki_stats = $statslib->wiki_stats(); -} else { - $wiki_stats = false; -} -$gBitSmarty->assign_by_ref('wiki_stats', $wiki_stats); - -if ($gBitSystem->isPackageActive( 'articles' ) ) { - $cms_stats = $statslib->cms_stats(); -} else { - $cms_stats = false; -} -$gBitSmarty->assign_by_ref('cms_stats', $cms_stats); - -if ($gBitSystem->isPackageActive( 'blogs' ) ) { - $blog_stats = $statslib->blog_stats(); -} else { - $blog_stats = false; -} -$gBitSmarty->assign_by_ref('blog_stats', $blog_stats); - -$user_stats = $statslib->user_stats(); -$gBitSmarty->assign_by_ref('user_stats', $user_stats); +$gStats = new Statistics(); -$site_stats = $statslib->site_stats(); -$gBitSmarty->assign_by_ref('site_stats', $site_stats); +$gBitSmarty->assign( 'siteStats', $gStats->getSiteStats() ); +$gBitSmarty->assign( 'contentOverview', $gStats->getContentOverview( $_REQUEST )); +$gBitSmarty->assign( 'contentStats', $gStats->getContentStats() ); -// Display the template $gBitSystem->display( 'bitpackage:stats/stats.tpl', tra( "Statistics" ) ); ?> diff --git a/item_chart.php b/item_chart.php index eb90839..3416f1b 100644 --- a/item_chart.php +++ b/item_chart.php @@ -1,6 +1,6 @@ <?php /** - * $Header: /cvsroot/bitweaver/_bit_stats/item_chart.php,v 1.4 2007/06/14 17:51:30 squareing Exp $ + * $Header: /cvsroot/bitweaver/_bit_stats/item_chart.php,v 1.5 2007/06/22 12:35:26 squareing Exp $ * * Copyright (c) 2004 bitweaver.org * Copyright (c) 2003 tikwiki.org @@ -8,7 +8,7 @@ * All Rights Reserved. See copyright.txt for details and a complete list of authors. * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details * - * $Id: item_chart.php,v 1.4 2007/06/14 17:51:30 squareing Exp $ + * $Id: item_chart.php,v 1.5 2007/06/22 12:35:26 squareing Exp $ * @package stats * @subpackage functions */ @@ -24,8 +24,9 @@ global $gBitSystem; $gBitSystem->isPackageActive( 'stats' ); $gBitSystem->verifyPermission( 'p_stats_view' ); -// data to be displayed -$data = $statslib->get_item_chart_data( !empty( $_REQUEST['content_type_guid'] ) ? $_REQUEST['content_type_guid'] : NULL ); +$stats = new Statistics(); + +$data = $stats->getContentTypeChartData( !empty( $_REQUEST['content_type_guid'] ) ? $_REQUEST['content_type_guid'] : NULL ); $chart_type = !empty( $_REQUEST['chart_type'] ) ? $_REQUEST['chart_type'] : 'points'; if( !empty( $_REQUEST['content_type_guid'] ) ) { diff --git a/pv_chart.php b/pv_chart.php index 89e288f..c965154 100644 --- a/pv_chart.php +++ b/pv_chart.php @@ -1,6 +1,6 @@ <?php /** - * $Header: /cvsroot/bitweaver/_bit_stats/pv_chart.php,v 1.6 2006/04/11 13:09:28 squareing Exp $ + * $Header: /cvsroot/bitweaver/_bit_stats/pv_chart.php,v 1.7 2007/06/22 12:35:26 squareing Exp $ * * Copyright (c) 2004 bitweaver.org * Copyright (c) 2003 tikwiki.org @@ -8,7 +8,7 @@ * All Rights Reserved. See copyright.txt for details and a complete list of authors. * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details * - * $Id: pv_chart.php,v 1.6 2006/04/11 13:09:28 squareing Exp $ + * $Id: pv_chart.php,v 1.7 2007/06/22 12:35:26 squareing Exp $ * @package stats * @subpackage functions */ @@ -17,16 +17,16 @@ * required setup */ require_once( '../bit_setup_inc.php' ); -//Include the code -include_once( STATS_PKG_PATH . "stats_lib.php" ); +include_once( STATS_PKG_PATH . "Statistics.php" ); include_once( UTIL_PKG_PATH . "phplot.php" ); -global $gBitSystem; $gBitSystem->isPackageActive( 'stats' ); $gBitSystem->verifyPermission( 'p_stats_view' ); +$stats = new Statistics(); + $days = isset( $_REQUEST["days"] ) ? $_REQUEST['days'] : 7; -$data = $statslib->get_pv_chart_data( $days ); +$data = $stats->getPageviewChartData( $days ); // initialise phplot and insert data $graph =& new PHPlot( 600, 600 ); diff --git a/referer_stats.php b/referer_stats.php index 40dcc52..562e16a 100644 --- a/referer_stats.php +++ b/referer_stats.php @@ -1,82 +1,29 @@ <?php /** - * $Header: /cvsroot/bitweaver/_bit_stats/referer_stats.php,v 1.9 2006/04/14 20:25:53 squareing Exp $ + * $Header: /cvsroot/bitweaver/_bit_stats/referer_stats.php,v 1.10 2007/06/22 12:35:26 squareing Exp $ * - * Copyright (c) 2004 bitweaver.org - * Copyright (c) 2003 tikwiki.org - * Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al. - * All Rights Reserved. See copyright.txt for details and a complete list of authors. - * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details - * - * $Id: referer_stats.php,v 1.9 2006/04/14 20:25:53 squareing Exp $ + * $Id: referer_stats.php,v 1.10 2007/06/22 12:35:26 squareing Exp $ * @package stats - * @subpackage functions */ /** * required setup */ require_once( '../bit_setup_inc.php' ); - -include_once ( STATS_PKG_PATH.'stats_lib.php'); +include_once ( STATS_PKG_PATH.'Statistics.php'); $gBitSystem->verifyPackage( 'stats' ); $gBitSystem->verifyFeature( 'stats_referers' ); $gBitSystem->verifyPermission( 'p_stats_view_referer' ); +$gStats = new Statistics(); -if (isset($_REQUEST["clear"])) { - - $statslib->clear_referer_stats(); -} - -if ( empty( $_REQUEST["sort_mode"] ) ) { - $sort_mode = 'hits_desc'; -} else { - $sort_mode = $_REQUEST["sort_mode"]; -} - -if (!isset($_REQUEST["offset"])) { - $offset = 0; -} else { - $offset = $_REQUEST["offset"]; -} - -$gBitSmarty->assign_by_ref('offset', $offset); - -if (isset($_REQUEST["find"])) { - $find = $_REQUEST["find"]; -} else { - $find = ''; -} - -$gBitSmarty->assign('find', $find); - -$gBitSmarty->assign_by_ref('sort_mode', $sort_mode); -$referers = $statslib->list_referer_stats($offset, $max_records, $sort_mode, $find); - -$cant_pages = ceil($referers["cant"] / $max_records); -$gBitSmarty->assign_by_ref('cant_pages', $cant_pages); -$gBitSmarty->assign('actual_page', 1 + ($offset / $max_records)); - -if ($referers["cant"] > ($offset + $max_records)) { - $gBitSmarty->assign('next_offset', $offset + $max_records); -} else { - $gBitSmarty->assign('next_offset', -1); -} - -// If offset is > 0 then prev_offset -if ($offset > 0) { - $gBitSmarty->assign('prev_offset', $offset - $max_records); -} else { - $gBitSmarty->assign('prev_offset', -1); +// get rid of all referers in the database +if( isset( $_REQUEST["clear"] )) { + $gStats->expungeReferers(); } -$gBitSmarty->assign_by_ref('referers', $referers["data"]); - - - -// Display the template -$gBitSystem->display( 'bitpackage:stats/referer_stats.tpl'); - +$gBitSmarty->assign( 'referers', $gStats->getRefererList( $_REQUEST )); +$gBitSmarty->assign( 'listInfo', $_REQUEST['listInfo'] ); +$gBitSystem->display( 'bitpackage:stats/referer_stats.tpl', tra( 'Referer Statistics' )); ?> diff --git a/stats_lib.php b/stats_lib.php deleted file mode 100644 index 73c7cc0..0000000 --- a/stats_lib.php +++ /dev/null @@ -1,452 +0,0 @@ -<?php -/** - * $Header: /cvsroot/bitweaver/_bit_stats/Attic/stats_lib.php,v 1.32 2007/06/22 11:15:00 lsces Exp $ - * - * Copyright (c) 2004 bitweaver.org - * Copyright (c) 2003 tikwiki.org - * Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al. - * All Rights Reserved. See copyright.txt for details and a complete list of authors. - * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details - * - * $Id: stats_lib.php,v 1.32 2007/06/22 11:15:00 lsces Exp $ - * @package stats - */ - -/** - * @package stats - */ -class StatsLib extends BitBase { - function StatsLib() { - BitBase::BitBase(); - } - - - /* referer methods */ - function clear_referer_stats() { - $query = "delete from stats_referers"; - - $result = $this->mDb->query($query); - } - - function list_referer_stats($offset, $max_records, $sort_mode, $find) { - $bindvars = array(); - if ($find) { - $findesc = $this->mDb->qstr('%' . strtoupper( $find ) . '%'); - $mid = " where (UPPER(`referer`) like ?)"; - $bindvars = array($findesc); - } else { - $mid = ""; - } - - $query = "select * from `".BIT_DB_PREFIX."stats_referers` $mid order by ".$this->mDb->convertSortmode($sort_mode);; - $query_cant = "select count(*) from `".BIT_DB_PREFIX."stats_referers` $mid"; - $result = $this->mDb->query($query,$bindvars,$max_records,$offset); - $cant = $this->mDb->getOne($query_cant,$bindvars); - $ret = array(); - - while ($res = $result->fetchRow()) { - $ret[] = $res; - } - - $retval = array(); - $retval["data"] = $ret; - $retval["cant"] = $cant; - return $retval; - } - - function register_referer($referer) { - if( !empty( $referer ) ) { - global $gBitSystem; - $now = $gBitSystem->getUTCTime(); - $cant = $this->mDb->getOne("select count(*) from `".BIT_DB_PREFIX."stats_referers` where `referer`=?",array($referer)); - - $query = "update `".BIT_DB_PREFIX."stats_referers` set `hits`=`hits`+1,`last`=? where `referer`=?"; - $rs = $this->mDb->query($query,array((int)$now,$referer)); - if( !$this->mDb->mDb->Affected_Rows() ) { - $query = "insert into `".BIT_DB_PREFIX."stats_referers`(`last`,`referer`,`hits`) values(?,?,1)"; - $result = $this->mDb->query($query,array((int)$now,$referer)); - } - } - } - - - /* content methods */ - function list_orphan_pages($offset = 0, $max_records = -1, $sort_mode = 'title_desc', $find = '') { - - if ($sort_mode == 'size_desc') { - $sort_mode = 'wiki_page_size_desc'; - } - - if ($sort_mode == 'size_asc') { - $sort_mode = 'wiki_page_size_asc'; - } - - $old_sort_mode = ''; - - if (in_array($sort_mode, array( - 'versions_desc', - 'versions_asc', - 'links_asc', - 'links_desc', - 'backlinks_asc', - 'backlinks_desc' - ))) { - $old_offset = $offset; - - $old_max_records = $max_records; - $old_sort_mode = $sort_mode; - $sort_mode = 'user_desc'; - $offset = 0; - $max_records = -1; - } - $bindvars = array(); - if ($find) { - $mid = " where UPPER(`page_name`) like ? "; - $bindvars[] = '%'.strtoupper( $find ).'%'; - } else { - $mid = ""; - } - - // If sort mode is versions then offset is 0, max_records is -1 (again) and sort_mode is nil - // If sort mode is links then offset is 0, max_records is -1 (again) and sort_mode is nil - // If sort mode is backlinks then offset is 0, max_records is -1 (again) and sort_mode is nil - $query = "select * from `".BIT_DB_PREFIX."wiki_pages` wp INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON( lc.`content_id`=wp.`content_id` ) $mid order by ".$this->mDb->convertSortmode($sort_mode); - $query_cant = "select count(*) from `".BIT_DB_PREFIX."wiki_pages` $mid"; - $result = $this->mDb->query($query,$bindvars,-1,0); - $cant = $this->mDb->getOne($query_cant,$bindvars); - $ret = array(); - $num_or = 0; - - while ($res = $result->fetchRow()) { - $title = $res["title"]; - $queryc = "select count(*) from `".BIT_DB_PREFIX."liberty_content_links` where `to_content_id`=?"; - $cant = $this->mDb->getOne( $queryc,array($res['content_id'] ) ); - $queryc = "select count(*) from `".BIT_DB_PREFIX."liberty_structures` ls WHERE ls.`content_id`=?"; - $cant += $this->mDb->getOne( $queryc, array( $res['content_id'] ) ); - - if ($cant == 0) { - $num_or++; - $aux = array(); - $aux["title"] = $title; - $page = $aux["title"]; - $page_as = addslashes($page); -// $aux["hits"] = $res["hits"]; - $aux["last_modified"] = $res["last_modified"]; - $aux["user_id"] = $res["user_id"]; - $aux["ip"] = $res["ip"]; - $aux["version"] = $res["version"]; - $aux["flag"] = $res["flag"] == 'y' ? tra('locked') : tra('unlocked'); - $aux["versions"] = $this->mDb->getOne("select count(*) from `".BIT_DB_PREFIX."liberty_content_history` WHERE `content_id`=?",array($res['content_id'])); - $aux["links"] = $this->mDb->getOne("select count(*) from `".BIT_DB_PREFIX."liberty_content_links` WHERE `from_content_id`=?",array( $res['content_id']) ); - $aux["backlinks"] = $this->mDb->getOne("select count(*) from `".BIT_DB_PREFIX."liberty_content_links` where `to_content_id`=?",array( $res['content_id'] ) ); - $ret[] = $aux; - } - } - - // If sortmode is versions, links or backlinks sort using the ad-hoc function and reduce using old_offse and old_max_records - if ($old_sort_mode == 'versions_asc') { - usort($ret, 'compare_versions'); - } - - if ($old_sort_mode == 'versions_desc') { - usort($ret, 'r_compare_versions'); - } - - if ($old_sort_mode == 'links_desc') { - usort($ret, 'compare_links'); - } - - if ($old_sort_mode == 'links_asc') { - usort($ret, 'r_compare_links'); - } - - if ($old_sort_mode == 'backlinks_desc') { - usort($ret, 'compare_backlinks'); - } - - if ($old_sort_mode == 'backlinks_asc') { - usort($ret, 'r_compare_backlinks'); - } - - if (in_array($old_sort_mode, array( - 'versions_desc', - 'versions_asc', - 'links_asc', - 'links_desc', - 'backlinks_asc', - 'backlinks_desc' - ))) { - $ret = array_slice($ret, $old_offset, $old_max_records); - } - - $retval = array(); - $retval["data"] = $ret; - $retval["cant"] = $num_or; - return $retval; - } - - function wiki_stats() { - global $gBitSystem; - $stats = array(); - if( $gBitSystem->isPackageActive( 'wiki' ) ) { - require_once( WIKI_PKG_PATH.'BitPage.php' ); - - $stats["pages"] = $this->mDb->getOne("select count(*) from `".BIT_DB_PREFIX."wiki_pages`",array()); - $stats["versions"] = $this->mDb->getOne("select count(*) from `".BIT_DB_PREFIX."liberty_content_history`",array()); - - if ($stats["pages"]) { - $stats["vpp"] = $stats["versions"] / $stats["pages"]; - } else { - $stats["vpp"] = 0; - } - $stats["visits"] = $this->mDb->getOne("SELECT sum(lch.`hits`) - FROM `".BIT_DB_PREFIX."liberty_content` lc - LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content_hits` lch - ON (lc.`content_id` = lch.`content_id`) - WHERE `content_type_guid`=?",array( BITPAGE_CONTENT_TYPE_GUID ) - ); - $or = $this->list_orphan_pages(0, -1, 'title_desc', ''); - $stats["orphan"] = $or["cant"]; - $links = $this->mDb->getOne("select count(*) from `".BIT_DB_PREFIX."liberty_content_links`",array()); - - if ($stats["pages"]) { - $stats["lpp"] = $links / $stats["pages"]; - } else { - $stats["lpp"] = 0; - } - $stats["size"] = $this->mDb->getOne("select sum(`wiki_page_size`) from `".BIT_DB_PREFIX."wiki_pages`",array()); - - if ($stats["pages"]) { - $stats["bpp"] = $stats["size"] / $stats["pages"]; - } else { - $stats["bpp"] = 0; - } - $stats["size"] = $stats["size"] / 1000000; - } - return $stats; - } - - function cms_stats() { - global $gBitSystem; - $stats = array(); - if( $gBitSystem->isPackageActive( 'articles' ) ) { - require_once( ARTICLES_PKG_PATH.'BitArticle.php' ); - - $stats["articles"] = $this->mDb->getOne("select count(*) from `".BIT_DB_PREFIX."articles`",array()); - $stats["reads"] = $this->mDb->getOne("SELECT sum(lch.`hits`) - FROM `".BIT_DB_PREFIX."liberty_content` lc - LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content_hits` lch - ON (lc.`content_id` = lch.`content_id`) - WHERE `content_type_guid`=?",array( BITARTICLE_CONTENT_TYPE_GUID ) - ); - $stats["rpa"] = ($stats["articles"] ? $stats["reads"] / $stats["articles"] : 0); -// $stats["size"] = $this->mDb->getOne("select sum(`size`) from `".BIT_DB_PREFIX."articles`",array()); -// $stats["bpa"] = ($stats["articles"] ? $stats["size"] / $stats["articles"] : 0); - $stats["topics"] = $this->mDb->getOne("select count(*) from `".BIT_DB_PREFIX."article_topics` where `active_topic`=?",array('y')); - } - return $stats; - } - - function blog_stats() { - global $gBitSystem; - $stats = array(); - if( $gBitSystem->isPackageActive( 'blogs' ) ) { - require_once( BLOGS_PKG_PATH.'BitBlogPost.php' ); - $stats["blogs"] = $this->mDb->getOne("select count(*) from `".BIT_DB_PREFIX."blogs`",array()); - $stats["posts"] = $this->mDb->getOne("select count(*) from `".BIT_DB_PREFIX."blog_posts`",array()); - $stats["ppb"] = ($stats["blogs"] ? $stats["posts"] / $stats["blogs"] : 0); - // $stats["size"] = $this->mDb->getOne("select sum(`data_size`) from `".BIT_DB_PREFIX."blog_posts`",array()); - // $stats["bpp"] = ($stats["posts"] ? $stats["size"] / $stats["posts"] : 0); - $stats["visits"] = $this->mDb->getOne("SELECT sum(lch.`hits`) - FROM `".BIT_DB_PREFIX."liberty_content` lc - LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content_hits` lch ON (lc.`content_id` = lch.`content_id`) - WHERE `content_type_guid`=?",array( BITBLOGPOST_CONTENT_TYPE_GUID ) - ); - } - return $stats; - } - - function registrationStats( $pPeriod ) { - global $gBitDbType; - - switch( $pPeriod ) { - case 'year': - $format = 'Y'; - break; - case 'quarter': - $format = 'Y-\QQ'; - break; - case 'day': - $format = 'Y-m-d'; - break; - case 'week': - $format = 'Y \Week W'; - break; - case 'month': - default: - $format = 'Y-m'; - break; - } - -// $sqlPeriod = $this->mDb->SQLDate( $format, $this->mDb->SQLIntToTimestamp( '`registration_date`' ) ); - $sqlPeriod = $this->mDb->SQLDate( $format, $this->mDb->SQLIntToTimestamp( 'registration_date' ) ); - $query = "SELECT $sqlPeriod AS period, COUNT(`user_id`) FROM `".BIT_DB_PREFIX."users_users` - GROUP BY( $sqlPeriod ) ORDER BY COUNT(`user_id`) DESC"; - $stats['per_period'] = $this->mDb->getAssoc( $query ); - $stats['max'] = !empty( $stats['per_period'] ) ? current( $stats['per_period'] ) : 0; - krsort( $stats['per_period'] ); - return $stats; - } - - function user_stats() { - global $gBitSystem; - $stats = array(); - $stats["users"] = $this->mDb->getOne("select count(*) from `".BIT_DB_PREFIX."users_users`",array()); - if( $gBitSystem->isPackageActive( 'tidbits' ) ) { - $stats["bookmarks"] = $this->mDb->getOne("select count(*) from `".BIT_DB_PREFIX."tidbits_bookmarks_urls`",array()); - $stats["bpu"] = ($stats["users"] ? $stats["bookmarks"] / $stats["users"] : 0); - } - return $stats; - } - - function site_stats() { - $stats = array(); - $stats["started"] = $this->mDb->getOne("select min(`stats_day`) from `".BIT_DB_PREFIX."stats_pageviews`",array()); - $stats["days"] = $this->mDb->getOne("select count(*) from `".BIT_DB_PREFIX."stats_pageviews`",array()); - $stats["pageviews"] = $this->mDb->getOne("select sum(`pageviews`) from `".BIT_DB_PREFIX."stats_pageviews`"); - $stats["ppd"] = ($stats["days"] ? $stats["pageviews"] / $stats["days"] : 0); - $stats["bestpvs"] = $this->mDb->getOne("select max(`pageviews`) from `".BIT_DB_PREFIX."stats_pageviews`",array()); - $stats["bestday"] = $this->mDb->getOne("select `stats_day` from `".BIT_DB_PREFIX."stats_pageviews` where `pageviews`=?",array((int)$stats["bestpvs"])); - $stats["worstpvs"] = $this->mDb->getOne("select min(`pageviews`) from `".BIT_DB_PREFIX."stats_pageviews`",array()); - $stats["worstday"] = $this->mDb->getOne("select `stats_day` from `".BIT_DB_PREFIX."stats_pageviews` where `pageviews`=?",array((int)$stats["worstpvs"])); - return $stats; - } - - // Stats //// - /*shared*/ - function add_pageview() { - $dayzero = mktime(0, 0, 0, date("m"), date("d"), date("Y")); - $this->mDb->StartTrans(); - $cant = $this->mDb->getOne("select count(*) from `".BIT_DB_PREFIX."stats_pageviews` where `stats_day`=?",array((int)$dayzero)); - - if ($cant) { - $query = "update `".BIT_DB_PREFIX."stats_pageviews` set `pageviews`=`pageviews`+1 where `stats_day`=?"; - } else { - $query = "insert into `".BIT_DB_PREFIX."stats_pageviews`(`stats_day`,`pageviews`) values(?,1)"; - } - $result = $this->mDb->query($query,array((int)$dayzero)); - $this->mDb->CompleteTrans(); - } - - function get_pv_chart_data( $days ) { - $now = mktime( 0, 0, 0, date( "m" ), date( "d" ), date( "Y" ) ); - $dfrom = 0; - if( $days != 0 ) $dfrom = $now - ( $days * 24 * 60 * 60 ); - - $query = "SELECT `stats_day`, `pageviews` FROM `".BIT_DB_PREFIX."stats_pageviews` WHERE `stats_day`<=? AND `stats_day`>=? ORDER BY `stats_day` ASC"; - $result = $this->mDb->query( $query,array( ( int )$now,( int )$dfrom ) ); - $ret = array(); - $n = ceil( $result->numRows() / 20 ); - $i = 0; - - while( $res = $result->fetchRow() ) { - if( $i % $n == 0 ) { - $data = array( - date( "j M Y", $res["stats_day"] ), - $res["pageviews"] - ); - } else { - $data = array( - "", - $res["pageviews"] - ); - } - $ret[] = $data; - $i++; - } - - return $ret; - } - - function get_usage_chart_data() { - global $gBitSystem, $gLibertySystem; - $ret['data'][0][] = 'a'; - foreach( $gLibertySystem->mContentTypes as $contentType ) { - if( $gBitSystem->isPackageActive( $contentType['handler_package'] ) ) { - $hits = $this->mDb->getOne( " - SELECT SUM(`hits`) - FROM `".BIT_DB_PREFIX."liberty_content` lc - LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content_hits` liberty_content_hits - ON (lc.`content_id` = liberty_content_hits.`content_id`) - WHERE content_type_guid=?", array( $contentType['content_type_guid'] ) - ); - if( !empty( $hits ) ) { - $ret['legend'][] = tra( $contentType['content_description'] ); - $ret['data'][0][] = $hits; - } - } - } - return $ret; - } - - function get_item_chart_data( $pContentTypeGuid=NULL ) { - global $gBitSystem, $gLibertySystem; - $ret['data'] = array(); - - if( in_array( $pContentTypeGuid, array_keys( $gLibertySystem->mContentTypes ) ) ) { - $query = " - SELECT `hits`, `title`, `content_type_guid` - FROM `".BIT_DB_PREFIX."liberty_content` lc - LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content_hits` liberty_content_hits - ON (lc.`content_id` = liberty_content_hits.`content_id`) - WHERE `content_type_guid`=? - ORDER BY `hits` DESC"; - $result = $this->mDb->query( $query, array( $pContentTypeGuid ), 159 ); - // this is needed to ensure all arrays have same size - $tmpHash[] = array( NULL, 0 ); - while( $res = $result->fetchRow() ) { - $tmpHash[] = array( - $res['title'], - $res['hits'], - ); - } - $ret['data'][$pContentTypeGuid] = array_chunk( $tmpHash, 40 ); - $ret['title'] = $gLibertySystem->mContentTypes[$pContentTypeGuid]['content_description']; - } else { - foreach( $gLibertySystem->mContentTypes as $contentType ) { - if( $gBitSystem->isPackageActive( $contentType['handler_package'] ) ) { - $query = " - SELECT `hits`, `title`, `content_type_guid` - FROM `".BIT_DB_PREFIX."liberty_content` lc - LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content_hits` liberty_content_hits - ON (lc.`content_id` = liberty_content_hits.`content_id`) - WHERE `content_type_guid`=? - ORDER BY `hits` DESC"; - $result = $this->mDb->query( $query, array( $contentType['content_type_guid'] ), 40 ); - // this is needed to ensure all arrays have same size - $ret['data'][$contentType['content_type_guid']] = array_fill( 0, 40, array( NULL, NULL ) ); - $i = 0; - while( $res = $result->fetchRow() ) { - $ret['data'][$contentType['content_type_guid']][$i++] = array( - $res['title'], - $res['hits'], - ); - } - } - } - $ret['title'] = 'All Content'; - } - $ret['max'] = $this->mDb->getOne( " - SELECT MAX(`hits`) - FROM `".BIT_DB_PREFIX."liberty_content` lc - LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content_hits` liberty_content_hits - ON (lc.`content_id` = liberty_content_hits.`content_id`) - "); - return $ret; - } -} - -global $statslib; -$statslib = new StatsLib(); - -?> diff --git a/templates/referer_stats.tpl b/templates/referer_stats.tpl index c6a5df7..7a43de5 100644 --- a/templates/referer_stats.tpl +++ b/templates/referer_stats.tpl @@ -6,28 +6,28 @@ </div> <div class="body"> + <a href="{$smarty.const.STATS_PKG_URL}referer_stats.php?clear=1">{tr}Clear Referer Statistics{/tr}</a> + {minifind} <table class="data"> <caption>{tr}Referer Statistics{/tr}</caption> <tr> - <th>{smartlink ititle="Hits" isort=hits iorder=desc idefault=1 offset=$offset}</th> + <th style="width:5%;">{smartlink ititle="Hits" isort=hits iorder=desc idefault=1 offset=$offset}</th> <th>{smartlink ititle="Referer" isort=referer offset=$offset}</th> - <th>{smartlink ititle="Last Hit" isort=last offset=$offset}</th> + <th style="width:15%;">{smartlink ititle="Last Hit" isort=last offset=$offset}</th> </tr> - {section name=user loop=$referers} + {section name=ix loop=$referers} <tr class="{cycle values='odd,even'}"> - <td style="text-align:right;">{$referers[user].hits}</td> - <td>{$referers[user].referer}</td> - <td style="text-align:right;">{$referers[user].last|bit_short_datetime}</td> + <td style="text-align:right;">{$referers[ix].hits}</td> + <td><a href="{$referers[ix].referer}">{$referers[ix].referer}</a></td> + <td style="text-align:right;">{$referers[ix].last|bit_short_datetime}</td> </tr> {sectionelse} <tr class="norecords"><td colspan="3">{tr}No records found{/tr}</td></tr> {/section} </table> - - <a href="{$smarty.const.STATS_PKG_URL}referer_stats.php?clear=1">{tr}clear stats{/tr}</a> </div> <!-- end .body --> {include file="bitpackage:kernel/pagination.tpl"} diff --git a/templates/stats.tpl b/templates/stats.tpl index c3cf91a..6b835d9 100644 --- a/templates/stats.tpl +++ b/templates/stats.tpl @@ -1,164 +1,65 @@ -{* $Header: /cvsroot/bitweaver/_bit_stats/templates/stats.tpl,v 1.7 2005/12/29 18:27:48 squareing Exp $ *} +{* $Header: /cvsroot/bitweaver/_bit_stats/templates/stats.tpl,v 1.8 2007/06/22 12:35:26 squareing Exp $ *} <div class="display statistics"> <div class="header"> <h1>{tr}Stats{/tr}</h1> </div> <div class="body"> - <div class="navbar"> - <ul> - <li><a href="#site_stats">{tr}Site{/tr}</a></li> - {if $wiki_stats}<li><a href="#wiki_stats">{tr}Wiki{/tr}</a></li>{/if} - {if $igal_stats}<li><a href="#igal_stats">{tr}Image galleries{/tr}</a></li>{/if} - {if $fgal_stats}<li><a href="#fgal_stats">{tr}File galleries{/tr}</a></li>{/if} - {if $cms_stats}<li><a href="#cms_stats">{tr}Articles{/tr}</a></li>{/if} - {if $forum_stats}<li><a href="#forum_stats">{tr}Forums{/tr}</a></li>{/if} - {if $blog_stats}<li><a href="#blog_stats">{tr}Weblogs{/tr}</a></li>{/if} - {if $poll_stats}<li><a href="#poll_stats">{tr}Polls{/tr}</a></li>{/if} - {if $faq_stats}<li><a href="#faq_stats">{tr}FAQs{/tr}</a></li>{/if} - {if $user_stats}<li><a href="#user_stats">{tr}Users{/tr}</a></li>{/if} - {if $quiz_stats}<li><a href="#quiz_stats">{tr}Quizzes{/tr}</a></li>{/if} - </ul> - </div> - - <a name="site_stats"></a> - <table class="clear data"> - <caption>{tr}Site Statistics{/tr}</caption> - <tr><th colspan="2">{tr}Global Stats{/tr}</th></tr> - <tr class="{cycle values="odd,even"}"><td>{tr}Started{/tr}</td><td style="text-align:right;">{$site_stats.started|bit_short_date}</td></tr> - <tr class="{cycle}"><td>{tr}Days online{/tr}</td><td style="text-align:right;">{$site_stats.days}</td></tr> - <tr class="{cycle}"><td>{tr}Total pageviews{/tr}</td><td style="text-align:right;">{$site_stats.pageviews}</td></tr> - <tr class="{cycle}"><td>{tr}Average pageviews per day{/tr}</td><td style="text-align:right;">{$site_stats.ppd|string_format:"%.2f"}</td></tr> - <tr class="{cycle}"><td>{tr}Best day{/tr}</td><td style="text-align:right;">{$site_stats.bestday|bit_short_date} ({$site_stats.bestpvs} {tr}pvs{/tr})</td></tr> - <tr class="{cycle}"><td>{tr}Worst day{/tr}</td><td style="text-align:right;">{$site_stats.worstday|bit_short_date} ({$site_stats.worstpvs} {tr}pvs{/tr})</td></tr> - <tr><td colspan="2"> </td></tr> - <!-- Site stats --> - - <!-- Wiki Stats --> - {if $wiki_stats} - <tr><th colspan="2"><a name="wiki_stats"></a>{tr}Wiki Stats{/tr}</th></tr> - <tr class="{cycle}"><td>{tr}Wiki Pages{/tr}</td><td style="text-align:right;">{$wiki_stats.pages}</td></tr> - <tr class="{cycle}"><td>{tr}Size of Wiki Pages{/tr}</td><td style="text-align:right;">{$wiki_stats.size} {tr}Mb{/tr}</td></tr> - <tr class="{cycle}"><td>{tr}Average page length{/tr}</td><td style="text-align:right;">{$wiki_stats.bpp|string_format:"%.2f"} {tr}bytes{/tr}</td></tr> - <tr class="{cycle}"><td>{tr}Versions{/tr}</td><td style="text-align:right;">{$wiki_stats.versions}</td></tr> - <tr class="{cycle}"><td>{tr}Average versions per page{/tr}</td><td style="text-align:right;">{$wiki_stats.vpp|string_format:"%.2f"}</td></tr> - <tr class="{cycle}"><td>{tr}Visits to wiki pages{/tr}</td><td style="text-align:right;">{$wiki_stats.visits}</td></tr> - <tr class="{cycle}"><td>{tr}Orphan pages{/tr}</td><td style="text-align:right;">{$wiki_stats.orphan}</td></tr> - <tr class="{cycle}"><td>{tr}Average links per page{/tr}</td><td style="text-align:right;">{$wiki_stats.lpp|string_format:"%.2f"}</td></tr> - <tr><td colspan="2"> </td></tr> - {/if} - <!-- Wiki Stats --> - - <!-- Image gallleries stats --> - {if $igal_stats} - <tr><th colspan="2"><a name="igal_stats"></a>{tr}Image galleries Stats{/tr}</th></tr> - <tr class="{cycle}"><td>{tr}Galleries{/tr}</td><td style="text-align:right;">{$igal_stats.galleries}</td></tr> - <tr class="{cycle}"><td>{tr}Images{/tr}</td><td style="text-align:right;">{$igal_stats.images}</td></tr> - <tr class="{cycle}"><td>{tr}Average images per gallery{/tr}</td><td style="text-align:right;">{$igal_stats.ipg|string_format:"%.2f"}</td></tr> - <tr class="{cycle}"><td>{tr}Total size of images{/tr}</td><td style="text-align:right;">{$igal_stats.size} {tr}Mb{/tr}</td></tr> - <tr class="{cycle}"><td>{tr}Average image size{/tr}</td><td style="text-align:right;">{$igal_stats.bpi|string_format:"%.2f"} {tr}bytes{/tr}</td></tr> - <tr class="{cycle}"><td>{tr}Visits to image galleries{/tr}</td><td style="text-align:right;">{$igal_stats.visits}</td></tr> - <tr><td colspan="2"> </td></tr> - {/if} - <!-- Image gallleries stats --> - - <!-- File gallleries stats --> - {if $fgal_stats} - <tr><th colspan="2"><a name="fgal_stats"></a>{tr}File galleries Stats{/tr}</th></tr> - <tr class="{cycle}"><td>{tr}Galleries{/tr}</td><td style="text-align:right;">{$fgal_stats.galleries}</td></tr> - <tr class="{cycle}"><td>{tr}Files{/tr}</td><td style="text-align:right;">{$fgal_stats.files}</td></tr> - <tr class="{cycle}"><td>{tr}Average files per gallery{/tr}</td><td style="text-align:right;">{$fgal_stats.fpg|string_format:"%.2f"}</td></tr> - <tr class="{cycle}"><td>{tr}Total size of files{/tr}</td><td style="text-align:right;">{$fgal_stats.size} {tr}Mb{/tr}</td></tr> - <tr class="{cycle}"><td>{tr}Average file size{/tr}</td><td style="text-align:right;">{$fgal_stats.bpf|string_format:"%.2f"} {tr}Mb{/tr}</td></tr> - <tr class="{cycle}"><td>{tr}Visits to file galleries{/tr}</td><td style="text-align:right;">{$fgal_stats.visits}</td></tr> - <tr class="{cycle}"><td>{tr}Downloads{/tr}</td><td style="text-align:right;">{$fgal_stats.downloads}</td></tr> - <tr><td colspan="2"> </td></tr> - {/if} - <!-- File gallleries stats --> - - <!-- CMS stats --> - {if $cms_stats} - <tr><th colspan="2"><a name="cms_stats"></a>{tr}CMS Stats{/tr}</th></tr> - <tr class="{cycle}"><td>{tr}Articles{/tr}</td><td style="text-align:right;">{$cms_stats.articles}</td></tr> - <tr class="{cycle}"><td>{tr}Total reads{/tr}</td><td style="text-align:right;">{$cms_stats.reads}</td></tr> - <tr class="{cycle}"><td>{tr}Average reads per article{/tr}</td><td style="text-align:right;">{$cms_stats.rpa|string_format:"%.2f"}</td></tr> - {* - <tr class="{cycle}"><td>{tr}Total articles size{/tr}</td><td style="text-align:right;">{$cms_stats.size} {tr}bytes{/tr}</td></tr> - <tr class="{cycle}"><td>{tr}Average article size{/tr}</td><td style="text-align:right;">{$cms_stats.bpa|string_format:"%.2f"} {tr}bytes{/tr}</td></tr> - *} - <tr class="{cycle}"><td>{tr}Topics{/tr}</td><td style="text-align:right;">{$cms_stats.topics}</td></tr> - <tr><td colspan="2"> </td></tr> - {/if} - <!-- CMS stats --> - - <!-- Forum stats --> - {if $forum_stats} - <tr><th colspan="2"><a name="forum_stats"></a>{tr}Forum Stats{/tr}</th></tr> - <tr class="{cycle}"><td>{tr}Forums{/tr}</td><td style="text-align:right;">{$forum_stats.forums}</td></tr> - <tr class="{cycle}"><td>{tr}Total topics{/tr}</td><td style="text-align:right;">{$forum_stats.topics}</td></tr> - <tr class="{cycle}"><td>{tr}Average topics per forums{/tr}</td><td style="text-align:right;">{$forum_stats.tpf|string_format:"%.2f"}</td></tr> - <tr class="{cycle}"><td>{tr}Total threads{/tr}</td><td style="text-align:right;">{$forum_stats.threads}</td></tr> - <tr class="{cycle}"><td>{tr}Average threads per topic{/tr}</td><td style="text-align:right;">{$forum_stats.tpt|string_format:"%.2f"}</td></tr> - <tr class="{cycle}"><td>{tr}Visits to forums{/tr}</td><td style="text-align:right;">{$forum_stats.visits}</td></tr> - <tr><td colspan="2"> </td></tr> - {/if} - <!-- Forum stats --> + <table class="data"> + <caption>{tr}Global Statistics{/tr}</caption> + <tr class="{cycle values="odd,even"}"><td>{tr}Started{/tr}</td><td style="text-align:right;">{$siteStats.started|bit_short_date}</td></tr> + <tr class="{cycle}"><td>{tr}Days online{/tr}</td><td style="text-align:right;">{$siteStats.days}</td></tr> + <tr class="{cycle}"><td>{tr}Total pageviews{/tr}</td><td style="text-align:right;">{$siteStats.pageviews}</td></tr> + <tr class="{cycle}"><td>{tr}Average pageviews per day{/tr}</td><td style="text-align:right;">{$siteStats.ppd|string_format:"%.2f"}</td></tr> + <tr class="{cycle}"><td>{tr}Best day{/tr}</td><td style="text-align:right;">{$siteStats.bestday|bit_short_date} ({$siteStats.bestpvs} {tr}pageviews{/tr})</td></tr> + <tr class="{cycle}"><td>{tr}Worst day{/tr}</td><td style="text-align:right;">{$siteStats.worstday|bit_short_date} ({$siteStats.worstpvs} {tr}pageviews{/tr})</td></tr> + </table> - <!-- Blogs stats --> - {if $blog_stats} - <tr><th colspan="2"><a name="blog_stats"></a>{tr}Blog Stats{/tr}</th></tr> - <tr class="{cycle}"><td>{tr}Weblogs{/tr}</td><td style="text-align:right;">{$blog_stats.blogs}</td></tr> - <tr class="{cycle}"><td>{tr}Total posts{/tr}</td><td style="text-align:right;">{$blog_stats.posts}</td></tr> - <tr class="{cycle}"><td>{tr}Average posts per weblog{/tr}</td><td style="text-align:right;">{$blog_stats.ppb|string_format:"%.2f"}</td></tr> - <tr class="{cycle}"><td>{tr}Visits to weblogs{/tr}</td><td style="text-align:right;">{$blog_stats.visits}</td></tr> - <tr><td colspan="2"> </td></tr> - {/if} - <!-- Blogs stats --> + <br /><hr /><br /> - <!-- Poll stats --> - {if $poll_stats} - <tr><th colspan="2"><a name="poll_stats"></a>{tr}Poll Stats{/tr}</th></tr> - <tr class="{cycle}"><td>{tr}Polls{/tr}</td><td style="text-align:right;">{$poll_stats.polls}</td></tr> - <tr class="{cycle}"><td>{tr}Total votes{/tr}</td><td style="text-align:right;">{$poll_stats.votes}</td></tr> - <tr class="{cycle}"><td>{tr}Average votes per poll{/tr}</td><td style="text-align:right;">{$poll_stats.vpp|string_format:"%.2f"}</td></tr> - <tr><td colspan="2"> </td></tr> - {/if} - <!-- Poll stats --> + <table class="data"> + <caption>{tr}Site Overview{/tr}</caption> + <tr> + <th>{smartlink ititle="Content Type" isort=content_type_guid}</th> + <th style="width:10%;">{smartlink ititle="# of Records" iorder=desc isort=content_count}</th> + <th style="width:10%;">{smartlink ititle="# of Hits" iorder=desc isort=total_hits}</th> + </tr> - <!-- FAQ stats --> - {if $faq_stats} - <tr><th colspan="2"><a name="faq_stats"></a>{tr}Faq Stats{/tr}</th></tr> - <tr class="{cycle}"><td>{tr}FAQs{/tr}</td><td style="text-align:right;">{$faq_stats.faqs}</td></tr> - <tr class="{cycle}"><td>{tr}Total questions{/tr}</td><td style="text-align:right;">{$faq_stats.questions}</td></tr> - <tr class="{cycle}"><td>{tr}Average questions per FAQ{/tr}</td><td style="text-align:right;">{$faq_stats.qpf|string_format:"%.2f"}</td></tr> - <tr><td colspan="2"> </td></tr> - {/if} - <!-- FAQ stats --> + {foreach from=$contentOverview item=site key=guid} + <tr class="{cycle values="odd,even"}"> + <td>{if $contentStats.$guid}<a href="#{$guid}">{/if}{$gLibertySystem->getContentTypeDescription($guid)}{if $contentStats.$guid}</a>{/if}</td> + <td style="text-align:right;">{$site.content_count}</td> + <td style="text-align:right;">{$site.total_hits|default:0}</td> + </tr> + {/foreach} + </table> - <!-- Users stats --> - {if $user_stats} - <tr><th colspan="2"><a name="user_stats"></a>{tr}User Stats{/tr}</th></tr> - <tr class="{cycle}"><td>{tr}<a href="{$smarty.const.STATS_PKG_URL}users.php">Users</a>{/tr}</td><td style="text-align:right;">{$user_stats.users}</td></tr> - <tr class="{cycle}"><td>{tr}User bookmarks{/tr}</td><td style="text-align:right;">{$user_stats.bookmarks}</td></tr> - <tr class="{cycle}"><td>{tr}Average bookmarks per user{/tr}</td><td style="text-align:right;">{$user_stats.bpu|string_format:"%.2f"}</td></tr> - <tr><td colspan="2"> </td></tr> - {/if} - <!-- Usersstats --> + <br /><hr /><br /> - <!-- Quiz stats --> - {if $quiz_stats} - <tr><th colspan="2"><a name="quiz_stats"></a>{tr}Quiz Stats{/tr}</th></tr> - <tr class="{cycle}"><td>{tr}Quizzes{/tr}</td><td style="text-align:right;">{$quiz_stats.quizzes}</td></tr> - <tr class="{cycle}"><td>{tr}Questions{/tr}</td><td style="text-align:right;">{$quiz_stats.questions}</td></tr> - <tr class="{cycle}"><td>{tr}Average questions per quiz{/tr}</td><td style="text-align:right;">{$quiz_stats.qpq|string_format:"%.2f"}</td></tr> - <tr class="{cycle}"><td>{tr}Quizzes taken{/tr}</td><td style="text-align:right;">{$quiz_stats.visits}</td></tr> - <tr class="{cycle}"><td>{tr}Average quiz score{/tr}</td><td style="text-align:right;">{$quiz_stats.avg|string_format:"%.2f"}</td></tr> - <tr class="{cycle}"><td>{tr}Average time per quiz{/tr}</td><td style="text-align:right;">{$quiz_stats.avgtime|string_format:"%.2f"} {tr}seconds{/tr}</td></tr> - <tr><td colspan="2"> </td></tr> - {/if} - <!-- Quiz stats --> + <table class="data"> + <caption>{tr}Package Statistics{/tr}</caption> + {foreach from=$contentStats item=stats key=guid} + <tr> + <th colspan="2">{$gLibertySystem->getContentTypeDescription($guid)}</th> + </tr> + <a name="{$guid}"></a> + {foreach from=$stats item=item} + <tr class="{cycle values="odd,even"}"> + <td>{$item.label}</td> + <td style="width:20%; text-align:right;"> + {if $item.modifier == 'display_bytes'} + {$item.value|display_bytes} + {else} + {$item.value} + {/if} + </td> + </tr> + {/foreach} + {/foreach} </table> + <br /><hr /><br /> + <h1>{tr}Graph options{/tr}</h1> {legend legend="Individual Package Statistics"} <div class="row"> @@ -204,7 +105,7 @@ <div class="row"> {formlabel label="Stats Period" for="days"} {forminput} - <input type="text" name="days" id="days" size="5" value="{$days}" /> {tr}days{/tr} + <input type="text" name="days" id="days" size="5" value="{$smarty.request.days}" /> {tr}days{/tr} {formhelp note="Number of days you want the graph to include. Insert 0 for full duration of your site."} {/forminput} </div> @@ -214,10 +115,10 @@ </div> {/form} - {if $pv_chart eq 'y'} + {if $smarty.request.pv_chart} <a name="pv_chart"></a> <div style="text-align:center;"> - <img src="{$smarty.const.STATS_PKG_URL}pv_chart.php?days={$days}" alt="Site Usage Statistics" /> + <img src="{$smarty.const.STATS_PKG_URL}pv_chart.php?days={$smarty.request.days}" alt="Site Usage Statistics" /> </div> {/if} </div> <!-- end .body --> diff --git a/usage_chart.php b/usage_chart.php index ff2f955..15f21a2 100644 --- a/usage_chart.php +++ b/usage_chart.php @@ -1,6 +1,6 @@ <?php /** - * $Header: /cvsroot/bitweaver/_bit_stats/usage_chart.php,v 1.4 2006/04/11 13:09:28 squareing Exp $ + * $Header: /cvsroot/bitweaver/_bit_stats/usage_chart.php,v 1.5 2007/06/22 12:35:26 squareing Exp $ * * Copyright (c) 2004 bitweaver.org * Copyright (c) 2003 tikwiki.org @@ -8,7 +8,7 @@ * All Rights Reserved. See copyright.txt for details and a complete list of authors. * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details * - * $Id: usage_chart.php,v 1.4 2006/04/11 13:09:28 squareing Exp $ + * $Id: usage_chart.php,v 1.5 2007/06/22 12:35:26 squareing Exp $ * @package stats * @subpackage functions */ @@ -24,8 +24,9 @@ global $gBitSystem; $gBitSystem->isPackageActive( 'stats' ); $gBitSystem->verifyPermission( 'p_stats_view' ); -// data to be displayed -$data = $statslib->get_usage_chart_data(); +$stats = new Statistics(); + +$data = $stats->getUsageChartData(); $chart_type = !empty( $_REQUEST['chart_type'] ) ? $_REQUEST['chart_type'] : 'bars'; @@ -1,12 +1,12 @@ <?php /** - * $Header: /cvsroot/bitweaver/_bit_stats/users.php,v 1.6 2006/04/11 13:09:28 squareing Exp $ + * $Header: /cvsroot/bitweaver/_bit_stats/users.php,v 1.7 2007/06/22 12:35:26 squareing Exp $ * * Copyright (c) 2005 bitweaver.org * All Rights Reserved. See copyright.txt for details and a complete list of authors. * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details * - * $Id: users.php,v 1.6 2006/04/11 13:09:28 squareing Exp $ + * $Id: users.php,v 1.7 2007/06/22 12:35:26 squareing Exp $ * @package stats * @subpackage functions */ @@ -16,23 +16,18 @@ require_once( '../bit_setup_inc.php' ); include_once( STATS_PKG_PATH.'stats_lib.php' ); -global $statslib, $gBitSystem; +$stats = new Statistics(); $gBitSystem->verifyPackage( 'stats' ); - $gBitSystem->verifyPermission( 'p_stats_view' ); -if (!isset($_REQUEST["period"])) { +if( !isset( $_REQUEST["period"] )) { $_REQUEST["period"] = 'month'; } +$gBitSmarty->assign( 'userStats', $stats->registrationStats( $_REQUEST["period"] )); $gBitSmarty->assign( 'period', $_REQUEST["period"] ); -$stats = $statslib->registrationStats( $_REQUEST["period"] ); - -$gBitSmarty->assign_by_ref( 'userStats', $stats ); - // Display the template $gBitSystem->display( 'bitpackage:stats/user_stats.tpl'); - -?>
\ No newline at end of file +?> |
