| 1 |
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName,Universal.Files.SeparateFunctionsFromOO.Mixed -- File naming is acceptable and mixed structure is acceptable for this type of file |
| 2 |
/** |
| 3 |
* Analytify Email Core Class |
| 4 |
* |
| 5 |
* This file contains the main email functionality for the Analytify plugin, |
| 6 |
* including email sending, scheduling, and rendering capabilities. |
| 7 |
* |
| 8 |
* @package WP_Analytify |
| 9 |
* @since 1.0.0 |
| 10 |
* @version 9.0.0 |
| 11 |
*/ |
| 12 |
|
| 13 |
ob_start(); |
| 14 |
|
| 15 |
// Include all email traits. |
| 16 |
$plugin_dir = defined( 'WP_ANALYTIFY_PLUGIN_DIR' ) ? WP_ANALYTIFY_PLUGIN_DIR : dirname( __DIR__ ); |
| 17 |
require_once $plugin_dir . '/classes/analytify-email/bootstrap.php'; |
| 18 |
require_once $plugin_dir . '/classes/analytify-email/settings.php'; |
| 19 |
// Since 9.0.0 — custom From/To bounds for monthly-style email reports (see `email-custom-range.php`). |
| 20 |
require_once $plugin_dir . '/classes/analytify-email/email-custom-range.php'; |
| 21 |
require_once $plugin_dir . '/classes/analytify-email/scheduler.php'; |
| 22 |
require_once $plugin_dir . '/classes/analytify-email/render.php'; |
| 23 |
require_once $plugin_dir . '/classes/analytify-email/single-send.php'; |
| 24 |
|
| 25 |
/** |
| 26 |
* Analytify Email Core Class |
| 27 |
* |
| 28 |
* @package WP_Analytify |
| 29 |
* @since 1.0.0 |
| 30 |
*/ |
| 31 |
class Analytify_Email_Core { |
| 32 |
|
| 33 |
// Use all the traits. |
| 34 |
use Analytify_Email_Bootstrap; |
| 35 |
use Analytify_Email_Settings; |
| 36 |
use Analytify_Email_Scheduler; |
| 37 |
use Analytify_Email_Render; |
| 38 |
use Analytify_Email_Single_Send; |
| 39 |
|
| 40 |
// Constructor is now handled by the bootstrap trait. |
| 41 |
// All other methods are now handled by their respective traits. |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Sanitize users email addresses. |
| 46 |
* |
| 47 |
* @param string $str The email string to sanitize. |
| 48 |
* @return string |
| 49 |
* |
| 50 |
* @phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed |
| 51 |
*/ |
| 52 |
function sanitize_multi_email( $str ) { |
| 53 |
|
| 54 |
if ( is_object( $str ) || is_array( $str ) ) { |
| 55 |
return ''; |
| 56 |
} |
| 57 |
|
| 58 |
$str = (string) $str; |
| 59 |
|
| 60 |
$filtered = wp_check_invalid_utf8( $str ); |
| 61 |
|
| 62 |
$keep_newlines = false; // Default value. |
| 63 |
$filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered ); |
| 64 |
|
| 65 |
$filtered = trim( $filtered ? $filtered : '' ); |
| 66 |
|
| 67 |
$found = false; |
| 68 |
|
| 69 |
while ( preg_match( '/%[a-f0-9]{2}/i', $filtered, $match ) ) { |
| 70 |
$filtered = str_replace( $match[0], '', $filtered ); |
| 71 |
$found = true; |
| 72 |
} |
| 73 |
|
| 74 |
if ( $found ) { |
| 75 |
// Strip out the whitespace that may now exist after removing the octets. |
| 76 |
$filtered = trim( preg_replace( '/ +/', ' ', $filtered ) ? preg_replace( '/ +/', ' ', $filtered ) : '' ); |
| 77 |
} |
| 78 |
|
| 79 |
return $filtered; |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Init email reports. |
| 84 |
* |
| 85 |
* @since 3.1.0 |
| 86 |
* @return null |
| 87 |
*/ |
| 88 |
function init_analytify_email() { |
| 89 |
new Analytify_Email_Core(); |
| 90 |
return null; |
| 91 |
} |
| 92 |
|
| 93 |
add_action( |
| 94 |
'init', |
| 95 |
function () { |
| 96 |
init_analytify_email(); |
| 97 |
} |
| 98 |
); |
| 99 |
|
| 100 |
ob_end_flush(); |
| 101 |
|