PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.38
Timetics – Appointment Booking Calendar & Scheduling v1.0.38
1.0.61 1.0.60 1.0.59 1.0.58 1.0.57 1.0.56 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 All 62 releases
timetics / core / emails / email.php

email.php in Timetics – Appointment Booking Calendar & Scheduling 1.0.38, at core/emails/email.php

170 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Core email class
4 *
5 * @package Timetics
6 */
7
8 namespace Timetics\Core\Emails;
9
10 /**
11 * Class Email
12 */
13 abstract class Email {
14 /**
15 * Constructor for core email class
16 *
17 * @return void
18 */
19 public function __construct() {
20 add_action( 'timetics-email-header', [$this, 'add_email_header'] );
21 add_action( 'timetics-email-footer', [$this, 'add_email_footer'] );
22 add_action( 'timetics-email-body', [$this, 'add_email_body'] );
23 }
24
25 /**
26 * Get email subject
27 *
28 * @return string
29 */
30 abstract public function get_subject();
31
32 /**
33 * Get email html template
34 *
35 * @return string
36 */
37 abstract public function get_template();
38
39 /**
40 * Get email recipent
41 *
42 * @return string
43 */
44 abstract public function get_recipient();
45
46 /**
47 * Get email header
48 *
49 * @return string
50 */
51 public function get_headers() {
52 $headers = 'MIME-Version: 1.0' . "\r\n";
53 $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
54 $from = get_bloginfo( 'name' );
55 $from_email = timetics_get_option('booking_created_customer_email_from');
56
57 // Append the "From" header
58 $headers .= 'From: ' .$from. ' <' . $from_email . '> ' . "\r\n";
59
60 return $headers;
61 }
62
63 /**
64 * Add email header
65 *
66 * @return void
67 */
68 public function add_email_header() {
69 include TIMETICS_PLUGIN_DIR . '/templates/emails/email-header.php';
70 }
71
72 /**
73 * Add email body
74 *
75 * @return void
76 */
77 public function add_email_body() {
78 $template = $this->get_template();
79
80 if ( file_exists( $template ) ) {
81 ob_start(); // Start output buffering
82 include $template;
83 $body = ob_get_clean(); // Retrieve and clean output buffer
84 echo wp_kses_post( $body ); // Output the email body
85 }
86 }
87 /**
88 * Add email footer
89 *
90 * @return void
91 */
92 public function add_email_footer() {
93 include TIMETICS_PLUGIN_DIR . '/templates/emails/email-footer.php';
94 }
95
96 /**
97 * Get email content
98 *
99 * @return string
100 */
101 public function get_template_content() {
102 ob_start();
103 $this->add_email_body();
104 $template = ob_get_clean();
105
106 return $template;
107
108 }
109
110 /**
111 * Send email using email template
112 *
113 * @return bool
114 */
115 public function send() {
116 $headers = $this->get_headers();
117 $subject = $this->get_subject();
118 $to = $this->get_recipient();
119 $message = $this->get_template_content();
120
121 /**
122 * Added temporary for leagacy sass. It will remove in future.
123 */
124 $data = apply_filters( 'timetics/admin/email/send', [$to, $subject, $message, $headers] );
125
126 return wp_mail( ...$data );
127 }
128
129 public function sanitize_content( $content ) {
130 // Define the allowed HTML tags and attributes
131 $allowed_tags = array(
132 'a' => array(
133 'href' => true,
134 'title' => true,
135 ),
136 'abbr' => array(
137 'title' => true,
138 ),
139 'acronym' => array(
140 'title' => true,
141 ),
142 'b' => array(),
143 'blockquote' => array(
144 'cite' => true,
145 ),
146 'cite' => array(),
147 'code' => array(),
148 'del' => array(
149 'datetime' => true,
150 ),
151 'em' => array(),
152 'i' => array(),
153 'q' => array(
154 'cite' => true,
155 ),
156 'img' => array (
157 'src' => true,
158 'data-*' => true
159 ),
160 'strike' => array(),
161 'strong' => array(),
162 );
163
164 $sanitized_content = wp_kses( $content, $allowed_tags );
165
166 return $sanitized_content;
167 }
168
169 }
170