public_html/wp-content/plugins/wp-statistics/includes/functions/functions.php
// This function gets the visitor statistics for a given time frame.
This function gets the visitor statistics for a given time frame.
This function gets the visitor statistics for a given time frame .
function wp_statistics_visitor( $time, $daily = null, $countonly = false ) {
		global $wpdb, $WP_Statistics;
		$history = 0;
		$select = '*';
		$sqlstatement = '';
		if( $countonly == true ) { $select = 'count(last_counter)'; }
		if( $daily == true ) {
			$result = $wpdb->query( "SELECT {$select} FROM {$wpdb->prefix}statistics_visitor WHERE `last_counter` = '{$WP_Statistics->Current_Date( 'Y-m-d', $time )}'");
			return $result;
		} else {
			switch( $time ) {
				case 'today':
					$sqlstatement = "SELECT {$select} FROM {$wpdb->prefix}statistics_visitor WHERE `last_counter` = '{$WP_Statistics->Current_Date( 'Y-m-d' )}'";
					break;
				case 'yesterday':
					$sqlstatement = "SELECT {$select} FROM {$wpdb->prefix}statistics_visitor WHERE `last_counter` = '{$WP_Statistics->Current_Date( 'Y-m-d', -1 )}'";
					break;
				case 'week':
					$sqlstatement = "SELECT {$select} FROM {$wpdb->prefix}statistics_visitor WHERE `last_counter` BETWEEN '{$WP_Statistics->Current_Date( 'Y-m-d', -7 )}' AND '{$WP_Statistics->Current_Date( 'Y-m-d' )}'";
					break;
				case 'month':
					$sqlstatement = "SELECT {$select} FROM {$wpdb->prefix}statistics_visitor WHERE `last_counter` BETWEEN '{$WP_Statistics->Current_Date( 'Y-m-d', -30 )}' AND '{$WP_Statistics->Current_Date( 'Y-m-d' )}'";
					break;
				case 'year':
					$sqlstatement = "SELECT {$select} FROM {$wpdb->prefix}statistics_visitor WHERE `last_counter` BETWEEN '{$WP_Statistics->Current_Date( 'Y-m-d', -365 )}' AND '{$WP_Statistics->Current_Date( 'Y-m-d' )}'";
					break;
				case 'total':
					$sqlstatement = "SELECT {$select} FROM {$wpdb->prefix}statistics_visitor";
					$history = $WP_Statistics->Get_Historical_Data( 'visitors' );
					break;
				default:
					$sqlstatement = "SELECT {$select} FROM {$wpdb->prefix}statistics_visitor WHERE `last_counter` BETWEEN '{$WP_Statistics->Current_Date( 'Y-m-d', $time )}' AND '{$WP_Statistics->Current_Date( 'Y-m-d' )}'";
					break;
			}
		}
		if( $countonly == true ) { 
			$result = $wpdb->get_var( $sqlstatement ); 
			$result += $history;
		}
		else { 
			$result = $wpdb->query( $sqlstatement ); 
		}
		return $result;
	}
function wp_statistics_visitor ( $ time , $ daily = null , $ countonly = false ) { global $ wpdb , $ WP_Statistics ; $ history = 0 ; $ select = '*' ; $ sqlstatement = '' ; if ( $ countonly == true ) { $ select = 'count(last_counter)' ; } if ( $ daily == true ) { $ result = $ wpdb -> query ( " SELECT  { $ select }  FROM  { $ wpdb -> prefix } statistics_visitor WHERE `last_counter` = ' { $ WP_Statistics -> Current_Date ( 'Y-m-d' , $ time ) } ' " ) ; return $ result ; } else { switch ( $ time ) { case 'today' : $ sqlstatement = " SELECT  { $ select }  FROM  { $ wpdb -> prefix } statistics_visitor WHERE `last_counter` = ' { $ WP_Statistics -> Current_Date ( 'Y-m-d' ) } ' " ; break ; case 'yesterday' : $ sqlstatement = " SELECT  { $ select }  FROM  { $ wpdb -> prefix } statistics_visitor WHERE `last_counter` = ' { $ WP_Statistics -> Current_Date ( 'Y-m-d' , - 1 ) } ' " ; break ; case 'week' : $ sqlstatement = " SELECT  { $ select }  FROM  { $ wpdb -> prefix } statistics_visitor WHERE `last_counter` BETWEEN ' { $ WP_Statistics -> Current_Date ( 'Y-m-d' , - 7 ) } ' AND ' { $ WP_Statistics -> Current_Date ( 'Y-m-d' ) } ' " ; break ; case 'month' : $ sqlstatement = " SELECT  { $ select }  FROM  { $ wpdb -> prefix } statistics_visitor WHERE `last_counter` BETWEEN ' { $ WP_Statistics -> Current_Date ( 'Y-m-d' , - 30 ) } ' AND ' { $ WP_Statistics -> Current_Date ( 'Y-m-d' ) } ' " ; break ; case 'year' : $ sqlstatement = " SELECT  { $ select }  FROM  { $ wpdb -> prefix } statistics_visitor WHERE `last_counter` BETWEEN ' { $ WP_Statistics -> Current_Date ( 'Y-m-d' , - 365 ) } ' AND ' { $ WP_Statistics -> Current_Date ( 'Y-m-d' ) } ' " ; break ; case 'total' : $ sqlstatement = " SELECT  { $ select }  FROM  { $ wpdb -> prefix } statistics_visitor " ; $ history = $ WP_Statistics -> Get_Historical_Data ( 'visitors' ) ; break ; default : $ sqlstatement = " SELECT  { $ select }  FROM  { $ wpdb -> prefix } statistics_visitor WHERE `last_counter` BETWEEN ' { $ WP_Statistics -> Current_Date ( 'Y-m-d' , $ time ) } ' AND ' { $ WP_Statistics -> Current_Date ( 'Y-m-d' ) } ' " ; break ; } } if ( $ countonly == true ) { $ result = $ wpdb -> get_var ( $ sqlstatement ) ; $ result += $ history ; } else { $ result = $ wpdb -> query ( $ sqlstatement ) ; } return $ result ; }
This function gets the visitor statistics for a given time frame.
This function gets the visitor statistics for a given time frame .
// We need database and the global $WP_Statistics object access. // We often don't need the complete results but just the count of rows, if that's the case, let's have MySQL just count the results for us. // If we've been asked to do a daily count, it's a slightly different SQL query, so handle it seperatly. // Fetch the results from the database. // This function accepts several options for time parameter, each one has a unique SQL query string. // They're pretty self explanatory. // Execute the SQL call, if we're only counting we can use get_var(), otherwise we use query().