|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use EventEspresso\core\exceptions\InvalidDataTypeException; |
|
4
|
|
|
use EventEspresso\core\exceptions\InvalidInterfaceException; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* EED_Events_Archive_Caff |
|
8
|
|
|
* |
|
9
|
|
|
* @package Event Espresso |
|
10
|
|
|
* @subpackage /modules/events_archive_caff/ |
|
11
|
|
|
* @author Brent Christensen |
|
12
|
|
|
*/ |
|
13
|
|
|
class EED_Events_Archive_Caff extends EED_Events_Archive |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @return EED_Events_Archive_Caff|EED_Module |
|
18
|
|
|
*/ |
|
19
|
|
|
public static function instance() |
|
20
|
|
|
{ |
|
21
|
|
|
return parent::get_instance(__CLASS__); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* set_hooks - for hooking into EE Core, other modules, etc |
|
27
|
|
|
* |
|
28
|
|
|
* @return void |
|
29
|
|
|
*/ |
|
30
|
|
|
public static function set_hooks() |
|
31
|
|
|
{ |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
36
|
|
|
* |
|
37
|
|
|
* @access public |
|
38
|
|
|
* @return void |
|
39
|
|
|
*/ |
|
40
|
|
|
public static function set_hooks_admin() |
|
41
|
|
|
{ |
|
42
|
|
|
self::setDefinitions(); |
|
43
|
|
|
add_action( |
|
44
|
|
|
'AHEE__template_settings__template__before_settings_form', |
|
45
|
|
|
array('EED_Events_Archive_Caff', 'template_settings_form'), |
|
46
|
|
|
10 |
|
47
|
|
|
); |
|
48
|
|
|
add_filter( |
|
49
|
|
|
'FHEE__General_Settings_Admin_Page__update_template_settings__data', |
|
50
|
|
|
array('EED_Events_Archive_Caff', 'update_template_settings'), |
|
51
|
|
|
10, |
|
52
|
|
|
2 |
|
53
|
|
|
); |
|
54
|
|
|
// AJAX |
|
55
|
|
|
add_action( |
|
56
|
|
|
'wp_ajax_espresso_update_event_archive_order', |
|
57
|
|
|
array('EED_Events_Archive_Caff', 'update_event_archive_order') |
|
58
|
|
|
); |
|
59
|
|
|
add_action( |
|
60
|
|
|
'wp_ajax_nopriv_espresso_update_event_archive_order', |
|
61
|
|
|
array('EED_Events_Archive_Caff', 'update_event_archive_order') |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* run - initial module setup |
|
68
|
|
|
* |
|
69
|
|
|
* @param WP $WP |
|
70
|
|
|
* @return void |
|
71
|
|
|
*/ |
|
72
|
|
|
public function run($WP) |
|
73
|
|
|
{ |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Conditionally set constants if they haven't been defined yet. |
|
79
|
|
|
*/ |
|
80
|
|
View Code Duplication |
public static function setDefinitions() |
|
81
|
|
|
{ |
|
82
|
|
|
if (! defined('EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH')) { |
|
83
|
|
|
define( |
|
84
|
|
|
'EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH', |
|
85
|
|
|
str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS |
|
86
|
|
|
); |
|
87
|
|
|
define('EVENT_ARCHIVE_CAFF_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @return void |
|
94
|
|
|
* @throws DomainException |
|
95
|
|
|
* @throws InvalidArgumentException |
|
96
|
|
|
* @throws InvalidDataTypeException |
|
97
|
|
|
* @throws InvalidInterfaceException |
|
98
|
|
|
*/ |
|
99
|
|
|
public static function template_settings_form() |
|
100
|
|
|
{ |
|
101
|
|
|
// grab general settings admin page and remove the existing hook callback |
|
102
|
|
|
$gen_set_admin = EE_Registry::instance()->LIB->EE_Admin_Page_Loader->get_admin_page_object('general_settings'); |
|
103
|
|
|
if ($gen_set_admin instanceof General_Settings_Admin_Page) { |
|
104
|
|
|
remove_action( |
|
105
|
|
|
'AHEE__template_settings__template__before_settings_form', |
|
106
|
|
|
array($gen_set_admin, 'template_settings_caff_features'), |
|
107
|
|
|
100 |
|
108
|
|
|
); |
|
109
|
|
|
} |
|
110
|
|
|
// first just grab the template settings |
|
111
|
|
|
$config = EE_Registry::instance()->CFG->template_settings; |
|
112
|
|
|
// then if the Event Archive config is valid, use that, else create a new one |
|
113
|
|
|
$config = $config instanceof EE_Template_Config |
|
114
|
|
|
&& $config->EED_Events_Archive instanceof EE_Events_Archive_Config |
|
115
|
|
|
? $config->EED_Events_Archive |
|
116
|
|
|
: new EE_Events_Archive_Config(); |
|
117
|
|
|
$config = apply_filters( |
|
118
|
|
|
'FHEE__EED_Events_Archive__template_settings_form__event_list_config', |
|
119
|
|
|
$config |
|
120
|
|
|
); |
|
121
|
|
|
$config->display_status_banner = isset($config->display_status_banner) |
|
122
|
|
|
? $config->display_status_banner |
|
123
|
|
|
: 0; |
|
124
|
|
|
$config->display_description = isset($config->display_description) |
|
125
|
|
|
? $config->display_description |
|
126
|
|
|
: 1; |
|
127
|
|
|
$config->display_ticket_selector = isset($config->display_ticket_selector) |
|
128
|
|
|
? $config->display_ticket_selector |
|
129
|
|
|
: 0; |
|
130
|
|
|
$config->display_datetimes = isset($config->display_datetimes) |
|
131
|
|
|
? $config->display_datetimes |
|
132
|
|
|
: 1; |
|
133
|
|
|
$config->display_venue = isset($config->display_venue) |
|
134
|
|
|
? $config->display_venue |
|
135
|
|
|
: 0; |
|
136
|
|
|
$config->display_expired_events = isset($config->display_expired_events) |
|
137
|
|
|
? $config->display_expired_events |
|
138
|
|
|
: 0; |
|
139
|
|
|
// display order options |
|
140
|
|
|
$config->use_sortable_display_order = isset($config->use_sortable_display_order) |
|
141
|
|
|
? $config->use_sortable_display_order |
|
142
|
|
|
: false; |
|
143
|
|
|
$config->display_order_tickets = isset($config->display_order_tickets) |
|
144
|
|
|
? $config->display_order_tickets |
|
145
|
|
|
: 120; |
|
146
|
|
|
$config->display_order_datetimes = isset($config->display_order_datetimes) |
|
147
|
|
|
? $config->display_order_datetimes |
|
148
|
|
|
: 110; |
|
149
|
|
|
$config->display_order_event = isset($config->display_order_event) |
|
150
|
|
|
? $config->display_order_event |
|
151
|
|
|
: 100; |
|
152
|
|
|
$config->display_order_venue = isset($config->display_order_venue) |
|
153
|
|
|
? $config->display_order_venue |
|
154
|
|
|
: 130; |
|
155
|
|
|
// get template parts |
|
156
|
|
|
$template_parts = EED_Events_Archive::instance()->initialize_template_parts($config); |
|
157
|
|
|
// convert to array so that we can add more properties |
|
158
|
|
|
$config = get_object_vars($config); |
|
159
|
|
|
$config['event_archive_display_order'] = $template_parts->generate_sortable_list_of_template_parts( |
|
160
|
|
|
'event-archive-sortable-js', |
|
161
|
|
|
'', |
|
162
|
|
|
'archive-sortable-li archive-sortable-js' |
|
163
|
|
|
); |
|
164
|
|
|
EEH_Template::display_template( |
|
165
|
|
|
EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH . 'admin-event-list-settings.template.php', |
|
166
|
|
|
$config |
|
167
|
|
|
); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* @param EE_Template_Config $CFG |
|
173
|
|
|
* @param array $REQ |
|
174
|
|
|
* @return EE_Template_Config |
|
175
|
|
|
*/ |
|
176
|
|
|
public static function update_template_settings($CFG, $REQ) |
|
177
|
|
|
{ |
|
178
|
|
|
/** @var EE_Events_Archive_Config $config */ |
|
179
|
|
|
$config = $CFG->EED_Events_Archive instanceof EE_Events_Archive_Config |
|
180
|
|
|
? $CFG->EED_Events_Archive |
|
181
|
|
|
: new EE_Events_Archive_Config(); |
|
182
|
|
|
// unless we are resetting the config... |
|
183
|
|
|
if (! isset($REQ['EED_Events_Archive_reset_event_list_settings']) |
|
184
|
|
|
|| absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1 |
|
185
|
|
|
) { |
|
186
|
|
|
$config->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner']) |
|
187
|
|
|
? absint($REQ['EED_Events_Archive_display_status_banner']) |
|
188
|
|
|
: 0; |
|
189
|
|
|
$config->display_description = isset($REQ['EED_Events_Archive_display_description']) |
|
190
|
|
|
? absint($REQ['EED_Events_Archive_display_description']) |
|
191
|
|
|
: 1; |
|
192
|
|
|
$config->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector']) |
|
193
|
|
|
? absint($REQ['EED_Events_Archive_display_ticket_selector']) |
|
194
|
|
|
: 0; |
|
195
|
|
|
$config->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes']) |
|
196
|
|
|
? absint($REQ['EED_Events_Archive_display_datetimes']) |
|
197
|
|
|
: 1; |
|
198
|
|
|
$config->display_venue = isset($REQ['EED_Events_Archive_display_venue']) |
|
199
|
|
|
? absint($REQ['EED_Events_Archive_display_venue']) |
|
200
|
|
|
: 0; |
|
201
|
|
|
$config->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events']) |
|
202
|
|
|
? absint($REQ['EED_Events_Archive_display_expired_events']) |
|
203
|
|
|
: 0; |
|
204
|
|
|
$config->use_sortable_display_order = isset($REQ['EED_Events_Archive_use_sortable_display_order']) |
|
205
|
|
|
? absint($REQ['EED_Events_Archive_use_sortable_display_order']) |
|
206
|
|
|
: 0; |
|
207
|
|
|
$config->display_order_event = $config->display_order_event !== null |
|
208
|
|
|
&& $config->use_sortable_display_order |
|
209
|
|
|
? $config->display_order_event |
|
210
|
|
|
: EED_Events_Archive::EVENT_DETAILS_PRIORITY; |
|
211
|
|
|
$config->display_order_datetimes = $config->display_order_datetimes !== null |
|
212
|
|
|
&& $config->use_sortable_display_order |
|
213
|
|
|
? $config->display_order_datetimes |
|
214
|
|
|
: EED_Events_Archive::EVENT_DATETIMES_PRIORITY; |
|
215
|
|
|
$config->display_order_tickets = $config->display_order_tickets !== null |
|
216
|
|
|
&& $config->use_sortable_display_order |
|
217
|
|
|
? $config->display_order_tickets |
|
218
|
|
|
: EED_Events_Archive::EVENT_TICKETS_PRIORITY; |
|
219
|
|
|
$config->display_order_venue = $config->display_order_venue !== null |
|
220
|
|
|
&& $config->use_sortable_display_order |
|
221
|
|
|
? $config->display_order_venue |
|
222
|
|
|
: EED_Events_Archive::EVENT_VENUES_PRIORITY; |
|
223
|
|
|
} |
|
224
|
|
|
$CFG->EED_Events_Archive = $config; |
|
225
|
|
|
do_action('AHEE__EED_Events_Archive__update_template_settings__after_update', $CFG, $REQ); |
|
226
|
|
|
return $CFG; |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* @return void |
|
232
|
|
|
* @throws InvalidArgumentException |
|
233
|
|
|
* @throws InvalidDataTypeException |
|
234
|
|
|
* @throws InvalidInterfaceException |
|
235
|
|
|
*/ |
|
236
|
|
|
public static function update_event_archive_order() |
|
237
|
|
|
{ |
|
238
|
|
|
/** @var EE_Config $config */ |
|
239
|
|
|
$config = EE_Registry::instance()->CFG; |
|
240
|
|
|
$config_saved = false; |
|
241
|
|
|
$template_parts = sanitize_text_field($_POST['elements']); |
|
242
|
|
|
if (! empty($template_parts)) { |
|
243
|
|
|
$template_parts = explode(',', trim($template_parts, ',')); |
|
244
|
|
|
foreach ($template_parts as $key => $template_part) { |
|
245
|
|
|
$template_part = "display_order_$template_part"; |
|
246
|
|
|
$priority = ($key * 10) + EED_Events_Archive::EVENT_DETAILS_PRIORITY; |
|
247
|
|
|
if ($config->template_settings->EED_Events_Archive instanceof EE_Events_Archive_Config |
|
248
|
|
|
&& property_exists( |
|
249
|
|
|
$config->template_settings->EED_Events_Archive, |
|
250
|
|
|
$template_part |
|
251
|
|
|
) |
|
252
|
|
|
) { |
|
253
|
|
|
$config->template_settings->EED_Events_Archive->{$template_part} = $priority; |
|
254
|
|
|
} |
|
255
|
|
|
do_action("AHEE__EED_Events_Archive__update_event_archive_order__$template_part", $priority); |
|
256
|
|
|
} |
|
257
|
|
|
$config_saved = $config->update_espresso_config(false, false); |
|
258
|
|
|
} |
|
259
|
|
View Code Duplication |
if ($config_saved) { |
|
260
|
|
|
EE_Error::add_success(__('Display Order has been successfully updated.', 'event_espresso')); |
|
261
|
|
|
} else { |
|
262
|
|
|
EE_Error::add_error( |
|
263
|
|
|
__('Display Order was not updated.', 'event_espresso'), |
|
264
|
|
|
__FILE__, |
|
265
|
|
|
__FUNCTION__, |
|
266
|
|
|
__LINE__ |
|
267
|
|
|
); |
|
268
|
|
|
} |
|
269
|
|
|
echo wp_json_encode(EE_Error::get_notices(false)); |
|
270
|
|
|
exit(); |
|
271
|
|
|
} |
|
272
|
|
|
} |
|
273
|
|
|
|