WP Statistics'; // Advertisement For WP Statistics Advanced Report Plugin $advanced_reporting_ad = is_plugin_active('wp-statistics-advanced-reporting/wp-statistics-advanced-reporting.php') ? '' : '

' . __('Get Better Reports', 'wp-statistics') . '

' . __('Detailed and customizable email reports are available with the Advanced Reporting add-on. Make sure you always have the insights you need to make informed decisions by digging deeper into your website analytics.', 'wp-statistics') . '

' . __('See the Full Picture — Try Advanced Reporting Today', 'wp-statistics') . '
'; $privacyBox = ''; $privacyAuditData = new PrivacyAuditDataProvider(); $complianceStatus = $privacyAuditData->getComplianceStatus(); if (intval($complianceStatus['percentage_ready']) !== 100 && !empty($complianceStatus['summary']) && intval($complianceStatus['summary']['action_required']) && Option::get('privacy_audit') && Option::get('show_privacy_issues_in_report')) { $privacyBox = '

' . __('Attention required!', 'wp-statistics') . '

' . sprintf( // translators: %s: Count of non-compliance items. __('There are %d items that need to be addressed to ensure compliance with privacy laws.', 'wp-statistics'), intval($complianceStatus['summary']['action_required']) ) . '

' . __('Review Audit Details', 'wp-statistics') . '
'; } $tipOfEmail = Helper::getReportEmailTip(); // "Your performance at a glance" section variables $startDate = date('Y-m-d', strtotime('-1 month')); $endDate = ''; if (!empty($schedule)) { $startDate = $schedule['start']; $endDate = $schedule['end']; } $websitePerformanceDataProvider = new WebsitePerformanceDataProvider($startDate, $endDate); function getPerformanceStyles($percentageChange) { $styles = [ 'background' => '#A9AAAE1A', // Default for 0 change 'color' => '#A9AAAE', 'image' => 'arrow.png' ]; if ($percentageChange > 0) { $styles['background'] = '#1961401A'; $styles['color'] = '#196140'; $styles['image'] = 'up.png'; } elseif ($percentageChange < 0) { $styles['background'] = '#FCECEB'; $styles['color'] = '#D54037'; $styles['image'] = 'down.png'; } return $styles; } function generatePerformanceSection($icon, $currentValue, $percentageChange, $label, $text_align = null, $text_align_reverse = null) { if (is_null($text_align)) { $text_align = is_rtl() ? 'right' : 'left'; } if (is_null($text_align_reverse)) { $text_align_reverse = is_rtl() ? 'left' : 'right'; } $styles = getPerformanceStyles($percentageChange); return '
' . $currentValue . ' ' . $percentageChange . '%
' . $label . '
'; } $email_performance_html = '
' . __('Your performance at a glance', 'wp-statistics') . '
' . generatePerformanceSection( 'visitor.png', Helper::formatNumberWithUnit($websitePerformanceDataProvider->getCurrentPeriodVisitors(), 1), $websitePerformanceDataProvider->getPercentageChangeVisitors(), __('Visitors', 'wp-statistics') ) . ' ' . generatePerformanceSection( 'referrals.png', Helper::formatNumberWithUnit($websitePerformanceDataProvider->getCurrentPeriodReferralsCount(), 1), $websitePerformanceDataProvider->getPercentageChangeReferrals(), __('Referrals', 'wp-statistics') ) . ' ' . generatePerformanceSection( 'views.png', Helper::formatNumberWithUnit($websitePerformanceDataProvider->getCurrentPeriodViews(), 1), $websitePerformanceDataProvider->getPercentageChangeViews(), __('Views', 'wp-statistics') ) . ' ' . generatePerformanceSection( 'contents.png', $websitePerformanceDataProvider->getCurrentPeriodContents(), $websitePerformanceDataProvider->getPercentageChangeContents(), __('Published Contents', 'wp-statistics') ) . '
'; $email_performance_html .= ''; // Initialize the first and second column content arrays $firstColumnContent = []; $secondColumnContent = []; // Add top author to the first column if (!empty($websitePerformanceDataProvider->getTopAuthor())) { $firstColumnContent['top_author'] = '
' . esc_html($websitePerformanceDataProvider->getTopAuthor()) . '
' . __('Top Author', 'wp-statistics') . '
'; } if (!empty($websitePerformanceDataProvider->getTopCategory())) { $topCategoryHtml = '
' . esc_html($websitePerformanceDataProvider->getTopCategory()) . '
' . __('Top Category', 'wp-statistics') . '
'; // Add top category to the first column if it's empty if (empty($firstColumnContent)) { $firstColumnContent['top_category'] = $topCategoryHtml; } else { // When the first column already has an item, add top category to the second column $secondColumnContent['top_category'] = $topCategoryHtml; } } if (!empty($websitePerformanceDataProvider->getTopPost())) { $topPostHtml = '
' . esc_html($websitePerformanceDataProvider->getTopPost()) . '
' . __('Top Content', 'wp-statistics') . '
'; // Add top post to the first column if it's empty if (empty($firstColumnContent)) { $firstColumnContent['top_post'] = $topPostHtml; } else if (empty($secondColumnContent)) { // If second column is empty, add top post to the second column $secondColumnContent['top_post'] = $topPostHtml; } else { // When both columns already have an item, add top post to second row of the first column $firstColumnContent['top_post'] = $topPostHtml; } } if (!empty($websitePerformanceDataProvider->getTopReferral())) { $topReferralHtml = '
' . esc_html($websitePerformanceDataProvider->getTopReferral()) . '
' . __('Top Referral', 'wp-statistics') . '
'; // Add top referral to the first column if it's empty if (empty($firstColumnContent)) { $firstColumnContent['top_referral'] = $topReferralHtml; } else if (empty($secondColumnContent)) { // If second column is empty, add top referral to the second column $secondColumnContent['top_referral'] = $topReferralHtml; } else if (count($firstColumnContent) == 1) { // When both columns already have an item but first column doesn't have a second row, add top referral to second row of the first column $firstColumnContent['top_referral'] = $topReferralHtml; } else { // Otherwise, add top referral to second row of the second column $secondColumnContent['top_referral'] = $topReferralHtml; } } // Create the table rows with the correct columns $email_performance_html .= '' . implode('', $firstColumnContent) . ''; $email_performance_html .= '' . implode('', $secondColumnContent) . ''; $email_performance_html .= '
'; $email_body = '
' . $final_logo . '

' . $email_title . '

' . $email_header; if (!empty($content)) { $email_body .= '
' .wp_kses_post($content) . '
'; } $email_body .= '
' .$email_performance_html . $privacyBox .'

' . $tipOfEmail['title'] . '

' . $tipOfEmail['content'] . '
' . $advanced_reporting_ad . $email_footer . $copyright . '
'; echo $email_body; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped