entries-report-plain.php
157 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Entries Report Plain Text Email Template |
| 4 | * |
| 5 | * @package EverestForms\Emails\Templates |
| 6 | * @since 2.0.9 |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | // Guard: provide safe defaults so the template never fatals on missing variables. |
| 12 | $period_label = isset( $period_label ) ? (string) $period_label : ''; |
| 13 | $is_test = isset( $is_test ) ? (bool) $is_test : false; |
| 14 | $summary = isset( $summary ) && is_array( $summary ) ? $summary : array(); |
| 15 | $entries_data = isset( $entries_data ) && is_array( $entries_data ) ? $entries_data : array(); |
| 16 | $highlights = isset( $highlights ) && is_array( $highlights ) ? $highlights : array(); |
| 17 | $footer = isset( $footer ) && is_array( $footer ) ? $footer : array(); |
| 18 | |
| 19 | $summary = wp_parse_args( |
| 20 | $summary, |
| 21 | array( |
| 22 | 'total_entries' => 0, |
| 23 | 'overall_change' => null, |
| 24 | 'active_forms' => 0, |
| 25 | 'total_forms' => 0, |
| 26 | 'total_unread' => 0, |
| 27 | ) |
| 28 | ); |
| 29 | |
| 30 | $footer = wp_parse_args( |
| 31 | $footer, |
| 32 | array( |
| 33 | 'entries_url' => admin_url( 'admin.php?page=evf-entries' ), |
| 34 | 'settings_url' => admin_url( 'admin.php?page=evf-settings&tab=advanced§ion=entry_reports' ), |
| 35 | 'unsubscribe_url' => '', |
| 36 | 'generated_at' => current_time( 'Y-m-d H:i:s' ), |
| 37 | 'plugin_version' => defined( 'EVF_VERSION' ) ? EVF_VERSION : '', |
| 38 | 'site_url' => home_url(), |
| 39 | ) |
| 40 | ); |
| 41 | |
| 42 | $separator = str_repeat( '-', 60 ); |
| 43 | |
| 44 | ?> |
| 45 | <?php echo esc_html( strtoupper( get_bloginfo( 'name' ) ) ); ?> — <?php echo esc_html( html_entity_decode( $period_label, ENT_QUOTES | ENT_HTML5, 'UTF-8' ) ); ?> |
| 46 | |
| 47 | <?php echo esc_html( $separator ); ?> |
| 48 | |
| 49 | <?php if ( $is_test ) : ?> |
| 50 | *** <?php esc_html_e( 'THIS IS A TEST EMAIL — DATA IS LIVE BUT SENT MANUALLY', 'everest-forms' ); ?> *** |
| 51 | |
| 52 | <?php echo esc_html( $separator ); ?> |
| 53 | |
| 54 | <?php endif; ?> |
| 55 | <?php esc_html_e( 'SUMMARY', 'everest-forms' ); ?> |
| 56 | |
| 57 | <?php echo esc_html( $separator ); ?> |
| 58 | <?php esc_html_e( 'Total Entries:', 'everest-forms' ); ?> <?php echo esc_html( number_format_i18n( (int) $summary['total_entries'] ) ); ?> |
| 59 | |
| 60 | <?php if ( ! is_null( $summary['overall_change'] ) ) : ?> |
| 61 | <?php |
| 62 | $change = (float) $summary['overall_change']; |
| 63 | $direction = $change > 0 ? "\xe2\x86\x91" : ( $change < 0 ? "\xe2\x86\x93" : "\xe2\x86\x92" ); // ↑ ↓ → |
| 64 | /* translators: %1$s: arrow symbol, %2$s: absolute percentage value */ |
| 65 | echo esc_html( sprintf( __( '%1$s %2$s%% vs last period', 'everest-forms' ), $direction, abs( $change ) ) ); |
| 66 | ?> |
| 67 | |
| 68 | <?php endif; ?> |
| 69 | <?php esc_html_e( 'Active Forms:', 'everest-forms' ); ?> <?php echo esc_html( (int) $summary['active_forms'] . ' / ' . (int) $summary['total_forms'] ); ?> |
| 70 | |
| 71 | <?php esc_html_e( 'Unread Entries:', 'everest-forms' ); ?> <?php echo esc_html( number_format_i18n( (int) $summary['total_unread'] ) ); ?> |
| 72 | |
| 73 | <?php if ( ! empty( $entries_data ) ) : ?> |
| 74 | <?php echo esc_html( $separator ); ?> |
| 75 | <?php esc_html_e( 'FORM BREAKDOWN', 'everest-forms' ); ?> |
| 76 | |
| 77 | <?php echo esc_html( $separator ); ?> |
| 78 | <?php |
| 79 | // Calculate column width from actual data, capped to avoid wrapping in narrow clients. |
| 80 | $max_name = 20; |
| 81 | foreach ( $entries_data as $form ) { |
| 82 | $name_len = function_exists( 'mb_strlen' ) ? mb_strlen( $form['form_name'] ) : strlen( $form['form_name'] ); |
| 83 | $max_name = max( $max_name, $name_len ); |
| 84 | } |
| 85 | $max_name = min( $max_name, 35 ); |
| 86 | |
| 87 | // Build header using str_pad to avoid variable format strings in printf. |
| 88 | $header = str_pad( __( 'Form Name', 'everest-forms' ), $max_name ) |
| 89 | . ' ' . str_pad( __( 'Entries', 'everest-forms' ), 8, ' ', STR_PAD_LEFT ) |
| 90 | . ' ' . str_pad( __( 'vs Last', 'everest-forms' ), 10, ' ', STR_PAD_LEFT ) |
| 91 | . ' ' . str_pad( __( 'Unread', 'everest-forms' ), 7, ' ', STR_PAD_LEFT ); |
| 92 | |
| 93 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- plain-text email, no HTML context. |
| 94 | echo esc_html( $header ) . "\n"; |
| 95 | echo esc_html( str_repeat( '-', $max_name + 32 ) ) . "\n"; |
| 96 | |
| 97 | foreach ( $entries_data as $form ) { |
| 98 | $name = function_exists( 'mb_strlen' ) && mb_strlen( $form['form_name'] ) > $max_name |
| 99 | ? mb_substr( $form['form_name'], 0, $max_name - 3 ) . '...' |
| 100 | : $form['form_name']; |
| 101 | |
| 102 | $change = isset( $form['change'] ) ? $form['change'] : null; |
| 103 | if ( is_null( $change ) ) { |
| 104 | $change_str = '—'; |
| 105 | } elseif ( $change > 0 ) { |
| 106 | $change_str = '↑ ' . (int) $change . '%'; |
| 107 | } elseif ( $change < 0 ) { |
| 108 | $change_str = '↓ ' . abs( (int) $change ) . '%'; |
| 109 | } else { |
| 110 | $change_str = '→ 0%'; |
| 111 | } |
| 112 | |
| 113 | $unread_str = isset( $form['unread'] ) && $form['unread'] > 0 |
| 114 | ? number_format_i18n( (int) $form['unread'] ) |
| 115 | : '—'; |
| 116 | |
| 117 | $row = str_pad( $name, $max_name ) |
| 118 | . ' ' . str_pad( number_format_i18n( (int) $form['current'] ), 8, ' ', STR_PAD_LEFT ) |
| 119 | . ' ' . str_pad( $change_str, 10, ' ', STR_PAD_LEFT ) |
| 120 | . ' ' . str_pad( $unread_str, 7, ' ', STR_PAD_LEFT ); |
| 121 | |
| 122 | echo esc_html( $row ) . "\n"; |
| 123 | } |
| 124 | ?> |
| 125 | |
| 126 | <?php endif; ?> |
| 127 | <?php if ( ! empty( $highlights ) ) : ?> |
| 128 | <?php echo esc_html( $separator ); ?> |
| 129 | <?php esc_html_e( 'HIGHLIGHTS', 'everest-forms' ); ?> |
| 130 | |
| 131 | <?php echo esc_html( $separator ); ?> |
| 132 | <?php foreach ( $highlights as $text ) : ?> |
| 133 | - <?php echo esc_html( wp_strip_all_tags( (string) $text ) ); ?> |
| 134 | |
| 135 | <?php endforeach; ?> |
| 136 | <?php endif; ?> |
| 137 | <?php echo esc_html( $separator ); ?> |
| 138 | <?php esc_html_e( 'LINKS', 'everest-forms' ); ?> |
| 139 | |
| 140 | <?php echo esc_html( $separator ); ?> |
| 141 | <?php esc_html_e( 'View All Entries:', 'everest-forms' ); ?> <?php echo esc_url( $footer['entries_url'] ); ?> |
| 142 | |
| 143 | <?php esc_html_e( 'Manage Settings:', 'everest-forms' ); ?> <?php echo esc_url( $footer['settings_url'] ); ?> |
| 144 | |
| 145 | <?php esc_html_e( 'Unsubscribe:', 'everest-forms' ); ?> <?php echo esc_url( $footer['unsubscribe_url'] ); ?> |
| 146 | |
| 147 | <?php echo esc_html( $separator ); ?> |
| 148 | <?php |
| 149 | printf( |
| 150 | /* translators: %1$s: datetime string, %2$s: plugin version number, %3$s: site URL */ |
| 151 | esc_html__( 'Generated on %1$s · Everest Forms v%2$s · %3$s', 'everest-forms' ), |
| 152 | esc_html( $footer['generated_at'] ), |
| 153 | esc_html( $footer['plugin_version'] ), |
| 154 | esc_url( $footer['site_url'] ) |
| 155 | ); |
| 156 | ?> |
| 157 |