prefix . Rayetun_AG_DB::BOT_VISITS_TABLE; $referrals_table = $wpdb->prefix . Rayetun_AG_DB::REFERRALS_TABLE; $score_data = Rayetun_AG_Visibility_Score::get_instance()->get_score(); $total_visits = (int) $wpdb->get_var( // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->prepare( 'SELECT COUNT(*) FROM %i WHERE visited_at > %s', $visits_table, $since ) ); $by_bot = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->prepare( 'SELECT bot_name, COUNT(*) as visits FROM %i WHERE visited_at > %s GROUP BY bot_name ORDER BY visits DESC LIMIT 8', $visits_table, $since ), ARRAY_A ); $total_referrals = (int) $wpdb->get_var( // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->prepare( 'SELECT COUNT(*) FROM %i WHERE visited_at > %s', $referrals_table, $since ) ); $by_platform = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->prepare( 'SELECT platform, COUNT(*) as cnt FROM %i WHERE visited_at > %s GROUP BY platform ORDER BY cnt DESC', $referrals_table, $since ), ARRAY_A ); $top_pages = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery $wpdb->prepare( 'SELECT page_url, COUNT(*) as visits FROM %i WHERE visited_at > %s GROUP BY page_url ORDER BY visits DESC LIMIT 10', $visits_table, $since ), ARRAY_A ); // Content scores. $scored_posts = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery "SELECT p.post_title, pm.meta_value as score FROM {$wpdb->posts} p INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id WHERE pm.meta_key = '_rayetun_ag_ai_score' AND p.post_status = 'publish' ORDER BY CAST(pm.meta_value AS UNSIGNED) ASC LIMIT 10", ARRAY_A ); return array( 'period' => $days, 'score' => $score_data, 'total_visits' => $total_visits, 'by_bot' => $by_bot, 'total_referrals' => $total_referrals, 'by_platform' => $by_platform, 'top_pages' => $top_pages, 'scored_posts' => $scored_posts, 'site_name' => get_bloginfo( 'name' ), 'site_url' => home_url( '/' ), 'generated_at' => current_time( 'mysql' ), ); } // ------------------------------------------------------------------------- // Report HTML builder // ------------------------------------------------------------------------- private function build_report_html( $data, $branding ) { $company_name = $branding['company_name'] ?? get_bloginfo( 'name' ); $accent_color = $branding['accent_color'] ?? '#0F5C6B'; $logo_url = $branding['logo_url'] ?? ''; $footer_text = $branding['footer_text'] ?? ''; $score = absint( $data['score']['score'] ?? 0 ); $grade = esc_html( $data['score']['grade'] ?? 'F' ); $pillars = $data['score']['pillars'] ?? array(); // SVG donut chart for score. $circumference = 2 * M_PI * 45; $dash_offset = $circumference - ( $score / 100 ) * $circumference; $score_color = $score >= 70 ? '#2E7D32' : ( $score >= 50 ? '#F0A500' : '#C62828' ); // This report is a self-contained document opened in a new tab / printed to // PDF, so it has no wp_head(). Register the stylesheet and print it with // wp_print_styles() — proper enqueuing, and no literal tag in source. wp_register_style( 'rayetun-ag-report', RAYETUN_AG_URL . 'admin/css/rayetun-ag-report.css', array(), RAYETUN_AG_VERSION ); ob_start(); ?>
| /100 |