diff options
| author | lsces <lester@lsces.co.uk> | 2025-08-27 17:26:04 +0100 |
|---|---|---|
| committer | lsces <lester@lsces.co.uk> | 2025-08-27 17:26:04 +0100 |
| commit | a57c635d8319f914f82eb5937eedd79aabba46e8 (patch) | |
| tree | 9a527e565fa932705d8360f620d3bc0267a8a949 | |
| parent | e4091e0a8778d65dbf0a8252c362aea9644fbf8c (diff) | |
| download | stats-a57c635d8319f914f82eb5937eedd79aabba46e8.tar.gz stats-a57c635d8319f914f82eb5937eedd79aabba46e8.tar.bz2 stats-a57c635d8319f914f82eb5937eedd79aabba46e8.zip | |
Code updated to PHP8.4 and namespace
| -rw-r--r-- | admin/admin_stats_inc.php | 47 | ||||
| -rw-r--r-- | admin/schema_inc.php | 50 | ||||
| -rw-r--r-- | admin/upgrade_inc.php | 29 | ||||
| -rw-r--r-- | includes/bit_setup_inc.php | 47 | ||||
| -rw-r--r-- | includes/classes/Statistics.php | 123 | ||||
| -rw-r--r-- | index.php | 8 | ||||
| -rw-r--r-- | item_chart.php | 8 | ||||
| -rw-r--r-- | pv_chart.php | 19 | ||||
| -rw-r--r-- | referrers.php | 33 | ||||
| -rw-r--r-- | templates/index.php | 2 | ||||
| -rw-r--r-- | usage_chart.php | 21 | ||||
| -rw-r--r-- | users.php | 13 |
12 files changed, 192 insertions, 208 deletions
diff --git a/admin/admin_stats_inc.php b/admin/admin_stats_inc.php index 21bd8ac..24f73ca 100644 --- a/admin/admin_stats_inc.php +++ b/admin/admin_stats_inc.php @@ -1,35 +1,38 @@ <?php -$formFeaturesBit = array( - 'stats_referers' => array( +$formFeaturesBit = [ + 'stats_referers' => [ 'label' => 'Referer Statistics', - 'type' => "checkbox", - 'note' => 'Records statistics including HTTP_REFERRER', - ), - 'google_tagmanager_id' => array( + 'type' => "checkbox", + 'note' => 'Records statistics including HTTP_REFERRER', + ], + 'google_tagmanager_id' => [ 'label' => "Google TagManager Container ID for GA4", - 'type' => "text", - 'note' => "TagManager Container ID, which should be conected to your GA4 measurement ID; e.g. GTM-ABCD1234 See from https://tagmanager.google.com", - ), - 'google_analytics_ua' => array( + 'type' => "text", + 'note' => "TagManager Container ID, which should be conected to your GA4 measurement ID; e.g. GTM-ABCD1234 See from https://tagmanager.google.com", + ], + 'google_analytics_ua' => [ 'label' => "Google Analytics UA (DISCONTINUED)", - 'type' => "text", - 'note' => "UA from anayltics.google.com; discontinued June 30, 2023", - ), - 'microsoft_analytics_ti' => array( + 'type' => "text", + 'note' => "UA from anayltics.google.com; discontinued June 30, 2023", + ], + 'microsoft_analytics_ti' => [ 'label' => "Microsoft Analytics TI", - 'type' => "text", - 'note' => "TI from ads.microsoft.com conversion javascript", - ), -); + 'type' => "text", + 'note' => "TI from ads.microsoft.com conversion javascript", + ], +]; $gBitSmarty->assign( 'formFeaturesBit', $formFeaturesBit ); if( !empty( $_POST['change_prefs'] ) ) { foreach ( array_keys( $formFeaturesBit ) as $feature) { - if( $formFeaturesBit[$feature]['type'] == 'text' ) { - simple_set_value( $feature, STATS_PKG_NAME ); - } else { - simple_set_toggle( $feature, STATS_PKG_NAME ); + switch ($formFeaturesBit[$feature]['type']) { + case 'text': + simple_set_value( $feature, STATS_PKG_NAME ); + break; + default: + simple_set_toggle( $feature, STATS_PKG_NAME ); + break; } } } diff --git a/admin/schema_inc.php b/admin/schema_inc.php index 5fc0e0c..4142e7e 100644 --- a/admin/schema_inc.php +++ b/admin/schema_inc.php @@ -1,31 +1,31 @@ <?php -$tables = array( +$tables = [ -'stats_referers' => " + 'stats_referers' => " referer C(50) NOTNULL, hits I8, last I8 ", -'stats_pageviews' => " + 'stats_pageviews' => " stats_day I8 PRIMARY, pageviews I8 ", -'stats_referer_urls' => " + 'stats_referer_urls' => " referer_url_id I4 PRIMARY, referer_url C(4096) NOTNULL ", -'stats_referer_users_map' => " + 'stats_referer_users_map' => " referer_url_id I4 PRIMARY, user_id I4 PRIMARY CONSTRAINT ' - , CONSTRAINT `stats_referer_users_url_ref` FOREIGN KEY (`referer_url_id`) REFERENCES `".BIT_DB_PREFIX."stats_referer_urls` (`referer_url_id`) - , CONSTRAINT `stats_referer_users_user_ref` FOREIGN KEY (`user_id`) REFERENCES `".BIT_DB_PREFIX."users_users` (`user_id`) ' -", -); + , CONSTRAINT `stats_referer_users_url_ref` FOREIGN KEY (`referer_url_id`) REFERENCES `" . BIT_DB_PREFIX . "stats_referer_urls` (`referer_url_id`) + , CONSTRAINT `stats_referer_users_user_ref` FOREIGN KEY (`user_id`) REFERENCES `" . BIT_DB_PREFIX . "users_users` (`user_id`) ' +", +]; global $gBitInstaller; @@ -33,35 +33,35 @@ foreach( array_keys( $tables ) AS $tableName ) { $gBitInstaller->registerSchemaTable( STATS_PKG_NAME, $tableName, $tables[$tableName] ); } -$gBitInstaller->registerPackageInfo( STATS_PKG_NAME, array( +$gBitInstaller->registerPackageInfo( STATS_PKG_NAME, [ 'description' => "Stats collects and display information about your site.", - 'license' => '<a href="http://www.gnu.org/licenses/licenses.html#LGPL">LGPL</a>', -) ); + 'license' => '<a href="http://www.gnu.org/licenses/licenses.html#LGPL">LGPL</a>', +] ); // ### Indexes $indices = array ( - 'stats_referer_url_idx' => array( 'table' => 'stats_referer_urls', 'cols' => 'referer_url', 'opts' => 'UNIQUE' ), - 'stats_referer_map_user_idx' => array( 'table' => 'stats_referer_users_map', 'cols' => 'user_id', 'opts' => NULL ), + 'stats_referer_url_idx' => [ 'table' => 'stats_referer_urls', 'cols' => 'referer_url', 'opts' => 'UNIQUE' ], + 'stats_referer_map_user_idx' => [ 'table' => 'stats_referer_users_map', 'cols' => 'user_id', 'opts' => null ], ); -// 'stats_referer_map_url_idx' => array( 'table' => 'stats_referer_urls', 'cols' => 'referer_url_id', 'opts' => NULL ), +// 'stats_referer_map_url_idx' => [ 'table' => 'stats_referer_urls', 'cols' => 'referer_url_id', 'opts' => NULL ], $gBitInstaller->registerSchemaIndexes( STATS_PKG_NAME, $indices ); // ### Sequences $sequences = array ( - 'stats_referer_url_id_seq' => array( 'start' => 1 ) + 'stats_referer_url_id_seq' => [ 'start' => 1 ] ); $gBitInstaller->registerSchemaSequences( STATS_PKG_NAME, $sequences ); // ### Default Preferences -$gBitInstaller->registerPreferences( STATS_PKG_NAME, array( - array(STATS_PKG_NAME, 'stats_referers','y'), - array(STATS_PKG_NAME, 'stats_pageviews','y') -) ); +$gBitInstaller->registerPreferences( STATS_PKG_NAME, [ + [ STATS_PKG_NAME, 'stats_referers', 'y' ], + [ STATS_PKG_NAME, 'stats_pageviews', 'y' ], +] ); // ### Default UserPermissions -$gBitInstaller->registerUserPermissions( STATS_PKG_NAME, array( - array('p_stats_admin', 'Can admin stats', 'admin', STATS_PKG_NAME), - array('p_stats_view_referer', 'Can view referer stats', 'editors', STATS_PKG_NAME), - array('p_stats_view', 'Can view site stats', 'editors', STATS_PKG_NAME), -) ); +$gBitInstaller->registerUserPermissions( STATS_PKG_NAME, [ + [ 'p_stats_admin', 'Can admin stats', 'admin', STATS_PKG_NAME ], + [ 'p_stats_view_referer', 'Can view referer stats', 'editors', STATS_PKG_NAME ], + [ 'p_stats_view', 'Can view site stats', 'editors', STATS_PKG_NAME ], +] ); diff --git a/admin/upgrade_inc.php b/admin/upgrade_inc.php deleted file mode 100644 index acc3181..0000000 --- a/admin/upgrade_inc.php +++ /dev/null @@ -1,29 +0,0 @@ -<?php - -global $gBitSystem, $gUpgradeFrom, $gUpgradeTo; - -$upgrades = array( - - 'BWR1' => array( - 'BWR2' => array( -// de-tikify tables -array( 'DATADICT' => array( - array( 'RENAMETABLE' => array( - 'tiki_referer_stats' => 'stats_referers', - 'tiki_pageviews' => 'stats_pageviews', - )), - array( 'RENAMECOLUMN' => array( - 'stats_pageviews' => array( - '`day`' => '`stats_day` I8 PRIMARY' - ), - )), -)), - ) - ), - -); - -if( isset( $upgrades[$gUpgradeFrom][$gUpgradeTo] ) ) { - $gBitSystem->registerUpgrade( STATS_PKG_NAME, $upgrades[$gUpgradeFrom][$gUpgradeTo] ); -} -?> diff --git a/includes/bit_setup_inc.php b/includes/bit_setup_inc.php index adb5695..a408412 100644 --- a/includes/bit_setup_inc.php +++ b/includes/bit_setup_inc.php @@ -1,28 +1,39 @@ <?php +use Bitweaver\Stats\Statistics; + global $gBitSystem, $gBitUser ; -$registerHash = array( +$pRegisterHash = [ 'package_name' => 'stats', - 'package_path' => dirname( dirname( __FILE__ ) ).'/', -); -$gBitSystem->registerPackage( $registerHash ); + 'package_path' => dirname( dirname( __FILE__ ) ) . '/', +]; + +// fix to quieten down VS Code which can't see the dynamic creation of these ... +define( 'STATS_PKG_NAME', $pRegisterHash['package_name'] ); +define( 'STATS_PKG_URL', BIT_ROOT_URL . basename( $pRegisterHash['package_path'] ) . '/' ); +define( 'STATS_PKG_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/' ); +define( 'STATS_PKG_INCLUDE_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/includes/'); +define( 'STATS_PKG_CLASS_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/includes/classes/'); +define( 'STATS_PKG_ADMIN_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['package_path'] ) . '/admin/'); + +$gBitSystem->registerPackage( $pRegisterHash ); if( $gBitSystem->isPackageActive( 'stats' )) { if( $gBitUser->hasPermission( 'p_stats_view' ) || $gBitUser->hasPermission( 'p_stats_view_referer' ) ) { - $menuHash = array( + $menuHash = [ 'package_name' => STATS_PKG_NAME, - 'index_url' => STATS_PKG_URL.'index.php', + 'index_url' => STATS_PKG_URL . 'index.php', 'menu_template' => 'bitpackage:stats/menu_stats.tpl', - ); + ]; $gBitSystem->registerAppMenu( $menuHash ); } - $gLibertySystem->registerService( STATS_PKG_NAME, STATS_PKG_NAME, array( - 'users_expunge_function' => 'stats_user_expunge', - 'users_register_function' => 'stats_user_register', - ) ); + $gLibertySystem->registerService( STATS_PKG_NAME, STATS_PKG_NAME, [ + 'users_expunge_function' => 'stats_user_expunge', + 'users_register_function' => 'stats_user_register', + ] ); - require_once( STATS_PKG_CLASS_PATH.'Statistics.php' ); + require_once STATS_PKG_CLASS_PATH . 'Statistics.php'; $stats = new Statistics(); if( $gBitSystem->isFeatureActive('stats_pageviews') ) { $stats->addPageview(); @@ -49,7 +60,7 @@ if( $gBitSystem->isPackageActive( 'stats' )) { function stats_user_expunge( &$pObject ) { if( is_a( $pObject, 'BitUser' ) && !empty( $pObject->mUserId ) ) { $pObject->StartTrans(); - $pObject->mDb->query( "DELETE FROM `".BIT_DB_PREFIX."stats_referer_users_map` WHERE user_id=?", array( $pObject->mUserId ) ); + $pObject->mDb->query( "DELETE FROM `".BIT_DB_PREFIX."stats_referer_users_map` WHERE user_id=?", [ $pObject->mUserId ] ); $pObject->CompleteTrans(); } } @@ -57,11 +68,11 @@ if( $gBitSystem->isPackageActive( 'stats' )) { function stats_user_register( &$pObject ) { if( !empty( $_COOKIE['referer_url'] ) && is_a( $pObject, 'BitUser' ) && !empty( $pObject->mUserId ) ) { $pObject->StartTrans(); - if( !$refererId = $pObject->mDb->getOne( "SELECT `referer_url_id` FROM `".BIT_DB_PREFIX."stats_referer_urls` WHERE `referer_url`=?", array( $_COOKIE['referer_url'] ) ) ) { + if( !$refererId = $pObject->mDb->getOne( "SELECT `referer_url_id` FROM `".BIT_DB_PREFIX."stats_referer_urls` WHERE `referer_url`=?", [ $_COOKIE['referer_url'] ] ) ) { $refererId = $pObject->mDb->GenID( 'stats_referer_url_id_seq' ); - $pObject->mDb->query( "INSERT INTO `".BIT_DB_PREFIX."stats_referer_urls` (`referer_url_id`,`referer_url`) VALUES(?,?)", array( $refererId, $_COOKIE['referer_url'] ) ); + $pObject->mDb->query( "INSERT INTO `".BIT_DB_PREFIX."stats_referer_urls` (`referer_url_id`,`referer_url`) VALUES(?,?)", [ $refererId, $_COOKIE['referer_url'] ] ); } - $pObject->mDb->query( "INSERT INTO `".BIT_DB_PREFIX."stats_referer_users_map` (`user_id`,`referer_url_id`) VALUES(?,?)", array( $pObject->mUserId, $refererId ) ); + $pObject->mDb->query( "INSERT INTO `".BIT_DB_PREFIX."stats_referer_users_map` (`user_id`,`referer_url_id`) VALUES(?,?)", [ $pObject->mUserId, $refererId ] ); $pObject->CompleteTrans(); } } @@ -71,10 +82,10 @@ if( $gBitSystem->isPackageActive( 'stats' )) { if( ($urlHash = parse_url( $pRefererUrl )) && !empty( $urlHash['host'] ) ) { $ret = $urlHash['host']; // q= google and bing search param, p= yahoo search param - $searchStrings = array( 'q', 'p' ); + $searchStrings = [ 'q', 'p' ]; foreach( $searchStrings as $param ) { if( !empty( $urlHash['query'] ) && strpos( $urlHash['query'], $param.'=' ) !== FALSE ) { - $result = array(); + $result = []; parse_str( $urlHash['query'], $result ); if( !empty( $result[$param] ) ) { $ret .= '/...'.$param.'='.$result[$param]; diff --git a/includes/classes/Statistics.php b/includes/classes/Statistics.php index 4c222cf..1deb893 100644 --- a/includes/classes/Statistics.php +++ b/includes/classes/Statistics.php @@ -4,15 +4,26 @@ * * $Id$ * @package stats - */ +**/ /** * @package stats * @subpackage Stats - */ +**/ +namespace Bitweaver\Stats; +use Bitweaver\BitBase; +use Bitweaver\Liberty\LibertyContent; +use Bitweaver\BitDb; + + class Statistics extends BitBase { - public static function prepGetList( &$pListHash ) { + /** + * Summary of prepGetList + * @param array $pListHash + * @return void + */ + public static function prepGetList( &$pListHash ): void { if( !empty( $pListHash['period'] ) ) { $pListHash['period_format'] = BitDb::getPeriodFormat( $pListHash['period'] ); @@ -25,14 +36,13 @@ class Statistics extends BitBase { * getRefererList gets a list of referers * * @param array $pListHash - * @access public * @return array of referers */ - function getRefererList( &$pListHash ) { + public function getRefererList( &$pListHash ) { global $gBitSystem; $hashKey = ''; - $ret = $bindVars = array(); + $ret = $bindVars = []; $selectSql = $joinSql = $whereSql = $groupSql = ""; $hashSql = "uu.`user_id` AS `hash_key`, "; @@ -72,7 +82,7 @@ class Statistics extends BitBase { LEFT JOIN `".BIT_DB_PREFIX."stats_referer_users_map` srum ON(uu.`user_id`=srum.`user_id`) LEFT JOIN `".BIT_DB_PREFIX."stats_referer_urls` sru ON (sru.`referer_url_id`=srum.`referer_url_id`) $whereSql ORDER BY ".$this->mDb->convertSortmode( $pListHash['sort_mode'] ); - if( $rs = $this->mDb->query( $query, $bindVars, -1, $pListHash['offset'], ($gBitSystem->isLive() ? 3600 : BIT_QUERY_DEFAULT) ) ) { + if( $rs = $this->mDb->query( $query, $bindVars, -1, $pListHash['offset'], $gBitSystem->isLive() ? 3600 : BIT_QUERY_DEFAULT ) ) { while( $row = $rs->fetchRow() ) { $key = $row['hash_key']; @@ -96,33 +106,31 @@ class Statistics extends BitBase { LibertyContent::postGetList( $pListHash ); if( $hashKey == 'host' ) { - uasort( $ret, array( $this, 'sortRefererHash' ) ); + uasort( $ret, [ $this, 'sortRefererHash' ] ); } return $ret; } - function sortRefererHash( $a, $b ) { + public function sortRefererHash( $a, $b ) { return count( $a ) < count( $b ); } /** * expungeReferers will remove all referers unconditionally * - * @access public - * @return TRUE on success, FALSE on failure + * @return bool TRUE on success, FALSE on failure */ - function expungeReferers() { - return( $this->mDb->query( "DELETE FROM `".BIT_DB_PREFIX."stats_referers`" )); + public 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 + * @return bool TRUE on success, FALSE on failure - mErrors will contain reason for failure */ - function storeReferer() { + public function storeReferer() { global $gBitSystem; if( !empty( $_SERVER['HTTP_REFERER'] ) && $parsed = parse_url( $_SERVER['HTTP_REFERER'] )) { @@ -134,12 +142,12 @@ class Statistics extends BitBase { $this->StartTrans(); $query = "UPDATE `".BIT_DB_PREFIX."stats_referers` SET `hits`=`hits`+1,`last`=? WHERE `referer`=?"; - $this->mDb->query( $query, array( $now, $store )); + $this->mDb->query( $query, [ $now, $store ]); // if the above didn't affect the db, we know that the entry doesn't exist yet. if( !$this->mDb->Affected_Rows() ) { $query = "INSERT INTO `".BIT_DB_PREFIX."stats_referers`( `last`, `referer`, `hits` ) VALUES( ?, ?, ? )"; - $this->mDb->query( $query, array( $now, $store, 1 )); + $this->mDb->query( $query, [ $now, $store, 1 ]); } $this->CompleteTrans(); } @@ -151,18 +159,17 @@ class Statistics extends BitBase { /** * addPageview to the pageview count * - * @access public * @return void */ - function addPageview() { + public function addPageview() { $dayzero = mktime( 0, 0, 0, date( "m" ), date( "d" ), date( "Y" )); $this->mDb->StartTrans(); // base method StartTrans will clearFromCache $query = "UPDATE `".BIT_DB_PREFIX."stats_pageviews` SET `pageviews`=`pageviews`+1 WHERE `stats_day`=?"; - $this->mDb->query( $query, array( $dayzero )); + $this->mDb->query( $query, [ $dayzero ]); // if the above didn't affect the db, we know that the entry doesn't exist yet. if( !$this->mDb->Affected_Rows() ) { $query = "INSERT INTO `".BIT_DB_PREFIX."stats_pageviews`( `pageviews`, `stats_day` ) VALUES( ?, ? )"; - $this->mDb->query( $query, array( 1, $dayzero )); + $this->mDb->query( $query, [ 1, $dayzero ]); } $this->mDb->CompleteTrans(); } @@ -171,10 +178,9 @@ class Statistics extends BitBase { * registrationStats * * @param array $pPeriod - * @access public - * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure + * @return array|bool TRUE on success, FALSE on failure - mErrors will contain reason for failure */ - function registrationStats( $pPeriodFormat ) { + public function registrationStats( $pPeriodFormat ) { global $gBitDbType; $sqlPeriod = $this->mDb->SQLDate( $pPeriodFormat, $this->mDb->SQLIntToTimestamp( 'registration_date' )); @@ -192,14 +198,13 @@ class Statistics extends BitBase { /** * getSiteStats will get a brief overview over the site * - * @access public * @return array with site stats */ - function getSiteStats() { + public 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["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`" ); @@ -211,10 +216,9 @@ class Statistics extends BitBase { * 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 ) { + public function getContentOverview( $pParamHash = NULL ) { global $gLibertySystem; if( empty( $pParamHash['sort_mode'] )) { @@ -234,13 +238,12 @@ class Statistics extends BitBase { /** * 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() { + public function getContentStats() { global $gLibertySystem; - $ret = array(); + $ret = []; foreach( $gLibertySystem->mContentTypes as $guid => $type ) { if( $typeClass = $gLibertySystem->getContentClassName( $guid )) { $object = new $typeClass(); @@ -257,32 +260,27 @@ class Statistics extends BitBase { * 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 ) { + public 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 ); + 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(); + $ret = []; $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"] - ); - } + $data = ( $i % $n == 0 ) ? [ + date( "j M Y", $res["stats_day"] ), + $res["pageviews"], + ] : [ + "", + $res["pageviews"], + ]; $ret[] = $data; $i++; } @@ -293,10 +291,9 @@ class Statistics extends BitBase { /** * getUsageChartData will fetch all data needed to create a graph with PHPlot * - * @access public * @return array for PHPlot graph */ - function getUsageChartData() { + public function getUsageChartData() { global $gBitSystem, $gLibertySystem; $ret['data'][0][] = 'a'; foreach( $gLibertySystem->mContentTypes as $contentType ) { @@ -307,7 +304,7 @@ class Statistics extends BitBase { 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( $guid ) + WHERE content_type_guid=?", [ $guid ] ); if( !empty( $hits )) { $ret['legend'][] = $gLibertySystem->getContentTypeName( $guid ); @@ -321,13 +318,12 @@ class Statistics extends BitBase { /** * 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 + * @param string $pContentTypeGuid specify the content_type_guid you want to create a graph for * @return array for PHPlot graph */ - function getContentTypeChartData( $pContentTypeGuid=NULL ) { + public function getContentTypeChartData( $pContentTypeGuid = '' ) { global $gLibertySystem; - $ret['data'] = array(); + $ret['data'] = []; if( in_array( $pContentTypeGuid, array_keys( $gLibertySystem->mContentTypes ))) { $query = " @@ -337,14 +333,14 @@ class Statistics extends BitBase { ON (lc.`content_id` = liberty_content_hits.`content_id`) WHERE `content_type_guid`=? ORDER BY `hits` DESC"; - $result = $this->mDb->query( $query, array( $pContentTypeGuid ), 40 ); - $tmpHash = array(); + $result = $this->mDb->query( $query, [ $pContentTypeGuid ], 40 ); + $tmpHash = []; // this is needed to ensure all arrays have same size while( $res = $result->fetchRow() ) { - $tmpHash = array( + $tmpHash = [ $res['title'], $res['hits'], - ); + ]; } $ret['data'][$pContentTypeGuid] = array_chunk( $tmpHash, 40 ); $ret['title'] = $gLibertySystem->getContentTypeName( $pContentTypeGuid ); @@ -357,15 +353,15 @@ class Statistics extends BitBase { 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 ); + $result = $this->mDb->query( $query, [ $contentType['content_type_guid'] ], 40 ); // this is needed to ensure all arrays have same size $i = 0; - $tmpHash = array( NULL, NULL ); + $tmpHash = [ null, null ]; while( $res = $result->fetchRow() ) { - $tmpHash = array( + $tmpHash = [ $res['title'], $res['hits'], - ); + ]; } $ret['data'][$contentType['content_type_guid']] = array_chunk( $tmpHash, 40 ); } @@ -374,4 +370,3 @@ class Statistics extends BitBase { return $ret; } } -?> @@ -10,8 +10,9 @@ /** * required setup */ -require_once( '../kernel/includes/setup_inc.php' ); -require_once( STATS_PKG_CLASS_PATH.'Statistics.php' ); +require_once '../kernel/includes/setup_inc.php'; +use Bitweaver\KernelTools; +use Bitweaver\Stats\Statistics; $gBitSystem->verifyPackage( 'stats' ); $gBitSystem->verifyPermission( 'p_stats_view' ); @@ -22,5 +23,4 @@ $gBitSmarty->assign( 'siteStats', $gStats->getSiteStats() ); $gBitSmarty->assign( 'contentOverview', $gStats->getContentOverview( $_REQUEST )); $gBitSmarty->assign( 'contentStats', $gStats->getContentStats() ); -$gBitSystem->display( 'bitpackage:stats/stats.tpl', tra( "Statistics" ) , array( 'display_mode' => 'display' )); -?> +$gBitSystem->display( 'bitpackage:stats/stats.tpl', KernelTools::tra( "Statistics" ) , [ 'display_mode' => 'display' ] ); diff --git a/item_chart.php b/item_chart.php index 3703e2a..454ccc9 100644 --- a/item_chart.php +++ b/item_chart.php @@ -16,7 +16,7 @@ /** * required setup */ -require_once( '../kernel/includes/setup_inc.php' ); +require_once '../kernel/includes/setup_inc.php'; include_once( STATS_PKG_PATH . "Statistics.php" ); include_once( UTIL_PKG_INCLUDE_PATH . "phplot.php" ); global $gBitSystem; @@ -26,11 +26,11 @@ $gBitSystem->verifyPermission( 'p_stats_view' ); $stats = new Statistics(); -$data = $stats->getContentTypeChartData( !empty( $_REQUEST['content_type_guid'] ) ? $_REQUEST['content_type_guid'] : NULL ); +$data = $stats->getContentTypeChartData( !empty( $_REQUEST['content_type_guid'] ) ? $_REQUEST['content_type_guid'] : null ); $chart_type = !empty( $_REQUEST['chart_type'] ) ? $_REQUEST['chart_type'] : 'bars'; // initialise phplot and insert data -$graph =& new PHPlot( 600, 400 * ( count( $data['data'] ) ) ); +$graph = new PHPlot( 600, 400 * ( count( $data['data'] ) ) ); $graph->SetPrintImage(0); $graph->SetPlotType( $chart_type ); $graph->SetXTickPos( 'none' ); @@ -41,7 +41,7 @@ $graph->SetXLabel( tra( 'Title' ) ); $i = 0; foreach( $data['data'] as $guid => $info ) { $graph->SetDataValues( $info ); - $graph->SetDrawXDataLabels( TRUE ); + $graph->SetDrawXDataLabels( true ); $graph->SetXLabelAngle( ( count( $info ) > 5 ) ? 90 : 0 ); $graph->SetNewPlotAreaPixels( 75, 30 + ( $i * 390 ), 580, 370 + ( $i * 390 ) ); if( !empty( $_REQUEST['content_type_guid'] ) ) { diff --git a/pv_chart.php b/pv_chart.php index 0f6c767..4341f84 100644 --- a/pv_chart.php +++ b/pv_chart.php @@ -16,9 +16,11 @@ /** * required setup */ -require_once( '../kernel/includes/setup_inc.php' ); -include_once( STATS_PKG_PATH . "Statistics.php" ); -include_once( UTIL_PKG_INCLUDE_PATH . "phplot.php" ); +use Bitweaver\KernelTools; +use Bitweaver\Stats\Statistics; + +require_once '../kernel/includes/setup_inc.php'; +include_once UTIL_PKG_INCLUDE_PATH . "phplot.php"; $gBitSystem->isPackageActive( 'stats' ); $gBitSystem->verifyPermission( 'p_stats_view' ); @@ -29,14 +31,13 @@ $days = isset( $_REQUEST["days"] ) ? $_REQUEST['days'] : 7; $data = $stats->getPageviewChartData( $days ); // initialise phplot and insert data -$graph =& new PHPlot( 600, 600 ); +$graph = new PHPlot( 600, 600 ); $graph->SetDataValues( $data ); -$graph->SetTitle( tra( 'Total Pageviews' ) ); -$graph->SetYTitle( tra( 'Pageviews' ) ); -$graph->SetXTitle( tra( 'Time') ); +$graph->SetTitle( KernelTools::tra( 'Total Pageviews' ) ); +$graph->SetYTitle( KernelTools::tra( 'Pageviews' ) ); +$graph->SetXTitle( KernelTools::tra( 'Time') ); $graph->SetPlotType( ( count( $data ) > 50 ) ? 'lines' : 'linepoints' ); -$graph->SetDrawXDataLabels( TRUE ); +$graph->SetDrawXDataLabels( true ); $graph->SetXLabelAngle( 90 ); $graph->SetXTickPos('none'); $graph->DrawGraph(); -?> diff --git a/referrers.php b/referrers.php index 2c9b513..684a7a8 100644 --- a/referrers.php +++ b/referrers.php @@ -9,8 +9,11 @@ /** * required setup */ -require_once( '../kernel/includes/setup_inc.php' ); -include_once ( STATS_PKG_CLASS_PATH.'Statistics.php'); +use Bitweaver\BitBase; +use Bitweaver\KernelTools; +use Bitweaver\Stats\Statistics; + +require_once '../kernel/includes/setup_inc.php'; $gBitSystem->verifyPackage( 'stats' ); $gBitSystem->verifyFeature( 'stats_referers' ); @@ -19,7 +22,7 @@ $gBitSystem->verifyPermission( 'p_stats_view_referer' ); $gStats = new Statistics(); if( empty( $_REQUEST['period'] ) || empty( $_REQUEST['timeframe'] ) ) { - bit_redirect( STATS_PKG_URL.'users.php' ); + KernelTools::bit_redirect( STATS_PKG_URL.'users.php' ); } // get rid of all referers in the database @@ -30,7 +33,7 @@ $referers = $gStats->getRefererList( $_REQUEST ); $totalRegistrations = 0; $maxRegistrations = 0; -$aggregateStats = array(); +$aggregateStats = []; foreach( array_keys( $referers ) as $refSite ) { $refSiteCount = count( $referers[$refSite] ); $totalRegistrations += $refSiteCount; @@ -40,23 +43,23 @@ foreach( array_keys( $referers ) as $refSite ) { foreach( array_keys( $referers[$refSite] ) as $r ) { $url = parse_url( $referers[$refSite][$r]['referer_url'] ); - $revenue = array(); + $revenue = []; if( $gBitSystem->isPackageActive( 'bitcommerce' ) ) { - require_once( BITCOMMERCE_PKG_INCLUDE_PATH.'bitcommerce_start_inc.php' ); - require_once( BITCOMMERCE_PKG_CLASS_PATH.'CommerceStatistics.php' ); - $revenue = $gCommerceStatistics->getCustomerRevenue( array( 'customers_id' => $referers[$refSite][$r]['user_id'] ) ); + require_once BITCOMMERCE_PKG_INCLUDE_PATH . 'bitcommerce_start_inc.php'; + require_once BITCOMMERCE_PKG_CLASS_PATH . 'CommerceStatistics.php'; + $revenue = $gCommerceStatistics->getCustomerRevenue( [ 'customers_id' => $referers[$refSite][$r]['user_id'] ] ); $referers[$refSite][$r]['revenue'] = $revenue; - $subVals = array( $refSite ); + $subVals = [ $refSite ]; if( !empty( $url['query'] ) ) { - $urlParams = array(); + $urlParams = []; parse_str( $url['query'], $urlParams ); if( !empty( $urlParams['adurl'] ) ) { $adUrl = parse_url( $urlParams['adurl'] ); if( !empty( $adUrl['query'] ) ) { array_push( $subVals, 'PPC' ); - $adParams = array(); + $adParams = []; parse_str( $adUrl['query'], $adParams ); - foreach( array( 'ctm_campaign', 'ctm_adgroup', 'ctm_term' ) as $subKey ) { + foreach( [ 'ctm_campaign', 'ctm_adgroup', 'ctm_term' ] as $subKey ) { if( isset( $adParams[$subKey] ) ) { $subKeyVal = !empty( $adParams[$subKey] ) ? $adParams[$subKey] : 'unknown' ; array_push( $subVals, $subKeyVal ); @@ -144,10 +147,10 @@ $gBitThemes->loadCss( STATS_PKG_PATH.'css/stats.css'); $gBitThemes->loadCss( CONFIG_PKG_PATH.'themes/bootstrap/bootstrap-table/bootstrap-table.css'); $gBitThemes->loadJavascript( CONFIG_PKG_PATH.'themes/bootstrap/bootstrap-table/bootstrap-table.js'); -$gBitSmarty->assignByRef( 'aggregateStats', $aggregateStats ); -$gBitSmarty->assignByRef( 'referers', $referers ); +$gBitSmarty->assign( 'aggregateStats', $aggregateStats ); +$gBitSmarty->assign( 'referers', $referers ); $gBitSmarty->assign( 'totalRegistrations', $totalRegistrations ); $gBitSmarty->assign( 'maxRegistrations', $maxRegistrations ); $gBitSmarty->assign( 'listInfo', $_REQUEST['listInfo'] ); -$gBitSystem->display( 'bitpackage:stats/referrer_stats.tpl', tra( 'Referer Statistics' ), array( 'display_mode' => 'display' )); +$gBitSystem->display( 'bitpackage:stats/referrer_stats.tpl', KernelTools::tra( 'Referer Statistics' ), [ 'display_mode' => 'display' ]); diff --git a/templates/index.php b/templates/index.php index 3e305fe..1e6de35 100644 --- a/templates/index.php +++ b/templates/index.php @@ -2,5 +2,3 @@ // This is not a package. header ("location: ../index.php"); - -?>
\ No newline at end of file diff --git a/usage_chart.php b/usage_chart.php index da29b05..821bd02 100644 --- a/usage_chart.php +++ b/usage_chart.php @@ -15,10 +15,12 @@ /** * required setup - */ -require_once( '../kernel/includes/setup_inc.php' ); -include_once( STATS_PKG_PATH . "Statistics.php" ); -include_once( UTIL_PKG_INCLUDE_PATH . "phplot.php" ); +**/ +use Bitweaver\KernelTools; +use Bitweaver\Stats\Statistics; + +require_once '../kernel/includes/setup_inc.php'; +include_once UTIL_PKG_INCLUDE_PATH . "phplot.php"; global $gBitSystem; $gBitSystem->isPackageActive( 'stats' ); @@ -31,24 +33,23 @@ $data = $stats->getUsageChartData(); $chart_type = !empty( $_REQUEST['chart_type'] ) ? $_REQUEST['chart_type'] : 'bars'; // initialise phplot and insert data -$graph =& new PHPlot( 600, 400 ); -$graph->SetTitle( tra( 'Site Usage Statistics' ) ); +$graph = new PHPlot( 600, 400 ); +$graph->SetTitle( KernelTools::tra( 'Site Usage Statistics' ) ); $graph->SetPlotType( $chart_type ); if( $chart_type == 'pie' ) { $graph->SetShading( 20 ); - $graph->SetLegendPixels( 1, 30, FALSE ); + $graph->SetLegendPixels( 1, 30 ); $graph->SetLegend( $data['legend'] ); $graph->SetDataValues( $data['data'] ); } else { array_shift( $data['data'][0] ); foreach( $data['data'][0] as $key => $item ) { - $bars[] = array( $data['legend'][$key], $item ); + $bars[] = [ $data['legend'][$key], $item ]; } $graph->SetShading( 7 ); $graph->SetDataValues( $bars ); - $graph->SetDrawXDataLabels( TRUE ); + $graph->SetDrawXDataLabels( true ); $graph->SetXLabelAngle( ( count( $bars ) > 5 ) ? 90 : 0 ); $graph->SetXTickPos('none'); } $graph->DrawGraph(); -?> @@ -13,14 +13,16 @@ /** * Required files */ -require_once( '../kernel/includes/setup_inc.php' ); -require_once( STATS_PKG_CLASS_PATH.'Statistics.php' ); +use Bitweaver\KernelTools; +use Bitweaver\Stats\Statistics; + +require_once '../kernel/includes/setup_inc.php'; $stats = new Statistics(); $gBitSystem->verifyPackage( 'stats' ); $gBitSystem->verifyPermission( 'p_stats_view' ); -$periodHash = array( 'day' => 'Daily', 'week' => 'Weekly', 'month' => 'Monthly', 'quarter' => 'Quarterly', 'year' => 'Yearly' ); +$periodHash = [ 'day' => 'Daily', 'week' => 'Weekly', 'month' => 'Monthly', 'quarter' => 'Quarterly', 'year' => 'Yearly' ]; $gBitSmarty->assign( 'periodHash', $periodHash ); if( !isset( $_REQUEST["period"] )) { @@ -49,12 +51,11 @@ switch( $_REQUEST["period"] ) { if( !empty( $_REQUEST['itemize'] ) ) { $listHash['registration_period'] = $_REQUEST['itemize']; $listHash['registration_period_format'] = $format; - bit_redirect( USERS_PKG_URL.'admin/index.php?registration_period='.urlencode( $_REQUEST['itemize'] ).'®istration_period_format='.urlencode( $listHash['registration_period_format'] ) ); + KernelTools::bit_redirect( USERS_PKG_URL.'admin/index.php?registration_period='.urlencode( $_REQUEST['itemize'] ).'®istration_period_format='.urlencode( $listHash['registration_period_format'] ) ); } $gBitSmarty->assign( 'userStats', $stats->registrationStats( $format )); $gBitSmarty->assign( 'period', $_REQUEST["period"] ); // Display the template -$gBitSystem->display( 'bitpackage:stats/user_stats.tpl', NULL, array( 'display_mode' => 'display' )); -?> +$gBitSystem->display( 'bitpackage:stats/user_stats.tpl', NULL, [ 'display_mode' => 'display' ]); |
