|
From: Jon O. <jon...@us...> - 2005-10-15 22:18:36
|
Update of /cvsroot/mxbb/mx_sitestats/includes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29610/includes Added Files: common.php Log Message: readded this module... --- NEW FILE: common.php --- <?php /** ------------------------------------------------------------------------ * Subject : mxBB - a fully modular portal and CMS (for phpBB) * Author : Jon Ohlsson and the mxBB Team * Credits : The phpBB Group & Marc Morisette, Marc Ferran (www.phpmix.com) * Copyright : (C) 2002-2005 mxBB Portal, phpMiX (c) 2004 * Email : jo...@mx... * Project site : www.mxbb-portal.com * ------------------------------------------------------------------------- * * $Id: common.php,v 1.1 2005/10/15 22:18:28 jonohlsson Exp $ */ /** * 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. */ define( '_SITESTATS_VERSION', 'v1.3.0' ); // Define table names. if ( empty( $mx_table_prefix ) ) { // Workaround to retrieve MX config data from phpBB scope... if ( !function_exists( 'get_mx_table_prefix' ) ) { function get_mx_table_prefix( $mx_root_path ) { global $phpEx; include( $mx_root_path . 'config.' . $phpEx ); return $mx_table_prefix; } } $mx_table_prefix = get_mx_table_prefix( $mx_root_path ); } define( 'SITESTATS_CONFIG_TABLE', $mx_table_prefix . 'sitestats_config' ); define( 'SITESTATS_COUNTER_TABLE', $mx_table_prefix . 'sitestats_counter' ); define( 'SITESTATS_REFERER_TABLE', $mx_table_prefix . 'sitestats_referer' ); // Load language files. if ( file_exists( $module_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_admin.' . $phpEx ) ) { include_once( $module_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_admin.' . $phpEx ); } else { include_once( $module_root_path . 'language/lang_english/lang_admin.' . $phpEx ); } if ( file_exists( $module_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.' . $phpEx ) ) { include_once( $module_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.' . $phpEx ); } else { include_once( $module_root_path . 'language/lang_english/lang_main.' . $phpEx ); } // ================================================================================ // [ SITESTATS CONFIG ] // ================================================================================ // Get SiteStats Settings from config table if ( defined( '_SITESTATS_CONFIG' ) ) { $sitestats_config = array(); $sql = 'SELECT * FROM ' . SITESTATS_CONFIG_TABLE; if ( !( $result = $db->sql_query( $sql ) ) ) { message_die( GENERAL_ERROR, "Couldn't query SiteStats config table", "", __LINE__, __FILE__, $sql ); } else { while ( $row = $db->sql_fetchrow( $result ) ) { $sitestats_config[$row['config_name']] = $row['config_value']; } } // Set Default Configuration (safety)... if ( empty( $sitestats_config['text_class'] ) ) { $sitestats_config['text_class'] = 'gensmall'; } if ( empty( $sitestats_config['counter_class'] ) ) { $sitestats_config['counter_class'] = 'gen'; } if ( !is_numeric( $sitestats_config['counter_size'] ) ) { $sitestats_config['counter_size'] = 8; } if ( !is_numeric( $sitestats_config['referers_count'] ) ) { $sitestats_config['referers_count'] = 10; } if ( !is_numeric( $sitestats_config['more_stats_page'] ) ) { $sitestats_config['more_stats_page'] = 0; } $sitestats_config['referers_logging'] = ( $sitestats_config['referers_logging'] == 1 ) ? true : false; $sitestats_config['referers_show_disabled'] = ( $sitestats_config['referers_show_disabled'] == 1 ) ? true : false; } // ================================================================================ // [ COMMON CLASSES ] // ================================================================================ // -------------------------------------------------------------------------------- // Site Statistics Classes // Base class with DB Utilities class sitestats { var $sql; // Last SQL query executed. function dbQuery( $sql ) { global $db; $this->sql = $sql; $result = $db->sql_query( $sql ); return $result; } function dbFetchRow( $sql ) { global $db; $this->sql = $sql; if ( !$result = $db->sql_query( $sql ) ) return false; if ( !$row = $db->sql_fetchrow( $result ) ) return false; return $row; } function dbMaxId( $table_name, $table_key ) { global $db; $sql = "SELECT MAX($table_key) AS max_id FROM $table_name"; $this->sql = $sql; if ( !$row = $this->dbFetchRow( $sql ) ) return -1; return $row['max_id']; } } //class sitestats // SiteStats Counter. class sitestats_counter extends sitestats { // Public Properties var $id, // Internal page identifier. $page, // Human page identifier. $hits_counter, // Hits Counter. $sess_counter; // Sessions Counter. var $digits_path, // Current relative path to digits path. $digits_ext; // File Extension for current digit images. // Constructor... function sitestats_counter() { @session_start(); global $HTTP_SESSION_VARS, $HTTP_SERVER_VARS; if ( isset( $HTTP_SERVER_VARS ) ) { $this->SESSION = &$HTTP_SESSION_VARS; $this->SERVER = &$HTTP_SERVER_VARS; } else { $this->SESSION = &$_SESSION; $this->SERVER = &$_SERVER; } } // Public Methods related to the Counter... function readCounter( $page ) { $this->page = $page; $sql = 'SELECT * FROM ' . SITESTATS_COUNTER_TABLE . " WHERE page = '" . $this->page . "'"; if ( !$row = $this->dbFetchRow( $sql ) ) { $this->id = 0; $this->hits_counter = 0; $this->sess_counter = 0; return false; } $this->id = $row['id']; $this->hits_counter = $row['hits_counter']; $this->sess_counter = $row['sess_counter']; return true; } function incrementCounter() { $sess_varname = 'sitestats_sess_counter_' . $this->page; $this->hits_counter++; if ( !isset( $this->SESSION[$sess_varname] ) ) { $this->SESSION[$sess_varname] = 1; $this->sess_counter++; } } function updateCounter() { if ( $this->id == 0 ) { // There is still no counter for this page? $this->id = $this->dbMaxId( SITESTATS_COUNTER_TABLE, 'id' ); if ( empty( $this->id ) ) $this->id = 0; $this->id++; $sql = 'INSERT INTO ' . SITESTATS_COUNTER_TABLE . ' (id, page, hits_counter, sess_counter)' . ' VALUES (' . $this->id . " , '" . $this->page . "' , " . $this->hits_counter . ' , ' . $this->sess_counter . ' )'; } else { // Update the hits counter for this page... $sql = 'UPDATE ' . SITESTATS_COUNTER_TABLE . " SET page = '" . $this->page . "' , " . ' hits_counter = ' . $this->hits_counter . ' , ' . ' sess_counter = ' . $this->sess_counter . ' WHERE id = ' . $this->id; } return $this->dbQuery( $sql ) ? true : false; } function deleteCounter() { $sql = 'DELETE FROM ' . SITESTATS_COUNTER_TABLE . ' WHERE id = ' . $this->id; return $this->dbQuery( $sql ) ? true : false; } // Public Methods related to Counter Images... function _getDigitsExt() { static $extens_ary = array( 'png', 'gif', 'jpg' ); for( $i = 0; $i < count( $extens_ary ); $i++ ) if ( file_exists( $this->digits_path . '0.' . $extens_ary[$i] ) ) return $extens_ary[$i]; return ''; } function setDigitParms( $digits_path, $digits_style ) { $this->digits_path = $digits_path . $digits_style . '/'; $this->digits_ext = $this->_getDigitsExt(); if ( empty( $this->digits_ext ) ) { return false; } return true; } function getCounterImages( $counter, $size, $get_image_size ) { if ( $get_image_size ) { $imgsize = @getimagesize( $this->digits_path . '0.' . $this->digits_ext ); // returns [w,h] $imgsize = ( $imgsize ) ? ' width="' . $imgsize[0] . '" height="' . $imgsize[1] . '"' : ''; } else { $imgsize = ''; } $s = sprintf( ( '%0' . $size . 'd' ), $counter ); $r = ''; for( $i = 0; $i < strlen( $s ); $i++ ) { $r .= '<img src="' . PORTAL_URL . $this->digits_path . substr( $s, $i, 1 ) . '.' . $this->digits_ext . '"' . $imgsize . ' border="0" alt="Powered by phpMiX SiteStats ' . _SITESTATS_VERSION . ' ;-)" />'; } return $r; } function getDigitStyles( $digits_path ) { $digits_ary = array(); $dir_handle = @opendir( $digits_path ); while ( $digits_style = @readdir( $dir_handle ) ) { if ( $digits_style <> '.' && $digits_style <> '..' ) { $this->digits_path = $digits_path . $digits_style . '/'; $extension = $this->_getDigitsExt(); if ( !empty( $extension ) ) { $digits_ary[$digits_style] = $extension; } } } @closedir( $dir_handle ); ksort( $digits_ary ); return $digits_ary; } // Public Methods related to HTTP Referer... function updateReferer() { $http_referer = $this->SERVER['HTTP_REFERER']; if ( empty( $http_referer ) ) // Do we have any referer? return true; $http_host = $this->SERVER['HTTP_HOST']; if ( eregi( $http_host, $http_referer ) ) // Is it an internal referer? return true; $http_url = parse_url( $http_referer ); $http_host = $http_url['host']; if ( empty( $http_host ) ) // Do we have a host in the URL? return true; $http_time = time(); $sql = 'SELECT * FROM ' . SITESTATS_REFERER_TABLE . " WHERE host = '" . $http_host . "'"; if ( !$row = $this->dbFetchRow( $sql ) ) { $sql = 'INSERT INTO ' . SITESTATS_REFERER_TABLE . ' (host, hits, firstvisit, lastvisit, enabled)' . " VALUES ('" . $http_host . "' , 1 , " . $http_time . ' , ' . $http_time . ' , 0 )'; } else { $sql = 'UPDATE ' . SITESTATS_REFERER_TABLE . ' SET hits = ' . ( $row['hits'] + 1 ) . ' , ' . ' lastvisit = ' . $http_time . " WHERE host = '" . $http_host . "'"; } return $this->dbQuery( $sql ) ? true : false; } } //class sitestats_counter // SiteStats phpBB Statistics. class sitestats_phpbb { var $usercount, $newestuser, $postcount, $topiccount; // get_db_stat var $return_limit; var $text_class; // Constructor function sitestats_phpbb() { $this->text_class = 'genmed'; $this->return_limit = 10; $this->usercount = -1; $this->newestuser = -1; $this->postcount = -1; $this->topiccount = -1; } // Basic phpBB statistics... function get_db_stat( $mode ) { if ( $this->$mode < 0 ) { $this->$mode = get_db_stat( $mode ); } return $this->$mode; } // Compute the percent math... function do_percent_math( $firstval, $value, $total ) { static $percent_array = array(); $cst = ( $firstval > 0 ) ? 90 / $firstval : 90; $percentage = ( $value == 0 ? 0 : ( $total ? min( 100, ( $value / $total ) * 100 ) : 0 ) ); $percent_array['percentage'] = number_format( $percentage, 2 ); $percent_array['bar_percent'] = max( 1, round( $value * $cst ) ); return $percent_array; } // Get voting bar info and Set templates variables... function set_voting_bar() { static $current_template_path = ''; global $board_config, $userdata, $db, $template; $vote_left = 'images/vote_lcap.gif'; $vote_right = 'images/vote_rcap.gif'; $vote_bar = 'images/voting_bar.gif'; if ( empty( $current_template_path ) ) { if ( !$board_config['override_user_style'] ) { if ( ( $userdata['user_id'] != ANONYMOUS ) && ( isset( $userdata['user_style'] ) ) ) { $style = $userdata['user_style']; if ( !$theme ) { $style = $board_config['default_style']; } } else { $style = $board_config['default_style']; } } else { $style = $board_config['default_style']; } $sql = 'SELECT * FROM ' . THEMES_TABLE . ' WHERE themes_id = ' . $style; if ( !( $result = $db->sql_query( $sql ) ) ) { message_die( CRITICAL_ERROR, 'Couldn\'t query database for theme info.' ); } if ( !$row = $db->sql_fetchrow( $result ) ) { message_die( CRITICAL_ERROR, 'Couldn\'t get theme data for themes_id=' . $style . '.' ); } $current_template_path = PHPBB_URL . 'templates/' . $row['template_name'] . '/'; } $template->assign_vars( array( 'LEFT_GRAPH_IMAGE' => $current_template_path . $vote_left, 'RIGHT_GRAPH_IMAGE' => $current_template_path . $vote_right, 'GRAPH_IMAGE' => $current_template_path . $vote_bar ) ); } } //class sitestats_phpbb $mxbb_footer_addup[] = 'mxBB Sitestats Module'; ?> |