Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/tutor-pro/addons/tutor-email/classes/Init.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
/**
3
+
* E-mail addon init.
4
+
*
5
+
* @package TutorPro\Addon
6
+
* @subpackage Email
7
+
*
8
+
* @since 2.0.0
9
+
*/
10
+
11
+
namespace TUTOR_EMAIL;
12
+
13
+
use TUTOR\Input;
14
+
use TUTOR\User;
15
+
16
+
if ( ! defined( 'ABSPATH' ) ) {
17
+
exit;
18
+
}
19
+
20
+
/**
21
+
* Class Init
22
+
*
23
+
* @since 2.0.0
24
+
*/
25
+
class Init {
26
+
/**
27
+
* Version of the addon.
28
+
*
29
+
* @var string
30
+
*/
31
+
public $version = TUTOR_EMAIL_VERSION;
32
+
33
+
/**
34
+
* Addon path.
35
+
*
36
+
* @var string
37
+
*/
38
+
public $path;
39
+
40
+
/**
41
+
* Url
42
+
*
43
+
* @var string
44
+
*/
45
+
public $url;
46
+
47
+
/**
48
+
* Basename
49
+
*
50
+
* @var string
51
+
*/
52
+
public $basename;
53
+
54
+
/**
55
+
* Email notification
56
+
*
57
+
* @var mixed
58
+
*/
59
+
private $email_notification;
60
+
61
+
/**
62
+
* Addon enable check and register hooks.
63
+
*
64
+
* @since 2.0.0
65
+
*/
66
+
public function __construct() {
67
+
if ( ! function_exists( 'tutor' ) ) {
68
+
return;
69
+
}
70
+
71
+
$addon_config = tutor_utils()->get_addon_config( TUTOR_EMAIL()->basename );
72
+
$is_enable = (bool) tutor_utils()->avalue_dot( 'is_enable', $addon_config );
73
+
if ( ! $is_enable ) {
74
+
return;
75
+
}
76
+
77
+
$this->path = plugin_dir_path( TUTOR_EMAIL_FILE );
78
+
$this->url = plugin_dir_url( TUTOR_EMAIL_FILE );
79
+
$this->basename = plugin_basename( TUTOR_EMAIL_FILE );
80
+
81
+
$this->load_tutor_email();
82
+
83
+
add_action( 'admin_init', array( $this, 'tutor_image_size_register' ) );
84
+
add_action( 'template_redirect', array( $this, 'load_email_preview' ) );
85
+
}
86
+
87
+
/**
88
+
* Preview email template on an URL
89
+
*
90
+
* @since 2.5.0
91
+
*
92
+
* @return void
93
+
*/
94
+
public function load_email_preview() {
95
+
if ( is_user_logged_in() && User::is_admin() && 'tutor-email-preview' === Input::get( 'page' ) ) {
96
+
$template = Input::get( 'template' );
97
+
$file = tutor_get_template( 'email.' . $template, true );
98
+
if ( file_exists( $file ) ) {
99
+
status_header( 200 );
100
+
101
+
ob_start();
102
+
include $file;
103
+
$footer_text = '<div class="tutor-email-footer-content" data-source="email_footer_text">' . json_decode( tutor_utils()->get_option( 'email_footer_text' ) ) . '</div>';
104
+
$content = ob_get_clean();
105
+
$content = $content . $footer_text;
106
+
107
+
// already sanitized inside template file.
108
+
echo $content; //phpcs:ignore.
109
+
exit;
110
+
}
111
+
}
112
+
}
113
+
114
+
/**
115
+
* Register email logo size
116
+
*
117
+
* @return void
118
+
*/
119
+
public function tutor_image_size_register() {
120
+
add_image_size( 'tutor-email-logo-size', 220, 50 );
121
+
}
122
+
123
+
/**
124
+
* Load tutor email
125
+
*
126
+
* @since 2.0.0
127
+
*
128
+
* @return void
129
+
*/
130
+
public function load_tutor_email() {
131
+
/**
132
+
* Loading Autoloader
133
+
*/
134
+
spl_autoload_register( array( $this, 'loader' ) );
135
+
$this->email_notification = new EmailNotification();
136
+
137
+
/**
138
+
* Handle email settings
139
+
*
140
+
* @since 2.5.0
141
+
*/
142
+
new EmailSettings();
143
+
144
+
/**
145
+
* Handle manual email.
146
+
*
147
+
* @since 2.5.0
148
+
*/
149
+
new ManualEmail();
150
+
151
+
/**
152
+
* Handle email queue with cron
153
+
*
154
+
* @since 1.8.7
155
+
*/
156
+
new EmailCron();
157
+
158
+
add_filter( 'tutor/options/attr', array( $this, 'add_options' ), 10 ); // Priority index is important. 'Content Drip' add-on uses 11.
159
+
}
160
+
161
+
/**
162
+
* Auto Load class and the files
163
+
*
164
+
* @since 2.0.0
165
+
*
166
+
* @param string $class_name class name.
167
+
*
168
+
* @return void
169
+
*/
170
+
private function loader( $class_name ) {
171
+
if ( ! class_exists( $class_name ) ) {
172
+
$class_name = preg_replace(
173
+
array( '/([a-z])([A-Z])/', '/\\\/' ),
174
+
array( '$1$2', DIRECTORY_SEPARATOR ),
175
+
$class_name
176
+
);
177
+
178
+
$class_name = str_replace( 'TUTOR_EMAIL' . DIRECTORY_SEPARATOR, 'classes' . DIRECTORY_SEPARATOR, $class_name );
179
+
$file_name = $this->path . $class_name . '.php';
180
+
181
+
if ( file_exists( $file_name ) && is_readable( $file_name ) ) {
182
+
require_once $file_name;
183
+
}
184
+
}
185
+
}
186
+
187
+
/**
188
+
* Get recipients
189
+
*
190
+
* @param mixed $key key.
191
+
*
192
+
* @return array
193
+
*/
194
+
private function get_recipient_array( $key = null ) {
195
+
$recipients = ( new EmailData() )->get_recipients();
196
+
197
+
if ( null === $key ) {
198
+
$new_array = array();
199
+
foreach ( $recipients as $recipient ) {
200
+
$new_array = array_merge( $new_array, $recipient );
201
+
}
202
+
203
+
return $new_array;
204
+
}
205
+
206
+
$admin_url = admin_url( 'admin.php' );
207
+
$array = $recipients[ $key ];
208
+
$fields = array();
209
+
210
+
foreach ( $recipients[ $key ] as $event => $mail ) {
211
+
$tooltip = ( isset( $mail['tooltip'] ) && ! empty( $mail['tooltip'] ) ) ? $mail['tooltip'] : null;
212
+
$email_edit_url = add_query_arg(
213
+
array(
214
+
'page' => 'tutor_settings',
215
+
'tab_page' => 'email_notification',
216
+
'edit' => $event,
217
+
'to' => $key,
218
+
),
219
+
$admin_url
220
+
);
221
+
222
+
$fields[] = array(
223
+
'key' => $key,
224
+
'event' => $event,
225
+
'type' => 'toggle_switch_button',
226
+
'label' => $mail['label'],
227
+
'template' => $mail['template'],
228
+
'tooltip' => $tooltip,
229
+
'default' => isset( $mail['default'] ) ? esc_attr( $mail['default'] ) : esc_attr( 'off' ),
230
+
'buttons' => array(
231
+
'edit' => array(
232
+
'type' => 'anchor',
233
+
'text' => __( 'Edit', 'tutor-pro' ),
234
+
'url' => $email_edit_url,
235
+
),
236
+
),
237
+
);
238
+
}
239
+
240
+
return $fields;
241
+
}
242
+
243
+
/**
244
+
* Email option and types
245
+
*
246
+
* @since 2.0.0
247
+
*
248
+
* @param mixed $attr attributes.
249
+
*
250
+
* @return array
251
+
*/
252
+
public function add_options( $attr ) {
253
+
254
+
$template_path = null;
255
+
$template_data = null;
256
+
257
+
if ( 'settings' === Input::get( 'edit' ) ) {
258
+
$template_path = TUTOR_EMAIL()->path . '/views/pages/settings.php';
259
+
}
260
+
261
+
if ( 'mailer' === Input::get( 'edit' ) ) {
262
+
$template_path = TUTOR_EMAIL()->path . '/views/pages/mailer.php';
263
+
}
264
+
265
+
if ( Input::has( 'edit' ) && ! in_array( Input::get( 'edit' ), array( 'settings', 'mailer' ), true ) ) {
266
+
$template_path = TUTOR_EMAIL()->path . '/views/pages/email-edit.php';
267
+
$to = Input::get( 'to' );
268
+
$edit = Input::get( 'edit' );
269
+
270
+
if ( 'email_to_students' === $to ) {
271
+
$to_readable = __( 'Email to Student', 'tutor-pro' );
272
+
} elseif ( 'email_to_teachers' === $to ) {
273
+
$to_readable = __( 'Email to Instructor', 'tutor-pro' );
274
+
} elseif ( 'email_to_admin' === $to ) {
275
+
$to_readable = __( 'Email to Admin', 'tutor-pro' );
276
+
} else {
277
+
$to_readable = ucwords( str_replace( '_', ' ', $to ) );
278
+
}
279
+
280
+
$template_data = array(
281
+
'to' => $to,
282
+
'key' => $edit,
283
+
'edit' => $edit,
284
+
'to_readable' => $to_readable,
285
+
'mail' => $this->get_recipient_array()[ $edit ],
286
+
'back_url' => add_query_arg(
287
+
array(
288
+
'page' => 'tutor_settings',
289
+
'tab_page' => 'email_notification',
290
+
),
291
+
admin_url( 'admin.php' )
292
+
),
293
+
);
294
+
295
+
$placeholders = array();
296
+
if ( isset( $template_data['mail']['placeholders'] ) && is_array( $template_data['mail']['placeholders'] ) ) {
297
+
$placeholders = array_values( $template_data['mail']['placeholders'] );
298
+
}
299
+
300
+
wp_localize_script( 'tutor-pro-email-template', '_tutorEmailPlaceholders', $placeholders );
301
+
}
302
+
303
+
$attr['email_notification'] = array(
304
+
'label' => __( 'Email', 'tutor-pro' ),
305
+
'slug' => 'email_notification',
306
+
'desc' => '',
307
+
'template' => 'basic',
308
+
'icon' => 'tutor-icon-envelope',
309
+
'template_path' => $template_path,
310
+
'edit_email_data' => $template_data,
311
+
'blocks' => array(
312
+
array(
313
+
'label' => null,
314
+
'slug' => 'email-settings-options',
315
+
'block_type' => 'custom',
316
+
'placement' => 'before',
317
+
'template_path' => TUTOR_EMAIL()->path . 'views/email-settings-options.php',
318
+
),
319
+
array(
320
+
'label' => __( 'Email to Students', 'tutor-pro' ),
321
+
'slug' => 'email_to_students',
322
+
'block_type' => 'uniform',
323
+
'fields' => $this->get_recipient_array( 'email_to_students' ),
324
+
),
325
+
array(
326
+
'label' => __( 'Email to Instructors', 'tutor-pro' ),
327
+
'slug' => 'email_to_teachers',
328
+
'block_type' => 'uniform',
329
+
'fields' => $this->get_recipient_array( 'email_to_teachers' ),
330
+
),
331
+
array(
332
+
'label' => __( 'Email to Admin', 'tutor-pro' ),
333
+
'slug' => 'email_to_admin',
334
+
'block_type' => 'uniform',
335
+
'fields' => $this->get_recipient_array( 'email_to_admin' ),
336
+
),
337
+
array(
338
+
'label' => __( 'Email Cron Settings', 'tutor-pro' ),
339
+
'slug' => 'email_sending',
340
+
'block_type' => 'uniform',
341
+
'fields' => array(
342
+
array(
343
+
'key' => 'tutor_email_disable_wpcron',
344
+
'label' => __( 'WP Cron for Bulk Mailing', 'tutor-pro' ),
345
+
'type' => 'toggle_switch',
346
+
'default' => 'off',
347
+
'desc' => __( 'Enable this option to let Tutor LMS use WordPress native scheduler for email sending activities', 'tutor-pro' ),
348
+
),
349
+
array(
350
+
'key' => 'tutor_email_cron_frequency',
351
+
'label' => __( 'WP Email Cron Frequency', 'tutor-pro' ),
352
+
'type' => 'number',
353
+
'min' => 10,
354
+
'default' => 300,
355
+
'desc' => __( 'Add the frequency mode in <strong>Second(s)</strong> which the Cron Setup will run', 'tutor-pro' ),
356
+
),
357
+
array(
358
+
'key' => 'tutor_bulk_email_limit',
359
+
'label' => __( 'Email Per Cron Execution', 'tutor-pro' ),
360
+
'type' => 'number',
361
+
'number_type' => 'integer',
362
+
'min' => 1,
363
+
'default' => 10,
364
+
'desc' => __( 'Number of emails you\'d like to send per cron execution', 'tutor-pro' ),
365
+
),
366
+
),
367
+
),
368
+
),
369
+
);
370
+
371
+
$attr = apply_filters( 'tutor_pro_after_email_notification_settings', $attr );
372
+
373
+
return $attr;
374
+
}
375
+
}
376
+