1
|
|
|
<?php if (!defined('EVENT_ESPRESSO_VERSION') ) |
2
|
|
|
exit('NO direct script access allowed'); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Event Espresso |
6
|
|
|
* |
7
|
|
|
* Event Registration and Management Plugin for Wordpress |
8
|
|
|
* |
9
|
|
|
* @package Event Espresso |
10
|
|
|
* @author Seth Shoultes |
11
|
|
|
* @copyright (c)2009-2012 Event Espresso All Rights Reserved. |
12
|
|
|
* @license @link http://eventespresso.com/support/terms-conditions/ ** see Plugin Licensing * * |
13
|
|
|
* @link http://www.eventespresso.com |
14
|
|
|
* @version 4.0 |
15
|
|
|
* |
16
|
|
|
* ------------------------------------------------------------------------ |
17
|
|
|
* |
18
|
|
|
* EE_Message_Admin_Page class |
19
|
|
|
* |
20
|
|
|
* for Admin setup of the message pages |
21
|
|
|
* |
22
|
|
|
* @package Event Espresso |
23
|
|
|
* @subpackage includes/core/message/EE_Message_Admin_Page.core.php |
24
|
|
|
* @author Darren Ethier |
25
|
|
|
* |
26
|
|
|
* ------------------------------------------------------------------------ |
27
|
|
|
*/ |
28
|
|
|
|
29
|
|
|
class Messages_Admin_Page extends EE_Admin_Page { |
30
|
|
|
|
31
|
|
|
protected $_active_messengers = array(); |
32
|
|
|
protected $_active_message_types = array(); |
33
|
|
|
protected $_active_message_type_name = ''; |
34
|
|
|
protected $_active_messenger; |
35
|
|
|
protected $_activate_state; |
36
|
|
|
protected $_activate_meta_box_type; |
37
|
|
|
protected $_current_message_meta_box; |
38
|
|
|
protected $_current_message_meta_box_object; |
39
|
|
|
protected $_context_switcher; |
40
|
|
|
protected $_shortcodes = array(); |
41
|
|
|
protected $_message_template_group; |
42
|
|
|
protected $_m_mt_settings = array(); |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* This is set via the _set_message_template_group method and holds whatever the template pack for the group is. IF there is no group then it gets automatically set to the Default template pack. |
47
|
|
|
* |
48
|
|
|
* @since 4.5.0 |
49
|
|
|
* |
50
|
|
|
* @var EE_Messages_Template_Pack |
51
|
|
|
*/ |
52
|
|
|
protected $_template_pack; |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* This is set via the _set_message_template_group method and holds whatever the template pack variation for the group is. If there is no group then it automatically gets set to default. |
59
|
|
|
* |
60
|
|
|
* @since 4.5.0 |
61
|
|
|
* |
62
|
|
|
* @var string |
63
|
|
|
*/ |
64
|
|
|
protected $_variation; |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
|
68
|
|
|
|
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* constructor |
72
|
|
|
* @constructor |
73
|
|
|
* @access public |
74
|
|
|
* @return void |
|
|
|
|
75
|
|
|
*/ |
76
|
|
|
public function __construct( $routing = TRUE ) { |
77
|
|
|
//make sure MSG Template helper is loaded. |
78
|
|
|
EE_Registry::instance()->load_helper('MSG_Template'); |
79
|
|
|
//make sure messages autoloader is running |
80
|
|
|
EED_Messages::set_autoloaders(); |
81
|
|
|
parent::__construct($routing); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
|
86
|
|
|
|
87
|
|
|
|
88
|
|
|
protected function _init_page_props() { |
89
|
|
|
global $espresso_wp_user; |
90
|
|
|
$this->page_slug = EE_MSG_PG_SLUG; |
91
|
|
|
$this->page_label = __('Messages Settings', 'event_espresso'); |
92
|
|
|
$this->_admin_base_url = EE_MSG_ADMIN_URL; |
93
|
|
|
$this->_admin_base_path = EE_MSG_ADMIN; |
94
|
|
|
|
95
|
|
|
$this->_activate_state = isset($this->_req_data['activate_state']) ? (array) $this->_req_data['activate_state'] : array(); |
96
|
|
|
|
97
|
|
|
$this->_active_messenger = isset( $this->_req_data['messenger'] ) ? $this->_req_data['messenger'] : NULL; |
98
|
|
|
|
99
|
|
|
EE_Registry::instance()->load_lib( 'messages' ); |
100
|
|
|
//we're also going to set the active messengers and active message types in here. |
101
|
|
|
$this->_active_messengers = EEH_MSG_Template::get_active_messengers_in_db(); |
102
|
|
|
$this->_active_messengers = !empty($this->_active_messengers) ? $this->_active_messengers : array(); |
103
|
|
|
$this->_active_message_types = !empty($this->_active_messenger) && !empty($this->_active_messengers[$this->_active_messenger]) && ! empty( $this->_active_messengers[$this->_active_messenger]['settings'][$this->_active_messenger . '-message_types'] ) ? array_keys($this->_active_messengers[$this->_active_messenger]['settings'][$this->_active_messenger . '-message_types']) : array(); |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
//what about saving the objects in the active_messengers and active_message_types? |
107
|
|
|
$this->_load_active_messenger_objects(); |
108
|
|
|
$this->_load_active_message_type_objects(); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
|
112
|
|
|
|
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* loads messenger objects into the $_active_messengers property (so we can access the needed methods) |
116
|
|
|
* |
117
|
|
|
* @access protected |
118
|
|
|
* @return void |
119
|
|
|
*/ |
120
|
|
|
protected function _load_active_messenger_objects() { |
121
|
|
|
foreach ( $this->_active_messengers as $messenger => $values ) { |
122
|
|
|
$ref = ucwords( str_replace( '_' , ' ', $messenger) ); |
123
|
|
|
$ref = str_replace( ' ', '_', $ref ); |
124
|
|
|
$classname = 'EE_' . $ref . '_messenger'; |
125
|
|
|
require_once( EE_LIBRARIES . 'messages'. DS .'messenger' . DS . $classname . '.class.php' ); |
126
|
|
|
if ( !class_exists($classname) ) |
127
|
|
|
throw new EE_Error( sprintf( __('There is no messenger for the given classname (%s)', 'event_espresso'), $classname ) ); |
128
|
|
|
|
129
|
|
|
$a = new ReflectionClass( $classname ); |
130
|
|
|
$this->_active_messengers[$messenger]['obj'] = $a->newInstance(); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
|
135
|
|
|
|
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* loads messenger objects into the $_active_messengers property (so we can access the needed methods) |
139
|
|
|
* |
140
|
|
|
* @access protected |
141
|
|
|
* @return void |
142
|
|
|
*/ |
143
|
|
|
protected function _load_active_message_type_objects() { |
144
|
|
|
if ( empty($this->_active_message_types) ) return; |
145
|
|
|
foreach ( $this->_active_message_types as $message_type ) { |
146
|
|
|
$ref = ucwords( str_replace( '_' , ' ', $message_type) ); |
147
|
|
|
$ref = str_replace( ' ', '_', $ref ); |
148
|
|
|
$classname = 'EE_' . $ref . '_message_type'; |
149
|
|
|
|
150
|
|
|
if ( !class_exists($classname) ) |
151
|
|
|
throw new EE_Error( sprintf( __('There is no message type for the given classname (%s)', 'event_espresso'), $classname ) ); |
152
|
|
|
|
153
|
|
|
$a = new ReflectionClass( $classname ); |
154
|
|
|
$this->_active_message_types[$message_type]['obj'] = $a->newInstance(); |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
|
159
|
|
|
|
160
|
|
|
protected function _ajax_hooks() { |
161
|
|
|
add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle' ) ); |
162
|
|
|
add_action('wp_ajax_activate_mt', array( $this, 'activate_mt_toggle') ); |
163
|
|
|
add_action('wp_ajax_ee_msgs_save_settings', array( $this, 'save_settings') ); |
164
|
|
|
add_action('wp_ajax_ee_msgs_update_mt_form', array( $this, 'update_mt_form' ) ); |
165
|
|
|
add_action('wp_ajax_switch_template_pack', array( $this, 'switch_template_pack' ) ); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
|
169
|
|
|
|
170
|
|
|
|
171
|
|
|
|
172
|
|
|
|
173
|
|
|
protected function _define_page_props() { |
174
|
|
|
$this->_admin_page_title = $this->page_label; |
175
|
|
|
$this->_labels = array( |
176
|
|
|
'buttons' => array( |
177
|
|
|
'add' => __('Add New Message Template', 'event_espresso'), |
178
|
|
|
'edit' => __('Edit Message Template', 'event_espresso'), |
179
|
|
|
'delete' => __('Delete Message Template', 'event_espresso') |
180
|
|
|
), |
181
|
|
|
'publishbox' => __('Update Actions', 'event_espresso') |
182
|
|
|
); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
|
186
|
|
|
|
187
|
|
|
|
188
|
|
|
|
189
|
|
|
|
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* an array for storing key => value pairs of request actions and their corresponding methods |
193
|
|
|
* @access protected |
194
|
|
|
* @return void |
195
|
|
|
*/ |
196
|
|
|
protected function _set_page_routes() { |
197
|
|
|
$grp_id = ! empty( $this->_req_data['GRP_ID'] ) && ! is_array( $this->_req_data['GRP_ID'] ) ? $this->_req_data['GRP_ID'] : 0; |
198
|
|
|
$grp_id = empty( $grp_id ) && !empty( $this->_req_data['id'] ) ? $this->_req_data['id'] : $grp_id; |
199
|
|
|
|
200
|
|
|
$this->_page_routes = array( |
201
|
|
|
'default'=> array( |
202
|
|
|
'func' => '_ee_default_messages_overview_list_table', |
203
|
|
|
'capability' => 'ee_read_global_messages' |
204
|
|
|
), |
205
|
|
|
'custom_mtps' => array( |
206
|
|
|
'func' => '_custom_mtps_preview', |
207
|
|
|
'capability' => 'ee_read_messages' |
208
|
|
|
), |
209
|
|
|
'add_new_message_template' =>array( |
210
|
|
|
'func' => '_add_message_template', |
211
|
|
|
'capability' => 'ee_edit_messages', |
212
|
|
|
'noheader' => TRUE |
213
|
|
|
), |
214
|
|
|
'edit_message_template' => array( |
215
|
|
|
'func' => '_edit_message_template', |
216
|
|
|
'capability' => 'ee_edit_message', |
217
|
|
|
'obj_id' => $grp_id |
218
|
|
|
), |
219
|
|
|
'preview_message' => array( |
220
|
|
|
'func' => '_preview_message', |
221
|
|
|
'capability' => 'ee_read_message', |
222
|
|
|
'obj_id' => $grp_id, |
223
|
|
|
'noheader' => true, |
224
|
|
|
'headers_sent_route' => 'display_preview_message' |
225
|
|
|
), |
226
|
|
|
'display_preview_message' => array( |
227
|
|
|
'func' => '_display_preview_message', |
228
|
|
|
'capability' => 'ee_read_message', |
229
|
|
|
'obj_id' => $grp_id |
230
|
|
|
), |
231
|
|
|
'insert_message_template' => array( |
232
|
|
|
'func' => '_insert_or_update_message_template', |
233
|
|
|
'capability' => 'ee_edit_messages', |
234
|
|
|
'args' => array( 'new_template' => TRUE ), |
235
|
|
|
'noheader' => TRUE |
236
|
|
|
), |
237
|
|
|
'update_message_template' => array( |
238
|
|
|
'func' => '_insert_or_update_message_template', |
239
|
|
|
'capability' => 'ee_edit_message', |
240
|
|
|
'obj_id' => $grp_id, |
241
|
|
|
'args' => array( 'new_template' => FALSE ), |
242
|
|
|
'noheader' => TRUE |
243
|
|
|
), |
244
|
|
|
'trash_message_template' => array( |
245
|
|
|
'func' => '_trash_or_restore_message_template', |
246
|
|
|
'capability' => 'ee_delete_message', |
247
|
|
|
'obj_id' => $grp_id, |
248
|
|
|
'args' => array( 'trash' => TRUE, 'all' => TRUE ), |
249
|
|
|
'noheader' => TRUE |
250
|
|
|
), |
251
|
|
|
'trash_message_template_context' => array( |
252
|
|
|
'func' => '_trash_or_restore_message_template', |
253
|
|
|
'capability' => 'ee_delete_message', |
254
|
|
|
'obj_id' => $grp_id, |
255
|
|
|
'args' => array( 'trash' => TRUE ), |
256
|
|
|
'noheader' => TRUE |
257
|
|
|
), |
258
|
|
|
'restore_message_template' => array( |
259
|
|
|
'func' => '_trash_or_restore_message_template', |
260
|
|
|
'capability' => 'ee_delete_message', |
261
|
|
|
'obj_id' => $grp_id, |
262
|
|
|
'args' => array( 'trash' => FALSE, 'all' => TRUE ), |
263
|
|
|
'noheader' => TRUE |
264
|
|
|
), |
265
|
|
|
'restore_message_template_context' => array( |
266
|
|
|
'func' => '_trash_or_restore_message_template', |
267
|
|
|
'capability' => 'ee_delete_message', |
268
|
|
|
'obj_id' => $grp_id, |
269
|
|
|
'args' => array('trash' => FALSE), |
270
|
|
|
'noheader' => TRUE |
271
|
|
|
), |
272
|
|
|
'delete_message_template' => array( |
273
|
|
|
'func' => '_delete_message_template', |
274
|
|
|
'capability' => 'ee_delete_message', |
275
|
|
|
'obj_id' => $grp_id, |
276
|
|
|
'noheader' => TRUE |
277
|
|
|
), |
278
|
|
|
'reset_to_default' => array( |
279
|
|
|
'func' => '_reset_to_default_template', |
280
|
|
|
'capability' => 'ee_edit_message', |
281
|
|
|
'obj_id' => $grp_id, |
282
|
|
|
'noheader' => TRUE |
283
|
|
|
), |
284
|
|
|
'settings' => array( |
285
|
|
|
'func' => '_settings', |
286
|
|
|
'capability' => 'manage_options' |
287
|
|
|
), |
288
|
|
|
'reports' => array( |
289
|
|
|
'func' => '_messages_reports', |
290
|
|
|
'capability' => 'ee_read_messages' |
291
|
|
|
), |
292
|
|
|
); |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
|
296
|
|
|
|
297
|
|
|
|
298
|
|
|
|
299
|
|
|
|
300
|
|
|
|
301
|
|
|
|
302
|
|
|
protected function _set_page_config() { |
303
|
|
|
|
304
|
|
|
$this->_page_config = array( |
305
|
|
|
'default' => array( |
306
|
|
|
'nav' => array( |
307
|
|
|
'label' => __('Default Message Templates', 'event_espresso'), |
308
|
|
|
'order' => 10 |
309
|
|
|
), |
310
|
|
|
'list_table' => 'Messages_Template_List_Table', |
311
|
|
|
'help_tabs' => array( |
312
|
|
|
'messages_overview_help_tab' => array( |
313
|
|
|
'title' => __('Messages Overview', 'event_espresso'), |
314
|
|
|
'filename' => 'messages_overview' |
315
|
|
|
), |
316
|
|
|
'messages_overview_messages_table_column_headings_help_tab' => array( |
317
|
|
|
'title' => __('Messages Table Column Headings', 'event_espresso'), |
318
|
|
|
'filename' => 'messages_overview_table_column_headings' |
319
|
|
|
), |
320
|
|
|
'messages_overview_messages_filters_help_tab' => array( |
321
|
|
|
'title' => __('Message Filters', 'event_espresso'), |
322
|
|
|
'filename' => 'messages_overview_filters' |
323
|
|
|
), |
324
|
|
|
'messages_overview_messages_views_help_tab' => array( |
325
|
|
|
'title' => __('Message Views', 'event_espresso'), |
326
|
|
|
'filename' => 'messages_overview_views' |
327
|
|
|
), |
328
|
|
|
'message_overview_message_types_help_tab' => array( |
329
|
|
|
'title' => __('Message Types', 'event_espresso'), |
330
|
|
|
'filename' => 'messages_overview_types' |
331
|
|
|
), |
332
|
|
|
'messages_overview_messengers_help_tab' => array( |
333
|
|
|
'title' => __('Messengers', 'event_espresso'), |
334
|
|
|
'filename' => 'messages_overview_messengers', |
335
|
|
|
), |
336
|
|
|
'messages_overview_other_help_tab' => array( |
337
|
|
|
'title' => __('Messages Other', 'event_espresso'), |
338
|
|
|
'filename' => 'messages_overview_other', |
339
|
|
|
), |
340
|
|
|
), |
341
|
|
|
'help_tour' => array( 'Messages_Overview_Help_Tour' ), |
342
|
|
|
'require_nonce' => FALSE |
343
|
|
|
), |
344
|
|
|
'custom_mtps' => array( |
345
|
|
|
'nav' => array( |
346
|
|
|
'label' => __('Custom Message Templates', 'event_espresso'), |
347
|
|
|
'order' => 15 |
348
|
|
|
), |
349
|
|
|
'help_tabs' => array(), |
350
|
|
|
'help_tour' => array(), |
351
|
|
|
'require_nonce' => FALSE |
352
|
|
|
), |
353
|
|
|
'add_new_message_template' => array( |
354
|
|
|
'nav' => array( |
355
|
|
|
'label' => __('Add New Message Templates', 'event_espresso'), |
356
|
|
|
'order' => 5, |
357
|
|
|
'persistent' => FALSE |
358
|
|
|
), |
359
|
|
|
'require_nonce' => FALSE |
360
|
|
|
), |
361
|
|
|
'edit_message_template' => array( |
362
|
|
|
'labels' => array( |
363
|
|
|
'buttons' => array( |
364
|
|
|
'reset' => __('Reset Templates'), |
365
|
|
|
), |
366
|
|
|
'publishbox' => __('Update Actions', 'event_espresso') |
367
|
|
|
), |
368
|
|
|
'nav' => array( |
369
|
|
|
'label' => __('Edit Message Templates', 'event_espresso'), |
370
|
|
|
'order' => 5, |
371
|
|
|
'persistent' => FALSE, |
372
|
|
|
'url' => '' |
373
|
|
|
), |
374
|
|
|
'metaboxes' => array('_publish_post_box', '_register_edit_meta_boxes'), |
375
|
|
|
'has_metaboxes' => TRUE, |
376
|
|
|
'help_tour' => array( 'Message_Templates_Edit_Help_Tour' ), |
377
|
|
|
'help_tabs' => array( |
378
|
|
|
'edit_message_template' => array( |
379
|
|
|
'title' => __('Message Template Editor', 'event_espresso'), |
380
|
|
|
'callback' => 'edit_message_template_help_tab' |
381
|
|
|
), |
382
|
|
|
'message_templates_help_tab' => array( |
383
|
|
|
'title' => __('Message Templates', 'event_espresso'), |
384
|
|
|
'filename' => 'messages_templates' |
385
|
|
|
), |
386
|
|
|
'message_template_shortcodes' => array( |
387
|
|
|
'title' => __('Message Shortcodes', 'event_espresso'), |
388
|
|
|
'callback' => 'message_template_shortcodes_help_tab' |
389
|
|
|
), |
390
|
|
|
'message_preview_help_tab' => array( |
391
|
|
|
'title' => __('Message Preview', 'event_espresso'), |
392
|
|
|
'filename' => 'messages_preview' |
393
|
|
|
), |
394
|
|
|
), |
395
|
|
|
'require_nonce' => FALSE |
396
|
|
|
), |
397
|
|
|
'display_preview_message' => array( |
398
|
|
|
'nav' => array( |
399
|
|
|
'label' => __('Message Preview', 'event_espresso'), |
400
|
|
|
'order' => 5, |
401
|
|
|
'url' => '', |
402
|
|
|
'persistent' => FALSE |
403
|
|
|
), |
404
|
|
|
'help_tabs' => array( |
405
|
|
|
'preview_message' => array( |
406
|
|
|
'title' => __('About Previews', 'event_espresso'), |
407
|
|
|
'callback' => 'preview_message_help_tab' |
408
|
|
|
) |
409
|
|
|
), |
410
|
|
|
'require_nonce' => FALSE |
411
|
|
|
), |
412
|
|
|
'settings' => array( |
413
|
|
|
'nav' => array( |
414
|
|
|
'label' => __('Settings', 'event_espresso'), |
415
|
|
|
'order' => 20 |
416
|
|
|
), |
417
|
|
|
'metaboxes' => array('_messages_settings_metaboxes'), |
418
|
|
|
'help_tabs' => array( |
419
|
|
|
'messages_settings_help_tab' => array( |
420
|
|
|
'title' => __('Messages Settings', 'event_espresso'), |
421
|
|
|
'filename' => 'messages_settings' |
422
|
|
|
), |
423
|
|
|
'messages_settings_message_types_help_tab' => array( |
424
|
|
|
'title' => __('Activating / Deactivating Message Types', 'event_espresso'), |
425
|
|
|
'filename' => 'messages_settings_message_types' |
426
|
|
|
), |
427
|
|
|
'messages_settings_messengers_help_tab' => array( |
428
|
|
|
'title' => __('Activating / Deactivating Messengers', 'event_espresso'), |
429
|
|
|
'filename' => 'messages_settings_messengers' |
430
|
|
|
), |
431
|
|
|
), |
432
|
|
|
'help_tour' => array( 'Messages_Settings_Help_Tour' ), |
433
|
|
|
'require_nonce' => FALSE |
434
|
|
|
) |
435
|
|
|
/*'reports' => array( |
436
|
|
|
'nav' => array( |
437
|
|
|
'label' => __('Reports', 'event_espresso'), |
438
|
|
|
'order' => 30 |
439
|
|
|
) |
440
|
|
|
)*/ |
441
|
|
|
); |
442
|
|
|
|
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
|
446
|
|
|
|
447
|
|
|
|
448
|
|
|
|
449
|
|
|
protected function _add_screen_options() { |
450
|
|
|
//todo |
451
|
|
|
} |
452
|
|
|
|
453
|
|
|
|
454
|
|
|
|
455
|
|
|
|
456
|
|
|
|
457
|
|
View Code Duplication |
protected function _add_screen_options_default() { |
|
|
|
|
458
|
|
|
$page_title = $this->_admin_page_title; |
459
|
|
|
$this->_admin_page_title = __('Global Message Templates', 'event_espresso'); |
460
|
|
|
$this->_per_page_screen_option(); |
461
|
|
|
$this->_admin_page_title = $page_title; |
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
|
465
|
|
|
|
466
|
|
|
|
467
|
|
|
|
468
|
|
|
|
469
|
|
|
//none of the below group are currently used for Messages |
470
|
|
|
protected function _add_feature_pointers() {} |
471
|
|
|
public function admin_init() { |
472
|
|
|
} |
473
|
|
|
public function admin_notices() {} |
474
|
|
|
public function admin_footer_scripts() {} |
475
|
|
|
|
476
|
|
|
|
477
|
|
|
|
478
|
|
|
|
479
|
|
|
|
480
|
|
|
|
481
|
|
|
public function messages_help_tab() { |
482
|
|
|
$templatepath = EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'; |
483
|
|
|
EEH_Template::display_template( $templatepath, array()); |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
|
487
|
|
|
public function messengers_help_tab() { |
488
|
|
|
$templatepath = EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'; |
489
|
|
|
EEH_Template::display_template( $templatepath, array()); |
490
|
|
|
} |
491
|
|
|
|
492
|
|
|
|
493
|
|
|
public function message_types_help_tab() { |
494
|
|
|
$templatepath = EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'; |
495
|
|
|
EEH_Template::display_template( $templatepath, array()); |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
|
499
|
|
|
public function messages_overview_help_tab() { |
500
|
|
|
$templatepath = EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'; |
501
|
|
|
EEH_Template::display_template( $templatepath, array()); |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
|
505
|
|
|
public function message_templates_help_tab() { |
506
|
|
|
$templatepath = EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'; |
507
|
|
|
EEH_Template::display_template( $templatepath, array()); |
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
|
511
|
|
|
public function edit_message_template_help_tab() { |
512
|
|
|
$templatepath = EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php'; |
513
|
|
|
$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title', 'event_espresso') . '" />'; |
|
|
|
|
514
|
|
|
$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview', 'event_espresso') . '" />'; |
515
|
|
|
$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields', 'event_espresso') . '" />'; |
516
|
|
|
$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox', 'event_espresso') . '" />'; |
517
|
|
|
$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox', 'event_espresso') . '" />'; |
518
|
|
|
EEH_Template::display_template( $templatepath, $args); |
519
|
|
|
} |
520
|
|
|
|
521
|
|
|
|
522
|
|
|
|
523
|
|
|
public function message_template_shortcodes_help_tab() { |
524
|
|
|
$this->_set_shortcodes(); |
525
|
|
|
$args['shortcodes'] = $this->_shortcodes; |
|
|
|
|
526
|
|
|
$template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php'; |
527
|
|
|
EEH_Template::display_template( $template_path, $args ); |
528
|
|
|
} |
529
|
|
|
|
530
|
|
|
|
531
|
|
|
|
532
|
|
|
public function preview_message_help_tab() { |
533
|
|
|
$templatepath = EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'; |
534
|
|
|
EEH_Template::display_template( $templatepath, array()); |
535
|
|
|
} |
536
|
|
|
|
537
|
|
|
|
538
|
|
|
public function settings_help_tab() { |
539
|
|
|
$templatepath = EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php'; |
540
|
|
|
$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'; |
|
|
|
|
541
|
|
|
$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'; |
542
|
|
|
$args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>'; |
543
|
|
|
$args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>'; |
544
|
|
|
EEH_Template::display_template( $templatepath, $args); |
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
|
548
|
|
|
|
549
|
|
|
|
550
|
|
|
|
551
|
|
|
public function load_scripts_styles() { |
552
|
|
|
wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION ); |
553
|
|
|
wp_enqueue_style('espresso_ee_msg'); |
554
|
|
|
|
555
|
|
|
wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, TRUE ); |
556
|
|
|
} |
557
|
|
|
|
558
|
|
|
|
559
|
|
|
|
560
|
|
|
|
561
|
|
|
|
562
|
|
|
public function wp_editor_css( $mce_css ) { |
563
|
|
|
//if we're on the edit_message_template route |
564
|
|
|
if ( $this->_req_action == 'edit_message_template' && $this->_active_messenger instanceof EE_messenger ) { |
565
|
|
|
$message_type_name = $this->_active_message_type_name; |
566
|
|
|
|
567
|
|
|
//we're going to REPLACE the existing mce css |
568
|
|
|
//we need to get the css file location from the active messenger |
569
|
|
|
$mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, TRUE, 'wpeditor', $this->_variation ); |
570
|
|
|
} |
571
|
|
|
|
572
|
|
|
return $mce_css; |
573
|
|
|
} |
574
|
|
|
|
575
|
|
|
|
576
|
|
|
|
577
|
|
|
|
578
|
|
|
public function load_scripts_styles_edit_message_template() { |
579
|
|
|
|
580
|
|
|
$this->_set_shortcodes(); |
581
|
|
|
|
582
|
|
|
EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
583
|
|
|
__('Are you sure you want to reset the %s %s message templates? Remember continuing will reset the templates for all contexts in this messenger and message type group.', 'event_espresso'), |
584
|
|
|
$this->_message_template_group->messenger_obj()->label['singular'], |
|
|
|
|
585
|
|
|
$this->_message_template_group->message_type_obj()->label['singular'] |
|
|
|
|
586
|
|
|
); |
587
|
|
|
EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('Switching the template pack for a messages template will reset the content for the template so the new layout is loaded. Any custom content in the existing template will be lost. Are you sure you wish to do this?', 'event_espresso' ); |
588
|
|
|
|
589
|
|
|
wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'), EVENT_ESPRESSO_VERSION ); |
590
|
|
|
|
591
|
|
|
wp_enqueue_script('ee_admin_js'); |
592
|
|
|
wp_enqueue_script('ee_msgs_edit_js'); |
593
|
|
|
|
594
|
|
|
//add in special css for tiny_mce |
595
|
|
|
add_filter( 'mce_css', array( $this, 'wp_editor_css' ) ); |
596
|
|
|
} |
597
|
|
|
|
598
|
|
|
|
599
|
|
|
|
600
|
|
|
public function load_scripts_styles_display_preview_message() { |
601
|
|
|
$this->_set_message_template_group(); |
602
|
|
|
if ( isset( $this->_req_data['messenger'] ) ) { |
603
|
|
|
$this->_active_messenger = $this->_active_messengers[$this->_req_data['messenger']]['obj']; |
604
|
|
|
} |
605
|
|
|
|
606
|
|
|
$message_type_name = isset( $this->_req_data['message_type'] ) ? $this->_req_data['message_type'] : ''; |
607
|
|
|
|
608
|
|
|
|
609
|
|
|
wp_enqueue_style('espresso_preview_css', $this->_active_messenger->get_variation( $this->_template_pack, $message_type_name, TRUE, 'preview', $this->_variation ) ); |
610
|
|
|
} |
611
|
|
|
|
612
|
|
|
|
613
|
|
|
|
614
|
|
|
public function load_scripts_styles_settings() { |
615
|
|
|
wp_register_style( 'ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(), EVENT_ESPRESSO_VERSION ); |
616
|
|
|
wp_enqueue_style( 'ee-text-links' ); |
617
|
|
|
wp_enqueue_style( 'ee-message-settings' ); |
618
|
|
|
|
619
|
|
|
wp_enqueue_script('ee-messages-settings'); |
620
|
|
|
} |
621
|
|
|
|
622
|
|
|
|
623
|
|
|
|
624
|
|
|
/** |
625
|
|
|
* set views array for List Table |
626
|
|
|
* @access public |
627
|
|
|
* @return array |
628
|
|
|
*/ |
629
|
|
View Code Duplication |
public function _set_list_table_views_default() { |
|
|
|
|
630
|
|
|
$this->_views = array( |
631
|
|
|
'in_use' => array( |
632
|
|
|
'slug' => 'in_use', |
633
|
|
|
'label' => __('In Use', 'event_espresso'), |
634
|
|
|
'count' => 0, |
635
|
|
|
'bulk_action' => array( |
636
|
|
|
'trash_message_template' => __('Move to Trash', 'event_espresso') |
637
|
|
|
) |
638
|
|
|
) |
639
|
|
|
); |
640
|
|
|
} |
641
|
|
|
|
642
|
|
|
|
643
|
|
|
|
644
|
|
|
protected function _ee_default_messages_overview_list_table() { |
645
|
|
|
$this->_admin_page_title = __('Default Message Templates', 'event_espresso'); |
646
|
|
|
$this->display_admin_list_table_page_with_no_sidebar(); |
647
|
|
|
} |
648
|
|
|
|
649
|
|
|
|
650
|
|
|
|
651
|
|
View Code Duplication |
protected function _custom_mtps_preview() { |
|
|
|
|
652
|
|
|
$this->_admin_page_title = __('Custom Message Templates (Preview)', 'event_espresso'); |
653
|
|
|
$this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso' ) . '" />'; |
654
|
|
|
$this->_template_args['preview_text'] = '<strong>'.__('Custom Message Templates is a feature that is only available in the caffeinated version of Event Espresso. With the Custom Message Templates feature, you are able to create custom templates and set them per event.', 'event_espresso').'</strong>'; |
655
|
|
|
$this->display_admin_caf_preview_page( 'custom_message_types', FALSE ); |
656
|
|
|
} |
657
|
|
|
|
658
|
|
|
|
659
|
|
|
|
660
|
|
|
|
661
|
|
|
|
662
|
|
|
|
663
|
|
|
|
664
|
|
|
|
665
|
|
|
/** |
666
|
|
|
* get_message_templates |
667
|
|
|
* This gets all the message templates for listing on the overview list. |
668
|
|
|
* |
669
|
|
|
* @access public |
670
|
|
|
* @param int $perpage the amount of templates groups to show per page |
671
|
|
|
* @param string $type the current _view we're getting templates for |
672
|
|
|
* @param bool $count return count? |
673
|
|
|
* @param bool $all disregard any paging info (get all data); |
674
|
|
|
* @param bool $global whether to return just global (true) or custom templates (false) |
675
|
|
|
* @return array|WP_Error object |
676
|
|
|
*/ |
677
|
|
|
public function get_message_templates( $perpage = 10, $type = 'in_use', $count = FALSE, $all = FALSE, $global = TRUE ) { |
678
|
|
|
global $espresso_wp_user; |
679
|
|
|
// start with an empty array |
680
|
|
|
$message_templates = array(); |
|
|
|
|
681
|
|
|
|
682
|
|
|
$MTP = EEM_Message_Template_Group::instance(); |
683
|
|
|
|
684
|
|
|
$this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby']; |
685
|
|
|
$orderby = $this->_req_data['orderby']; |
686
|
|
|
|
687
|
|
|
$order = ( isset( $this->_req_data['order'] ) && ! empty( $this->_req_data['order'] ) ) ? $this->_req_data['order'] : 'ASC'; |
688
|
|
|
|
689
|
|
|
$current_page = isset( $this->_req_data['paged'] ) && !empty( $this->_req_data['paged'] ) ? $this->_req_data['paged'] : 1; |
690
|
|
|
$per_page = isset( $this->_req_data['perpage'] ) && !empty( $this->_req_data['perpage'] ) ? $this->_req_data['perpage'] : $perpage; |
691
|
|
|
|
692
|
|
|
$offset = ($current_page-1)*$per_page; |
693
|
|
|
$limit = $all ? NULL : array( $offset, $per_page ); |
694
|
|
|
|
695
|
|
|
|
696
|
|
|
//options will match what is in the _views array property |
697
|
|
|
switch( $type ) { |
698
|
|
|
|
699
|
|
|
case 'in_use': |
700
|
|
|
$templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, TRUE ); |
701
|
|
|
break; |
702
|
|
|
|
703
|
|
|
default: |
704
|
|
|
$templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global ); |
705
|
|
|
|
706
|
|
|
} |
707
|
|
|
|
708
|
|
|
return $templates; |
709
|
|
|
} |
710
|
|
|
|
711
|
|
|
|
712
|
|
|
|
713
|
|
|
|
714
|
|
|
|
715
|
|
|
|
716
|
|
|
|
717
|
|
|
public function get_active_messengers() { |
718
|
|
|
return $this->_active_messengers; |
719
|
|
|
} |
720
|
|
|
|
721
|
|
|
|
722
|
|
|
|
723
|
|
|
|
724
|
|
|
public function get_active_message_types() { |
725
|
|
|
return $this->_active_message_types; |
726
|
|
|
} |
727
|
|
|
|
728
|
|
|
|
729
|
|
|
|
730
|
|
|
|
731
|
|
|
/** |
732
|
|
|
* filters etc might need a list of installed message_types |
733
|
|
|
* @return array an array of message type objects |
734
|
|
|
*/ |
735
|
|
|
public function get_installed_message_types() { |
736
|
|
|
$installed_objects = $this->_get_installed_message_objects(); |
737
|
|
|
$imts = $installed_objects['message_types']; |
738
|
|
|
$installed = array(); |
739
|
|
|
|
740
|
|
|
foreach ( $imts as $message_type ) { |
741
|
|
|
$installed[$message_type->name]['obj'] = $message_type; |
742
|
|
|
} |
743
|
|
|
|
744
|
|
|
return $installed; |
745
|
|
|
} |
746
|
|
|
|
747
|
|
|
|
748
|
|
|
|
749
|
|
|
/** |
750
|
|
|
* The purpose of this function is to return all installed message objects (messengers and message type regardless of whether they are ACTIVE or not) |
751
|
|
|
* @return array array consisting of installed messenger objects and installed message type objects. |
752
|
|
|
*/ |
753
|
|
|
protected function _get_installed_message_objects() { |
754
|
|
|
//get all installed messengers and message_types |
755
|
|
|
$EE_MSG = new EE_messages(); |
756
|
|
|
$installed_message_objects = array( |
757
|
|
|
'messengers' => $EE_MSG->get_installed_messengers(), |
758
|
|
|
'message_types' => $EE_MSG->get_installed_message_types() |
759
|
|
|
); |
760
|
|
|
return $installed_message_objects; |
761
|
|
|
} |
762
|
|
|
|
763
|
|
|
|
764
|
|
|
/** |
765
|
|
|
* _add_message_template |
766
|
|
|
* |
767
|
|
|
* This is used when creating a custom template. All Custom Templates start based off another template. |
768
|
|
|
* |
769
|
|
|
* @access protected |
770
|
|
|
* @return void |
771
|
|
|
*/ |
772
|
|
|
protected function _add_message_template( $message_type = '', $messenger='', $GRP_ID = '' ) { |
773
|
|
|
//set values override any request data |
774
|
|
|
$message_type = !empty( $message_type ) ? $message_type : ''; |
775
|
|
|
$message_type = empty( $message_type ) && !empty( $this->_req_data['message_type'] ) ? $this->_req_data['message_type'] : $message_type; |
776
|
|
|
|
777
|
|
|
$messenger = !empty( $messenger ) ? $messenger : ''; |
778
|
|
|
$messenger = empty( $messenger ) && !empty( $this->_req_data['messenger'] ) ? $this->_req_data['messenger'] : $messenger; |
779
|
|
|
|
780
|
|
|
$GRP_ID = !empty( $GRP_ID ) ? $GRP_ID : ''; |
781
|
|
|
$GRP_ID = empty( $GRP_ID ) && !empty( $this->_req_data['GRP_ID'] ) ? $this->_req_data['GRP_ID'] : $GRP_ID; |
782
|
|
|
|
783
|
|
|
//we need messenger and message type. They should be coming from the event editor. If not here then return error |
784
|
|
|
if ( empty( $message_type ) || empty( $messenger ) ) |
785
|
|
|
throw new EE_error(__('Sorry, but we can\'t create new templates because we\'re missing the messenger or message type', 'event_espresso')); |
786
|
|
|
|
787
|
|
|
//we need the GRP_ID for the template being used as the base for the new template |
788
|
|
|
if ( empty( $GRP_ID ) ) |
789
|
|
|
throw new EE_Error( __('In order to create a custom message template the GRP_ID of the template being used as a base is needed', 'event_espresso' ) ); |
790
|
|
|
|
791
|
|
|
//let's just make sure the template gets generated! |
792
|
|
|
|
793
|
|
|
//we need to reassign some variables for what the insert is expecting |
794
|
|
|
$this->_req_data['MTP_messenger'] = $messenger; |
795
|
|
|
$this->_req_data['MTP_message_type'] = $message_type; |
796
|
|
|
$this->_req_data['GRP_ID'] = $GRP_ID; |
797
|
|
|
$this->_insert_or_update_message_template(TRUE); |
798
|
|
|
} |
799
|
|
|
|
800
|
|
|
|
801
|
|
|
|
802
|
|
|
/** |
803
|
|
|
* public wrapper for the _add_message_template method |
804
|
|
|
* @param string $message_type message type slug |
805
|
|
|
* @param string $messenger messenger slug |
806
|
|
|
* @param int $GRP_ID GRP_ID for the related message template group this new template will be based off of. |
807
|
|
|
*/ |
808
|
|
|
public function add_message_template( $message_type, $messenger, $GRP_ID ) { |
809
|
|
|
$this->_add_message_template( $message_type, $messenger, $GRP_ID ); |
810
|
|
|
} |
811
|
|
|
|
812
|
|
|
|
813
|
|
|
/** |
814
|
|
|
* _edit_message_template |
815
|
|
|
* |
816
|
|
|
* @access protected |
817
|
|
|
* @return void |
818
|
|
|
*/ |
819
|
|
|
protected function _edit_message_template() { |
820
|
|
|
do_action( 'AHEE_log', __FILE__, __FUNCTION__, ''); |
821
|
|
|
|
822
|
|
|
//we filter the tinyMCE settings to remove the validation since message templates by their nature will not have valid html in the templates. |
823
|
|
|
add_filter( 'tiny_mce_before_init', array( $this, 'filter_tinymce_init'), 10, 2 ); |
824
|
|
|
|
825
|
|
|
$GRP_ID = isset( $this->_req_data['id'] ) && !empty( $this->_req_data['id'] ) ? absint( $this->_req_data['id'] ) : FALSE; |
826
|
|
|
|
827
|
|
|
$this->_set_shortcodes(); //this also sets the _message_template property. |
828
|
|
|
$message_template_group = $this->_message_template_group; |
829
|
|
|
$c_label = $message_template_group->context_label(); |
|
|
|
|
830
|
|
|
$c_config = $message_template_group->contexts_config(); |
|
|
|
|
831
|
|
|
|
832
|
|
|
reset( $c_config ); |
833
|
|
|
$context = isset( $this->_req_data['context']) && !empty($this->_req_data['context'] ) ? strtolower($this->_req_data['context']) : key($c_config); |
834
|
|
|
|
835
|
|
|
|
836
|
|
|
if ( empty($GRP_ID) ) { |
837
|
|
|
$action = 'insert_message_template'; |
838
|
|
|
$button_both = FALSE; |
|
|
|
|
839
|
|
|
$button_text = array( __( 'Save','event_espresso') ); |
|
|
|
|
840
|
|
|
$button_actions = array('something_different'); |
|
|
|
|
841
|
|
|
$referrer = FALSE; |
|
|
|
|
842
|
|
|
$edit_message_template_form_url = add_query_arg( array( 'action' => $action, 'noheader' => TRUE ), EE_MSG_ADMIN_URL ); |
843
|
|
|
} else { |
844
|
|
|
$action = 'update_message_template'; |
845
|
|
|
$button_both = TRUE; |
|
|
|
|
846
|
|
|
$button_text = array(); |
|
|
|
|
847
|
|
|
$button_actions = array(); |
|
|
|
|
848
|
|
|
$referrer = $this->_admin_base_url; |
|
|
|
|
849
|
|
|
$edit_message_template_form_url = add_query_arg( array( 'action' => $action, 'noheader' => TRUE ), EE_MSG_ADMIN_URL ); |
850
|
|
|
} |
851
|
|
|
|
852
|
|
|
//set active messenger for this view |
853
|
|
|
$this->_active_messenger = $this->_active_messengers[$message_template_group->messenger()]['obj']; |
|
|
|
|
854
|
|
|
$this->_active_message_type_name = $message_template_group->message_type(); |
|
|
|
|
855
|
|
|
|
856
|
|
|
|
857
|
|
|
//Do we have any validation errors? |
858
|
|
|
$validators = $this->_get_transient(); |
859
|
|
|
$v_fields = !empty($validators) ? array_keys($validators) : array(); |
860
|
|
|
|
861
|
|
|
|
862
|
|
|
//we need to assemble the title from Various details |
863
|
|
|
$context_label = sprintf( __('(%s %s)', 'event_espresso'), $c_config[$context]['label'], ucwords($c_label['label'] )); |
864
|
|
|
|
865
|
|
|
$title = sprintf( __(' %s %s Template %s', 'event_espresso'), ucwords($message_template_group->messenger_obj()->label['singular']), ucwords($message_template_group->message_type_obj()->label['singular']), $context_label ); |
|
|
|
|
866
|
|
|
|
867
|
|
|
$this->_template_args['GRP_ID'] = $GRP_ID; |
868
|
|
|
$this->_template_args['message_template'] = $message_template_group; |
869
|
|
|
$this->_template_args['is_extra_fields'] = FALSE; |
870
|
|
|
|
871
|
|
|
|
872
|
|
|
//let's get the EE_messages_controller so we can get template form fields |
873
|
|
|
$MSG = new EE_messages(); |
874
|
|
|
$template_field_structure = $MSG->get_fields($message_template_group->messenger(), $message_template_group->message_type()); |
|
|
|
|
875
|
|
|
|
876
|
|
|
if ( !$template_field_structure ) { |
877
|
|
|
$template_field_structure = FALSE; |
878
|
|
|
$template_fields = __('There was an error in assembling the fields for this display (you should see an error message)', 'event_espresso'); |
879
|
|
|
} |
880
|
|
|
|
881
|
|
|
|
882
|
|
|
$message_templates = $message_template_group->context_templates(); |
|
|
|
|
883
|
|
|
|
884
|
|
|
|
885
|
|
|
//if we have the extra key.. then we need to remove the content index from the template_field_structure as it will get handled in the "extra" array. |
886
|
|
|
if ( is_array($template_field_structure[$context]) && isset( $template_field_structure[$context]['extra']) ) { |
887
|
|
|
foreach ( $template_field_structure[$context]['extra'] as $reference_field => $new_fields ) { |
888
|
|
|
unset( $template_field_structure[$context][$reference_field] ); |
889
|
|
|
} |
890
|
|
|
} |
891
|
|
|
|
892
|
|
|
//let's loop through the template_field_structure and actually assemble the input fields! |
893
|
|
|
if ( !empty($template_field_structure) ) { |
894
|
|
|
$id_prefix= 'ee-msg-edit-template-fields-'; |
|
|
|
|
895
|
|
|
foreach ( $template_field_structure[$context] as $template_field => $field_setup_array ) { |
896
|
|
|
//if this is an 'extra' template field then we need to remove any existing fields that are keyed up in the extra array and reset them. |
897
|
|
|
if ( $template_field == 'extra' ) { |
898
|
|
|
$this->_template_args['is_extra_fields'] = TRUE; |
899
|
|
|
foreach ( $field_setup_array as $reference_field => $new_fields_array ) { |
900
|
|
|
foreach ( $new_fields_array as $extra_field => $extra_array ) { |
901
|
|
|
//let's verify if we need this extra field via the shortcodes parameter. |
902
|
|
|
$continue = FALSE; |
903
|
|
|
if ( isset( $extra_array['shortcodes_required'] ) ) { |
904
|
|
|
foreach ( (array) $extra_array['shortcodes_required'] as $shortcode ) { |
905
|
|
|
if ( !array_key_exists( $shortcode, $this->_shortcodes ) ) |
906
|
|
|
$continue = TRUE; |
907
|
|
|
} |
908
|
|
|
if ( $continue ) continue; |
909
|
|
|
} |
910
|
|
|
|
911
|
|
|
$field_id = $reference_field . '-' . $extra_field . '-content'; |
912
|
|
|
$template_form_fields[$field_id] = $extra_array; |
|
|
|
|
913
|
|
|
$template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']'; |
|
|
|
|
914
|
|
|
$css_class = isset( $extra_array['css_class'] ) ? $extra_array['css_class'] : ''; |
915
|
|
|
$template_form_fields[$field_id]['css_class'] = !empty( $v_fields ) && in_array($extra_field, $v_fields) && ( is_array($validators[$extra_field] ) && isset( $validators[$extra_field]['msg'] ) ) ? 'validate-error ' . $css_class : $css_class; |
916
|
|
|
$content = $message_templates[$context][$reference_field]->get('MTP_content'); |
917
|
|
|
$template_form_fields[$field_id]['value'] = !empty($message_templates) && isset($content[$extra_field]) ? stripslashes( html_entity_decode( $content[$extra_field], ENT_QUOTES, "UTF-8") ) : ''; |
918
|
|
|
|
919
|
|
|
//do we have a validation error? if we do then let's use that value instead |
920
|
|
|
$template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) ? $validators[$extra_field]['value'] : $template_form_fields[$field_id]['value']; |
921
|
|
|
|
922
|
|
|
|
923
|
|
|
$template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
924
|
|
|
|
925
|
|
|
//shortcode selector |
926
|
|
|
$field_name_to_use = $extra_field == 'main' ? 'content' : $extra_field; |
927
|
|
|
$template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( $field_name_to_use, $field_id ); |
928
|
|
|
|
929
|
|
|
if ( isset( $extra_array['input'] ) && $extra_array['input'] == 'wp_editor' ) { |
930
|
|
|
//we want to decode the entities |
931
|
|
|
$template_form_fields[$field_id]['value'] = stripslashes( html_entity_decode( $template_form_fields[$field_id]['value'], ENT_QUOTES, "UTF-8") ); |
932
|
|
|
|
933
|
|
|
}/**/ |
934
|
|
|
} |
935
|
|
|
$templatefield_MTP_id = $reference_field . '-MTP_ID'; |
936
|
|
|
$templatefield_templatename_id = $reference_field . '-name'; |
937
|
|
|
|
938
|
|
|
$template_form_fields[$templatefield_MTP_id] = array( |
939
|
|
|
'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
940
|
|
|
'label' => NULL, |
941
|
|
|
'input' => 'hidden', |
942
|
|
|
'type' => 'int', |
943
|
|
|
'required' => FALSE, |
944
|
|
|
'validation' => FALSE, |
945
|
|
|
'value' => !empty($message_templates) ? $message_templates[$context][$reference_field]->ID() : '', |
946
|
|
|
'css_class' => '', |
947
|
|
|
'format' => '%d', |
948
|
|
|
'db-col' => 'MTP_ID' |
949
|
|
|
); |
950
|
|
|
|
951
|
|
|
$template_form_fields[$templatefield_templatename_id] = array( |
952
|
|
|
'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
953
|
|
|
'label' => NULL, |
954
|
|
|
'input' => 'hidden', |
955
|
|
|
'type' => 'string', |
956
|
|
|
'required' => FALSE, |
957
|
|
|
'validation' => TRUE, |
958
|
|
|
'value' => $reference_field, |
959
|
|
|
'css_class' => '', |
960
|
|
|
'format' => '%s', |
961
|
|
|
'db-col' => 'MTP_template_field' |
962
|
|
|
); |
963
|
|
|
} |
964
|
|
|
continue; //skip the next stuff, we got the necessary fields here for this dataset. |
965
|
|
|
} else { |
966
|
|
|
$field_id = $template_field . '-content'; |
967
|
|
|
$template_form_fields[$field_id] = $field_setup_array; |
968
|
|
|
$template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
969
|
|
|
$template_form_fields[$field_id]['value'] = !empty($message_templates) && is_array($message_templates[$context]) && isset($message_templates[$context][$template_field]) ?$message_templates[$context][$template_field]->get('MTP_content') : ''; |
970
|
|
|
|
971
|
|
|
//do we have a validator error for this field? if we do then we'll use that value instead |
972
|
|
|
$template_form_fields[$field_id]['value'] = isset($validators[$template_field]) ? $validators[$template_field]['value'] : $template_form_fields[$field_id]['value']; |
973
|
|
|
|
974
|
|
|
|
975
|
|
|
$template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
976
|
|
|
$css_class = isset($field_setup_array['css_class']) ? $field_setup_array['css_class'] : ''; |
977
|
|
|
$template_form_fields[$field_id]['css_class'] = !empty( $v_fields ) && in_array( $template_field, $v_fields ) && isset( $validators[$template_field]['msg'] ) ? 'validate-error ' . $css_class : $css_class; |
978
|
|
|
|
979
|
|
|
//shortcode selector |
980
|
|
|
$template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( $template_field, $field_id ); |
981
|
|
|
|
982
|
|
|
if ( isset( $field_setup_array['input'] ) && $field_setup_array['input'] == 'wp_editor' ) { |
983
|
|
|
//we want to decode the entities |
984
|
|
|
$template_form_fields[$field_id]['value'] = $template_form_fields[$field_id]['value']; |
985
|
|
|
}/**/ |
986
|
|
|
} |
987
|
|
|
|
988
|
|
|
//k took care of content field(s) now let's take care of others. |
989
|
|
|
|
990
|
|
|
$templatefield_MTP_id = $template_field . '-MTP_ID'; |
991
|
|
|
$templatefield_field_templatename_id = $template_field . '-name'; |
992
|
|
|
|
993
|
|
|
//foreach template field there are actually two form fields created |
994
|
|
|
$template_form_fields[$templatefield_MTP_id] = array( |
995
|
|
|
'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
996
|
|
|
'label' => NULL, |
997
|
|
|
'input' => 'hidden', |
998
|
|
|
'type' => 'int', |
999
|
|
|
'required' => FALSE, |
1000
|
|
|
'validation' => TRUE, |
1001
|
|
|
'value' => !empty($message_templates) ? $message_templates[$context][$template_field]->ID() : '', |
1002
|
|
|
'css_class' => '', |
1003
|
|
|
'format' => '%d', |
1004
|
|
|
'db-col' => 'MTP_ID' |
1005
|
|
|
); |
1006
|
|
|
|
1007
|
|
|
$template_form_fields[$templatefield_field_templatename_id] = array( |
1008
|
|
|
'name' => 'MTP_template_fields[' . $template_field . '][name]', |
1009
|
|
|
'label' => NULL, |
1010
|
|
|
'input' => 'hidden', |
1011
|
|
|
'type' => 'string', |
1012
|
|
|
'required' => FALSE, |
1013
|
|
|
'validation' => TRUE, |
1014
|
|
|
'value' => $template_field, |
1015
|
|
|
'css_class' => '', |
1016
|
|
|
'format' => '%s', |
1017
|
|
|
'db-col' => 'MTP_template_field' |
1018
|
|
|
); |
1019
|
|
|
|
1020
|
|
|
} |
1021
|
|
|
|
1022
|
|
|
//add other fields |
1023
|
|
|
$template_form_fields['ee-msg-current-context'] = array( |
1024
|
|
|
'name' => 'MTP_context', |
1025
|
|
|
'label' => null, |
1026
|
|
|
'input' => 'hidden', |
1027
|
|
|
'type' => 'string', |
1028
|
|
|
'required' => FALSE, |
1029
|
|
|
'validation' => TRUE, |
1030
|
|
|
'value' => $context, |
1031
|
|
|
'css_class' => '', |
1032
|
|
|
'format' => '%s', |
1033
|
|
|
'db-col' => 'MTP_context' |
1034
|
|
|
); |
1035
|
|
|
|
1036
|
|
|
$template_form_fields['ee-msg-grp-id'] = array( |
1037
|
|
|
'name' => 'GRP_ID', |
1038
|
|
|
'label' => null, |
1039
|
|
|
'input' => 'hidden', |
1040
|
|
|
'type' => 'int', |
1041
|
|
|
'required' => FALSE, |
1042
|
|
|
'validation' => TRUE, |
1043
|
|
|
'value' => $GRP_ID, |
1044
|
|
|
'css_class' => '', |
1045
|
|
|
'format' => '%d', |
1046
|
|
|
'db-col' => 'GRP_ID' |
1047
|
|
|
); |
1048
|
|
|
|
1049
|
|
|
$template_form_fields['ee-msg-messenger'] = array( |
1050
|
|
|
'name' => 'MTP_messenger', |
1051
|
|
|
'label' => null, |
1052
|
|
|
'input' => 'hidden', |
1053
|
|
|
'type' => 'string', |
1054
|
|
|
'required' => FALSE, |
1055
|
|
|
'validation' => TRUE, |
1056
|
|
|
'value' => $message_template_group->messenger(), |
|
|
|
|
1057
|
|
|
'css_class' => '', |
1058
|
|
|
'format' => '%s', |
1059
|
|
|
'db-col' => 'MTP_messenger' |
1060
|
|
|
); |
1061
|
|
|
|
1062
|
|
|
$template_form_fields['ee-msg-message-type'] = array( |
1063
|
|
|
'name' => 'MTP_message_type', |
1064
|
|
|
'label' => null, |
1065
|
|
|
'input' => 'hidden', |
1066
|
|
|
'type' => 'string', |
1067
|
|
|
'required' => FALSE, |
1068
|
|
|
'validation' => TRUE, |
1069
|
|
|
'value' => $message_template_group->message_type(), |
|
|
|
|
1070
|
|
|
'css_class' => '', |
1071
|
|
|
'format' => '%s', |
1072
|
|
|
'db-col' => 'MTP_message_type' |
1073
|
|
|
); |
1074
|
|
|
|
1075
|
|
|
$sidebar_form_fields['ee-msg-is-global'] = array( |
|
|
|
|
1076
|
|
|
'name' => 'MTP_is_global', |
1077
|
|
|
'label' => __('Global Template', 'event_espresso'), |
1078
|
|
|
'input' => 'hidden', |
1079
|
|
|
'type' => 'int', |
1080
|
|
|
'required' => FALSE, |
1081
|
|
|
'validation' => TRUE, |
1082
|
|
|
'value' => $message_template_group->get('MTP_is_global'), |
1083
|
|
|
'css_class' => '', |
1084
|
|
|
'format' => '%d', |
1085
|
|
|
'db-col' => 'MTP_is_global' |
1086
|
|
|
); |
1087
|
|
|
|
1088
|
|
|
$sidebar_form_fields['ee-msg-is-override'] = array( |
1089
|
|
|
'name' => 'MTP_is_override', |
1090
|
|
|
'label' => __('Override all custom', 'event_espresso'), |
1091
|
|
|
'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden', |
|
|
|
|
1092
|
|
|
'type' => 'int', |
1093
|
|
|
'required' => FALSE, |
1094
|
|
|
'validation' => TRUE, |
1095
|
|
|
'value' => $message_template_group->get('MTP_is_override'), |
1096
|
|
|
'css_class' => '', |
1097
|
|
|
'format' => '%d', |
1098
|
|
|
'db-col' => 'MTP_is_override' |
1099
|
|
|
); |
1100
|
|
|
|
1101
|
|
|
$sidebar_form_fields['ee-msg-is-active'] = array( |
1102
|
|
|
'name' => 'MTP_is_active', |
1103
|
|
|
'label' => __('Active Template', 'event_espresso'), |
1104
|
|
|
'input' => 'hidden', |
1105
|
|
|
'type' => 'int', |
1106
|
|
|
'required' => FALSE, |
1107
|
|
|
'validation' => TRUE, |
1108
|
|
|
'value' => $message_template_group->is_active(), |
|
|
|
|
1109
|
|
|
'css_class' => '', |
1110
|
|
|
'format' => '%d', |
1111
|
|
|
'db-col' => 'MTP_is_active' |
1112
|
|
|
); |
1113
|
|
|
|
1114
|
|
|
$sidebar_form_fields['ee-msg-deleted'] = array( |
1115
|
|
|
'name' => 'MTP_deleted', |
1116
|
|
|
'label' => null, |
1117
|
|
|
'input' => 'hidden', |
1118
|
|
|
'type' => 'int', |
1119
|
|
|
'required' => FALSE, |
1120
|
|
|
'validation' => TRUE, |
1121
|
|
|
'value' => $message_template_group->get('MTP_deleted'), |
1122
|
|
|
'css_class' => '', |
1123
|
|
|
'format' => '%d', |
1124
|
|
|
'db-col' => 'MTP_deleted' |
1125
|
|
|
); |
1126
|
|
|
$sidebar_form_fields['ee-msg-author'] = array( |
1127
|
|
|
'name' => 'MTP_user_id', |
1128
|
|
|
'label' => __('Author', 'event_espresso'), |
1129
|
|
|
'input' => 'hidden', |
1130
|
|
|
'type'=> 'int', |
1131
|
|
|
'required' => FALSE, |
1132
|
|
|
'validation' => FALSE, |
1133
|
|
|
'value' => $message_template_group->user(), |
|
|
|
|
1134
|
|
|
'format' => '%d', |
1135
|
|
|
'db-col' => 'MTP_user_id' |
1136
|
|
|
); |
1137
|
|
|
|
1138
|
|
|
$sidebar_form_fields['ee-msg-route'] = array( |
1139
|
|
|
'name' => 'action', |
1140
|
|
|
'input' => 'hidden', |
1141
|
|
|
'type' => 'string', |
1142
|
|
|
'value' => $action |
1143
|
|
|
); |
1144
|
|
|
|
1145
|
|
|
$sidebar_form_fields['ee-msg-id'] = array( |
1146
|
|
|
'name' => 'id', |
1147
|
|
|
'input' => 'hidden', |
1148
|
|
|
'type' => 'int', |
1149
|
|
|
'value' => $GRP_ID |
1150
|
|
|
); |
1151
|
|
|
$sidebar_form_fields['ee-msg-evt-nonce'] = array( |
1152
|
|
|
'name' => $action . '_nonce', |
1153
|
|
|
'input' => 'hidden', |
1154
|
|
|
'type' => 'string', |
1155
|
|
|
'value' => wp_create_nonce( $action . '_nonce') |
1156
|
|
|
); |
1157
|
|
|
|
1158
|
|
|
$sidebar_array = array('ee-msg-is-global', 'ee-msg-is-override', 'ee-msg-deleted', 'ee-msg-is-active'); |
|
|
|
|
1159
|
|
|
|
1160
|
|
|
if ( isset($this->_req_data['template_switch']) && $this->_req_data['template_switch'] ) { |
1161
|
|
|
$sidebar_form_fields['ee-msg-template-switch'] = array( |
1162
|
|
|
'name' => 'template_switch', |
1163
|
|
|
'input' => 'hidden', |
1164
|
|
|
'type' => 'int', |
1165
|
|
|
'value' => 1 |
1166
|
|
|
); |
1167
|
|
|
} |
1168
|
|
|
|
1169
|
|
|
|
1170
|
|
|
$template_fields = $this->_generate_admin_form_fields( $template_form_fields ); |
1171
|
|
|
$sidebar_fields = $this->_generate_admin_form_fields( $sidebar_form_fields ); |
1172
|
|
|
|
1173
|
|
|
|
1174
|
|
|
} //end if ( !empty($template_field_structure) ) |
1175
|
|
|
|
1176
|
|
|
//set extra content for publish box |
1177
|
|
|
$this->_template_args['publish_box_extra_content'] = $sidebar_fields; |
|
|
|
|
1178
|
|
|
$this->_set_publish_post_box_vars( 'id', $GRP_ID ); |
1179
|
|
|
|
1180
|
|
|
//add preview button |
1181
|
|
|
$preview_url = parent::add_query_args_and_nonce( array( 'message_type' => $message_template_group->message_type(), 'messenger' => $message_template_group->messenger(), 'context' => $context,'GRP_ID' => $GRP_ID, 'action' => 'preview_message' ), $this->_admin_base_url ); |
|
|
|
|
1182
|
|
|
$preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview', 'event_espresso') . '</a>'; |
1183
|
|
|
|
1184
|
|
|
|
1185
|
|
|
//setup context switcher |
1186
|
|
|
$context_switcher_args = array( |
1187
|
|
|
'page' => 'espresso_messages', |
1188
|
|
|
'action' => 'edit_message_template', |
1189
|
|
|
'id' => $GRP_ID, |
1190
|
|
|
'context' => $context, |
1191
|
|
|
'extra' => $preview_button |
1192
|
|
|
); |
1193
|
|
|
$this->_set_context_switcher($message_template_group, $context_switcher_args); |
|
|
|
|
1194
|
|
|
|
1195
|
|
|
|
1196
|
|
|
//main box |
1197
|
|
|
$this->_template_args['template_fields'] = $template_fields; |
|
|
|
|
1198
|
|
|
$this->_template_args['sidebar_box_id'] = 'details'; |
1199
|
|
|
$this->_template_args['action'] = $action; |
1200
|
|
|
$this->_template_args['context'] = $context; |
1201
|
|
|
$this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url; |
1202
|
|
|
$this->_template_args['learn_more_about_message_templates_link'] = $this->_learn_more_about_message_templates_link(); |
1203
|
|
|
|
1204
|
|
|
|
1205
|
|
|
$this->_template_args['before_admin_page_content'] = $this->add_context_switcher(); |
1206
|
|
|
$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before(); |
1207
|
|
|
$this->_template_args['after_admin_page_content'] = $this->_add_form_element_after(); |
1208
|
|
|
|
1209
|
|
|
$this->_template_path = $this->_template_args['GRP_ID'] ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
1210
|
|
|
|
1211
|
|
|
//send along EE_Message_Template_Group object for further template use. |
1212
|
|
|
$this->_template_args['MTP'] = $message_template_group; |
1213
|
|
|
|
1214
|
|
|
$this->_template_args['admin_page_content'] = EEH_Template::display_template( $this->_template_path, $this->_template_args, TRUE ); |
1215
|
|
|
|
1216
|
|
|
|
1217
|
|
|
//finally, let's set the admin_page title |
1218
|
|
|
$this->_admin_page_title = sprintf( __('Editing %s', 'event_espresso'), $title ); |
1219
|
|
|
|
1220
|
|
|
|
1221
|
|
|
//we need to take care of setting the shortcodes property for use elsewhere. |
1222
|
|
|
$this->_set_shortcodes(); |
1223
|
|
|
|
1224
|
|
|
|
1225
|
|
|
|
1226
|
|
|
//final template wrapper |
1227
|
|
|
$this->display_admin_page_with_sidebar(); |
1228
|
|
|
} |
1229
|
|
|
|
1230
|
|
|
|
1231
|
|
|
public function filter_tinymce_init( $mceInit, $editor_id ) { |
|
|
|
|
1232
|
|
|
return $mceInit; |
1233
|
|
|
} |
1234
|
|
|
|
1235
|
|
|
|
1236
|
|
|
|
1237
|
|
|
public function add_context_switcher() { |
1238
|
|
|
return $this->_context_switcher; |
1239
|
|
|
} |
1240
|
|
|
|
1241
|
|
|
public function _add_form_element_before() { |
1242
|
|
|
return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">'; |
1243
|
|
|
} |
1244
|
|
|
|
1245
|
|
|
public function _add_form_element_after() { |
1246
|
|
|
return '</form>'; |
1247
|
|
|
} |
1248
|
|
|
|
1249
|
|
|
|
1250
|
|
|
|
1251
|
|
|
|
1252
|
|
|
/** |
1253
|
|
|
* This executes switching the template pack for a message template. |
1254
|
|
|
* |
1255
|
|
|
* @since 4.5.0 |
1256
|
|
|
* |
1257
|
|
|
* @return json json object |
1258
|
|
|
*/ |
1259
|
|
|
public function switch_template_pack() { |
1260
|
|
|
$GRP_ID = ! empty( $this->_req_data['GRP_ID'] ) ? $this->_req_data['GRP_ID'] : 0; |
1261
|
|
|
$template_pack = ! empty( $this->_req_data['template_pack'] ) ? $this->_req_data['template_pack'] : ''; |
1262
|
|
|
|
1263
|
|
|
//verify we have needed values. |
1264
|
|
|
if ( empty( $GRP_ID ) || empty( $template_pack ) ) { |
1265
|
|
|
$this->_template_args['error'] = TRUE; |
1266
|
|
|
EE_Error::add_error( __('The required date for switching templates is not available.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
1267
|
|
|
} else { |
1268
|
|
|
//get template, set the new template_pack and then reset to default |
1269
|
|
|
$mtpg = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
1270
|
|
|
|
1271
|
|
|
$mtpg->set_template_pack_name( $template_pack ); |
|
|
|
|
1272
|
|
|
$this->_req_data['msgr'] = $mtpg->messenger(); |
|
|
|
|
1273
|
|
|
$this->_req_data['mt'] = $mtpg->message_type(); |
|
|
|
|
1274
|
|
|
|
1275
|
|
|
$query_args = $this->_reset_to_default_template(); |
1276
|
|
|
|
1277
|
|
|
if ( empty( $query_args['id'] ) ) { |
1278
|
|
|
EE_Error::add_error( __('Something went wrong with switching the template pack. Please try again or contact EE support', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
1279
|
|
|
$this->_template_args['error'] = TRUE; |
1280
|
|
|
} else { |
1281
|
|
|
$template_label =$mtpg->get_template_pack()->label; |
|
|
|
|
1282
|
|
|
$template_pack_labels = $mtpg->messenger_obj()->get_supports_labels(); |
|
|
|
|
1283
|
|
|
EE_Error::add_success( sprintf( __('This message template has been successfully switched to use the %s %s. Please wait while the page reloads with your new template.', 'event_espresso'), $template_label, $template_pack_labels->template_pack ) ); |
1284
|
|
|
//generate the redirect url for js. |
1285
|
|
|
$url = self::add_query_args_and_nonce( $query_args, $this->_admin_base_url ); |
1286
|
|
|
$this->_template_args['data']['redirect_url'] = $url; |
1287
|
|
|
$this->_template_args['success'] = true; |
1288
|
|
|
} |
1289
|
|
|
|
1290
|
|
|
$this->_return_json(); |
1291
|
|
|
|
1292
|
|
|
} |
1293
|
|
|
} |
1294
|
|
|
|
1295
|
|
|
|
1296
|
|
|
|
1297
|
|
|
/** |
1298
|
|
|
* This handles resetting the template for the given messenger/message_type so that users can start from scratch if they want. |
1299
|
|
|
* |
1300
|
|
|
* @access protected |
1301
|
|
|
* @return void |
1302
|
|
|
*/ |
1303
|
|
|
protected function _reset_to_default_template() { |
1304
|
|
|
$success = TRUE; |
|
|
|
|
1305
|
|
|
$templates = array(); |
1306
|
|
|
$GRP_ID = !empty( $this->_req_data['GRP_ID'] ) ? $this->_req_data['GRP_ID'] : 0; |
1307
|
|
|
//we need to make sure we've got the info we need. |
1308
|
|
|
if ( !isset( $this->_req_data['msgr'] ) && !isset( $this->_req_data['mt'] ) && !isset( $this->_req_data['GRP_ID'] ) ) { |
1309
|
|
|
EE_Error::add_error( __('In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset. At least one of these is missing.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
1310
|
|
|
$success = FALSE; |
|
|
|
|
1311
|
|
|
} |
1312
|
|
|
|
1313
|
|
|
//all templates will be reset to whatever the defaults are for the global template matching the messenger and message type. |
1314
|
|
|
$success = !empty( $GRP_ID ) ? TRUE : FALSE; |
1315
|
|
|
|
1316
|
|
|
if ( $success ) { |
1317
|
|
|
|
1318
|
|
|
//let's first determine if the incoming template is a global template, if it isn't then we need to get the global template matching messenger and message type. |
1319
|
|
|
$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
|
|
|
|
1320
|
|
|
|
1321
|
|
|
|
1322
|
|
|
//note this is ONLY deleteing the template fields (Message Template rows) NOT the message template group. |
1323
|
|
|
$success = $this->_delete_mtp_permanently( $GRP_ID, FALSE ); |
1324
|
|
|
|
1325
|
|
|
if ( $success ) { |
1326
|
|
|
//if successfully deleted, lets generate the new ones. Note. We set GLOBAL to true, because resets on ANY template will use the related global template defaults for regeneration. This means that if a custom template is reset it resets to whatever the related global template is. HOWEVER, we DO keep the template pack and template variation set for the current custom template when resetting. |
1327
|
|
|
$templates = $this->_generate_new_templates( $this->_req_data['msgr'], $this->_req_data['mt'], $GRP_ID, TRUE ); |
|
|
|
|
1328
|
|
|
} |
1329
|
|
|
|
1330
|
|
|
} |
1331
|
|
|
|
1332
|
|
|
//any error messages? |
1333
|
|
|
if ( !$success ) { |
1334
|
|
|
EE_Error::add_error( __('Something went wrong with deleting existing templates. Unable to reset to default', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
1335
|
|
|
} |
1336
|
|
|
|
1337
|
|
|
//all good, let's add a success message! |
1338
|
|
|
if ( $success && ! empty( $templates ) ) { |
1339
|
|
|
$templates = $templates[0]; //the info for the template we generated is the first element in the returned array. |
1340
|
|
|
EE_Error::overwrite_success(); |
1341
|
|
|
EE_Error::add_success( __('Templates have been reset to defaults.', 'event_espresso') ); |
1342
|
|
|
} |
1343
|
|
|
|
1344
|
|
|
|
1345
|
|
|
$query_args = array( |
1346
|
|
|
'id' => isset( $templates['GRP_ID'] ) ? $templates['GRP_ID'] : NULL, |
1347
|
|
|
'context' => isset( $templates['MTP_context'] ) ? $templates['MTP_context'] : NULL, |
1348
|
|
|
'action' => isset( $templates['GRP_ID'] ) ? 'edit_message_template' : 'default' |
1349
|
|
|
); |
1350
|
|
|
|
1351
|
|
|
//if called via ajax then we return query args otherwise redirect |
1352
|
|
View Code Duplication |
if ( defined('DOING_AJAX') && DOING_AJAX ) { |
1353
|
|
|
return $query_args; |
1354
|
|
|
} else { |
1355
|
|
|
$this->_redirect_after_action( FALSE, '', '', $query_args, TRUE ); |
1356
|
|
|
} |
1357
|
|
|
|
1358
|
|
|
} |
1359
|
|
|
|
1360
|
|
|
|
1361
|
|
|
|
1362
|
|
|
/** |
1363
|
|
|
* Retrieve and set the message preview for display. |
1364
|
|
|
* |
1365
|
|
|
* @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview. |
1366
|
|
|
* @return void |
1367
|
|
|
*/ |
1368
|
|
|
public function _preview_message( $send = FALSE ) { |
1369
|
|
|
//first make sure we've got the necessary parameters |
1370
|
|
|
if ( !isset( $this->_req_data['message_type'] ) || !isset( $this->_req_data['messenger'] ) || !isset( $this->_req_data['messenger'] ) || !isset( $this->_req_data['GRP_ID'] ) ) { |
1371
|
|
|
EE_Error::add_error( __('Missing necessary parameters for displaying preview', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
1372
|
|
|
} |
1373
|
|
|
|
1374
|
|
|
EE_Registry::instance()->REQ->set( 'GRP_ID', $this->_req_data['GRP_ID'] ); |
1375
|
|
|
|
1376
|
|
|
$MSG = new EE_messages(); |
1377
|
|
|
|
1378
|
|
|
//get the preview! |
1379
|
|
|
$preview = $MSG->preview_message( $this->_req_data['message_type'], $this->_req_data['context'], $this->_req_data['messenger'], $send ); |
1380
|
|
|
|
1381
|
|
|
if ( $send ) { |
1382
|
|
|
return $preview; |
1383
|
|
|
} |
1384
|
|
|
|
1385
|
|
|
//let's add a button to go back to the edit view |
1386
|
|
|
$query_args = array( |
1387
|
|
|
'id' => $this->_req_data['GRP_ID'], |
1388
|
|
|
'context' => $this->_req_data['context'], |
1389
|
|
|
'action' => 'edit_message_template' |
1390
|
|
|
); |
1391
|
|
|
$go_back_url = parent::add_query_args_and_nonce( $query_args, $this->_admin_base_url ); |
|
|
|
|
1392
|
|
|
$preview_button = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit', 'event_espresso') . '</a>'; |
1393
|
|
|
|
1394
|
|
|
//let's provide a helpful title for context |
1395
|
|
|
$preview_title = sprintf( __('Viewing Preview for %s %s Message Template', 'event_espresso'), ucwords($this->_active_messengers[$this->_req_data['messenger']]['obj']->label['singular']), ucwords($this->_active_message_types[$this->_req_data['message_type']]['obj']->label['singular']) ); |
1396
|
|
|
|
1397
|
|
|
|
1398
|
|
|
//setup display of preview. |
1399
|
|
|
$this->_admin_page_title = $preview_title; |
1400
|
|
|
$this->_template_args['admin_page_content'] = $preview_button . '<br />' .stripslashes($preview); |
1401
|
|
|
$this->_template_args['data']['force_json'] = TRUE; |
1402
|
|
|
} |
1403
|
|
|
|
1404
|
|
|
|
1405
|
|
|
|
1406
|
|
|
|
1407
|
|
|
/** |
1408
|
|
|
* The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it gets called automatically. |
1409
|
|
|
* |
1410
|
|
|
* @since 4.5.0 |
1411
|
|
|
* |
1412
|
|
|
* @return string |
1413
|
|
|
*/ |
1414
|
|
|
protected function _display_preview_message() { |
1415
|
|
|
$this->display_admin_page_with_no_sidebar(); |
1416
|
|
|
} |
1417
|
|
|
|
1418
|
|
|
|
1419
|
|
|
|
1420
|
|
|
|
1421
|
|
|
/** |
1422
|
|
|
* registers metaboxes that should show up on the "edit_message_template" page |
1423
|
|
|
* |
1424
|
|
|
* @access protected |
1425
|
|
|
* @return void |
1426
|
|
|
*/ |
1427
|
|
|
protected function _register_edit_meta_boxes() { |
1428
|
|
|
add_meta_box( 'mtp_valid_shortcodes', __('Valid Shortcodes', 'event_espresso'), array( $this, 'shortcode_meta_box' ), $this->_current_screen->id, 'side', 'default' ); |
1429
|
|
|
add_meta_box( 'mtp_extra_actions', __('Extra Actions', 'event_espresso'), array( $this, 'extra_actions_meta_box' ), $this->_current_screen->id, 'side', 'high' ); |
1430
|
|
|
add_meta_box( 'mtp_templates', __('Template Styles', 'event_espresso'), array( $this, 'template_pack_meta_box' ), $this->_current_screen->id, 'side', 'high' ); |
1431
|
|
|
} |
1432
|
|
|
|
1433
|
|
|
|
1434
|
|
|
|
1435
|
|
|
/** |
1436
|
|
|
* metabox content for all template pack and variation selection. |
1437
|
|
|
* |
1438
|
|
|
* @since 4.5.0 |
1439
|
|
|
* |
1440
|
|
|
* @return string |
1441
|
|
|
*/ |
1442
|
|
|
public function template_pack_meta_box() { |
1443
|
|
|
$this->_set_message_template_group(); |
1444
|
|
|
|
1445
|
|
|
|
1446
|
|
|
//setup template pack select values. |
1447
|
|
|
$template_packs = EED_Messages::get_template_packs(); |
1448
|
|
|
|
1449
|
|
|
$tp_select_values = array(); |
1450
|
|
|
|
1451
|
|
|
foreach ( $template_packs as $tp ) { |
1452
|
|
|
//only include template packs that support this messenger and message type! |
1453
|
|
|
$supports = $tp->get_supports(); |
1454
|
|
|
if ( ! isset( $supports[$this->_message_template_group->messenger()] ) || ! in_array( $this->_message_template_group->message_type(), $supports[$this->_message_template_group->messenger()] ) ) { |
|
|
|
|
1455
|
|
|
//not supported |
1456
|
|
|
continue; |
1457
|
|
|
} |
1458
|
|
|
|
1459
|
|
|
$tp_select_values[] = array( |
1460
|
|
|
'text' => $tp->label, |
1461
|
|
|
'id' => $tp->dbref |
1462
|
|
|
); |
1463
|
|
|
} |
1464
|
|
|
|
1465
|
|
|
//if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by the default template pack. This still allows for the odd template pack to override. |
1466
|
|
|
if ( empty( $tp_select_values ) ) { |
1467
|
|
|
$tp_select_values[] = array( |
1468
|
|
|
'text' => __('Default', 'event_espresso'), |
1469
|
|
|
'id' => 'default' |
1470
|
|
|
); |
1471
|
|
|
} |
1472
|
|
|
|
1473
|
|
|
//setup variation select values for the currently selected template. |
1474
|
|
|
$variations = $this->_message_template_group->get_template_pack()->get_variations( $this->_message_template_group->messenger(), $this->_message_template_group->message_type() ); |
|
|
|
|
1475
|
|
|
$variations_select_values = array(); |
1476
|
|
|
foreach ( $variations as $variation => $label ) { |
1477
|
|
|
$variations_select_values[] = array( |
1478
|
|
|
'text' => $label, |
1479
|
|
|
'id' => $variation |
1480
|
|
|
); |
1481
|
|
|
} |
1482
|
|
|
|
1483
|
|
|
$template_pack_labels= $this->_message_template_group->messenger_obj()->get_supports_labels(); |
|
|
|
|
1484
|
|
|
|
1485
|
|
|
$template_args['template_packs_selector'] = EEH_Form_Fields::select_input( 'MTP_template_pack', $tp_select_values, $this->_message_template_group->get_template_pack_name() ); |
|
|
|
|
1486
|
|
|
$template_args['variations_selector'] = EEH_Form_Fields::select_input( 'MTP_template_variation', $variations_select_values, $this->_message_template_group->get_template_pack_variation() ); |
|
|
|
|
1487
|
|
|
$template_args['template_pack_label'] = $template_pack_labels->template_pack; |
1488
|
|
|
$template_args['template_variation_label'] = $template_pack_labels->template_variation; |
1489
|
|
|
$template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
1490
|
|
|
$template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
1491
|
|
|
|
1492
|
|
|
$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
1493
|
|
|
|
1494
|
|
|
EEH_Template::display_template( $template, $template_args ); |
1495
|
|
|
} |
1496
|
|
|
|
1497
|
|
|
|
1498
|
|
|
|
1499
|
|
|
/** |
1500
|
|
|
* This meta box holds any extra actions related to Message Templates |
1501
|
|
|
* For now, this includes Resetting templates to defaults and sending a test email. |
1502
|
|
|
* |
1503
|
|
|
* @access public |
1504
|
|
|
* @return void |
1505
|
|
|
*/ |
1506
|
|
|
public function extra_actions_meta_box() { |
1507
|
|
|
$template_form_fields = array(); |
1508
|
|
|
|
1509
|
|
|
$extra_args = array( |
1510
|
|
|
'msgr' => $this->_message_template_group->messenger(), |
|
|
|
|
1511
|
|
|
'mt' => $this->_message_template_group->message_type(), |
|
|
|
|
1512
|
|
|
'GRP_ID' => $this->_message_template_group->GRP_ID() |
|
|
|
|
1513
|
|
|
); |
1514
|
|
|
|
1515
|
|
|
$button = $this->get_action_link_or_button( 'reset_to_default', 'reset', $extra_args, 'button-primary reset-default-button' ); |
1516
|
|
|
|
1517
|
|
|
|
1518
|
|
|
//test button |
1519
|
|
|
//first we need to see if there are any fields |
1520
|
|
|
$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields(); |
|
|
|
|
1521
|
|
|
|
1522
|
|
|
if ( !empty( $fields ) ) { |
1523
|
|
|
//yup there be fields |
1524
|
|
|
foreach ( $fields as $field => $config ) { |
1525
|
|
|
$field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
|
|
|
1526
|
|
|
$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
|
|
|
|
1527
|
|
|
$default = isset( $config['default'] ) ? $config['default'] : ''; |
1528
|
|
|
$default = isset( $config['value'] ) ? $config['value'] : $default; |
1529
|
|
|
|
1530
|
|
|
//if type is hidden and the value is empty something may have gone wrong so let's correct with the defaults |
1531
|
|
|
$fix = $config['input'] == 'hidden' && isset($existing[$field]) && empty($existing[$field]) ? $default : ''; |
1532
|
|
|
$existing[$field] = isset( $existing[$field] ) && empty( $fix ) ? $existing[$field] : $fix; |
1533
|
|
|
|
1534
|
|
|
$template_form_fields[$field_id] = array( |
1535
|
|
|
'name' => 'test_settings_fld[' . $field . ']', |
1536
|
|
|
'label' => $config['label'], |
1537
|
|
|
'input' => $config['input'], |
1538
|
|
|
'type' => $config['type'], |
1539
|
|
|
'required' => $config['required'], |
1540
|
|
|
'validation' => $config['validation'], |
1541
|
|
|
'value' => isset( $existing[$field] ) ? $existing[$field] : $default, |
1542
|
|
|
'css_class' => $config['css_class'], |
1543
|
|
|
'options' => isset( $config['options'] ) ? $config['options'] : array(), |
1544
|
|
|
'default' => $default, |
1545
|
|
|
'format' => $config['format'] |
1546
|
|
|
); |
1547
|
|
|
} |
1548
|
|
|
} |
1549
|
|
|
|
1550
|
|
|
$test_settings_fields = !empty( $template_form_fields) ? $this->_generate_admin_form_fields( $template_form_fields, 'string', 'ee_tst_settings_flds' ) : ''; |
|
|
|
|
1551
|
|
|
|
1552
|
|
|
$test_settings_html = ''; |
1553
|
|
|
//print out $test_settings_fields |
1554
|
|
|
if ( !empty( $test_settings_fields ) ) { |
1555
|
|
|
echo $test_settings_fields; |
1556
|
|
|
$test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" name="test_button" value="' . __('Test Send', 'event_espresso') . '" /><div style="clear:both"></div>'; |
1557
|
|
|
} |
1558
|
|
|
|
1559
|
|
|
//and button |
1560
|
|
|
echo $test_settings_html . '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>' . '<div class="publishing-action alignright resetbutton">' . $button . '</div><div style="clear:both"></div>'; |
1561
|
|
|
} |
1562
|
|
|
|
1563
|
|
|
|
1564
|
|
|
|
1565
|
|
|
|
1566
|
|
|
/** |
1567
|
|
|
* This returns the shortcode selector skeleton for a given context and field. |
1568
|
|
|
* |
1569
|
|
|
* @since 4.9.rc.000 |
1570
|
|
|
* |
1571
|
|
|
* @param string $field The name of the field retrieving shortcodes for. |
1572
|
|
|
* @param string $linked_input_id The css id of the input that the shortcodes get added to. |
1573
|
|
|
* @return string |
1574
|
|
|
*/ |
1575
|
|
|
protected function _get_shortcode_selector( $field, $linked_input_id ) { |
1576
|
|
|
$template_args = array( |
1577
|
|
|
'shortcodes' => $this->_get_shortcodes( array( $field ), true ), |
1578
|
|
|
'fieldname' => $field, |
1579
|
|
|
'linked_input_id' => $linked_input_id |
1580
|
|
|
); |
1581
|
|
|
return EEH_Template::display_template( EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', $template_args, true ); |
1582
|
|
|
} |
1583
|
|
|
|
1584
|
|
|
|
1585
|
|
|
/** |
1586
|
|
|
* This just takes care of returning the meta box content for shortcodes (only used on the edit message template page) |
1587
|
|
|
* |
1588
|
|
|
* @access public |
1589
|
|
|
* @return void |
1590
|
|
|
*/ |
1591
|
|
|
public function shortcode_meta_box() { |
1592
|
|
|
$shortcodes = $this->_get_shortcodes(array(), FALSE); //just make sure shortcodes property is set |
1593
|
|
|
$messenger = $this->_message_template_group->messenger_obj(); |
|
|
|
|
1594
|
|
|
//now let's set the content depending on the status of the shortcodes array |
1595
|
|
|
if ( empty( $shortcodes ) ) { |
1596
|
|
|
$content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
1597
|
|
|
echo $content; |
1598
|
|
|
} else { |
1599
|
|
|
$alt = 0; |
|
|
|
|
1600
|
|
|
?> |
1601
|
|
|
<div style="float:right; margin-top:10px"><?php echo $this->_get_help_tab_link('message_template_shortcodes'); ?></div><p class="small-text"><?php printf( __('You can view the shortcodes usable in your template by clicking the %s icon next to each field.', 'event_espresso' ), '<span class="dashicons dashicons-menu"></span>' ); ?></p> |
1602
|
|
|
<?php |
1603
|
|
|
} |
1604
|
|
|
|
1605
|
|
|
|
1606
|
|
|
} |
1607
|
|
|
|
1608
|
|
|
|
1609
|
|
|
/** |
1610
|
|
|
* used to set the $_shortcodes property for when its needed elsewhere. |
1611
|
|
|
* |
1612
|
|
|
* @access protected |
1613
|
|
|
* @return void |
1614
|
|
|
*/ |
1615
|
|
|
protected function _set_shortcodes() { |
1616
|
|
|
|
1617
|
|
|
//no need to run this if the property is already set |
1618
|
|
|
if ( !empty($this->_shortcodes ) ) return; |
1619
|
|
|
|
1620
|
|
|
$this->_shortcodes = $this->_get_shortcodes(); |
1621
|
|
|
} |
1622
|
|
|
|
1623
|
|
|
|
1624
|
|
|
|
1625
|
|
|
|
1626
|
|
|
|
1627
|
|
|
/** |
1628
|
|
|
* get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes property) |
1629
|
|
|
* |
1630
|
|
|
* @access protected |
1631
|
|
|
* @param array $fields include an array of specific field name sthat you want to be used to get the shortcodes for. Defaults to all (for the given context) |
1632
|
|
|
* @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes |
1633
|
|
|
* @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is true just an array of shortcode/label pairs. |
1634
|
|
|
*/ |
1635
|
|
|
protected function _get_shortcodes( $fields = array(), $merged = TRUE ) { |
1636
|
|
|
$this->_set_message_template_group(); |
1637
|
|
|
|
1638
|
|
|
//we need the messenger and message template to retrieve the valid shortcodes array. |
1639
|
|
|
$GRP_ID = isset( $this->_req_data['id'] ) && !empty( $this->_req_data['id'] ) ? absint( $this->_req_data['id'] ) : FALSE; |
1640
|
|
|
$context = isset( $this->_req_data['context'] ) ? $this->_req_data['context'] : key( $this->_message_template_group->contexts_config() ); |
|
|
|
|
1641
|
|
|
|
1642
|
|
|
return !empty($GRP_ID) ? $this->_message_template_group->get_shortcodes( $context, $fields, $merged ) : array(); |
|
|
|
|
1643
|
|
|
} |
1644
|
|
|
|
1645
|
|
|
|
1646
|
|
|
|
1647
|
|
|
/** |
1648
|
|
|
* This sets the _message_template property (containing the called message_template object) |
1649
|
|
|
* |
1650
|
|
|
* @access protected |
1651
|
|
|
* @return void |
1652
|
|
|
*/ |
1653
|
|
|
protected function _set_message_template_group() { |
1654
|
|
|
|
1655
|
|
|
if ( !empty( $this->_message_template_group ) ) |
1656
|
|
|
return; //get out if this is already set. |
1657
|
|
|
|
1658
|
|
|
$GRP_ID = ! empty( $this->_req_data['GRP_ID'] ) ? absint( $this->_req_data['GRP_ID'] ) : FALSE; |
1659
|
|
|
$GRP_ID = empty( $GRP_ID ) && ! empty( $this->_req_data['id'] ) ? $this->_req_data['id'] : $GRP_ID; |
1660
|
|
|
|
1661
|
|
|
//let's get the message templates |
1662
|
|
|
$MTP = EEM_Message_Template_Group::instance(); |
1663
|
|
|
|
1664
|
|
|
if ( empty($GRP_ID) ) |
1665
|
|
|
$this->_message_template_group = $MTP->create_default_object(); |
1666
|
|
|
else |
1667
|
|
|
$this->_message_template_group = $MTP->get_one_by_ID( $GRP_ID ); |
1668
|
|
|
|
1669
|
|
|
$this->_template_pack = $this->_message_template_group->get_template_pack(); |
|
|
|
|
1670
|
|
|
$this->_variation = $this->_message_template_group->get_template_pack_variation(); |
|
|
|
|
1671
|
|
|
|
1672
|
|
|
} |
1673
|
|
|
|
1674
|
|
|
|
1675
|
|
|
|
1676
|
|
|
|
1677
|
|
|
/** |
1678
|
|
|
* sets up a context switcher for edit forms |
1679
|
|
|
* |
1680
|
|
|
* @access protected |
1681
|
|
|
* @param EE_Message_Template_Group $template_object the template group object being displayed on the form |
|
|
|
|
1682
|
|
|
* @param array $args various things the context switcher needs. |
1683
|
|
|
* @return void |
1684
|
|
|
*/ |
1685
|
|
|
protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args) { |
1686
|
|
|
$context_details = $template_group_object->contexts_config(); |
1687
|
|
|
$context_label = $template_group_object->context_label(); |
1688
|
|
|
ob_start(); |
1689
|
|
|
?> |
1690
|
|
|
<div class="ee-msg-switcher-container"> |
1691
|
|
|
<form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm"> |
1692
|
|
|
<?php |
1693
|
|
|
foreach ( $args as $name => $value ) { |
1694
|
|
|
if ( $name == 'context' || empty($value) || $name == 'extra' ) continue; |
1695
|
|
|
?> |
1696
|
|
|
<input type="hidden" name="<?php echo $name; ?>" value = "<?php echo $value; ?>" /> |
1697
|
|
|
<?php |
1698
|
|
|
} |
1699
|
|
|
//setup nonce_url |
1700
|
|
|
wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
1701
|
|
|
?> |
1702
|
|
|
<select name="context"> |
1703
|
|
|
<?php |
1704
|
|
|
$context_templates = $template_group_object->context_templates(); |
1705
|
|
|
if ( is_array($context_templates) ) : |
1706
|
|
|
foreach ( $context_templates as $context => $template_fields ) : |
1707
|
|
|
$checked = ($context == $args['context']) ? 'selected="selected"' : ''; |
1708
|
|
|
?> |
1709
|
|
|
<option value="<?php echo $context; ?>" <?php echo $checked; ?>><?php echo $context_details[$context]['label']; ?></option> |
1710
|
|
|
<?php endforeach; endif; ?> |
1711
|
|
|
</select> |
1712
|
|
|
<?php $button_text = sprintf( __('Switch %s', 'event_espresso'), ucwords($context_label['label']) ); ?> |
1713
|
|
|
<input id="submit-msg-context-switcher-sbmt" class="button-secondary" type="submit" value="<?php echo $button_text; ?>"> |
1714
|
|
|
</form> |
1715
|
|
|
<?php echo $args['extra']; ?> |
1716
|
|
|
</div> <!-- end .ee-msg-switcher-container --> |
1717
|
|
|
<?php |
1718
|
|
|
$output = ob_get_contents(); |
1719
|
|
|
ob_clean(); |
1720
|
|
|
$this->_context_switcher = $output; |
1721
|
|
|
} |
1722
|
|
|
|
1723
|
|
|
|
1724
|
|
|
|
1725
|
|
|
|
1726
|
|
|
|
1727
|
|
|
|
1728
|
|
|
/** |
1729
|
|
|
* utility for sanitizing new values coming in. |
1730
|
|
|
* Note: this is only used when updating a context. |
1731
|
|
|
* |
1732
|
|
|
* @access protected |
1733
|
|
|
* @param int $index This helps us know which template field to select from the request array. |
1734
|
|
|
*/ |
1735
|
|
|
protected function _set_message_template_column_values($index) { |
1736
|
|
|
if ( is_array($this->_req_data['MTP_template_fields'][$index]['content'] ) ) { |
1737
|
|
|
foreach ( $this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value ) { |
|
|
|
|
1738
|
|
|
$this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value; |
1739
|
|
|
} |
1740
|
|
|
} else { |
1741
|
|
|
$this->_req_data['MTP_template_fields'][$index]['content'] = $this->_req_data['MTP_template_fields'][$index]['content']; |
1742
|
|
|
} |
1743
|
|
|
|
1744
|
|
|
|
1745
|
|
|
$set_column_values = array( |
1746
|
|
|
'MTP_ID' => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']), |
1747
|
|
|
'GRP_ID' => absint($this->_req_data['GRP_ID']), |
1748
|
|
|
'MTP_user_id' => absint($this->_req_data['MTP_user_id']), |
1749
|
|
|
'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']), |
1750
|
|
|
'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']), |
1751
|
|
|
'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']), |
1752
|
|
|
'MTP_context' => strtolower($this->_req_data['MTP_context']), |
1753
|
|
|
'MTP_content' => $this->_req_data['MTP_template_fields'][$index]['content'], |
1754
|
|
|
'MTP_is_global' => isset($this->_req_data['MTP_is_global']) ? absint($this->_req_data['MTP_is_global']) : 0, |
1755
|
|
|
'MTP_is_override' => isset($this->_req_data['MTP_is_override']) ? absint($this->_req_data['MTP_is_override']) : 0, |
1756
|
|
|
'MTP_deleted' => absint($this->_req_data['MTP_deleted']), |
1757
|
|
|
'MTP_is_active' => absint($this->_req_data['MTP_is_active']) |
1758
|
|
|
); |
1759
|
|
|
|
1760
|
|
|
|
1761
|
|
|
return $set_column_values; |
1762
|
|
|
} |
1763
|
|
|
|
1764
|
|
|
|
1765
|
|
|
|
1766
|
|
|
|
1767
|
|
|
|
1768
|
|
|
|
1769
|
|
|
protected function _insert_or_update_message_template($new = FALSE ) { |
1770
|
|
|
|
1771
|
|
|
do_action ( 'AHEE_log', __FILE__, __FUNCTION__, ''); |
1772
|
|
|
$success = 0; |
1773
|
|
|
$override = FALSE; |
1774
|
|
|
|
1775
|
|
|
//setup notices description |
1776
|
|
|
$messenger = !empty($this->_req_data['MTP_messenger']) ? ucwords(str_replace('_', ' ', $this->_req_data['MTP_messenger'] ) ) : false; |
1777
|
|
|
$message_type = !empty($this->_req_data['MTP_message_type']) ? ucwords(str_replace('_', ' ', $this->_req_data['MTP_message_type'] ) ) : false; |
1778
|
|
|
$context = !empty($this->_req_data['MTP_context']) ? ucwords(str_replace('_', ' ', $this->_req_data['MTP_context'] ) ) : false; |
1779
|
|
|
|
1780
|
|
|
$item_desc = $messenger ? $messenger . ' ' . $message_type . ' ' . $context . ' ' : ''; |
1781
|
|
|
$item_desc .= 'Message Template'; |
1782
|
|
|
$query_args = array(); |
1783
|
|
|
$validates = ''; |
|
|
|
|
1784
|
|
|
|
1785
|
|
|
//if this is "new" then we need to generate the default contexts for the selected messenger/message_type for user to edit. |
1786
|
|
|
if ( $new ) { |
1787
|
|
|
$GRP_ID = !empty( $this->_req_data['GRP_ID'] ) ? $this->_req_data['GRP_ID'] : 0; |
1788
|
|
|
if ( $edit_array = $this->_generate_new_templates($messenger, $message_type, $GRP_ID ) ) { |
|
|
|
|
1789
|
|
|
if ( empty($edit_array) ) { |
1790
|
|
|
$success = 0; |
1791
|
|
|
} else { |
1792
|
|
|
$success = 1; |
1793
|
|
|
$edit_array = $edit_array[0]; |
1794
|
|
|
$query_args = array( |
1795
|
|
|
'id' => $edit_array['GRP_ID'], |
1796
|
|
|
'context' => $edit_array['MTP_context'], |
1797
|
|
|
'action' => 'edit_message_template' |
1798
|
|
|
); |
1799
|
|
|
} |
1800
|
|
|
} |
1801
|
|
|
$action_desc = 'created'; |
1802
|
|
|
} else { |
1803
|
|
|
$MTPG = EEM_Message_Template_Group::instance(); |
1804
|
|
|
$MTP = EEM_Message_Template::instance(); |
1805
|
|
|
|
1806
|
|
|
|
1807
|
|
|
//run update for each template field in displayed context |
1808
|
|
|
if ( !isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'] ) ) { |
1809
|
|
|
EE_Error::add_error( __('There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
1810
|
|
|
$success = 0; |
1811
|
|
|
$action_desc = ''; |
1812
|
|
|
|
1813
|
|
|
} else { |
1814
|
|
|
//first validate all fields! |
1815
|
|
|
$validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $this->_req_data['MTP_context'], $this->_req_data['MTP_messenger'], $this->_req_data['MTP_message_type']); |
|
|
|
|
1816
|
|
|
|
1817
|
|
|
//if $validate returned error messages (i.e. is_array()) then we need to process them and setup an appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array. WE need to make sure there is no actual error messages in validates. |
1818
|
|
|
if ( is_array($validates) && !empty($validates) ) { |
1819
|
|
|
//add the transient so when the form loads we know which fields to highlight |
1820
|
|
|
$this->_add_transient( 'edit_message_template', $validates ); |
|
|
|
|
1821
|
|
|
|
1822
|
|
|
$success = 0; |
1823
|
|
|
$action_desc =''; |
1824
|
|
|
|
1825
|
|
|
//setup notices |
1826
|
|
|
foreach ( $validates as $field => $error ) { |
1827
|
|
|
if ( isset($error['msg'] ) ) |
1828
|
|
|
EE_Error::add_error( $error['msg'], __FILE__, __FUNCTION__, __LINE__ ); |
1829
|
|
|
} |
1830
|
|
|
|
1831
|
|
|
} else { |
1832
|
|
|
foreach ( $this->_req_data['MTP_template_fields'] as $template_field => $content ) { |
|
|
|
|
1833
|
|
|
$set_column_values = $this->_set_message_template_column_values($template_field); |
1834
|
|
|
|
1835
|
|
|
$where_cols_n_values = array( 'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']); |
1836
|
|
|
|
1837
|
|
|
$message_template_fields = array( |
1838
|
|
|
'GRP_ID' => $set_column_values['GRP_ID'], |
1839
|
|
|
'MTP_template_field' => $set_column_values['MTP_template_field'], |
1840
|
|
|
'MTP_context' => $set_column_values['MTP_context'], |
1841
|
|
|
'MTP_content' => $set_column_values['MTP_content'] |
1842
|
|
|
); |
1843
|
|
|
if ( $updated = $MTP->update( $message_template_fields, array( $where_cols_n_values ) ) ) { |
1844
|
|
|
if ( $updated === FALSE ) { |
1845
|
|
|
$msg = sprintf( __('%s field was NOT updated for some reason', 'event_espresso'), $template_field ); |
1846
|
|
|
EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__ ); |
1847
|
|
|
} else { |
1848
|
|
|
$success = 1; |
1849
|
|
|
} |
1850
|
|
|
} |
1851
|
|
|
$action_desc = 'updated'; |
1852
|
|
|
} |
1853
|
|
|
|
1854
|
|
|
//we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs) |
1855
|
|
|
$mtpg_fields = array( |
1856
|
|
|
'MTP_user_id' => $set_column_values['MTP_user_id'], |
|
|
|
|
1857
|
|
|
'MTP_messenger' => $set_column_values['MTP_messenger'], |
1858
|
|
|
'MTP_message_type' => $set_column_values['MTP_message_type'], |
1859
|
|
|
'MTP_is_global' => $set_column_values['MTP_is_global'], |
1860
|
|
|
'MTP_is_override' => $set_column_values['MTP_is_override'], |
1861
|
|
|
'MTP_deleted' => $set_column_values['MTP_deleted'], |
1862
|
|
|
'MTP_is_active' => $set_column_values['MTP_is_active'], |
1863
|
|
|
'MTP_name' => !empty( $this->_req_data['ee_msg_non_global_fields']['MTP_name'] ) ? $this->_req_data['ee_msg_non_global_fields']['MTP_name'] : '', |
1864
|
|
|
'MTP_description' => !empty( $this->_req_data['ee_msg_non_global_fields']['MTP_description'] ) ? $this->_req_data['ee_msg_non_global_fields']['MTP_description'] : '' |
1865
|
|
|
); |
1866
|
|
|
|
1867
|
|
|
$mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID'] ); |
1868
|
|
|
$updated = $MTPG->update( $mtpg_fields, array($mtpg_where) ); |
1869
|
|
|
|
1870
|
|
|
if ( $updated === FALSE ) { |
1871
|
|
|
$msg = sprintf( __('The Message Template Group (%d) was NOT updated for some reason', 'event_espresso'), $set_column_values['GRP_ID'] ); |
1872
|
|
|
EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__ ); |
1873
|
|
|
} else { |
1874
|
|
|
//k now we need to ensure the template_pack and template_variation fields are set. |
1875
|
|
|
$template_pack = ! empty( $this->_req_data['MTP_template_pack' ] ) ? $this->_req_data['MTP_template_pack'] : 'default'; |
1876
|
|
|
$template_variation = ! empty( $this->_req_data['MTP_template_variation'] ) ? $this->_req_data['MTP_template_variation'] : 'default'; |
1877
|
|
|
$mtpg_obj = $MTPG->get_one_by_ID( $set_column_values['GRP_ID'] ); |
1878
|
|
|
if ( $mtpg_obj instanceof EE_Message_Template_Group ) { |
1879
|
|
|
$mtpg_obj->set_template_pack_name( $template_pack ); |
1880
|
|
|
$mtpg_obj->set_template_pack_variation( $template_variation ); |
1881
|
|
|
} |
1882
|
|
|
$success = 1; |
1883
|
|
|
} |
1884
|
|
|
} |
1885
|
|
|
} |
1886
|
|
|
|
1887
|
|
|
} |
1888
|
|
|
|
1889
|
|
|
//we return things differently if doing ajax |
1890
|
|
|
if ( defined('DOING_AJAX') && DOING_AJAX ) { |
1891
|
|
|
$this->_template_args['success'] = $success; |
1892
|
|
|
$this->_template_args['error'] = ! $success ? TRUE : FALSE; |
1893
|
|
|
$this->_template_args['content'] = ''; |
1894
|
|
|
$this->_template_args['data'] = array( |
1895
|
|
|
'grpID' => $edit_array['GRP_ID'], |
|
|
|
|
1896
|
|
|
'templateName' => $edit_array['template_name'] |
1897
|
|
|
); |
1898
|
|
|
if ( $success ) { |
1899
|
|
|
EE_Error::overwrite_success(); |
1900
|
|
|
EE_Error::add_success( __('The new template has been created and automatically selected for this event. You can edit the new template by clicking the edit button. Note before this template is assigned to this event, the event must be saved.', 'event_espresso') ); |
1901
|
|
|
} |
1902
|
|
|
|
1903
|
|
|
$this->_return_json(); |
1904
|
|
|
} |
1905
|
|
|
|
1906
|
|
|
|
1907
|
|
|
//was a test send triggered? |
1908
|
|
|
if ( isset( $this->_req_data['test_button'] ) ) { |
1909
|
|
|
EE_Error::overwrite_success(); |
1910
|
|
|
$this->_do_test_send( $this->_req_data['MTP_context'], $this->_req_data['MTP_messenger'], $this->_req_data['MTP_message_type'] ); |
1911
|
|
|
$override = TRUE; |
1912
|
|
|
} |
1913
|
|
|
|
1914
|
|
|
if ( empty( $query_args ) ) { |
1915
|
|
|
$query_args = array( |
1916
|
|
|
'id' => $this->_req_data['GRP_ID'], |
1917
|
|
|
'context' => $this->_req_data['MTP_context'], |
1918
|
|
|
'action' => 'edit_message_template' |
1919
|
|
|
); |
1920
|
|
|
} |
1921
|
|
|
|
1922
|
|
|
$this->_redirect_after_action( $success, $item_desc, $action_desc, $query_args, $override ); |
|
|
|
|
1923
|
|
|
} |
1924
|
|
|
|
1925
|
|
|
|
1926
|
|
|
|
1927
|
|
|
|
1928
|
|
|
/** |
1929
|
|
|
* processes a test send request to do an actual messenger delivery test for the given message template being tested |
1930
|
|
|
* @param string $context what context being tested |
1931
|
|
|
* @param string $messenger messenger being tested |
1932
|
|
|
* @param string $message_type message type being tested |
1933
|
|
|
* @return void |
1934
|
|
|
*/ |
1935
|
|
|
protected function _do_test_send( $context, $messenger, $message_type ) { |
1936
|
|
|
//set things up for preview |
1937
|
|
|
$this->_req_data['messenger'] = $messenger; |
1938
|
|
|
$this->_req_data['message_type'] = $message_type; |
1939
|
|
|
$this->_req_data['context'] = $context; |
1940
|
|
|
$this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID'] ) ? $this->_req_data['GRP_ID'] : ''; |
1941
|
|
|
|
1942
|
|
|
//let's save any existing fields that might be required by the messenger |
1943
|
|
|
if ( isset( $this->_req_data['test_settings_fld'] ) ) { |
1944
|
|
|
$this->_active_messengers[$messenger]['obj']->set_existing_test_settings( $this->_req_data['test_settings_fld'] ); |
1945
|
|
|
} |
1946
|
|
|
|
1947
|
|
|
$success = $this->_preview_message(TRUE); |
1948
|
|
|
|
1949
|
|
|
if ( $success ) { |
|
|
|
|
1950
|
|
|
EE_Error::add_success( __('Test message sent', 'event_espresso') ); |
1951
|
|
|
} else { |
1952
|
|
|
EE_Error::add_error( __('The test message was not sent', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
1953
|
|
|
} |
1954
|
|
|
} |
1955
|
|
|
|
1956
|
|
|
|
1957
|
|
|
|
1958
|
|
|
|
1959
|
|
|
|
1960
|
|
|
|
1961
|
|
|
/** |
1962
|
|
|
* _generate_new_templates |
1963
|
|
|
* This will handle the messenger, message_type selection when "adding a new custom template" for an event and will automatically create the defaults for the event. The user would then be redirected to edit the default context for the event. |
1964
|
|
|
* |
1965
|
|
|
* @access protected |
1966
|
|
|
* @param string $messenger the messenger we are generating templates for |
1967
|
|
|
* @param array $message_types array of message types that the templates are generated for. |
1968
|
|
|
* @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to indicate the message_template_group being used as the base. |
1969
|
|
|
* @return array|error_object array of data required for the redirect to the correct edit page or error object if encountering problems. |
1970
|
|
|
*/ |
1971
|
|
|
protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = FALSE) { |
1972
|
|
|
|
1973
|
|
|
//if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we just don't generate any templates. |
1974
|
|
|
if ( empty( $message_types ) ) |
1975
|
|
|
return true; |
1976
|
|
|
|
1977
|
|
|
EE_Registry::instance()->load_helper( 'MSG_Template' ); |
1978
|
|
|
|
1979
|
|
|
return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global); |
1980
|
|
|
|
1981
|
|
|
} |
1982
|
|
|
|
1983
|
|
|
|
1984
|
|
|
|
1985
|
|
|
|
1986
|
|
|
|
1987
|
|
|
/** |
1988
|
|
|
* [_trash_or_restore_message_template] |
1989
|
|
|
* |
1990
|
|
|
* @access protected |
1991
|
|
|
* @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE) |
1992
|
|
|
* @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just an individual context (FALSE). |
1993
|
|
|
* @return void |
1994
|
|
|
*/ |
1995
|
|
|
protected function _trash_or_restore_message_template($trash = TRUE, $all = FALSE ) { |
1996
|
|
|
do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
1997
|
|
|
$MTP = EEM_Message_Template_Group::instance(); |
1998
|
|
|
|
1999
|
|
|
$success = 1; |
2000
|
|
|
|
2001
|
|
|
//incoming GRP_IDs |
2002
|
|
|
if ( $all ) { |
2003
|
|
|
//Checkboxes |
2004
|
|
|
if ( !empty( $this->_req_data['checkbox'] ) && is_array($this->_req_data['checkbox'] ) ) { |
2005
|
|
|
//if array has more than one element then success message should be plural. |
2006
|
|
|
//todo: what about nonce? |
2007
|
|
|
$success = count( $this->_req_data['checkbox'] ) > 1 ? 2 : 1; |
2008
|
|
|
|
2009
|
|
|
//cycle through checkboxes |
2010
|
|
|
while ( list( $GRP_ID, $value ) = each ($this->_req_data['checkbox']) ) { |
|
|
|
|
2011
|
|
|
$trashed_or_restored = $trash ? $MTP->delete_by_ID( $GRP_ID ) : $MTP->restore_by_ID( $GRP_ID ); |
2012
|
|
|
if ( ! $trashed_or_restored ) { |
2013
|
|
|
$success = 0; |
2014
|
|
|
} |
2015
|
|
|
} |
2016
|
|
|
} else { |
2017
|
|
|
//grab single GRP_ID and handle |
2018
|
|
|
$GRP_ID = isset( $this->_req_data['id'] ) ? absint($this->_req_data['id']) : 0; |
2019
|
|
|
if ( ! empty( $GRP_ID ) ) { |
2020
|
|
|
$trashed_or_restored = $trash ? $MTP->delete_by_ID( $GRP_ID ) : $MTP->restore_by_ID( $GRP_ID ); |
2021
|
|
|
if ( ! $trashed_or_restored ) { |
2022
|
|
|
$success = 0; |
2023
|
|
|
} |
2024
|
|
|
} else { |
2025
|
|
|
$success = 0; |
2026
|
|
|
} |
2027
|
|
|
} |
2028
|
|
|
|
2029
|
|
|
} |
2030
|
|
|
|
2031
|
|
|
$action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso'); |
2032
|
|
|
|
2033
|
|
|
$action_desc = !empty( $this->_req_data['template_switch'] ) ? __('switched') : $action_desc; |
2034
|
|
|
|
2035
|
|
|
$item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success, 'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); |
2036
|
|
|
|
2037
|
|
|
$item_desc = !empty( $this->_req_data['template_switch'] ) ? _n('template', 'templates', $success, 'event_espresso') : $item_desc; |
2038
|
|
|
|
2039
|
|
|
$this->_redirect_after_action( $success, $item_desc, $action_desc, array() ); |
2040
|
|
|
|
2041
|
|
|
} |
2042
|
|
|
|
2043
|
|
|
|
2044
|
|
|
|
2045
|
|
|
|
2046
|
|
|
|
2047
|
|
|
|
2048
|
|
|
|
2049
|
|
|
/** |
2050
|
|
|
* [_delete_message_template] |
2051
|
|
|
* NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group. |
2052
|
|
|
* @return void |
2053
|
|
|
*/ |
2054
|
|
|
protected function _delete_message_template() { |
2055
|
|
|
do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
2056
|
|
|
|
2057
|
|
|
$success = 1; |
|
|
|
|
2058
|
|
|
|
2059
|
|
|
//checkboxes |
2060
|
|
|
if ( !empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'] ) ) { |
2061
|
|
|
//if array has more than one element then success message should be plural |
2062
|
|
|
$success = count( $this->_req_data['checkbox'] ) > 1 ? 2 : 1; |
2063
|
|
|
|
2064
|
|
|
//cycle through bulk action checkboxes |
2065
|
|
|
while ( list( $GRP_ID, $value ) = each($this->_req_data['checkbox'] ) ) { |
|
|
|
|
2066
|
|
|
$success = $this->_delete_mtp_permanently( $GRP_ID ); |
2067
|
|
|
} |
2068
|
|
|
} else { |
2069
|
|
|
//grab single grp_id and delete |
2070
|
|
|
$GRP_ID = absint($this->_req_data['id'] ); |
2071
|
|
|
$success = $this->_delete_mtp_permanently( $GRP_ID ); |
2072
|
|
|
} |
2073
|
|
|
|
2074
|
|
|
$this->_redirect_after_action( $success, 'Message Templates', 'deleted', array() ); |
2075
|
|
|
|
2076
|
|
|
} |
2077
|
|
|
|
2078
|
|
|
|
2079
|
|
|
|
2080
|
|
|
|
2081
|
|
|
/** |
2082
|
|
|
* helper for permanently deleting a mtP group and all related message_templates |
2083
|
|
|
* @param int $GRP_ID The group being deleted |
2084
|
|
|
* @param bool $include_group whether to delete the Message Template Group as well. |
2085
|
|
|
* @return success boolean to indicate the success of the deletes or not. |
2086
|
|
|
*/ |
2087
|
|
|
private function _delete_mtp_permanently( $GRP_ID, $include_group = TRUE ) { |
2088
|
|
|
$success = 1; |
2089
|
|
|
$MTPG = EEM_Message_Template_Group::instance(); |
2090
|
|
|
//first let's GET this group |
2091
|
|
|
$MTG = $MTPG->get_one_by_ID( $GRP_ID ); |
2092
|
|
|
//then delete permanently all the related Message Templates |
2093
|
|
|
$deleted = $MTG->delete_related_permanently( 'Message_Template' ); |
2094
|
|
|
|
2095
|
|
|
if ( $deleted === 0 ) |
2096
|
|
|
$success = 0; |
2097
|
|
|
|
2098
|
|
|
//now delete permanently this particular group |
2099
|
|
|
|
2100
|
|
|
if ( $include_group && ! $MTG->delete_permanently() ) { |
2101
|
|
|
$success = 0; |
2102
|
|
|
} |
2103
|
|
|
return $success; |
2104
|
|
|
} |
2105
|
|
|
|
2106
|
|
|
|
2107
|
|
|
|
2108
|
|
|
|
2109
|
|
|
|
2110
|
|
|
|
2111
|
|
|
|
2112
|
|
|
/** |
2113
|
|
|
* _learn_more_about_message_templates_link |
2114
|
|
|
* @access protected |
2115
|
|
|
* @return string |
2116
|
|
|
*/ |
2117
|
|
|
protected function _learn_more_about_message_templates_link() { |
2118
|
|
|
return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works', 'event_espresso') . '</a>'; |
2119
|
|
|
} |
2120
|
|
|
|
2121
|
|
|
|
2122
|
|
|
|
2123
|
|
|
|
2124
|
|
|
|
2125
|
|
|
|
2126
|
|
|
/** |
2127
|
|
|
* Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by ajax and other routes. |
2128
|
|
|
* @return void |
2129
|
|
|
*/ |
2130
|
|
|
protected function _settings() { |
2131
|
|
|
|
2132
|
|
|
EE_Registry::instance()->load_helper( 'Tabbed_Content' ); |
2133
|
|
|
|
2134
|
|
|
$this->_set_m_mt_settings(); |
2135
|
|
|
|
2136
|
|
|
$selected_messenger = isset( $this->_req_data['selected_messenger'] ) ? $this->_req_data['selected_messenger'] : 'email'; |
2137
|
|
|
|
2138
|
|
|
//let's setup the messenger tabs |
2139
|
|
|
$this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links( $this->_m_mt_settings['messenger_tabs'], 'messenger_links', '|', $selected_messenger ); |
2140
|
|
|
$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">'; |
2141
|
|
|
$this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->'; |
2142
|
|
|
|
2143
|
|
|
$this->display_admin_page_with_sidebar(); |
2144
|
|
|
|
2145
|
|
|
} |
2146
|
|
|
|
2147
|
|
|
|
2148
|
|
|
|
2149
|
|
|
|
2150
|
|
|
/** |
2151
|
|
|
* This sets the $_m_mt_settings property for when needed (used on the Messages settings page) |
2152
|
|
|
* |
2153
|
|
|
* @access protected |
2154
|
|
|
* @return void |
2155
|
|
|
*/ |
2156
|
|
|
protected function _set_m_mt_settings() { |
2157
|
|
|
//first if this is already set then lets get out no need to regenerate data. |
2158
|
|
|
if ( !empty($this->_m_mt_settings) ) |
2159
|
|
|
return; |
2160
|
|
|
|
2161
|
|
|
$selected_messenger = isset( $this->_req_data['selected_messenger'] ) ? $this->_req_data['selected_messenger'] : 'email'; |
|
|
|
|
2162
|
|
|
|
2163
|
|
|
//get all installed messengers and message_types |
2164
|
|
|
$installed_message_objects = $this->_get_installed_message_objects(); |
2165
|
|
|
|
2166
|
|
|
$messengers = $installed_message_objects['messengers']; |
2167
|
|
|
$message_types = $installed_message_objects['message_types']; |
2168
|
|
|
|
2169
|
|
|
//assemble the array for the _tab_text_links helper |
2170
|
|
|
|
2171
|
|
|
foreach ( $messengers as $messenger ) { |
2172
|
|
|
$this->_m_mt_settings['messenger_tabs'][$messenger->name] = array( |
2173
|
|
|
'label' => ucwords($messenger->label['singular']), |
2174
|
|
|
'class' => isset( $this->_active_messengers[$messenger->name] ) ? 'messenger-active' : '', |
2175
|
|
|
'href' => $messenger->name, |
2176
|
|
|
'title' => __('Modify this Messenger', 'event_espresso'), |
2177
|
|
|
'slug' => $messenger->name, |
2178
|
|
|
'obj' => $messenger |
2179
|
|
|
); |
2180
|
|
|
|
2181
|
|
|
$message_types_for_messenger = $messenger->get_valid_message_types(); |
2182
|
|
|
|
2183
|
|
|
//assemble the array for the ACTIVE and INACTIVE message types with the selected messenger //note that all message types will be in the inactive box if the messenger is NOT active. |
2184
|
|
|
$selected_settings = isset( $this->_active_messengers[$messenger->name]['settings'] ) ? $this->_active_messengers[$messenger->name]['settings'] : array(); |
2185
|
|
|
foreach ( $message_types as $message_type ) { |
2186
|
|
|
//first we need to verify that this message type is valid with this messenger. Cause if it isn't then it shouldn't show in either the inactive OR active metabox. |
2187
|
|
|
if ( ! in_array( $message_type->name, $message_types_for_messenger ) ) { |
2188
|
|
|
continue; |
2189
|
|
|
} |
2190
|
|
|
|
2191
|
|
|
$a_or_i = isset( $selected_settings[$messenger->name . '-message_types'][$message_type->name] ) && $selected_settings[$messenger->name . '-message_types'][$message_type->name] ? 'active' : 'inactive'; |
2192
|
|
|
|
2193
|
|
|
$this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
2194
|
|
|
'label' => ucwords($message_type->label['singular']), |
2195
|
|
|
'class' => 'message-type-' . $a_or_i, |
2196
|
|
|
'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
2197
|
|
|
'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
2198
|
|
|
'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
2199
|
|
|
'title' => $a_or_i == 'active' ? __('Drag this message type to the Inactive window to deactivate', 'event_espresso') : __('Drag this message type to the messenger to activate', 'event_espresso'), |
2200
|
|
|
'content' => $a_or_i == 'active' ? $this->_message_type_settings_content( $message_type, $messenger, TRUE ) : $this->_message_type_settings_content( $message_type, $messenger ), |
2201
|
|
|
'slug' => $message_type->name, |
2202
|
|
|
'active' => $a_or_i == 'active' ? TRUE : FALSE, |
2203
|
|
|
'obj' => $message_type |
2204
|
|
|
); |
2205
|
|
|
} |
2206
|
|
|
} |
2207
|
|
|
} |
2208
|
|
|
|
2209
|
|
|
|
2210
|
|
|
/** |
2211
|
|
|
* This just prepares the content for the message type settings |
2212
|
|
|
* @param object $message_type The message type object |
2213
|
|
|
* @param object $messenger The messenger object |
2214
|
|
|
* @param boolean $active Whether the message type is active or not |
2215
|
|
|
* @return string html output for the content |
2216
|
|
|
*/ |
2217
|
|
|
protected function _message_type_settings_content( $message_type, $messenger, $active = FALSE ) { |
2218
|
|
|
//get message type fields |
2219
|
|
|
$fields = $message_type->get_admin_settings_fields(); |
2220
|
|
|
$settings_template_args['template_form_fields']= ''; |
|
|
|
|
2221
|
|
|
|
2222
|
|
|
if ( !empty( $fields ) && $active ) { |
2223
|
|
|
|
2224
|
|
|
$existing_settings = $message_type->get_existing_admin_settings( $messenger->name ); |
2225
|
|
|
|
2226
|
|
|
foreach( $fields as $fldname => $fldprops ) { |
2227
|
|
|
$field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
2228
|
|
|
$template_form_field[$field_id] = array( |
|
|
|
|
2229
|
|
|
'name' => 'message_type_settings[' . $fldname . ']', |
2230
|
|
|
'label' => $fldprops['label'], |
2231
|
|
|
'input' => $fldprops['field_type'], |
2232
|
|
|
'type' => $fldprops['value_type'], |
2233
|
|
|
'required' => $fldprops['required'], |
2234
|
|
|
'validation' => $fldprops['validation'], |
2235
|
|
|
'value' => isset( $existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'], |
2236
|
|
|
'options' => isset( $fldprops['options'] ) ? $fldprops['options'] : array(), |
2237
|
|
|
'default' => isset( $existing_settings[$fldname] ) ? $existing_settings[$fldname] : $fldprops['default'], |
2238
|
|
|
'css_class' => 'no-drag', |
2239
|
|
|
'format' => $fldprops['format'] |
2240
|
|
|
); |
2241
|
|
|
} |
2242
|
|
|
|
2243
|
|
|
|
2244
|
|
|
$settings_template_args['template_form_fields'] = !empty($template_form_field) ? $this->_generate_admin_form_fields( $template_form_field, 'string', 'ee_mt_activate_form' ) : ''; |
|
|
|
|
2245
|
|
|
} |
2246
|
|
|
|
2247
|
|
|
$settings_template_args['description'] = $message_type->description; |
2248
|
|
|
//we also need some hidden fields |
2249
|
|
|
$settings_template_args['hidden_fields'] = array( |
2250
|
|
|
'message_type_settings[messenger]' => array( |
2251
|
|
|
'type' => 'hidden', |
2252
|
|
|
'value' => $messenger->name |
2253
|
|
|
), |
2254
|
|
|
'message_type_settings[message_type]' => array( |
2255
|
|
|
'type' => 'hidden', |
2256
|
|
|
'value' => $message_type->name |
2257
|
|
|
), |
2258
|
|
|
'type' => array( |
2259
|
|
|
'type' => 'hidden', |
2260
|
|
|
'value' => 'message_type' |
2261
|
|
|
) |
2262
|
|
|
); |
2263
|
|
|
|
2264
|
|
|
$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( $settings_template_args['hidden_fields'], 'array' ); |
2265
|
|
|
$settings_template_args['show_form'] = empty( $settings_template_args['template_form_fields'] ) ? ' hidden' : ''; |
2266
|
|
|
|
2267
|
|
|
|
2268
|
|
|
|
2269
|
|
|
$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
2270
|
|
|
$content = EEH_Template::display_template( $template, $settings_template_args, TRUE ); |
2271
|
|
|
return $content; |
2272
|
|
|
} |
2273
|
|
|
|
2274
|
|
|
|
2275
|
|
|
|
2276
|
|
|
/** |
2277
|
|
|
* Generate all the metaboxes for the message types and register them for the messages settings page. |
2278
|
|
|
* |
2279
|
|
|
* @access protected |
2280
|
|
|
* @return void |
2281
|
|
|
*/ |
2282
|
|
|
protected function _messages_settings_metaboxes() { |
2283
|
|
|
$this->_set_m_mt_settings(); |
2284
|
|
|
$m_boxes = $mt_boxes = array(); |
2285
|
|
|
$m_template_args = $mt_template_args = array(); |
2286
|
|
|
|
2287
|
|
|
$selected_messenger = isset( $this->_req_data['selected_messenger'] ) ? $this->_req_data['selected_messenger'] : 'email'; |
2288
|
|
|
|
2289
|
|
|
foreach ( $this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array ) { |
2290
|
|
|
|
2291
|
|
|
$hide_on_message = isset( $this->_active_messengers[$messenger] ) ? '' : 'hidden'; |
2292
|
|
|
$hide_off_message = isset( $this->_active_messengers[$messenger] ) ? 'hidden' : ''; |
2293
|
|
|
|
2294
|
|
|
//messenger meta boxes |
2295
|
|
|
$active = $selected_messenger == $messenger ? TRUE : FALSE; |
2296
|
|
|
$active_mt_tabs = isset( $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] ) ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] : ''; |
2297
|
|
|
$m_boxes[$messenger . '_a_box'] = sprintf( __('%s Settings', 'event_espresso'), $tab_array['label'] ); |
2298
|
|
|
$m_template_args[$messenger . '_a_box'] = array( |
2299
|
|
|
'active_message_types' => !empty( $active_mt_tabs ) ? $this->_get_mt_tabs( $active_mt_tabs ) : '', |
2300
|
|
|
'inactive_message_types' => isset( $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] ) ? $this->_get_mt_tabs( $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] ) : '', |
2301
|
|
|
'content' => $this->_get_messenger_box_content( $tab_array['obj'] ), |
2302
|
|
|
'hidden' => $active ? '' : ' hidden', |
2303
|
|
|
'hide_on_message' => $hide_on_message, |
2304
|
|
|
'messenger' => $messenger, |
2305
|
|
|
'active' => $active |
2306
|
|
|
); |
2307
|
|
|
|
2308
|
|
|
|
2309
|
|
|
//message type meta boxes (which is really just the inactive container for each messenger showing inactive message types for that messenger) |
2310
|
|
|
$mt_boxes[$messenger . '_i_box'] = __('Inactive Message Types', 'event_espresso'); |
2311
|
|
|
$mt_template_args[$messenger . '_i_box'] = array( |
2312
|
|
|
'active_message_types' => !empty( $active_mt_tabs ) ? $this->_get_mt_tabs( $active_mt_tabs ) : '', |
2313
|
|
|
'inactive_message_types' => isset( $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] ) ? $this->_get_mt_tabs( $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] ) : '', |
2314
|
|
|
'hidden' => $active ? '' : ' hidden', |
2315
|
|
|
'hide_on_message' => $hide_on_message, |
2316
|
|
|
'hide_off_message' => $hide_off_message, |
2317
|
|
|
'messenger' => $messenger, |
2318
|
|
|
'active' => $active |
2319
|
|
|
); |
2320
|
|
|
} |
2321
|
|
|
|
2322
|
|
|
//register messenger metaboxes |
2323
|
|
|
$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
2324
|
|
View Code Duplication |
foreach ( $m_boxes as $box => $label ) { |
2325
|
|
|
$callback_args = array( 'template_path' => $m_template_path, 'template_args' => $m_template_args[$box] ); |
2326
|
|
|
$msgr = str_replace( '_a_box', '', $box ); |
2327
|
|
|
add_meta_box( 'espresso_' . $msgr . '_settings', $label, create_function('$post, $metabox', 'echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );'), $this->_current_screen_id, 'normal', 'high', $callback_args ); |
|
|
|
|
2328
|
|
|
} |
2329
|
|
|
|
2330
|
|
|
//register message type metaboxes |
2331
|
|
|
$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
2332
|
|
View Code Duplication |
foreach ( $mt_boxes as $box => $label ) { |
2333
|
|
|
$callback_args = array( 'template_path' => $mt_template_path, 'template_args' => $mt_template_args[$box] ); |
2334
|
|
|
$mt = str_replace( '_i_box', '', $box ); |
2335
|
|
|
add_meta_box( 'espresso_' . $mt . '_inactive_mts', $label, create_function('$post, $metabox', 'echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );'), $this->_current_screen_id, 'side', 'high', $callback_args ); |
|
|
|
|
2336
|
|
|
} |
2337
|
|
|
|
2338
|
|
|
} |
2339
|
|
|
|
2340
|
|
|
|
2341
|
|
|
/** |
2342
|
|
|
* this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate |
2343
|
|
|
* @param array $tab_array This is an array of message type tab details used to generate the tabs |
2344
|
|
|
* @return string html formatted tabs |
2345
|
|
|
*/ |
2346
|
|
|
protected function _get_mt_tabs( $tab_array ) { |
2347
|
|
|
$tab_array = (array) $tab_array; |
2348
|
|
|
$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
2349
|
|
|
$tabs = ''; |
2350
|
|
|
|
2351
|
|
|
foreach ( $tab_array as $tab ) { |
2352
|
|
|
$tabs .= EEH_Template::display_template( $template, $tab, TRUE ); |
2353
|
|
|
} |
2354
|
|
|
|
2355
|
|
|
return $tabs; |
2356
|
|
|
} |
2357
|
|
|
|
2358
|
|
|
|
2359
|
|
|
|
2360
|
|
|
|
2361
|
|
|
/** |
2362
|
|
|
* This prepares the content of the messenger meta box admin settings |
2363
|
|
|
* @param object $messenger The messenger we're setting up content for |
2364
|
|
|
* @return string html formatted content |
2365
|
|
|
*/ |
2366
|
|
|
protected function _get_messenger_box_content( $messenger ) { |
2367
|
|
|
|
2368
|
|
|
$fields = $messenger->get_admin_settings_fields(); |
2369
|
|
|
$settings_template_args['template_form_fields'] = ''; |
|
|
|
|
2370
|
|
|
|
2371
|
|
|
//is $messenger active? |
2372
|
|
|
$settings_template_args['active'] = isset($this->_active_messengers[$messenger->name]) ? TRUE : FALSE; |
2373
|
|
|
|
2374
|
|
|
|
2375
|
|
|
if ( !empty( $fields ) ) { |
2376
|
|
|
|
2377
|
|
|
$existing_settings = $messenger->get_existing_admin_settings(); |
2378
|
|
|
|
2379
|
|
|
foreach( $fields as $fldname => $fldprops ) { |
2380
|
|
|
$field_id = $messenger->name . '-' . $fldname; |
2381
|
|
|
$template_form_field[$field_id] = array( |
|
|
|
|
2382
|
|
|
'name' => 'messenger_settings[' . $field_id . ']', |
2383
|
|
|
'label' => $fldprops['label'], |
2384
|
|
|
'input' => $fldprops['field_type'], |
2385
|
|
|
'type' => $fldprops['value_type'], |
2386
|
|
|
'required' => $fldprops['required'], |
2387
|
|
|
'validation' => $fldprops['validation'], |
2388
|
|
|
'value' => isset( $existing_settings[$field_id]) ? $existing_settings[$field_id] : $fldprops['default'], |
2389
|
|
|
'css_class' => '', |
2390
|
|
|
'format' => $fldprops['format'] |
2391
|
|
|
); |
2392
|
|
|
} |
2393
|
|
|
|
2394
|
|
|
|
2395
|
|
|
$settings_template_args['template_form_fields'] = !empty($template_form_field) ? $this->_generate_admin_form_fields( $template_form_field, 'string', 'ee_m_activate_form' ) : ''; |
|
|
|
|
2396
|
|
|
} |
2397
|
|
|
|
2398
|
|
|
//we also need some hidden fields |
2399
|
|
|
$settings_template_args['hidden_fields'] = array( |
2400
|
|
|
'messenger_settings[messenger]' => array( |
2401
|
|
|
'type' => 'hidden', |
2402
|
|
|
'value' => $messenger->name |
2403
|
|
|
), |
2404
|
|
|
'type' => array( |
2405
|
|
|
'type' => 'hidden', |
2406
|
|
|
'value' => 'messenger' |
2407
|
|
|
) |
2408
|
|
|
); |
2409
|
|
|
|
2410
|
|
|
//make sure any active message types that are existing are included in the hidden fields |
2411
|
|
|
if ( isset( $this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] ) ) { |
2412
|
|
|
foreach ( $this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values ) { |
2413
|
|
|
$settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = array( |
2414
|
|
|
'type' => 'hidden', |
2415
|
|
|
'value' => $mt |
2416
|
|
|
); |
2417
|
|
|
} |
2418
|
|
|
} |
2419
|
|
|
|
2420
|
|
|
$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( $settings_template_args['hidden_fields'], 'array' ); |
2421
|
|
|
|
2422
|
|
|
$active = isset( $this->_active_messengers[$messenger->name] ) ? TRUE : FALSE; |
2423
|
|
|
|
2424
|
|
|
$settings_template_args['messenger'] = $messenger->name; |
2425
|
|
|
$settings_template_args['description'] = $messenger->description; |
2426
|
|
|
$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden'; |
2427
|
|
|
|
2428
|
|
|
|
2429
|
|
|
$settings_template_args['show_hide_edit_form'] = isset( $this->_active_messengers[$messenger->name] ) ? $settings_template_args['show_hide_edit_form'] : ' hidden'; |
2430
|
|
|
|
2431
|
|
|
$settings_template_args['show_hide_edit_form'] = empty( $settings_template_args['template_form_fields'] ) ? ' hidden' : $settings_template_args['show_hide_edit_form']; |
2432
|
|
|
|
2433
|
|
|
|
2434
|
|
|
$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
2435
|
|
|
$settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
2436
|
|
|
$settings_template_args['on_off_status'] = $active ? true : false; |
2437
|
|
|
$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
2438
|
|
|
$content = EEH_Template::display_template( $template, $settings_template_args, TRUE); |
2439
|
|
|
return $content; |
2440
|
|
|
} |
2441
|
|
|
|
2442
|
|
|
|
2443
|
|
|
|
2444
|
|
|
|
2445
|
|
|
/** |
2446
|
|
|
* used by ajax on the messages settings page to activate|deactivate the messenger |
2447
|
|
|
* @return void |
2448
|
|
|
*/ |
2449
|
|
|
public function activate_messenger_toggle() { |
2450
|
|
|
$success = TRUE; |
2451
|
|
|
//let's check that we have required data |
2452
|
|
|
if ( !isset( $this->_req_data[ 'messenger' ] ) ) { |
2453
|
|
|
EE_Error::add_error( __('Messenger name needed to toggle activation. None given', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
2454
|
|
|
$success = FALSE; |
2455
|
|
|
} |
2456
|
|
|
|
2457
|
|
|
//do a nonce check here since we're not arriving via a normal route |
2458
|
|
|
$nonce = isset($this->_req_data[ 'activate_nonce' ]) ? sanitize_text_field( $this->_req_data[ 'activate_nonce'] ) : ''; |
2459
|
|
|
$nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
2460
|
|
|
|
2461
|
|
|
$this->_verify_nonce( $nonce, $nonce_ref ); |
2462
|
|
|
|
2463
|
|
|
|
2464
|
|
|
|
2465
|
|
|
if ( !isset( $this->_req_data[ 'status' ])) { |
2466
|
|
|
EE_Error::add_error( __('Messenger status needed to know whether activation or deactivation is happening. No status is given', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
2467
|
|
|
$success = FALSE; |
2468
|
|
|
} |
2469
|
|
|
|
2470
|
|
|
//do check to verify we have a valid status. |
2471
|
|
|
$status = $this->_req_data['status']; |
2472
|
|
|
|
2473
|
|
View Code Duplication |
if ( $status != 'off' && $status != 'on' ) { |
2474
|
|
|
EE_Error::add_error( sprintf( __('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), $this->_req_data['status'] ), __FILE__, __FUNCTION__, __LINE__ ); |
2475
|
|
|
$success = FALSE; |
2476
|
|
|
} |
2477
|
|
|
|
2478
|
|
View Code Duplication |
if ( $success ) { |
2479
|
|
|
//made it here? Stop dawdling then!! |
2480
|
|
|
if ( $status == 'off' ) { |
2481
|
|
|
//off = deactivate. get it? |
2482
|
|
|
$success = $this->_activate_messenger( $this->_req_data['messenger'], TRUE ); |
2483
|
|
|
} else { |
2484
|
|
|
$success = $this->_activate_messenger( $this->_req_data['messenger'] ); |
2485
|
|
|
} |
2486
|
|
|
} |
2487
|
|
|
|
2488
|
|
|
$this->_template_args['success'] = $success; |
2489
|
|
|
|
2490
|
|
|
//no special instructions so let's just do the json return (which should automatically do all the special stuff). |
2491
|
|
|
$this->_return_json(); |
2492
|
|
|
|
2493
|
|
|
} |
2494
|
|
|
|
2495
|
|
|
|
2496
|
|
|
|
2497
|
|
|
|
2498
|
|
|
|
2499
|
|
|
/** |
2500
|
|
|
* used by ajax from the messages settings page to activate|deactivate a message type |
2501
|
|
|
* |
2502
|
|
|
* @access public |
2503
|
|
|
* @return void |
2504
|
|
|
*/ |
2505
|
|
|
public function activate_mt_toggle() { |
2506
|
|
|
$success = TRUE; |
2507
|
|
|
|
2508
|
|
|
|
2509
|
|
|
//let's make sure we have the necessary data |
2510
|
|
|
if ( !isset( $this->_req_data[ 'message_type' ] ) ) { |
2511
|
|
|
EE_Error::add_error( __('Message Type name needed to toggle activation. None given', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
2512
|
|
|
$success = FALSE; |
2513
|
|
|
} |
2514
|
|
|
|
2515
|
|
|
|
2516
|
|
|
//do a nonce check here since we're not arriving via a normal route |
2517
|
|
|
$nonce = isset( $this->_req_data['mt_nonce'] ) ? sanitize_text_field( $this->_req_data['mt_nonce'] ) : ''; |
2518
|
|
|
$nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
2519
|
|
|
|
2520
|
|
|
$this->_verify_nonce( $nonce, $nonce_ref ); |
2521
|
|
|
|
2522
|
|
|
|
2523
|
|
|
if ( !isset( $this->_req_data[ 'messenger' ] ) ) { |
2524
|
|
|
EE_Error::add_error( __('Messenger name needed to toggle activation. None given', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
2525
|
|
|
$success = FALSE; |
2526
|
|
|
} |
2527
|
|
|
|
2528
|
|
|
if ( !isset( $this->_req_data[ 'status' ])) { |
2529
|
|
|
EE_Error::add_error( __('Messenger status needed to know whether activation or deactivation is happening. No status is given', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
2530
|
|
|
$success = FALSE; |
2531
|
|
|
} |
2532
|
|
|
|
2533
|
|
|
|
2534
|
|
|
//do check to verify we have a valid status. |
2535
|
|
|
$status = $this->_req_data['status']; |
2536
|
|
|
|
2537
|
|
View Code Duplication |
if ( $status != 'activate' && $status != 'deactivate' ) { |
2538
|
|
|
EE_Error::add_error( sprintf( __('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), $this->_req_data['status'] ), __FILE__, __FUNCTION__, __LINE__ ); |
2539
|
|
|
$success = FALSE; |
2540
|
|
|
} |
2541
|
|
|
|
2542
|
|
|
|
2543
|
|
View Code Duplication |
if ( $success ) { |
2544
|
|
|
//made it here? um, what are you waiting for then? |
2545
|
|
|
$deactivate = $status == 'deactivate' ? TRUE : FALSE; |
2546
|
|
|
$success = $this->_activate_messenger( $this->_req_data['messenger'], $deactivate, $this->_req_data['message_type'] ); |
2547
|
|
|
} |
2548
|
|
|
|
2549
|
|
|
$this->_template_args['success'] = $success; |
2550
|
|
|
$this->_return_json(); |
2551
|
|
|
|
2552
|
|
|
} |
2553
|
|
|
|
2554
|
|
|
|
2555
|
|
|
|
2556
|
|
|
|
2557
|
|
|
|
2558
|
|
|
|
2559
|
|
|
/** |
2560
|
|
|
* This just updates the active_messengers usermeta field when a messenger or message type is activated/deactivated. |
2561
|
|
|
* NOTE: deactivating will remove the messenger (or message type) from the active_messengers wp_options field so all saved settings WILL be lost for the messenger AND message_types associated with that messenger (or message type). |
2562
|
|
|
* |
2563
|
|
|
* @param string $messenger What messenger we're toggling |
2564
|
|
|
* @param boolean $deactivate if true then we deactivate |
2565
|
|
|
* @param mixed $message_type if present what message type we're toggling |
2566
|
|
|
* @return void |
2567
|
|
|
*/ |
2568
|
|
|
protected function _activate_messenger($messenger, $deactivate = FALSE, $message_type = FALSE) { |
2569
|
|
|
global $espresso_wp_user; |
2570
|
|
|
$templates = TRUE; |
|
|
|
|
2571
|
|
|
$this->_set_m_mt_settings(); |
2572
|
|
|
|
2573
|
|
|
if ( !$deactivate ) { |
2574
|
|
|
|
2575
|
|
|
|
2576
|
|
|
//we are activating. we can use $this->_m_mt_settings to get all the installed messengers |
2577
|
|
|
$this->_active_messengers[$messenger]['settings'] = !isset($this->_active_messengers[$messenger]['settings']) ? array() : $this->_active_messengers[$messenger]['settings']; |
2578
|
|
|
$this->_active_messengers[$messenger]['obj'] = $this->_m_mt_settings['messenger_tabs'][$messenger]['obj']; |
2579
|
|
|
|
2580
|
|
|
//get has_active so we can sure its kept up to date. |
2581
|
|
|
$has_activated = get_option( 'ee_has_activated_messages' ); |
2582
|
|
|
|
2583
|
|
|
if ( empty( $has_activated[$messenger] ) ) { |
2584
|
|
|
$has_activated[$messenger] = array(); |
2585
|
|
|
} |
2586
|
|
|
|
2587
|
|
|
//k we need to get what default message types are to be associated with the messenger that's been activated. |
2588
|
|
|
$default_types = $message_type ? (array) $message_type : $this->_active_messengers[$messenger]['obj']->get_default_message_types(); |
2589
|
|
|
|
2590
|
|
|
foreach ( $default_types as $type ) { |
2591
|
|
|
$settings_fields = $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'][$type]['obj']->get_admin_settings_fields(); |
2592
|
|
|
if ( !empty( $settings_fields ) ) { |
2593
|
|
|
//we have fields for this message type so let's get the defaults for saving. |
2594
|
|
|
foreach ( $settings_fields as $field => $values ) { |
2595
|
|
|
$settings[$field] = $values['default']; |
|
|
|
|
2596
|
|
|
} |
2597
|
|
|
//let's set the data for reloading this message type form in ajax |
2598
|
|
|
$this->_template_args['data']['mt_reload'][] = $type; |
2599
|
|
|
} else { |
2600
|
|
|
$settings = array(); |
2601
|
|
|
} |
2602
|
|
|
$this->_active_messengers[$messenger]['settings'][$messenger . '-message_types'][$type]['settings'] = $settings; |
|
|
|
|
2603
|
|
|
|
2604
|
|
|
if ( ! in_array( $type, $has_activated[$messenger] ) ) { |
2605
|
|
|
$has_activated[$messenger][] = $type; |
2606
|
|
|
} |
2607
|
|
|
} |
2608
|
|
|
|
2609
|
|
|
//any default settings for the messenger? |
2610
|
|
|
$msgr_settings = $this->_active_messengers[$messenger]['obj']->get_admin_settings_fields(); |
2611
|
|
|
|
2612
|
|
View Code Duplication |
if ( !empty( $msgr_settings ) ) { |
2613
|
|
|
foreach ( $msgr_settings as $field => $value ) { |
2614
|
|
|
$this->_active_messengers[$messenger]['settings'][$field] = $value; |
2615
|
|
|
} |
2616
|
|
|
} |
2617
|
|
|
|
2618
|
|
|
//update settings in database |
2619
|
|
|
EEH_MSG_Template::update_active_messengers_in_db( $this->_active_messengers ); |
2620
|
|
|
update_option( 'ee_has_activated_messages', $has_activated ); |
2621
|
|
|
|
2622
|
|
|
|
2623
|
|
|
//generate new templates (if necessary) |
2624
|
|
|
$templates = $this->_generate_new_templates( $messenger, $default_types, 0, TRUE ); |
2625
|
|
|
|
2626
|
|
|
EE_Error::overwrite_success(); |
2627
|
|
|
|
2628
|
|
|
//if generation failed then we need to remove the active messenger. |
2629
|
|
|
if ( !$templates ) { |
2630
|
|
|
unset($this->_active_messengers[$messenger]); |
2631
|
|
|
EEH_MSG_Template::update_active_messengers_in_db( $this->_active_messengers ); |
2632
|
|
|
} else { |
2633
|
|
|
//all is good let's do a success message |
2634
|
|
|
if ( $message_type ) { |
2635
|
|
|
EE_Error::add_success( sprintf( __('%s message type has been successfully activated with the %s messenger', 'event_espresso'),ucwords($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'][$message_type]['obj']->label['singular']), ucwords( $this->_active_messengers[$messenger]['obj']->label['singular'] ) ) ); |
2636
|
|
|
|
2637
|
|
|
//if message type was invoice then let's make sure we activate the invoice payment method. |
2638
|
|
|
if ( $message_type == 'invoice' ) { |
2639
|
|
|
EE_Registry::instance()->load_lib( 'Payment_Method_Manager' ); |
2640
|
|
|
$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type( 'Invoice' ); |
2641
|
|
|
if ( $pm instanceof EE_Payment_Method ) { |
2642
|
|
|
EE_Error::add_attention( __('Activating the invoice message type also automatically activates the invoice payment method. If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.', 'event_espresso' ) ); |
2643
|
|
|
} |
2644
|
|
|
} |
2645
|
|
|
} else { |
2646
|
|
|
EE_Error::add_success( sprintf( __('%s messenger has been successfully activated', 'event_espresso'), ucwords( $this->_active_messengers[$messenger]['obj']->label['singular'] ) ) ); |
2647
|
|
|
} |
2648
|
|
|
} |
2649
|
|
|
|
2650
|
|
|
$this->_template_args['data']['active_mts'] = $default_types; |
2651
|
|
|
|
2652
|
|
|
} else { |
2653
|
|
|
//we're deactivating |
2654
|
|
|
|
2655
|
|
|
$MTP = EEM_Message_Template_Group::instance(); |
2656
|
|
|
|
2657
|
|
|
|
2658
|
|
|
//okay let's update the message templates that match this messenger so that they are deactivated in the database as well. |
2659
|
|
|
$update_array = array( |
2660
|
|
|
'MTP_messenger' => $messenger); |
2661
|
|
|
|
2662
|
|
|
if ( $message_type ) { |
2663
|
|
|
$update_array['MTP_message_type'] = $message_type; |
2664
|
|
|
} |
2665
|
|
|
|
2666
|
|
|
$success = $MTP->update( array( 'MTP_is_active' => 0 ), array($update_array) ); |
|
|
|
|
2667
|
|
|
|
2668
|
|
|
$messenger_obj = $this->_active_messengers[$messenger]['obj']; |
2669
|
|
|
|
2670
|
|
|
//if this is a message type deactivation then we're only unsetting the message type otherwise unset the messenger |
2671
|
|
|
if ( $message_type ) { |
2672
|
|
|
unset( $this->_active_messengers[$messenger]['settings'][$messenger . '-message_types'][$message_type] ); |
2673
|
|
|
} else { |
2674
|
|
|
unset( $this->_active_messengers[$messenger] ); |
2675
|
|
|
} |
2676
|
|
|
|
2677
|
|
|
EEH_MSG_Template::update_active_messengers_in_db( $this->_active_messengers ); |
2678
|
|
|
EE_Error::overwrite_success(); |
2679
|
|
|
if ( $message_type ) { |
2680
|
|
|
EE_Error::add_success( sprintf( __('%s message type has been successfully deactivated', 'event_espresso'), ucwords($this->_m_mt_settings['message_type_tabs'][$messenger]['active'][$message_type]['obj']->label['singular']) ) ); |
2681
|
|
|
} else { |
2682
|
|
|
EE_Error::add_success( sprintf( __('%s messenger has been successfully deactivated', 'event_espresso'), ucwords($messenger_obj->label['singular'] ) ) ); |
2683
|
|
|
} |
2684
|
|
|
|
2685
|
|
|
//if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method. |
2686
|
|
|
if ( $messenger == 'html' || $message_type == 'invoice') { |
2687
|
|
|
EE_Registry::instance()->load_lib( 'Payment_Method_Manager' ); |
2688
|
|
|
$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method( 'invoice' ); |
2689
|
|
|
if ( $count_updated > 0 ) { |
2690
|
|
|
$msg = $message_type == 'invoice' ? __('Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then vist the payment methods admin page to reactivate the invoice payment method.', 'event_espresso' ) : __('Deactivating the html messenger also automatically deactivates the invoice payment method. In order for invoices to be generated the html messenger must be be active. If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.', 'event_espresso' ); |
2691
|
|
|
EE_Error::add_attention( $msg ); |
2692
|
|
|
} |
2693
|
|
|
} |
2694
|
|
|
|
2695
|
|
|
} |
2696
|
|
|
|
2697
|
|
|
return true; |
2698
|
|
|
} |
2699
|
|
|
|
2700
|
|
|
|
2701
|
|
|
|
2702
|
|
|
|
2703
|
|
|
/** |
2704
|
|
|
* handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax) |
2705
|
|
|
* @return string html data |
2706
|
|
|
*/ |
2707
|
|
|
public function update_mt_form() { |
2708
|
|
|
if ( !isset( $this->_req_data['messenger'] ) || !isset( $this->_req_data['message_type'] ) ) { |
2709
|
|
|
EE_Error::add_error( __('Require message type or messenger to send an updated form'), __FILE__, __FUNCTION__, __LINE__ ); |
2710
|
|
|
$this->_return_json(); |
2711
|
|
|
} |
2712
|
|
|
|
2713
|
|
|
$message_types = $this->get_installed_message_types(); |
2714
|
|
|
|
2715
|
|
|
$message_type = $message_types[$this->_req_data['message_type']]['obj']; |
2716
|
|
|
$messenger = $this->_active_messengers[$this->_req_data['messenger']]['obj']; |
2717
|
|
|
|
2718
|
|
|
$content = $this->_message_type_settings_content ( $message_type, $messenger, TRUE, TRUE ); |
|
|
|
|
2719
|
|
|
$this->_template_args['success'] = true; |
2720
|
|
|
$this->_template_args['content'] = $content; |
2721
|
|
|
$this->_return_json(); |
2722
|
|
|
} |
2723
|
|
|
|
2724
|
|
|
|
2725
|
|
|
|
2726
|
|
|
|
2727
|
|
|
/** |
2728
|
|
|
* this handles saving the settings for a messenger or message type |
2729
|
|
|
* @return json success or fail message |
2730
|
|
|
*/ |
2731
|
|
|
public function save_settings() { |
2732
|
|
|
if ( !isset( $this->_req_data['type'] ) ) { |
2733
|
|
|
EE_Error::add_error(__('Cannot save settings because type is unknown (messenger settings or messsage type settings?)', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
2734
|
|
|
$this->_template_args['error'] = TRUE; |
2735
|
|
|
$this->_return_json(); |
2736
|
|
|
} |
2737
|
|
|
|
2738
|
|
|
|
2739
|
|
|
if ( $this->_req_data['type'] == 'messenger' ) { |
2740
|
|
|
$settings = $this->_req_data['messenger_settings']; //this should be an array. |
2741
|
|
|
$messenger = $settings['messenger']; |
2742
|
|
|
//let's setup the settings data |
2743
|
|
|
foreach ( $settings as $key => $value ) { |
2744
|
|
|
switch ( $key ) { |
2745
|
|
|
case 'messenger' : |
2746
|
|
|
unset( $settings['messenger'] ); |
2747
|
|
|
break; |
2748
|
|
|
case 'message_types' : |
2749
|
|
|
if ( isset( $this->_active_messengers[$messenger]['settings'][$messenger . '-message_types'] ) ) { |
2750
|
|
|
foreach ( $this->_active_messengers[$messenger]['settings'][$messenger . '-message_types'] as $mt => $v ) { |
2751
|
|
|
if ( isset( $settings['message_types'][$mt] ) ) |
2752
|
|
|
$settings[$messenger . '-message_types'][$mt]['settings'] = isset( $this->_active_messengers[$messenger]['settings'][$messenger . '-message_types'][$mt] ) ? $this->_active_messengers[$messenger]['settings'][$messenger . '-message_types'][$mt] : array(); |
2753
|
|
|
} |
2754
|
|
|
} else { |
2755
|
|
|
foreach ( $value as $mt => $v ) { |
2756
|
|
|
//let's see if this message type is already present and has settings. |
2757
|
|
|
$settings[$messenger . '-message_types'][$mt]['settings'] = array(); |
2758
|
|
|
} |
2759
|
|
|
} |
2760
|
|
|
//k settings are set let's get rid of the message types index |
2761
|
|
|
unset( $settings['message_types'] ); |
2762
|
|
|
break; |
2763
|
|
|
default : |
2764
|
|
|
$settings[$key] = $value; |
2765
|
|
|
break; |
2766
|
|
|
} |
2767
|
|
|
} |
2768
|
|
|
$this->_active_messengers[$messenger]['settings'] = $settings; |
2769
|
|
|
} |
2770
|
|
|
|
2771
|
|
|
else if ( $this->_req_data['type'] == 'message_type' ) { |
2772
|
|
|
$settings = $this->_req_data['message_type_settings']; |
2773
|
|
|
$messenger = $settings['messenger']; |
2774
|
|
|
$message_type = $settings['message_type']; |
2775
|
|
|
|
2776
|
|
|
foreach ( $settings as $key => $value ) { |
2777
|
|
|
switch ( $key ) { |
2778
|
|
|
case 'messenger' : |
2779
|
|
|
unset( $settings['messenger'] ); |
2780
|
|
|
break; |
2781
|
|
|
case 'message_type' : |
2782
|
|
|
unset( $settings['message_type'] ); |
2783
|
|
|
break; |
2784
|
|
|
default : |
2785
|
|
|
$settings['settings'][$key] = $value; |
2786
|
|
|
unset( $settings[$key] ); |
2787
|
|
|
break; |
2788
|
|
|
} |
2789
|
|
|
} |
2790
|
|
|
|
2791
|
|
|
$this->_active_messengers[$messenger]['settings'][$messenger . '-message_types'][$message_type] = $settings; |
2792
|
|
|
} |
2793
|
|
|
|
2794
|
|
|
//okay we should have the data all setup. Now we just update! |
2795
|
|
|
$success = EEH_MSG_Template::update_active_messengers_in_db( $this->_active_messengers ); |
2796
|
|
|
|
2797
|
|
|
if ( $success ) { |
2798
|
|
|
EE_Error::add_success( __('Settings updated', 'event_espresso') ); |
2799
|
|
|
} else { |
2800
|
|
|
EE_Error::add_error( __('Settings did not get updated', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
2801
|
|
|
} |
2802
|
|
|
|
2803
|
|
|
$this->_template_args['success'] = $success; |
2804
|
|
|
$this->_return_json(); |
2805
|
|
|
} |
2806
|
|
|
|
2807
|
|
|
|
2808
|
|
|
|
2809
|
|
|
|
2810
|
|
|
|
2811
|
|
|
|
2812
|
|
|
protected function _messages_reports() { |
2813
|
|
|
$this->_template_args['admin_page_content'] = "Feature coming soon man, sit back, relax, and enjoy the fireworks."; |
2814
|
|
|
$this->display_admin_page_with_no_sidebar(); |
2815
|
|
|
} |
2816
|
|
|
|
2817
|
|
|
} |
2818
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.