get_row( "SELECT count(DISTINCT ip) AS visitors FROM `$table_name` WHERE feed='' AND spider=''" )->$row; // phpcs:ignore $result_j[ $row . '_tyear' ] = $wpdb->get_row( $wpdb->prepare( "SELECT count(DISTINCT ip) AS visitors FROM `$table_name` WHERE feed='' AND spider='' AND date LIKE %s", $thisyear . '%' ) )->$row; // phpcs:ignore $result_j[ $row . '_total' ] += $offsets['alltotalvisits']; break; case 'visitors_feeds': $row_title = __( 'Visitors through Feeds', 'newstatpress' ); // db call ok; no-cache ok; unprepared SQL OK. $result_j[ $row . '_total' ] = $wpdb->get_row( "SELECT count(DISTINCT ip) AS visitors_feeds FROM `$table_name` WHERE feed<>'' AND spider='' AND agent<>''" )->$row; // phpcs:ignore $result_j[ $row . '_tyear' ] = $wpdb->get_row( $wpdb->prepare( "SELECT count(DISTINCT ip) AS visitors_feeds FROM `$table_name` WHERE feed<>'' AND spider='' AND agent<>'' AND date LIKE %s", $thisyear . '%' ) )->$row; // phpcs:ignore $result_j[ $row . '_total' ] += $offsets['visitorsfeeds']; break; case 'pageview': $row_title = __( 'Pageviews', 'newstatpress' ); // db call ok; no-cache ok; unprepared SQL OK. $result_j[ $row . '_total' ] = $wpdb->get_row( "SELECT count(date) AS pageview FROM `$table_name` WHERE feed='' AND spider=''" )->$row; // phpcs:ignore $result_j[ $row . '_tyear' ] = $wpdb->get_row( $wpdb->prepare( "SELECT count(date) AS pageview FROM `$table_name` WHERE feed='' AND spider='' AND date LIKE %s", $thisyear . '%' ) )->$row; // phpcs:ignore $result_j[ $row . '_total' ] += $offsets['pageviews']; break; case 'spiders': $row_title = __( 'Spiders', 'newstatpress' ); // db call ok; no-cache ok; unprepared SQL OK. $result_j[ $row . '_total' ] = $wpdb->get_row( "SELECT count(date) AS spiders FROM `$table_name` WHERE feed='' AND spider<>''" )->$row; // phpcs:ignore $result_j[ $row . '_tyear' ] = $wpdb->get_row( $wpdb->prepare( "SELECT count(date) AS spiders FROM `$table_name` WHERE feed='' AND spider<>'' AND date LIKE %s", $thisyear . '%' ) )->$row; // phpcs:ignore $result_j[ $row . '_total' ] += $offsets['spy']; break; case 'feeds': $row_title = __( 'Pageviews through Feeds', 'newstatpress' ); // db call ok; no-cache ok; unprepared SQL OK. $result_j[ $row . '_total' ] = $wpdb->get_row( "SELECT count(date) AS feeds FROM `$table_name` WHERE feed<>'' AND spider=''" )->$row; // phpcs:ignore $result_j[ $row . '_tyear' ] = $wpdb->get_row( $wpdb->prepare( "SELECT count(date) AS feeds FROM `$table_name` WHERE feed<>'' AND spider='' AND date LIKE %s", $thisyear . '%' ) )->$row; // phpcs:ignore $result_j[ $row . '_total' ] += $offsets['pageviewfeeds']; break; } } // make graph. $maxxday = 0; for ( $gg = $gdays - 1;$gg >= 0;$gg-- ) { $date = gmdate( 'Ymd', current_time( 'timestamp' ) - 86400 * $gg ); // db call ok; no-cache ok; unprepared SQL OK. $qry_visitors = $wpdb->get_row( $wpdb->prepare( "SELECT count(DISTINCT ip) AS total FROM `$table_name` WHERE feed='' AND spider='' AND date = %s", $date ) ); // phpcs:ignore $visitors[ $gg ] = $qry_visitors->total; // db call ok; no-cache ok; unprepared SQL OK. $qry_pageviews = $wpdb->get_row( $wpdb->prepare( "SELECT count(date) AS total FROM `$table_name` WHERE feed='' AND spider='' AND date = %s", $date ) ); // phpcs:ignore $pageviews[ $gg ] = $qry_pageviews->total; // db call ok; no-cache ok; unprepared SQL OK. $qry_spiders = $wpdb->get_row( $wpdb->prepare( "SELECT count(date) AS total FROM `$table_name` WHERE feed='' AND spider<>'' AND date = %s", $date ) ); // phpcs:ignore $spiders[ $gg ] = $qry_spiders->total; // db call ok; no-cache ok; unprepared SQL OK. $qry_feeds = $wpdb->get_row( $wpdb->prepare( "SELECT count(date) AS total FROM `$table_name` WHERE feed<>'' AND spider='' AND date = %s", $date ) ); // phpcs:ignore $feeds[ $gg ] = $qry_feeds->total; $total = $visitors[ $gg ] + $pageviews[ $gg ] + $spiders[ $gg ] + $feeds[ $gg ]; if ( $total > $maxxday ) { $maxxday = $total; } } if ( 0 === $maxxday ) { $maxxday = 1; } $result_j['visitors'] = $visitors; // export. $result_j['pageviews'] = $pageviews; // export. $result_j['spiders'] = $spiders; // export. $result_j['feeds'] = $feeds; // export. $result_j['max'] = $maxxday; // export. // output an HTML representation of the collected data. $overview_table = ''; // dashboard. $overview_table .= ""; // build body table overview. $overview_rows = array( 'visitors', 'visitors_feeds', 'pageview', 'feeds', 'spiders' ); foreach ( $overview_rows as $row ) { $result = nsp_calculate_variation( $result_j[ $row . '_tmonth' ], $result_j[ $row . '_lmonth' ] ); // build full current row. $overview_table .= "'; $overview_table .= "\n"; $overview_table .= "\n"; $overview_table .= "\n"; $overview_table .= "\n"; $overview_table .= "\n"; $overview_table .= "\n"; $overview_table .= "\n"; $overview_table .= ''; } $overview_table .= '
" . __( 'Total since', 'newstatpress' ) . " " . __( 'This year', 'newstatpress' ) . " " . __( 'Last month', 'newstatpress' ) . " " . __( 'This month', 'newstatpress' ) . " " . __( 'Target This month', 'newstatpress' ) . " " . __( 'Yesterday', 'newstatpress' ) . " " . __( 'Today', 'newstatpress' ) . "
$since $thisyear_header $lastmonth_header $thismonth_header $thismonth_header $yesterday_header $today_header
" . $result_j[ $row . '_title' ] . '" . $result_j[ $row . '_total' ] . "" . $result_j[ $row . '_tyear' ] . "" . $result_j[ $row . '_lmonth' ] . "" . $result_j[ $row . '_tmonth' ] . $result[0] . " $result[1] $result[2] " . $result_j[ $row . '_qry_y' ] . "" . $result_j[ $row . '_qry_t' ] . "
'; $start_of_week = get_option( 'start_of_week' ); $gd = ( 90 / $gdays ) . '%'; $overview_graph = ""; for ( $gg = $gdays - 1;$gg >= 0;$gg-- ) { $scale_factor = 2; // 2 : 200px in CSS $date = gmdate( 'Ymd', current_time( 'timestamp' ) - 86400 * $gg ); $px_visitors = $scale_factor * ( round( $result_j['visitors'][ $gg ] * 100 / $maxxday ) ); $px_pageviews = $scale_factor * ( round( $result_j['pageviews'][ $gg ] * 100 / $maxxday ) ); $px_spiders = $scale_factor * ( round( $result_j['spiders'][ $gg ] * 100 / $maxxday ) ); $px_feeds = $scale_factor * ( round( $result_j['feeds'][ $gg ] * 100 / $maxxday ) ); $px_white = $scale_factor * 100 - $px_feeds - $px_spiders - $px_pageviews - $px_visitors; $overview_graph .= "\n"; } $overview_graph .= '
"; $overview_graph .= "
"; if ( gmdate( 'w', current_time( 'timestamp' ) - 86400 * $gg === $start_of_week ) ) { $overview_graph .= "
"; } else { $overview_graph .= "
"; } $overview_graph .= gmdate( 'd', current_time( 'timestamp' ) - 86400 * $gg ) . ' ' . gmdate( 'M', current_time( 'timestamp' ) - 86400 * $gg ) . "
'; $overview_table = $overview_table . $overview_graph; $result_h = $overview_table; return $result_h; }