$days, 'per_page' => 1 ) ); if ( empty( $r['ok'] ) || empty( $r['body']['meta'] ) ) { return null; } $data = $r['body']['meta']; set_transient( $key, $data, 10 * MINUTE_IN_SECONDS ); return $data; } /** Render. */ public static function render() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display-only period switch. $days = isset( $_GET['htform_days'] ) && '30' === $_GET['htform_days'] ? 30 : 7; $m = self::stats( $days ); if ( null === $m ) { echo '

' . esc_html__( 'Could not load leads from HTforms right now. Check HTforms → Troubleshooting.', 'htforms-builder' ) . '

'; return; } $chart = isset( $m['chart'] ) ? (array) $m['chart'] : array(); $max = 1; foreach ( $chart as $c ) { $max = max( $max, (int) $c['count'] ); } $total = isset( $m['period_total'] ) ? (int) $m['period_total'] : 0; $unread = isset( $m['counts']['unread'] ) ? (int) $m['counts']['unread'] : 0; $entries = admin_url( 'admin.php?page=htform-entries' ); echo '
'; echo '

'; foreach ( array( 7, 30 ) as $d ) { printf( '%3$s ', esc_url( add_query_arg( 'htform_days', $d, admin_url( 'index.php' ) ) ), $d === $days ? 'current' : '', esc_html( sprintf( /* translators: %d days */ __( 'Last %d days', 'htforms-builder' ), $d ) ) ); } echo '

'; echo '
' . esc_html__( 'New leads:', 'htforms-builder' ) . ' ' . esc_html( number_format_i18n( $total ) ) . '' . esc_html__( 'Unread:', 'htforms-builder' ) . ' ' . esc_html( number_format_i18n( $unread ) ) . '
'; echo '
'; $step = max( 1, (int) floor( count( $chart ) / 6 ) ); foreach ( $chart as $i => $c ) { $h = round( ( (int) $c['count'] / $max ) * 100, 1 ); $label = 0 === $i % $step ? date_i18n( 'M j', strtotime( $c['date'] ) ) : ''; printf( '
%4$s
', esc_attr( date_i18n( get_option( 'date_format' ), strtotime( $c['date'] ) ) ), (int) $c['count'], esc_attr( (string) $h ), esc_html( $label ) ); } echo '
'; if ( ! empty( $m['sources'] ) ) { echo '

' . esc_html__( 'Where leads came from:', 'htforms-builder' ) . ' '; $parts = array(); foreach ( array_slice( (array) $m['sources'], 0, 5 ) as $s ) { if ( empty( $s['source'] ) || in_array( strtolower( $s['source'] ), array( 'unknown', 'not recorded' ), true ) ) continue; $parts[] = esc_html( $s['source'] . ' (' . (int) $s['count'] . ')' ); } echo implode( ' · ', $parts ) . '

'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped above. } if ( ! empty( $m['countries'] ) ) { echo '

' . esc_html__( 'Top countries:', 'htforms-builder' ) . ' '; $parts = array(); foreach ( array_slice( (array) $m['countries'], 0, 5 ) as $c ) { if ( ! preg_match( '/^[A-Z]{2}$/', (string) $c['code'] ) || 'XX' === $c['code'] ) continue; $parts[] = esc_html( $c['code'] . ' (' . (int) $c['count'] . ')' ); } echo implode( ' · ', $parts ) . '

'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped above. } if ( isset( $m['coverage'] ) ) { $c = $m['coverage']; echo '

' . esc_html( sprintf( __( 'Source recorded for %1$d of %3$d leads. Country detected for %2$d of %3$d leads.', 'htforms-builder' ), (int) $c['sourceRecorded'], (int) $c['countryRecorded'], (int) $c['total'] ) ) . '

'; } echo '

' . esc_html__( 'View all entries', 'htforms-builder' ) . '

'; echo '
'; } }