public_html/wp-content/plugins/wp-statistics/includes/functions/functions.php
// This function returns the statistics for a given page.
This function returns the statistics for a given page.
This function returns the statistics for a given page .
function wp_statistics_pages( $time, $page_uri = '', $id = -1, $rangestartdate = null, $rangeenddate = null ) {
		global $wpdb, $WP_Statistics;
		$history = 0;
		$sqlstatement = '';
		if( $page_uri == '' ) { $page_uri = wp_statistics_get_uri(); }
		$page_uri_sql = esc_sql( $page_uri );
		if( $id != -1 ) {
			$page_sql = '`id` = '  . $id;
			$history_key = 'page';
			$history_id = $id;
		} else {		
			$page_sql = "`URI` = '{$page_uri_sql}'";
			$history_key = 'uri';
			$history_id = $page_uri;
		}
		switch($time) {
			case 'today':
				$sqlstatement = "SELECT SUM(count) FROM {$wpdb->prefix}statistics_pages WHERE `date` = '{$WP_Statistics->Current_Date( 'Y-m-d' )}' AND {$page_sql}";
				break;
			case 'yesterday':
				$sqlstatement = "SELECT SUM(count) FROM {$wpdb->prefix}statistics_pages WHERE `date` = '{$WP_Statistics->Current_Date( 'Y-m-d', -1 )}' AND {$page_sql}";
				break;
			case 'week':
				$sqlstatement = "SELECT SUM(count) FROM {$wpdb->prefix}statistics_pages WHERE `date` BETWEEN '{$WP_Statistics->Current_Date( 'Y-m-d', -7 )}' AND '{$WP_Statistics->Current_Date( 'Y-m-d' )}' AND {$page_sql}";
				break;
			case 'month':
				$sqlstatement = "SELECT SUM(count) FROM {$wpdb->prefix}statistics_pages WHERE `date` BETWEEN '{$WP_Statistics->Current_Date( 'Y-m-d', -30 )}' AND '{$WP_Statistics->Current_Date( 'Y-m-d' )}' AND {$page_sql}";
				break;
			case 'year':
				$sqlstatement = "SELECT SUM(count) FROM {$wpdb->prefix}statistics_pages WHERE `date` BETWEEN '{$WP_Statistics->Current_Date( 'Y-m-d', -365 )}' AND '{$WP_Statistics->Current_Date( 'Y-m-d' )}' AND {$page_sql}";
				break;
			case 'total':
				$sqlstatement = "SELECT SUM(count) FROM {$wpdb->prefix}statistics_pages WHERE {$page_sql}";
				$history = $WP_Statistics->Get_Historical_Data( $history_key, $history_id );
				break;
			case 'range':
				$sqlstatement = "SELECT SUM(count) FROM {$wpdb->prefix}statistics_pages WHERE `date` BETWEEN '" . $WP_Statistics->Current_Date( 'Y-m-d', '-0', strtotime( $rangestartdate ) ) . "' AND '" . $WP_Statistics->Current_Date( 'Y-m-d', '-0', strtotime( $rangeenddate ) ) . "' AND {$page_sql}";
				break;
			default:
				$sqlstatement = "SELECT SUM(count) FROM {$wpdb->prefix}statistics_pages WHERE `date` = '{$WP_Statistics->Current_Date( 'Y-m-d', $time )}' AND {$page_sql}";
				break;
		}
		$result = $wpdb->get_var( $sqlstatement );
		$result += $history;
		if( $result == '' ) { $result = 0; }
		return $result;
	}
function wp_statistics_pages ( $ time , $ page_uri = '' , $ id = - 1 , $ rangestartdate = null , $ rangeenddate = null ) { global $ wpdb , $ WP_Statistics ; $ history = 0 ; $ sqlstatement = '' ; if ( $ page_uri == '' ) { $ page_uri = wp_statistics_get_uri ( ) ; } $ page_uri_sql = esc_sql ( $ page_uri ) ; if ( $ id != - 1 ) { $ page_sql = '`id` = ' . $ id ; $ history_key = 'page' ; $ history_id = $ id ; } else { $ page_sql = " `URI` = ' { $ page_uri_sql } ' " ; $ history_key = 'uri' ; $ history_id = $ page_uri ; } switch ( $ time ) { case 'today' : $ sqlstatement = " SELECT SUM(count) FROM  { $ wpdb -> prefix } statistics_pages WHERE `date` = ' { $ WP_Statistics -> Current_Date ( 'Y-m-d' ) } ' AND  { $ page_sql } " ; break ; case 'yesterday' : $ sqlstatement = " SELECT SUM(count) FROM  { $ wpdb -> prefix } statistics_pages WHERE `date` = ' { $ WP_Statistics -> Current_Date ( 'Y-m-d' , - 1 ) } ' AND  { $ page_sql } " ; break ; case 'week' : $ sqlstatement = " SELECT SUM(count) FROM  { $ wpdb -> prefix } statistics_pages WHERE `date` BETWEEN ' { $ WP_Statistics -> Current_Date ( 'Y-m-d' , - 7 ) } ' AND ' { $ WP_Statistics -> Current_Date ( 'Y-m-d' ) } ' AND  { $ page_sql } " ; break ; case 'month' : $ sqlstatement = " SELECT SUM(count) FROM  { $ wpdb -> prefix } statistics_pages WHERE `date` BETWEEN ' { $ WP_Statistics -> Current_Date ( 'Y-m-d' , - 30 ) } ' AND ' { $ WP_Statistics -> Current_Date ( 'Y-m-d' ) } ' AND  { $ page_sql } " ; break ; case 'year' : $ sqlstatement = " SELECT SUM(count) FROM  { $ wpdb -> prefix } statistics_pages WHERE `date` BETWEEN ' { $ WP_Statistics -> Current_Date ( 'Y-m-d' , - 365 ) } ' AND ' { $ WP_Statistics -> Current_Date ( 'Y-m-d' ) } ' AND  { $ page_sql } " ; break ; case 'total' : $ sqlstatement = " SELECT SUM(count) FROM  { $ wpdb -> prefix } statistics_pages WHERE  { $ page_sql } " ; $ history = $ WP_Statistics -> Get_Historical_Data ( $ history_key , $ history_id ) ; break ; case 'range' : $ sqlstatement = " SELECT SUM(count) FROM  { $ wpdb -> prefix } statistics_pages WHERE `date` BETWEEN ' " . $ WP_Statistics -> Current_Date ( 'Y-m-d' , '-0' , strtotime ( $ rangestartdate ) ) . " ' AND ' " . $ WP_Statistics -> Current_Date ( 'Y-m-d' , '-0' , strtotime ( $ rangeenddate ) ) . " ' AND  { $ page_sql } " ; break ; default : $ sqlstatement = " SELECT SUM(count) FROM  { $ wpdb -> prefix } statistics_pages WHERE `date` = ' { $ WP_Statistics -> Current_Date ( 'Y-m-d' , $ time ) } ' AND  { $ page_sql } " ; break ; } $ result = $ wpdb -> get_var ( $ sqlstatement ) ; $ result += $ history ; if ( $ result == '' ) { $ result = 0 ; } return $ result ; }
This function returns the statistics for a given page.
This function returns the statistics for a given page .
// We need database and the global $WP_Statistics object access. // If no page URI has been passed in, get the current page URI. // If a page/post ID has been passed, use it to select the rows, otherwise use the URI. //  Note that a single page/post ID can have multiple URI's associated with it. // This function accepts several options for time parameter, each one has a unique SQL query string. // They're pretty self explanatory. // Since this function only every returns a count, just use get_var(). // If we have an empty result, return 0 instead of a blank.