0; $k-- ) { // current month. } */ for ( $i = 0; $i < $day; $i++ ) { switch ( $row ) { case 'visitors': // phpcs:ignore -- db call ok; no-cache ok $qry_daylmonth = $wpdb->get_row( $wpdb->prepare( "SELECT count(DISTINCT ip) AS visitors FROM `$table_name` WHERE feed='' AND spider='' AND date LIKE %s", $lastmonth . $i . '%' ) ); // phpcs:ignore: unprepared SQL OK.. // phpcs:ignore -- db call ok; no-cache ok $qry_day = $wpdb->get_row( $wpdb->prepare( "SELECT count(DISTINCT ip) AS visitors FROM `$table_name` WHERE feed='' AND spider='' AND date LIKE %s", $year . $month . $i . '%' ) ); // phpcs:ignore: unprepared SQL OK. break; case 'visitors_feeds': // phpcs:ignore -- db call ok; no-cache ok $qry_daylmonth = $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", $lastmonth . $i . '%' ) ); // phpcs:ignore: unprepared SQL OK.. // phpcs:ignore -- db call ok; no-cache ok $qry_day = $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", $year . $month . $i . '%' ) ); // phpcs:ignore: unprepared SQL OK. break; case 'pageview': // phpcs:ignore -- db call ok; no-cache ok $qry_daylmonth = $wpdb->get_row( $wpdb->prepare( "SELECT count(date) AS pageview FROM `$table_name` WHERE feed='' AND spider='' AND date LIKE %s", $lastmonth . $i . '%' ) ); // phpcs:ignore: unprepared SQL OK.. // phpcs:ignore -- db call ok; no-cache ok $qry_day = $wpdb->get_row( $wpdb->prepare( "SELECT count(date) AS pageview FROM `$table_name` WHERE feed='' AND spider='' AND date LIKE %s", $year . $month . $i . '%' ) ); // phpcs:ignore: unprepared SQL OK. break; case 'spiders': // phpcs:ignore -- db call ok; no-cache ok $qry_daylmonth = $wpdb->get_row( $wpdb->prepare( "SELECT count(date) AS spiders FROM `$table_name` WHERE feed='' AND spider<>'' AND date LIKE %s", $lastmonth . $i . '%' ) ); // phpcs:ignore: unprepared SQL OK.. // phpcs:ignore -- db call ok; no-cache ok $qry_day = $wpdb->get_row( $wpdb->prepare( "SELECT count(date) AS spiders FROM `$table_name` WHERE feed='' AND spider<>'' AND date LIKE %s", $year . $month . $i . '%' ) ); // phpcs:ignore: unprepared SQL OK. break; case 'feeds': // phpcs:ignore -- db call ok; no-cache ok $qry_daylmonth = $wpdb->get_row( $wpdb->prepare( "SELECT count(date) AS feeds FROM `$table_name` WHERE feed<>'' AND spider='' AND date LIKE %s", $lastmonth . $i . '%' ) ); // phpcs:ignore: unprepared SQL OK.. // phpcs:ignore -- db call ok; no-cache ok $qry_day = $wpdb->get_row( $wpdb->prepare( "SELECT count(date) AS feeds FROM `$table_name` WHERE feed<>'' AND spider='' AND date LIKE %s", $year . $month . $i . '%' ) ); // phpcs:ignore: unprepared SQL OK. break; } $tot += $qry_day->$row; $totlm += $qry_daylmonth->$row; } $qry_tmonth = new stdClass(); $qry_lmonth = new stdClass(); $qry_tmonth->$row = $tot; $qry_lmonth->$row = $totlm; } else { // classic. switch ( $row ) { case 'visitors': // phpcs:ignore -- db call ok; no-cache ok $qry_tmonth = $wpdb->get_row( $wpdb->prepare( "SELECT count(DISTINCT ip) AS visitors FROM `$table_name` WHERE feed='' AND spider='' AND date BETWEEN %s AND %s", $thismonth1, $thismonth31 ) ); // phpcs:ignore: unprepared SQL OK.. // phpcs:ignore -- db call ok; no-cache ok $qry_lmonth = $wpdb->get_row( $wpdb->prepare( "SELECT count(DISTINCT ip) AS visitors FROM `$table_name` WHERE feed='' AND spider='' AND date BETWEEN %s AND %s", $lastmonth1, $lastmonth31 ) ); // phpcs:ignore: unprepared SQL OK. break; case 'visitors_feeds': // phpcs:ignore -- db call ok; no-cache ok $qry_tmonth = $wpdb->get_row( $wpdb->prepare( "SELECT count(DISTINCT ip) AS visitors_feeds FROM `$table_name` WHERE feed<>'' AND spider='' AND agent<>'' AND date BETWEEN %s AND %s", $thismonth1, $thismonth31 ) ); // phpcs:ignore: unprepared SQL OK.. // phpcs:ignore -- db call ok; no-cache ok $qry_lmonth = $wpdb->get_row( $wpdb->prepare( "SELECT count(DISTINCT ip) AS visitors_feeds FROM `$table_name` WHERE feed<>'' AND spider='' AND agent<>'' AND date BETWEEN %s AND %s", $lastmonth1, $lastmonth31 ) ); // phpcs:ignore: unprepared SQL OK. break; case 'pageview': // phpcs:ignore -- db call ok; no-cache ok $qry_tmonth = $wpdb->get_row( $wpdb->prepare( "SELECT count(date) AS pageview FROM `$table_name` WHERE feed='' AND spider='' AND date BETWEEN %s AND %s", $thismonth1, $thismonth31 ) ); // phpcs:ignore: unprepared SQL OK.. // phpcs:ignore -- db call ok; no-cache ok $qry_lmonth = $wpdb->get_row( $wpdb->prepare( "SELECT count(date) AS pageview FROM `$table_name` WHERE feed='' AND spider='' AND date BETWEEN %s AND %s", $lastmonth1, $lastmonth31 ) ); // phpcs:ignore: unprepared SQL OK. break; case 'spiders': // phpcs:ignore -- db call ok; no-cache ok $qry_tmonth = $wpdb->get_row( $wpdb->prepare( "SELECT count(date) AS spiders FROM `$table_name` WHERE feed='' AND spider<>'' AND date BETWEEN %s AND %s", $thismonth1, $thismonth31 ) ); // phpcs:ignore: unprepared SQL OK.. // phpcs:ignore -- db call ok; no-cache ok $qry_lmonth = $wpdb->get_row( $wpdb->prepare( "SELECT count(date) AS spiders FROM `$table_name` WHERE feed='' AND spider<>'' AND date BETWEEN %s AND %s", $lastmonth1, $lastmonth31 ) ); // phpcs:ignore: unprepared SQL OK. break; case 'feeds': // phpcs:ignore -- db call ok; no-cache ok $qry_tmonth = $wpdb->get_row( $wpdb->prepare( "SELECT count(date) AS feeds FROM `$table_name` WHERE feed<>'' AND spider='' AND date BETWEEN %s AND %s", $thismonth1, $thismonth31 ) ); // phpcs:ignore: unprepared SQL OK.. // phpcs:ignore -- db call ok; no-cache ok $qry_lmonth = $wpdb->get_row( $wpdb->prepare( "SELECT count(date) AS feeds FROM `$table_name` WHERE feed<>'' AND spider='' AND date BETWEEN %s AND %s", $lastmonth1, $lastmonth31 ) ); // phpcs:ignore: unprepared SQL OK. break; } } $result_j[ $row . '_tmonth' ] = $qry_tmonth->$row; // export. $result_j[ $row . '_lmonth' ] = $qry_lmonth->$row; // export. switch ( $row ) { case 'visitors': // phpcs:ignore -- db call ok; no-cache ok $qry_y = $wpdb->get_row( $wpdb->prepare( "SELECT count(DISTINCT ip) AS visitors FROM `$table_name` WHERE feed='' AND spider='' AND date LIKE %s", $yesterday ) ); // phpcs:ignore: unprepared SQL OK.. // phpcs:ignore -- db call ok; no-cache ok $qry_t = $wpdb->get_row( $wpdb->prepare( "SELECT count(DISTINCT ip) AS visitors FROM `$table_name` WHERE feed='' AND spider='' AND date LIKE %s", $today ) ); // phpcs:ignore: unprepared SQL OK. break; case 'visitors_feeds': // phpcs:ignore -- db call ok; no-cache ok $qry_y = $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", $yesterday ) ); // phpcs:ignore: unprepared SQL OK.. // phpcs:ignore -- db call ok; no-cache ok $qry_t = $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", $today ) ); // phpcs:ignore: unprepared SQL OK. break; case 'pageview': // phpcs:ignore -- db call ok; no-cache ok $qry_y = $wpdb->get_row( $wpdb->prepare( "SELECT count(date) AS pageview FROM `$table_name` WHERE feed='' AND spider='' AND date LIKE %s", $yesterday ) ); // phpcs:ignore: unprepared SQL OK.. // phpcs:ignore -- db call ok; no-cache ok $qry_t = $wpdb->get_row( $wpdb->prepare( "SELECT count(date) AS pageview FROM `$table_name` WHERE feed='' AND spider='' AND date LIKE %s", $today ) ); // phpcs:ignore: unprepared SQL OK. break; case 'spiders': // phpcs:ignore -- db call ok; no-cache ok $qry_y = $wpdb->get_row( $wpdb->prepare( "SELECT count(date) AS spiders FROM `$table_name` WHERE feed='' AND spider<>'' AND date LIKE %s", $yesterday ) ); // phpcs:ignore: unprepared SQL OK.. // phpcs:ignore -- db call ok; no-cache ok $qry_t = $wpdb->get_row( $wpdb->prepare( "SELECT count(date) AS spiders FROM `$table_name` WHERE feed='' AND spider<>'' AND date LIKE %s", $today ) ); // phpcs:ignore: unprepared SQL OK. break; case 'feeds': // phpcs:ignore -- db call ok; no-cache ok $qry_y = $wpdb->get_row( $wpdb->prepare( "SELECT count(date) AS feeds FROM `$table_name` WHERE feed<>'' AND spider='' AND date LIKE %s", $yesterday ) ); // phpcs:ignore: unprepared SQL OK.. // phpcs:ignore -- db call ok; no-cache ok $qry_t = $wpdb->get_row( $wpdb->prepare( "SELECT count(date) AS feeds FROM `$table_name` WHERE feed<>'' AND spider='' AND date LIKE %s", $today ) ); // phpcs:ignore: unprepared SQL OK. break; } $result_j[ $row . '_qry_y' ] = $qry_y->$row; // export. $result_j[ $row . '_qry_t' ] = $qry_t->$row; // export. if ( 0 <> $result_j[ $row . '_lmonth' ] ) { $result_j[ $row . '_perc_change' ] = round( 100 * ( $result_j[ $row . '_tmonth' ] / $result_j[ $row . '_lmonth' ] ) - 100, 1 ) . '%'; // export. } else { $result_j[ $row . '_perc_change' ] = ''; } $result_j[ $row . '_title' ] = $row_title; // export. } if ( 'JSON' === $typ ) { return $result_j; // avoid to calculte HTML if not necessary. } // output a HTML representation of the collected data. $overview_table = ''; // dashboard. $overview_table .= ""; 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 .= ''; } $overview_table .= "
" . __( 'M-1', 'newstatpress' ) . " " . __( 'M', 'newstatpress' ) . " " . __( 'Y', 'newstatpress' ) . " " . __( 'T', 'newstatpress' ) . "
$lastmonth_header $thismonth_header $yesterday_header $today_header
" . $result_j[ $row . '_title' ] . '" . $result_j[ $row . '_lmonth' ] . "" . $result_j[ $row . '_tmonth' ] . $result[0] . "" . $result_j[ $row . '_qry_y' ] . "" . $result_j[ $row . '_qry_t' ] . "
\n"; $result_h = $overview_table; return $result_h; }