@@ -27,12 +27,12 @@ discard block |
||
| 27 | 27 | * @param int | \EE_Event $event |
| 28 | 28 | * @return bool |
| 29 | 29 | */ |
| 30 | -function is_espresso_event( $event = NULL ) { |
|
| 31 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
| 30 | +function is_espresso_event($event = NULL) { |
|
| 31 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
| 32 | 32 | // extract EE_Event object from passed param regardless of what it is (within reason of course) |
| 33 | - $event = EEH_Event_View::get_event( $event ); |
|
| 33 | + $event = EEH_Event_View::get_event($event); |
|
| 34 | 34 | // do we have a valid event ? |
| 35 | - return $event instanceof EE_Event ? TRUE : FALSE; |
|
| 35 | + return $event instanceof EE_Event ? TRUE : FALSE; |
|
| 36 | 36 | } |
| 37 | 37 | return FALSE; |
| 38 | 38 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * @return bool |
| 45 | 45 | */ |
| 46 | 46 | function is_espresso_event_single() { |
| 47 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
| 47 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
| 48 | 48 | global $wp_query; |
| 49 | 49 | // return conditionals set by CPTs |
| 50 | 50 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_single : FALSE; |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * @return bool |
| 60 | 60 | */ |
| 61 | 61 | function is_espresso_event_archive() { |
| 62 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
| 62 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
| 63 | 63 | global $wp_query; |
| 64 | 64 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_archive : FALSE; |
| 65 | 65 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * @return bool |
| 74 | 74 | */ |
| 75 | 75 | function is_espresso_event_taxonomy() { |
| 76 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
| 76 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
| 77 | 77 | global $wp_query; |
| 78 | 78 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_taxonomy : FALSE; |
| 79 | 79 | } |
@@ -87,10 +87,10 @@ discard block |
||
| 87 | 87 | * @param int | \EE_Venue $venue |
| 88 | 88 | * @return bool |
| 89 | 89 | */ |
| 90 | -function is_espresso_venue( $venue = NULL ) { |
|
| 91 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
| 90 | +function is_espresso_venue($venue = NULL) { |
|
| 91 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
| 92 | 92 | // extract EE_Venue object from passed param regardless of what it is (within reason of course) |
| 93 | - $venue = EEH_Venue_View::get_venue( $venue, FALSE ); |
|
| 93 | + $venue = EEH_Venue_View::get_venue($venue, FALSE); |
|
| 94 | 94 | // do we have a valid event ? |
| 95 | 95 | return $venue instanceof EE_Venue ? TRUE : FALSE; |
| 96 | 96 | } |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * @return bool |
| 105 | 105 | */ |
| 106 | 106 | function is_espresso_venue_single() { |
| 107 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
| 107 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
| 108 | 108 | global $wp_query; |
| 109 | 109 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_single : FALSE; |
| 110 | 110 | } |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | * @return bool |
| 119 | 119 | */ |
| 120 | 120 | function is_espresso_venue_archive() { |
| 121 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
| 121 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
| 122 | 122 | global $wp_query; |
| 123 | 123 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_archive : FALSE; |
| 124 | 124 | } |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | * @return bool |
| 133 | 133 | */ |
| 134 | 134 | function is_espresso_venue_taxonomy() { |
| 135 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
| 135 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
| 136 | 136 | global $wp_query; |
| 137 | 137 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_taxonomy : FALSE; |
| 138 | 138 | } |
@@ -146,12 +146,12 @@ discard block |
||
| 146 | 146 | * @param $conditional_tag |
| 147 | 147 | * @return bool |
| 148 | 148 | */ |
| 149 | -function can_use_espresso_conditionals( $conditional_tag ) { |
|
| 150 | - if ( ! did_action( 'AHEE__EE_System__initialize' )) { |
|
| 149 | +function can_use_espresso_conditionals($conditional_tag) { |
|
| 150 | + if ( ! did_action('AHEE__EE_System__initialize')) { |
|
| 151 | 151 | EE_Error::doing_it_wrong( |
| 152 | 152 | __FUNCTION__, |
| 153 | 153 | sprintf( |
| 154 | - __( 'The "%s" conditional tag can not be used until after the "init" hook has run, but works best when used within a theme\'s template files.','event_espresso'), |
|
| 154 | + __('The "%s" conditional tag can not be used until after the "init" hook has run, but works best when used within a theme\'s template files.', 'event_espresso'), |
|
| 155 | 155 | $conditional_tag |
| 156 | 156 | ), |
| 157 | 157 | '4.4.0' |
@@ -166,13 +166,13 @@ discard block |
||
| 166 | 166 | |
| 167 | 167 | /*************************** Event Queries ***************************/ |
| 168 | 168 | |
| 169 | -if ( ! function_exists( 'espresso_get_events' )) { |
|
| 169 | +if ( ! function_exists('espresso_get_events')) { |
|
| 170 | 170 | /** |
| 171 | 171 | * espresso_get_events |
| 172 | 172 | * @param array $params |
| 173 | 173 | * @return array |
| 174 | 174 | */ |
| 175 | - function espresso_get_events( $params = array() ) { |
|
| 175 | + function espresso_get_events($params = array()) { |
|
| 176 | 176 | //set default params |
| 177 | 177 | $default_espresso_events_params = array( |
| 178 | 178 | 'limit' => 10, |
@@ -183,18 +183,18 @@ discard block |
||
| 183 | 183 | 'sort' => 'ASC' |
| 184 | 184 | ); |
| 185 | 185 | // allow the defaults to be filtered |
| 186 | - $default_espresso_events_params = apply_filters( 'espresso_get_events__default_espresso_events_params', $default_espresso_events_params ); |
|
| 186 | + $default_espresso_events_params = apply_filters('espresso_get_events__default_espresso_events_params', $default_espresso_events_params); |
|
| 187 | 187 | // grab params and merge with defaults, then extract |
| 188 | - $params = array_merge( $default_espresso_events_params, $params ); |
|
| 188 | + $params = array_merge($default_espresso_events_params, $params); |
|
| 189 | 189 | // run the query |
| 190 | - $events_query = new EE_Event_List_Query( $params ); |
|
| 190 | + $events_query = new EE_Event_List_Query($params); |
|
| 191 | 191 | // assign results to a variable so we can return it |
| 192 | 192 | $events = $events_query->have_posts() ? $events_query->posts : array(); |
| 193 | 193 | // but first reset the query and postdata |
| 194 | 194 | wp_reset_query(); |
| 195 | 195 | wp_reset_postdata(); |
| 196 | 196 | EED_Events_Archive::remove_all_events_archive_filters(); |
| 197 | - unset( $events_query ); |
|
| 197 | + unset($events_query); |
|
| 198 | 198 | return $events; |
| 199 | 199 | } |
| 200 | 200 | } |
@@ -208,32 +208,32 @@ discard block |
||
| 208 | 208 | * espresso_load_ticket_selector |
| 209 | 209 | */ |
| 210 | 210 | function espresso_load_ticket_selector() { |
| 211 | - EE_Registry::instance()->load_file( EE_MODULES . 'ticket_selector', 'EED_Ticket_Selector', 'module' ); |
|
| 211 | + EE_Registry::instance()->load_file(EE_MODULES.'ticket_selector', 'EED_Ticket_Selector', 'module'); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | -if ( ! function_exists( 'espresso_ticket_selector' )) { |
|
| 214 | +if ( ! function_exists('espresso_ticket_selector')) { |
|
| 215 | 215 | /** |
| 216 | 216 | * espresso_ticket_selector |
| 217 | 217 | * @param null $event |
| 218 | 218 | */ |
| 219 | - function espresso_ticket_selector( $event = NULL ) { |
|
| 220 | - if ( ! apply_filters( 'FHEE_disable_espresso_ticket_selector', FALSE ) ) { |
|
| 219 | + function espresso_ticket_selector($event = NULL) { |
|
| 220 | + if ( ! apply_filters('FHEE_disable_espresso_ticket_selector', FALSE)) { |
|
| 221 | 221 | espresso_load_ticket_selector(); |
| 222 | - echo EED_Ticket_Selector::display_ticket_selector( $event ); |
|
| 222 | + echo EED_Ticket_Selector::display_ticket_selector($event); |
|
| 223 | 223 | } |
| 224 | 224 | } |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | |
| 228 | - if ( ! function_exists( 'espresso_view_details_btn' )) { |
|
| 228 | + if ( ! function_exists('espresso_view_details_btn')) { |
|
| 229 | 229 | /** |
| 230 | 230 | * espresso_view_details_btn |
| 231 | 231 | * @param null $event |
| 232 | 232 | */ |
| 233 | - function espresso_view_details_btn( $event = NULL ) { |
|
| 234 | - if ( ! apply_filters( 'FHEE_disable_espresso_view_details_btn', FALSE ) ) { |
|
| 233 | + function espresso_view_details_btn($event = NULL) { |
|
| 234 | + if ( ! apply_filters('FHEE_disable_espresso_view_details_btn', FALSE)) { |
|
| 235 | 235 | espresso_load_ticket_selector(); |
| 236 | - echo EED_Ticket_Selector::display_ticket_selector( $event, TRUE ); |
|
| 236 | + echo EED_Ticket_Selector::display_ticket_selector($event, TRUE); |
|
| 237 | 237 | } |
| 238 | 238 | } |
| 239 | 239 | } |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | |
| 244 | 244 | /*************************** EEH_Event_View ***************************/ |
| 245 | 245 | |
| 246 | -if ( ! function_exists( 'espresso_load_event_list_assets' )) { |
|
| 246 | +if ( ! function_exists('espresso_load_event_list_assets')) { |
|
| 247 | 247 | /** |
| 248 | 248 | * espresso_load_event_list_assets |
| 249 | 249 | * ensures that event list styles and scripts are loaded |
@@ -252,13 +252,13 @@ discard block |
||
| 252 | 252 | */ |
| 253 | 253 | function espresso_load_event_list_assets() { |
| 254 | 254 | $event_list = EED_Events_Archive::instance(); |
| 255 | - add_action( 'AHEE__EE_System__initialize_last', array( $event_list, 'load_event_list_assets' ), 10 ); |
|
| 256 | - add_filter( 'FHEE_enable_default_espresso_css', '__return_true' ); |
|
| 255 | + add_action('AHEE__EE_System__initialize_last', array($event_list, 'load_event_list_assets'), 10); |
|
| 256 | + add_filter('FHEE_enable_default_espresso_css', '__return_true'); |
|
| 257 | 257 | } |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | |
| 261 | -if ( ! function_exists( 'espresso_event_reg_button' )) { |
|
| 261 | +if ( ! function_exists('espresso_event_reg_button')) { |
|
| 262 | 262 | /** |
| 263 | 263 | * espresso_event_reg_button |
| 264 | 264 | * returns the "Register Now" button if event is active, |
@@ -270,9 +270,9 @@ discard block |
||
| 270 | 270 | * @param bool $EVT_ID |
| 271 | 271 | * @return string |
| 272 | 272 | */ |
| 273 | - function espresso_event_reg_button( $btn_text_if_active = NULL, $btn_text_if_inactive = FALSE, $EVT_ID = FALSE ) { |
|
| 274 | - $event_status = EEH_Event_View::event_active_status( $EVT_ID ); |
|
| 275 | - switch ( $event_status ) { |
|
| 273 | + function espresso_event_reg_button($btn_text_if_active = NULL, $btn_text_if_inactive = FALSE, $EVT_ID = FALSE) { |
|
| 274 | + $event_status = EEH_Event_View::event_active_status($EVT_ID); |
|
| 275 | + switch ($event_status) { |
|
| 276 | 276 | case EE_Datetime::sold_out : |
| 277 | 277 | $btn_text = __('Sold Out', 'event_espresso'); |
| 278 | 278 | $class = 'ee-pink'; |
@@ -288,10 +288,10 @@ discard block |
||
| 288 | 288 | case EE_Datetime::upcoming : |
| 289 | 289 | case EE_Datetime::active : |
| 290 | 290 | default : |
| 291 | - $btn_text =! empty( $btn_text_if_active ) ? $btn_text_if_active : __( 'Register Now', 'event_espresso' ); |
|
| 291 | + $btn_text = ! empty($btn_text_if_active) ? $btn_text_if_active : __('Register Now', 'event_espresso'); |
|
| 292 | 292 | $class = 'ee-green'; |
| 293 | 293 | } |
| 294 | - if ( $event_status < 1 && ! empty( $btn_text_if_inactive )) { |
|
| 294 | + if ($event_status < 1 && ! empty($btn_text_if_inactive)) { |
|
| 295 | 295 | $btn_text = $btn_text_if_inactive; |
| 296 | 296 | $class = 'ee-grey'; |
| 297 | 297 | } |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | |
| 306 | 306 | |
| 307 | 307 | |
| 308 | -if ( ! function_exists( 'espresso_display_ticket_selector' )) { |
|
| 308 | +if ( ! function_exists('espresso_display_ticket_selector')) { |
|
| 309 | 309 | /** |
| 310 | 310 | * espresso_display_ticket_selector |
| 311 | 311 | * whether or not to display the Ticket Selector for an event |
@@ -313,14 +313,14 @@ discard block |
||
| 313 | 313 | * @param bool $EVT_ID |
| 314 | 314 | * @return boolean |
| 315 | 315 | */ |
| 316 | - function espresso_display_ticket_selector( $EVT_ID = FALSE ) { |
|
| 317 | - return EEH_Event_View::display_ticket_selector( $EVT_ID ); |
|
| 316 | + function espresso_display_ticket_selector($EVT_ID = FALSE) { |
|
| 317 | + return EEH_Event_View::display_ticket_selector($EVT_ID); |
|
| 318 | 318 | } |
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | |
| 322 | 322 | |
| 323 | -if ( ! function_exists( 'espresso_event_status_banner' )) { |
|
| 323 | +if ( ! function_exists('espresso_event_status_banner')) { |
|
| 324 | 324 | /** |
| 325 | 325 | * espresso_event_status |
| 326 | 326 | * returns a banner showing the event status if it is sold out, expired, or inactive |
@@ -328,13 +328,13 @@ discard block |
||
| 328 | 328 | * @param bool $EVT_ID |
| 329 | 329 | * @return string |
| 330 | 330 | */ |
| 331 | - function espresso_event_status_banner( $EVT_ID = FALSE ) { |
|
| 332 | - return EEH_Event_View::event_status( $EVT_ID ); |
|
| 331 | + function espresso_event_status_banner($EVT_ID = FALSE) { |
|
| 332 | + return EEH_Event_View::event_status($EVT_ID); |
|
| 333 | 333 | } |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | |
| 337 | -if ( ! function_exists( 'espresso_event_status' )) { |
|
| 337 | +if ( ! function_exists('espresso_event_status')) { |
|
| 338 | 338 | /** |
| 339 | 339 | * espresso_event_status |
| 340 | 340 | * returns the event status if it is sold out, expired, or inactive |
@@ -343,17 +343,17 @@ discard block |
||
| 343 | 343 | * @param bool $echo |
| 344 | 344 | * @return string |
| 345 | 345 | */ |
| 346 | - function espresso_event_status( $EVT_ID = 0, $echo = TRUE ) { |
|
| 347 | - if ( $echo ) { |
|
| 348 | - echo EEH_Event_View::event_active_status( $EVT_ID ); |
|
| 346 | + function espresso_event_status($EVT_ID = 0, $echo = TRUE) { |
|
| 347 | + if ($echo) { |
|
| 348 | + echo EEH_Event_View::event_active_status($EVT_ID); |
|
| 349 | 349 | return ''; |
| 350 | 350 | } |
| 351 | - return EEH_Event_View::event_active_status( $EVT_ID ); |
|
| 351 | + return EEH_Event_View::event_active_status($EVT_ID); |
|
| 352 | 352 | } |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | |
| 356 | -if ( ! function_exists( 'espresso_event_categories' )) { |
|
| 356 | +if ( ! function_exists('espresso_event_categories')) { |
|
| 357 | 357 | /** |
| 358 | 358 | * espresso_event_categories |
| 359 | 359 | * returns the terms associated with an event |
@@ -363,17 +363,17 @@ discard block |
||
| 363 | 363 | * @param bool $echo |
| 364 | 364 | * @return string |
| 365 | 365 | */ |
| 366 | - function espresso_event_categories( $EVT_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE ) { |
|
| 367 | - if ( $echo ) { |
|
| 368 | - echo EEH_Event_View::event_categories( $EVT_ID, $hide_uncategorized ); |
|
| 366 | + function espresso_event_categories($EVT_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE) { |
|
| 367 | + if ($echo) { |
|
| 368 | + echo EEH_Event_View::event_categories($EVT_ID, $hide_uncategorized); |
|
| 369 | 369 | return ''; |
| 370 | 370 | } |
| 371 | - return EEH_Event_View::event_categories( $EVT_ID, $hide_uncategorized ); |
|
| 371 | + return EEH_Event_View::event_categories($EVT_ID, $hide_uncategorized); |
|
| 372 | 372 | } |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | |
| 376 | -if ( ! function_exists( 'espresso_event_tickets_available' )) { |
|
| 376 | +if ( ! function_exists('espresso_event_tickets_available')) { |
|
| 377 | 377 | /** |
| 378 | 378 | * espresso_event_tickets_available |
| 379 | 379 | * returns the ticket types available for purchase for an event |
@@ -383,26 +383,26 @@ discard block |
||
| 383 | 383 | * @param bool $format |
| 384 | 384 | * @return string |
| 385 | 385 | */ |
| 386 | - function espresso_event_tickets_available( $EVT_ID = 0, $echo = TRUE, $format = TRUE ) { |
|
| 387 | - $tickets = EEH_Event_View::event_tickets_available( $EVT_ID ); |
|
| 388 | - if ( is_array( $tickets ) && ! empty( $tickets )) { |
|
| 386 | + function espresso_event_tickets_available($EVT_ID = 0, $echo = TRUE, $format = TRUE) { |
|
| 387 | + $tickets = EEH_Event_View::event_tickets_available($EVT_ID); |
|
| 388 | + if (is_array($tickets) && ! empty($tickets)) { |
|
| 389 | 389 | // if formatting then $html will be a string, else it will be an array of ticket objects |
| 390 | - $html = $format ? '<ul id="ee-event-tickets-ul-' . $EVT_ID . '" class="ee-event-tickets-ul">' : array(); |
|
| 391 | - foreach ( $tickets as $ticket ) { |
|
| 392 | - if ( $ticket instanceof EE_Ticket ) { |
|
| 393 | - if ( $format ) { |
|
| 394 | - $html .= '<li id="ee-event-tickets-li-' . $ticket->ID() . '" class="ee-event-tickets-li">'; |
|
| 395 | - $html .= $ticket->name() . ' ' . EEH_Template::format_currency( $ticket->get_ticket_total_with_taxes() ); |
|
| 390 | + $html = $format ? '<ul id="ee-event-tickets-ul-'.$EVT_ID.'" class="ee-event-tickets-ul">' : array(); |
|
| 391 | + foreach ($tickets as $ticket) { |
|
| 392 | + if ($ticket instanceof EE_Ticket) { |
|
| 393 | + if ($format) { |
|
| 394 | + $html .= '<li id="ee-event-tickets-li-'.$ticket->ID().'" class="ee-event-tickets-li">'; |
|
| 395 | + $html .= $ticket->name().' '.EEH_Template::format_currency($ticket->get_ticket_total_with_taxes()); |
|
| 396 | 396 | $html .= '</li>'; |
| 397 | 397 | } else { |
| 398 | 398 | $html[] = $ticket; |
| 399 | 399 | } |
| 400 | 400 | } |
| 401 | 401 | } |
| 402 | - if ( $format ) { |
|
| 402 | + if ($format) { |
|
| 403 | 403 | $html .= '</ul>'; |
| 404 | 404 | } |
| 405 | - if ( $echo && ! $format ) { |
|
| 405 | + if ($echo && ! $format) { |
|
| 406 | 406 | echo $html; |
| 407 | 407 | return ''; |
| 408 | 408 | } |
@@ -412,7 +412,7 @@ discard block |
||
| 412 | 412 | } |
| 413 | 413 | } |
| 414 | 414 | |
| 415 | -if ( ! function_exists( 'espresso_event_date_obj' )) { |
|
| 415 | +if ( ! function_exists('espresso_event_date_obj')) { |
|
| 416 | 416 | /** |
| 417 | 417 | * espresso_event_date_obj |
| 418 | 418 | * returns the primary date object for an event |
@@ -420,13 +420,13 @@ discard block |
||
| 420 | 420 | * @param bool $EVT_ID |
| 421 | 421 | * @return object |
| 422 | 422 | */ |
| 423 | - function espresso_event_date_obj( $EVT_ID = FALSE ) { |
|
| 424 | - return EEH_Event_View::get_primary_date_obj( $EVT_ID ); |
|
| 423 | + function espresso_event_date_obj($EVT_ID = FALSE) { |
|
| 424 | + return EEH_Event_View::get_primary_date_obj($EVT_ID); |
|
| 425 | 425 | } |
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | |
| 429 | -if ( ! function_exists( 'espresso_event_date' )) { |
|
| 429 | +if ( ! function_exists('espresso_event_date')) { |
|
| 430 | 430 | /** |
| 431 | 431 | * espresso_event_date |
| 432 | 432 | * returns the primary date for an event |
@@ -437,22 +437,22 @@ discard block |
||
| 437 | 437 | * @param bool $echo |
| 438 | 438 | * @return string |
| 439 | 439 | */ |
| 440 | - function espresso_event_date( $date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE ) { |
|
| 441 | - $date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' ); |
|
| 442 | - $time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' ); |
|
| 443 | - $date_format = apply_filters( 'FHEE__espresso_event_date__date_format', $date_format ); |
|
| 444 | - $time_format = apply_filters( 'FHEE__espresso_event_date__time_format', $time_format ); |
|
| 445 | - if($echo){ |
|
| 446 | - echo EEH_Event_View::the_event_date( $date_format, $time_format, $EVT_ID ); |
|
| 440 | + function espresso_event_date($date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE) { |
|
| 441 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
| 442 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
| 443 | + $date_format = apply_filters('FHEE__espresso_event_date__date_format', $date_format); |
|
| 444 | + $time_format = apply_filters('FHEE__espresso_event_date__time_format', $time_format); |
|
| 445 | + if ($echo) { |
|
| 446 | + echo EEH_Event_View::the_event_date($date_format, $time_format, $EVT_ID); |
|
| 447 | 447 | return ''; |
| 448 | 448 | } |
| 449 | - return EEH_Event_View::the_event_date( $date_format, $time_format, $EVT_ID ); |
|
| 449 | + return EEH_Event_View::the_event_date($date_format, $time_format, $EVT_ID); |
|
| 450 | 450 | |
| 451 | 451 | } |
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | |
| 455 | -if ( ! function_exists( 'espresso_list_of_event_dates' )) { |
|
| 455 | +if ( ! function_exists('espresso_list_of_event_dates')) { |
|
| 456 | 456 | /** |
| 457 | 457 | * espresso_list_of_event_dates |
| 458 | 458 | * returns a unordered list of dates for an event |
@@ -467,40 +467,40 @@ discard block |
||
| 467 | 467 | * @param null $limit |
| 468 | 468 | * @return string |
| 469 | 469 | */ |
| 470 | - function espresso_list_of_event_dates( $EVT_ID = 0, $date_format = '', $time_format = '', $echo = TRUE, $show_expired = NULL, $format = TRUE, $add_breaks = TRUE, $limit = NULL ) { |
|
| 471 | - $date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' ); |
|
| 472 | - $time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' ); |
|
| 473 | - $date_format = apply_filters( 'FHEE__espresso_list_of_event_dates__date_format', $date_format ); |
|
| 474 | - $time_format = apply_filters( 'FHEE__espresso_list_of_event_dates__time_format', $time_format ); |
|
| 475 | - $datetimes = EEH_Event_View::get_all_date_obj( $EVT_ID, $show_expired, FALSE, $limit ); |
|
| 476 | - if ( ! $format ) { |
|
| 477 | - return apply_filters( 'FHEE__espresso_list_of_event_dates__datetimes', $datetimes ); |
|
| 470 | + function espresso_list_of_event_dates($EVT_ID = 0, $date_format = '', $time_format = '', $echo = TRUE, $show_expired = NULL, $format = TRUE, $add_breaks = TRUE, $limit = NULL) { |
|
| 471 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
| 472 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
| 473 | + $date_format = apply_filters('FHEE__espresso_list_of_event_dates__date_format', $date_format); |
|
| 474 | + $time_format = apply_filters('FHEE__espresso_list_of_event_dates__time_format', $time_format); |
|
| 475 | + $datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, $show_expired, FALSE, $limit); |
|
| 476 | + if ( ! $format) { |
|
| 477 | + return apply_filters('FHEE__espresso_list_of_event_dates__datetimes', $datetimes); |
|
| 478 | 478 | } |
| 479 | 479 | //d( $datetimes ); |
| 480 | - if ( is_array( $datetimes ) && ! empty( $datetimes )) { |
|
| 480 | + if (is_array($datetimes) && ! empty($datetimes)) { |
|
| 481 | 481 | global $post; |
| 482 | - $html = $format ? '<ul id="ee-event-datetimes-ul-' . $post->ID . '" class="ee-event-datetimes-ul ee-clearfix">' : ''; |
|
| 483 | - foreach ( $datetimes as $datetime ) { |
|
| 484 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 485 | - $html .= '<li id="ee-event-datetimes-li-' . $datetime->ID(); |
|
| 486 | - $html .= '" class="ee-event-datetimes-li ee-event-datetimes-li-' . $datetime->get_active_status() . '">'; |
|
| 482 | + $html = $format ? '<ul id="ee-event-datetimes-ul-'.$post->ID.'" class="ee-event-datetimes-ul ee-clearfix">' : ''; |
|
| 483 | + foreach ($datetimes as $datetime) { |
|
| 484 | + if ($datetime instanceof EE_Datetime) { |
|
| 485 | + $html .= '<li id="ee-event-datetimes-li-'.$datetime->ID(); |
|
| 486 | + $html .= '" class="ee-event-datetimes-li ee-event-datetimes-li-'.$datetime->get_active_status().'">'; |
|
| 487 | 487 | $datetime_name = $datetime->name(); |
| 488 | - $html .= ! empty( $datetime_name ) ? '<strong>' . $datetime_name . '</strong>' : ''; |
|
| 489 | - $html .= ! empty( $datetime_name ) && $add_breaks ? '<br />' : ''; |
|
| 490 | - $html .= '<span class="dashicons dashicons-calendar"></span><span class="ee-event-datetimes-li-daterange">' . $datetime->date_range( $date_format ) . '</span><br/>'; |
|
| 491 | - $html .= '<span class="dashicons dashicons-clock"></span><span class="ee-event-datetimes-li-timerange">' . $datetime->time_range( $time_format ) . '</span>'; |
|
| 488 | + $html .= ! empty($datetime_name) ? '<strong>'.$datetime_name.'</strong>' : ''; |
|
| 489 | + $html .= ! empty($datetime_name) && $add_breaks ? '<br />' : ''; |
|
| 490 | + $html .= '<span class="dashicons dashicons-calendar"></span><span class="ee-event-datetimes-li-daterange">'.$datetime->date_range($date_format).'</span><br/>'; |
|
| 491 | + $html .= '<span class="dashicons dashicons-clock"></span><span class="ee-event-datetimes-li-timerange">'.$datetime->time_range($time_format).'</span>'; |
|
| 492 | 492 | $datetime_description = $datetime->description(); |
| 493 | - $html .= ! empty( $datetime_description ) && $add_breaks ? '<br />' : ''; |
|
| 494 | - $html .= ! empty( $datetime_description ) ? ' - ' . $datetime_description : ''; |
|
| 495 | - $html = apply_filters( 'FHEE__espresso_list_of_event_dates__datetime_html', $html, $datetime ); |
|
| 493 | + $html .= ! empty($datetime_description) && $add_breaks ? '<br />' : ''; |
|
| 494 | + $html .= ! empty($datetime_description) ? ' - '.$datetime_description : ''; |
|
| 495 | + $html = apply_filters('FHEE__espresso_list_of_event_dates__datetime_html', $html, $datetime); |
|
| 496 | 496 | $html .= '</li>'; |
| 497 | 497 | } |
| 498 | 498 | } |
| 499 | 499 | $html .= $format ? '</ul>' : ''; |
| 500 | 500 | } else { |
| 501 | - $html = $format ? '<p><span class="dashicons dashicons-marker pink-text"></span>' . __( 'There are no upcoming dates for this event.', 'event_espresso' ) . '</p><br/>' : ''; |
|
| 501 | + $html = $format ? '<p><span class="dashicons dashicons-marker pink-text"></span>'.__('There are no upcoming dates for this event.', 'event_espresso').'</p><br/>' : ''; |
|
| 502 | 502 | } |
| 503 | - if ( $echo ) { |
|
| 503 | + if ($echo) { |
|
| 504 | 504 | echo $html; |
| 505 | 505 | return ''; |
| 506 | 506 | } |
@@ -509,7 +509,7 @@ discard block |
||
| 509 | 509 | } |
| 510 | 510 | |
| 511 | 511 | |
| 512 | -if ( ! function_exists( 'espresso_event_end_date' )) { |
|
| 512 | +if ( ! function_exists('espresso_event_end_date')) { |
|
| 513 | 513 | /** |
| 514 | 514 | * espresso_event_end_date |
| 515 | 515 | * returns the last date for an event |
@@ -520,20 +520,20 @@ discard block |
||
| 520 | 520 | * @param bool $echo |
| 521 | 521 | * @return string |
| 522 | 522 | */ |
| 523 | - function espresso_event_end_date( $date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE ) { |
|
| 524 | - $date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' ); |
|
| 525 | - $time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' ); |
|
| 526 | - $date_format = apply_filters( 'FHEE__espresso_event_end_date__date_format', $date_format ); |
|
| 527 | - $time_format = apply_filters( 'FHEE__espresso_event_end_date__time_format', $time_format ); |
|
| 528 | - if($echo){ |
|
| 529 | - echo EEH_Event_View::the_event_end_date( $date_format, $time_format, $EVT_ID ); |
|
| 523 | + function espresso_event_end_date($date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE) { |
|
| 524 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
| 525 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
| 526 | + $date_format = apply_filters('FHEE__espresso_event_end_date__date_format', $date_format); |
|
| 527 | + $time_format = apply_filters('FHEE__espresso_event_end_date__time_format', $time_format); |
|
| 528 | + if ($echo) { |
|
| 529 | + echo EEH_Event_View::the_event_end_date($date_format, $time_format, $EVT_ID); |
|
| 530 | 530 | return ''; |
| 531 | 531 | } |
| 532 | - return EEH_Event_View::the_event_end_date( $date_format, $time_format, $EVT_ID ); |
|
| 532 | + return EEH_Event_View::the_event_end_date($date_format, $time_format, $EVT_ID); |
|
| 533 | 533 | } |
| 534 | 534 | } |
| 535 | 535 | |
| 536 | -if ( ! function_exists( 'espresso_event_date_range' )) { |
|
| 536 | +if ( ! function_exists('espresso_event_date_range')) { |
|
| 537 | 537 | /** |
| 538 | 538 | * espresso_event_date_range |
| 539 | 539 | * returns the first and last chronologically ordered dates for an event (if different) |
@@ -546,31 +546,31 @@ discard block |
||
| 546 | 546 | * @param bool $echo |
| 547 | 547 | * @return string |
| 548 | 548 | */ |
| 549 | - function espresso_event_date_range( $date_format = '', $time_format = '', $single_date_format = '', $single_time_format = '', $EVT_ID = FALSE, $echo = TRUE ) { |
|
| 549 | + function espresso_event_date_range($date_format = '', $time_format = '', $single_date_format = '', $single_time_format = '', $EVT_ID = FALSE, $echo = TRUE) { |
|
| 550 | 550 | // set and filter date and time formats when a range is returned |
| 551 | - $date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' ); |
|
| 552 | - $date_format = apply_filters( 'FHEE__espresso_event_date_range__date_format', $date_format ); |
|
| 551 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
| 552 | + $date_format = apply_filters('FHEE__espresso_event_date_range__date_format', $date_format); |
|
| 553 | 553 | // get the start and end date with NO time portion |
| 554 | - $the_event_date = EEH_Event_View::the_earliest_event_date( $date_format, '', $EVT_ID ); |
|
| 555 | - $the_event_end_date = EEH_Event_View::the_latest_event_date( $date_format, '', $EVT_ID ); |
|
| 554 | + $the_event_date = EEH_Event_View::the_earliest_event_date($date_format, '', $EVT_ID); |
|
| 555 | + $the_event_end_date = EEH_Event_View::the_latest_event_date($date_format, '', $EVT_ID); |
|
| 556 | 556 | // now we can determine if date range spans more than one day |
| 557 | - if ( $the_event_date != $the_event_end_date ) { |
|
| 558 | - $time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' ); |
|
| 559 | - $time_format = apply_filters( 'FHEE__espresso_event_date_range__time_format', $time_format ); |
|
| 557 | + if ($the_event_date != $the_event_end_date) { |
|
| 558 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
| 559 | + $time_format = apply_filters('FHEE__espresso_event_date_range__time_format', $time_format); |
|
| 560 | 560 | $html = sprintf( |
| 561 | - __( '%1$s - %2$s', 'event_espresso' ), |
|
| 562 | - EEH_Event_View::the_earliest_event_date( $date_format, $time_format, $EVT_ID ), |
|
| 563 | - EEH_Event_View::the_latest_event_date( $date_format, $time_format, $EVT_ID ) |
|
| 561 | + __('%1$s - %2$s', 'event_espresso'), |
|
| 562 | + EEH_Event_View::the_earliest_event_date($date_format, $time_format, $EVT_ID), |
|
| 563 | + EEH_Event_View::the_latest_event_date($date_format, $time_format, $EVT_ID) |
|
| 564 | 564 | ); |
| 565 | 565 | } else { |
| 566 | 566 | // set and filter date and time formats when only a single datetime is returned |
| 567 | - $single_date_format = ! empty( $single_date_format ) ? $single_date_format : get_option( 'date_format' ); |
|
| 568 | - $single_time_format = ! empty( $single_time_format ) ? $single_time_format : get_option( 'time_format' ); |
|
| 569 | - $single_date_format = apply_filters( 'FHEE__espresso_event_date_range__single_date_format', $single_date_format ); |
|
| 570 | - $single_time_format = apply_filters( 'FHEE__espresso_event_date_range__single_time_format', $single_time_format ); |
|
| 571 | - $html = EEH_Event_View::the_earliest_event_date( $single_date_format, $single_time_format, $EVT_ID ); |
|
| 567 | + $single_date_format = ! empty($single_date_format) ? $single_date_format : get_option('date_format'); |
|
| 568 | + $single_time_format = ! empty($single_time_format) ? $single_time_format : get_option('time_format'); |
|
| 569 | + $single_date_format = apply_filters('FHEE__espresso_event_date_range__single_date_format', $single_date_format); |
|
| 570 | + $single_time_format = apply_filters('FHEE__espresso_event_date_range__single_time_format', $single_time_format); |
|
| 571 | + $html = EEH_Event_View::the_earliest_event_date($single_date_format, $single_time_format, $EVT_ID); |
|
| 572 | 572 | } |
| 573 | - if ( $echo ) { |
|
| 573 | + if ($echo) { |
|
| 574 | 574 | echo $html; |
| 575 | 575 | return ''; |
| 576 | 576 | } |
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | } |
| 580 | 580 | |
| 581 | 581 | |
| 582 | -if ( ! function_exists( 'espresso_event_date_as_calendar_page' )) { |
|
| 582 | +if ( ! function_exists('espresso_event_date_as_calendar_page')) { |
|
| 583 | 583 | /** |
| 584 | 584 | * espresso_event_date_as_calendar_page |
| 585 | 585 | * returns the primary date for an event, stylized to appear as the page of a calendar |
@@ -587,15 +587,15 @@ discard block |
||
| 587 | 587 | * @param bool $EVT_ID |
| 588 | 588 | * @return string |
| 589 | 589 | */ |
| 590 | - function espresso_event_date_as_calendar_page( $EVT_ID = FALSE ) { |
|
| 591 | - EEH_Event_View::event_date_as_calendar_page( $EVT_ID ); |
|
| 590 | + function espresso_event_date_as_calendar_page($EVT_ID = FALSE) { |
|
| 591 | + EEH_Event_View::event_date_as_calendar_page($EVT_ID); |
|
| 592 | 592 | } |
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | |
| 596 | 596 | |
| 597 | 597 | |
| 598 | -if ( ! function_exists( 'espresso_event_link_url' )) { |
|
| 598 | +if ( ! function_exists('espresso_event_link_url')) { |
|
| 599 | 599 | /** |
| 600 | 600 | * espresso_event_link_url |
| 601 | 601 | * |
@@ -603,18 +603,18 @@ discard block |
||
| 603 | 603 | * @param bool $echo |
| 604 | 604 | * @return string |
| 605 | 605 | */ |
| 606 | - function espresso_event_link_url( $EVT_ID = 0, $echo = TRUE ) { |
|
| 607 | - if ( $echo ) { |
|
| 608 | - echo EEH_Event_View::event_link_url( $EVT_ID ); |
|
| 606 | + function espresso_event_link_url($EVT_ID = 0, $echo = TRUE) { |
|
| 607 | + if ($echo) { |
|
| 608 | + echo EEH_Event_View::event_link_url($EVT_ID); |
|
| 609 | 609 | return ''; |
| 610 | 610 | } |
| 611 | - return EEH_Event_View::event_link_url( $EVT_ID ); |
|
| 611 | + return EEH_Event_View::event_link_url($EVT_ID); |
|
| 612 | 612 | } |
| 613 | 613 | } |
| 614 | 614 | |
| 615 | 615 | |
| 616 | 616 | |
| 617 | -if ( ! function_exists( 'espresso_event_has_content_or_excerpt' )) { |
|
| 617 | +if ( ! function_exists('espresso_event_has_content_or_excerpt')) { |
|
| 618 | 618 | /** |
| 619 | 619 | * espresso_event_has_content_or_excerpt |
| 620 | 620 | * |
@@ -622,15 +622,15 @@ discard block |
||
| 622 | 622 | * @param bool $EVT_ID |
| 623 | 623 | * @return boolean |
| 624 | 624 | */ |
| 625 | - function espresso_event_has_content_or_excerpt( $EVT_ID = FALSE ) { |
|
| 626 | - return EEH_Event_View::event_has_content_or_excerpt( $EVT_ID ); |
|
| 625 | + function espresso_event_has_content_or_excerpt($EVT_ID = FALSE) { |
|
| 626 | + return EEH_Event_View::event_has_content_or_excerpt($EVT_ID); |
|
| 627 | 627 | } |
| 628 | 628 | } |
| 629 | 629 | |
| 630 | 630 | |
| 631 | 631 | |
| 632 | 632 | |
| 633 | -if ( ! function_exists( 'espresso_event_content_or_excerpt' )) { |
|
| 633 | +if ( ! function_exists('espresso_event_content_or_excerpt')) { |
|
| 634 | 634 | /** |
| 635 | 635 | * espresso_event_content_or_excerpt |
| 636 | 636 | * |
@@ -639,18 +639,18 @@ discard block |
||
| 639 | 639 | * @param bool $echo |
| 640 | 640 | * @return string |
| 641 | 641 | */ |
| 642 | - function espresso_event_content_or_excerpt( $num_words = 55, $more = NULL, $echo = TRUE ) { |
|
| 643 | - if ( $echo ) { |
|
| 644 | - echo EEH_Event_View::event_content_or_excerpt( $num_words, $more ); |
|
| 642 | + function espresso_event_content_or_excerpt($num_words = 55, $more = NULL, $echo = TRUE) { |
|
| 643 | + if ($echo) { |
|
| 644 | + echo EEH_Event_View::event_content_or_excerpt($num_words, $more); |
|
| 645 | 645 | return ''; |
| 646 | 646 | } |
| 647 | - return EEH_Event_View::event_content_or_excerpt( $num_words, $more ); |
|
| 647 | + return EEH_Event_View::event_content_or_excerpt($num_words, $more); |
|
| 648 | 648 | } |
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | |
| 652 | 652 | |
| 653 | -if ( ! function_exists( 'espresso_event_phone' )) { |
|
| 653 | +if ( ! function_exists('espresso_event_phone')) { |
|
| 654 | 654 | /** |
| 655 | 655 | * espresso_event_phone |
| 656 | 656 | * |
@@ -658,18 +658,18 @@ discard block |
||
| 658 | 658 | * @param bool $echo |
| 659 | 659 | * @return string |
| 660 | 660 | */ |
| 661 | - function espresso_event_phone( $EVT_ID = 0, $echo = TRUE ) { |
|
| 662 | - if ( $echo ) { |
|
| 663 | - echo EEH_Event_View::event_phone( $EVT_ID ); |
|
| 661 | + function espresso_event_phone($EVT_ID = 0, $echo = TRUE) { |
|
| 662 | + if ($echo) { |
|
| 663 | + echo EEH_Event_View::event_phone($EVT_ID); |
|
| 664 | 664 | return ''; |
| 665 | 665 | } |
| 666 | - return EEH_Event_View::event_phone( $EVT_ID ); |
|
| 666 | + return EEH_Event_View::event_phone($EVT_ID); |
|
| 667 | 667 | } |
| 668 | 668 | } |
| 669 | 669 | |
| 670 | 670 | |
| 671 | 671 | |
| 672 | -if ( ! function_exists( 'espresso_edit_event_link' )) { |
|
| 672 | +if ( ! function_exists('espresso_edit_event_link')) { |
|
| 673 | 673 | /** |
| 674 | 674 | * espresso_edit_event_link |
| 675 | 675 | * returns a link to edit an event |
@@ -678,39 +678,39 @@ discard block |
||
| 678 | 678 | * @param bool $echo |
| 679 | 679 | * @return string |
| 680 | 680 | */ |
| 681 | - function espresso_edit_event_link( $EVT_ID = 0, $echo = TRUE ) { |
|
| 682 | - if ( $echo ) { |
|
| 683 | - echo EEH_Event_View::edit_event_link( $EVT_ID ); |
|
| 681 | + function espresso_edit_event_link($EVT_ID = 0, $echo = TRUE) { |
|
| 682 | + if ($echo) { |
|
| 683 | + echo EEH_Event_View::edit_event_link($EVT_ID); |
|
| 684 | 684 | return ''; |
| 685 | 685 | } |
| 686 | - return EEH_Event_View::edit_event_link( $EVT_ID ); |
|
| 686 | + return EEH_Event_View::edit_event_link($EVT_ID); |
|
| 687 | 687 | } |
| 688 | 688 | } |
| 689 | 689 | |
| 690 | 690 | |
| 691 | -if ( ! function_exists( 'espresso_organization_name' )) { |
|
| 691 | +if ( ! function_exists('espresso_organization_name')) { |
|
| 692 | 692 | /** |
| 693 | 693 | * espresso_organization_name |
| 694 | 694 | * @param bool $echo |
| 695 | 695 | * @return string |
| 696 | 696 | */ |
| 697 | 697 | function espresso_organization_name($echo = TRUE) { |
| 698 | - if($echo){ |
|
| 699 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'name' ); |
|
| 698 | + if ($echo) { |
|
| 699 | + echo EE_Registry::instance()->CFG->organization->get_pretty('name'); |
|
| 700 | 700 | return ''; |
| 701 | 701 | } |
| 702 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'name' ); |
|
| 702 | + return EE_Registry::instance()->CFG->organization->get_pretty('name'); |
|
| 703 | 703 | } |
| 704 | 704 | } |
| 705 | 705 | |
| 706 | -if ( ! function_exists( 'espresso_organization_address' )) { |
|
| 706 | +if ( ! function_exists('espresso_organization_address')) { |
|
| 707 | 707 | /** |
| 708 | 708 | * espresso_organization_address |
| 709 | 709 | * @param string $type |
| 710 | 710 | * @return string |
| 711 | 711 | */ |
| 712 | - function espresso_organization_address( $type = 'inline' ) { |
|
| 713 | - if ( EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config ) { |
|
| 712 | + function espresso_organization_address($type = 'inline') { |
|
| 713 | + if (EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config) { |
|
| 714 | 714 | $address = new EventEspresso\core\domain\entities\GenericAddress( |
| 715 | 715 | EE_Registry::instance()->CFG->organization->address_1, |
| 716 | 716 | EE_Registry::instance()->CFG->organization->address_2, |
@@ -719,129 +719,129 @@ discard block |
||
| 719 | 719 | EE_Registry::instance()->CFG->organization->zip, |
| 720 | 720 | EE_Registry::instance()->CFG->organization->CNT_ISO |
| 721 | 721 | ); |
| 722 | - return EEH_Address::format( $address, $type ); |
|
| 722 | + return EEH_Address::format($address, $type); |
|
| 723 | 723 | } |
| 724 | 724 | return ''; |
| 725 | 725 | } |
| 726 | 726 | } |
| 727 | 727 | |
| 728 | -if ( ! function_exists( 'espresso_organization_email' )) { |
|
| 728 | +if ( ! function_exists('espresso_organization_email')) { |
|
| 729 | 729 | /** |
| 730 | 730 | * espresso_organization_email |
| 731 | 731 | * @param bool $echo |
| 732 | 732 | * @return string |
| 733 | 733 | */ |
| 734 | - function espresso_organization_email( $echo = TRUE ) { |
|
| 735 | - if($echo){ |
|
| 736 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'email' ); |
|
| 734 | + function espresso_organization_email($echo = TRUE) { |
|
| 735 | + if ($echo) { |
|
| 736 | + echo EE_Registry::instance()->CFG->organization->get_pretty('email'); |
|
| 737 | 737 | return ''; |
| 738 | 738 | } |
| 739 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'email' ); |
|
| 739 | + return EE_Registry::instance()->CFG->organization->get_pretty('email'); |
|
| 740 | 740 | } |
| 741 | 741 | } |
| 742 | 742 | |
| 743 | -if ( ! function_exists( 'espresso_organization_logo_url' )) { |
|
| 743 | +if ( ! function_exists('espresso_organization_logo_url')) { |
|
| 744 | 744 | /** |
| 745 | 745 | * espresso_organization_logo_url |
| 746 | 746 | * @param bool $echo |
| 747 | 747 | * @return string |
| 748 | 748 | */ |
| 749 | - function espresso_organization_logo_url( $echo = TRUE ) { |
|
| 750 | - if($echo){ |
|
| 751 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'logo_url' ); |
|
| 749 | + function espresso_organization_logo_url($echo = TRUE) { |
|
| 750 | + if ($echo) { |
|
| 751 | + echo EE_Registry::instance()->CFG->organization->get_pretty('logo_url'); |
|
| 752 | 752 | return ''; |
| 753 | 753 | } |
| 754 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'logo_url' ); |
|
| 754 | + return EE_Registry::instance()->CFG->organization->get_pretty('logo_url'); |
|
| 755 | 755 | } |
| 756 | 756 | } |
| 757 | 757 | |
| 758 | -if ( ! function_exists( 'espresso_organization_facebook' )) { |
|
| 758 | +if ( ! function_exists('espresso_organization_facebook')) { |
|
| 759 | 759 | /** |
| 760 | 760 | * espresso_organization_facebook |
| 761 | 761 | * @param bool $echo |
| 762 | 762 | * @return string |
| 763 | 763 | */ |
| 764 | - function espresso_organization_facebook( $echo = TRUE ) { |
|
| 765 | - if($echo){ |
|
| 766 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'facebook' ); |
|
| 764 | + function espresso_organization_facebook($echo = TRUE) { |
|
| 765 | + if ($echo) { |
|
| 766 | + echo EE_Registry::instance()->CFG->organization->get_pretty('facebook'); |
|
| 767 | 767 | return ''; |
| 768 | 768 | } |
| 769 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'facebook' ); |
|
| 769 | + return EE_Registry::instance()->CFG->organization->get_pretty('facebook'); |
|
| 770 | 770 | } |
| 771 | 771 | } |
| 772 | 772 | |
| 773 | -if ( ! function_exists( 'espresso_organization_twitter' )) { |
|
| 773 | +if ( ! function_exists('espresso_organization_twitter')) { |
|
| 774 | 774 | /** |
| 775 | 775 | * espresso_organization_twitter |
| 776 | 776 | * @param bool $echo |
| 777 | 777 | * @return string |
| 778 | 778 | */ |
| 779 | - function espresso_organization_twitter( $echo = TRUE ) { |
|
| 780 | - if($echo){ |
|
| 781 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'twitter' ); |
|
| 779 | + function espresso_organization_twitter($echo = TRUE) { |
|
| 780 | + if ($echo) { |
|
| 781 | + echo EE_Registry::instance()->CFG->organization->get_pretty('twitter'); |
|
| 782 | 782 | return ''; |
| 783 | 783 | } |
| 784 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'twitter' ); |
|
| 784 | + return EE_Registry::instance()->CFG->organization->get_pretty('twitter'); |
|
| 785 | 785 | } |
| 786 | 786 | } |
| 787 | 787 | |
| 788 | -if ( ! function_exists( 'espresso_organization_linkedin' )) { |
|
| 788 | +if ( ! function_exists('espresso_organization_linkedin')) { |
|
| 789 | 789 | /** |
| 790 | 790 | * espresso_organization_linkedin |
| 791 | 791 | * @param bool $echo |
| 792 | 792 | * @return string |
| 793 | 793 | */ |
| 794 | - function espresso_organization_linkedin( $echo = TRUE ) { |
|
| 795 | - if($echo){ |
|
| 796 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'linkedin' ); |
|
| 794 | + function espresso_organization_linkedin($echo = TRUE) { |
|
| 795 | + if ($echo) { |
|
| 796 | + echo EE_Registry::instance()->CFG->organization->get_pretty('linkedin'); |
|
| 797 | 797 | return ''; |
| 798 | 798 | } |
| 799 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'linkedin' ); |
|
| 799 | + return EE_Registry::instance()->CFG->organization->get_pretty('linkedin'); |
|
| 800 | 800 | } |
| 801 | 801 | } |
| 802 | 802 | |
| 803 | -if ( ! function_exists( 'espresso_organization_pinterest' )) { |
|
| 803 | +if ( ! function_exists('espresso_organization_pinterest')) { |
|
| 804 | 804 | /** |
| 805 | 805 | * espresso_organization_pinterest |
| 806 | 806 | * @param bool $echo |
| 807 | 807 | * @return string |
| 808 | 808 | */ |
| 809 | - function espresso_organization_pinterest( $echo = TRUE ) { |
|
| 810 | - if($echo){ |
|
| 811 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'pinterest' ); |
|
| 809 | + function espresso_organization_pinterest($echo = TRUE) { |
|
| 810 | + if ($echo) { |
|
| 811 | + echo EE_Registry::instance()->CFG->organization->get_pretty('pinterest'); |
|
| 812 | 812 | return ''; |
| 813 | 813 | } |
| 814 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'pinterest' ); |
|
| 814 | + return EE_Registry::instance()->CFG->organization->get_pretty('pinterest'); |
|
| 815 | 815 | } |
| 816 | 816 | } |
| 817 | 817 | |
| 818 | -if ( ! function_exists( 'espresso_organization_google' )) { |
|
| 818 | +if ( ! function_exists('espresso_organization_google')) { |
|
| 819 | 819 | /** |
| 820 | 820 | * espresso_organization_google |
| 821 | 821 | * @param bool $echo |
| 822 | 822 | * @return string |
| 823 | 823 | */ |
| 824 | - function espresso_organization_google( $echo = TRUE ) { |
|
| 825 | - if($echo){ |
|
| 826 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'google' ); |
|
| 824 | + function espresso_organization_google($echo = TRUE) { |
|
| 825 | + if ($echo) { |
|
| 826 | + echo EE_Registry::instance()->CFG->organization->get_pretty('google'); |
|
| 827 | 827 | return ''; |
| 828 | 828 | } |
| 829 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'google' ); |
|
| 829 | + return EE_Registry::instance()->CFG->organization->get_pretty('google'); |
|
| 830 | 830 | } |
| 831 | 831 | } |
| 832 | 832 | |
| 833 | -if ( ! function_exists( 'espresso_organization_instagram' )) { |
|
| 833 | +if ( ! function_exists('espresso_organization_instagram')) { |
|
| 834 | 834 | /** |
| 835 | 835 | * espresso_organization_instagram |
| 836 | 836 | * @param bool $echo |
| 837 | 837 | * @return string |
| 838 | 838 | */ |
| 839 | - function espresso_organization_instagram( $echo = TRUE ) { |
|
| 840 | - if($echo){ |
|
| 841 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'instagram' ); |
|
| 839 | + function espresso_organization_instagram($echo = TRUE) { |
|
| 840 | + if ($echo) { |
|
| 841 | + echo EE_Registry::instance()->CFG->organization->get_pretty('instagram'); |
|
| 842 | 842 | return ''; |
| 843 | 843 | } |
| 844 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'instagram' ); |
|
| 844 | + return EE_Registry::instance()->CFG->organization->get_pretty('instagram'); |
|
| 845 | 845 | } |
| 846 | 846 | } |
| 847 | 847 | |
@@ -851,7 +851,7 @@ discard block |
||
| 851 | 851 | |
| 852 | 852 | |
| 853 | 853 | |
| 854 | -if ( ! function_exists( 'espresso_event_venues' )) { |
|
| 854 | +if ( ! function_exists('espresso_event_venues')) { |
|
| 855 | 855 | /** |
| 856 | 856 | * espresso_event_venues |
| 857 | 857 | * |
@@ -865,7 +865,7 @@ discard block |
||
| 865 | 865 | |
| 866 | 866 | |
| 867 | 867 | |
| 868 | -if ( ! function_exists( 'espresso_venue_id' )) { |
|
| 868 | +if ( ! function_exists('espresso_venue_id')) { |
|
| 869 | 869 | /** |
| 870 | 870 | * espresso_venue_name |
| 871 | 871 | * |
@@ -873,15 +873,15 @@ discard block |
||
| 873 | 873 | * @param int $EVT_ID |
| 874 | 874 | * @return string |
| 875 | 875 | */ |
| 876 | - function espresso_venue_id( $EVT_ID = 0 ) { |
|
| 877 | - $venue = EEH_Venue_View::get_venue( $EVT_ID ); |
|
| 876 | + function espresso_venue_id($EVT_ID = 0) { |
|
| 877 | + $venue = EEH_Venue_View::get_venue($EVT_ID); |
|
| 878 | 878 | return $venue instanceof EE_Venue ? $venue->ID() : 0; |
| 879 | 879 | } |
| 880 | 880 | } |
| 881 | 881 | |
| 882 | 882 | |
| 883 | 883 | |
| 884 | -if ( ! function_exists( 'espresso_is_venue_private' ) ) { |
|
| 884 | +if ( ! function_exists('espresso_is_venue_private')) { |
|
| 885 | 885 | /** |
| 886 | 886 | * Return whether a venue is private or not. |
| 887 | 887 | * @see EEH_Venue_View::get_venue() for more info on expected return results. |
@@ -890,45 +890,45 @@ discard block |
||
| 890 | 890 | * |
| 891 | 891 | * @return bool | null |
| 892 | 892 | */ |
| 893 | - function espresso_is_venue_private( $VNU_ID = 0 ) { |
|
| 894 | - return EEH_Venue_View::is_venue_private( $VNU_ID ); |
|
| 893 | + function espresso_is_venue_private($VNU_ID = 0) { |
|
| 894 | + return EEH_Venue_View::is_venue_private($VNU_ID); |
|
| 895 | 895 | } |
| 896 | 896 | } |
| 897 | 897 | |
| 898 | 898 | |
| 899 | 899 | |
| 900 | -if ( ! function_exists( 'espresso_venue_is_password_protected' ) ) { |
|
| 900 | +if ( ! function_exists('espresso_venue_is_password_protected')) { |
|
| 901 | 901 | /** |
| 902 | 902 | * returns true or false if a venue is password protected or not |
| 903 | 903 | * |
| 904 | 904 | * @param int $VNU_ID optional, the venue id to check. |
| 905 | 905 | * @return string |
| 906 | 906 | */ |
| 907 | - function espresso_venue_is_password_protected( $VNU_ID = 0 ) { |
|
| 908 | - EE_Registry::instance()->load_helper( 'Venue_View' ); |
|
| 909 | - return EEH_Venue_View::is_venue_password_protected( $VNU_ID ); |
|
| 907 | + function espresso_venue_is_password_protected($VNU_ID = 0) { |
|
| 908 | + EE_Registry::instance()->load_helper('Venue_View'); |
|
| 909 | + return EEH_Venue_View::is_venue_password_protected($VNU_ID); |
|
| 910 | 910 | } |
| 911 | 911 | } |
| 912 | 912 | |
| 913 | 913 | |
| 914 | 914 | |
| 915 | -if ( ! function_exists( 'espresso_password_protected_venue_form' ) ) { |
|
| 915 | +if ( ! function_exists('espresso_password_protected_venue_form')) { |
|
| 916 | 916 | /** |
| 917 | 917 | * Returns a password form if venue is password protected. |
| 918 | 918 | * |
| 919 | 919 | * @param int $VNU_ID optional, the venue id to check. |
| 920 | 920 | * @return string |
| 921 | 921 | */ |
| 922 | - function espresso_password_protected_venue_form( $VNU_ID = 0 ) { |
|
| 923 | - EE_Registry::instance()->load_helper( 'Venue_View' ); |
|
| 924 | - return EEH_Venue_View::password_protected_venue_form( $VNU_ID ); |
|
| 922 | + function espresso_password_protected_venue_form($VNU_ID = 0) { |
|
| 923 | + EE_Registry::instance()->load_helper('Venue_View'); |
|
| 924 | + return EEH_Venue_View::password_protected_venue_form($VNU_ID); |
|
| 925 | 925 | } |
| 926 | 926 | } |
| 927 | 927 | |
| 928 | 928 | |
| 929 | 929 | |
| 930 | 930 | |
| 931 | -if ( ! function_exists( 'espresso_venue_name' )) { |
|
| 931 | +if ( ! function_exists('espresso_venue_name')) { |
|
| 932 | 932 | /** |
| 933 | 933 | * espresso_venue_name |
| 934 | 934 | * |
@@ -938,19 +938,19 @@ discard block |
||
| 938 | 938 | * @param bool $echo |
| 939 | 939 | * @return string |
| 940 | 940 | */ |
| 941 | - function espresso_venue_name( $VNU_ID = 0, $link_to = 'details', $echo = TRUE ) { |
|
| 942 | - if($echo){ |
|
| 943 | - echo EEH_Venue_View::venue_name( $link_to, $VNU_ID ); |
|
| 941 | + function espresso_venue_name($VNU_ID = 0, $link_to = 'details', $echo = TRUE) { |
|
| 942 | + if ($echo) { |
|
| 943 | + echo EEH_Venue_View::venue_name($link_to, $VNU_ID); |
|
| 944 | 944 | return ''; |
| 945 | 945 | } |
| 946 | - return EEH_Venue_View::venue_name( $link_to, $VNU_ID ); |
|
| 946 | + return EEH_Venue_View::venue_name($link_to, $VNU_ID); |
|
| 947 | 947 | } |
| 948 | 948 | } |
| 949 | 949 | |
| 950 | 950 | |
| 951 | 951 | |
| 952 | 952 | |
| 953 | -if ( ! function_exists( 'espresso_venue_link' )) { |
|
| 953 | +if ( ! function_exists('espresso_venue_link')) { |
|
| 954 | 954 | /** |
| 955 | 955 | * espresso_venue_link |
| 956 | 956 | * |
@@ -959,14 +959,14 @@ discard block |
||
| 959 | 959 | * @param string $text |
| 960 | 960 | * @return string |
| 961 | 961 | */ |
| 962 | - function espresso_venue_link( $VNU_ID = 0, $text = '' ) { |
|
| 963 | - return EEH_Venue_View::venue_details_link( $VNU_ID, $text ); |
|
| 962 | + function espresso_venue_link($VNU_ID = 0, $text = '') { |
|
| 963 | + return EEH_Venue_View::venue_details_link($VNU_ID, $text); |
|
| 964 | 964 | } |
| 965 | 965 | } |
| 966 | 966 | |
| 967 | 967 | |
| 968 | 968 | |
| 969 | -if ( ! function_exists( 'espresso_venue_description' )) { |
|
| 969 | +if ( ! function_exists('espresso_venue_description')) { |
|
| 970 | 970 | /** |
| 971 | 971 | * espresso_venue_description |
| 972 | 972 | * |
@@ -975,17 +975,17 @@ discard block |
||
| 975 | 975 | * @param bool $echo |
| 976 | 976 | * @return string |
| 977 | 977 | */ |
| 978 | - function espresso_venue_description( $VNU_ID = FALSE, $echo = TRUE ) { |
|
| 979 | - if($echo){ |
|
| 980 | - echo EEH_Venue_View::venue_description( $VNU_ID ); |
|
| 978 | + function espresso_venue_description($VNU_ID = FALSE, $echo = TRUE) { |
|
| 979 | + if ($echo) { |
|
| 980 | + echo EEH_Venue_View::venue_description($VNU_ID); |
|
| 981 | 981 | return ''; |
| 982 | 982 | } |
| 983 | - return EEH_Venue_View::venue_description( $VNU_ID ); |
|
| 983 | + return EEH_Venue_View::venue_description($VNU_ID); |
|
| 984 | 984 | } |
| 985 | 985 | } |
| 986 | 986 | |
| 987 | 987 | |
| 988 | -if ( ! function_exists( 'espresso_venue_excerpt' )) { |
|
| 988 | +if ( ! function_exists('espresso_venue_excerpt')) { |
|
| 989 | 989 | /** |
| 990 | 990 | * espresso_venue_excerpt |
| 991 | 991 | * |
@@ -994,18 +994,18 @@ discard block |
||
| 994 | 994 | * @param bool $echo |
| 995 | 995 | * @return string |
| 996 | 996 | */ |
| 997 | - function espresso_venue_excerpt( $VNU_ID = 0, $echo = TRUE ) { |
|
| 998 | - if ( $echo ) { |
|
| 999 | - echo EEH_Venue_View::venue_excerpt( $VNU_ID ); |
|
| 997 | + function espresso_venue_excerpt($VNU_ID = 0, $echo = TRUE) { |
|
| 998 | + if ($echo) { |
|
| 999 | + echo EEH_Venue_View::venue_excerpt($VNU_ID); |
|
| 1000 | 1000 | return ''; |
| 1001 | 1001 | } |
| 1002 | - return EEH_Venue_View::venue_excerpt( $VNU_ID ); |
|
| 1002 | + return EEH_Venue_View::venue_excerpt($VNU_ID); |
|
| 1003 | 1003 | } |
| 1004 | 1004 | } |
| 1005 | 1005 | |
| 1006 | 1006 | |
| 1007 | 1007 | |
| 1008 | -if ( ! function_exists( 'espresso_venue_categories' )) { |
|
| 1008 | +if ( ! function_exists('espresso_venue_categories')) { |
|
| 1009 | 1009 | /** |
| 1010 | 1010 | * espresso_venue_categories |
| 1011 | 1011 | * returns the terms associated with a venue |
@@ -1015,17 +1015,17 @@ discard block |
||
| 1015 | 1015 | * @param bool $echo |
| 1016 | 1016 | * @return string |
| 1017 | 1017 | */ |
| 1018 | - function espresso_venue_categories( $VNU_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE ) { |
|
| 1019 | - if ( $echo ) { |
|
| 1020 | - echo EEH_Venue_View::venue_categories( $VNU_ID, $hide_uncategorized ); |
|
| 1018 | + function espresso_venue_categories($VNU_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE) { |
|
| 1019 | + if ($echo) { |
|
| 1020 | + echo EEH_Venue_View::venue_categories($VNU_ID, $hide_uncategorized); |
|
| 1021 | 1021 | return ''; |
| 1022 | 1022 | } |
| 1023 | - return EEH_Venue_View::venue_categories( $VNU_ID, $hide_uncategorized ); |
|
| 1023 | + return EEH_Venue_View::venue_categories($VNU_ID, $hide_uncategorized); |
|
| 1024 | 1024 | } |
| 1025 | 1025 | } |
| 1026 | 1026 | |
| 1027 | 1027 | |
| 1028 | -if ( ! function_exists( 'espresso_venue_address' )) { |
|
| 1028 | +if ( ! function_exists('espresso_venue_address')) { |
|
| 1029 | 1029 | /** |
| 1030 | 1030 | * espresso_venue_address |
| 1031 | 1031 | * returns a formatted block of html for displaying a venue's address |
@@ -1035,17 +1035,17 @@ discard block |
||
| 1035 | 1035 | * @param bool $echo |
| 1036 | 1036 | * @return string |
| 1037 | 1037 | */ |
| 1038 | - function espresso_venue_address( $type = 'multiline', $VNU_ID = 0, $echo = TRUE ) { |
|
| 1039 | - if ( $echo ) { |
|
| 1040 | - echo EEH_Venue_View::venue_address( $type, $VNU_ID ); |
|
| 1038 | + function espresso_venue_address($type = 'multiline', $VNU_ID = 0, $echo = TRUE) { |
|
| 1039 | + if ($echo) { |
|
| 1040 | + echo EEH_Venue_View::venue_address($type, $VNU_ID); |
|
| 1041 | 1041 | return ''; |
| 1042 | 1042 | } |
| 1043 | - return EEH_Venue_View::venue_address( $type, $VNU_ID ); |
|
| 1043 | + return EEH_Venue_View::venue_address($type, $VNU_ID); |
|
| 1044 | 1044 | } |
| 1045 | 1045 | } |
| 1046 | 1046 | |
| 1047 | 1047 | |
| 1048 | -if ( ! function_exists( 'espresso_venue_raw_address' )) { |
|
| 1048 | +if ( ! function_exists('espresso_venue_raw_address')) { |
|
| 1049 | 1049 | /** |
| 1050 | 1050 | * espresso_venue_address |
| 1051 | 1051 | * returns an UN-formatted string containing a venue's address |
@@ -1055,17 +1055,17 @@ discard block |
||
| 1055 | 1055 | * @param bool $echo |
| 1056 | 1056 | * @return string |
| 1057 | 1057 | */ |
| 1058 | - function espresso_venue_raw_address( $type = 'multiline', $VNU_ID = 0, $echo = TRUE ) { |
|
| 1059 | - if ( $echo ) { |
|
| 1060 | - echo EEH_Venue_View::venue_address( $type, $VNU_ID, FALSE, FALSE ); |
|
| 1058 | + function espresso_venue_raw_address($type = 'multiline', $VNU_ID = 0, $echo = TRUE) { |
|
| 1059 | + if ($echo) { |
|
| 1060 | + echo EEH_Venue_View::venue_address($type, $VNU_ID, FALSE, FALSE); |
|
| 1061 | 1061 | return ''; |
| 1062 | 1062 | } |
| 1063 | - return EEH_Venue_View::venue_address( $type, $VNU_ID, FALSE, FALSE ); |
|
| 1063 | + return EEH_Venue_View::venue_address($type, $VNU_ID, FALSE, FALSE); |
|
| 1064 | 1064 | } |
| 1065 | 1065 | } |
| 1066 | 1066 | |
| 1067 | 1067 | |
| 1068 | -if ( ! function_exists( 'espresso_venue_has_address' )) { |
|
| 1068 | +if ( ! function_exists('espresso_venue_has_address')) { |
|
| 1069 | 1069 | /** |
| 1070 | 1070 | * espresso_venue_has_address |
| 1071 | 1071 | * returns TRUE or FALSE if a Venue has address information |
@@ -1073,13 +1073,13 @@ discard block |
||
| 1073 | 1073 | * @param int $VNU_ID |
| 1074 | 1074 | * @return bool |
| 1075 | 1075 | */ |
| 1076 | - function espresso_venue_has_address( $VNU_ID = 0 ) { |
|
| 1077 | - return EEH_Venue_View::venue_has_address( $VNU_ID ); |
|
| 1076 | + function espresso_venue_has_address($VNU_ID = 0) { |
|
| 1077 | + return EEH_Venue_View::venue_has_address($VNU_ID); |
|
| 1078 | 1078 | } |
| 1079 | 1079 | } |
| 1080 | 1080 | |
| 1081 | 1081 | |
| 1082 | -if ( ! function_exists( 'espresso_venue_gmap' )) { |
|
| 1082 | +if ( ! function_exists('espresso_venue_gmap')) { |
|
| 1083 | 1083 | /** |
| 1084 | 1084 | * espresso_venue_gmap |
| 1085 | 1085 | * returns a google map for the venue address |
@@ -1090,17 +1090,17 @@ discard block |
||
| 1090 | 1090 | * @param bool $echo |
| 1091 | 1091 | * @return string |
| 1092 | 1092 | */ |
| 1093 | - function espresso_venue_gmap( $VNU_ID = 0, $map_ID = FALSE, $gmap = array(), $echo = TRUE ) { |
|
| 1094 | - if ( $echo ) { |
|
| 1095 | - echo EEH_Venue_View::venue_gmap( $VNU_ID, $map_ID, $gmap ); |
|
| 1093 | + function espresso_venue_gmap($VNU_ID = 0, $map_ID = FALSE, $gmap = array(), $echo = TRUE) { |
|
| 1094 | + if ($echo) { |
|
| 1095 | + echo EEH_Venue_View::venue_gmap($VNU_ID, $map_ID, $gmap); |
|
| 1096 | 1096 | return ''; |
| 1097 | 1097 | } |
| 1098 | - return EEH_Venue_View::venue_gmap( $VNU_ID, $map_ID, $gmap ); |
|
| 1098 | + return EEH_Venue_View::venue_gmap($VNU_ID, $map_ID, $gmap); |
|
| 1099 | 1099 | } |
| 1100 | 1100 | } |
| 1101 | 1101 | |
| 1102 | 1102 | |
| 1103 | -if ( ! function_exists( 'espresso_venue_phone' )) { |
|
| 1103 | +if ( ! function_exists('espresso_venue_phone')) { |
|
| 1104 | 1104 | /** |
| 1105 | 1105 | * espresso_venue_phone |
| 1106 | 1106 | * |
@@ -1108,18 +1108,18 @@ discard block |
||
| 1108 | 1108 | * @param bool $echo |
| 1109 | 1109 | * @return string |
| 1110 | 1110 | */ |
| 1111 | - function espresso_venue_phone( $VNU_ID = 0, $echo = TRUE ) { |
|
| 1112 | - if ( $echo ) { |
|
| 1113 | - echo EEH_Venue_View::venue_phone( $VNU_ID ); |
|
| 1111 | + function espresso_venue_phone($VNU_ID = 0, $echo = TRUE) { |
|
| 1112 | + if ($echo) { |
|
| 1113 | + echo EEH_Venue_View::venue_phone($VNU_ID); |
|
| 1114 | 1114 | return ''; |
| 1115 | 1115 | } |
| 1116 | - return EEH_Venue_View::venue_phone( $VNU_ID ); |
|
| 1116 | + return EEH_Venue_View::venue_phone($VNU_ID); |
|
| 1117 | 1117 | } |
| 1118 | 1118 | } |
| 1119 | 1119 | |
| 1120 | 1120 | |
| 1121 | 1121 | |
| 1122 | -if ( ! function_exists( 'espresso_venue_website' )) { |
|
| 1122 | +if ( ! function_exists('espresso_venue_website')) { |
|
| 1123 | 1123 | /** |
| 1124 | 1124 | * espresso_venue_website |
| 1125 | 1125 | * |
@@ -1127,18 +1127,18 @@ discard block |
||
| 1127 | 1127 | * @param bool $echo |
| 1128 | 1128 | * @return string |
| 1129 | 1129 | */ |
| 1130 | - function espresso_venue_website( $VNU_ID = 0, $echo = TRUE ) { |
|
| 1131 | - if ( $echo ) { |
|
| 1132 | - echo EEH_Venue_View::venue_website_link( $VNU_ID ); |
|
| 1130 | + function espresso_venue_website($VNU_ID = 0, $echo = TRUE) { |
|
| 1131 | + if ($echo) { |
|
| 1132 | + echo EEH_Venue_View::venue_website_link($VNU_ID); |
|
| 1133 | 1133 | return ''; |
| 1134 | 1134 | } |
| 1135 | - return EEH_Venue_View::venue_website_link( $VNU_ID ); |
|
| 1135 | + return EEH_Venue_View::venue_website_link($VNU_ID); |
|
| 1136 | 1136 | } |
| 1137 | 1137 | } |
| 1138 | 1138 | |
| 1139 | 1139 | |
| 1140 | 1140 | |
| 1141 | -if ( ! function_exists( 'espresso_edit_venue_link' )) { |
|
| 1141 | +if ( ! function_exists('espresso_edit_venue_link')) { |
|
| 1142 | 1142 | /** |
| 1143 | 1143 | * espresso_edit_venue_link |
| 1144 | 1144 | * |
@@ -1146,12 +1146,12 @@ discard block |
||
| 1146 | 1146 | * @param bool $echo |
| 1147 | 1147 | * @return string |
| 1148 | 1148 | */ |
| 1149 | - function espresso_edit_venue_link( $VNU_ID = 0, $echo = TRUE ) { |
|
| 1150 | - if($echo){ |
|
| 1151 | - echo EEH_Venue_View::edit_venue_link( $VNU_ID ); |
|
| 1149 | + function espresso_edit_venue_link($VNU_ID = 0, $echo = TRUE) { |
|
| 1150 | + if ($echo) { |
|
| 1151 | + echo EEH_Venue_View::edit_venue_link($VNU_ID); |
|
| 1152 | 1152 | return ''; |
| 1153 | 1153 | } |
| 1154 | - return EEH_Venue_View::edit_venue_link( $VNU_ID ); |
|
| 1154 | + return EEH_Venue_View::edit_venue_link($VNU_ID); |
|
| 1155 | 1155 | } |
| 1156 | 1156 | } |
| 1157 | 1157 | |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 3 | - exit('NO direct script access allowed'); |
|
| 3 | + exit('NO direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -25,1090 +25,1090 @@ discard block |
||
| 25 | 25 | { |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @Constructor |
|
| 30 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 31 | - * @access public |
|
| 32 | - */ |
|
| 33 | - public function __construct($routing = true) |
|
| 34 | - { |
|
| 35 | - define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form' . DS); |
|
| 36 | - define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets' . DS); |
|
| 37 | - define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/'); |
|
| 38 | - define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates' . DS); |
|
| 39 | - define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/'); |
|
| 40 | - parent::__construct($routing); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - protected function _extend_page_config() |
|
| 45 | - { |
|
| 46 | - $this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN; |
|
| 47 | - $qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0; |
|
| 48 | - $qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID']) ? $this->_req_data['QSG_ID'] : 0; |
|
| 49 | - |
|
| 50 | - $new_page_routes = array( |
|
| 51 | - 'question_groups' => array( |
|
| 52 | - 'func' => '_question_groups_overview_list_table', |
|
| 53 | - 'capability' => 'ee_read_question_groups', |
|
| 54 | - ), |
|
| 55 | - 'add_question' => array( |
|
| 56 | - 'func' => '_edit_question', |
|
| 57 | - 'capability' => 'ee_edit_questions', |
|
| 58 | - ), |
|
| 59 | - 'insert_question' => array( |
|
| 60 | - 'func' => '_insert_or_update_question', |
|
| 61 | - 'args' => array('new_question' => true), |
|
| 62 | - 'capability' => 'ee_edit_questions', |
|
| 63 | - 'noheader' => true, |
|
| 64 | - ), |
|
| 65 | - 'duplicate_question' => array( |
|
| 66 | - 'func' => '_duplicate_question', |
|
| 67 | - 'capability' => 'ee_edit_questions', |
|
| 68 | - 'noheader' => true, |
|
| 69 | - ), |
|
| 70 | - 'trash_question' => array( |
|
| 71 | - 'func' => '_trash_question', |
|
| 72 | - 'capability' => 'ee_delete_question', |
|
| 73 | - 'obj_id' => $qst_id, |
|
| 74 | - 'noheader' => true, |
|
| 75 | - ), |
|
| 76 | - |
|
| 77 | - 'restore_question' => array( |
|
| 78 | - 'func' => '_trash_or_restore_questions', |
|
| 79 | - 'capability' => 'ee_delete_question', |
|
| 80 | - 'obj_id' => $qst_id, |
|
| 81 | - 'args' => array('trash' => false), |
|
| 82 | - 'noheader' => true, |
|
| 83 | - ), |
|
| 84 | - |
|
| 85 | - 'delete_question' => array( |
|
| 86 | - 'func' => '_delete_question', |
|
| 87 | - 'capability' => 'ee_delete_question', |
|
| 88 | - 'obj_id' => $qst_id, |
|
| 89 | - 'noheader' => true, |
|
| 90 | - ), |
|
| 91 | - |
|
| 92 | - 'trash_questions' => array( |
|
| 93 | - 'func' => '_trash_or_restore_questions', |
|
| 94 | - 'capability' => 'ee_delete_questions', |
|
| 95 | - 'args' => array('trash' => true), |
|
| 96 | - 'noheader' => true, |
|
| 97 | - ), |
|
| 98 | - |
|
| 99 | - 'restore_questions' => array( |
|
| 100 | - 'func' => '_trash_or_restore_questions', |
|
| 101 | - 'capability' => 'ee_delete_questions', |
|
| 102 | - 'args' => array('trash' => false), |
|
| 103 | - 'noheader' => true, |
|
| 104 | - ), |
|
| 105 | - |
|
| 106 | - 'delete_questions' => array( |
|
| 107 | - 'func' => '_delete_questions', |
|
| 108 | - 'args' => array(), |
|
| 109 | - 'capability' => 'ee_delete_questions', |
|
| 110 | - 'noheader' => true, |
|
| 111 | - ), |
|
| 112 | - |
|
| 113 | - 'add_question_group' => array( |
|
| 114 | - 'func' => '_edit_question_group', |
|
| 115 | - 'capability' => 'ee_edit_question_groups', |
|
| 116 | - ), |
|
| 117 | - |
|
| 118 | - 'edit_question_group' => array( |
|
| 119 | - 'func' => '_edit_question_group', |
|
| 120 | - 'capability' => 'ee_edit_question_group', |
|
| 121 | - 'obj_id' => $qsg_id, |
|
| 122 | - 'args' => array('edit'), |
|
| 123 | - ), |
|
| 124 | - |
|
| 125 | - 'delete_question_groups' => array( |
|
| 126 | - 'func' => '_delete_question_groups', |
|
| 127 | - 'capability' => 'ee_delete_question_groups', |
|
| 128 | - 'noheader' => true, |
|
| 129 | - ), |
|
| 130 | - |
|
| 131 | - 'delete_question_group' => array( |
|
| 132 | - 'func' => '_delete_question_groups', |
|
| 133 | - 'capability' => 'ee_delete_question_group', |
|
| 134 | - 'obj_id' => $qsg_id, |
|
| 135 | - 'noheader' => true, |
|
| 136 | - ), |
|
| 137 | - |
|
| 138 | - 'trash_question_group' => array( |
|
| 139 | - 'func' => '_trash_or_restore_question_groups', |
|
| 140 | - 'args' => array('trash' => true), |
|
| 141 | - 'capability' => 'ee_delete_question_group', |
|
| 142 | - 'obj_id' => $qsg_id, |
|
| 143 | - 'noheader' => true, |
|
| 144 | - ), |
|
| 145 | - |
|
| 146 | - 'restore_question_group' => array( |
|
| 147 | - 'func' => '_trash_or_restore_question_groups', |
|
| 148 | - 'args' => array('trash' => false), |
|
| 149 | - 'capability' => 'ee_delete_question_group', |
|
| 150 | - 'obj_id' => $qsg_id, |
|
| 151 | - 'noheader' => true, |
|
| 152 | - ), |
|
| 153 | - |
|
| 154 | - 'insert_question_group' => array( |
|
| 155 | - 'func' => '_insert_or_update_question_group', |
|
| 156 | - 'args' => array('new_question_group' => true), |
|
| 157 | - 'capability' => 'ee_edit_question_groups', |
|
| 158 | - 'noheader' => true, |
|
| 159 | - ), |
|
| 160 | - |
|
| 161 | - 'update_question_group' => array( |
|
| 162 | - 'func' => '_insert_or_update_question_group', |
|
| 163 | - 'args' => array('new_question_group' => false), |
|
| 164 | - 'capability' => 'ee_edit_question_group', |
|
| 165 | - 'obj_id' => $qsg_id, |
|
| 166 | - 'noheader' => true, |
|
| 167 | - ), |
|
| 168 | - |
|
| 169 | - 'trash_question_groups' => array( |
|
| 170 | - 'func' => '_trash_or_restore_question_groups', |
|
| 171 | - 'args' => array('trash' => true), |
|
| 172 | - 'capability' => 'ee_delete_question_groups', |
|
| 173 | - 'noheader' => array('trash' => false), |
|
| 174 | - ), |
|
| 175 | - |
|
| 176 | - 'restore_question_groups' => array( |
|
| 177 | - 'func' => '_trash_or_restore_question_groups', |
|
| 178 | - 'args' => array('trash' => false), |
|
| 179 | - 'capability' => 'ee_delete_question_groups', |
|
| 180 | - 'noheader' => true, |
|
| 181 | - ), |
|
| 182 | - |
|
| 183 | - |
|
| 184 | - 'espresso_update_question_group_order' => array( |
|
| 185 | - 'func' => 'update_question_group_order', |
|
| 186 | - 'capability' => 'ee_edit_question_groups', |
|
| 187 | - 'noheader' => true, |
|
| 188 | - ), |
|
| 189 | - |
|
| 190 | - 'view_reg_form_settings' => array( |
|
| 191 | - 'func' => '_reg_form_settings', |
|
| 192 | - 'capability' => 'manage_options', |
|
| 193 | - ), |
|
| 194 | - |
|
| 195 | - 'update_reg_form_settings' => array( |
|
| 196 | - 'func' => '_update_reg_form_settings', |
|
| 197 | - 'capability' => 'manage_options', |
|
| 198 | - 'noheader' => true, |
|
| 199 | - ), |
|
| 200 | - ); |
|
| 201 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 202 | - |
|
| 203 | - $new_page_config = array( |
|
| 204 | - |
|
| 205 | - 'question_groups' => array( |
|
| 206 | - 'nav' => array( |
|
| 207 | - 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
| 208 | - 'order' => 20, |
|
| 209 | - ), |
|
| 210 | - 'list_table' => 'Registration_Form_Question_Groups_Admin_List_Table', |
|
| 211 | - 'help_tabs' => array( |
|
| 212 | - 'registration_form_question_groups_help_tab' => array( |
|
| 213 | - 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
| 214 | - 'filename' => 'registration_form_question_groups', |
|
| 215 | - ), |
|
| 216 | - 'registration_form_question_groups_table_column_headings_help_tab' => array( |
|
| 217 | - 'title' => esc_html__('Question Groups Table Column Headings', 'event_espresso'), |
|
| 218 | - 'filename' => 'registration_form_question_groups_table_column_headings', |
|
| 219 | - ), |
|
| 220 | - 'registration_form_question_groups_views_bulk_actions_search_help_tab' => array( |
|
| 221 | - 'title' => esc_html__('Question Groups Views & Bulk Actions & Search', 'event_espresso'), |
|
| 222 | - 'filename' => 'registration_form_question_groups_views_bulk_actions_search', |
|
| 223 | - ), |
|
| 224 | - ), |
|
| 225 | - 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
| 226 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 227 | - 'require_nonce' => false, |
|
| 228 | - 'qtips' => array( |
|
| 229 | - 'EE_Registration_Form_Tips', |
|
| 230 | - ), |
|
| 231 | - ), |
|
| 232 | - |
|
| 233 | - 'add_question' => array( |
|
| 234 | - 'nav' => array( |
|
| 235 | - 'label' => esc_html__('Add Question', 'event_espresso'), |
|
| 236 | - 'order' => 5, |
|
| 237 | - 'persistent' => false, |
|
| 238 | - ), |
|
| 239 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 240 | - 'help_tabs' => array( |
|
| 241 | - 'registration_form_add_question_help_tab' => array( |
|
| 242 | - 'title' => esc_html__('Add Question', 'event_espresso'), |
|
| 243 | - 'filename' => 'registration_form_add_question', |
|
| 244 | - ), |
|
| 245 | - ), |
|
| 246 | - 'help_tour' => array('Registration_Form_Add_Question_Help_Tour'), |
|
| 247 | - 'require_nonce' => false, |
|
| 248 | - ), |
|
| 249 | - |
|
| 250 | - 'add_question_group' => array( |
|
| 251 | - 'nav' => array( |
|
| 252 | - 'label' => esc_html__('Add Question Group', 'event_espresso'), |
|
| 253 | - 'order' => 5, |
|
| 254 | - 'persistent' => false, |
|
| 255 | - ), |
|
| 256 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 257 | - 'help_tabs' => array( |
|
| 258 | - 'registration_form_add_question_group_help_tab' => array( |
|
| 259 | - 'title' => esc_html__('Add Question Group', 'event_espresso'), |
|
| 260 | - 'filename' => 'registration_form_add_question_group', |
|
| 261 | - ), |
|
| 262 | - ), |
|
| 263 | - 'help_tour' => array('Registration_Form_Add_Question_Group_Help_Tour'), |
|
| 264 | - 'require_nonce' => false, |
|
| 265 | - ), |
|
| 266 | - |
|
| 267 | - 'edit_question_group' => array( |
|
| 268 | - 'nav' => array( |
|
| 269 | - 'label' => esc_html__('Edit Question Group', 'event_espresso'), |
|
| 270 | - 'order' => 5, |
|
| 271 | - 'persistent' => false, |
|
| 272 | - 'url' => isset($this->_req_data['question_group_id']) ? add_query_arg(array('question_group_id' => $this->_req_data['question_group_id']), |
|
| 273 | - $this->_current_page_view_url) : $this->_admin_base_url, |
|
| 274 | - ), |
|
| 275 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 276 | - 'help_tabs' => array( |
|
| 277 | - 'registration_form_edit_question_group_help_tab' => array( |
|
| 278 | - 'title' => esc_html__('Edit Question Group', 'event_espresso'), |
|
| 279 | - 'filename' => 'registration_form_edit_question_group', |
|
| 280 | - ), |
|
| 281 | - ), |
|
| 282 | - 'help_tour' => array('Registration_Form_Edit_Question_Group_Help_Tour'), |
|
| 283 | - 'require_nonce' => false, |
|
| 284 | - ), |
|
| 285 | - |
|
| 286 | - 'view_reg_form_settings' => array( |
|
| 287 | - 'nav' => array( |
|
| 288 | - 'label' => esc_html__('Reg Form Settings', 'event_espresso'), |
|
| 289 | - 'order' => 40, |
|
| 290 | - ), |
|
| 291 | - 'labels' => array( |
|
| 292 | - 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 293 | - ), |
|
| 294 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 295 | - 'help_tabs' => array( |
|
| 296 | - 'registration_form_reg_form_settings_help_tab' => array( |
|
| 297 | - 'title' => esc_html__('Registration Form Settings', 'event_espresso'), |
|
| 298 | - 'filename' => 'registration_form_reg_form_settings', |
|
| 299 | - ), |
|
| 300 | - ), |
|
| 301 | - 'help_tour' => array('Registration_Form_Settings_Help_Tour'), |
|
| 302 | - 'require_nonce' => false, |
|
| 303 | - ), |
|
| 304 | - |
|
| 305 | - ); |
|
| 306 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 307 | - |
|
| 308 | - //change the list table we're going to use so it's the NEW list table! |
|
| 309 | - $this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table'; |
|
| 310 | - |
|
| 311 | - |
|
| 312 | - //additional labels |
|
| 313 | - $new_labels = array( |
|
| 314 | - 'add_question' => esc_html__('Add New Question', 'event_espresso'), |
|
| 315 | - 'delete_question' => esc_html__('Delete Question', 'event_espresso'), |
|
| 316 | - 'add_question_group' => esc_html__('Add New Question Group', 'event_espresso'), |
|
| 317 | - 'edit_question_group' => esc_html__('Edit Question Group', 'event_espresso'), |
|
| 318 | - 'delete_question_group' => esc_html__('Delete Question Group', 'event_espresso'), |
|
| 319 | - ); |
|
| 320 | - $this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels); |
|
| 321 | - |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - |
|
| 325 | - protected function _ajax_hooks() |
|
| 326 | - { |
|
| 327 | - add_action('wp_ajax_espresso_update_question_group_order', array($this, 'update_question_group_order')); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - |
|
| 331 | - public function load_scripts_styles_question_groups() |
|
| 332 | - { |
|
| 333 | - wp_enqueue_script('espresso_ajax_table_sorting'); |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - |
|
| 337 | - public function load_scripts_styles_add_question_group() |
|
| 338 | - { |
|
| 339 | - $this->load_scripts_styles_forms(); |
|
| 340 | - $this->load_sortable_question_script(); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - public function load_scripts_styles_edit_question_group() |
|
| 344 | - { |
|
| 345 | - $this->load_scripts_styles_forms(); |
|
| 346 | - $this->load_sortable_question_script(); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * registers and enqueues script for questions |
|
| 352 | - * |
|
| 353 | - * @return void |
|
| 354 | - */ |
|
| 355 | - public function load_sortable_question_script() |
|
| 356 | - { |
|
| 357 | - wp_register_script('ee-question-sortable', REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js', |
|
| 358 | - array('jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true); |
|
| 359 | - wp_enqueue_script('ee-question-sortable'); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - |
|
| 363 | - protected function _set_list_table_views_default() |
|
| 364 | - { |
|
| 365 | - $this->_views = array( |
|
| 366 | - 'all' => array( |
|
| 367 | - 'slug' => 'all', |
|
| 368 | - 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
| 369 | - 'count' => 0, |
|
| 370 | - 'bulk_action' => array( |
|
| 371 | - 'trash_questions' => esc_html__('Trash', 'event_espresso'), |
|
| 372 | - ), |
|
| 373 | - ), |
|
| 374 | - ); |
|
| 375 | - |
|
| 376 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions', |
|
| 377 | - 'espresso_registration_form_trash_questions') |
|
| 378 | - ) { |
|
| 379 | - $this->_views['trash'] = array( |
|
| 380 | - 'slug' => 'trash', |
|
| 381 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 382 | - 'count' => 0, |
|
| 383 | - 'bulk_action' => array( |
|
| 384 | - 'delete_questions' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 385 | - 'restore_questions' => esc_html__('Restore', 'event_espresso'), |
|
| 386 | - ), |
|
| 387 | - ); |
|
| 388 | - } |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - |
|
| 392 | - protected function _set_list_table_views_question_groups() |
|
| 393 | - { |
|
| 394 | - $this->_views = array( |
|
| 395 | - 'all' => array( |
|
| 396 | - 'slug' => 'all', |
|
| 397 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 398 | - 'count' => 0, |
|
| 399 | - 'bulk_action' => array( |
|
| 400 | - 'trash_question_groups' => esc_html__('Trash', 'event_espresso'), |
|
| 401 | - ), |
|
| 402 | - ), |
|
| 403 | - ); |
|
| 404 | - |
|
| 405 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_question_groups', |
|
| 406 | - 'espresso_registration_form_trash_question_groups') |
|
| 407 | - ) { |
|
| 408 | - $this->_views['trash'] = array( |
|
| 409 | - 'slug' => 'trash', |
|
| 410 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 411 | - 'count' => 0, |
|
| 412 | - 'bulk_action' => array( |
|
| 413 | - 'delete_question_groups' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 414 | - 'restore_question_groups' => esc_html__('Restore', 'event_espresso'), |
|
| 415 | - ), |
|
| 416 | - ); |
|
| 417 | - } |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - |
|
| 421 | - protected function _questions_overview_list_table() |
|
| 422 | - { |
|
| 423 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 424 | - 'add_question', |
|
| 425 | - 'add_question', |
|
| 426 | - array(), |
|
| 427 | - 'add-new-h2' |
|
| 428 | - ); |
|
| 429 | - parent::_questions_overview_list_table(); |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - protected function _question_groups_overview_list_table() |
|
| 434 | - { |
|
| 435 | - $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso'); |
|
| 436 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 437 | - 'add_question_group', |
|
| 438 | - 'add_question_group', |
|
| 439 | - array(), |
|
| 440 | - 'add-new-h2' |
|
| 441 | - ); |
|
| 442 | - $this->display_admin_list_table_page_with_sidebar(); |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - |
|
| 446 | - protected function _delete_question() |
|
| 447 | - { |
|
| 448 | - $success = $this->_delete_items($this->_question_model); |
|
| 449 | - $this->_redirect_after_action( |
|
| 450 | - $success, |
|
| 451 | - $this->_question_model->item_name($success), |
|
| 452 | - 'deleted', |
|
| 453 | - array('action' => 'default', 'status' => 'all') |
|
| 454 | - ); |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - |
|
| 458 | - protected function _delete_questions() |
|
| 459 | - { |
|
| 460 | - $success = $this->_delete_items($this->_question_model); |
|
| 461 | - $this->_redirect_after_action( |
|
| 462 | - $success, |
|
| 463 | - $this->_question_model->item_name($success), |
|
| 464 | - 'deleted permanently', |
|
| 465 | - array('action' => 'default', 'status' => 'trash') |
|
| 466 | - ); |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * Performs the deletion of a single or multiple questions or question groups. |
|
| 472 | - * |
|
| 473 | - * @param EEM_Soft_Delete_Base $model |
|
| 474 | - * @return int number of items deleted permanently |
|
| 475 | - */ |
|
| 476 | - private function _delete_items(EEM_Soft_Delete_Base $model) |
|
| 477 | - { |
|
| 478 | - $success = 0; |
|
| 479 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 480 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 481 | - // if array has more than one element than success message should be plural |
|
| 482 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 483 | - // cycle thru bulk action checkboxes |
|
| 484 | - while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 485 | - if (! $this->_delete_item($ID, $model)) { |
|
| 486 | - $success = 0; |
|
| 487 | - } |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - } elseif (! empty($this->_req_data['QSG_ID'])) { |
|
| 491 | - $success = $this->_delete_item($this->_req_data['QSG_ID'], $model); |
|
| 492 | - |
|
| 493 | - } elseif (! empty($this->_req_data['QST_ID'])) { |
|
| 494 | - $success = $this->_delete_item($this->_req_data['QST_ID'], $model); |
|
| 495 | - } else { |
|
| 496 | - EE_Error::add_error(sprintf(esc_html__("No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.", |
|
| 497 | - "event_espresso")), __FILE__, __FUNCTION__, __LINE__); |
|
| 498 | - } |
|
| 499 | - return $success; |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - /** |
|
| 503 | - * Deletes the specified question (and its associated question options) or question group |
|
| 504 | - * |
|
| 505 | - * @param int $id |
|
| 506 | - * @param EEM_Soft_Delete_Base $model |
|
| 507 | - * @return boolean |
|
| 508 | - */ |
|
| 509 | - protected function _delete_item($id, $model) |
|
| 510 | - { |
|
| 511 | - if ($model instanceof EEM_Question) { |
|
| 512 | - EEM_Question_Option::instance()->delete_permanently(array(array('QST_ID' => absint($id)))); |
|
| 513 | - } |
|
| 514 | - return $model->delete_permanently_by_ID(absint($id)); |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - |
|
| 518 | - /****************************** QUESTION GROUPS ******************************/ |
|
| 519 | - |
|
| 520 | - |
|
| 521 | - protected function _edit_question_group($type = 'add') |
|
| 522 | - { |
|
| 523 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 524 | - $ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID']) ? absint($this->_req_data['QSG_ID']) : false; |
|
| 525 | - |
|
| 526 | - switch ($this->_req_action) { |
|
| 527 | - case 'add_question_group' : |
|
| 528 | - $this->_admin_page_title = esc_html__('Add Question Group', 'event_espresso'); |
|
| 529 | - break; |
|
| 530 | - case 'edit_question_group' : |
|
| 531 | - $this->_admin_page_title = esc_html__('Edit Question Group', 'event_espresso'); |
|
| 532 | - break; |
|
| 533 | - default : |
|
| 534 | - $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
| 535 | - } |
|
| 536 | - // add ID to title if editing |
|
| 537 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
| 538 | - if ($ID) { |
|
| 539 | - /** @var EE_Question_Group $questionGroup */ |
|
| 540 | - $questionGroup = $this->_question_group_model->get_one_by_ID($ID); |
|
| 541 | - $additional_hidden_fields = array('QSG_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
| 542 | - $this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields); |
|
| 543 | - } else { |
|
| 544 | - /** @var EE_Question_Group $questionGroup */ |
|
| 545 | - $questionGroup = EEM_Question_Group::instance()->create_default_object(); |
|
| 546 | - $questionGroup->set_order_to_latest(); |
|
| 547 | - $this->_set_add_edit_form_tags('insert_question_group'); |
|
| 548 | - } |
|
| 549 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 550 | - $this->_template_args['all_questions'] = $questionGroup->questions_in_and_not_in_group(); |
|
| 551 | - $this->_template_args['QSG_ID'] = $ID ? $ID : true; |
|
| 552 | - $this->_template_args['question_group'] = $questionGroup; |
|
| 553 | - |
|
| 554 | - $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url); |
|
| 555 | - $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL); |
|
| 556 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template(REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php', |
|
| 557 | - $this->_template_args, true); |
|
| 558 | - |
|
| 559 | - // the details template wrapper |
|
| 560 | - $this->display_admin_page_with_sidebar(); |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - |
|
| 564 | - protected function _delete_question_groups() |
|
| 565 | - { |
|
| 566 | - $success = $this->_delete_items($this->_question_group_model); |
|
| 567 | - $this->_redirect_after_action($success, $this->_question_group_model->item_name($success), |
|
| 568 | - 'deleted permanently', array('action' => 'question_groups', 'status' => 'trash')); |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * @param bool $new_question_group |
|
| 574 | - */ |
|
| 575 | - protected function _insert_or_update_question_group($new_question_group = true) |
|
| 576 | - { |
|
| 577 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 578 | - $set_column_values = $this->_set_column_values_for($this->_question_group_model); |
|
| 579 | - if ($new_question_group) { |
|
| 580 | - $QSG_ID = $this->_question_group_model->insert($set_column_values); |
|
| 581 | - $success = $QSG_ID ? 1 : 0; |
|
| 582 | - } else { |
|
| 583 | - $QSG_ID = absint($this->_req_data['QSG_ID']); |
|
| 584 | - unset($set_column_values['QSG_ID']); |
|
| 585 | - $success = $this->_question_group_model->update($set_column_values, array(array('QSG_ID' => $QSG_ID))); |
|
| 586 | - } |
|
| 587 | - $phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string(EEM_Attendee::system_question_phone); |
|
| 588 | - // update the existing related questions |
|
| 589 | - // BUT FIRST... delete the phone question from the Question_Group_Question if it is being added to this question group (therefore removed from the existing group) |
|
| 590 | - if (isset($this->_req_data['questions'], $this->_req_data['questions'][$phone_question_id])) { |
|
| 591 | - // delete where QST ID = system phone question ID and Question Group ID is NOT this group |
|
| 592 | - EEM_Question_Group_Question::instance()->delete(array( |
|
| 593 | - array( |
|
| 594 | - 'QST_ID' => $phone_question_id, |
|
| 595 | - 'QSG_ID' => array('!=', $QSG_ID), |
|
| 596 | - ), |
|
| 597 | - )); |
|
| 598 | - } |
|
| 599 | - /** @type EE_Question_Group $question_group */ |
|
| 600 | - $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID); |
|
| 601 | - $questions = $question_group->questions(); |
|
| 602 | - // make sure system phone question is added to list of questions for this group |
|
| 603 | - if (! isset($questions[$phone_question_id])) { |
|
| 604 | - $questions[$phone_question_id] = EEM_Question::instance()->get_one_by_ID($phone_question_id); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - foreach ($questions as $question_ID => $question) { |
|
| 608 | - // first we always check for order. |
|
| 609 | - if (! empty($this->_req_data['question_orders'][$question_ID])) { |
|
| 610 | - //update question order |
|
| 611 | - $question_group->update_question_order($question_ID, $this->_req_data['question_orders'][$question_ID]); |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - // then we always check if adding or removing. |
|
| 615 | - if (isset($this->_req_data['questions'], $this->_req_data['questions'][$question_ID])) { |
|
| 616 | - $question_group->add_question($question_ID); |
|
| 617 | - } else { |
|
| 618 | - // not found, remove it (but only if not a system question for the personal group with the exception of lname system question - we allow removal of it) |
|
| 619 | - if ( |
|
| 620 | - in_array( |
|
| 621 | - $question->system_ID(), |
|
| 622 | - EEM_Question::instance()->required_system_questions_in_system_question_group($question_group->system_group()) |
|
| 623 | - ) |
|
| 624 | - ) { |
|
| 625 | - continue; |
|
| 626 | - } else { |
|
| 627 | - $question_group->remove_question($question_ID); |
|
| 628 | - } |
|
| 629 | - } |
|
| 630 | - } |
|
| 631 | - // save new related questions |
|
| 632 | - if (isset($this->_req_data['questions'])) { |
|
| 633 | - foreach ($this->_req_data['questions'] as $QST_ID) { |
|
| 634 | - $question_group->add_question($QST_ID); |
|
| 635 | - if (isset($this->_req_data['question_orders'][$QST_ID])) { |
|
| 636 | - $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][$QST_ID]); |
|
| 637 | - } |
|
| 638 | - } |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - if ($success !== false) { |
|
| 642 | - $msg = $new_question_group ? sprintf(esc_html__('The %s has been created', 'event_espresso'), |
|
| 643 | - $this->_question_group_model->item_name()) : sprintf(esc_html__('The %s has been updated', |
|
| 644 | - 'event_espresso'), $this->_question_group_model->item_name()); |
|
| 645 | - EE_Error::add_success($msg); |
|
| 646 | - } |
|
| 647 | - $this->_redirect_after_action(false, '', '', array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), |
|
| 648 | - true); |
|
| 649 | - |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - /** |
|
| 653 | - * duplicates a question and all its question options and redirects to the new question. |
|
| 654 | - */ |
|
| 655 | - public function _duplicate_question() |
|
| 656 | - { |
|
| 657 | - $question_ID = (int)$this->_req_data['QST_ID']; |
|
| 658 | - $question = EEM_Question::instance()->get_one_by_ID($question_ID); |
|
| 659 | - if ($question instanceof EE_Question) { |
|
| 660 | - $new_question = $question->duplicate(); |
|
| 661 | - if ($new_question instanceof EE_Question) { |
|
| 662 | - $this->_redirect_after_action(true, esc_html__('Question', 'event_espresso'), |
|
| 663 | - esc_html__('Duplicated', 'event_espresso'), |
|
| 664 | - array('action' => 'edit_question', 'QST_ID' => $new_question->ID()), true); |
|
| 665 | - } else { |
|
| 666 | - global $wpdb; |
|
| 667 | - EE_Error::add_error(sprintf(esc_html__('Could not duplicate question with ID %1$d because: %2$s', |
|
| 668 | - 'event_espresso'), $question_ID, $wpdb->last_error), __FILE__, __FUNCTION__, __LINE__); |
|
| 669 | - $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
| 670 | - } |
|
| 671 | - } else { |
|
| 672 | - EE_Error::add_error(sprintf(esc_html__('Could not duplicate question with ID %d because it didn\'t exist!', |
|
| 673 | - 'event_espresso'), $question_ID), __FILE__, __FUNCTION__, __LINE__); |
|
| 674 | - $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
| 675 | - } |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - |
|
| 679 | - /** |
|
| 680 | - * @param bool $trash |
|
| 681 | - */ |
|
| 682 | - protected function _trash_or_restore_question_groups($trash = true) |
|
| 683 | - { |
|
| 684 | - $this->_trash_or_restore_items($this->_question_group_model, $trash); |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - |
|
| 688 | - /** |
|
| 689 | - *_trash_question |
|
| 690 | - */ |
|
| 691 | - protected function _trash_question() |
|
| 692 | - { |
|
| 693 | - $success = $this->_question_model->delete_by_ID((int)$this->_req_data['QST_ID']); |
|
| 694 | - $query_args = array('action' => 'default', 'status' => 'all'); |
|
| 695 | - $this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args); |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - |
|
| 699 | - /** |
|
| 700 | - * @param bool $trash |
|
| 701 | - */ |
|
| 702 | - protected function _trash_or_restore_questions($trash = true) |
|
| 703 | - { |
|
| 704 | - $this->_trash_or_restore_items($this->_question_model, $trash); |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - |
|
| 708 | - /** |
|
| 709 | - * Internally used to delete or restore items, using the request data. Meant to be |
|
| 710 | - * flexible between question or question groups |
|
| 711 | - * |
|
| 712 | - * @param EEM_Soft_Delete_Base $model |
|
| 713 | - * @param boolean $trash whether to trash or restore |
|
| 714 | - */ |
|
| 715 | - private function _trash_or_restore_items(EEM_Soft_Delete_Base $model, $trash = true) |
|
| 716 | - { |
|
| 717 | - |
|
| 718 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 719 | - |
|
| 720 | - $success = 1; |
|
| 721 | - //Checkboxes |
|
| 722 | - //echo "trash $trash"; |
|
| 723 | - //var_dump($this->_req_data['checkbox']);die; |
|
| 724 | - if (isset($this->_req_data['checkbox'])) { |
|
| 725 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 726 | - // if array has more than one element than success message should be plural |
|
| 727 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 728 | - // cycle thru bulk action checkboxes |
|
| 729 | - while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 730 | - if (! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
| 731 | - $success = 0; |
|
| 732 | - } |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - } else { |
|
| 736 | - // grab single id and delete |
|
| 737 | - $ID = absint($this->_req_data['checkbox']); |
|
| 738 | - if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
| 739 | - $success = 0; |
|
| 740 | - } |
|
| 741 | - } |
|
| 742 | - |
|
| 743 | - } else { |
|
| 744 | - // delete via trash link |
|
| 745 | - // grab single id and delete |
|
| 746 | - $ID = absint($this->_req_data[$model->primary_key_name()]); |
|
| 747 | - if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
| 748 | - $success = 0; |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - |
|
| 754 | - $action = $model instanceof EEM_Question ? 'default' : 'question_groups';//strtolower( $model->item_name(2) ); |
|
| 755 | - //echo "action :$action"; |
|
| 756 | - //$action = 'questions' ? 'default' : $action; |
|
| 757 | - if ($trash) { |
|
| 758 | - $action_desc = 'trashed'; |
|
| 759 | - $status = 'trash'; |
|
| 760 | - } else { |
|
| 761 | - $action_desc = 'restored'; |
|
| 762 | - $status = 'all'; |
|
| 763 | - } |
|
| 764 | - $this->_redirect_after_action($success, $model->item_name($success), $action_desc, |
|
| 765 | - array('action' => $action, 'status' => $status)); |
|
| 766 | - } |
|
| 767 | - |
|
| 768 | - |
|
| 769 | - /** |
|
| 770 | - * @param $per_page |
|
| 771 | - * @param int $current_page |
|
| 772 | - * @param bool|false $count |
|
| 773 | - * @return \EE_Soft_Delete_Base_Class[]|int |
|
| 774 | - */ |
|
| 775 | - public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
| 776 | - { |
|
| 777 | - $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
| 778 | - |
|
| 779 | - if ($count) { |
|
| 780 | - //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
| 781 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 782 | - $results = $this->_question_model->count_deleted($where); |
|
| 783 | - } else { |
|
| 784 | - //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
| 785 | - $results = $this->_question_model->get_all_deleted($query_params); |
|
| 786 | - } |
|
| 787 | - return $results; |
|
| 788 | - } |
|
| 789 | - |
|
| 790 | - |
|
| 791 | - /** |
|
| 792 | - * @param $per_page |
|
| 793 | - * @param int $current_page |
|
| 794 | - * @param bool|false $count |
|
| 795 | - * @return \EE_Soft_Delete_Base_Class[] |
|
| 796 | - */ |
|
| 797 | - public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
| 798 | - { |
|
| 799 | - $questionGroupModel = EEM_Question_Group::instance(); |
|
| 800 | - $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
| 801 | - if ($count) { |
|
| 802 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 803 | - $results = $questionGroupModel->count($where); |
|
| 804 | - } else { |
|
| 805 | - $results = $questionGroupModel->get_all($query_params); |
|
| 806 | - } |
|
| 807 | - return $results; |
|
| 808 | - } |
|
| 809 | - |
|
| 810 | - |
|
| 811 | - /** |
|
| 812 | - * @param $per_page |
|
| 813 | - * @param int $current_page |
|
| 814 | - * @param bool $count |
|
| 815 | - * @return \EE_Soft_Delete_Base_Class[]|int |
|
| 816 | - */ |
|
| 817 | - public function get_trashed_question_groups($per_page, $current_page = 1, $count = false) |
|
| 818 | - { |
|
| 819 | - $questionGroupModel = EEM_Question_Group::instance(); |
|
| 820 | - $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
| 821 | - if ($count) { |
|
| 822 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 823 | - $query_params['limit'] = null; |
|
| 824 | - $results = $questionGroupModel->count_deleted($where); |
|
| 825 | - } else { |
|
| 826 | - $results = $questionGroupModel->get_all_deleted($query_params); |
|
| 827 | - } |
|
| 828 | - return $results; |
|
| 829 | - } |
|
| 830 | - |
|
| 831 | - |
|
| 832 | - /** |
|
| 833 | - * method for performing updates to question order |
|
| 834 | - * |
|
| 835 | - * @return array results array |
|
| 836 | - */ |
|
| 837 | - public function update_question_group_order() |
|
| 838 | - { |
|
| 839 | - |
|
| 840 | - $success = esc_html__('Question group order was updated successfully.', 'event_espresso'); |
|
| 841 | - |
|
| 842 | - // grab our row IDs |
|
| 843 | - $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) |
|
| 844 | - ? explode(',', rtrim($this->_req_data['row_ids'], ',')) |
|
| 845 | - : array(); |
|
| 846 | - |
|
| 847 | - $perpage = ! empty($this->_req_data['perpage']) |
|
| 848 | - ? (int)$this->_req_data['perpage'] |
|
| 849 | - : null; |
|
| 850 | - $curpage = ! empty($this->_req_data['curpage']) |
|
| 851 | - ? (int)$this->_req_data['curpage'] |
|
| 852 | - : null; |
|
| 853 | - |
|
| 854 | - if (! empty($row_ids)) { |
|
| 855 | - //figure out where we start the row_id count at for the current page. |
|
| 856 | - $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage; |
|
| 857 | - |
|
| 858 | - $row_count = count($row_ids); |
|
| 859 | - for ($i = 0; $i < $row_count; $i++) { |
|
| 860 | - //Update the questions when re-ordering |
|
| 861 | - $updated = EEM_Question_Group::instance()->update( |
|
| 862 | - array('QSG_order' => $qsgcount), |
|
| 863 | - array(array('QSG_ID' => $row_ids[$i])) |
|
| 864 | - ); |
|
| 865 | - if ($updated === false) { |
|
| 866 | - $success = false; |
|
| 867 | - } |
|
| 868 | - $qsgcount++; |
|
| 869 | - } |
|
| 870 | - } else { |
|
| 871 | - $success = false; |
|
| 872 | - } |
|
| 873 | - |
|
| 874 | - $errors = ! $success |
|
| 875 | - ? esc_html__('An error occurred. The question group order was not updated.', 'event_espresso') |
|
| 876 | - : false; |
|
| 877 | - |
|
| 878 | - echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors)); |
|
| 879 | - die(); |
|
| 880 | - |
|
| 881 | - } |
|
| 882 | - |
|
| 883 | - |
|
| 884 | - |
|
| 885 | - /*************************************** REGISTRATION SETTINGS ***************************************/ |
|
| 886 | - |
|
| 887 | - |
|
| 888 | - /** |
|
| 889 | - * _reg_form_settings |
|
| 890 | - * |
|
| 891 | - * @throws \EE_Error |
|
| 892 | - */ |
|
| 893 | - protected function _reg_form_settings() |
|
| 894 | - { |
|
| 895 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 896 | - add_action( |
|
| 897 | - 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
| 898 | - array($this, 'email_validation_settings_form'), |
|
| 899 | - 2 |
|
| 900 | - ); |
|
| 901 | - $this->_template_args = (array)apply_filters( |
|
| 902 | - 'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args', |
|
| 903 | - $this->_template_args |
|
| 904 | - ); |
|
| 905 | - $this->_set_add_edit_form_tags('update_reg_form_settings'); |
|
| 906 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 907 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 908 | - REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php', |
|
| 909 | - $this->_template_args, |
|
| 910 | - true |
|
| 911 | - ); |
|
| 912 | - $this->display_admin_page_with_sidebar(); |
|
| 913 | - } |
|
| 914 | - |
|
| 915 | - |
|
| 916 | - /** |
|
| 917 | - * _update_reg_form_settings |
|
| 918 | - */ |
|
| 919 | - protected function _update_reg_form_settings() |
|
| 920 | - { |
|
| 921 | - EE_Registry::instance()->CFG->registration = $this->update_email_validation_settings_form( |
|
| 922 | - EE_Registry::instance()->CFG->registration |
|
| 923 | - ); |
|
| 924 | - EE_Registry::instance()->CFG->registration = apply_filters( |
|
| 925 | - 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
| 926 | - EE_Registry::instance()->CFG->registration |
|
| 927 | - ); |
|
| 928 | - $success = $this->_update_espresso_configuration( |
|
| 929 | - esc_html__('Registration Form Options', 'event_espresso'), |
|
| 930 | - EE_Registry::instance()->CFG, |
|
| 931 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 932 | - ); |
|
| 933 | - $this->_redirect_after_action($success, esc_html__('Registration Form Options', 'event_espresso'), 'updated', |
|
| 934 | - array('action' => 'view_reg_form_settings')); |
|
| 935 | - } |
|
| 936 | - |
|
| 937 | - |
|
| 938 | - /** |
|
| 939 | - * email_validation_settings_form |
|
| 940 | - * |
|
| 941 | - * @access public |
|
| 942 | - * @return void |
|
| 943 | - * @throws \EE_Error |
|
| 944 | - */ |
|
| 945 | - public function email_validation_settings_form() |
|
| 946 | - { |
|
| 947 | - echo $this->_email_validation_settings_form()->get_html(); |
|
| 948 | - } |
|
| 949 | - |
|
| 950 | - |
|
| 951 | - /** |
|
| 952 | - * _email_validation_settings_form |
|
| 953 | - * |
|
| 954 | - * @access protected |
|
| 955 | - * @return EE_Form_Section_Proper |
|
| 956 | - * @throws \EE_Error |
|
| 957 | - */ |
|
| 958 | - protected function _email_validation_settings_form() |
|
| 959 | - { |
|
| 960 | - return new EE_Form_Section_Proper( |
|
| 961 | - array( |
|
| 962 | - 'name' => 'email_validation_settings', |
|
| 963 | - 'html_id' => 'email_validation_settings', |
|
| 964 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 965 | - 'subsections' => array( |
|
| 966 | - 'email_validation_hdr' => new EE_Form_Section_HTML( |
|
| 967 | - EEH_HTML::h2(esc_html__('Email Validation Settings', 'event_espresso')) |
|
| 968 | - ), |
|
| 969 | - 'email_validation_level' => new EE_Select_Input( |
|
| 970 | - array( |
|
| 971 | - 'basic' => esc_html__('Basic', 'event_espresso'), |
|
| 972 | - 'wp_default' => esc_html__('WordPress Default', 'event_espresso'), |
|
| 973 | - 'i18n' => esc_html__('International', 'event_espresso'), |
|
| 974 | - 'i18n_dns' => esc_html__('International + DNS Check', 'event_espresso'), |
|
| 975 | - ), |
|
| 976 | - array( |
|
| 977 | - 'html_label_text' => esc_html__('Email Validation Level', 'event_espresso') |
|
| 978 | - . EEH_Template::get_help_tab_link('email_validation_info'), |
|
| 979 | - 'html_help_text' => esc_html__('These levels range from basic validation ( ie: [email protected] ) to more advanced checks against international email addresses (ie: üñîçøðé@example.com ) with additional MX and A record checks to confirm the domain actually exists. More information on on each level can be found within the help section.', |
|
| 980 | - 'event_espresso'), |
|
| 981 | - 'default' => isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
| 982 | - ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 983 | - : 'wp_default', |
|
| 984 | - 'required' => false, |
|
| 985 | - ) |
|
| 986 | - ), |
|
| 987 | - ), |
|
| 988 | - ) |
|
| 989 | - ); |
|
| 990 | - } |
|
| 991 | - |
|
| 992 | - |
|
| 993 | - /** |
|
| 994 | - * update_email_validation_settings_form |
|
| 995 | - * |
|
| 996 | - * @access public |
|
| 997 | - * @param \EE_Registration_Config $EE_Registration_Config |
|
| 998 | - * @return \EE_Registration_Config |
|
| 999 | - */ |
|
| 1000 | - public function update_email_validation_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
| 1001 | - { |
|
| 1002 | - $prev_email_validation_level = $EE_Registration_Config->email_validation_level; |
|
| 1003 | - try { |
|
| 1004 | - $email_validation_settings_form = $this->_email_validation_settings_form(); |
|
| 1005 | - // if not displaying a form, then check for form submission |
|
| 1006 | - if ($email_validation_settings_form->was_submitted()) { |
|
| 1007 | - // capture form data |
|
| 1008 | - $email_validation_settings_form->receive_form_submission(); |
|
| 1009 | - // validate form data |
|
| 1010 | - if ($email_validation_settings_form->is_valid()) { |
|
| 1011 | - // grab validated data from form |
|
| 1012 | - $valid_data = $email_validation_settings_form->valid_data(); |
|
| 1013 | - if (isset($valid_data['email_validation_level'])) { |
|
| 1014 | - $email_validation_level = $valid_data['email_validation_level']; |
|
| 1015 | - // now if they want to use international email addresses |
|
| 1016 | - if ($email_validation_level === 'i18n' || $email_validation_level === 'i18n_dns') { |
|
| 1017 | - // in case we need to reset their email validation level, |
|
| 1018 | - // make sure that the previous value wasn't already set to one of the i18n options. |
|
| 1019 | - if ($prev_email_validation_level === 'i18n' || $prev_email_validation_level === 'i18n_dns') { |
|
| 1020 | - // if so, then reset it back to "basic" since that is the only other option that, |
|
| 1021 | - // despite offering poor validation, supports i18n email addresses |
|
| 1022 | - $prev_email_validation_level = 'basic'; |
|
| 1023 | - } |
|
| 1024 | - // confirm our i18n email validation will work on the server |
|
| 1025 | - if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { |
|
| 1026 | - // or reset email validation level to previous value |
|
| 1027 | - $email_validation_level = $prev_email_validation_level; |
|
| 1028 | - } |
|
| 1029 | - } |
|
| 1030 | - $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
| 1031 | - } else { |
|
| 1032 | - EE_Error::add_error( |
|
| 1033 | - esc_html__( |
|
| 1034 | - 'Invalid or missing Email Validation settings. Please refresh the form and try again.', |
|
| 1035 | - 'event_espresso' |
|
| 1036 | - ), |
|
| 1037 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1038 | - ); |
|
| 1039 | - } |
|
| 1040 | - } else { |
|
| 1041 | - if ($email_validation_settings_form->submission_error_message() !== '') { |
|
| 1042 | - EE_Error::add_error( |
|
| 1043 | - $email_validation_settings_form->submission_error_message(), |
|
| 1044 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1045 | - ); |
|
| 1046 | - } |
|
| 1047 | - } |
|
| 1048 | - } |
|
| 1049 | - } catch (EE_Error $e) { |
|
| 1050 | - $e->get_error(); |
|
| 1051 | - } |
|
| 1052 | - return $EE_Registration_Config; |
|
| 1053 | - } |
|
| 1054 | - |
|
| 1055 | - |
|
| 1056 | - /** |
|
| 1057 | - * confirms that the server's PHP version has the PCRE module enabled, |
|
| 1058 | - * and that the PCRE version works with our i18n email validation |
|
| 1059 | - * |
|
| 1060 | - * @param \EE_Registration_Config $EE_Registration_Config |
|
| 1061 | - * @param string $email_validation_level |
|
| 1062 | - * @return bool |
|
| 1063 | - */ |
|
| 1064 | - private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level) |
|
| 1065 | - { |
|
| 1066 | - // first check that PCRE is enabled |
|
| 1067 | - if (! defined('PREG_BAD_UTF8_ERROR')) { |
|
| 1068 | - EE_Error::add_error( |
|
| 1069 | - sprintf( |
|
| 1070 | - esc_html__( |
|
| 1071 | - 'We\'re sorry, but it appears that your server\'s version of PHP was not compiled with PCRE unicode support.%1$sPlease contact your hosting company and ask them whether the PCRE compiled with your version of PHP on your server can be been built with the "--enable-unicode-properties" and "--enable-utf8" configuration switches to enable more complex regex expressions.%1$sIf they are unable, or unwilling to do so, then your server will not support international email addresses using UTF-8 unicode characters. This means you will either have to lower your email validation level to "Basic" or "WordPress Default", or switch to a hosting company that has/can enable PCRE unicode support on the server.', |
|
| 1072 | - 'event_espresso' |
|
| 1073 | - ), |
|
| 1074 | - '<br />' |
|
| 1075 | - ), |
|
| 1076 | - __FILE__, |
|
| 1077 | - __FUNCTION__, |
|
| 1078 | - __LINE__ |
|
| 1079 | - ); |
|
| 1080 | - return false; |
|
| 1081 | - } else { |
|
| 1082 | - // PCRE support is enabled, but let's still |
|
| 1083 | - // perform a test to see if the server will support it. |
|
| 1084 | - // but first, save the updated validation level to the config, |
|
| 1085 | - // so that the validation strategy picks it up. |
|
| 1086 | - // this will get bumped back down if it doesn't work |
|
| 1087 | - $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
| 1088 | - try { |
|
| 1089 | - $email_validator = new EE_Email_Validation_Strategy(); |
|
| 1090 | - $i18n_email_address = apply_filters( |
|
| 1091 | - 'FHEE__Extend_Registration_Form_Admin_Page__update_email_validation_settings_form__i18n_email_address', |
|
| 1092 | - 'jägerjü[email protected]' |
|
| 1093 | - ); |
|
| 1094 | - $email_validator->validate($i18n_email_address); |
|
| 1095 | - } catch (Exception $e) { |
|
| 1096 | - EE_Error::add_error( |
|
| 1097 | - sprintf( |
|
| 1098 | - esc_html__( |
|
| 1099 | - 'We\'re sorry, but it appears that your server\'s configuration will not support the "International" or "International + DNS Check" email validation levels.%1$sTo correct this issue, please consult with your hosting company regarding your server\'s PCRE settings.%1$sIt is recommended that your PHP version be configured to use PCRE 8.10 or newer.%1$sMore information regarding PCRE versions and installation can be found here: %2$s', |
|
| 1100 | - 'event_espresso' |
|
| 1101 | - ), |
|
| 1102 | - '<br />', |
|
| 1103 | - '<a href="http://php.net/manual/en/pcre.installation.php" target="_blank">http://php.net/manual/en/pcre.installation.php</a>' |
|
| 1104 | - ), |
|
| 1105 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1106 | - ); |
|
| 1107 | - return false; |
|
| 1108 | - } |
|
| 1109 | - } |
|
| 1110 | - return true; |
|
| 1111 | - } |
|
| 28 | + /** |
|
| 29 | + * @Constructor |
|
| 30 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 31 | + * @access public |
|
| 32 | + */ |
|
| 33 | + public function __construct($routing = true) |
|
| 34 | + { |
|
| 35 | + define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form' . DS); |
|
| 36 | + define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets' . DS); |
|
| 37 | + define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/'); |
|
| 38 | + define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates' . DS); |
|
| 39 | + define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/'); |
|
| 40 | + parent::__construct($routing); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + protected function _extend_page_config() |
|
| 45 | + { |
|
| 46 | + $this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN; |
|
| 47 | + $qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0; |
|
| 48 | + $qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID']) ? $this->_req_data['QSG_ID'] : 0; |
|
| 49 | + |
|
| 50 | + $new_page_routes = array( |
|
| 51 | + 'question_groups' => array( |
|
| 52 | + 'func' => '_question_groups_overview_list_table', |
|
| 53 | + 'capability' => 'ee_read_question_groups', |
|
| 54 | + ), |
|
| 55 | + 'add_question' => array( |
|
| 56 | + 'func' => '_edit_question', |
|
| 57 | + 'capability' => 'ee_edit_questions', |
|
| 58 | + ), |
|
| 59 | + 'insert_question' => array( |
|
| 60 | + 'func' => '_insert_or_update_question', |
|
| 61 | + 'args' => array('new_question' => true), |
|
| 62 | + 'capability' => 'ee_edit_questions', |
|
| 63 | + 'noheader' => true, |
|
| 64 | + ), |
|
| 65 | + 'duplicate_question' => array( |
|
| 66 | + 'func' => '_duplicate_question', |
|
| 67 | + 'capability' => 'ee_edit_questions', |
|
| 68 | + 'noheader' => true, |
|
| 69 | + ), |
|
| 70 | + 'trash_question' => array( |
|
| 71 | + 'func' => '_trash_question', |
|
| 72 | + 'capability' => 'ee_delete_question', |
|
| 73 | + 'obj_id' => $qst_id, |
|
| 74 | + 'noheader' => true, |
|
| 75 | + ), |
|
| 76 | + |
|
| 77 | + 'restore_question' => array( |
|
| 78 | + 'func' => '_trash_or_restore_questions', |
|
| 79 | + 'capability' => 'ee_delete_question', |
|
| 80 | + 'obj_id' => $qst_id, |
|
| 81 | + 'args' => array('trash' => false), |
|
| 82 | + 'noheader' => true, |
|
| 83 | + ), |
|
| 84 | + |
|
| 85 | + 'delete_question' => array( |
|
| 86 | + 'func' => '_delete_question', |
|
| 87 | + 'capability' => 'ee_delete_question', |
|
| 88 | + 'obj_id' => $qst_id, |
|
| 89 | + 'noheader' => true, |
|
| 90 | + ), |
|
| 91 | + |
|
| 92 | + 'trash_questions' => array( |
|
| 93 | + 'func' => '_trash_or_restore_questions', |
|
| 94 | + 'capability' => 'ee_delete_questions', |
|
| 95 | + 'args' => array('trash' => true), |
|
| 96 | + 'noheader' => true, |
|
| 97 | + ), |
|
| 98 | + |
|
| 99 | + 'restore_questions' => array( |
|
| 100 | + 'func' => '_trash_or_restore_questions', |
|
| 101 | + 'capability' => 'ee_delete_questions', |
|
| 102 | + 'args' => array('trash' => false), |
|
| 103 | + 'noheader' => true, |
|
| 104 | + ), |
|
| 105 | + |
|
| 106 | + 'delete_questions' => array( |
|
| 107 | + 'func' => '_delete_questions', |
|
| 108 | + 'args' => array(), |
|
| 109 | + 'capability' => 'ee_delete_questions', |
|
| 110 | + 'noheader' => true, |
|
| 111 | + ), |
|
| 112 | + |
|
| 113 | + 'add_question_group' => array( |
|
| 114 | + 'func' => '_edit_question_group', |
|
| 115 | + 'capability' => 'ee_edit_question_groups', |
|
| 116 | + ), |
|
| 117 | + |
|
| 118 | + 'edit_question_group' => array( |
|
| 119 | + 'func' => '_edit_question_group', |
|
| 120 | + 'capability' => 'ee_edit_question_group', |
|
| 121 | + 'obj_id' => $qsg_id, |
|
| 122 | + 'args' => array('edit'), |
|
| 123 | + ), |
|
| 124 | + |
|
| 125 | + 'delete_question_groups' => array( |
|
| 126 | + 'func' => '_delete_question_groups', |
|
| 127 | + 'capability' => 'ee_delete_question_groups', |
|
| 128 | + 'noheader' => true, |
|
| 129 | + ), |
|
| 130 | + |
|
| 131 | + 'delete_question_group' => array( |
|
| 132 | + 'func' => '_delete_question_groups', |
|
| 133 | + 'capability' => 'ee_delete_question_group', |
|
| 134 | + 'obj_id' => $qsg_id, |
|
| 135 | + 'noheader' => true, |
|
| 136 | + ), |
|
| 137 | + |
|
| 138 | + 'trash_question_group' => array( |
|
| 139 | + 'func' => '_trash_or_restore_question_groups', |
|
| 140 | + 'args' => array('trash' => true), |
|
| 141 | + 'capability' => 'ee_delete_question_group', |
|
| 142 | + 'obj_id' => $qsg_id, |
|
| 143 | + 'noheader' => true, |
|
| 144 | + ), |
|
| 145 | + |
|
| 146 | + 'restore_question_group' => array( |
|
| 147 | + 'func' => '_trash_or_restore_question_groups', |
|
| 148 | + 'args' => array('trash' => false), |
|
| 149 | + 'capability' => 'ee_delete_question_group', |
|
| 150 | + 'obj_id' => $qsg_id, |
|
| 151 | + 'noheader' => true, |
|
| 152 | + ), |
|
| 153 | + |
|
| 154 | + 'insert_question_group' => array( |
|
| 155 | + 'func' => '_insert_or_update_question_group', |
|
| 156 | + 'args' => array('new_question_group' => true), |
|
| 157 | + 'capability' => 'ee_edit_question_groups', |
|
| 158 | + 'noheader' => true, |
|
| 159 | + ), |
|
| 160 | + |
|
| 161 | + 'update_question_group' => array( |
|
| 162 | + 'func' => '_insert_or_update_question_group', |
|
| 163 | + 'args' => array('new_question_group' => false), |
|
| 164 | + 'capability' => 'ee_edit_question_group', |
|
| 165 | + 'obj_id' => $qsg_id, |
|
| 166 | + 'noheader' => true, |
|
| 167 | + ), |
|
| 168 | + |
|
| 169 | + 'trash_question_groups' => array( |
|
| 170 | + 'func' => '_trash_or_restore_question_groups', |
|
| 171 | + 'args' => array('trash' => true), |
|
| 172 | + 'capability' => 'ee_delete_question_groups', |
|
| 173 | + 'noheader' => array('trash' => false), |
|
| 174 | + ), |
|
| 175 | + |
|
| 176 | + 'restore_question_groups' => array( |
|
| 177 | + 'func' => '_trash_or_restore_question_groups', |
|
| 178 | + 'args' => array('trash' => false), |
|
| 179 | + 'capability' => 'ee_delete_question_groups', |
|
| 180 | + 'noheader' => true, |
|
| 181 | + ), |
|
| 182 | + |
|
| 183 | + |
|
| 184 | + 'espresso_update_question_group_order' => array( |
|
| 185 | + 'func' => 'update_question_group_order', |
|
| 186 | + 'capability' => 'ee_edit_question_groups', |
|
| 187 | + 'noheader' => true, |
|
| 188 | + ), |
|
| 189 | + |
|
| 190 | + 'view_reg_form_settings' => array( |
|
| 191 | + 'func' => '_reg_form_settings', |
|
| 192 | + 'capability' => 'manage_options', |
|
| 193 | + ), |
|
| 194 | + |
|
| 195 | + 'update_reg_form_settings' => array( |
|
| 196 | + 'func' => '_update_reg_form_settings', |
|
| 197 | + 'capability' => 'manage_options', |
|
| 198 | + 'noheader' => true, |
|
| 199 | + ), |
|
| 200 | + ); |
|
| 201 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 202 | + |
|
| 203 | + $new_page_config = array( |
|
| 204 | + |
|
| 205 | + 'question_groups' => array( |
|
| 206 | + 'nav' => array( |
|
| 207 | + 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
| 208 | + 'order' => 20, |
|
| 209 | + ), |
|
| 210 | + 'list_table' => 'Registration_Form_Question_Groups_Admin_List_Table', |
|
| 211 | + 'help_tabs' => array( |
|
| 212 | + 'registration_form_question_groups_help_tab' => array( |
|
| 213 | + 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
| 214 | + 'filename' => 'registration_form_question_groups', |
|
| 215 | + ), |
|
| 216 | + 'registration_form_question_groups_table_column_headings_help_tab' => array( |
|
| 217 | + 'title' => esc_html__('Question Groups Table Column Headings', 'event_espresso'), |
|
| 218 | + 'filename' => 'registration_form_question_groups_table_column_headings', |
|
| 219 | + ), |
|
| 220 | + 'registration_form_question_groups_views_bulk_actions_search_help_tab' => array( |
|
| 221 | + 'title' => esc_html__('Question Groups Views & Bulk Actions & Search', 'event_espresso'), |
|
| 222 | + 'filename' => 'registration_form_question_groups_views_bulk_actions_search', |
|
| 223 | + ), |
|
| 224 | + ), |
|
| 225 | + 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
| 226 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 227 | + 'require_nonce' => false, |
|
| 228 | + 'qtips' => array( |
|
| 229 | + 'EE_Registration_Form_Tips', |
|
| 230 | + ), |
|
| 231 | + ), |
|
| 232 | + |
|
| 233 | + 'add_question' => array( |
|
| 234 | + 'nav' => array( |
|
| 235 | + 'label' => esc_html__('Add Question', 'event_espresso'), |
|
| 236 | + 'order' => 5, |
|
| 237 | + 'persistent' => false, |
|
| 238 | + ), |
|
| 239 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 240 | + 'help_tabs' => array( |
|
| 241 | + 'registration_form_add_question_help_tab' => array( |
|
| 242 | + 'title' => esc_html__('Add Question', 'event_espresso'), |
|
| 243 | + 'filename' => 'registration_form_add_question', |
|
| 244 | + ), |
|
| 245 | + ), |
|
| 246 | + 'help_tour' => array('Registration_Form_Add_Question_Help_Tour'), |
|
| 247 | + 'require_nonce' => false, |
|
| 248 | + ), |
|
| 249 | + |
|
| 250 | + 'add_question_group' => array( |
|
| 251 | + 'nav' => array( |
|
| 252 | + 'label' => esc_html__('Add Question Group', 'event_espresso'), |
|
| 253 | + 'order' => 5, |
|
| 254 | + 'persistent' => false, |
|
| 255 | + ), |
|
| 256 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 257 | + 'help_tabs' => array( |
|
| 258 | + 'registration_form_add_question_group_help_tab' => array( |
|
| 259 | + 'title' => esc_html__('Add Question Group', 'event_espresso'), |
|
| 260 | + 'filename' => 'registration_form_add_question_group', |
|
| 261 | + ), |
|
| 262 | + ), |
|
| 263 | + 'help_tour' => array('Registration_Form_Add_Question_Group_Help_Tour'), |
|
| 264 | + 'require_nonce' => false, |
|
| 265 | + ), |
|
| 266 | + |
|
| 267 | + 'edit_question_group' => array( |
|
| 268 | + 'nav' => array( |
|
| 269 | + 'label' => esc_html__('Edit Question Group', 'event_espresso'), |
|
| 270 | + 'order' => 5, |
|
| 271 | + 'persistent' => false, |
|
| 272 | + 'url' => isset($this->_req_data['question_group_id']) ? add_query_arg(array('question_group_id' => $this->_req_data['question_group_id']), |
|
| 273 | + $this->_current_page_view_url) : $this->_admin_base_url, |
|
| 274 | + ), |
|
| 275 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 276 | + 'help_tabs' => array( |
|
| 277 | + 'registration_form_edit_question_group_help_tab' => array( |
|
| 278 | + 'title' => esc_html__('Edit Question Group', 'event_espresso'), |
|
| 279 | + 'filename' => 'registration_form_edit_question_group', |
|
| 280 | + ), |
|
| 281 | + ), |
|
| 282 | + 'help_tour' => array('Registration_Form_Edit_Question_Group_Help_Tour'), |
|
| 283 | + 'require_nonce' => false, |
|
| 284 | + ), |
|
| 285 | + |
|
| 286 | + 'view_reg_form_settings' => array( |
|
| 287 | + 'nav' => array( |
|
| 288 | + 'label' => esc_html__('Reg Form Settings', 'event_espresso'), |
|
| 289 | + 'order' => 40, |
|
| 290 | + ), |
|
| 291 | + 'labels' => array( |
|
| 292 | + 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 293 | + ), |
|
| 294 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 295 | + 'help_tabs' => array( |
|
| 296 | + 'registration_form_reg_form_settings_help_tab' => array( |
|
| 297 | + 'title' => esc_html__('Registration Form Settings', 'event_espresso'), |
|
| 298 | + 'filename' => 'registration_form_reg_form_settings', |
|
| 299 | + ), |
|
| 300 | + ), |
|
| 301 | + 'help_tour' => array('Registration_Form_Settings_Help_Tour'), |
|
| 302 | + 'require_nonce' => false, |
|
| 303 | + ), |
|
| 304 | + |
|
| 305 | + ); |
|
| 306 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 307 | + |
|
| 308 | + //change the list table we're going to use so it's the NEW list table! |
|
| 309 | + $this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table'; |
|
| 310 | + |
|
| 311 | + |
|
| 312 | + //additional labels |
|
| 313 | + $new_labels = array( |
|
| 314 | + 'add_question' => esc_html__('Add New Question', 'event_espresso'), |
|
| 315 | + 'delete_question' => esc_html__('Delete Question', 'event_espresso'), |
|
| 316 | + 'add_question_group' => esc_html__('Add New Question Group', 'event_espresso'), |
|
| 317 | + 'edit_question_group' => esc_html__('Edit Question Group', 'event_espresso'), |
|
| 318 | + 'delete_question_group' => esc_html__('Delete Question Group', 'event_espresso'), |
|
| 319 | + ); |
|
| 320 | + $this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels); |
|
| 321 | + |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + |
|
| 325 | + protected function _ajax_hooks() |
|
| 326 | + { |
|
| 327 | + add_action('wp_ajax_espresso_update_question_group_order', array($this, 'update_question_group_order')); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + |
|
| 331 | + public function load_scripts_styles_question_groups() |
|
| 332 | + { |
|
| 333 | + wp_enqueue_script('espresso_ajax_table_sorting'); |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + |
|
| 337 | + public function load_scripts_styles_add_question_group() |
|
| 338 | + { |
|
| 339 | + $this->load_scripts_styles_forms(); |
|
| 340 | + $this->load_sortable_question_script(); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + public function load_scripts_styles_edit_question_group() |
|
| 344 | + { |
|
| 345 | + $this->load_scripts_styles_forms(); |
|
| 346 | + $this->load_sortable_question_script(); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * registers and enqueues script for questions |
|
| 352 | + * |
|
| 353 | + * @return void |
|
| 354 | + */ |
|
| 355 | + public function load_sortable_question_script() |
|
| 356 | + { |
|
| 357 | + wp_register_script('ee-question-sortable', REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js', |
|
| 358 | + array('jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true); |
|
| 359 | + wp_enqueue_script('ee-question-sortable'); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + |
|
| 363 | + protected function _set_list_table_views_default() |
|
| 364 | + { |
|
| 365 | + $this->_views = array( |
|
| 366 | + 'all' => array( |
|
| 367 | + 'slug' => 'all', |
|
| 368 | + 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
| 369 | + 'count' => 0, |
|
| 370 | + 'bulk_action' => array( |
|
| 371 | + 'trash_questions' => esc_html__('Trash', 'event_espresso'), |
|
| 372 | + ), |
|
| 373 | + ), |
|
| 374 | + ); |
|
| 375 | + |
|
| 376 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions', |
|
| 377 | + 'espresso_registration_form_trash_questions') |
|
| 378 | + ) { |
|
| 379 | + $this->_views['trash'] = array( |
|
| 380 | + 'slug' => 'trash', |
|
| 381 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 382 | + 'count' => 0, |
|
| 383 | + 'bulk_action' => array( |
|
| 384 | + 'delete_questions' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 385 | + 'restore_questions' => esc_html__('Restore', 'event_espresso'), |
|
| 386 | + ), |
|
| 387 | + ); |
|
| 388 | + } |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + |
|
| 392 | + protected function _set_list_table_views_question_groups() |
|
| 393 | + { |
|
| 394 | + $this->_views = array( |
|
| 395 | + 'all' => array( |
|
| 396 | + 'slug' => 'all', |
|
| 397 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 398 | + 'count' => 0, |
|
| 399 | + 'bulk_action' => array( |
|
| 400 | + 'trash_question_groups' => esc_html__('Trash', 'event_espresso'), |
|
| 401 | + ), |
|
| 402 | + ), |
|
| 403 | + ); |
|
| 404 | + |
|
| 405 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_question_groups', |
|
| 406 | + 'espresso_registration_form_trash_question_groups') |
|
| 407 | + ) { |
|
| 408 | + $this->_views['trash'] = array( |
|
| 409 | + 'slug' => 'trash', |
|
| 410 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 411 | + 'count' => 0, |
|
| 412 | + 'bulk_action' => array( |
|
| 413 | + 'delete_question_groups' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 414 | + 'restore_question_groups' => esc_html__('Restore', 'event_espresso'), |
|
| 415 | + ), |
|
| 416 | + ); |
|
| 417 | + } |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + |
|
| 421 | + protected function _questions_overview_list_table() |
|
| 422 | + { |
|
| 423 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 424 | + 'add_question', |
|
| 425 | + 'add_question', |
|
| 426 | + array(), |
|
| 427 | + 'add-new-h2' |
|
| 428 | + ); |
|
| 429 | + parent::_questions_overview_list_table(); |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + protected function _question_groups_overview_list_table() |
|
| 434 | + { |
|
| 435 | + $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso'); |
|
| 436 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 437 | + 'add_question_group', |
|
| 438 | + 'add_question_group', |
|
| 439 | + array(), |
|
| 440 | + 'add-new-h2' |
|
| 441 | + ); |
|
| 442 | + $this->display_admin_list_table_page_with_sidebar(); |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + |
|
| 446 | + protected function _delete_question() |
|
| 447 | + { |
|
| 448 | + $success = $this->_delete_items($this->_question_model); |
|
| 449 | + $this->_redirect_after_action( |
|
| 450 | + $success, |
|
| 451 | + $this->_question_model->item_name($success), |
|
| 452 | + 'deleted', |
|
| 453 | + array('action' => 'default', 'status' => 'all') |
|
| 454 | + ); |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + |
|
| 458 | + protected function _delete_questions() |
|
| 459 | + { |
|
| 460 | + $success = $this->_delete_items($this->_question_model); |
|
| 461 | + $this->_redirect_after_action( |
|
| 462 | + $success, |
|
| 463 | + $this->_question_model->item_name($success), |
|
| 464 | + 'deleted permanently', |
|
| 465 | + array('action' => 'default', 'status' => 'trash') |
|
| 466 | + ); |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * Performs the deletion of a single or multiple questions or question groups. |
|
| 472 | + * |
|
| 473 | + * @param EEM_Soft_Delete_Base $model |
|
| 474 | + * @return int number of items deleted permanently |
|
| 475 | + */ |
|
| 476 | + private function _delete_items(EEM_Soft_Delete_Base $model) |
|
| 477 | + { |
|
| 478 | + $success = 0; |
|
| 479 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 480 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 481 | + // if array has more than one element than success message should be plural |
|
| 482 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 483 | + // cycle thru bulk action checkboxes |
|
| 484 | + while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 485 | + if (! $this->_delete_item($ID, $model)) { |
|
| 486 | + $success = 0; |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + } elseif (! empty($this->_req_data['QSG_ID'])) { |
|
| 491 | + $success = $this->_delete_item($this->_req_data['QSG_ID'], $model); |
|
| 492 | + |
|
| 493 | + } elseif (! empty($this->_req_data['QST_ID'])) { |
|
| 494 | + $success = $this->_delete_item($this->_req_data['QST_ID'], $model); |
|
| 495 | + } else { |
|
| 496 | + EE_Error::add_error(sprintf(esc_html__("No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.", |
|
| 497 | + "event_espresso")), __FILE__, __FUNCTION__, __LINE__); |
|
| 498 | + } |
|
| 499 | + return $success; |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + /** |
|
| 503 | + * Deletes the specified question (and its associated question options) or question group |
|
| 504 | + * |
|
| 505 | + * @param int $id |
|
| 506 | + * @param EEM_Soft_Delete_Base $model |
|
| 507 | + * @return boolean |
|
| 508 | + */ |
|
| 509 | + protected function _delete_item($id, $model) |
|
| 510 | + { |
|
| 511 | + if ($model instanceof EEM_Question) { |
|
| 512 | + EEM_Question_Option::instance()->delete_permanently(array(array('QST_ID' => absint($id)))); |
|
| 513 | + } |
|
| 514 | + return $model->delete_permanently_by_ID(absint($id)); |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + |
|
| 518 | + /****************************** QUESTION GROUPS ******************************/ |
|
| 519 | + |
|
| 520 | + |
|
| 521 | + protected function _edit_question_group($type = 'add') |
|
| 522 | + { |
|
| 523 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 524 | + $ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID']) ? absint($this->_req_data['QSG_ID']) : false; |
|
| 525 | + |
|
| 526 | + switch ($this->_req_action) { |
|
| 527 | + case 'add_question_group' : |
|
| 528 | + $this->_admin_page_title = esc_html__('Add Question Group', 'event_espresso'); |
|
| 529 | + break; |
|
| 530 | + case 'edit_question_group' : |
|
| 531 | + $this->_admin_page_title = esc_html__('Edit Question Group', 'event_espresso'); |
|
| 532 | + break; |
|
| 533 | + default : |
|
| 534 | + $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
| 535 | + } |
|
| 536 | + // add ID to title if editing |
|
| 537 | + $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
| 538 | + if ($ID) { |
|
| 539 | + /** @var EE_Question_Group $questionGroup */ |
|
| 540 | + $questionGroup = $this->_question_group_model->get_one_by_ID($ID); |
|
| 541 | + $additional_hidden_fields = array('QSG_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
| 542 | + $this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields); |
|
| 543 | + } else { |
|
| 544 | + /** @var EE_Question_Group $questionGroup */ |
|
| 545 | + $questionGroup = EEM_Question_Group::instance()->create_default_object(); |
|
| 546 | + $questionGroup->set_order_to_latest(); |
|
| 547 | + $this->_set_add_edit_form_tags('insert_question_group'); |
|
| 548 | + } |
|
| 549 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 550 | + $this->_template_args['all_questions'] = $questionGroup->questions_in_and_not_in_group(); |
|
| 551 | + $this->_template_args['QSG_ID'] = $ID ? $ID : true; |
|
| 552 | + $this->_template_args['question_group'] = $questionGroup; |
|
| 553 | + |
|
| 554 | + $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url); |
|
| 555 | + $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL); |
|
| 556 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template(REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php', |
|
| 557 | + $this->_template_args, true); |
|
| 558 | + |
|
| 559 | + // the details template wrapper |
|
| 560 | + $this->display_admin_page_with_sidebar(); |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + |
|
| 564 | + protected function _delete_question_groups() |
|
| 565 | + { |
|
| 566 | + $success = $this->_delete_items($this->_question_group_model); |
|
| 567 | + $this->_redirect_after_action($success, $this->_question_group_model->item_name($success), |
|
| 568 | + 'deleted permanently', array('action' => 'question_groups', 'status' => 'trash')); |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * @param bool $new_question_group |
|
| 574 | + */ |
|
| 575 | + protected function _insert_or_update_question_group($new_question_group = true) |
|
| 576 | + { |
|
| 577 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 578 | + $set_column_values = $this->_set_column_values_for($this->_question_group_model); |
|
| 579 | + if ($new_question_group) { |
|
| 580 | + $QSG_ID = $this->_question_group_model->insert($set_column_values); |
|
| 581 | + $success = $QSG_ID ? 1 : 0; |
|
| 582 | + } else { |
|
| 583 | + $QSG_ID = absint($this->_req_data['QSG_ID']); |
|
| 584 | + unset($set_column_values['QSG_ID']); |
|
| 585 | + $success = $this->_question_group_model->update($set_column_values, array(array('QSG_ID' => $QSG_ID))); |
|
| 586 | + } |
|
| 587 | + $phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string(EEM_Attendee::system_question_phone); |
|
| 588 | + // update the existing related questions |
|
| 589 | + // BUT FIRST... delete the phone question from the Question_Group_Question if it is being added to this question group (therefore removed from the existing group) |
|
| 590 | + if (isset($this->_req_data['questions'], $this->_req_data['questions'][$phone_question_id])) { |
|
| 591 | + // delete where QST ID = system phone question ID and Question Group ID is NOT this group |
|
| 592 | + EEM_Question_Group_Question::instance()->delete(array( |
|
| 593 | + array( |
|
| 594 | + 'QST_ID' => $phone_question_id, |
|
| 595 | + 'QSG_ID' => array('!=', $QSG_ID), |
|
| 596 | + ), |
|
| 597 | + )); |
|
| 598 | + } |
|
| 599 | + /** @type EE_Question_Group $question_group */ |
|
| 600 | + $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID); |
|
| 601 | + $questions = $question_group->questions(); |
|
| 602 | + // make sure system phone question is added to list of questions for this group |
|
| 603 | + if (! isset($questions[$phone_question_id])) { |
|
| 604 | + $questions[$phone_question_id] = EEM_Question::instance()->get_one_by_ID($phone_question_id); |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + foreach ($questions as $question_ID => $question) { |
|
| 608 | + // first we always check for order. |
|
| 609 | + if (! empty($this->_req_data['question_orders'][$question_ID])) { |
|
| 610 | + //update question order |
|
| 611 | + $question_group->update_question_order($question_ID, $this->_req_data['question_orders'][$question_ID]); |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + // then we always check if adding or removing. |
|
| 615 | + if (isset($this->_req_data['questions'], $this->_req_data['questions'][$question_ID])) { |
|
| 616 | + $question_group->add_question($question_ID); |
|
| 617 | + } else { |
|
| 618 | + // not found, remove it (but only if not a system question for the personal group with the exception of lname system question - we allow removal of it) |
|
| 619 | + if ( |
|
| 620 | + in_array( |
|
| 621 | + $question->system_ID(), |
|
| 622 | + EEM_Question::instance()->required_system_questions_in_system_question_group($question_group->system_group()) |
|
| 623 | + ) |
|
| 624 | + ) { |
|
| 625 | + continue; |
|
| 626 | + } else { |
|
| 627 | + $question_group->remove_question($question_ID); |
|
| 628 | + } |
|
| 629 | + } |
|
| 630 | + } |
|
| 631 | + // save new related questions |
|
| 632 | + if (isset($this->_req_data['questions'])) { |
|
| 633 | + foreach ($this->_req_data['questions'] as $QST_ID) { |
|
| 634 | + $question_group->add_question($QST_ID); |
|
| 635 | + if (isset($this->_req_data['question_orders'][$QST_ID])) { |
|
| 636 | + $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][$QST_ID]); |
|
| 637 | + } |
|
| 638 | + } |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + if ($success !== false) { |
|
| 642 | + $msg = $new_question_group ? sprintf(esc_html__('The %s has been created', 'event_espresso'), |
|
| 643 | + $this->_question_group_model->item_name()) : sprintf(esc_html__('The %s has been updated', |
|
| 644 | + 'event_espresso'), $this->_question_group_model->item_name()); |
|
| 645 | + EE_Error::add_success($msg); |
|
| 646 | + } |
|
| 647 | + $this->_redirect_after_action(false, '', '', array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), |
|
| 648 | + true); |
|
| 649 | + |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + /** |
|
| 653 | + * duplicates a question and all its question options and redirects to the new question. |
|
| 654 | + */ |
|
| 655 | + public function _duplicate_question() |
|
| 656 | + { |
|
| 657 | + $question_ID = (int)$this->_req_data['QST_ID']; |
|
| 658 | + $question = EEM_Question::instance()->get_one_by_ID($question_ID); |
|
| 659 | + if ($question instanceof EE_Question) { |
|
| 660 | + $new_question = $question->duplicate(); |
|
| 661 | + if ($new_question instanceof EE_Question) { |
|
| 662 | + $this->_redirect_after_action(true, esc_html__('Question', 'event_espresso'), |
|
| 663 | + esc_html__('Duplicated', 'event_espresso'), |
|
| 664 | + array('action' => 'edit_question', 'QST_ID' => $new_question->ID()), true); |
|
| 665 | + } else { |
|
| 666 | + global $wpdb; |
|
| 667 | + EE_Error::add_error(sprintf(esc_html__('Could not duplicate question with ID %1$d because: %2$s', |
|
| 668 | + 'event_espresso'), $question_ID, $wpdb->last_error), __FILE__, __FUNCTION__, __LINE__); |
|
| 669 | + $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
| 670 | + } |
|
| 671 | + } else { |
|
| 672 | + EE_Error::add_error(sprintf(esc_html__('Could not duplicate question with ID %d because it didn\'t exist!', |
|
| 673 | + 'event_espresso'), $question_ID), __FILE__, __FUNCTION__, __LINE__); |
|
| 674 | + $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
| 675 | + } |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + |
|
| 679 | + /** |
|
| 680 | + * @param bool $trash |
|
| 681 | + */ |
|
| 682 | + protected function _trash_or_restore_question_groups($trash = true) |
|
| 683 | + { |
|
| 684 | + $this->_trash_or_restore_items($this->_question_group_model, $trash); |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + |
|
| 688 | + /** |
|
| 689 | + *_trash_question |
|
| 690 | + */ |
|
| 691 | + protected function _trash_question() |
|
| 692 | + { |
|
| 693 | + $success = $this->_question_model->delete_by_ID((int)$this->_req_data['QST_ID']); |
|
| 694 | + $query_args = array('action' => 'default', 'status' => 'all'); |
|
| 695 | + $this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args); |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + |
|
| 699 | + /** |
|
| 700 | + * @param bool $trash |
|
| 701 | + */ |
|
| 702 | + protected function _trash_or_restore_questions($trash = true) |
|
| 703 | + { |
|
| 704 | + $this->_trash_or_restore_items($this->_question_model, $trash); |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + |
|
| 708 | + /** |
|
| 709 | + * Internally used to delete or restore items, using the request data. Meant to be |
|
| 710 | + * flexible between question or question groups |
|
| 711 | + * |
|
| 712 | + * @param EEM_Soft_Delete_Base $model |
|
| 713 | + * @param boolean $trash whether to trash or restore |
|
| 714 | + */ |
|
| 715 | + private function _trash_or_restore_items(EEM_Soft_Delete_Base $model, $trash = true) |
|
| 716 | + { |
|
| 717 | + |
|
| 718 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 719 | + |
|
| 720 | + $success = 1; |
|
| 721 | + //Checkboxes |
|
| 722 | + //echo "trash $trash"; |
|
| 723 | + //var_dump($this->_req_data['checkbox']);die; |
|
| 724 | + if (isset($this->_req_data['checkbox'])) { |
|
| 725 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 726 | + // if array has more than one element than success message should be plural |
|
| 727 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 728 | + // cycle thru bulk action checkboxes |
|
| 729 | + while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 730 | + if (! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
| 731 | + $success = 0; |
|
| 732 | + } |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + } else { |
|
| 736 | + // grab single id and delete |
|
| 737 | + $ID = absint($this->_req_data['checkbox']); |
|
| 738 | + if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
| 739 | + $success = 0; |
|
| 740 | + } |
|
| 741 | + } |
|
| 742 | + |
|
| 743 | + } else { |
|
| 744 | + // delete via trash link |
|
| 745 | + // grab single id and delete |
|
| 746 | + $ID = absint($this->_req_data[$model->primary_key_name()]); |
|
| 747 | + if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
| 748 | + $success = 0; |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + |
|
| 754 | + $action = $model instanceof EEM_Question ? 'default' : 'question_groups';//strtolower( $model->item_name(2) ); |
|
| 755 | + //echo "action :$action"; |
|
| 756 | + //$action = 'questions' ? 'default' : $action; |
|
| 757 | + if ($trash) { |
|
| 758 | + $action_desc = 'trashed'; |
|
| 759 | + $status = 'trash'; |
|
| 760 | + } else { |
|
| 761 | + $action_desc = 'restored'; |
|
| 762 | + $status = 'all'; |
|
| 763 | + } |
|
| 764 | + $this->_redirect_after_action($success, $model->item_name($success), $action_desc, |
|
| 765 | + array('action' => $action, 'status' => $status)); |
|
| 766 | + } |
|
| 767 | + |
|
| 768 | + |
|
| 769 | + /** |
|
| 770 | + * @param $per_page |
|
| 771 | + * @param int $current_page |
|
| 772 | + * @param bool|false $count |
|
| 773 | + * @return \EE_Soft_Delete_Base_Class[]|int |
|
| 774 | + */ |
|
| 775 | + public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
| 776 | + { |
|
| 777 | + $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
| 778 | + |
|
| 779 | + if ($count) { |
|
| 780 | + //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
| 781 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 782 | + $results = $this->_question_model->count_deleted($where); |
|
| 783 | + } else { |
|
| 784 | + //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
| 785 | + $results = $this->_question_model->get_all_deleted($query_params); |
|
| 786 | + } |
|
| 787 | + return $results; |
|
| 788 | + } |
|
| 789 | + |
|
| 790 | + |
|
| 791 | + /** |
|
| 792 | + * @param $per_page |
|
| 793 | + * @param int $current_page |
|
| 794 | + * @param bool|false $count |
|
| 795 | + * @return \EE_Soft_Delete_Base_Class[] |
|
| 796 | + */ |
|
| 797 | + public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
| 798 | + { |
|
| 799 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
| 800 | + $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
| 801 | + if ($count) { |
|
| 802 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 803 | + $results = $questionGroupModel->count($where); |
|
| 804 | + } else { |
|
| 805 | + $results = $questionGroupModel->get_all($query_params); |
|
| 806 | + } |
|
| 807 | + return $results; |
|
| 808 | + } |
|
| 809 | + |
|
| 810 | + |
|
| 811 | + /** |
|
| 812 | + * @param $per_page |
|
| 813 | + * @param int $current_page |
|
| 814 | + * @param bool $count |
|
| 815 | + * @return \EE_Soft_Delete_Base_Class[]|int |
|
| 816 | + */ |
|
| 817 | + public function get_trashed_question_groups($per_page, $current_page = 1, $count = false) |
|
| 818 | + { |
|
| 819 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
| 820 | + $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
| 821 | + if ($count) { |
|
| 822 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 823 | + $query_params['limit'] = null; |
|
| 824 | + $results = $questionGroupModel->count_deleted($where); |
|
| 825 | + } else { |
|
| 826 | + $results = $questionGroupModel->get_all_deleted($query_params); |
|
| 827 | + } |
|
| 828 | + return $results; |
|
| 829 | + } |
|
| 830 | + |
|
| 831 | + |
|
| 832 | + /** |
|
| 833 | + * method for performing updates to question order |
|
| 834 | + * |
|
| 835 | + * @return array results array |
|
| 836 | + */ |
|
| 837 | + public function update_question_group_order() |
|
| 838 | + { |
|
| 839 | + |
|
| 840 | + $success = esc_html__('Question group order was updated successfully.', 'event_espresso'); |
|
| 841 | + |
|
| 842 | + // grab our row IDs |
|
| 843 | + $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) |
|
| 844 | + ? explode(',', rtrim($this->_req_data['row_ids'], ',')) |
|
| 845 | + : array(); |
|
| 846 | + |
|
| 847 | + $perpage = ! empty($this->_req_data['perpage']) |
|
| 848 | + ? (int)$this->_req_data['perpage'] |
|
| 849 | + : null; |
|
| 850 | + $curpage = ! empty($this->_req_data['curpage']) |
|
| 851 | + ? (int)$this->_req_data['curpage'] |
|
| 852 | + : null; |
|
| 853 | + |
|
| 854 | + if (! empty($row_ids)) { |
|
| 855 | + //figure out where we start the row_id count at for the current page. |
|
| 856 | + $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage; |
|
| 857 | + |
|
| 858 | + $row_count = count($row_ids); |
|
| 859 | + for ($i = 0; $i < $row_count; $i++) { |
|
| 860 | + //Update the questions when re-ordering |
|
| 861 | + $updated = EEM_Question_Group::instance()->update( |
|
| 862 | + array('QSG_order' => $qsgcount), |
|
| 863 | + array(array('QSG_ID' => $row_ids[$i])) |
|
| 864 | + ); |
|
| 865 | + if ($updated === false) { |
|
| 866 | + $success = false; |
|
| 867 | + } |
|
| 868 | + $qsgcount++; |
|
| 869 | + } |
|
| 870 | + } else { |
|
| 871 | + $success = false; |
|
| 872 | + } |
|
| 873 | + |
|
| 874 | + $errors = ! $success |
|
| 875 | + ? esc_html__('An error occurred. The question group order was not updated.', 'event_espresso') |
|
| 876 | + : false; |
|
| 877 | + |
|
| 878 | + echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors)); |
|
| 879 | + die(); |
|
| 880 | + |
|
| 881 | + } |
|
| 882 | + |
|
| 883 | + |
|
| 884 | + |
|
| 885 | + /*************************************** REGISTRATION SETTINGS ***************************************/ |
|
| 886 | + |
|
| 887 | + |
|
| 888 | + /** |
|
| 889 | + * _reg_form_settings |
|
| 890 | + * |
|
| 891 | + * @throws \EE_Error |
|
| 892 | + */ |
|
| 893 | + protected function _reg_form_settings() |
|
| 894 | + { |
|
| 895 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 896 | + add_action( |
|
| 897 | + 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
| 898 | + array($this, 'email_validation_settings_form'), |
|
| 899 | + 2 |
|
| 900 | + ); |
|
| 901 | + $this->_template_args = (array)apply_filters( |
|
| 902 | + 'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args', |
|
| 903 | + $this->_template_args |
|
| 904 | + ); |
|
| 905 | + $this->_set_add_edit_form_tags('update_reg_form_settings'); |
|
| 906 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 907 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 908 | + REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php', |
|
| 909 | + $this->_template_args, |
|
| 910 | + true |
|
| 911 | + ); |
|
| 912 | + $this->display_admin_page_with_sidebar(); |
|
| 913 | + } |
|
| 914 | + |
|
| 915 | + |
|
| 916 | + /** |
|
| 917 | + * _update_reg_form_settings |
|
| 918 | + */ |
|
| 919 | + protected function _update_reg_form_settings() |
|
| 920 | + { |
|
| 921 | + EE_Registry::instance()->CFG->registration = $this->update_email_validation_settings_form( |
|
| 922 | + EE_Registry::instance()->CFG->registration |
|
| 923 | + ); |
|
| 924 | + EE_Registry::instance()->CFG->registration = apply_filters( |
|
| 925 | + 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
| 926 | + EE_Registry::instance()->CFG->registration |
|
| 927 | + ); |
|
| 928 | + $success = $this->_update_espresso_configuration( |
|
| 929 | + esc_html__('Registration Form Options', 'event_espresso'), |
|
| 930 | + EE_Registry::instance()->CFG, |
|
| 931 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 932 | + ); |
|
| 933 | + $this->_redirect_after_action($success, esc_html__('Registration Form Options', 'event_espresso'), 'updated', |
|
| 934 | + array('action' => 'view_reg_form_settings')); |
|
| 935 | + } |
|
| 936 | + |
|
| 937 | + |
|
| 938 | + /** |
|
| 939 | + * email_validation_settings_form |
|
| 940 | + * |
|
| 941 | + * @access public |
|
| 942 | + * @return void |
|
| 943 | + * @throws \EE_Error |
|
| 944 | + */ |
|
| 945 | + public function email_validation_settings_form() |
|
| 946 | + { |
|
| 947 | + echo $this->_email_validation_settings_form()->get_html(); |
|
| 948 | + } |
|
| 949 | + |
|
| 950 | + |
|
| 951 | + /** |
|
| 952 | + * _email_validation_settings_form |
|
| 953 | + * |
|
| 954 | + * @access protected |
|
| 955 | + * @return EE_Form_Section_Proper |
|
| 956 | + * @throws \EE_Error |
|
| 957 | + */ |
|
| 958 | + protected function _email_validation_settings_form() |
|
| 959 | + { |
|
| 960 | + return new EE_Form_Section_Proper( |
|
| 961 | + array( |
|
| 962 | + 'name' => 'email_validation_settings', |
|
| 963 | + 'html_id' => 'email_validation_settings', |
|
| 964 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 965 | + 'subsections' => array( |
|
| 966 | + 'email_validation_hdr' => new EE_Form_Section_HTML( |
|
| 967 | + EEH_HTML::h2(esc_html__('Email Validation Settings', 'event_espresso')) |
|
| 968 | + ), |
|
| 969 | + 'email_validation_level' => new EE_Select_Input( |
|
| 970 | + array( |
|
| 971 | + 'basic' => esc_html__('Basic', 'event_espresso'), |
|
| 972 | + 'wp_default' => esc_html__('WordPress Default', 'event_espresso'), |
|
| 973 | + 'i18n' => esc_html__('International', 'event_espresso'), |
|
| 974 | + 'i18n_dns' => esc_html__('International + DNS Check', 'event_espresso'), |
|
| 975 | + ), |
|
| 976 | + array( |
|
| 977 | + 'html_label_text' => esc_html__('Email Validation Level', 'event_espresso') |
|
| 978 | + . EEH_Template::get_help_tab_link('email_validation_info'), |
|
| 979 | + 'html_help_text' => esc_html__('These levels range from basic validation ( ie: [email protected] ) to more advanced checks against international email addresses (ie: üñîçøðé@example.com ) with additional MX and A record checks to confirm the domain actually exists. More information on on each level can be found within the help section.', |
|
| 980 | + 'event_espresso'), |
|
| 981 | + 'default' => isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
| 982 | + ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 983 | + : 'wp_default', |
|
| 984 | + 'required' => false, |
|
| 985 | + ) |
|
| 986 | + ), |
|
| 987 | + ), |
|
| 988 | + ) |
|
| 989 | + ); |
|
| 990 | + } |
|
| 991 | + |
|
| 992 | + |
|
| 993 | + /** |
|
| 994 | + * update_email_validation_settings_form |
|
| 995 | + * |
|
| 996 | + * @access public |
|
| 997 | + * @param \EE_Registration_Config $EE_Registration_Config |
|
| 998 | + * @return \EE_Registration_Config |
|
| 999 | + */ |
|
| 1000 | + public function update_email_validation_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
| 1001 | + { |
|
| 1002 | + $prev_email_validation_level = $EE_Registration_Config->email_validation_level; |
|
| 1003 | + try { |
|
| 1004 | + $email_validation_settings_form = $this->_email_validation_settings_form(); |
|
| 1005 | + // if not displaying a form, then check for form submission |
|
| 1006 | + if ($email_validation_settings_form->was_submitted()) { |
|
| 1007 | + // capture form data |
|
| 1008 | + $email_validation_settings_form->receive_form_submission(); |
|
| 1009 | + // validate form data |
|
| 1010 | + if ($email_validation_settings_form->is_valid()) { |
|
| 1011 | + // grab validated data from form |
|
| 1012 | + $valid_data = $email_validation_settings_form->valid_data(); |
|
| 1013 | + if (isset($valid_data['email_validation_level'])) { |
|
| 1014 | + $email_validation_level = $valid_data['email_validation_level']; |
|
| 1015 | + // now if they want to use international email addresses |
|
| 1016 | + if ($email_validation_level === 'i18n' || $email_validation_level === 'i18n_dns') { |
|
| 1017 | + // in case we need to reset their email validation level, |
|
| 1018 | + // make sure that the previous value wasn't already set to one of the i18n options. |
|
| 1019 | + if ($prev_email_validation_level === 'i18n' || $prev_email_validation_level === 'i18n_dns') { |
|
| 1020 | + // if so, then reset it back to "basic" since that is the only other option that, |
|
| 1021 | + // despite offering poor validation, supports i18n email addresses |
|
| 1022 | + $prev_email_validation_level = 'basic'; |
|
| 1023 | + } |
|
| 1024 | + // confirm our i18n email validation will work on the server |
|
| 1025 | + if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { |
|
| 1026 | + // or reset email validation level to previous value |
|
| 1027 | + $email_validation_level = $prev_email_validation_level; |
|
| 1028 | + } |
|
| 1029 | + } |
|
| 1030 | + $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
| 1031 | + } else { |
|
| 1032 | + EE_Error::add_error( |
|
| 1033 | + esc_html__( |
|
| 1034 | + 'Invalid or missing Email Validation settings. Please refresh the form and try again.', |
|
| 1035 | + 'event_espresso' |
|
| 1036 | + ), |
|
| 1037 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1038 | + ); |
|
| 1039 | + } |
|
| 1040 | + } else { |
|
| 1041 | + if ($email_validation_settings_form->submission_error_message() !== '') { |
|
| 1042 | + EE_Error::add_error( |
|
| 1043 | + $email_validation_settings_form->submission_error_message(), |
|
| 1044 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1045 | + ); |
|
| 1046 | + } |
|
| 1047 | + } |
|
| 1048 | + } |
|
| 1049 | + } catch (EE_Error $e) { |
|
| 1050 | + $e->get_error(); |
|
| 1051 | + } |
|
| 1052 | + return $EE_Registration_Config; |
|
| 1053 | + } |
|
| 1054 | + |
|
| 1055 | + |
|
| 1056 | + /** |
|
| 1057 | + * confirms that the server's PHP version has the PCRE module enabled, |
|
| 1058 | + * and that the PCRE version works with our i18n email validation |
|
| 1059 | + * |
|
| 1060 | + * @param \EE_Registration_Config $EE_Registration_Config |
|
| 1061 | + * @param string $email_validation_level |
|
| 1062 | + * @return bool |
|
| 1063 | + */ |
|
| 1064 | + private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level) |
|
| 1065 | + { |
|
| 1066 | + // first check that PCRE is enabled |
|
| 1067 | + if (! defined('PREG_BAD_UTF8_ERROR')) { |
|
| 1068 | + EE_Error::add_error( |
|
| 1069 | + sprintf( |
|
| 1070 | + esc_html__( |
|
| 1071 | + 'We\'re sorry, but it appears that your server\'s version of PHP was not compiled with PCRE unicode support.%1$sPlease contact your hosting company and ask them whether the PCRE compiled with your version of PHP on your server can be been built with the "--enable-unicode-properties" and "--enable-utf8" configuration switches to enable more complex regex expressions.%1$sIf they are unable, or unwilling to do so, then your server will not support international email addresses using UTF-8 unicode characters. This means you will either have to lower your email validation level to "Basic" or "WordPress Default", or switch to a hosting company that has/can enable PCRE unicode support on the server.', |
|
| 1072 | + 'event_espresso' |
|
| 1073 | + ), |
|
| 1074 | + '<br />' |
|
| 1075 | + ), |
|
| 1076 | + __FILE__, |
|
| 1077 | + __FUNCTION__, |
|
| 1078 | + __LINE__ |
|
| 1079 | + ); |
|
| 1080 | + return false; |
|
| 1081 | + } else { |
|
| 1082 | + // PCRE support is enabled, but let's still |
|
| 1083 | + // perform a test to see if the server will support it. |
|
| 1084 | + // but first, save the updated validation level to the config, |
|
| 1085 | + // so that the validation strategy picks it up. |
|
| 1086 | + // this will get bumped back down if it doesn't work |
|
| 1087 | + $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
| 1088 | + try { |
|
| 1089 | + $email_validator = new EE_Email_Validation_Strategy(); |
|
| 1090 | + $i18n_email_address = apply_filters( |
|
| 1091 | + 'FHEE__Extend_Registration_Form_Admin_Page__update_email_validation_settings_form__i18n_email_address', |
|
| 1092 | + 'jägerjü[email protected]' |
|
| 1093 | + ); |
|
| 1094 | + $email_validator->validate($i18n_email_address); |
|
| 1095 | + } catch (Exception $e) { |
|
| 1096 | + EE_Error::add_error( |
|
| 1097 | + sprintf( |
|
| 1098 | + esc_html__( |
|
| 1099 | + 'We\'re sorry, but it appears that your server\'s configuration will not support the "International" or "International + DNS Check" email validation levels.%1$sTo correct this issue, please consult with your hosting company regarding your server\'s PCRE settings.%1$sIt is recommended that your PHP version be configured to use PCRE 8.10 or newer.%1$sMore information regarding PCRE versions and installation can be found here: %2$s', |
|
| 1100 | + 'event_espresso' |
|
| 1101 | + ), |
|
| 1102 | + '<br />', |
|
| 1103 | + '<a href="http://php.net/manual/en/pcre.installation.php" target="_blank">http://php.net/manual/en/pcre.installation.php</a>' |
|
| 1104 | + ), |
|
| 1105 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1106 | + ); |
|
| 1107 | + return false; |
|
| 1108 | + } |
|
| 1109 | + } |
|
| 1110 | + return true; |
|
| 1111 | + } |
|
| 1112 | 1112 | |
| 1113 | 1113 | |
| 1114 | 1114 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | 3 | exit('NO direct script access allowed'); |
| 4 | 4 | } |
| 5 | 5 | |
@@ -32,11 +32,11 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | public function __construct($routing = true) |
| 34 | 34 | { |
| 35 | - define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form' . DS); |
|
| 36 | - define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets' . DS); |
|
| 37 | - define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/'); |
|
| 38 | - define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates' . DS); |
|
| 39 | - define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/'); |
|
| 35 | + define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND.'registration_form'.DS); |
|
| 36 | + define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN.'assets'.DS); |
|
| 37 | + define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registration_form/assets/'); |
|
| 38 | + define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN.'templates'.DS); |
|
| 39 | + define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registration_form/templates/'); |
|
| 40 | 40 | parent::__construct($routing); |
| 41 | 41 | } |
| 42 | 42 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | $qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0; |
| 48 | 48 | $qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID']) ? $this->_req_data['QSG_ID'] : 0; |
| 49 | 49 | |
| 50 | - $new_page_routes = array( |
|
| 50 | + $new_page_routes = array( |
|
| 51 | 51 | 'question_groups' => array( |
| 52 | 52 | 'func' => '_question_groups_overview_list_table', |
| 53 | 53 | 'capability' => 'ee_read_question_groups', |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | |
| 311 | 311 | |
| 312 | 312 | //additional labels |
| 313 | - $new_labels = array( |
|
| 313 | + $new_labels = array( |
|
| 314 | 314 | 'add_question' => esc_html__('Add New Question', 'event_espresso'), |
| 315 | 315 | 'delete_question' => esc_html__('Delete Question', 'event_espresso'), |
| 316 | 316 | 'add_question_group' => esc_html__('Add New Question Group', 'event_espresso'), |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | */ |
| 355 | 355 | public function load_sortable_question_script() |
| 356 | 356 | { |
| 357 | - wp_register_script('ee-question-sortable', REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js', |
|
| 357 | + wp_register_script('ee-question-sortable', REGISTRATION_FORM_CAF_ASSETS_URL.'ee_question_order.js', |
|
| 358 | 358 | array('jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true); |
| 359 | 359 | wp_enqueue_script('ee-question-sortable'); |
| 360 | 360 | } |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | |
| 421 | 421 | protected function _questions_overview_list_table() |
| 422 | 422 | { |
| 423 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 423 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
| 424 | 424 | 'add_question', |
| 425 | 425 | 'add_question', |
| 426 | 426 | array(), |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | protected function _question_groups_overview_list_table() |
| 434 | 434 | { |
| 435 | 435 | $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso'); |
| 436 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 436 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
| 437 | 437 | 'add_question_group', |
| 438 | 438 | 'add_question_group', |
| 439 | 439 | array(), |
@@ -477,20 +477,20 @@ discard block |
||
| 477 | 477 | { |
| 478 | 478 | $success = 0; |
| 479 | 479 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 480 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 480 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 481 | 481 | // if array has more than one element than success message should be plural |
| 482 | 482 | $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
| 483 | 483 | // cycle thru bulk action checkboxes |
| 484 | 484 | while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
| 485 | - if (! $this->_delete_item($ID, $model)) { |
|
| 485 | + if ( ! $this->_delete_item($ID, $model)) { |
|
| 486 | 486 | $success = 0; |
| 487 | 487 | } |
| 488 | 488 | } |
| 489 | 489 | |
| 490 | - } elseif (! empty($this->_req_data['QSG_ID'])) { |
|
| 490 | + } elseif ( ! empty($this->_req_data['QSG_ID'])) { |
|
| 491 | 491 | $success = $this->_delete_item($this->_req_data['QSG_ID'], $model); |
| 492 | 492 | |
| 493 | - } elseif (! empty($this->_req_data['QST_ID'])) { |
|
| 493 | + } elseif ( ! empty($this->_req_data['QST_ID'])) { |
|
| 494 | 494 | $success = $this->_delete_item($this->_req_data['QST_ID'], $model); |
| 495 | 495 | } else { |
| 496 | 496 | EE_Error::add_error(sprintf(esc_html__("No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.", |
@@ -534,7 +534,7 @@ discard block |
||
| 534 | 534 | $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
| 535 | 535 | } |
| 536 | 536 | // add ID to title if editing |
| 537 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
| 537 | + $this->_admin_page_title = $ID ? $this->_admin_page_title.' # '.$ID : $this->_admin_page_title; |
|
| 538 | 538 | if ($ID) { |
| 539 | 539 | /** @var EE_Question_Group $questionGroup */ |
| 540 | 540 | $questionGroup = $this->_question_group_model->get_one_by_ID($ID); |
@@ -553,7 +553,7 @@ discard block |
||
| 553 | 553 | |
| 554 | 554 | $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url); |
| 555 | 555 | $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL); |
| 556 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template(REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php', |
|
| 556 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template(REGISTRATION_FORM_CAF_TEMPLATE_PATH.'question_groups_main_meta_box.template.php', |
|
| 557 | 557 | $this->_template_args, true); |
| 558 | 558 | |
| 559 | 559 | // the details template wrapper |
@@ -600,13 +600,13 @@ discard block |
||
| 600 | 600 | $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID); |
| 601 | 601 | $questions = $question_group->questions(); |
| 602 | 602 | // make sure system phone question is added to list of questions for this group |
| 603 | - if (! isset($questions[$phone_question_id])) { |
|
| 603 | + if ( ! isset($questions[$phone_question_id])) { |
|
| 604 | 604 | $questions[$phone_question_id] = EEM_Question::instance()->get_one_by_ID($phone_question_id); |
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | foreach ($questions as $question_ID => $question) { |
| 608 | 608 | // first we always check for order. |
| 609 | - if (! empty($this->_req_data['question_orders'][$question_ID])) { |
|
| 609 | + if ( ! empty($this->_req_data['question_orders'][$question_ID])) { |
|
| 610 | 610 | //update question order |
| 611 | 611 | $question_group->update_question_order($question_ID, $this->_req_data['question_orders'][$question_ID]); |
| 612 | 612 | } |
@@ -654,7 +654,7 @@ discard block |
||
| 654 | 654 | */ |
| 655 | 655 | public function _duplicate_question() |
| 656 | 656 | { |
| 657 | - $question_ID = (int)$this->_req_data['QST_ID']; |
|
| 657 | + $question_ID = (int) $this->_req_data['QST_ID']; |
|
| 658 | 658 | $question = EEM_Question::instance()->get_one_by_ID($question_ID); |
| 659 | 659 | if ($question instanceof EE_Question) { |
| 660 | 660 | $new_question = $question->duplicate(); |
@@ -690,7 +690,7 @@ discard block |
||
| 690 | 690 | */ |
| 691 | 691 | protected function _trash_question() |
| 692 | 692 | { |
| 693 | - $success = $this->_question_model->delete_by_ID((int)$this->_req_data['QST_ID']); |
|
| 693 | + $success = $this->_question_model->delete_by_ID((int) $this->_req_data['QST_ID']); |
|
| 694 | 694 | $query_args = array('action' => 'default', 'status' => 'all'); |
| 695 | 695 | $this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args); |
| 696 | 696 | } |
@@ -722,12 +722,12 @@ discard block |
||
| 722 | 722 | //echo "trash $trash"; |
| 723 | 723 | //var_dump($this->_req_data['checkbox']);die; |
| 724 | 724 | if (isset($this->_req_data['checkbox'])) { |
| 725 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 725 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 726 | 726 | // if array has more than one element than success message should be plural |
| 727 | 727 | $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
| 728 | 728 | // cycle thru bulk action checkboxes |
| 729 | 729 | while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
| 730 | - if (! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
| 730 | + if ( ! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
| 731 | 731 | $success = 0; |
| 732 | 732 | } |
| 733 | 733 | } |
@@ -735,7 +735,7 @@ discard block |
||
| 735 | 735 | } else { |
| 736 | 736 | // grab single id and delete |
| 737 | 737 | $ID = absint($this->_req_data['checkbox']); |
| 738 | - if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
| 738 | + if ( ! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
| 739 | 739 | $success = 0; |
| 740 | 740 | } |
| 741 | 741 | } |
@@ -744,14 +744,14 @@ discard block |
||
| 744 | 744 | // delete via trash link |
| 745 | 745 | // grab single id and delete |
| 746 | 746 | $ID = absint($this->_req_data[$model->primary_key_name()]); |
| 747 | - if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
| 747 | + if ( ! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
| 748 | 748 | $success = 0; |
| 749 | 749 | } |
| 750 | 750 | |
| 751 | 751 | } |
| 752 | 752 | |
| 753 | 753 | |
| 754 | - $action = $model instanceof EEM_Question ? 'default' : 'question_groups';//strtolower( $model->item_name(2) ); |
|
| 754 | + $action = $model instanceof EEM_Question ? 'default' : 'question_groups'; //strtolower( $model->item_name(2) ); |
|
| 755 | 755 | //echo "action :$action"; |
| 756 | 756 | //$action = 'questions' ? 'default' : $action; |
| 757 | 757 | if ($trash) { |
@@ -845,13 +845,13 @@ discard block |
||
| 845 | 845 | : array(); |
| 846 | 846 | |
| 847 | 847 | $perpage = ! empty($this->_req_data['perpage']) |
| 848 | - ? (int)$this->_req_data['perpage'] |
|
| 848 | + ? (int) $this->_req_data['perpage'] |
|
| 849 | 849 | : null; |
| 850 | 850 | $curpage = ! empty($this->_req_data['curpage']) |
| 851 | - ? (int)$this->_req_data['curpage'] |
|
| 851 | + ? (int) $this->_req_data['curpage'] |
|
| 852 | 852 | : null; |
| 853 | 853 | |
| 854 | - if (! empty($row_ids)) { |
|
| 854 | + if ( ! empty($row_ids)) { |
|
| 855 | 855 | //figure out where we start the row_id count at for the current page. |
| 856 | 856 | $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage; |
| 857 | 857 | |
@@ -898,14 +898,14 @@ discard block |
||
| 898 | 898 | array($this, 'email_validation_settings_form'), |
| 899 | 899 | 2 |
| 900 | 900 | ); |
| 901 | - $this->_template_args = (array)apply_filters( |
|
| 901 | + $this->_template_args = (array) apply_filters( |
|
| 902 | 902 | 'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args', |
| 903 | 903 | $this->_template_args |
| 904 | 904 | ); |
| 905 | 905 | $this->_set_add_edit_form_tags('update_reg_form_settings'); |
| 906 | 906 | $this->_set_publish_post_box_vars(null, false, false, null, false); |
| 907 | 907 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 908 | - REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php', |
|
| 908 | + REGISTRATION_FORM_CAF_TEMPLATE_PATH.'reg_form_settings.template.php', |
|
| 909 | 909 | $this->_template_args, |
| 910 | 910 | true |
| 911 | 911 | ); |
@@ -925,7 +925,7 @@ discard block |
||
| 925 | 925 | 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
| 926 | 926 | EE_Registry::instance()->CFG->registration |
| 927 | 927 | ); |
| 928 | - $success = $this->_update_espresso_configuration( |
|
| 928 | + $success = $this->_update_espresso_configuration( |
|
| 929 | 929 | esc_html__('Registration Form Options', 'event_espresso'), |
| 930 | 930 | EE_Registry::instance()->CFG, |
| 931 | 931 | __FILE__, __FUNCTION__, __LINE__ |
@@ -1022,7 +1022,7 @@ discard block |
||
| 1022 | 1022 | $prev_email_validation_level = 'basic'; |
| 1023 | 1023 | } |
| 1024 | 1024 | // confirm our i18n email validation will work on the server |
| 1025 | - if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { |
|
| 1025 | + if ( ! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { |
|
| 1026 | 1026 | // or reset email validation level to previous value |
| 1027 | 1027 | $email_validation_level = $prev_email_validation_level; |
| 1028 | 1028 | } |
@@ -1064,7 +1064,7 @@ discard block |
||
| 1064 | 1064 | private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level) |
| 1065 | 1065 | { |
| 1066 | 1066 | // first check that PCRE is enabled |
| 1067 | - if (! defined('PREG_BAD_UTF8_ERROR')) { |
|
| 1067 | + if ( ! defined('PREG_BAD_UTF8_ERROR')) { |
|
| 1068 | 1068 | EE_Error::add_error( |
| 1069 | 1069 | sprintf( |
| 1070 | 1070 | esc_html__( |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * @param string $value_to_normalize |
| 14 | - * @return int|mixed|string |
|
| 14 | + * @return integer|null |
|
| 15 | 15 | * @throws \EE_Validation_Error |
| 16 | 16 | */ |
| 17 | 17 | public function normalize($value_to_normalize) { |
@@ -20,8 +20,8 @@ discard block |
||
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | if ( is_null( $value_to_normalize ) || $value_to_normalize === '' ) { |
| 23 | - return null; |
|
| 24 | - } |
|
| 23 | + return null; |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | 26 | if( ! is_string( $value_to_normalize )){ |
| 27 | 27 | throw new EE_Validation_Error( sprintf( __( 'The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso' ), print_r( $value_to_normalize, TRUE), gettype( $value_to_normalize ) ) ); |
@@ -56,9 +56,9 @@ discard block |
||
| 56 | 56 | * @return string |
| 57 | 57 | */ |
| 58 | 58 | public function unnormalize( $normalized_value ) { |
| 59 | - if ($normalized_value === null) { |
|
| 60 | - return ''; |
|
| 61 | - }elseif( empty( $normalized_value ) ){ |
|
| 59 | + if ($normalized_value === null) { |
|
| 60 | + return ''; |
|
| 61 | + }elseif( empty( $normalized_value ) ){ |
|
| 62 | 62 | return '0'; |
| 63 | 63 | }else{ |
| 64 | 64 | return "$normalized_value"; |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | * @subpackage |
| 8 | 8 | * @author Mike Nelson |
| 9 | 9 | */ |
| 10 | -class EE_Int_Normalization extends EE_Normalization_Strategy_Base{ |
|
| 10 | +class EE_Int_Normalization extends EE_Normalization_Strategy_Base { |
|
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * @param string $value_to_normalize |
@@ -15,38 +15,38 @@ discard block |
||
| 15 | 15 | * @throws \EE_Validation_Error |
| 16 | 16 | */ |
| 17 | 17 | public function normalize($value_to_normalize) { |
| 18 | - if( is_int( $value_to_normalize ) ){ |
|
| 18 | + if (is_int($value_to_normalize)) { |
|
| 19 | 19 | return $value_to_normalize; |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | - if ( is_null( $value_to_normalize ) || $value_to_normalize === '' ) { |
|
| 22 | + if (is_null($value_to_normalize) || $value_to_normalize === '') { |
|
| 23 | 23 | return null; |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - if( ! is_string( $value_to_normalize )){ |
|
| 27 | - throw new EE_Validation_Error( sprintf( __( 'The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso' ), print_r( $value_to_normalize, TRUE), gettype( $value_to_normalize ) ) ); |
|
| 26 | + if ( ! is_string($value_to_normalize)) { |
|
| 27 | + throw new EE_Validation_Error(sprintf(__('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), print_r($value_to_normalize, TRUE), gettype($value_to_normalize))); |
|
| 28 | 28 | } |
| 29 | 29 | $thousands_separator = EE_Config::instance()->currency->thsnds; |
| 30 | - $value_to_normalize = str_replace( $thousands_separator, "", $value_to_normalize ); |
|
| 31 | - $value_to_normalize = str_replace( array(" ","\t"), '', $value_to_normalize ); |
|
| 32 | - if ( preg_match( '/^\d+$/', $value_to_normalize )) { |
|
| 33 | - return intval( $value_to_normalize ); |
|
| 30 | + $value_to_normalize = str_replace($thousands_separator, "", $value_to_normalize); |
|
| 31 | + $value_to_normalize = str_replace(array(" ", "\t"), '', $value_to_normalize); |
|
| 32 | + if (preg_match('/^\d+$/', $value_to_normalize)) { |
|
| 33 | + return intval($value_to_normalize); |
|
| 34 | 34 | } else { |
| 35 | 35 | //find if this input has a int validation strategy |
| 36 | 36 | //in which case, use its message |
| 37 | 37 | $validation_error_message = NULL; |
| 38 | - foreach( $this->_input->get_validation_strategies() as $validation_strategy ){ |
|
| 39 | - if( $validation_strategy instanceof EE_Int_Validation_Strategy ){ |
|
| 38 | + foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
| 39 | + if ($validation_strategy instanceof EE_Int_Validation_Strategy) { |
|
| 40 | 40 | $validation_error_message = $validation_strategy->get_validation_error_message(); |
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | 43 | //this really shouldn't ever happen because fields with a int normalization strategy |
| 44 | 44 | //should also have a int validation strategy, but in case it doesnt use the default |
| 45 | - if( ! $validation_error_message ){ |
|
| 45 | + if ( ! $validation_error_message) { |
|
| 46 | 46 | $default_validation_strategy = new EE_Int_Validation_Strategy(); |
| 47 | 47 | $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
| 48 | 48 | } |
| 49 | - throw new EE_Validation_Error( $validation_error_message, 'numeric_only' ); |
|
| 49 | + throw new EE_Validation_Error($validation_error_message, 'numeric_only'); |
|
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | 52 | |
@@ -55,12 +55,12 @@ discard block |
||
| 55 | 55 | * @param int $normalized_value |
| 56 | 56 | * @return string |
| 57 | 57 | */ |
| 58 | - public function unnormalize( $normalized_value ) { |
|
| 58 | + public function unnormalize($normalized_value) { |
|
| 59 | 59 | if ($normalized_value === null) { |
| 60 | 60 | return ''; |
| 61 | - }elseif( empty( $normalized_value ) ){ |
|
| 61 | + }elseif (empty($normalized_value)) { |
|
| 62 | 62 | return '0'; |
| 63 | - }else{ |
|
| 63 | + } else { |
|
| 64 | 64 | return "$normalized_value"; |
| 65 | 65 | } |
| 66 | 66 | } |
@@ -58,9 +58,9 @@ |
||
| 58 | 58 | public function unnormalize( $normalized_value ) { |
| 59 | 59 | if ($normalized_value === null) { |
| 60 | 60 | return ''; |
| 61 | - }elseif( empty( $normalized_value ) ){ |
|
| 61 | + } elseif( empty( $normalized_value ) ){ |
|
| 62 | 62 | return '0'; |
| 63 | - }else{ |
|
| 63 | + } else{ |
|
| 64 | 64 | return "$normalized_value"; |
| 65 | 65 | } |
| 66 | 66 | } |
@@ -15,10 +15,10 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | public function normalize($value_to_normalize) { |
| 17 | 17 | if(is_array($value_to_normalize)) { |
| 18 | - return array_shift($value_to_normalize); |
|
| 19 | - //consider `"null"` values to be equivalent to null. |
|
| 20 | - }elseif($value_to_normalize === '' || $value_to_normalize === null) { |
|
| 21 | - return null; |
|
| 18 | + return array_shift($value_to_normalize); |
|
| 19 | + //consider `"null"` values to be equivalent to null. |
|
| 20 | + }elseif($value_to_normalize === '' || $value_to_normalize === null) { |
|
| 21 | + return null; |
|
| 22 | 22 | }else{ |
| 23 | 23 | return $value_to_normalize; |
| 24 | 24 | } |
@@ -29,10 +29,10 @@ discard block |
||
| 29 | 29 | * @return string |
| 30 | 30 | */ |
| 31 | 31 | public function unnormalize( $normalized_value ){ |
| 32 | - //account for default "select here" option values |
|
| 33 | - if ($normalized_value === null) { |
|
| 34 | - return ''; |
|
| 35 | - } |
|
| 32 | + //account for default "select here" option values |
|
| 33 | + if ($normalized_value === null) { |
|
| 34 | + return ''; |
|
| 35 | + } |
|
| 36 | 36 | return $normalized_value; |
| 37 | 37 | } |
| 38 | 38 | } |
@@ -7,19 +7,19 @@ discard block |
||
| 7 | 7 | * @subpackage |
| 8 | 8 | * @author Mike Nelson |
| 9 | 9 | */ |
| 10 | -class EE_Text_Normalization extends EE_Normalization_Strategy_Base{ |
|
| 10 | +class EE_Text_Normalization extends EE_Normalization_Strategy_Base { |
|
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * @param string $value_to_normalize |
| 14 | 14 | * @return array|mixed|string |
| 15 | 15 | */ |
| 16 | 16 | public function normalize($value_to_normalize) { |
| 17 | - if(is_array($value_to_normalize)) { |
|
| 17 | + if (is_array($value_to_normalize)) { |
|
| 18 | 18 | return array_shift($value_to_normalize); |
| 19 | 19 | //consider `"null"` values to be equivalent to null. |
| 20 | - }elseif($value_to_normalize === '' || $value_to_normalize === null) { |
|
| 20 | + }elseif ($value_to_normalize === '' || $value_to_normalize === null) { |
|
| 21 | 21 | return null; |
| 22 | - }else{ |
|
| 22 | + } else { |
|
| 23 | 23 | return $value_to_normalize; |
| 24 | 24 | } |
| 25 | 25 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * @param string $normalized_value |
| 29 | 29 | * @return string |
| 30 | 30 | */ |
| 31 | - public function unnormalize( $normalized_value ){ |
|
| 31 | + public function unnormalize($normalized_value) { |
|
| 32 | 32 | //account for default "select here" option values |
| 33 | 33 | if ($normalized_value === null) { |
| 34 | 34 | return ''; |
@@ -17,9 +17,9 @@ |
||
| 17 | 17 | if(is_array($value_to_normalize)) { |
| 18 | 18 | return array_shift($value_to_normalize); |
| 19 | 19 | //consider `"null"` values to be equivalent to null. |
| 20 | - }elseif($value_to_normalize === '' || $value_to_normalize === null) { |
|
| 20 | + } elseif($value_to_normalize === '' || $value_to_normalize === null) { |
|
| 21 | 21 | return null; |
| 22 | - }else{ |
|
| 22 | + } else{ |
|
| 23 | 23 | return $value_to_normalize; |
| 24 | 24 | } |
| 25 | 25 | } |
@@ -445,8 +445,8 @@ discard block |
||
| 445 | 445 | $new_question->set_admin_label( sprintf( __( '%s **Duplicate**', 'event_espresso' ), $this->admin_label() ) ); |
| 446 | 446 | $new_question->set_system_ID( null ); |
| 447 | 447 | $new_question->set_wp_user( get_current_user_id() ); |
| 448 | - //if we're duplicating a trashed question, assume we don't want the new one to be trashed |
|
| 449 | - $new_question->set_deleted( false ); |
|
| 448 | + //if we're duplicating a trashed question, assume we don't want the new one to be trashed |
|
| 449 | + $new_question->set_deleted( false ); |
|
| 450 | 450 | $success = $new_question->save(); |
| 451 | 451 | if( $success ) { |
| 452 | 452 | //we don't totally want to duplicate the question options, because we want them to be for the NEW question |
@@ -501,8 +501,8 @@ discard block |
||
| 501 | 501 | } |
| 502 | 502 | // has this question been answered ? |
| 503 | 503 | if ( $answer instanceof EE_Answer |
| 504 | - && $answer->value() !== '' |
|
| 505 | - ) { |
|
| 504 | + && $answer->value() !== '' |
|
| 505 | + ) { |
|
| 506 | 506 | //answer gets htmlspecialchars called on it, undo that please |
| 507 | 507 | //because the form input's display strategy may call esc_attr too |
| 508 | 508 | //which also does html special characters |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | -<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 2 | - exit( 'No direct script access allowed' ); |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | /** |
| 5 | 5 | * Event Espresso |
@@ -37,9 +37,9 @@ discard block |
||
| 37 | 37 | * date_format and the second value is the time format |
| 38 | 38 | * @return EE_Question |
| 39 | 39 | */ |
| 40 | - public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) { |
|
| 41 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats ); |
|
| 42 | - return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats ); |
|
| 40 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) { |
|
| 41 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 42 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | |
@@ -50,8 +50,8 @@ discard block |
||
| 50 | 50 | * the website will be used. |
| 51 | 51 | * @return EE_Question |
| 52 | 52 | */ |
| 53 | - public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
|
| 54 | - return new self( $props_n_values, TRUE, $timezone ); |
|
| 53 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) { |
|
| 54 | + return new self($props_n_values, TRUE, $timezone); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | |
@@ -62,8 +62,8 @@ discard block |
||
| 62 | 62 | * @access public |
| 63 | 63 | * @param string $QST_display_text |
| 64 | 64 | */ |
| 65 | - public function set_display_text( $QST_display_text = '' ) { |
|
| 66 | - $this->set( 'QST_display_text', $QST_display_text ); |
|
| 65 | + public function set_display_text($QST_display_text = '') { |
|
| 66 | + $this->set('QST_display_text', $QST_display_text); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | |
@@ -74,8 +74,8 @@ discard block |
||
| 74 | 74 | * @access public |
| 75 | 75 | * @param string $QST_admin_label |
| 76 | 76 | */ |
| 77 | - public function set_admin_label( $QST_admin_label = '' ) { |
|
| 78 | - $this->set( 'QST_admin_label', $QST_admin_label ); |
|
| 77 | + public function set_admin_label($QST_admin_label = '') { |
|
| 78 | + $this->set('QST_admin_label', $QST_admin_label); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | |
@@ -86,8 +86,8 @@ discard block |
||
| 86 | 86 | * @access public |
| 87 | 87 | * @param mixed $QST_system |
| 88 | 88 | */ |
| 89 | - public function set_system_ID( $QST_system = '' ) { |
|
| 90 | - $this->set( 'QST_system', $QST_system ); |
|
| 89 | + public function set_system_ID($QST_system = '') { |
|
| 90 | + $this->set('QST_system', $QST_system); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | |
@@ -98,8 +98,8 @@ discard block |
||
| 98 | 98 | * @access public |
| 99 | 99 | * @param string $QST_type |
| 100 | 100 | */ |
| 101 | - public function set_question_type( $QST_type = '' ) { |
|
| 102 | - $this->set( 'QST_type', $QST_type ); |
|
| 101 | + public function set_question_type($QST_type = '') { |
|
| 102 | + $this->set('QST_type', $QST_type); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | |
@@ -110,8 +110,8 @@ discard block |
||
| 110 | 110 | * @access public |
| 111 | 111 | * @param bool $QST_required |
| 112 | 112 | */ |
| 113 | - public function set_required( $QST_required = FALSE ) { |
|
| 114 | - $this->set( 'QST_required', $QST_required ); |
|
| 113 | + public function set_required($QST_required = FALSE) { |
|
| 114 | + $this->set('QST_required', $QST_required); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | |
@@ -122,8 +122,8 @@ discard block |
||
| 122 | 122 | * @access public |
| 123 | 123 | * @param string $QST_required_text |
| 124 | 124 | */ |
| 125 | - public function set_required_text( $QST_required_text = '' ) { |
|
| 126 | - $this->set( 'QST_required_text', $QST_required_text ); |
|
| 125 | + public function set_required_text($QST_required_text = '') { |
|
| 126 | + $this->set('QST_required_text', $QST_required_text); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | |
@@ -134,8 +134,8 @@ discard block |
||
| 134 | 134 | * @access public |
| 135 | 135 | * @param int $QST_order |
| 136 | 136 | */ |
| 137 | - public function set_order( $QST_order = 0 ) { |
|
| 138 | - $this->set( 'QST_order', $QST_order ); |
|
| 137 | + public function set_order($QST_order = 0) { |
|
| 138 | + $this->set('QST_order', $QST_order); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | |
@@ -146,8 +146,8 @@ discard block |
||
| 146 | 146 | * @access public |
| 147 | 147 | * @param bool $QST_admin_only |
| 148 | 148 | */ |
| 149 | - public function set_admin_only( $QST_admin_only = FALSE ) { |
|
| 150 | - $this->set( 'QST_admin_only', $QST_admin_only ); |
|
| 149 | + public function set_admin_only($QST_admin_only = FALSE) { |
|
| 150 | + $this->set('QST_admin_only', $QST_admin_only); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | |
@@ -158,8 +158,8 @@ discard block |
||
| 158 | 158 | * @access public |
| 159 | 159 | * @param int $QST_wp_user |
| 160 | 160 | */ |
| 161 | - public function set_wp_user( $QST_wp_user = 1 ) { |
|
| 162 | - $this->set( 'QST_wp_user', $QST_wp_user ); |
|
| 161 | + public function set_wp_user($QST_wp_user = 1) { |
|
| 162 | + $this->set('QST_wp_user', $QST_wp_user); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | |
@@ -175,8 +175,8 @@ discard block |
||
| 175 | 175 | * @access public |
| 176 | 176 | * @param bool $QST_deleted |
| 177 | 177 | */ |
| 178 | - public function set_deleted( $QST_deleted = FALSE ) { |
|
| 179 | - $this->set( 'QST_deleted', $QST_deleted ); |
|
| 178 | + public function set_deleted($QST_deleted = FALSE) { |
|
| 179 | + $this->set('QST_deleted', $QST_deleted); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | * @return string |
| 188 | 188 | */ |
| 189 | 189 | public function display_text() { |
| 190 | - return $this->get( 'QST_display_text' ); |
|
| 190 | + return $this->get('QST_display_text'); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | * @return string |
| 199 | 199 | */ |
| 200 | 200 | public function admin_label() { |
| 201 | - return $this->get( 'QST_admin_label' ); |
|
| 201 | + return $this->get('QST_admin_label'); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | * @return string |
| 210 | 210 | */ |
| 211 | 211 | public function system_ID() { |
| 212 | - return $this->get( 'QST_system' ); |
|
| 212 | + return $this->get('QST_system'); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | * @return boolean |
| 221 | 221 | */ |
| 222 | 222 | public function required() { |
| 223 | - return $this->get( 'QST_required' ); |
|
| 223 | + return $this->get('QST_required'); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | * @return string |
| 233 | 233 | */ |
| 234 | 234 | public function required_text() { |
| 235 | - return $this->get( 'QST_required_text' ); |
|
| 235 | + return $this->get('QST_required_text'); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | * @return string |
| 244 | 244 | */ |
| 245 | 245 | public function type() { |
| 246 | - return $this->get( 'QST_type' ); |
|
| 246 | + return $this->get('QST_type'); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | * @return int |
| 256 | 256 | */ |
| 257 | 257 | public function order() { |
| 258 | - return $this->get( 'QST_order' ); |
|
| 258 | + return $this->get('QST_order'); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | * @return boolean |
| 268 | 268 | */ |
| 269 | 269 | public function admin_only() { |
| 270 | - return $this->get( 'QST_admin_only' ); |
|
| 270 | + return $this->get('QST_admin_only'); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | * @return int |
| 279 | 279 | */ |
| 280 | 280 | public function wp_user() { |
| 281 | - return $this->get( 'QST_wp_user' ); |
|
| 281 | + return $this->get('QST_wp_user'); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | * @return boolean |
| 290 | 290 | */ |
| 291 | 291 | public function deleted() { |
| 292 | - return $this->get( 'QST_deleted' ); |
|
| 292 | + return $this->get('QST_deleted'); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * @return EE_Answer[] |
| 300 | 300 | */ |
| 301 | 301 | public function answers() { |
| 302 | - return $this->get_many_related( 'Answer' ); |
|
| 302 | + return $this->get_many_related('Answer'); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | * @return boolean true = has answers, false = no answers. |
| 310 | 310 | */ |
| 311 | 311 | public function has_answers() { |
| 312 | - return $this->count_related( 'Answer' ) > 0 ? TRUE : FALSE; |
|
| 312 | + return $this->count_related('Answer') > 0 ? TRUE : FALSE; |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | * @return EE_Question_Group[] |
| 320 | 320 | */ |
| 321 | 321 | public function question_groups() { |
| 322 | - return $this->get_many_related( 'Question_Group' ); |
|
| 322 | + return $this->get_many_related('Question_Group'); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | |
@@ -333,24 +333,24 @@ discard block |
||
| 333 | 333 | * whether it was trashed or not. |
| 334 | 334 | * @return EE_Question_Option[] |
| 335 | 335 | */ |
| 336 | - public function options( $notDeletedOptionsOnly = TRUE, $selected_value_to_always_include = NULL ) { |
|
| 337 | - if ( ! $this->ID() ) { |
|
| 336 | + public function options($notDeletedOptionsOnly = TRUE, $selected_value_to_always_include = NULL) { |
|
| 337 | + if ( ! $this->ID()) { |
|
| 338 | 338 | return array(); |
| 339 | 339 | } |
| 340 | 340 | $query_params = array(); |
| 341 | - if ( $selected_value_to_always_include ) { |
|
| 342 | - if ( is_array( $selected_value_to_always_include ) ) { |
|
| 343 | - $query_params[ 0 ][ 'OR*options-query' ][ 'QSO_value' ] = array( 'IN', $selected_value_to_always_include ); |
|
| 341 | + if ($selected_value_to_always_include) { |
|
| 342 | + if (is_array($selected_value_to_always_include)) { |
|
| 343 | + $query_params[0]['OR*options-query']['QSO_value'] = array('IN', $selected_value_to_always_include); |
|
| 344 | 344 | } else { |
| 345 | - $query_params[ 0 ][ 'OR*options-query' ][ 'QSO_value' ] = $selected_value_to_always_include; |
|
| 345 | + $query_params[0]['OR*options-query']['QSO_value'] = $selected_value_to_always_include; |
|
| 346 | 346 | } |
| 347 | 347 | } |
| 348 | - if ( $notDeletedOptionsOnly ) { |
|
| 349 | - $query_params[ 0 ][ 'OR*options-query' ][ 'QSO_deleted' ] = FALSE; |
|
| 348 | + if ($notDeletedOptionsOnly) { |
|
| 349 | + $query_params[0]['OR*options-query']['QSO_deleted'] = FALSE; |
|
| 350 | 350 | } |
| 351 | 351 | //order by QSO_order |
| 352 | - $query_params[ 'order_by' ] = array( 'QSO_order' => 'ASC' ); |
|
| 353 | - return $this->get_many_related( 'Question_Option', $query_params ); |
|
| 352 | + $query_params['order_by'] = array('QSO_order' => 'ASC'); |
|
| 353 | + return $this->get_many_related('Question_Option', $query_params); |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | |
@@ -360,7 +360,7 @@ discard block |
||
| 360 | 360 | * @return \EE_Question_Option[] |
| 361 | 361 | */ |
| 362 | 362 | public function temp_options() { |
| 363 | - return $this->_model_relations[ 'Question_Option' ]; |
|
| 363 | + return $this->_model_relations['Question_Option']; |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | |
@@ -371,8 +371,8 @@ discard block |
||
| 371 | 371 | * @param EE_Question_Option $option |
| 372 | 372 | * @return boolean success |
| 373 | 373 | */ |
| 374 | - public function add_option( EE_Question_Option $option ) { |
|
| 375 | - return $this->_add_relation_to( $option, 'Question_Option' ); |
|
| 374 | + public function add_option(EE_Question_Option $option) { |
|
| 375 | + return $this->_add_relation_to($option, 'Question_Option'); |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | |
@@ -382,8 +382,8 @@ discard block |
||
| 382 | 382 | * @param EE_Question_Option $option |
| 383 | 383 | * @return boolean success |
| 384 | 384 | */ |
| 385 | - public function add_temp_option( EE_Question_Option $option ) { |
|
| 386 | - $this->_model_relations[ 'Question_Option' ][ ] = $option; |
|
| 385 | + public function add_temp_option(EE_Question_Option $option) { |
|
| 386 | + $this->_model_relations['Question_Option'][] = $option; |
|
| 387 | 387 | return TRUE; |
| 388 | 388 | } |
| 389 | 389 | |
@@ -394,8 +394,8 @@ discard block |
||
| 394 | 394 | * @param EE_Question_Option $option |
| 395 | 395 | * @return boolean success |
| 396 | 396 | */ |
| 397 | - public function remove_option( EE_Question_Option $option ) { |
|
| 398 | - return $this->_remove_relation_to( $option, 'Question_Option' ); |
|
| 397 | + public function remove_option(EE_Question_Option $option) { |
|
| 398 | + return $this->_remove_relation_to($option, 'Question_Option'); |
|
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | |
@@ -404,8 +404,8 @@ discard block |
||
| 404 | 404 | * @return bool |
| 405 | 405 | */ |
| 406 | 406 | public function is_system_question() { |
| 407 | - $system_ID = $this->get( 'QST_system' ); |
|
| 408 | - return ! empty( $system_ID ) ? TRUE : FALSE; |
|
| 407 | + $system_ID = $this->get('QST_system'); |
|
| 408 | + return ! empty($system_ID) ? TRUE : FALSE; |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | |
@@ -418,8 +418,8 @@ discard block |
||
| 418 | 418 | */ |
| 419 | 419 | public function set_order_to_latest() { |
| 420 | 420 | $latest_order = $this->get_model()->get_latest_question_order(); |
| 421 | - $latest_order ++; |
|
| 422 | - $this->set( 'QST_order', $latest_order ); |
|
| 421 | + $latest_order++; |
|
| 422 | + $this->set('QST_order', $latest_order); |
|
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | |
@@ -438,20 +438,20 @@ discard block |
||
| 438 | 438 | * Duplicates this question and its question options |
| 439 | 439 | * @return \EE_Question |
| 440 | 440 | */ |
| 441 | - public function duplicate( $options = array() ) { |
|
| 441 | + public function duplicate($options = array()) { |
|
| 442 | 442 | $new_question = clone $this; |
| 443 | - $new_question->set( 'QST_ID', null ); |
|
| 444 | - $new_question->set_display_text( sprintf( __( '%s **Duplicate**', 'event_espresso' ), $this->display_text() ) ); |
|
| 445 | - $new_question->set_admin_label( sprintf( __( '%s **Duplicate**', 'event_espresso' ), $this->admin_label() ) ); |
|
| 446 | - $new_question->set_system_ID( null ); |
|
| 447 | - $new_question->set_wp_user( get_current_user_id() ); |
|
| 443 | + $new_question->set('QST_ID', null); |
|
| 444 | + $new_question->set_display_text(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->display_text())); |
|
| 445 | + $new_question->set_admin_label(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->admin_label())); |
|
| 446 | + $new_question->set_system_ID(null); |
|
| 447 | + $new_question->set_wp_user(get_current_user_id()); |
|
| 448 | 448 | //if we're duplicating a trashed question, assume we don't want the new one to be trashed |
| 449 | - $new_question->set_deleted( false ); |
|
| 449 | + $new_question->set_deleted(false); |
|
| 450 | 450 | $success = $new_question->save(); |
| 451 | - if( $success ) { |
|
| 451 | + if ($success) { |
|
| 452 | 452 | //we don't totally want to duplicate the question options, because we want them to be for the NEW question |
| 453 | - foreach( $this->options() as $question_option ) { |
|
| 454 | - $question_option->duplicate( array( 'QST_ID' => $new_question->ID() ) ); |
|
| 453 | + foreach ($this->options() as $question_option) { |
|
| 454 | + $question_option->duplicate(array('QST_ID' => $new_question->ID())); |
|
| 455 | 455 | } |
| 456 | 456 | return $new_question; |
| 457 | 457 | } else { |
@@ -464,7 +464,7 @@ discard block |
||
| 464 | 464 | * @return int|float |
| 465 | 465 | */ |
| 466 | 466 | public function max() { |
| 467 | - return $this->get( 'QST_max' ); |
|
| 467 | + return $this->get('QST_max'); |
|
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | /** |
@@ -472,8 +472,8 @@ discard block |
||
| 472 | 472 | * @param int|float $new_max |
| 473 | 473 | * @return void |
| 474 | 474 | */ |
| 475 | - public function set_max( $new_max ) { |
|
| 476 | - $this->set( 'QST_max', $new_max ); |
|
| 475 | + public function set_max($new_max) { |
|
| 476 | + $this->set('QST_max', $new_max); |
|
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | |
@@ -485,7 +485,7 @@ discard block |
||
| 485 | 485 | * @param array $input_constructor_args |
| 486 | 486 | * @return EE_Form_Input_Base |
| 487 | 487 | */ |
| 488 | - public function generate_form_input( $registration = null, $answer = null, $input_constructor_args = array() ) { |
|
| 488 | + public function generate_form_input($registration = null, $answer = null, $input_constructor_args = array()) { |
|
| 489 | 489 | $identifier = $this->is_system_question() ? $this->system_ID() : $this->ID(); |
| 490 | 490 | |
| 491 | 491 | $input_constructor_args = array_merge( |
@@ -496,29 +496,29 @@ discard block |
||
| 496 | 496 | ), |
| 497 | 497 | $input_constructor_args |
| 498 | 498 | ); |
| 499 | - if( ! $answer instanceof EE_Answer && $registration instanceof EE_Registration ) { |
|
| 500 | - $answer = EEM_Answer::instance()->get_registration_question_answer_object( $registration, $this->ID() ); |
|
| 499 | + if ( ! $answer instanceof EE_Answer && $registration instanceof EE_Registration) { |
|
| 500 | + $answer = EEM_Answer::instance()->get_registration_question_answer_object($registration, $this->ID()); |
|
| 501 | 501 | } |
| 502 | 502 | // has this question been answered ? |
| 503 | - if ( $answer instanceof EE_Answer |
|
| 503 | + if ($answer instanceof EE_Answer |
|
| 504 | 504 | && $answer->value() !== '' |
| 505 | 505 | ) { |
| 506 | 506 | //answer gets htmlspecialchars called on it, undo that please |
| 507 | 507 | //because the form input's display strategy may call esc_attr too |
| 508 | 508 | //which also does html special characters |
| 509 | 509 | $values_with_html_special_chars = $answer->value(); |
| 510 | - if( is_array( $values_with_html_special_chars ) ) { |
|
| 511 | - $default_value = array_map( 'htmlspecialchars_decode', $values_with_html_special_chars ); |
|
| 510 | + if (is_array($values_with_html_special_chars)) { |
|
| 511 | + $default_value = array_map('htmlspecialchars_decode', $values_with_html_special_chars); |
|
| 512 | 512 | } else { |
| 513 | - $default_value = htmlspecialchars_decode( $values_with_html_special_chars ); |
|
| 513 | + $default_value = htmlspecialchars_decode($values_with_html_special_chars); |
|
| 514 | 514 | } |
| 515 | 515 | $input_constructor_args['default'] = $default_value; |
| 516 | 516 | } |
| 517 | - $max_max_for_question = EEM_Question::instance()->absolute_max_for_system_question( $this->system_ID() ); |
|
| 518 | - if( EEM_Question::instance()->question_type_is_in_category( $this->type(), 'text' ) ) { |
|
| 519 | - $input_constructor_args[ 'validation_strategies' ][] = new EE_Max_Length_Validation_Strategy( |
|
| 517 | + $max_max_for_question = EEM_Question::instance()->absolute_max_for_system_question($this->system_ID()); |
|
| 518 | + if (EEM_Question::instance()->question_type_is_in_category($this->type(), 'text')) { |
|
| 519 | + $input_constructor_args['validation_strategies'][] = new EE_Max_Length_Validation_Strategy( |
|
| 520 | 520 | null, |
| 521 | - min( $max_max_for_question, $this->max() ) |
|
| 521 | + min($max_max_for_question, $this->max()) |
|
| 522 | 522 | ); |
| 523 | 523 | } |
| 524 | 524 | $input_constructor_args = apply_filters( |
@@ -530,22 +530,22 @@ discard block |
||
| 530 | 530 | ); |
| 531 | 531 | |
| 532 | 532 | $result = null; |
| 533 | - switch ( $this->type() ) { |
|
| 533 | + switch ($this->type()) { |
|
| 534 | 534 | // Text |
| 535 | 535 | case EEM_Question::QST_type_text : |
| 536 | - $result = new EE_Text_Input( $input_constructor_args ); |
|
| 536 | + $result = new EE_Text_Input($input_constructor_args); |
|
| 537 | 537 | break; |
| 538 | 538 | // Textarea |
| 539 | 539 | case EEM_Question::QST_type_textarea : |
| 540 | - $result = new EE_Text_Area_Input( $input_constructor_args ); |
|
| 540 | + $result = new EE_Text_Area_Input($input_constructor_args); |
|
| 541 | 541 | break; |
| 542 | 542 | // Radio Buttons |
| 543 | 543 | case EEM_Question::QST_type_radio : |
| 544 | - $result = new EE_Radio_Button_Input( $this->options(), $input_constructor_args ); |
|
| 544 | + $result = new EE_Radio_Button_Input($this->options(), $input_constructor_args); |
|
| 545 | 545 | break; |
| 546 | 546 | // Dropdown |
| 547 | 547 | case EEM_Question::QST_type_dropdown : |
| 548 | - $result = new EE_Select_Input( $this->options(), $input_constructor_args ); |
|
| 548 | + $result = new EE_Select_Input($this->options(), $input_constructor_args); |
|
| 549 | 549 | break; |
| 550 | 550 | // State Dropdown |
| 551 | 551 | case EEM_Question::QST_type_state : |
@@ -556,7 +556,7 @@ discard block |
||
| 556 | 556 | $registration, |
| 557 | 557 | $answer |
| 558 | 558 | ); |
| 559 | - $result = new EE_State_Select_Input( $state_options, $input_constructor_args ); |
|
| 559 | + $result = new EE_State_Select_Input($state_options, $input_constructor_args); |
|
| 560 | 560 | break; |
| 561 | 561 | // Country Dropdown |
| 562 | 562 | case EEM_Question::QST_type_country : |
@@ -567,49 +567,49 @@ discard block |
||
| 567 | 567 | $registration, |
| 568 | 568 | $answer |
| 569 | 569 | ); |
| 570 | - $result = new EE_Country_Select_Input( $country_options, $input_constructor_args ); |
|
| 570 | + $result = new EE_Country_Select_Input($country_options, $input_constructor_args); |
|
| 571 | 571 | break; |
| 572 | 572 | // Checkboxes |
| 573 | 573 | case EEM_Question::QST_type_checkbox : |
| 574 | - $result = new EE_Checkbox_Multi_Input( $this->options(), $input_constructor_args ); |
|
| 574 | + $result = new EE_Checkbox_Multi_Input($this->options(), $input_constructor_args); |
|
| 575 | 575 | break; |
| 576 | 576 | // Date |
| 577 | 577 | case EEM_Question::QST_type_date : |
| 578 | - $result = new EE_Datepicker_Input( $input_constructor_args ); |
|
| 578 | + $result = new EE_Datepicker_Input($input_constructor_args); |
|
| 579 | 579 | break; |
| 580 | 580 | case EEM_Question::QST_type_html_textarea : |
| 581 | - $input_constructor_args[ 'validation_strategies' ][] = new EE_Simple_HTML_Validation_Strategy(); |
|
| 582 | - $result = new EE_Text_Area_Input( $input_constructor_args ); |
|
| 583 | - $result->remove_validation_strategy( 'EE_Plaintext_Validation_Strategy' ); |
|
| 581 | + $input_constructor_args['validation_strategies'][] = new EE_Simple_HTML_Validation_Strategy(); |
|
| 582 | + $result = new EE_Text_Area_Input($input_constructor_args); |
|
| 583 | + $result->remove_validation_strategy('EE_Plaintext_Validation_Strategy'); |
|
| 584 | 584 | break; |
| 585 | 585 | case EEM_Question::QST_type_email : |
| 586 | - $result = new EE_Email_Input( $input_constructor_args ); |
|
| 586 | + $result = new EE_Email_Input($input_constructor_args); |
|
| 587 | 587 | break; |
| 588 | 588 | case EEM_Question::QST_type_us_phone : |
| 589 | - $result = new EE_Phone_Input( $input_constructor_args ); |
|
| 589 | + $result = new EE_Phone_Input($input_constructor_args); |
|
| 590 | 590 | break; |
| 591 | 591 | case EEM_Question::QST_type_int : |
| 592 | - $input_constructor_args[ 'validation_strategies' ][] = new EE_Int_Validation_Strategy(); |
|
| 593 | - $result = new EE_Text_Input( $input_constructor_args ); |
|
| 592 | + $input_constructor_args['validation_strategies'][] = new EE_Int_Validation_Strategy(); |
|
| 593 | + $result = new EE_Text_Input($input_constructor_args); |
|
| 594 | 594 | break; |
| 595 | 595 | case EEM_Question::QST_type_decimal : |
| 596 | - $input_constructor_args[ 'validation_strategies' ][] = new EE_Float_Validation_Strategy(); |
|
| 597 | - $result = new EE_Text_Input( $input_constructor_args ); |
|
| 596 | + $input_constructor_args['validation_strategies'][] = new EE_Float_Validation_Strategy(); |
|
| 597 | + $result = new EE_Text_Input($input_constructor_args); |
|
| 598 | 598 | break; |
| 599 | 599 | case EEM_Question::QST_type_url : |
| 600 | - $input_constructor_args[ 'validation_strategies' ][] = new EE_URL_Validation_Strategy(); |
|
| 601 | - $result = new EE_Text_Input( $input_constructor_args ); |
|
| 600 | + $input_constructor_args['validation_strategies'][] = new EE_URL_Validation_Strategy(); |
|
| 601 | + $result = new EE_Text_Input($input_constructor_args); |
|
| 602 | 602 | break; |
| 603 | 603 | case EEM_Question::QST_type_year : |
| 604 | 604 | $result = new EE_Year_Input( |
| 605 | 605 | $input_constructor_args, |
| 606 | - apply_filters( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__four_digit', true, $this ), |
|
| 607 | - apply_filters( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__early_range', 100, $this ), |
|
| 608 | - apply_filters( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__end_range', 100, $this ) |
|
| 606 | + apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__four_digit', true, $this), |
|
| 607 | + apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__early_range', 100, $this), |
|
| 608 | + apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__end_range', 100, $this) |
|
| 609 | 609 | ); |
| 610 | 610 | break; |
| 611 | 611 | case EEM_Question::QST_type_multi_select : |
| 612 | - $result = new EE_Select_Multiple_Input( $this->options(), $input_constructor_args ); |
|
| 612 | + $result = new EE_Select_Multiple_Input($this->options(), $input_constructor_args); |
|
| 613 | 613 | break; |
| 614 | 614 | // fallback |
| 615 | 615 | default : |
@@ -620,12 +620,12 @@ discard block |
||
| 620 | 620 | $this, |
| 621 | 621 | $input_constructor_args |
| 622 | 622 | ); |
| 623 | - if( ! $default_input ){ |
|
| 624 | - $default_input = new EE_Text_Input( $input_constructor_args ); |
|
| 623 | + if ( ! $default_input) { |
|
| 624 | + $default_input = new EE_Text_Input($input_constructor_args); |
|
| 625 | 625 | } |
| 626 | 626 | $result = $default_input; |
| 627 | 627 | } |
| 628 | - return apply_filters( 'FHEE__EE_Question__generate_form_input__return', $result, $registration, $this, $answer ); |
|
| 628 | + return apply_filters('FHEE__EE_Question__generate_form_input__return', $result, $registration, $this, $answer); |
|
| 629 | 629 | } |
| 630 | 630 | |
| 631 | 631 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -16,1428 +16,1428 @@ discard block |
||
| 16 | 16 | { |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
| 21 | - * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
| 22 | - */ |
|
| 23 | - const req_type_normal = 0; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Indicates this is a brand new installation of EE so we should install |
|
| 27 | - * tables and default data etc |
|
| 28 | - */ |
|
| 29 | - const req_type_new_activation = 1; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
| 33 | - * and we just exited maintenance mode). We MUST check the database is setup properly |
|
| 34 | - * and that default data is setup too |
|
| 35 | - */ |
|
| 36 | - const req_type_reactivation = 2; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * indicates that EE has been upgraded since its previous request. |
|
| 40 | - * We may have data migration scripts to call and will want to trigger maintenance mode |
|
| 41 | - */ |
|
| 42 | - const req_type_upgrade = 3; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
| 46 | - */ |
|
| 47 | - const req_type_downgrade = 4; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @deprecated since version 4.6.0.dev.006 |
|
| 51 | - * Now whenever a new_activation is detected the request type is still just |
|
| 52 | - * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
| 53 | - * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
| 54 | - * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
| 55 | - * (Specifically, when the migration manager indicates migrations are finished |
|
| 56 | - * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
| 57 | - */ |
|
| 58 | - const req_type_activation_but_not_installed = 5; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
| 62 | - */ |
|
| 63 | - const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * instance of the EE_System object |
|
| 68 | - * |
|
| 69 | - * @var $_instance |
|
| 70 | - * @access private |
|
| 71 | - */ |
|
| 72 | - private static $_instance = null; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @type EE_Registry $Registry |
|
| 76 | - * @access protected |
|
| 77 | - */ |
|
| 78 | - protected $registry; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
| 82 | - * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
| 83 | - * |
|
| 84 | - * @var int |
|
| 85 | - */ |
|
| 86 | - private $_req_type; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Whether or not there was a non-micro version change in EE core version during this request |
|
| 90 | - * |
|
| 91 | - * @var boolean |
|
| 92 | - */ |
|
| 93 | - private $_major_version_change = false; |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @singleton method used to instantiate class object |
|
| 99 | - * @access public |
|
| 100 | - * @param \EE_Registry $Registry |
|
| 101 | - * @return \EE_System |
|
| 102 | - */ |
|
| 103 | - public static function instance(EE_Registry $Registry = null) |
|
| 104 | - { |
|
| 105 | - // check if class object is instantiated |
|
| 106 | - if ( ! self::$_instance instanceof EE_System) { |
|
| 107 | - self::$_instance = new self($Registry); |
|
| 108 | - } |
|
| 109 | - return self::$_instance; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * resets the instance and returns it |
|
| 116 | - * |
|
| 117 | - * @return EE_System |
|
| 118 | - */ |
|
| 119 | - public static function reset() |
|
| 120 | - { |
|
| 121 | - self::$_instance->_req_type = null; |
|
| 122 | - //make sure none of the old hooks are left hanging around |
|
| 123 | - remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 124 | - //we need to reset the migration manager in order for it to detect DMSs properly |
|
| 125 | - EE_Data_Migration_Manager::reset(); |
|
| 126 | - self::instance()->detect_activations_or_upgrades(); |
|
| 127 | - self::instance()->perform_activations_upgrades_and_migrations(); |
|
| 128 | - return self::instance(); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * sets hooks for running rest of system |
|
| 135 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
| 136 | - * starting EE Addons from any other point may lead to problems |
|
| 137 | - * |
|
| 138 | - * @access private |
|
| 139 | - * @param \EE_Registry $Registry |
|
| 140 | - */ |
|
| 141 | - private function __construct(EE_Registry $Registry) |
|
| 142 | - { |
|
| 143 | - $this->registry = $Registry; |
|
| 144 | - do_action('AHEE__EE_System__construct__begin', $this); |
|
| 145 | - // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
| 146 | - add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons')); |
|
| 147 | - // when an ee addon is activated, we want to call the core hook(s) again |
|
| 148 | - // because the newly-activated addon didn't get a chance to run at all |
|
| 149 | - add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
| 150 | - // detect whether install or upgrade |
|
| 151 | - add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'), |
|
| 152 | - 3); |
|
| 153 | - // load EE_Config, EE_Textdomain, etc |
|
| 154 | - add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5); |
|
| 155 | - // load EE_Config, EE_Textdomain, etc |
|
| 156 | - add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
| 157 | - array($this, 'register_shortcodes_modules_and_widgets'), 7); |
|
| 158 | - // you wanna get going? I wanna get going... let's get going! |
|
| 159 | - add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9); |
|
| 160 | - //other housekeeping |
|
| 161 | - //exclude EE critical pages from wp_list_pages |
|
| 162 | - add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10); |
|
| 163 | - // ALL EE Addons should use the following hook point to attach their initial setup too |
|
| 164 | - // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
| 165 | - do_action('AHEE__EE_System__construct__complete', $this); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * load_espresso_addons |
|
| 172 | - * allow addons to load first so that they can set hooks for running DMS's, etc |
|
| 173 | - * this is hooked into both: |
|
| 174 | - * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 175 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 176 | - * and the WP 'activate_plugin' hookpoint |
|
| 177 | - * |
|
| 178 | - * @access public |
|
| 179 | - * @return void |
|
| 180 | - */ |
|
| 181 | - public function load_espresso_addons() |
|
| 182 | - { |
|
| 183 | - // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
| 184 | - // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
| 185 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
| 186 | - //load and setup EE_Capabilities |
|
| 187 | - $this->registry->load_core('Capabilities'); |
|
| 188 | - //caps need to be initialized on every request so that capability maps are set. |
|
| 189 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
| 190 | - $this->registry->CAP->init_caps(); |
|
| 191 | - do_action('AHEE__EE_System__load_espresso_addons'); |
|
| 192 | - //if the WP API basic auth plugin isn't already loaded, load it now. |
|
| 193 | - //We want it for mobile apps. Just include the entire plugin |
|
| 194 | - //also, don't load the basic auth when a plugin is getting activated, because |
|
| 195 | - //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
| 196 | - //and causes a fatal error |
|
| 197 | - if ( ! function_exists('json_basic_auth_handler') |
|
| 198 | - && ! function_exists('json_basic_auth_error') |
|
| 199 | - && ! ( |
|
| 200 | - isset($_GET['action']) |
|
| 201 | - && in_array($_GET['action'], array('activate', 'activate-selected')) |
|
| 202 | - ) |
|
| 203 | - && ! ( |
|
| 204 | - isset($_GET['activate']) |
|
| 205 | - && $_GET['activate'] === 'true' |
|
| 206 | - ) |
|
| 207 | - ) { |
|
| 208 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
| 209 | - } |
|
| 210 | - do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * detect_activations_or_upgrades |
|
| 217 | - * Checks for activation or upgrade of core first; |
|
| 218 | - * then also checks if any registered addons have been activated or upgraded |
|
| 219 | - * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
| 220 | - * which runs during the WP 'plugins_loaded' action at priority 3 |
|
| 221 | - * |
|
| 222 | - * @access public |
|
| 223 | - * @return void |
|
| 224 | - */ |
|
| 225 | - public function detect_activations_or_upgrades() |
|
| 226 | - { |
|
| 227 | - //first off: let's make sure to handle core |
|
| 228 | - $this->detect_if_activation_or_upgrade(); |
|
| 229 | - foreach ($this->registry->addons as $addon) { |
|
| 230 | - //detect teh request type for that addon |
|
| 231 | - $addon->detect_activation_or_upgrade(); |
|
| 232 | - } |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * detect_if_activation_or_upgrade |
|
| 239 | - * Takes care of detecting whether this is a brand new install or code upgrade, |
|
| 240 | - * and either setting up the DB or setting up maintenance mode etc. |
|
| 241 | - * |
|
| 242 | - * @access public |
|
| 243 | - * @return void |
|
| 244 | - */ |
|
| 245 | - public function detect_if_activation_or_upgrade() |
|
| 246 | - { |
|
| 247 | - do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
| 248 | - // load M-Mode class |
|
| 249 | - $this->registry->load_core('Maintenance_Mode'); |
|
| 250 | - // check if db has been updated, or if its a brand-new installation |
|
| 251 | - $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
| 252 | - $request_type = $this->detect_req_type($espresso_db_update); |
|
| 253 | - //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
| 254 | - switch ($request_type) { |
|
| 255 | - case EE_System::req_type_new_activation: |
|
| 256 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
| 257 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 258 | - break; |
|
| 259 | - case EE_System::req_type_reactivation: |
|
| 260 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
| 261 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 262 | - break; |
|
| 263 | - case EE_System::req_type_upgrade: |
|
| 264 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
| 265 | - //migrations may be required now that we've upgraded |
|
| 266 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 267 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 268 | - // echo "done upgrade";die; |
|
| 269 | - break; |
|
| 270 | - case EE_System::req_type_downgrade: |
|
| 271 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
| 272 | - //its possible migrations are no longer required |
|
| 273 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 274 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 275 | - break; |
|
| 276 | - case EE_System::req_type_normal: |
|
| 277 | - default: |
|
| 278 | - // $this->_maybe_redirect_to_ee_about(); |
|
| 279 | - break; |
|
| 280 | - } |
|
| 281 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * Updates the list of installed versions and sets hooks for |
|
| 288 | - * initializing the database later during the request |
|
| 289 | - * |
|
| 290 | - * @param array $espresso_db_update |
|
| 291 | - */ |
|
| 292 | - protected function _handle_core_version_change($espresso_db_update) |
|
| 293 | - { |
|
| 294 | - $this->update_list_of_installed_versions($espresso_db_update); |
|
| 295 | - //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
| 296 | - add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 297 | - array($this, 'initialize_db_if_no_migrations_required')); |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
| 304 | - * information about what versions of EE have been installed and activated, |
|
| 305 | - * NOT necessarily the state of the database |
|
| 306 | - * |
|
| 307 | - * @param null $espresso_db_update |
|
| 308 | - * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it |
|
| 309 | - * from the options table |
|
| 310 | - * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
| 311 | - */ |
|
| 312 | - private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
| 313 | - { |
|
| 314 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
| 315 | - if ( ! $espresso_db_update) { |
|
| 316 | - $espresso_db_update = get_option('espresso_db_update'); |
|
| 317 | - } |
|
| 318 | - // check that option is an array |
|
| 319 | - if ( ! is_array($espresso_db_update)) { |
|
| 320 | - // if option is FALSE, then it never existed |
|
| 321 | - if ($espresso_db_update === false) { |
|
| 322 | - // make $espresso_db_update an array and save option with autoload OFF |
|
| 323 | - $espresso_db_update = array(); |
|
| 324 | - add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
| 325 | - } else { |
|
| 326 | - // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
| 327 | - $espresso_db_update = array($espresso_db_update => array()); |
|
| 328 | - update_option('espresso_db_update', $espresso_db_update); |
|
| 329 | - } |
|
| 330 | - } else { |
|
| 331 | - $corrected_db_update = array(); |
|
| 332 | - //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
| 333 | - foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
| 334 | - if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
| 335 | - //the key is an int, and the value IS NOT an array |
|
| 336 | - //so it must be numerically-indexed, where values are versions installed... |
|
| 337 | - //fix it! |
|
| 338 | - $version_string = $should_be_array; |
|
| 339 | - $corrected_db_update[$version_string] = array('unknown-date'); |
|
| 340 | - } else { |
|
| 341 | - //ok it checks out |
|
| 342 | - $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
| 343 | - } |
|
| 344 | - } |
|
| 345 | - $espresso_db_update = $corrected_db_update; |
|
| 346 | - update_option('espresso_db_update', $espresso_db_update); |
|
| 347 | - } |
|
| 348 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
| 349 | - return $espresso_db_update; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * Does the traditional work of setting up the plugin's database and adding default data. |
|
| 356 | - * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
| 357 | - * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
| 358 | - * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
| 359 | - * so that it will be done when migrations are finished |
|
| 360 | - * |
|
| 361 | - * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
| 362 | - * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
| 363 | - * This is a resource-intensive job |
|
| 364 | - * so we prefer to only do it when necessary |
|
| 365 | - * @return void |
|
| 366 | - */ |
|
| 367 | - public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
| 368 | - { |
|
| 369 | - $request_type = $this->detect_req_type(); |
|
| 370 | - //only initialize system if we're not in maintenance mode. |
|
| 371 | - if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 372 | - update_option('ee_flush_rewrite_rules', true); |
|
| 373 | - if ($verify_schema) { |
|
| 374 | - EEH_Activation::initialize_db_and_folders(); |
|
| 375 | - } |
|
| 376 | - EEH_Activation::initialize_db_content(); |
|
| 377 | - EEH_Activation::system_initialization(); |
|
| 378 | - if ($initialize_addons_too) { |
|
| 379 | - $this->initialize_addons(); |
|
| 380 | - } |
|
| 381 | - } else { |
|
| 382 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
| 383 | - } |
|
| 384 | - if ($request_type === EE_System::req_type_new_activation |
|
| 385 | - || $request_type === EE_System::req_type_reactivation |
|
| 386 | - || ( |
|
| 387 | - $request_type === EE_System::req_type_upgrade |
|
| 388 | - && $this->is_major_version_change() |
|
| 389 | - ) |
|
| 390 | - ) { |
|
| 391 | - add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
| 392 | - } |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * Initializes the db for all registered addons |
|
| 399 | - */ |
|
| 400 | - public function initialize_addons() |
|
| 401 | - { |
|
| 402 | - //foreach registered addon, make sure its db is up-to-date too |
|
| 403 | - foreach ($this->registry->addons as $addon) { |
|
| 404 | - $addon->initialize_db_if_no_migrations_required(); |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
| 412 | - * |
|
| 413 | - * @param array $version_history |
|
| 414 | - * @param string $current_version_to_add version to be added to the version history |
|
| 415 | - * @return boolean success as to whether or not this option was changed |
|
| 416 | - */ |
|
| 417 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
| 418 | - { |
|
| 419 | - if ( ! $version_history) { |
|
| 420 | - $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
| 421 | - } |
|
| 422 | - if ($current_version_to_add == null) { |
|
| 423 | - $current_version_to_add = espresso_version(); |
|
| 424 | - } |
|
| 425 | - $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
| 426 | - // re-save |
|
| 427 | - return update_option('espresso_db_update', $version_history); |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * Detects if the current version indicated in the has existed in the list of |
|
| 434 | - * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
| 435 | - * |
|
| 436 | - * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
| 437 | - * If not supplied, fetches it from the options table. |
|
| 438 | - * Also, caches its result so later parts of the code can also know whether |
|
| 439 | - * there's been an update or not. This way we can add the current version to |
|
| 440 | - * espresso_db_update, but still know if this is a new install or not |
|
| 441 | - * @return int one of the constants on EE_System::req_type_ |
|
| 442 | - */ |
|
| 443 | - public function detect_req_type($espresso_db_update = null) |
|
| 444 | - { |
|
| 445 | - if ($this->_req_type === null) { |
|
| 446 | - $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update |
|
| 447 | - : $this->fix_espresso_db_upgrade_option(); |
|
| 448 | - $this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update, |
|
| 449 | - 'ee_espresso_activation', espresso_version()); |
|
| 450 | - $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
| 451 | - } |
|
| 452 | - return $this->_req_type; |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - |
|
| 456 | - |
|
| 457 | - /** |
|
| 458 | - * Returns whether or not there was a non-micro version change (ie, change in either |
|
| 459 | - * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
| 460 | - * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
| 461 | - * |
|
| 462 | - * @param $activation_history |
|
| 463 | - * @return bool |
|
| 464 | - */ |
|
| 465 | - protected function _detect_major_version_change($activation_history) |
|
| 466 | - { |
|
| 467 | - $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
| 468 | - $previous_version_parts = explode('.', $previous_version); |
|
| 469 | - $current_version_parts = explode('.', espresso_version()); |
|
| 470 | - return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
| 471 | - && ($previous_version_parts[0] !== $current_version_parts[0] |
|
| 472 | - || $previous_version_parts[1] !== $current_version_parts[1] |
|
| 473 | - ); |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * Returns true if either the major or minor version of EE changed during this request. |
|
| 480 | - * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
| 481 | - * |
|
| 482 | - * @return bool |
|
| 483 | - */ |
|
| 484 | - public function is_major_version_change() |
|
| 485 | - { |
|
| 486 | - return $this->_major_version_change; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
| 493 | - * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily |
|
| 494 | - * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
| 495 | - * just activated to (for core that will always be espresso_version()) |
|
| 496 | - * |
|
| 497 | - * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
| 498 | - * ee plugin. for core that's 'espresso_db_update' |
|
| 499 | - * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to |
|
| 500 | - * indicate that this plugin was just activated |
|
| 501 | - * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
| 502 | - * espresso_version()) |
|
| 503 | - * @return int one of the constants on EE_System::req_type_* |
|
| 504 | - */ |
|
| 505 | - public static function detect_req_type_given_activation_history( |
|
| 506 | - $activation_history_for_addon, |
|
| 507 | - $activation_indicator_option_name, |
|
| 508 | - $version_to_upgrade_to |
|
| 509 | - ) { |
|
| 510 | - $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
| 511 | - if ($activation_history_for_addon) { |
|
| 512 | - //it exists, so this isn't a completely new install |
|
| 513 | - //check if this version already in that list of previously installed versions |
|
| 514 | - if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
| 515 | - //it a version we haven't seen before |
|
| 516 | - if ($version_is_higher === 1) { |
|
| 517 | - $req_type = EE_System::req_type_upgrade; |
|
| 518 | - } else { |
|
| 519 | - $req_type = EE_System::req_type_downgrade; |
|
| 520 | - } |
|
| 521 | - delete_option($activation_indicator_option_name); |
|
| 522 | - } else { |
|
| 523 | - // its not an update. maybe a reactivation? |
|
| 524 | - if (get_option($activation_indicator_option_name, false)) { |
|
| 525 | - if ($version_is_higher === -1) { |
|
| 526 | - $req_type = EE_System::req_type_downgrade; |
|
| 527 | - } elseif ($version_is_higher === 0) { |
|
| 528 | - //we've seen this version before, but it's an activation. must be a reactivation |
|
| 529 | - $req_type = EE_System::req_type_reactivation; |
|
| 530 | - } else {//$version_is_higher === 1 |
|
| 531 | - $req_type = EE_System::req_type_upgrade; |
|
| 532 | - } |
|
| 533 | - delete_option($activation_indicator_option_name); |
|
| 534 | - } else { |
|
| 535 | - //we've seen this version before and the activation indicate doesn't show it was just activated |
|
| 536 | - if ($version_is_higher === -1) { |
|
| 537 | - $req_type = EE_System::req_type_downgrade; |
|
| 538 | - } elseif ($version_is_higher === 0) { |
|
| 539 | - //we've seen this version before and it's not an activation. its normal request |
|
| 540 | - $req_type = EE_System::req_type_normal; |
|
| 541 | - } else {//$version_is_higher === 1 |
|
| 542 | - $req_type = EE_System::req_type_upgrade; |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - } else { |
|
| 547 | - //brand new install |
|
| 548 | - $req_type = EE_System::req_type_new_activation; |
|
| 549 | - delete_option($activation_indicator_option_name); |
|
| 550 | - } |
|
| 551 | - return $req_type; |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
| 558 | - * the $activation_history_for_addon |
|
| 559 | - * |
|
| 560 | - * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
| 561 | - * sometimes containing 'unknown-date' |
|
| 562 | - * @param string $version_to_upgrade_to (current version) |
|
| 563 | - * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
| 564 | - * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
| 565 | - * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
| 566 | - * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
| 567 | - */ |
|
| 568 | - protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
| 569 | - { |
|
| 570 | - //find the most recently-activated version |
|
| 571 | - $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
| 572 | - return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * Gets the most recently active version listed in the activation history, |
|
| 579 | - * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
| 580 | - * |
|
| 581 | - * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
| 582 | - * sometimes containing 'unknown-date' |
|
| 583 | - * @return string |
|
| 584 | - */ |
|
| 585 | - protected static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
| 586 | - { |
|
| 587 | - $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
| 588 | - $most_recently_active_version = '0.0.0.dev.000'; |
|
| 589 | - if (is_array($activation_history)) { |
|
| 590 | - foreach ($activation_history as $version => $times_activated) { |
|
| 591 | - //check there is a record of when this version was activated. Otherwise, |
|
| 592 | - //mark it as unknown |
|
| 593 | - if ( ! $times_activated) { |
|
| 594 | - $times_activated = array('unknown-date'); |
|
| 595 | - } |
|
| 596 | - if (is_string($times_activated)) { |
|
| 597 | - $times_activated = array($times_activated); |
|
| 598 | - } |
|
| 599 | - foreach ($times_activated as $an_activation) { |
|
| 600 | - if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
| 601 | - $most_recently_active_version = $version; |
|
| 602 | - $most_recently_active_version_activation = $an_activation == 'unknown-date' |
|
| 603 | - ? '1970-01-01 00:00:00' : $an_activation; |
|
| 604 | - } |
|
| 605 | - } |
|
| 606 | - } |
|
| 607 | - } |
|
| 608 | - return $most_recently_active_version; |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - |
|
| 612 | - |
|
| 613 | - /** |
|
| 614 | - * This redirects to the about EE page after activation |
|
| 615 | - * |
|
| 616 | - * @return void |
|
| 617 | - */ |
|
| 618 | - public function redirect_to_about_ee() |
|
| 619 | - { |
|
| 620 | - $notices = EE_Error::get_notices(false); |
|
| 621 | - //if current user is an admin and it's not an ajax or rest request |
|
| 622 | - if ( |
|
| 623 | - ! (defined('DOING_AJAX') && DOING_AJAX) |
|
| 624 | - && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
| 625 | - && ! isset($notices['errors']) |
|
| 626 | - && apply_filters( |
|
| 627 | - 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
| 628 | - $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default') |
|
| 629 | - ) |
|
| 630 | - ) { |
|
| 631 | - $query_params = array('page' => 'espresso_about'); |
|
| 632 | - if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) { |
|
| 633 | - $query_params['new_activation'] = true; |
|
| 634 | - } |
|
| 635 | - if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) { |
|
| 636 | - $query_params['reactivation'] = true; |
|
| 637 | - } |
|
| 638 | - $url = add_query_arg($query_params, admin_url('admin.php')); |
|
| 639 | - wp_safe_redirect($url); |
|
| 640 | - exit(); |
|
| 641 | - } |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - |
|
| 645 | - |
|
| 646 | - /** |
|
| 647 | - * load_core_configuration |
|
| 648 | - * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 649 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 650 | - * |
|
| 651 | - * @return void |
|
| 652 | - */ |
|
| 653 | - public function load_core_configuration() |
|
| 654 | - { |
|
| 655 | - do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
| 656 | - $this->registry->load_core('EE_Load_Textdomain'); |
|
| 657 | - //load textdomain |
|
| 658 | - EE_Load_Textdomain::load_textdomain(); |
|
| 659 | - // load and setup EE_Config and EE_Network_Config |
|
| 660 | - $this->registry->load_core('Config'); |
|
| 661 | - $this->registry->load_core('Network_Config'); |
|
| 662 | - // setup autoloaders |
|
| 663 | - // enable logging? |
|
| 664 | - if ($this->registry->CFG->admin->use_full_logging) { |
|
| 665 | - $this->registry->load_core('Log'); |
|
| 666 | - } |
|
| 667 | - // check for activation errors |
|
| 668 | - $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
| 669 | - if ($activation_errors) { |
|
| 670 | - EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 671 | - update_option('ee_plugin_activation_errors', false); |
|
| 672 | - } |
|
| 673 | - // get model names |
|
| 674 | - $this->_parse_model_names(); |
|
| 675 | - //load caf stuff a chance to play during the activation process too. |
|
| 676 | - $this->_maybe_brew_regular(); |
|
| 677 | - do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - |
|
| 681 | - |
|
| 682 | - /** |
|
| 683 | - * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
| 684 | - * |
|
| 685 | - * @return void |
|
| 686 | - */ |
|
| 687 | - private function _parse_model_names() |
|
| 688 | - { |
|
| 689 | - //get all the files in the EE_MODELS folder that end in .model.php |
|
| 690 | - $models = glob(EE_MODELS . '*.model.php'); |
|
| 691 | - $model_names = array(); |
|
| 692 | - $non_abstract_db_models = array(); |
|
| 693 | - foreach ($models as $model) { |
|
| 694 | - // get model classname |
|
| 695 | - $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
| 696 | - $short_name = str_replace('EEM_', '', $classname); |
|
| 697 | - $reflectionClass = new ReflectionClass($classname); |
|
| 698 | - if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
| 699 | - $non_abstract_db_models[$short_name] = $classname; |
|
| 700 | - } |
|
| 701 | - $model_names[$short_name] = $classname; |
|
| 702 | - } |
|
| 703 | - $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
| 704 | - $this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names', |
|
| 705 | - $non_abstract_db_models); |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - |
|
| 709 | - |
|
| 710 | - /** |
|
| 711 | - * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
| 712 | - * that need to be setup before our EE_System launches. |
|
| 713 | - * |
|
| 714 | - * @return void |
|
| 715 | - */ |
|
| 716 | - private function _maybe_brew_regular() |
|
| 717 | - { |
|
| 718 | - if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
| 719 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
| 720 | - } |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - |
|
| 724 | - |
|
| 725 | - /** |
|
| 726 | - * register_shortcodes_modules_and_widgets |
|
| 727 | - * generate lists of shortcodes and modules, then verify paths and classes |
|
| 728 | - * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
| 729 | - * which runs during the WP 'plugins_loaded' action at priority 7 |
|
| 730 | - * |
|
| 731 | - * @access public |
|
| 732 | - * @return void |
|
| 733 | - */ |
|
| 734 | - public function register_shortcodes_modules_and_widgets() |
|
| 735 | - { |
|
| 736 | - do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
| 737 | - // check for addons using old hookpoint |
|
| 738 | - if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
| 739 | - $this->_incompatible_addon_error(); |
|
| 740 | - } |
|
| 741 | - } |
|
| 742 | - |
|
| 743 | - |
|
| 744 | - |
|
| 745 | - /** |
|
| 746 | - * _incompatible_addon_error |
|
| 747 | - * |
|
| 748 | - * @access public |
|
| 749 | - * @return void |
|
| 750 | - */ |
|
| 751 | - private function _incompatible_addon_error() |
|
| 752 | - { |
|
| 753 | - // get array of classes hooking into here |
|
| 754 | - $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons'); |
|
| 755 | - if ( ! empty($class_names)) { |
|
| 756 | - $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
| 757 | - 'event_espresso'); |
|
| 758 | - $msg .= '<ul>'; |
|
| 759 | - foreach ($class_names as $class_name) { |
|
| 760 | - $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
| 761 | - $class_name) . '</b></li>'; |
|
| 762 | - } |
|
| 763 | - $msg .= '</ul>'; |
|
| 764 | - $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
| 765 | - 'event_espresso'); |
|
| 766 | - // save list of incompatible addons to wp-options for later use |
|
| 767 | - add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
| 768 | - if (is_admin()) { |
|
| 769 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 770 | - } |
|
| 771 | - } |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - |
|
| 775 | - |
|
| 776 | - /** |
|
| 777 | - * brew_espresso |
|
| 778 | - * begins the process of setting hooks for initializing EE in the correct order |
|
| 779 | - * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint |
|
| 780 | - * which runs during the WP 'plugins_loaded' action at priority 9 |
|
| 781 | - * |
|
| 782 | - * @return void |
|
| 783 | - */ |
|
| 784 | - public function brew_espresso() |
|
| 785 | - { |
|
| 786 | - do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
| 787 | - // load some final core systems |
|
| 788 | - add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
| 789 | - add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
| 790 | - add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
| 791 | - add_action('init', array($this, 'load_controllers'), 7); |
|
| 792 | - add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
| 793 | - add_action('init', array($this, 'initialize'), 10); |
|
| 794 | - add_action('init', array($this, 'initialize_last'), 100); |
|
| 795 | - add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 100); |
|
| 796 | - add_action('admin_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 100); |
|
| 797 | - add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100); |
|
| 798 | - if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
| 799 | - // pew pew pew |
|
| 800 | - $this->registry->load_core('PUE'); |
|
| 801 | - do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
| 802 | - } |
|
| 803 | - do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - |
|
| 807 | - |
|
| 808 | - /** |
|
| 809 | - * set_hooks_for_core |
|
| 810 | - * |
|
| 811 | - * @access public |
|
| 812 | - * @return void |
|
| 813 | - */ |
|
| 814 | - public function set_hooks_for_core() |
|
| 815 | - { |
|
| 816 | - $this->_deactivate_incompatible_addons(); |
|
| 817 | - do_action('AHEE__EE_System__set_hooks_for_core'); |
|
| 818 | - } |
|
| 819 | - |
|
| 820 | - |
|
| 821 | - |
|
| 822 | - /** |
|
| 823 | - * Using the information gathered in EE_System::_incompatible_addon_error, |
|
| 824 | - * deactivates any addons considered incompatible with the current version of EE |
|
| 825 | - */ |
|
| 826 | - private function _deactivate_incompatible_addons() |
|
| 827 | - { |
|
| 828 | - $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
| 829 | - if ( ! empty($incompatible_addons)) { |
|
| 830 | - $active_plugins = get_option('active_plugins', array()); |
|
| 831 | - foreach ($active_plugins as $active_plugin) { |
|
| 832 | - foreach ($incompatible_addons as $incompatible_addon) { |
|
| 833 | - if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
| 834 | - unset($_GET['activate']); |
|
| 835 | - espresso_deactivate_plugin($active_plugin); |
|
| 836 | - } |
|
| 837 | - } |
|
| 838 | - } |
|
| 839 | - } |
|
| 840 | - } |
|
| 841 | - |
|
| 842 | - |
|
| 843 | - |
|
| 844 | - /** |
|
| 845 | - * perform_activations_upgrades_and_migrations |
|
| 846 | - * |
|
| 847 | - * @access public |
|
| 848 | - * @return void |
|
| 849 | - */ |
|
| 850 | - public function perform_activations_upgrades_and_migrations() |
|
| 851 | - { |
|
| 852 | - //first check if we had previously attempted to setup EE's directories but failed |
|
| 853 | - if (EEH_Activation::upload_directories_incomplete()) { |
|
| 854 | - EEH_Activation::create_upload_directories(); |
|
| 855 | - } |
|
| 856 | - do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 857 | - } |
|
| 858 | - |
|
| 859 | - |
|
| 860 | - |
|
| 861 | - /** |
|
| 862 | - * load_CPTs_and_session |
|
| 863 | - * |
|
| 864 | - * @access public |
|
| 865 | - * @return void |
|
| 866 | - */ |
|
| 867 | - public function load_CPTs_and_session() |
|
| 868 | - { |
|
| 869 | - do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
| 870 | - // register Custom Post Types |
|
| 871 | - $this->registry->load_core('Register_CPTs'); |
|
| 872 | - do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
| 873 | - } |
|
| 874 | - |
|
| 875 | - |
|
| 876 | - |
|
| 877 | - /** |
|
| 878 | - * load_controllers |
|
| 879 | - * this is the best place to load any additional controllers that needs access to EE core. |
|
| 880 | - * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
| 881 | - * time |
|
| 882 | - * |
|
| 883 | - * @access public |
|
| 884 | - * @return void |
|
| 885 | - */ |
|
| 886 | - public function load_controllers() |
|
| 887 | - { |
|
| 888 | - do_action('AHEE__EE_System__load_controllers__start'); |
|
| 889 | - // let's get it started |
|
| 890 | - if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
| 891 | - do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
| 892 | - $this->registry->load_core('Front_Controller', array(), false, true); |
|
| 893 | - } else if ( ! EE_FRONT_AJAX) { |
|
| 894 | - do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
| 895 | - EE_Registry::instance()->load_core('Admin'); |
|
| 896 | - } |
|
| 897 | - do_action('AHEE__EE_System__load_controllers__complete'); |
|
| 898 | - } |
|
| 899 | - |
|
| 900 | - |
|
| 901 | - |
|
| 902 | - /** |
|
| 903 | - * core_loaded_and_ready |
|
| 904 | - * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
| 905 | - * |
|
| 906 | - * @access public |
|
| 907 | - * @return void |
|
| 908 | - */ |
|
| 909 | - public function core_loaded_and_ready() |
|
| 910 | - { |
|
| 911 | - do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
| 912 | - do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
| 913 | - $this->registry->load_core('Session'); |
|
| 914 | - // add_action( 'wp_loaded', array( $this, 'set_hooks_for_shortcodes_modules_and_addons' ), 1 ); |
|
| 915 | - } |
|
| 916 | - |
|
| 917 | - |
|
| 918 | - |
|
| 919 | - /** |
|
| 920 | - * initialize |
|
| 921 | - * this is the best place to begin initializing client code |
|
| 922 | - * |
|
| 923 | - * @access public |
|
| 924 | - * @return void |
|
| 925 | - */ |
|
| 926 | - public function initialize() |
|
| 927 | - { |
|
| 928 | - do_action('AHEE__EE_System__initialize'); |
|
| 929 | - } |
|
| 930 | - |
|
| 931 | - |
|
| 932 | - |
|
| 933 | - /** |
|
| 934 | - * initialize_last |
|
| 935 | - * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to |
|
| 936 | - * initialize has done so |
|
| 937 | - * |
|
| 938 | - * @access public |
|
| 939 | - * @return void |
|
| 940 | - */ |
|
| 941 | - public function initialize_last() |
|
| 942 | - { |
|
| 943 | - do_action('AHEE__EE_System__initialize_last'); |
|
| 944 | - } |
|
| 945 | - |
|
| 946 | - |
|
| 947 | - |
|
| 948 | - /** |
|
| 949 | - * set_hooks_for_shortcodes_modules_and_addons |
|
| 950 | - * this is the best place for other systems to set callbacks for hooking into other parts of EE |
|
| 951 | - * this happens at the very beginning of the wp_loaded hookpoint |
|
| 952 | - * |
|
| 953 | - * @access public |
|
| 954 | - * @return void |
|
| 955 | - */ |
|
| 956 | - public function set_hooks_for_shortcodes_modules_and_addons() |
|
| 957 | - { |
|
| 958 | - // do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' ); |
|
| 959 | - } |
|
| 960 | - |
|
| 961 | - |
|
| 962 | - |
|
| 963 | - /** |
|
| 964 | - * do_not_cache |
|
| 965 | - * sets no cache headers and defines no cache constants for WP plugins |
|
| 966 | - * |
|
| 967 | - * @access public |
|
| 968 | - * @return void |
|
| 969 | - */ |
|
| 970 | - public static function do_not_cache() |
|
| 971 | - { |
|
| 972 | - // set no cache constants |
|
| 973 | - if ( ! defined('DONOTCACHEPAGE')) { |
|
| 974 | - define('DONOTCACHEPAGE', true); |
|
| 975 | - } |
|
| 976 | - if ( ! defined('DONOTCACHCEOBJECT')) { |
|
| 977 | - define('DONOTCACHCEOBJECT', true); |
|
| 978 | - } |
|
| 979 | - if ( ! defined('DONOTCACHEDB')) { |
|
| 980 | - define('DONOTCACHEDB', true); |
|
| 981 | - } |
|
| 982 | - // add no cache headers |
|
| 983 | - add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
| 984 | - // plus a little extra for nginx and Google Chrome |
|
| 985 | - add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
| 986 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
| 987 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
| 988 | - } |
|
| 989 | - |
|
| 990 | - |
|
| 991 | - |
|
| 992 | - /** |
|
| 993 | - * extra_nocache_headers |
|
| 994 | - * |
|
| 995 | - * @access public |
|
| 996 | - * @param $headers |
|
| 997 | - * @return array |
|
| 998 | - */ |
|
| 999 | - public static function extra_nocache_headers($headers) |
|
| 1000 | - { |
|
| 1001 | - // for NGINX |
|
| 1002 | - $headers['X-Accel-Expires'] = 0; |
|
| 1003 | - // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
| 1004 | - $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
| 1005 | - return $headers; |
|
| 1006 | - } |
|
| 1007 | - |
|
| 1008 | - |
|
| 1009 | - |
|
| 1010 | - /** |
|
| 1011 | - * nocache_headers |
|
| 1012 | - * |
|
| 1013 | - * @access public |
|
| 1014 | - * @return void |
|
| 1015 | - */ |
|
| 1016 | - public static function nocache_headers() |
|
| 1017 | - { |
|
| 1018 | - nocache_headers(); |
|
| 1019 | - } |
|
| 1020 | - |
|
| 1021 | - |
|
| 1022 | - |
|
| 1023 | - /** |
|
| 1024 | - * espresso_toolbar_items |
|
| 1025 | - * |
|
| 1026 | - * @access public |
|
| 1027 | - * @param WP_Admin_Bar $admin_bar |
|
| 1028 | - * @return void |
|
| 1029 | - */ |
|
| 1030 | - public function espresso_toolbar_items(WP_Admin_Bar $admin_bar) |
|
| 1031 | - { |
|
| 1032 | - // if in full M-Mode, or its an AJAX request, or user is NOT an admin |
|
| 1033 | - if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1034 | - || defined('DOING_AJAX') |
|
| 1035 | - || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
| 1036 | - ) { |
|
| 1037 | - return; |
|
| 1038 | - } |
|
| 1039 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1040 | - $menu_class = 'espresso_menu_item_class'; |
|
| 1041 | - //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
| 1042 | - //because they're only defined in each of their respective constructors |
|
| 1043 | - //and this might be a frontend request, in which case they aren't available |
|
| 1044 | - $events_admin_url = admin_url("admin.php?page=espresso_events"); |
|
| 1045 | - $reg_admin_url = admin_url("admin.php?page=espresso_registrations"); |
|
| 1046 | - $extensions_admin_url = admin_url("admin.php?page=espresso_packages"); |
|
| 1047 | - //Top Level |
|
| 1048 | - $admin_bar->add_menu(array( |
|
| 1049 | - 'id' => 'espresso-toolbar', |
|
| 1050 | - 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
| 1051 | - . _x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
| 1052 | - . '</span>', |
|
| 1053 | - 'href' => $events_admin_url, |
|
| 1054 | - 'meta' => array( |
|
| 1055 | - 'title' => __('Event Espresso', 'event_espresso'), |
|
| 1056 | - 'class' => $menu_class . 'first', |
|
| 1057 | - ), |
|
| 1058 | - )); |
|
| 1059 | - //Events |
|
| 1060 | - if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) { |
|
| 1061 | - $admin_bar->add_menu(array( |
|
| 1062 | - 'id' => 'espresso-toolbar-events', |
|
| 1063 | - 'parent' => 'espresso-toolbar', |
|
| 1064 | - 'title' => __('Events', 'event_espresso'), |
|
| 1065 | - 'href' => $events_admin_url, |
|
| 1066 | - 'meta' => array( |
|
| 1067 | - 'title' => __('Events', 'event_espresso'), |
|
| 1068 | - 'target' => '', |
|
| 1069 | - 'class' => $menu_class, |
|
| 1070 | - ), |
|
| 1071 | - )); |
|
| 1072 | - } |
|
| 1073 | - if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) { |
|
| 1074 | - //Events Add New |
|
| 1075 | - $admin_bar->add_menu(array( |
|
| 1076 | - 'id' => 'espresso-toolbar-events-new', |
|
| 1077 | - 'parent' => 'espresso-toolbar-events', |
|
| 1078 | - 'title' => __('Add New', 'event_espresso'), |
|
| 1079 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url), |
|
| 1080 | - 'meta' => array( |
|
| 1081 | - 'title' => __('Add New', 'event_espresso'), |
|
| 1082 | - 'target' => '', |
|
| 1083 | - 'class' => $menu_class, |
|
| 1084 | - ), |
|
| 1085 | - )); |
|
| 1086 | - } |
|
| 1087 | - if (is_single() && (get_post_type() == 'espresso_events')) { |
|
| 1088 | - //Current post |
|
| 1089 | - global $post; |
|
| 1090 | - if ($this->registry->CAP->current_user_can('ee_edit_event', |
|
| 1091 | - 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID) |
|
| 1092 | - ) { |
|
| 1093 | - //Events Edit Current Event |
|
| 1094 | - $admin_bar->add_menu(array( |
|
| 1095 | - 'id' => 'espresso-toolbar-events-edit', |
|
| 1096 | - 'parent' => 'espresso-toolbar-events', |
|
| 1097 | - 'title' => __('Edit Event', 'event_espresso'), |
|
| 1098 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID), |
|
| 1099 | - $events_admin_url), |
|
| 1100 | - 'meta' => array( |
|
| 1101 | - 'title' => __('Edit Event', 'event_espresso'), |
|
| 1102 | - 'target' => '', |
|
| 1103 | - 'class' => $menu_class, |
|
| 1104 | - ), |
|
| 1105 | - )); |
|
| 1106 | - } |
|
| 1107 | - } |
|
| 1108 | - //Events View |
|
| 1109 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
| 1110 | - 'ee_admin_bar_menu_espresso-toolbar-events-view') |
|
| 1111 | - ) { |
|
| 1112 | - $admin_bar->add_menu(array( |
|
| 1113 | - 'id' => 'espresso-toolbar-events-view', |
|
| 1114 | - 'parent' => 'espresso-toolbar-events', |
|
| 1115 | - 'title' => __('View', 'event_espresso'), |
|
| 1116 | - 'href' => $events_admin_url, |
|
| 1117 | - 'meta' => array( |
|
| 1118 | - 'title' => __('View', 'event_espresso'), |
|
| 1119 | - 'target' => '', |
|
| 1120 | - 'class' => $menu_class, |
|
| 1121 | - ), |
|
| 1122 | - )); |
|
| 1123 | - } |
|
| 1124 | - if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) { |
|
| 1125 | - //Events View All |
|
| 1126 | - $admin_bar->add_menu(array( |
|
| 1127 | - 'id' => 'espresso-toolbar-events-all', |
|
| 1128 | - 'parent' => 'espresso-toolbar-events-view', |
|
| 1129 | - 'title' => __('All', 'event_espresso'), |
|
| 1130 | - 'href' => $events_admin_url, |
|
| 1131 | - 'meta' => array( |
|
| 1132 | - 'title' => __('All', 'event_espresso'), |
|
| 1133 | - 'target' => '', |
|
| 1134 | - 'class' => $menu_class, |
|
| 1135 | - ), |
|
| 1136 | - )); |
|
| 1137 | - } |
|
| 1138 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
| 1139 | - 'ee_admin_bar_menu_espresso-toolbar-events-today') |
|
| 1140 | - ) { |
|
| 1141 | - //Events View Today |
|
| 1142 | - $admin_bar->add_menu(array( |
|
| 1143 | - 'id' => 'espresso-toolbar-events-today', |
|
| 1144 | - 'parent' => 'espresso-toolbar-events-view', |
|
| 1145 | - 'title' => __('Today', 'event_espresso'), |
|
| 1146 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
| 1147 | - $events_admin_url), |
|
| 1148 | - 'meta' => array( |
|
| 1149 | - 'title' => __('Today', 'event_espresso'), |
|
| 1150 | - 'target' => '', |
|
| 1151 | - 'class' => $menu_class, |
|
| 1152 | - ), |
|
| 1153 | - )); |
|
| 1154 | - } |
|
| 1155 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
| 1156 | - 'ee_admin_bar_menu_espresso-toolbar-events-month') |
|
| 1157 | - ) { |
|
| 1158 | - //Events View This Month |
|
| 1159 | - $admin_bar->add_menu(array( |
|
| 1160 | - 'id' => 'espresso-toolbar-events-month', |
|
| 1161 | - 'parent' => 'espresso-toolbar-events-view', |
|
| 1162 | - 'title' => __('This Month', 'event_espresso'), |
|
| 1163 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
| 1164 | - $events_admin_url), |
|
| 1165 | - 'meta' => array( |
|
| 1166 | - 'title' => __('This Month', 'event_espresso'), |
|
| 1167 | - 'target' => '', |
|
| 1168 | - 'class' => $menu_class, |
|
| 1169 | - ), |
|
| 1170 | - )); |
|
| 1171 | - } |
|
| 1172 | - //Registration Overview |
|
| 1173 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1174 | - 'ee_admin_bar_menu_espresso-toolbar-registrations') |
|
| 1175 | - ) { |
|
| 1176 | - $admin_bar->add_menu(array( |
|
| 1177 | - 'id' => 'espresso-toolbar-registrations', |
|
| 1178 | - 'parent' => 'espresso-toolbar', |
|
| 1179 | - 'title' => __('Registrations', 'event_espresso'), |
|
| 1180 | - 'href' => $reg_admin_url, |
|
| 1181 | - 'meta' => array( |
|
| 1182 | - 'title' => __('Registrations', 'event_espresso'), |
|
| 1183 | - 'target' => '', |
|
| 1184 | - 'class' => $menu_class, |
|
| 1185 | - ), |
|
| 1186 | - )); |
|
| 1187 | - } |
|
| 1188 | - //Registration Overview Today |
|
| 1189 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1190 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today') |
|
| 1191 | - ) { |
|
| 1192 | - $admin_bar->add_menu(array( |
|
| 1193 | - 'id' => 'espresso-toolbar-registrations-today', |
|
| 1194 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 1195 | - 'title' => __('Today', 'event_espresso'), |
|
| 1196 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
| 1197 | - $reg_admin_url), |
|
| 1198 | - 'meta' => array( |
|
| 1199 | - 'title' => __('Today', 'event_espresso'), |
|
| 1200 | - 'target' => '', |
|
| 1201 | - 'class' => $menu_class, |
|
| 1202 | - ), |
|
| 1203 | - )); |
|
| 1204 | - } |
|
| 1205 | - //Registration Overview Today Completed |
|
| 1206 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1207 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved') |
|
| 1208 | - ) { |
|
| 1209 | - $admin_bar->add_menu(array( |
|
| 1210 | - 'id' => 'espresso-toolbar-registrations-today-approved', |
|
| 1211 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1212 | - 'title' => __('Approved', 'event_espresso'), |
|
| 1213 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1214 | - 'action' => 'default', |
|
| 1215 | - 'status' => 'today', |
|
| 1216 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1217 | - ), $reg_admin_url), |
|
| 1218 | - 'meta' => array( |
|
| 1219 | - 'title' => __('Approved', 'event_espresso'), |
|
| 1220 | - 'target' => '', |
|
| 1221 | - 'class' => $menu_class, |
|
| 1222 | - ), |
|
| 1223 | - )); |
|
| 1224 | - } |
|
| 1225 | - //Registration Overview Today Pending\ |
|
| 1226 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1227 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending') |
|
| 1228 | - ) { |
|
| 1229 | - $admin_bar->add_menu(array( |
|
| 1230 | - 'id' => 'espresso-toolbar-registrations-today-pending', |
|
| 1231 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1232 | - 'title' => __('Pending', 'event_espresso'), |
|
| 1233 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1234 | - 'action' => 'default', |
|
| 1235 | - 'status' => 'today', |
|
| 1236 | - 'reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1237 | - ), $reg_admin_url), |
|
| 1238 | - 'meta' => array( |
|
| 1239 | - 'title' => __('Pending Payment', 'event_espresso'), |
|
| 1240 | - 'target' => '', |
|
| 1241 | - 'class' => $menu_class, |
|
| 1242 | - ), |
|
| 1243 | - )); |
|
| 1244 | - } |
|
| 1245 | - //Registration Overview Today Incomplete |
|
| 1246 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1247 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved') |
|
| 1248 | - ) { |
|
| 1249 | - $admin_bar->add_menu(array( |
|
| 1250 | - 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
| 1251 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1252 | - 'title' => __('Not Approved', 'event_espresso'), |
|
| 1253 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1254 | - 'action' => 'default', |
|
| 1255 | - 'status' => 'today', |
|
| 1256 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1257 | - ), $reg_admin_url), |
|
| 1258 | - 'meta' => array( |
|
| 1259 | - 'title' => __('Not Approved', 'event_espresso'), |
|
| 1260 | - 'target' => '', |
|
| 1261 | - 'class' => $menu_class, |
|
| 1262 | - ), |
|
| 1263 | - )); |
|
| 1264 | - } |
|
| 1265 | - //Registration Overview Today Incomplete |
|
| 1266 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1267 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled') |
|
| 1268 | - ) { |
|
| 1269 | - $admin_bar->add_menu(array( |
|
| 1270 | - 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
| 1271 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1272 | - 'title' => __('Cancelled', 'event_espresso'), |
|
| 1273 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1274 | - 'action' => 'default', |
|
| 1275 | - 'status' => 'today', |
|
| 1276 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
| 1277 | - ), $reg_admin_url), |
|
| 1278 | - 'meta' => array( |
|
| 1279 | - 'title' => __('Cancelled', 'event_espresso'), |
|
| 1280 | - 'target' => '', |
|
| 1281 | - 'class' => $menu_class, |
|
| 1282 | - ), |
|
| 1283 | - )); |
|
| 1284 | - } |
|
| 1285 | - //Registration Overview This Month |
|
| 1286 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1287 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month') |
|
| 1288 | - ) { |
|
| 1289 | - $admin_bar->add_menu(array( |
|
| 1290 | - 'id' => 'espresso-toolbar-registrations-month', |
|
| 1291 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 1292 | - 'title' => __('This Month', 'event_espresso'), |
|
| 1293 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
| 1294 | - $reg_admin_url), |
|
| 1295 | - 'meta' => array( |
|
| 1296 | - 'title' => __('This Month', 'event_espresso'), |
|
| 1297 | - 'target' => '', |
|
| 1298 | - 'class' => $menu_class, |
|
| 1299 | - ), |
|
| 1300 | - )); |
|
| 1301 | - } |
|
| 1302 | - //Registration Overview This Month Approved |
|
| 1303 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1304 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved') |
|
| 1305 | - ) { |
|
| 1306 | - $admin_bar->add_menu(array( |
|
| 1307 | - 'id' => 'espresso-toolbar-registrations-month-approved', |
|
| 1308 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1309 | - 'title' => __('Approved', 'event_espresso'), |
|
| 1310 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1311 | - 'action' => 'default', |
|
| 1312 | - 'status' => 'month', |
|
| 1313 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1314 | - ), $reg_admin_url), |
|
| 1315 | - 'meta' => array( |
|
| 1316 | - 'title' => __('Approved', 'event_espresso'), |
|
| 1317 | - 'target' => '', |
|
| 1318 | - 'class' => $menu_class, |
|
| 1319 | - ), |
|
| 1320 | - )); |
|
| 1321 | - } |
|
| 1322 | - //Registration Overview This Month Pending |
|
| 1323 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1324 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending') |
|
| 1325 | - ) { |
|
| 1326 | - $admin_bar->add_menu(array( |
|
| 1327 | - 'id' => 'espresso-toolbar-registrations-month-pending', |
|
| 1328 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1329 | - 'title' => __('Pending', 'event_espresso'), |
|
| 1330 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1331 | - 'action' => 'default', |
|
| 1332 | - 'status' => 'month', |
|
| 1333 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1334 | - ), $reg_admin_url), |
|
| 1335 | - 'meta' => array( |
|
| 1336 | - 'title' => __('Pending', 'event_espresso'), |
|
| 1337 | - 'target' => '', |
|
| 1338 | - 'class' => $menu_class, |
|
| 1339 | - ), |
|
| 1340 | - )); |
|
| 1341 | - } |
|
| 1342 | - //Registration Overview This Month Not Approved |
|
| 1343 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1344 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved') |
|
| 1345 | - ) { |
|
| 1346 | - $admin_bar->add_menu(array( |
|
| 1347 | - 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
| 1348 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1349 | - 'title' => __('Not Approved', 'event_espresso'), |
|
| 1350 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1351 | - 'action' => 'default', |
|
| 1352 | - 'status' => 'month', |
|
| 1353 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1354 | - ), $reg_admin_url), |
|
| 1355 | - 'meta' => array( |
|
| 1356 | - 'title' => __('Not Approved', 'event_espresso'), |
|
| 1357 | - 'target' => '', |
|
| 1358 | - 'class' => $menu_class, |
|
| 1359 | - ), |
|
| 1360 | - )); |
|
| 1361 | - } |
|
| 1362 | - //Registration Overview This Month Cancelled |
|
| 1363 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1364 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled') |
|
| 1365 | - ) { |
|
| 1366 | - $admin_bar->add_menu(array( |
|
| 1367 | - 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
| 1368 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1369 | - 'title' => __('Cancelled', 'event_espresso'), |
|
| 1370 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1371 | - 'action' => 'default', |
|
| 1372 | - 'status' => 'month', |
|
| 1373 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
| 1374 | - ), $reg_admin_url), |
|
| 1375 | - 'meta' => array( |
|
| 1376 | - 'title' => __('Cancelled', 'event_espresso'), |
|
| 1377 | - 'target' => '', |
|
| 1378 | - 'class' => $menu_class, |
|
| 1379 | - ), |
|
| 1380 | - )); |
|
| 1381 | - } |
|
| 1382 | - //Extensions & Services |
|
| 1383 | - if ($this->registry->CAP->current_user_can('ee_read_ee', |
|
| 1384 | - 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services') |
|
| 1385 | - ) { |
|
| 1386 | - $admin_bar->add_menu(array( |
|
| 1387 | - 'id' => 'espresso-toolbar-extensions-and-services', |
|
| 1388 | - 'parent' => 'espresso-toolbar', |
|
| 1389 | - 'title' => __('Extensions & Services', 'event_espresso'), |
|
| 1390 | - 'href' => $extensions_admin_url, |
|
| 1391 | - 'meta' => array( |
|
| 1392 | - 'title' => __('Extensions & Services', 'event_espresso'), |
|
| 1393 | - 'target' => '', |
|
| 1394 | - 'class' => $menu_class, |
|
| 1395 | - ), |
|
| 1396 | - )); |
|
| 1397 | - } |
|
| 1398 | - } |
|
| 1399 | - |
|
| 1400 | - |
|
| 1401 | - |
|
| 1402 | - /** |
|
| 1403 | - * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
| 1404 | - * never returned with the function. |
|
| 1405 | - * |
|
| 1406 | - * @param array $exclude_array any existing pages being excluded are in this array. |
|
| 1407 | - * @return array |
|
| 1408 | - */ |
|
| 1409 | - public function remove_pages_from_wp_list_pages($exclude_array) |
|
| 1410 | - { |
|
| 1411 | - return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
| 1412 | - } |
|
| 1413 | - |
|
| 1414 | - |
|
| 1415 | - |
|
| 1416 | - |
|
| 1417 | - |
|
| 1418 | - |
|
| 1419 | - /*********************************************** WP_ENQUEUE_SCRIPTS HOOK ***********************************************/ |
|
| 1420 | - /** |
|
| 1421 | - * wp_enqueue_scripts |
|
| 1422 | - * |
|
| 1423 | - * @access public |
|
| 1424 | - * @return void |
|
| 1425 | - */ |
|
| 1426 | - public function wp_enqueue_scripts() |
|
| 1427 | - { |
|
| 1428 | - // unlike other systems, EE_System_scripts loading is turned ON by default, but prior to the init hook, can be turned off via: add_filter( 'FHEE_load_EE_System_scripts', '__return_false' ); |
|
| 1429 | - if (apply_filters('FHEE_load_EE_System_scripts', true)) { |
|
| 1430 | - // jquery_validate loading is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via: add_filter( 'FHEE_load_jquery_validate', '__return_true' ); |
|
| 1431 | - if (apply_filters('FHEE_load_jquery_validate', false)) { |
|
| 1432 | - // register jQuery Validate and additional methods |
|
| 1433 | - wp_register_script('jquery-validate', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 1434 | - array('jquery'), '1.15.0', true); |
|
| 1435 | - wp_register_script('jquery-validate-extra-methods', |
|
| 1436 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 1437 | - array('jquery', 'jquery-validate'), '1.15.0', true); |
|
| 1438 | - } |
|
| 1439 | - } |
|
| 1440 | - } |
|
| 19 | + /** |
|
| 20 | + * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
| 21 | + * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
| 22 | + */ |
|
| 23 | + const req_type_normal = 0; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Indicates this is a brand new installation of EE so we should install |
|
| 27 | + * tables and default data etc |
|
| 28 | + */ |
|
| 29 | + const req_type_new_activation = 1; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
| 33 | + * and we just exited maintenance mode). We MUST check the database is setup properly |
|
| 34 | + * and that default data is setup too |
|
| 35 | + */ |
|
| 36 | + const req_type_reactivation = 2; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * indicates that EE has been upgraded since its previous request. |
|
| 40 | + * We may have data migration scripts to call and will want to trigger maintenance mode |
|
| 41 | + */ |
|
| 42 | + const req_type_upgrade = 3; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
| 46 | + */ |
|
| 47 | + const req_type_downgrade = 4; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @deprecated since version 4.6.0.dev.006 |
|
| 51 | + * Now whenever a new_activation is detected the request type is still just |
|
| 52 | + * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
| 53 | + * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
| 54 | + * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
| 55 | + * (Specifically, when the migration manager indicates migrations are finished |
|
| 56 | + * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
| 57 | + */ |
|
| 58 | + const req_type_activation_but_not_installed = 5; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
| 62 | + */ |
|
| 63 | + const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * instance of the EE_System object |
|
| 68 | + * |
|
| 69 | + * @var $_instance |
|
| 70 | + * @access private |
|
| 71 | + */ |
|
| 72 | + private static $_instance = null; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @type EE_Registry $Registry |
|
| 76 | + * @access protected |
|
| 77 | + */ |
|
| 78 | + protected $registry; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
| 82 | + * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
| 83 | + * |
|
| 84 | + * @var int |
|
| 85 | + */ |
|
| 86 | + private $_req_type; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Whether or not there was a non-micro version change in EE core version during this request |
|
| 90 | + * |
|
| 91 | + * @var boolean |
|
| 92 | + */ |
|
| 93 | + private $_major_version_change = false; |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @singleton method used to instantiate class object |
|
| 99 | + * @access public |
|
| 100 | + * @param \EE_Registry $Registry |
|
| 101 | + * @return \EE_System |
|
| 102 | + */ |
|
| 103 | + public static function instance(EE_Registry $Registry = null) |
|
| 104 | + { |
|
| 105 | + // check if class object is instantiated |
|
| 106 | + if ( ! self::$_instance instanceof EE_System) { |
|
| 107 | + self::$_instance = new self($Registry); |
|
| 108 | + } |
|
| 109 | + return self::$_instance; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * resets the instance and returns it |
|
| 116 | + * |
|
| 117 | + * @return EE_System |
|
| 118 | + */ |
|
| 119 | + public static function reset() |
|
| 120 | + { |
|
| 121 | + self::$_instance->_req_type = null; |
|
| 122 | + //make sure none of the old hooks are left hanging around |
|
| 123 | + remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 124 | + //we need to reset the migration manager in order for it to detect DMSs properly |
|
| 125 | + EE_Data_Migration_Manager::reset(); |
|
| 126 | + self::instance()->detect_activations_or_upgrades(); |
|
| 127 | + self::instance()->perform_activations_upgrades_and_migrations(); |
|
| 128 | + return self::instance(); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * sets hooks for running rest of system |
|
| 135 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
| 136 | + * starting EE Addons from any other point may lead to problems |
|
| 137 | + * |
|
| 138 | + * @access private |
|
| 139 | + * @param \EE_Registry $Registry |
|
| 140 | + */ |
|
| 141 | + private function __construct(EE_Registry $Registry) |
|
| 142 | + { |
|
| 143 | + $this->registry = $Registry; |
|
| 144 | + do_action('AHEE__EE_System__construct__begin', $this); |
|
| 145 | + // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
| 146 | + add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons')); |
|
| 147 | + // when an ee addon is activated, we want to call the core hook(s) again |
|
| 148 | + // because the newly-activated addon didn't get a chance to run at all |
|
| 149 | + add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
| 150 | + // detect whether install or upgrade |
|
| 151 | + add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'), |
|
| 152 | + 3); |
|
| 153 | + // load EE_Config, EE_Textdomain, etc |
|
| 154 | + add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5); |
|
| 155 | + // load EE_Config, EE_Textdomain, etc |
|
| 156 | + add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
| 157 | + array($this, 'register_shortcodes_modules_and_widgets'), 7); |
|
| 158 | + // you wanna get going? I wanna get going... let's get going! |
|
| 159 | + add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9); |
|
| 160 | + //other housekeeping |
|
| 161 | + //exclude EE critical pages from wp_list_pages |
|
| 162 | + add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10); |
|
| 163 | + // ALL EE Addons should use the following hook point to attach their initial setup too |
|
| 164 | + // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
| 165 | + do_action('AHEE__EE_System__construct__complete', $this); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * load_espresso_addons |
|
| 172 | + * allow addons to load first so that they can set hooks for running DMS's, etc |
|
| 173 | + * this is hooked into both: |
|
| 174 | + * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 175 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 176 | + * and the WP 'activate_plugin' hookpoint |
|
| 177 | + * |
|
| 178 | + * @access public |
|
| 179 | + * @return void |
|
| 180 | + */ |
|
| 181 | + public function load_espresso_addons() |
|
| 182 | + { |
|
| 183 | + // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
| 184 | + // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
| 185 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
| 186 | + //load and setup EE_Capabilities |
|
| 187 | + $this->registry->load_core('Capabilities'); |
|
| 188 | + //caps need to be initialized on every request so that capability maps are set. |
|
| 189 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
| 190 | + $this->registry->CAP->init_caps(); |
|
| 191 | + do_action('AHEE__EE_System__load_espresso_addons'); |
|
| 192 | + //if the WP API basic auth plugin isn't already loaded, load it now. |
|
| 193 | + //We want it for mobile apps. Just include the entire plugin |
|
| 194 | + //also, don't load the basic auth when a plugin is getting activated, because |
|
| 195 | + //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
| 196 | + //and causes a fatal error |
|
| 197 | + if ( ! function_exists('json_basic_auth_handler') |
|
| 198 | + && ! function_exists('json_basic_auth_error') |
|
| 199 | + && ! ( |
|
| 200 | + isset($_GET['action']) |
|
| 201 | + && in_array($_GET['action'], array('activate', 'activate-selected')) |
|
| 202 | + ) |
|
| 203 | + && ! ( |
|
| 204 | + isset($_GET['activate']) |
|
| 205 | + && $_GET['activate'] === 'true' |
|
| 206 | + ) |
|
| 207 | + ) { |
|
| 208 | + include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
| 209 | + } |
|
| 210 | + do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * detect_activations_or_upgrades |
|
| 217 | + * Checks for activation or upgrade of core first; |
|
| 218 | + * then also checks if any registered addons have been activated or upgraded |
|
| 219 | + * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
| 220 | + * which runs during the WP 'plugins_loaded' action at priority 3 |
|
| 221 | + * |
|
| 222 | + * @access public |
|
| 223 | + * @return void |
|
| 224 | + */ |
|
| 225 | + public function detect_activations_or_upgrades() |
|
| 226 | + { |
|
| 227 | + //first off: let's make sure to handle core |
|
| 228 | + $this->detect_if_activation_or_upgrade(); |
|
| 229 | + foreach ($this->registry->addons as $addon) { |
|
| 230 | + //detect teh request type for that addon |
|
| 231 | + $addon->detect_activation_or_upgrade(); |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * detect_if_activation_or_upgrade |
|
| 239 | + * Takes care of detecting whether this is a brand new install or code upgrade, |
|
| 240 | + * and either setting up the DB or setting up maintenance mode etc. |
|
| 241 | + * |
|
| 242 | + * @access public |
|
| 243 | + * @return void |
|
| 244 | + */ |
|
| 245 | + public function detect_if_activation_or_upgrade() |
|
| 246 | + { |
|
| 247 | + do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
| 248 | + // load M-Mode class |
|
| 249 | + $this->registry->load_core('Maintenance_Mode'); |
|
| 250 | + // check if db has been updated, or if its a brand-new installation |
|
| 251 | + $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
| 252 | + $request_type = $this->detect_req_type($espresso_db_update); |
|
| 253 | + //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
| 254 | + switch ($request_type) { |
|
| 255 | + case EE_System::req_type_new_activation: |
|
| 256 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
| 257 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 258 | + break; |
|
| 259 | + case EE_System::req_type_reactivation: |
|
| 260 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
| 261 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 262 | + break; |
|
| 263 | + case EE_System::req_type_upgrade: |
|
| 264 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
| 265 | + //migrations may be required now that we've upgraded |
|
| 266 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 267 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 268 | + // echo "done upgrade";die; |
|
| 269 | + break; |
|
| 270 | + case EE_System::req_type_downgrade: |
|
| 271 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
| 272 | + //its possible migrations are no longer required |
|
| 273 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 274 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 275 | + break; |
|
| 276 | + case EE_System::req_type_normal: |
|
| 277 | + default: |
|
| 278 | + // $this->_maybe_redirect_to_ee_about(); |
|
| 279 | + break; |
|
| 280 | + } |
|
| 281 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * Updates the list of installed versions and sets hooks for |
|
| 288 | + * initializing the database later during the request |
|
| 289 | + * |
|
| 290 | + * @param array $espresso_db_update |
|
| 291 | + */ |
|
| 292 | + protected function _handle_core_version_change($espresso_db_update) |
|
| 293 | + { |
|
| 294 | + $this->update_list_of_installed_versions($espresso_db_update); |
|
| 295 | + //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
| 296 | + add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 297 | + array($this, 'initialize_db_if_no_migrations_required')); |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
| 304 | + * information about what versions of EE have been installed and activated, |
|
| 305 | + * NOT necessarily the state of the database |
|
| 306 | + * |
|
| 307 | + * @param null $espresso_db_update |
|
| 308 | + * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it |
|
| 309 | + * from the options table |
|
| 310 | + * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
| 311 | + */ |
|
| 312 | + private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
| 313 | + { |
|
| 314 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
| 315 | + if ( ! $espresso_db_update) { |
|
| 316 | + $espresso_db_update = get_option('espresso_db_update'); |
|
| 317 | + } |
|
| 318 | + // check that option is an array |
|
| 319 | + if ( ! is_array($espresso_db_update)) { |
|
| 320 | + // if option is FALSE, then it never existed |
|
| 321 | + if ($espresso_db_update === false) { |
|
| 322 | + // make $espresso_db_update an array and save option with autoload OFF |
|
| 323 | + $espresso_db_update = array(); |
|
| 324 | + add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
| 325 | + } else { |
|
| 326 | + // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
| 327 | + $espresso_db_update = array($espresso_db_update => array()); |
|
| 328 | + update_option('espresso_db_update', $espresso_db_update); |
|
| 329 | + } |
|
| 330 | + } else { |
|
| 331 | + $corrected_db_update = array(); |
|
| 332 | + //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
| 333 | + foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
| 334 | + if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
| 335 | + //the key is an int, and the value IS NOT an array |
|
| 336 | + //so it must be numerically-indexed, where values are versions installed... |
|
| 337 | + //fix it! |
|
| 338 | + $version_string = $should_be_array; |
|
| 339 | + $corrected_db_update[$version_string] = array('unknown-date'); |
|
| 340 | + } else { |
|
| 341 | + //ok it checks out |
|
| 342 | + $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
| 343 | + } |
|
| 344 | + } |
|
| 345 | + $espresso_db_update = $corrected_db_update; |
|
| 346 | + update_option('espresso_db_update', $espresso_db_update); |
|
| 347 | + } |
|
| 348 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
| 349 | + return $espresso_db_update; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * Does the traditional work of setting up the plugin's database and adding default data. |
|
| 356 | + * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
| 357 | + * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
| 358 | + * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
| 359 | + * so that it will be done when migrations are finished |
|
| 360 | + * |
|
| 361 | + * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
| 362 | + * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
| 363 | + * This is a resource-intensive job |
|
| 364 | + * so we prefer to only do it when necessary |
|
| 365 | + * @return void |
|
| 366 | + */ |
|
| 367 | + public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
| 368 | + { |
|
| 369 | + $request_type = $this->detect_req_type(); |
|
| 370 | + //only initialize system if we're not in maintenance mode. |
|
| 371 | + if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 372 | + update_option('ee_flush_rewrite_rules', true); |
|
| 373 | + if ($verify_schema) { |
|
| 374 | + EEH_Activation::initialize_db_and_folders(); |
|
| 375 | + } |
|
| 376 | + EEH_Activation::initialize_db_content(); |
|
| 377 | + EEH_Activation::system_initialization(); |
|
| 378 | + if ($initialize_addons_too) { |
|
| 379 | + $this->initialize_addons(); |
|
| 380 | + } |
|
| 381 | + } else { |
|
| 382 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
| 383 | + } |
|
| 384 | + if ($request_type === EE_System::req_type_new_activation |
|
| 385 | + || $request_type === EE_System::req_type_reactivation |
|
| 386 | + || ( |
|
| 387 | + $request_type === EE_System::req_type_upgrade |
|
| 388 | + && $this->is_major_version_change() |
|
| 389 | + ) |
|
| 390 | + ) { |
|
| 391 | + add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * Initializes the db for all registered addons |
|
| 399 | + */ |
|
| 400 | + public function initialize_addons() |
|
| 401 | + { |
|
| 402 | + //foreach registered addon, make sure its db is up-to-date too |
|
| 403 | + foreach ($this->registry->addons as $addon) { |
|
| 404 | + $addon->initialize_db_if_no_migrations_required(); |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
| 412 | + * |
|
| 413 | + * @param array $version_history |
|
| 414 | + * @param string $current_version_to_add version to be added to the version history |
|
| 415 | + * @return boolean success as to whether or not this option was changed |
|
| 416 | + */ |
|
| 417 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
| 418 | + { |
|
| 419 | + if ( ! $version_history) { |
|
| 420 | + $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
| 421 | + } |
|
| 422 | + if ($current_version_to_add == null) { |
|
| 423 | + $current_version_to_add = espresso_version(); |
|
| 424 | + } |
|
| 425 | + $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
| 426 | + // re-save |
|
| 427 | + return update_option('espresso_db_update', $version_history); |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * Detects if the current version indicated in the has existed in the list of |
|
| 434 | + * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
| 435 | + * |
|
| 436 | + * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
| 437 | + * If not supplied, fetches it from the options table. |
|
| 438 | + * Also, caches its result so later parts of the code can also know whether |
|
| 439 | + * there's been an update or not. This way we can add the current version to |
|
| 440 | + * espresso_db_update, but still know if this is a new install or not |
|
| 441 | + * @return int one of the constants on EE_System::req_type_ |
|
| 442 | + */ |
|
| 443 | + public function detect_req_type($espresso_db_update = null) |
|
| 444 | + { |
|
| 445 | + if ($this->_req_type === null) { |
|
| 446 | + $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update |
|
| 447 | + : $this->fix_espresso_db_upgrade_option(); |
|
| 448 | + $this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update, |
|
| 449 | + 'ee_espresso_activation', espresso_version()); |
|
| 450 | + $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
| 451 | + } |
|
| 452 | + return $this->_req_type; |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + |
|
| 456 | + |
|
| 457 | + /** |
|
| 458 | + * Returns whether or not there was a non-micro version change (ie, change in either |
|
| 459 | + * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
| 460 | + * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
| 461 | + * |
|
| 462 | + * @param $activation_history |
|
| 463 | + * @return bool |
|
| 464 | + */ |
|
| 465 | + protected function _detect_major_version_change($activation_history) |
|
| 466 | + { |
|
| 467 | + $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
| 468 | + $previous_version_parts = explode('.', $previous_version); |
|
| 469 | + $current_version_parts = explode('.', espresso_version()); |
|
| 470 | + return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
| 471 | + && ($previous_version_parts[0] !== $current_version_parts[0] |
|
| 472 | + || $previous_version_parts[1] !== $current_version_parts[1] |
|
| 473 | + ); |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * Returns true if either the major or minor version of EE changed during this request. |
|
| 480 | + * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
| 481 | + * |
|
| 482 | + * @return bool |
|
| 483 | + */ |
|
| 484 | + public function is_major_version_change() |
|
| 485 | + { |
|
| 486 | + return $this->_major_version_change; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
| 493 | + * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily |
|
| 494 | + * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
| 495 | + * just activated to (for core that will always be espresso_version()) |
|
| 496 | + * |
|
| 497 | + * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
| 498 | + * ee plugin. for core that's 'espresso_db_update' |
|
| 499 | + * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to |
|
| 500 | + * indicate that this plugin was just activated |
|
| 501 | + * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
| 502 | + * espresso_version()) |
|
| 503 | + * @return int one of the constants on EE_System::req_type_* |
|
| 504 | + */ |
|
| 505 | + public static function detect_req_type_given_activation_history( |
|
| 506 | + $activation_history_for_addon, |
|
| 507 | + $activation_indicator_option_name, |
|
| 508 | + $version_to_upgrade_to |
|
| 509 | + ) { |
|
| 510 | + $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
| 511 | + if ($activation_history_for_addon) { |
|
| 512 | + //it exists, so this isn't a completely new install |
|
| 513 | + //check if this version already in that list of previously installed versions |
|
| 514 | + if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
| 515 | + //it a version we haven't seen before |
|
| 516 | + if ($version_is_higher === 1) { |
|
| 517 | + $req_type = EE_System::req_type_upgrade; |
|
| 518 | + } else { |
|
| 519 | + $req_type = EE_System::req_type_downgrade; |
|
| 520 | + } |
|
| 521 | + delete_option($activation_indicator_option_name); |
|
| 522 | + } else { |
|
| 523 | + // its not an update. maybe a reactivation? |
|
| 524 | + if (get_option($activation_indicator_option_name, false)) { |
|
| 525 | + if ($version_is_higher === -1) { |
|
| 526 | + $req_type = EE_System::req_type_downgrade; |
|
| 527 | + } elseif ($version_is_higher === 0) { |
|
| 528 | + //we've seen this version before, but it's an activation. must be a reactivation |
|
| 529 | + $req_type = EE_System::req_type_reactivation; |
|
| 530 | + } else {//$version_is_higher === 1 |
|
| 531 | + $req_type = EE_System::req_type_upgrade; |
|
| 532 | + } |
|
| 533 | + delete_option($activation_indicator_option_name); |
|
| 534 | + } else { |
|
| 535 | + //we've seen this version before and the activation indicate doesn't show it was just activated |
|
| 536 | + if ($version_is_higher === -1) { |
|
| 537 | + $req_type = EE_System::req_type_downgrade; |
|
| 538 | + } elseif ($version_is_higher === 0) { |
|
| 539 | + //we've seen this version before and it's not an activation. its normal request |
|
| 540 | + $req_type = EE_System::req_type_normal; |
|
| 541 | + } else {//$version_is_higher === 1 |
|
| 542 | + $req_type = EE_System::req_type_upgrade; |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + } else { |
|
| 547 | + //brand new install |
|
| 548 | + $req_type = EE_System::req_type_new_activation; |
|
| 549 | + delete_option($activation_indicator_option_name); |
|
| 550 | + } |
|
| 551 | + return $req_type; |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
| 558 | + * the $activation_history_for_addon |
|
| 559 | + * |
|
| 560 | + * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
| 561 | + * sometimes containing 'unknown-date' |
|
| 562 | + * @param string $version_to_upgrade_to (current version) |
|
| 563 | + * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
| 564 | + * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
| 565 | + * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
| 566 | + * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
| 567 | + */ |
|
| 568 | + protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
| 569 | + { |
|
| 570 | + //find the most recently-activated version |
|
| 571 | + $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
| 572 | + return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * Gets the most recently active version listed in the activation history, |
|
| 579 | + * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
| 580 | + * |
|
| 581 | + * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
| 582 | + * sometimes containing 'unknown-date' |
|
| 583 | + * @return string |
|
| 584 | + */ |
|
| 585 | + protected static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
| 586 | + { |
|
| 587 | + $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
| 588 | + $most_recently_active_version = '0.0.0.dev.000'; |
|
| 589 | + if (is_array($activation_history)) { |
|
| 590 | + foreach ($activation_history as $version => $times_activated) { |
|
| 591 | + //check there is a record of when this version was activated. Otherwise, |
|
| 592 | + //mark it as unknown |
|
| 593 | + if ( ! $times_activated) { |
|
| 594 | + $times_activated = array('unknown-date'); |
|
| 595 | + } |
|
| 596 | + if (is_string($times_activated)) { |
|
| 597 | + $times_activated = array($times_activated); |
|
| 598 | + } |
|
| 599 | + foreach ($times_activated as $an_activation) { |
|
| 600 | + if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
| 601 | + $most_recently_active_version = $version; |
|
| 602 | + $most_recently_active_version_activation = $an_activation == 'unknown-date' |
|
| 603 | + ? '1970-01-01 00:00:00' : $an_activation; |
|
| 604 | + } |
|
| 605 | + } |
|
| 606 | + } |
|
| 607 | + } |
|
| 608 | + return $most_recently_active_version; |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + |
|
| 612 | + |
|
| 613 | + /** |
|
| 614 | + * This redirects to the about EE page after activation |
|
| 615 | + * |
|
| 616 | + * @return void |
|
| 617 | + */ |
|
| 618 | + public function redirect_to_about_ee() |
|
| 619 | + { |
|
| 620 | + $notices = EE_Error::get_notices(false); |
|
| 621 | + //if current user is an admin and it's not an ajax or rest request |
|
| 622 | + if ( |
|
| 623 | + ! (defined('DOING_AJAX') && DOING_AJAX) |
|
| 624 | + && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
| 625 | + && ! isset($notices['errors']) |
|
| 626 | + && apply_filters( |
|
| 627 | + 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
| 628 | + $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default') |
|
| 629 | + ) |
|
| 630 | + ) { |
|
| 631 | + $query_params = array('page' => 'espresso_about'); |
|
| 632 | + if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) { |
|
| 633 | + $query_params['new_activation'] = true; |
|
| 634 | + } |
|
| 635 | + if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) { |
|
| 636 | + $query_params['reactivation'] = true; |
|
| 637 | + } |
|
| 638 | + $url = add_query_arg($query_params, admin_url('admin.php')); |
|
| 639 | + wp_safe_redirect($url); |
|
| 640 | + exit(); |
|
| 641 | + } |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + |
|
| 645 | + |
|
| 646 | + /** |
|
| 647 | + * load_core_configuration |
|
| 648 | + * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 649 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 650 | + * |
|
| 651 | + * @return void |
|
| 652 | + */ |
|
| 653 | + public function load_core_configuration() |
|
| 654 | + { |
|
| 655 | + do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
| 656 | + $this->registry->load_core('EE_Load_Textdomain'); |
|
| 657 | + //load textdomain |
|
| 658 | + EE_Load_Textdomain::load_textdomain(); |
|
| 659 | + // load and setup EE_Config and EE_Network_Config |
|
| 660 | + $this->registry->load_core('Config'); |
|
| 661 | + $this->registry->load_core('Network_Config'); |
|
| 662 | + // setup autoloaders |
|
| 663 | + // enable logging? |
|
| 664 | + if ($this->registry->CFG->admin->use_full_logging) { |
|
| 665 | + $this->registry->load_core('Log'); |
|
| 666 | + } |
|
| 667 | + // check for activation errors |
|
| 668 | + $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
| 669 | + if ($activation_errors) { |
|
| 670 | + EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 671 | + update_option('ee_plugin_activation_errors', false); |
|
| 672 | + } |
|
| 673 | + // get model names |
|
| 674 | + $this->_parse_model_names(); |
|
| 675 | + //load caf stuff a chance to play during the activation process too. |
|
| 676 | + $this->_maybe_brew_regular(); |
|
| 677 | + do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
| 678 | + } |
|
| 679 | + |
|
| 680 | + |
|
| 681 | + |
|
| 682 | + /** |
|
| 683 | + * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
| 684 | + * |
|
| 685 | + * @return void |
|
| 686 | + */ |
|
| 687 | + private function _parse_model_names() |
|
| 688 | + { |
|
| 689 | + //get all the files in the EE_MODELS folder that end in .model.php |
|
| 690 | + $models = glob(EE_MODELS . '*.model.php'); |
|
| 691 | + $model_names = array(); |
|
| 692 | + $non_abstract_db_models = array(); |
|
| 693 | + foreach ($models as $model) { |
|
| 694 | + // get model classname |
|
| 695 | + $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
| 696 | + $short_name = str_replace('EEM_', '', $classname); |
|
| 697 | + $reflectionClass = new ReflectionClass($classname); |
|
| 698 | + if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
| 699 | + $non_abstract_db_models[$short_name] = $classname; |
|
| 700 | + } |
|
| 701 | + $model_names[$short_name] = $classname; |
|
| 702 | + } |
|
| 703 | + $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
| 704 | + $this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names', |
|
| 705 | + $non_abstract_db_models); |
|
| 706 | + } |
|
| 707 | + |
|
| 708 | + |
|
| 709 | + |
|
| 710 | + /** |
|
| 711 | + * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
| 712 | + * that need to be setup before our EE_System launches. |
|
| 713 | + * |
|
| 714 | + * @return void |
|
| 715 | + */ |
|
| 716 | + private function _maybe_brew_regular() |
|
| 717 | + { |
|
| 718 | + if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
| 719 | + require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
| 720 | + } |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + |
|
| 724 | + |
|
| 725 | + /** |
|
| 726 | + * register_shortcodes_modules_and_widgets |
|
| 727 | + * generate lists of shortcodes and modules, then verify paths and classes |
|
| 728 | + * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
| 729 | + * which runs during the WP 'plugins_loaded' action at priority 7 |
|
| 730 | + * |
|
| 731 | + * @access public |
|
| 732 | + * @return void |
|
| 733 | + */ |
|
| 734 | + public function register_shortcodes_modules_and_widgets() |
|
| 735 | + { |
|
| 736 | + do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
| 737 | + // check for addons using old hookpoint |
|
| 738 | + if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
| 739 | + $this->_incompatible_addon_error(); |
|
| 740 | + } |
|
| 741 | + } |
|
| 742 | + |
|
| 743 | + |
|
| 744 | + |
|
| 745 | + /** |
|
| 746 | + * _incompatible_addon_error |
|
| 747 | + * |
|
| 748 | + * @access public |
|
| 749 | + * @return void |
|
| 750 | + */ |
|
| 751 | + private function _incompatible_addon_error() |
|
| 752 | + { |
|
| 753 | + // get array of classes hooking into here |
|
| 754 | + $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons'); |
|
| 755 | + if ( ! empty($class_names)) { |
|
| 756 | + $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
| 757 | + 'event_espresso'); |
|
| 758 | + $msg .= '<ul>'; |
|
| 759 | + foreach ($class_names as $class_name) { |
|
| 760 | + $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
| 761 | + $class_name) . '</b></li>'; |
|
| 762 | + } |
|
| 763 | + $msg .= '</ul>'; |
|
| 764 | + $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
| 765 | + 'event_espresso'); |
|
| 766 | + // save list of incompatible addons to wp-options for later use |
|
| 767 | + add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
| 768 | + if (is_admin()) { |
|
| 769 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 770 | + } |
|
| 771 | + } |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + |
|
| 775 | + |
|
| 776 | + /** |
|
| 777 | + * brew_espresso |
|
| 778 | + * begins the process of setting hooks for initializing EE in the correct order |
|
| 779 | + * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint |
|
| 780 | + * which runs during the WP 'plugins_loaded' action at priority 9 |
|
| 781 | + * |
|
| 782 | + * @return void |
|
| 783 | + */ |
|
| 784 | + public function brew_espresso() |
|
| 785 | + { |
|
| 786 | + do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
| 787 | + // load some final core systems |
|
| 788 | + add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
| 789 | + add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
| 790 | + add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
| 791 | + add_action('init', array($this, 'load_controllers'), 7); |
|
| 792 | + add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
| 793 | + add_action('init', array($this, 'initialize'), 10); |
|
| 794 | + add_action('init', array($this, 'initialize_last'), 100); |
|
| 795 | + add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 100); |
|
| 796 | + add_action('admin_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 100); |
|
| 797 | + add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100); |
|
| 798 | + if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
| 799 | + // pew pew pew |
|
| 800 | + $this->registry->load_core('PUE'); |
|
| 801 | + do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
| 802 | + } |
|
| 803 | + do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + |
|
| 807 | + |
|
| 808 | + /** |
|
| 809 | + * set_hooks_for_core |
|
| 810 | + * |
|
| 811 | + * @access public |
|
| 812 | + * @return void |
|
| 813 | + */ |
|
| 814 | + public function set_hooks_for_core() |
|
| 815 | + { |
|
| 816 | + $this->_deactivate_incompatible_addons(); |
|
| 817 | + do_action('AHEE__EE_System__set_hooks_for_core'); |
|
| 818 | + } |
|
| 819 | + |
|
| 820 | + |
|
| 821 | + |
|
| 822 | + /** |
|
| 823 | + * Using the information gathered in EE_System::_incompatible_addon_error, |
|
| 824 | + * deactivates any addons considered incompatible with the current version of EE |
|
| 825 | + */ |
|
| 826 | + private function _deactivate_incompatible_addons() |
|
| 827 | + { |
|
| 828 | + $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
| 829 | + if ( ! empty($incompatible_addons)) { |
|
| 830 | + $active_plugins = get_option('active_plugins', array()); |
|
| 831 | + foreach ($active_plugins as $active_plugin) { |
|
| 832 | + foreach ($incompatible_addons as $incompatible_addon) { |
|
| 833 | + if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
| 834 | + unset($_GET['activate']); |
|
| 835 | + espresso_deactivate_plugin($active_plugin); |
|
| 836 | + } |
|
| 837 | + } |
|
| 838 | + } |
|
| 839 | + } |
|
| 840 | + } |
|
| 841 | + |
|
| 842 | + |
|
| 843 | + |
|
| 844 | + /** |
|
| 845 | + * perform_activations_upgrades_and_migrations |
|
| 846 | + * |
|
| 847 | + * @access public |
|
| 848 | + * @return void |
|
| 849 | + */ |
|
| 850 | + public function perform_activations_upgrades_and_migrations() |
|
| 851 | + { |
|
| 852 | + //first check if we had previously attempted to setup EE's directories but failed |
|
| 853 | + if (EEH_Activation::upload_directories_incomplete()) { |
|
| 854 | + EEH_Activation::create_upload_directories(); |
|
| 855 | + } |
|
| 856 | + do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 857 | + } |
|
| 858 | + |
|
| 859 | + |
|
| 860 | + |
|
| 861 | + /** |
|
| 862 | + * load_CPTs_and_session |
|
| 863 | + * |
|
| 864 | + * @access public |
|
| 865 | + * @return void |
|
| 866 | + */ |
|
| 867 | + public function load_CPTs_and_session() |
|
| 868 | + { |
|
| 869 | + do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
| 870 | + // register Custom Post Types |
|
| 871 | + $this->registry->load_core('Register_CPTs'); |
|
| 872 | + do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
| 873 | + } |
|
| 874 | + |
|
| 875 | + |
|
| 876 | + |
|
| 877 | + /** |
|
| 878 | + * load_controllers |
|
| 879 | + * this is the best place to load any additional controllers that needs access to EE core. |
|
| 880 | + * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
| 881 | + * time |
|
| 882 | + * |
|
| 883 | + * @access public |
|
| 884 | + * @return void |
|
| 885 | + */ |
|
| 886 | + public function load_controllers() |
|
| 887 | + { |
|
| 888 | + do_action('AHEE__EE_System__load_controllers__start'); |
|
| 889 | + // let's get it started |
|
| 890 | + if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
| 891 | + do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
| 892 | + $this->registry->load_core('Front_Controller', array(), false, true); |
|
| 893 | + } else if ( ! EE_FRONT_AJAX) { |
|
| 894 | + do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
| 895 | + EE_Registry::instance()->load_core('Admin'); |
|
| 896 | + } |
|
| 897 | + do_action('AHEE__EE_System__load_controllers__complete'); |
|
| 898 | + } |
|
| 899 | + |
|
| 900 | + |
|
| 901 | + |
|
| 902 | + /** |
|
| 903 | + * core_loaded_and_ready |
|
| 904 | + * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
| 905 | + * |
|
| 906 | + * @access public |
|
| 907 | + * @return void |
|
| 908 | + */ |
|
| 909 | + public function core_loaded_and_ready() |
|
| 910 | + { |
|
| 911 | + do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
| 912 | + do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
| 913 | + $this->registry->load_core('Session'); |
|
| 914 | + // add_action( 'wp_loaded', array( $this, 'set_hooks_for_shortcodes_modules_and_addons' ), 1 ); |
|
| 915 | + } |
|
| 916 | + |
|
| 917 | + |
|
| 918 | + |
|
| 919 | + /** |
|
| 920 | + * initialize |
|
| 921 | + * this is the best place to begin initializing client code |
|
| 922 | + * |
|
| 923 | + * @access public |
|
| 924 | + * @return void |
|
| 925 | + */ |
|
| 926 | + public function initialize() |
|
| 927 | + { |
|
| 928 | + do_action('AHEE__EE_System__initialize'); |
|
| 929 | + } |
|
| 930 | + |
|
| 931 | + |
|
| 932 | + |
|
| 933 | + /** |
|
| 934 | + * initialize_last |
|
| 935 | + * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to |
|
| 936 | + * initialize has done so |
|
| 937 | + * |
|
| 938 | + * @access public |
|
| 939 | + * @return void |
|
| 940 | + */ |
|
| 941 | + public function initialize_last() |
|
| 942 | + { |
|
| 943 | + do_action('AHEE__EE_System__initialize_last'); |
|
| 944 | + } |
|
| 945 | + |
|
| 946 | + |
|
| 947 | + |
|
| 948 | + /** |
|
| 949 | + * set_hooks_for_shortcodes_modules_and_addons |
|
| 950 | + * this is the best place for other systems to set callbacks for hooking into other parts of EE |
|
| 951 | + * this happens at the very beginning of the wp_loaded hookpoint |
|
| 952 | + * |
|
| 953 | + * @access public |
|
| 954 | + * @return void |
|
| 955 | + */ |
|
| 956 | + public function set_hooks_for_shortcodes_modules_and_addons() |
|
| 957 | + { |
|
| 958 | + // do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' ); |
|
| 959 | + } |
|
| 960 | + |
|
| 961 | + |
|
| 962 | + |
|
| 963 | + /** |
|
| 964 | + * do_not_cache |
|
| 965 | + * sets no cache headers and defines no cache constants for WP plugins |
|
| 966 | + * |
|
| 967 | + * @access public |
|
| 968 | + * @return void |
|
| 969 | + */ |
|
| 970 | + public static function do_not_cache() |
|
| 971 | + { |
|
| 972 | + // set no cache constants |
|
| 973 | + if ( ! defined('DONOTCACHEPAGE')) { |
|
| 974 | + define('DONOTCACHEPAGE', true); |
|
| 975 | + } |
|
| 976 | + if ( ! defined('DONOTCACHCEOBJECT')) { |
|
| 977 | + define('DONOTCACHCEOBJECT', true); |
|
| 978 | + } |
|
| 979 | + if ( ! defined('DONOTCACHEDB')) { |
|
| 980 | + define('DONOTCACHEDB', true); |
|
| 981 | + } |
|
| 982 | + // add no cache headers |
|
| 983 | + add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
| 984 | + // plus a little extra for nginx and Google Chrome |
|
| 985 | + add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
| 986 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
| 987 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
| 988 | + } |
|
| 989 | + |
|
| 990 | + |
|
| 991 | + |
|
| 992 | + /** |
|
| 993 | + * extra_nocache_headers |
|
| 994 | + * |
|
| 995 | + * @access public |
|
| 996 | + * @param $headers |
|
| 997 | + * @return array |
|
| 998 | + */ |
|
| 999 | + public static function extra_nocache_headers($headers) |
|
| 1000 | + { |
|
| 1001 | + // for NGINX |
|
| 1002 | + $headers['X-Accel-Expires'] = 0; |
|
| 1003 | + // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
| 1004 | + $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
| 1005 | + return $headers; |
|
| 1006 | + } |
|
| 1007 | + |
|
| 1008 | + |
|
| 1009 | + |
|
| 1010 | + /** |
|
| 1011 | + * nocache_headers |
|
| 1012 | + * |
|
| 1013 | + * @access public |
|
| 1014 | + * @return void |
|
| 1015 | + */ |
|
| 1016 | + public static function nocache_headers() |
|
| 1017 | + { |
|
| 1018 | + nocache_headers(); |
|
| 1019 | + } |
|
| 1020 | + |
|
| 1021 | + |
|
| 1022 | + |
|
| 1023 | + /** |
|
| 1024 | + * espresso_toolbar_items |
|
| 1025 | + * |
|
| 1026 | + * @access public |
|
| 1027 | + * @param WP_Admin_Bar $admin_bar |
|
| 1028 | + * @return void |
|
| 1029 | + */ |
|
| 1030 | + public function espresso_toolbar_items(WP_Admin_Bar $admin_bar) |
|
| 1031 | + { |
|
| 1032 | + // if in full M-Mode, or its an AJAX request, or user is NOT an admin |
|
| 1033 | + if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1034 | + || defined('DOING_AJAX') |
|
| 1035 | + || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
| 1036 | + ) { |
|
| 1037 | + return; |
|
| 1038 | + } |
|
| 1039 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1040 | + $menu_class = 'espresso_menu_item_class'; |
|
| 1041 | + //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
| 1042 | + //because they're only defined in each of their respective constructors |
|
| 1043 | + //and this might be a frontend request, in which case they aren't available |
|
| 1044 | + $events_admin_url = admin_url("admin.php?page=espresso_events"); |
|
| 1045 | + $reg_admin_url = admin_url("admin.php?page=espresso_registrations"); |
|
| 1046 | + $extensions_admin_url = admin_url("admin.php?page=espresso_packages"); |
|
| 1047 | + //Top Level |
|
| 1048 | + $admin_bar->add_menu(array( |
|
| 1049 | + 'id' => 'espresso-toolbar', |
|
| 1050 | + 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
| 1051 | + . _x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
| 1052 | + . '</span>', |
|
| 1053 | + 'href' => $events_admin_url, |
|
| 1054 | + 'meta' => array( |
|
| 1055 | + 'title' => __('Event Espresso', 'event_espresso'), |
|
| 1056 | + 'class' => $menu_class . 'first', |
|
| 1057 | + ), |
|
| 1058 | + )); |
|
| 1059 | + //Events |
|
| 1060 | + if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) { |
|
| 1061 | + $admin_bar->add_menu(array( |
|
| 1062 | + 'id' => 'espresso-toolbar-events', |
|
| 1063 | + 'parent' => 'espresso-toolbar', |
|
| 1064 | + 'title' => __('Events', 'event_espresso'), |
|
| 1065 | + 'href' => $events_admin_url, |
|
| 1066 | + 'meta' => array( |
|
| 1067 | + 'title' => __('Events', 'event_espresso'), |
|
| 1068 | + 'target' => '', |
|
| 1069 | + 'class' => $menu_class, |
|
| 1070 | + ), |
|
| 1071 | + )); |
|
| 1072 | + } |
|
| 1073 | + if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) { |
|
| 1074 | + //Events Add New |
|
| 1075 | + $admin_bar->add_menu(array( |
|
| 1076 | + 'id' => 'espresso-toolbar-events-new', |
|
| 1077 | + 'parent' => 'espresso-toolbar-events', |
|
| 1078 | + 'title' => __('Add New', 'event_espresso'), |
|
| 1079 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url), |
|
| 1080 | + 'meta' => array( |
|
| 1081 | + 'title' => __('Add New', 'event_espresso'), |
|
| 1082 | + 'target' => '', |
|
| 1083 | + 'class' => $menu_class, |
|
| 1084 | + ), |
|
| 1085 | + )); |
|
| 1086 | + } |
|
| 1087 | + if (is_single() && (get_post_type() == 'espresso_events')) { |
|
| 1088 | + //Current post |
|
| 1089 | + global $post; |
|
| 1090 | + if ($this->registry->CAP->current_user_can('ee_edit_event', |
|
| 1091 | + 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID) |
|
| 1092 | + ) { |
|
| 1093 | + //Events Edit Current Event |
|
| 1094 | + $admin_bar->add_menu(array( |
|
| 1095 | + 'id' => 'espresso-toolbar-events-edit', |
|
| 1096 | + 'parent' => 'espresso-toolbar-events', |
|
| 1097 | + 'title' => __('Edit Event', 'event_espresso'), |
|
| 1098 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID), |
|
| 1099 | + $events_admin_url), |
|
| 1100 | + 'meta' => array( |
|
| 1101 | + 'title' => __('Edit Event', 'event_espresso'), |
|
| 1102 | + 'target' => '', |
|
| 1103 | + 'class' => $menu_class, |
|
| 1104 | + ), |
|
| 1105 | + )); |
|
| 1106 | + } |
|
| 1107 | + } |
|
| 1108 | + //Events View |
|
| 1109 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
| 1110 | + 'ee_admin_bar_menu_espresso-toolbar-events-view') |
|
| 1111 | + ) { |
|
| 1112 | + $admin_bar->add_menu(array( |
|
| 1113 | + 'id' => 'espresso-toolbar-events-view', |
|
| 1114 | + 'parent' => 'espresso-toolbar-events', |
|
| 1115 | + 'title' => __('View', 'event_espresso'), |
|
| 1116 | + 'href' => $events_admin_url, |
|
| 1117 | + 'meta' => array( |
|
| 1118 | + 'title' => __('View', 'event_espresso'), |
|
| 1119 | + 'target' => '', |
|
| 1120 | + 'class' => $menu_class, |
|
| 1121 | + ), |
|
| 1122 | + )); |
|
| 1123 | + } |
|
| 1124 | + if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) { |
|
| 1125 | + //Events View All |
|
| 1126 | + $admin_bar->add_menu(array( |
|
| 1127 | + 'id' => 'espresso-toolbar-events-all', |
|
| 1128 | + 'parent' => 'espresso-toolbar-events-view', |
|
| 1129 | + 'title' => __('All', 'event_espresso'), |
|
| 1130 | + 'href' => $events_admin_url, |
|
| 1131 | + 'meta' => array( |
|
| 1132 | + 'title' => __('All', 'event_espresso'), |
|
| 1133 | + 'target' => '', |
|
| 1134 | + 'class' => $menu_class, |
|
| 1135 | + ), |
|
| 1136 | + )); |
|
| 1137 | + } |
|
| 1138 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
| 1139 | + 'ee_admin_bar_menu_espresso-toolbar-events-today') |
|
| 1140 | + ) { |
|
| 1141 | + //Events View Today |
|
| 1142 | + $admin_bar->add_menu(array( |
|
| 1143 | + 'id' => 'espresso-toolbar-events-today', |
|
| 1144 | + 'parent' => 'espresso-toolbar-events-view', |
|
| 1145 | + 'title' => __('Today', 'event_espresso'), |
|
| 1146 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
| 1147 | + $events_admin_url), |
|
| 1148 | + 'meta' => array( |
|
| 1149 | + 'title' => __('Today', 'event_espresso'), |
|
| 1150 | + 'target' => '', |
|
| 1151 | + 'class' => $menu_class, |
|
| 1152 | + ), |
|
| 1153 | + )); |
|
| 1154 | + } |
|
| 1155 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
| 1156 | + 'ee_admin_bar_menu_espresso-toolbar-events-month') |
|
| 1157 | + ) { |
|
| 1158 | + //Events View This Month |
|
| 1159 | + $admin_bar->add_menu(array( |
|
| 1160 | + 'id' => 'espresso-toolbar-events-month', |
|
| 1161 | + 'parent' => 'espresso-toolbar-events-view', |
|
| 1162 | + 'title' => __('This Month', 'event_espresso'), |
|
| 1163 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
| 1164 | + $events_admin_url), |
|
| 1165 | + 'meta' => array( |
|
| 1166 | + 'title' => __('This Month', 'event_espresso'), |
|
| 1167 | + 'target' => '', |
|
| 1168 | + 'class' => $menu_class, |
|
| 1169 | + ), |
|
| 1170 | + )); |
|
| 1171 | + } |
|
| 1172 | + //Registration Overview |
|
| 1173 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1174 | + 'ee_admin_bar_menu_espresso-toolbar-registrations') |
|
| 1175 | + ) { |
|
| 1176 | + $admin_bar->add_menu(array( |
|
| 1177 | + 'id' => 'espresso-toolbar-registrations', |
|
| 1178 | + 'parent' => 'espresso-toolbar', |
|
| 1179 | + 'title' => __('Registrations', 'event_espresso'), |
|
| 1180 | + 'href' => $reg_admin_url, |
|
| 1181 | + 'meta' => array( |
|
| 1182 | + 'title' => __('Registrations', 'event_espresso'), |
|
| 1183 | + 'target' => '', |
|
| 1184 | + 'class' => $menu_class, |
|
| 1185 | + ), |
|
| 1186 | + )); |
|
| 1187 | + } |
|
| 1188 | + //Registration Overview Today |
|
| 1189 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1190 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today') |
|
| 1191 | + ) { |
|
| 1192 | + $admin_bar->add_menu(array( |
|
| 1193 | + 'id' => 'espresso-toolbar-registrations-today', |
|
| 1194 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 1195 | + 'title' => __('Today', 'event_espresso'), |
|
| 1196 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
| 1197 | + $reg_admin_url), |
|
| 1198 | + 'meta' => array( |
|
| 1199 | + 'title' => __('Today', 'event_espresso'), |
|
| 1200 | + 'target' => '', |
|
| 1201 | + 'class' => $menu_class, |
|
| 1202 | + ), |
|
| 1203 | + )); |
|
| 1204 | + } |
|
| 1205 | + //Registration Overview Today Completed |
|
| 1206 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1207 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved') |
|
| 1208 | + ) { |
|
| 1209 | + $admin_bar->add_menu(array( |
|
| 1210 | + 'id' => 'espresso-toolbar-registrations-today-approved', |
|
| 1211 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1212 | + 'title' => __('Approved', 'event_espresso'), |
|
| 1213 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1214 | + 'action' => 'default', |
|
| 1215 | + 'status' => 'today', |
|
| 1216 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1217 | + ), $reg_admin_url), |
|
| 1218 | + 'meta' => array( |
|
| 1219 | + 'title' => __('Approved', 'event_espresso'), |
|
| 1220 | + 'target' => '', |
|
| 1221 | + 'class' => $menu_class, |
|
| 1222 | + ), |
|
| 1223 | + )); |
|
| 1224 | + } |
|
| 1225 | + //Registration Overview Today Pending\ |
|
| 1226 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1227 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending') |
|
| 1228 | + ) { |
|
| 1229 | + $admin_bar->add_menu(array( |
|
| 1230 | + 'id' => 'espresso-toolbar-registrations-today-pending', |
|
| 1231 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1232 | + 'title' => __('Pending', 'event_espresso'), |
|
| 1233 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1234 | + 'action' => 'default', |
|
| 1235 | + 'status' => 'today', |
|
| 1236 | + 'reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1237 | + ), $reg_admin_url), |
|
| 1238 | + 'meta' => array( |
|
| 1239 | + 'title' => __('Pending Payment', 'event_espresso'), |
|
| 1240 | + 'target' => '', |
|
| 1241 | + 'class' => $menu_class, |
|
| 1242 | + ), |
|
| 1243 | + )); |
|
| 1244 | + } |
|
| 1245 | + //Registration Overview Today Incomplete |
|
| 1246 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1247 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved') |
|
| 1248 | + ) { |
|
| 1249 | + $admin_bar->add_menu(array( |
|
| 1250 | + 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
| 1251 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1252 | + 'title' => __('Not Approved', 'event_espresso'), |
|
| 1253 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1254 | + 'action' => 'default', |
|
| 1255 | + 'status' => 'today', |
|
| 1256 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1257 | + ), $reg_admin_url), |
|
| 1258 | + 'meta' => array( |
|
| 1259 | + 'title' => __('Not Approved', 'event_espresso'), |
|
| 1260 | + 'target' => '', |
|
| 1261 | + 'class' => $menu_class, |
|
| 1262 | + ), |
|
| 1263 | + )); |
|
| 1264 | + } |
|
| 1265 | + //Registration Overview Today Incomplete |
|
| 1266 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1267 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled') |
|
| 1268 | + ) { |
|
| 1269 | + $admin_bar->add_menu(array( |
|
| 1270 | + 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
| 1271 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1272 | + 'title' => __('Cancelled', 'event_espresso'), |
|
| 1273 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1274 | + 'action' => 'default', |
|
| 1275 | + 'status' => 'today', |
|
| 1276 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
| 1277 | + ), $reg_admin_url), |
|
| 1278 | + 'meta' => array( |
|
| 1279 | + 'title' => __('Cancelled', 'event_espresso'), |
|
| 1280 | + 'target' => '', |
|
| 1281 | + 'class' => $menu_class, |
|
| 1282 | + ), |
|
| 1283 | + )); |
|
| 1284 | + } |
|
| 1285 | + //Registration Overview This Month |
|
| 1286 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1287 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month') |
|
| 1288 | + ) { |
|
| 1289 | + $admin_bar->add_menu(array( |
|
| 1290 | + 'id' => 'espresso-toolbar-registrations-month', |
|
| 1291 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 1292 | + 'title' => __('This Month', 'event_espresso'), |
|
| 1293 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
| 1294 | + $reg_admin_url), |
|
| 1295 | + 'meta' => array( |
|
| 1296 | + 'title' => __('This Month', 'event_espresso'), |
|
| 1297 | + 'target' => '', |
|
| 1298 | + 'class' => $menu_class, |
|
| 1299 | + ), |
|
| 1300 | + )); |
|
| 1301 | + } |
|
| 1302 | + //Registration Overview This Month Approved |
|
| 1303 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1304 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved') |
|
| 1305 | + ) { |
|
| 1306 | + $admin_bar->add_menu(array( |
|
| 1307 | + 'id' => 'espresso-toolbar-registrations-month-approved', |
|
| 1308 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1309 | + 'title' => __('Approved', 'event_espresso'), |
|
| 1310 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1311 | + 'action' => 'default', |
|
| 1312 | + 'status' => 'month', |
|
| 1313 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1314 | + ), $reg_admin_url), |
|
| 1315 | + 'meta' => array( |
|
| 1316 | + 'title' => __('Approved', 'event_espresso'), |
|
| 1317 | + 'target' => '', |
|
| 1318 | + 'class' => $menu_class, |
|
| 1319 | + ), |
|
| 1320 | + )); |
|
| 1321 | + } |
|
| 1322 | + //Registration Overview This Month Pending |
|
| 1323 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1324 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending') |
|
| 1325 | + ) { |
|
| 1326 | + $admin_bar->add_menu(array( |
|
| 1327 | + 'id' => 'espresso-toolbar-registrations-month-pending', |
|
| 1328 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1329 | + 'title' => __('Pending', 'event_espresso'), |
|
| 1330 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1331 | + 'action' => 'default', |
|
| 1332 | + 'status' => 'month', |
|
| 1333 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1334 | + ), $reg_admin_url), |
|
| 1335 | + 'meta' => array( |
|
| 1336 | + 'title' => __('Pending', 'event_espresso'), |
|
| 1337 | + 'target' => '', |
|
| 1338 | + 'class' => $menu_class, |
|
| 1339 | + ), |
|
| 1340 | + )); |
|
| 1341 | + } |
|
| 1342 | + //Registration Overview This Month Not Approved |
|
| 1343 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1344 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved') |
|
| 1345 | + ) { |
|
| 1346 | + $admin_bar->add_menu(array( |
|
| 1347 | + 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
| 1348 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1349 | + 'title' => __('Not Approved', 'event_espresso'), |
|
| 1350 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1351 | + 'action' => 'default', |
|
| 1352 | + 'status' => 'month', |
|
| 1353 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1354 | + ), $reg_admin_url), |
|
| 1355 | + 'meta' => array( |
|
| 1356 | + 'title' => __('Not Approved', 'event_espresso'), |
|
| 1357 | + 'target' => '', |
|
| 1358 | + 'class' => $menu_class, |
|
| 1359 | + ), |
|
| 1360 | + )); |
|
| 1361 | + } |
|
| 1362 | + //Registration Overview This Month Cancelled |
|
| 1363 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1364 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled') |
|
| 1365 | + ) { |
|
| 1366 | + $admin_bar->add_menu(array( |
|
| 1367 | + 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
| 1368 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1369 | + 'title' => __('Cancelled', 'event_espresso'), |
|
| 1370 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1371 | + 'action' => 'default', |
|
| 1372 | + 'status' => 'month', |
|
| 1373 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
| 1374 | + ), $reg_admin_url), |
|
| 1375 | + 'meta' => array( |
|
| 1376 | + 'title' => __('Cancelled', 'event_espresso'), |
|
| 1377 | + 'target' => '', |
|
| 1378 | + 'class' => $menu_class, |
|
| 1379 | + ), |
|
| 1380 | + )); |
|
| 1381 | + } |
|
| 1382 | + //Extensions & Services |
|
| 1383 | + if ($this->registry->CAP->current_user_can('ee_read_ee', |
|
| 1384 | + 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services') |
|
| 1385 | + ) { |
|
| 1386 | + $admin_bar->add_menu(array( |
|
| 1387 | + 'id' => 'espresso-toolbar-extensions-and-services', |
|
| 1388 | + 'parent' => 'espresso-toolbar', |
|
| 1389 | + 'title' => __('Extensions & Services', 'event_espresso'), |
|
| 1390 | + 'href' => $extensions_admin_url, |
|
| 1391 | + 'meta' => array( |
|
| 1392 | + 'title' => __('Extensions & Services', 'event_espresso'), |
|
| 1393 | + 'target' => '', |
|
| 1394 | + 'class' => $menu_class, |
|
| 1395 | + ), |
|
| 1396 | + )); |
|
| 1397 | + } |
|
| 1398 | + } |
|
| 1399 | + |
|
| 1400 | + |
|
| 1401 | + |
|
| 1402 | + /** |
|
| 1403 | + * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
| 1404 | + * never returned with the function. |
|
| 1405 | + * |
|
| 1406 | + * @param array $exclude_array any existing pages being excluded are in this array. |
|
| 1407 | + * @return array |
|
| 1408 | + */ |
|
| 1409 | + public function remove_pages_from_wp_list_pages($exclude_array) |
|
| 1410 | + { |
|
| 1411 | + return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
| 1412 | + } |
|
| 1413 | + |
|
| 1414 | + |
|
| 1415 | + |
|
| 1416 | + |
|
| 1417 | + |
|
| 1418 | + |
|
| 1419 | + /*********************************************** WP_ENQUEUE_SCRIPTS HOOK ***********************************************/ |
|
| 1420 | + /** |
|
| 1421 | + * wp_enqueue_scripts |
|
| 1422 | + * |
|
| 1423 | + * @access public |
|
| 1424 | + * @return void |
|
| 1425 | + */ |
|
| 1426 | + public function wp_enqueue_scripts() |
|
| 1427 | + { |
|
| 1428 | + // unlike other systems, EE_System_scripts loading is turned ON by default, but prior to the init hook, can be turned off via: add_filter( 'FHEE_load_EE_System_scripts', '__return_false' ); |
|
| 1429 | + if (apply_filters('FHEE_load_EE_System_scripts', true)) { |
|
| 1430 | + // jquery_validate loading is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via: add_filter( 'FHEE_load_jquery_validate', '__return_true' ); |
|
| 1431 | + if (apply_filters('FHEE_load_jquery_validate', false)) { |
|
| 1432 | + // register jQuery Validate and additional methods |
|
| 1433 | + wp_register_script('jquery-validate', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 1434 | + array('jquery'), '1.15.0', true); |
|
| 1435 | + wp_register_script('jquery-validate-extra-methods', |
|
| 1436 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 1437 | + array('jquery', 'jquery-validate'), '1.15.0', true); |
|
| 1438 | + } |
|
| 1439 | + } |
|
| 1440 | + } |
|
| 1441 | 1441 | |
| 1442 | 1442 | |
| 1443 | 1443 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -16,314 +16,314 @@ discard block |
||
| 16 | 16 | class EE_Form_Input_With_Options_Base extends EE_Form_Input_Base |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * array of available options to choose as an answer |
|
| 21 | - * |
|
| 22 | - * @var array |
|
| 23 | - */ |
|
| 24 | - protected $_options = array(); |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * whether to display the html_label_text above the checkbox/radio button options |
|
| 28 | - * |
|
| 29 | - * @var boolean |
|
| 30 | - */ |
|
| 31 | - protected $_display_html_label_text = true; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * whether to display an question option description as part of the input label |
|
| 35 | - * |
|
| 36 | - * @var boolean |
|
| 37 | - */ |
|
| 38 | - protected $_use_desc_in_label = true; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * strlen() result for the longest input value (what gets displayed in the label) |
|
| 42 | - * this is used to apply a css class to the input label |
|
| 43 | - * |
|
| 44 | - * @var int |
|
| 45 | - */ |
|
| 46 | - protected $_label_size = 0; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * whether to enforce the label size value passed in the constructor |
|
| 50 | - * |
|
| 51 | - * @var boolean |
|
| 52 | - */ |
|
| 53 | - protected $_enforce_label_size = false; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * whether to allow multiple selections (ie, the value of this input should be an array) |
|
| 57 | - * or not (ie, the value should be a simple int, string, etc) |
|
| 58 | - * |
|
| 59 | - * @var boolean |
|
| 60 | - */ |
|
| 61 | - protected $_multiple_selections = false; |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @param array $answer_options |
|
| 67 | - * @param array $input_settings { |
|
| 68 | - * @type int|string $label_size |
|
| 69 | - * @type boolean $display_html_label_text |
|
| 70 | - * } |
|
| 71 | - * And all the options accepted by EE_Form_Input_Base |
|
| 72 | - */ |
|
| 73 | - public function __construct($answer_options = array(), $input_settings = array()) |
|
| 74 | - { |
|
| 75 | - if (isset($input_settings['label_size'])) { |
|
| 76 | - $this->_set_label_size($input_settings['label_size']); |
|
| 77 | - if (isset($input_settings['enforce_label_size']) && $input_settings['enforce_label_size']) { |
|
| 78 | - $this->_enforce_label_size = true; |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - if (isset($input_settings['display_html_label_text'])) { |
|
| 82 | - $this->set_display_html_label_text($input_settings['display_html_label_text']); |
|
| 83 | - } |
|
| 84 | - $this->set_select_options($answer_options); |
|
| 85 | - parent::__construct($input_settings); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Sets the allowed options for this input. Also has the side-effect of |
|
| 92 | - * updating the normalization strategy to match the keys provided in the array |
|
| 93 | - * |
|
| 94 | - * @param array $answer_options |
|
| 95 | - * @return void just has the side-effect of setting the options for this input |
|
| 96 | - */ |
|
| 97 | - public function set_select_options($answer_options = array()) |
|
| 98 | - { |
|
| 99 | - $answer_options = is_array($answer_options) ? $answer_options : array($answer_options); |
|
| 100 | - //get the first item in the select options and check it's type |
|
| 101 | - $this->_options = reset($answer_options) instanceof EE_Question_Option |
|
| 102 | - ? $this->_process_question_options($answer_options) |
|
| 103 | - : $answer_options; |
|
| 104 | - //d( $this->_options ); |
|
| 105 | - $select_option_keys = array_keys($this->_options); |
|
| 106 | - // attempt to determine data type for values in order to set normalization type |
|
| 107 | - if ( |
|
| 108 | - count($this->_options) === 2 |
|
| 109 | - && ( |
|
| 110 | - (in_array(true, $select_option_keys, true) && in_array(false, $select_option_keys, true)) |
|
| 111 | - || (in_array(1, $select_option_keys, true) && in_array(0, $select_option_keys, true)) |
|
| 112 | - ) |
|
| 113 | - ) { |
|
| 114 | - // values appear to be boolean, like TRUE, FALSE, 1, 0 |
|
| 115 | - $normalization = new EE_Boolean_Normalization(); |
|
| 116 | - } else { |
|
| 117 | - //are ALL the options ints? If so use int validation |
|
| 118 | - $all_ints = true; |
|
| 119 | - foreach ($select_option_keys as $value) { |
|
| 120 | - //allow for a default value which may be empty. |
|
| 121 | - if ( ! is_int($value) && $value !== '' && $value !== null) { |
|
| 122 | - $all_ints = false; |
|
| 123 | - break; |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - if ($all_ints) { |
|
| 127 | - $normalization = new EE_Int_Normalization(); |
|
| 128 | - } else { |
|
| 129 | - $normalization = new EE_Text_Normalization(); |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - // does input type have multiple options ? |
|
| 133 | - if ($this->_multiple_selections) { |
|
| 134 | - $this->_set_normalization_strategy(new EE_Many_Valued_Normalization($normalization)); |
|
| 135 | - } else { |
|
| 136 | - $this->_set_normalization_strategy($normalization); |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @return array |
|
| 144 | - */ |
|
| 145 | - public function options() |
|
| 146 | - { |
|
| 147 | - return $this->_options; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Returns an array which is guaranteed to not be multidimensional |
|
| 154 | - * |
|
| 155 | - * @return array |
|
| 156 | - */ |
|
| 157 | - public function flat_options() |
|
| 158 | - { |
|
| 159 | - return $this->_flatten_select_options($this->options()); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Makes sure $arr is a flat array, not a multidimensional one |
|
| 166 | - * |
|
| 167 | - * @param array $arr |
|
| 168 | - * @return array |
|
| 169 | - */ |
|
| 170 | - protected function _flatten_select_options($arr) |
|
| 171 | - { |
|
| 172 | - $flat_array = array(); |
|
| 173 | - if (EEH_Array::is_multi_dimensional_array($arr)) { |
|
| 174 | - foreach ($arr as $sub_array) { |
|
| 175 | - foreach ((array)$sub_array as $key => $value) { |
|
| 176 | - $flat_array[$key] = $value; |
|
| 177 | - $this->_set_label_size($value); |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - } else { |
|
| 181 | - foreach ($arr as $key => $value) { |
|
| 182 | - $flat_array[$key] = $value; |
|
| 183 | - $this->_set_label_size($value); |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - return $flat_array; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * @param EE_Question_Option[] $question_options_array |
|
| 193 | - * @return array |
|
| 194 | - */ |
|
| 195 | - protected function _process_question_options($question_options_array = array()) |
|
| 196 | - { |
|
| 197 | - $flat_array = array(); |
|
| 198 | - foreach ($question_options_array as $question_option) { |
|
| 199 | - if ($question_option instanceof EE_Question_Option) { |
|
| 200 | - $desc = ''; |
|
| 201 | - if ($this->_use_desc_in_label) { |
|
| 202 | - $desc = $question_option->desc(); |
|
| 203 | - $desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : ''; |
|
| 204 | - } |
|
| 205 | - $value = $question_option->value(); |
|
| 206 | - // add value even if it's empty |
|
| 207 | - $flat_array[$value] = $value; |
|
| 208 | - // if both value and desc are not empty, then separate with a dash |
|
| 209 | - if ( ! empty($value) && ! empty($desc)) { |
|
| 210 | - $flat_array[$value] .= ' - ' . $desc; |
|
| 211 | - } else { |
|
| 212 | - // otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary |
|
| 213 | - $flat_array[$value] .= $desc; |
|
| 214 | - } |
|
| 215 | - } elseif (is_array($question_option)) { |
|
| 216 | - $flat_array += $this->_flatten_select_options($question_option); |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - return $flat_array; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * set_label_sizes |
|
| 226 | - * |
|
| 227 | - * @return void |
|
| 228 | - */ |
|
| 229 | - public function set_label_sizes() |
|
| 230 | - { |
|
| 231 | - // did the input settings specifically say to NOT set the label size dynamically ? |
|
| 232 | - if ( ! $this->_enforce_label_size) { |
|
| 233 | - foreach ($this->_options as $option) { |
|
| 234 | - // calculate the strlen of the label |
|
| 235 | - $this->_set_label_size($option); |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * _set_label_size_class |
|
| 244 | - * |
|
| 245 | - * @param int|string $value |
|
| 246 | - * @return void |
|
| 247 | - */ |
|
| 248 | - private function _set_label_size($value = '') |
|
| 249 | - { |
|
| 250 | - // determine length of option value |
|
| 251 | - $val_size = is_int($value) ? $value : strlen($value); |
|
| 252 | - // use new value if bigger than existing |
|
| 253 | - $this->_label_size = $val_size > $this->_label_size ? $val_size : $this->_label_size; |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * get_label_size_class |
|
| 260 | - * |
|
| 261 | - * @return string |
|
| 262 | - */ |
|
| 263 | - public function get_label_size_class() |
|
| 264 | - { |
|
| 265 | - $size = ' medium-lbl'; |
|
| 266 | - // use maximum option value length to determine label size |
|
| 267 | - if ($this->_label_size < 3) { |
|
| 268 | - $size = ' nano-lbl'; |
|
| 269 | - } else if ($this->_label_size < 6) { |
|
| 270 | - $size = ' micro-lbl'; |
|
| 271 | - } else if ($this->_label_size < 12) { |
|
| 272 | - $size = ' tiny-lbl'; |
|
| 273 | - } else if ($this->_label_size < 25) { |
|
| 274 | - $size = ' small-lbl'; |
|
| 275 | - } else if ($this->_label_size < 50) { |
|
| 276 | - $size = ' medium-lbl'; |
|
| 277 | - } else if ($this->_label_size >= 100) { |
|
| 278 | - $size = ' big-lbl'; |
|
| 279 | - } |
|
| 280 | - return $size; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * Returns the pretty value for the normalized value |
|
| 287 | - * |
|
| 288 | - * @return string |
|
| 289 | - */ |
|
| 290 | - public function pretty_value() |
|
| 291 | - { |
|
| 292 | - $options = $this->flat_options(); |
|
| 293 | - $unnormalized_value_choices = $this->get_normalization_strategy()->unnormalize($this->_normalized_value); |
|
| 294 | - if ( ! $this->_multiple_selections) { |
|
| 295 | - $unnormalized_value_choices = array($unnormalized_value_choices); |
|
| 296 | - } |
|
| 297 | - $pretty_strings = array(); |
|
| 298 | - foreach ((array)$unnormalized_value_choices as $unnormalized_value_choice) { |
|
| 299 | - if (isset($options[$unnormalized_value_choice])) { |
|
| 300 | - $pretty_strings[] = $options[$unnormalized_value_choice]; |
|
| 301 | - } else { |
|
| 302 | - $pretty_strings[] = $this->normalized_value(); |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - return implode(', ', $pretty_strings); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * @return boolean |
|
| 312 | - */ |
|
| 313 | - public function display_html_label_text() |
|
| 314 | - { |
|
| 315 | - return $this->_display_html_label_text; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * @param boolean $display_html_label_text |
|
| 322 | - */ |
|
| 323 | - public function set_display_html_label_text($display_html_label_text) |
|
| 324 | - { |
|
| 325 | - $this->_display_html_label_text = filter_var($display_html_label_text, FILTER_VALIDATE_BOOLEAN); |
|
| 326 | - } |
|
| 19 | + /** |
|
| 20 | + * array of available options to choose as an answer |
|
| 21 | + * |
|
| 22 | + * @var array |
|
| 23 | + */ |
|
| 24 | + protected $_options = array(); |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * whether to display the html_label_text above the checkbox/radio button options |
|
| 28 | + * |
|
| 29 | + * @var boolean |
|
| 30 | + */ |
|
| 31 | + protected $_display_html_label_text = true; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * whether to display an question option description as part of the input label |
|
| 35 | + * |
|
| 36 | + * @var boolean |
|
| 37 | + */ |
|
| 38 | + protected $_use_desc_in_label = true; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * strlen() result for the longest input value (what gets displayed in the label) |
|
| 42 | + * this is used to apply a css class to the input label |
|
| 43 | + * |
|
| 44 | + * @var int |
|
| 45 | + */ |
|
| 46 | + protected $_label_size = 0; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * whether to enforce the label size value passed in the constructor |
|
| 50 | + * |
|
| 51 | + * @var boolean |
|
| 52 | + */ |
|
| 53 | + protected $_enforce_label_size = false; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * whether to allow multiple selections (ie, the value of this input should be an array) |
|
| 57 | + * or not (ie, the value should be a simple int, string, etc) |
|
| 58 | + * |
|
| 59 | + * @var boolean |
|
| 60 | + */ |
|
| 61 | + protected $_multiple_selections = false; |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @param array $answer_options |
|
| 67 | + * @param array $input_settings { |
|
| 68 | + * @type int|string $label_size |
|
| 69 | + * @type boolean $display_html_label_text |
|
| 70 | + * } |
|
| 71 | + * And all the options accepted by EE_Form_Input_Base |
|
| 72 | + */ |
|
| 73 | + public function __construct($answer_options = array(), $input_settings = array()) |
|
| 74 | + { |
|
| 75 | + if (isset($input_settings['label_size'])) { |
|
| 76 | + $this->_set_label_size($input_settings['label_size']); |
|
| 77 | + if (isset($input_settings['enforce_label_size']) && $input_settings['enforce_label_size']) { |
|
| 78 | + $this->_enforce_label_size = true; |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + if (isset($input_settings['display_html_label_text'])) { |
|
| 82 | + $this->set_display_html_label_text($input_settings['display_html_label_text']); |
|
| 83 | + } |
|
| 84 | + $this->set_select_options($answer_options); |
|
| 85 | + parent::__construct($input_settings); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Sets the allowed options for this input. Also has the side-effect of |
|
| 92 | + * updating the normalization strategy to match the keys provided in the array |
|
| 93 | + * |
|
| 94 | + * @param array $answer_options |
|
| 95 | + * @return void just has the side-effect of setting the options for this input |
|
| 96 | + */ |
|
| 97 | + public function set_select_options($answer_options = array()) |
|
| 98 | + { |
|
| 99 | + $answer_options = is_array($answer_options) ? $answer_options : array($answer_options); |
|
| 100 | + //get the first item in the select options and check it's type |
|
| 101 | + $this->_options = reset($answer_options) instanceof EE_Question_Option |
|
| 102 | + ? $this->_process_question_options($answer_options) |
|
| 103 | + : $answer_options; |
|
| 104 | + //d( $this->_options ); |
|
| 105 | + $select_option_keys = array_keys($this->_options); |
|
| 106 | + // attempt to determine data type for values in order to set normalization type |
|
| 107 | + if ( |
|
| 108 | + count($this->_options) === 2 |
|
| 109 | + && ( |
|
| 110 | + (in_array(true, $select_option_keys, true) && in_array(false, $select_option_keys, true)) |
|
| 111 | + || (in_array(1, $select_option_keys, true) && in_array(0, $select_option_keys, true)) |
|
| 112 | + ) |
|
| 113 | + ) { |
|
| 114 | + // values appear to be boolean, like TRUE, FALSE, 1, 0 |
|
| 115 | + $normalization = new EE_Boolean_Normalization(); |
|
| 116 | + } else { |
|
| 117 | + //are ALL the options ints? If so use int validation |
|
| 118 | + $all_ints = true; |
|
| 119 | + foreach ($select_option_keys as $value) { |
|
| 120 | + //allow for a default value which may be empty. |
|
| 121 | + if ( ! is_int($value) && $value !== '' && $value !== null) { |
|
| 122 | + $all_ints = false; |
|
| 123 | + break; |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + if ($all_ints) { |
|
| 127 | + $normalization = new EE_Int_Normalization(); |
|
| 128 | + } else { |
|
| 129 | + $normalization = new EE_Text_Normalization(); |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + // does input type have multiple options ? |
|
| 133 | + if ($this->_multiple_selections) { |
|
| 134 | + $this->_set_normalization_strategy(new EE_Many_Valued_Normalization($normalization)); |
|
| 135 | + } else { |
|
| 136 | + $this->_set_normalization_strategy($normalization); |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @return array |
|
| 144 | + */ |
|
| 145 | + public function options() |
|
| 146 | + { |
|
| 147 | + return $this->_options; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Returns an array which is guaranteed to not be multidimensional |
|
| 154 | + * |
|
| 155 | + * @return array |
|
| 156 | + */ |
|
| 157 | + public function flat_options() |
|
| 158 | + { |
|
| 159 | + return $this->_flatten_select_options($this->options()); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Makes sure $arr is a flat array, not a multidimensional one |
|
| 166 | + * |
|
| 167 | + * @param array $arr |
|
| 168 | + * @return array |
|
| 169 | + */ |
|
| 170 | + protected function _flatten_select_options($arr) |
|
| 171 | + { |
|
| 172 | + $flat_array = array(); |
|
| 173 | + if (EEH_Array::is_multi_dimensional_array($arr)) { |
|
| 174 | + foreach ($arr as $sub_array) { |
|
| 175 | + foreach ((array)$sub_array as $key => $value) { |
|
| 176 | + $flat_array[$key] = $value; |
|
| 177 | + $this->_set_label_size($value); |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + } else { |
|
| 181 | + foreach ($arr as $key => $value) { |
|
| 182 | + $flat_array[$key] = $value; |
|
| 183 | + $this->_set_label_size($value); |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + return $flat_array; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * @param EE_Question_Option[] $question_options_array |
|
| 193 | + * @return array |
|
| 194 | + */ |
|
| 195 | + protected function _process_question_options($question_options_array = array()) |
|
| 196 | + { |
|
| 197 | + $flat_array = array(); |
|
| 198 | + foreach ($question_options_array as $question_option) { |
|
| 199 | + if ($question_option instanceof EE_Question_Option) { |
|
| 200 | + $desc = ''; |
|
| 201 | + if ($this->_use_desc_in_label) { |
|
| 202 | + $desc = $question_option->desc(); |
|
| 203 | + $desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : ''; |
|
| 204 | + } |
|
| 205 | + $value = $question_option->value(); |
|
| 206 | + // add value even if it's empty |
|
| 207 | + $flat_array[$value] = $value; |
|
| 208 | + // if both value and desc are not empty, then separate with a dash |
|
| 209 | + if ( ! empty($value) && ! empty($desc)) { |
|
| 210 | + $flat_array[$value] .= ' - ' . $desc; |
|
| 211 | + } else { |
|
| 212 | + // otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary |
|
| 213 | + $flat_array[$value] .= $desc; |
|
| 214 | + } |
|
| 215 | + } elseif (is_array($question_option)) { |
|
| 216 | + $flat_array += $this->_flatten_select_options($question_option); |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + return $flat_array; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * set_label_sizes |
|
| 226 | + * |
|
| 227 | + * @return void |
|
| 228 | + */ |
|
| 229 | + public function set_label_sizes() |
|
| 230 | + { |
|
| 231 | + // did the input settings specifically say to NOT set the label size dynamically ? |
|
| 232 | + if ( ! $this->_enforce_label_size) { |
|
| 233 | + foreach ($this->_options as $option) { |
|
| 234 | + // calculate the strlen of the label |
|
| 235 | + $this->_set_label_size($option); |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * _set_label_size_class |
|
| 244 | + * |
|
| 245 | + * @param int|string $value |
|
| 246 | + * @return void |
|
| 247 | + */ |
|
| 248 | + private function _set_label_size($value = '') |
|
| 249 | + { |
|
| 250 | + // determine length of option value |
|
| 251 | + $val_size = is_int($value) ? $value : strlen($value); |
|
| 252 | + // use new value if bigger than existing |
|
| 253 | + $this->_label_size = $val_size > $this->_label_size ? $val_size : $this->_label_size; |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * get_label_size_class |
|
| 260 | + * |
|
| 261 | + * @return string |
|
| 262 | + */ |
|
| 263 | + public function get_label_size_class() |
|
| 264 | + { |
|
| 265 | + $size = ' medium-lbl'; |
|
| 266 | + // use maximum option value length to determine label size |
|
| 267 | + if ($this->_label_size < 3) { |
|
| 268 | + $size = ' nano-lbl'; |
|
| 269 | + } else if ($this->_label_size < 6) { |
|
| 270 | + $size = ' micro-lbl'; |
|
| 271 | + } else if ($this->_label_size < 12) { |
|
| 272 | + $size = ' tiny-lbl'; |
|
| 273 | + } else if ($this->_label_size < 25) { |
|
| 274 | + $size = ' small-lbl'; |
|
| 275 | + } else if ($this->_label_size < 50) { |
|
| 276 | + $size = ' medium-lbl'; |
|
| 277 | + } else if ($this->_label_size >= 100) { |
|
| 278 | + $size = ' big-lbl'; |
|
| 279 | + } |
|
| 280 | + return $size; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * Returns the pretty value for the normalized value |
|
| 287 | + * |
|
| 288 | + * @return string |
|
| 289 | + */ |
|
| 290 | + public function pretty_value() |
|
| 291 | + { |
|
| 292 | + $options = $this->flat_options(); |
|
| 293 | + $unnormalized_value_choices = $this->get_normalization_strategy()->unnormalize($this->_normalized_value); |
|
| 294 | + if ( ! $this->_multiple_selections) { |
|
| 295 | + $unnormalized_value_choices = array($unnormalized_value_choices); |
|
| 296 | + } |
|
| 297 | + $pretty_strings = array(); |
|
| 298 | + foreach ((array)$unnormalized_value_choices as $unnormalized_value_choice) { |
|
| 299 | + if (isset($options[$unnormalized_value_choice])) { |
|
| 300 | + $pretty_strings[] = $options[$unnormalized_value_choice]; |
|
| 301 | + } else { |
|
| 302 | + $pretty_strings[] = $this->normalized_value(); |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + return implode(', ', $pretty_strings); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * @return boolean |
|
| 312 | + */ |
|
| 313 | + public function display_html_label_text() |
|
| 314 | + { |
|
| 315 | + return $this->_display_html_label_text; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * @param boolean $display_html_label_text |
|
| 322 | + */ |
|
| 323 | + public function set_display_html_label_text($display_html_label_text) |
|
| 324 | + { |
|
| 325 | + $this->_display_html_label_text = filter_var($display_html_label_text, FILTER_VALIDATE_BOOLEAN); |
|
| 326 | + } |
|
| 327 | 327 | |
| 328 | 328 | |
| 329 | 329 | |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | $flat_array = array(); |
| 173 | 173 | if (EEH_Array::is_multi_dimensional_array($arr)) { |
| 174 | 174 | foreach ($arr as $sub_array) { |
| 175 | - foreach ((array)$sub_array as $key => $value) { |
|
| 175 | + foreach ((array) $sub_array as $key => $value) { |
|
| 176 | 176 | $flat_array[$key] = $value; |
| 177 | 177 | $this->_set_label_size($value); |
| 178 | 178 | } |
@@ -200,14 +200,14 @@ discard block |
||
| 200 | 200 | $desc = ''; |
| 201 | 201 | if ($this->_use_desc_in_label) { |
| 202 | 202 | $desc = $question_option->desc(); |
| 203 | - $desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : ''; |
|
| 203 | + $desc = ! empty($desc) ? '<span class="ee-question-option-desc">'.$desc.'</span>' : ''; |
|
| 204 | 204 | } |
| 205 | 205 | $value = $question_option->value(); |
| 206 | 206 | // add value even if it's empty |
| 207 | 207 | $flat_array[$value] = $value; |
| 208 | 208 | // if both value and desc are not empty, then separate with a dash |
| 209 | 209 | if ( ! empty($value) && ! empty($desc)) { |
| 210 | - $flat_array[$value] .= ' - ' . $desc; |
|
| 210 | + $flat_array[$value] .= ' - '.$desc; |
|
| 211 | 211 | } else { |
| 212 | 212 | // otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary |
| 213 | 213 | $flat_array[$value] .= $desc; |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | $unnormalized_value_choices = array($unnormalized_value_choices); |
| 296 | 296 | } |
| 297 | 297 | $pretty_strings = array(); |
| 298 | - foreach ((array)$unnormalized_value_choices as $unnormalized_value_choice) { |
|
| 298 | + foreach ((array) $unnormalized_value_choices as $unnormalized_value_choice) { |
|
| 299 | 299 | if (isset($options[$unnormalized_value_choice])) { |
| 300 | 300 | $pretty_strings[] = $options[$unnormalized_value_choice]; |
| 301 | 301 | } else { |
@@ -33,11 +33,11 @@ discard block |
||
| 33 | 33 | public static function set_hooks() { |
| 34 | 34 | // create download buttons |
| 35 | 35 | add_filter( |
| 36 | - 'FHEE__espresso_list_of_event_dates__datetime_html', |
|
| 37 | - array( 'EED_Ical', 'generate_add_to_iCal_button' ), |
|
| 38 | - 10, |
|
| 39 | - 2 |
|
| 40 | - ); |
|
| 36 | + 'FHEE__espresso_list_of_event_dates__datetime_html', |
|
| 37 | + array( 'EED_Ical', 'generate_add_to_iCal_button' ), |
|
| 38 | + 10, |
|
| 39 | + 2 |
|
| 40 | + ); |
|
| 41 | 41 | // process ics download request |
| 42 | 42 | EE_Config::register_route( 'download_ics_file', 'EED_Ical', 'download_ics_file' ); |
| 43 | 43 | } |
@@ -66,15 +66,15 @@ discard block |
||
| 66 | 66 | |
| 67 | 67 | |
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * generate_add_to_iCal_button |
|
| 71 | - * |
|
| 72 | - * @access public |
|
| 73 | - * @param $html |
|
| 74 | - * @param $datetime |
|
| 75 | - * @return string |
|
| 76 | - * @throws \EE_Error |
|
| 77 | - */ |
|
| 69 | + /** |
|
| 70 | + * generate_add_to_iCal_button |
|
| 71 | + * |
|
| 72 | + * @access public |
|
| 73 | + * @param $html |
|
| 74 | + * @param $datetime |
|
| 75 | + * @return string |
|
| 76 | + * @throws \EE_Error |
|
| 77 | + */ |
|
| 78 | 78 | public static function generate_add_to_iCal_button( $html, $datetime ) { |
| 79 | 79 | // first verify a proper datetime object has been received |
| 80 | 80 | if ( $datetime instanceof EE_Datetime ) { |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | $html .= '</form>'; |
| 94 | 94 | break; |
| 95 | 95 | // buttons are just links that have been styled to appear as buttons, |
| 96 | - // but may not be blend with a theme as well as submit buttons |
|
| 96 | + // but may not be blend with a theme as well as submit buttons |
|
| 97 | 97 | case 'button' : |
| 98 | 98 | $html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="' . $URL; |
| 99 | 99 | $html .= '" title="' . __( 'Add to iCal Calendar', 'event_espresso' ) . '">'; |
@@ -114,13 +114,13 @@ discard block |
||
| 114 | 114 | |
| 115 | 115 | |
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * download_ics_file |
|
| 119 | - * |
|
| 120 | - * @access public |
|
| 121 | - * @return void |
|
| 122 | - * @throws \EE_Error |
|
| 123 | - */ |
|
| 117 | + /** |
|
| 118 | + * download_ics_file |
|
| 119 | + * |
|
| 120 | + * @access public |
|
| 121 | + * @return void |
|
| 122 | + * @throws \EE_Error |
|
| 123 | + */ |
|
| 124 | 124 | public static function download_ics_file() { |
| 125 | 125 | if ( EE_Registry::instance()->REQ->is_set( 'ics_id' )) { |
| 126 | 126 | $DTT_ID = absint( EE_Registry::instance()->REQ->get( 'ics_id' )); |
@@ -228,8 +228,8 @@ discard block |
||
| 228 | 228 | //Escape special chars within the description |
| 229 | 229 | $description = EED_Ical::_escape_ICal_data( $description ); |
| 230 | 230 | |
| 231 | - //Remove line breaks and output in iCal format |
|
| 232 | - $description = str_replace( array( "\r\n", "\n"), '\n', $description ); |
|
| 231 | + //Remove line breaks and output in iCal format |
|
| 232 | + $description = str_replace( array( "\r\n", "\n"), '\n', $description ); |
|
| 233 | 233 | |
| 234 | 234 | return $description; |
| 235 | 235 | } |
@@ -1,4 +1,6 @@ |
||
| 1 | -<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | +} |
|
| 2 | 4 | |
| 3 | 5 | /** |
| 4 | 6 | * EED_Ical Class |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | * @return EED_Ical|EED_Module |
| 20 | 20 | */ |
| 21 | 21 | public static function instance() { |
| 22 | - return parent::get_instance( __CLASS__ ); |
|
| 22 | + return parent::get_instance(__CLASS__); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | |
@@ -34,12 +34,12 @@ discard block |
||
| 34 | 34 | // create download buttons |
| 35 | 35 | add_filter( |
| 36 | 36 | 'FHEE__espresso_list_of_event_dates__datetime_html', |
| 37 | - array( 'EED_Ical', 'generate_add_to_iCal_button' ), |
|
| 37 | + array('EED_Ical', 'generate_add_to_iCal_button'), |
|
| 38 | 38 | 10, |
| 39 | 39 | 2 |
| 40 | 40 | ); |
| 41 | 41 | // process ics download request |
| 42 | - EE_Config::register_route( 'download_ics_file', 'EED_Ical', 'download_ics_file' ); |
|
| 42 | + EE_Config::register_route('download_ics_file', 'EED_Ical', 'download_ics_file'); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * @param WP $WP |
| 63 | 63 | * @return void |
| 64 | 64 | */ |
| 65 | - public function run( $WP ) {} |
|
| 65 | + public function run($WP) {} |
|
| 66 | 66 | |
| 67 | 67 | |
| 68 | 68 | |
@@ -75,35 +75,35 @@ discard block |
||
| 75 | 75 | * @return string |
| 76 | 76 | * @throws \EE_Error |
| 77 | 77 | */ |
| 78 | - public static function generate_add_to_iCal_button( $html, $datetime ) { |
|
| 78 | + public static function generate_add_to_iCal_button($html, $datetime) { |
|
| 79 | 79 | // first verify a proper datetime object has been received |
| 80 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 80 | + if ($datetime instanceof EE_Datetime) { |
|
| 81 | 81 | // set whether a link or submit button is shown |
| 82 | - $iCal_type = apply_filters( 'FHEE__EED_Ical__generate_add_to_iCal_button__iCal_type', 'submit' ); |
|
| 82 | + $iCal_type = apply_filters('FHEE__EED_Ical__generate_add_to_iCal_button__iCal_type', 'submit'); |
|
| 83 | 83 | // generate a link to the route we registered in set_hooks() |
| 84 | - $URL = add_query_arg( array( 'ee' => 'download_ics_file', 'ics_id' => $datetime->ID() ), site_url() ); |
|
| 84 | + $URL = add_query_arg(array('ee' => 'download_ics_file', 'ics_id' => $datetime->ID()), site_url()); |
|
| 85 | 85 | // what type ? |
| 86 | - switch ( $iCal_type ) { |
|
| 86 | + switch ($iCal_type) { |
|
| 87 | 87 | // submit buttons appear as buttons and are very compatible with a theme's style |
| 88 | 88 | case 'submit' : |
| 89 | - $html .= '<form id="download-iCal-frm-' . $datetime->ID(); |
|
| 90 | - $html .= '" class="download-iCal-frm" action="' . $URL . '" method="post" >'; |
|
| 89 | + $html .= '<form id="download-iCal-frm-'.$datetime->ID(); |
|
| 90 | + $html .= '" class="download-iCal-frm" action="'.$URL.'" method="post" >'; |
|
| 91 | 91 | $html .= '<input type="submit" class="ee-ical-sbmt" value="" title="'; |
| 92 | - $html .= __( 'Add to iCal Calendar', 'event_espresso' ) . '"/>'; |
|
| 92 | + $html .= __('Add to iCal Calendar', 'event_espresso').'"/>'; |
|
| 93 | 93 | $html .= '</form>'; |
| 94 | 94 | break; |
| 95 | 95 | // buttons are just links that have been styled to appear as buttons, |
| 96 | 96 | // but may not be blend with a theme as well as submit buttons |
| 97 | 97 | case 'button' : |
| 98 | - $html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="' . $URL; |
|
| 99 | - $html .= '" title="' . __( 'Add to iCal Calendar', 'event_espresso' ) . '">'; |
|
| 98 | + $html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="'.$URL; |
|
| 99 | + $html .= '" title="'.__('Add to iCal Calendar', 'event_espresso').'">'; |
|
| 100 | 100 | $html .= ' <span class="dashicons dashicons-calendar"></span>'; |
| 101 | 101 | $html .= '</a>'; |
| 102 | 102 | break; |
| 103 | 103 | // links are just links that use the calendar dashicon |
| 104 | 104 | case 'icon' : |
| 105 | - $html .= '<a class="ee-ical-lnk" href="' . $URL . '" title="'; |
|
| 106 | - $html .= __( 'Add to iCal Calendar', 'event_espresso' ) . '">'; |
|
| 105 | + $html .= '<a class="ee-ical-lnk" href="'.$URL.'" title="'; |
|
| 106 | + $html .= __('Add to iCal Calendar', 'event_espresso').'">'; |
|
| 107 | 107 | $html .= ' <span class="dashicons dashicons-calendar"></span>'; |
| 108 | 108 | $html .= '</a>'; |
| 109 | 109 | break; |
@@ -122,29 +122,29 @@ discard block |
||
| 122 | 122 | * @throws \EE_Error |
| 123 | 123 | */ |
| 124 | 124 | public static function download_ics_file() { |
| 125 | - if ( EE_Registry::instance()->REQ->is_set( 'ics_id' )) { |
|
| 126 | - $DTT_ID = absint( EE_Registry::instance()->REQ->get( 'ics_id' )); |
|
| 127 | - $datetime = EE_Registry::instance()->load_model( 'Datetime' )->get_one_by_ID( $DTT_ID ); |
|
| 128 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 125 | + if (EE_Registry::instance()->REQ->is_set('ics_id')) { |
|
| 126 | + $DTT_ID = absint(EE_Registry::instance()->REQ->get('ics_id')); |
|
| 127 | + $datetime = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($DTT_ID); |
|
| 128 | + if ($datetime instanceof EE_Datetime) { |
|
| 129 | 129 | // get related event, venues, and event categories |
| 130 | 130 | $event = $datetime->event(); |
| 131 | 131 | // get related category Term object and it's name |
| 132 | 132 | $category = $event->first_event_category(); |
| 133 | - if ( $category instanceof EE_Term ) { |
|
| 133 | + if ($category instanceof EE_Term) { |
|
| 134 | 134 | $category = $category->name(); |
| 135 | 135 | } |
| 136 | 136 | $location = ''; |
| 137 | 137 | // get first related venue and convert to CSV string |
| 138 | - $venue = $event->venues(array( 'limit'=>1 )); |
|
| 139 | - if ( is_array( $venue ) && ! empty( $venue )) { |
|
| 140 | - $venue = array_shift( $venue ); |
|
| 141 | - if ( $venue instanceof EE_Venue ) { |
|
| 142 | - $location = espresso_venue_raw_address( 'inline', $venue->ID(), FALSE ); |
|
| 138 | + $venue = $event->venues(array('limit'=>1)); |
|
| 139 | + if (is_array($venue) && ! empty($venue)) { |
|
| 140 | + $venue = array_shift($venue); |
|
| 141 | + if ($venue instanceof EE_Venue) { |
|
| 142 | + $location = espresso_venue_raw_address('inline', $venue->ID(), FALSE); |
|
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | //Generate filename |
| 147 | - $filename = $event->slug() . '-' . $datetime->start_date( 'Y-m-d' ) . '.ics'; |
|
| 147 | + $filename = $event->slug().'-'.$datetime->start_date('Y-m-d').'.ics'; |
|
| 148 | 148 | |
| 149 | 149 | //Check the datetime status has not been cancelled and set the ics value accordingly |
| 150 | 150 | $status = $datetime->get_active_status(); |
@@ -153,62 +153,62 @@ discard block |
||
| 153 | 153 | // Create array of ics details, escape strings, convert timestamps to ics format, etc |
| 154 | 154 | $ics_data = array( |
| 155 | 155 | 'ORGANIZER_NAME' => EE_Registry::instance()->CFG->organization->name, |
| 156 | - 'UID' => md5( $event->name() . $event->ID() . $datetime->ID() ), |
|
| 156 | + 'UID' => md5($event->name().$event->ID().$datetime->ID()), |
|
| 157 | 157 | 'ORGANIZER' => EE_Registry::instance()->CFG->organization->email, |
| 158 | - 'DTSTAMP' => date( EED_Ical::iCal_datetime_format ), |
|
| 158 | + 'DTSTAMP' => date(EED_Ical::iCal_datetime_format), |
|
| 159 | 159 | 'LOCATION' => $location, |
| 160 | 160 | 'SUMMARY' => $event->name(), |
| 161 | - 'DESCRIPTION' => wp_strip_all_tags( $event->description() ), |
|
| 161 | + 'DESCRIPTION' => wp_strip_all_tags($event->description()), |
|
| 162 | 162 | 'STATUS' => $status, |
| 163 | 163 | 'CATEGORIES' => $category, |
| 164 | - 'URL;VALUE=URI' => get_permalink( $event->ID() ), |
|
| 165 | - 'DTSTART' => date( EED_Ical::iCal_datetime_format, $datetime->start() ), |
|
| 166 | - 'DTEND' => date( EED_Ical::iCal_datetime_format, $datetime->end() ), |
|
| 164 | + 'URL;VALUE=URI' => get_permalink($event->ID()), |
|
| 165 | + 'DTSTART' => date(EED_Ical::iCal_datetime_format, $datetime->start()), |
|
| 166 | + 'DTEND' => date(EED_Ical::iCal_datetime_format, $datetime->end()), |
|
| 167 | 167 | ); |
| 168 | 168 | |
| 169 | 169 | //Filter the values used within the ics output. |
| 170 | 170 | //NOTE - all values within ics_data will be escaped automatically. |
| 171 | - $ics_data = apply_filters( 'FHEE__EED_Ical__download_ics_file_ics_data', $ics_data, $datetime ); |
|
| 171 | + $ics_data = apply_filters('FHEE__EED_Ical__download_ics_file_ics_data', $ics_data, $datetime); |
|
| 172 | 172 | |
| 173 | 173 | //Escape all ics data |
| 174 | - foreach( $ics_data as $key => $value ) { |
|
| 174 | + foreach ($ics_data as $key => $value) { |
|
| 175 | 175 | //Description is escaped differently from all all values |
| 176 | - if( $key === 'DESCRIPTION' ) { |
|
| 177 | - $ics_data[$key] = EED_Ical::_escape_ICal_description( wp_strip_all_tags( $value ) ); |
|
| 176 | + if ($key === 'DESCRIPTION') { |
|
| 177 | + $ics_data[$key] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value)); |
|
| 178 | 178 | } else { |
| 179 | - $ics_data[$key] = EED_Ical::_escape_ICal_data( $value ); |
|
| 179 | + $ics_data[$key] = EED_Ical::_escape_ICal_data($value); |
|
| 180 | 180 | } |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | //Pull the organizer name from ics_data and remove it from the array. |
| 184 | - $organizer_name = isset( $ics_data['ORGANIZER_NAME'] ) ? $ics_data['ORGANIZER_NAME'] : ''; |
|
| 185 | - unset( $ics_data['ORGANIZER_NAME'] ); |
|
| 184 | + $organizer_name = isset($ics_data['ORGANIZER_NAME']) ? $ics_data['ORGANIZER_NAME'] : ''; |
|
| 185 | + unset($ics_data['ORGANIZER_NAME']); |
|
| 186 | 186 | |
| 187 | 187 | // set headers |
| 188 | - header( 'Content-type: text/calendar; charset=utf-8' ); |
|
| 189 | - header( 'Content-Disposition: attachment; filename="' . $filename . '"' ); |
|
| 190 | - header( 'Cache-Control: private, max-age=0, must-revalidate' ); |
|
| 191 | - header( 'Pragma: public' ); |
|
| 192 | - header( 'Content-Type: application/octet-stream' ); |
|
| 193 | - header( 'Content-Type: application/force-download' ); |
|
| 194 | - header( 'Cache-Control: no-cache, must-revalidate' ); |
|
| 195 | - header( 'Content-Transfer-Encoding: binary' ); |
|
| 196 | - header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); // past date |
|
| 197 | - ini_set( 'zlib.output_compression', '0' ); |
|
| 188 | + header('Content-type: text/calendar; charset=utf-8'); |
|
| 189 | + header('Content-Disposition: attachment; filename="'.$filename.'"'); |
|
| 190 | + header('Cache-Control: private, max-age=0, must-revalidate'); |
|
| 191 | + header('Pragma: public'); |
|
| 192 | + header('Content-Type: application/octet-stream'); |
|
| 193 | + header('Content-Type: application/force-download'); |
|
| 194 | + header('Cache-Control: no-cache, must-revalidate'); |
|
| 195 | + header('Content-Transfer-Encoding: binary'); |
|
| 196 | + header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // past date |
|
| 197 | + ini_set('zlib.output_compression', '0'); |
|
| 198 | 198 | // echo the output |
| 199 | - echo "BEGIN:VCALENDAR" . PHP_EOL; |
|
| 200 | - echo "VERSION:2.0" . PHP_EOL; |
|
| 201 | - echo "PRODID:-//{$organizer_name}//NONSGML PDA Calendar Version 1.0//EN" . PHP_EOL; |
|
| 202 | - echo "CALSCALE:GREGORIAN" . PHP_EOL; |
|
| 203 | - echo "BEGIN:VEVENT" . PHP_EOL; |
|
| 199 | + echo "BEGIN:VCALENDAR".PHP_EOL; |
|
| 200 | + echo "VERSION:2.0".PHP_EOL; |
|
| 201 | + echo "PRODID:-//{$organizer_name}//NONSGML PDA Calendar Version 1.0//EN".PHP_EOL; |
|
| 202 | + echo "CALSCALE:GREGORIAN".PHP_EOL; |
|
| 203 | + echo "BEGIN:VEVENT".PHP_EOL; |
|
| 204 | 204 | |
| 205 | 205 | //Output all remaining values from ics_data. |
| 206 | - foreach( $ics_data as $key => $value ) { |
|
| 207 | - echo $key . ':' . $value . PHP_EOL; |
|
| 206 | + foreach ($ics_data as $key => $value) { |
|
| 207 | + echo $key.':'.$value.PHP_EOL; |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - echo "END:VEVENT" . PHP_EOL; |
|
| 211 | - echo "END:VCALENDAR" . PHP_EOL; |
|
| 210 | + echo "END:VEVENT".PHP_EOL; |
|
| 211 | + echo "END:VCALENDAR".PHP_EOL; |
|
| 212 | 212 | } |
| 213 | 213 | } |
| 214 | 214 | die(); |
@@ -223,8 +223,8 @@ discard block |
||
| 223 | 223 | * @param string $string |
| 224 | 224 | * @return string |
| 225 | 225 | */ |
| 226 | - private static function _escape_ICal_data( $string = '' ) { |
|
| 227 | - return preg_replace( '/([\,;])/', '\\\$1', $string ); |
|
| 226 | + private static function _escape_ICal_data($string = '') { |
|
| 227 | + return preg_replace('/([\,;])/', '\\\$1', $string); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -234,13 +234,13 @@ discard block |
||
| 234 | 234 | * @param string $description |
| 235 | 235 | * @return string |
| 236 | 236 | */ |
| 237 | - private static function _escape_ICal_description( $description = '' ) { |
|
| 237 | + private static function _escape_ICal_description($description = '') { |
|
| 238 | 238 | |
| 239 | 239 | //Escape special chars within the description |
| 240 | - $description = EED_Ical::_escape_ICal_data( $description ); |
|
| 240 | + $description = EED_Ical::_escape_ICal_data($description); |
|
| 241 | 241 | |
| 242 | 242 | //Remove line breaks and output in iCal format |
| 243 | - $description = str_replace( array( "\r\n", "\n"), '\n', $description ); |
|
| 243 | + $description = str_replace(array("\r\n", "\n"), '\n', $description); |
|
| 244 | 244 | |
| 245 | 245 | return $description; |
| 246 | 246 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | $this->_admin_base_url = EE_MSG_ADMIN_URL; |
| 88 | 88 | $this->_admin_base_path = EE_MSG_ADMIN; |
| 89 | 89 | |
| 90 | - $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array(); |
|
| 90 | + $this->_activate_state = isset($this->_req_data['activate_state']) ? (array) $this->_req_data['activate_state'] : array(); |
|
| 91 | 91 | |
| 92 | 92 | $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
| 93 | 93 | $this->_load_message_resource_manager(); |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | array('none_selected' => __('Show All Messengers', 'event_espresso')), |
| 220 | 220 | $messenger_options |
| 221 | 221 | ); |
| 222 | - $input = new EE_Select_Input( |
|
| 222 | + $input = new EE_Select_Input( |
|
| 223 | 223 | $messenger_options, |
| 224 | 224 | array( |
| 225 | 225 | 'html_name' => 'ee_messenger_filter_by', |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | array('none_selected' => __('Show All Message Types', 'event_espresso')), |
| 258 | 258 | $message_type_options |
| 259 | 259 | ); |
| 260 | - $input = new EE_Select_Input( |
|
| 260 | + $input = new EE_Select_Input( |
|
| 261 | 261 | $message_type_options, |
| 262 | 262 | array( |
| 263 | 263 | 'html_name' => 'ee_message_type_filter_by', |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | array('none_selected' => __('Show all Contexts', 'event_espresso')), |
| 296 | 296 | $context_options |
| 297 | 297 | ); |
| 298 | - $input = new EE_Select_Input( |
|
| 298 | + $input = new EE_Select_Input( |
|
| 299 | 299 | $context_options, |
| 300 | 300 | array( |
| 301 | 301 | 'html_name' => 'ee_context_filter_by', |
@@ -676,47 +676,47 @@ discard block |
||
| 676 | 676 | |
| 677 | 677 | public function messages_help_tab() |
| 678 | 678 | { |
| 679 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 679 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php'); |
|
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | |
| 683 | 683 | public function messengers_help_tab() |
| 684 | 684 | { |
| 685 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 685 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php'); |
|
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | |
| 689 | 689 | public function message_types_help_tab() |
| 690 | 690 | { |
| 691 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 691 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php'); |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | |
| 695 | 695 | public function messages_overview_help_tab() |
| 696 | 696 | { |
| 697 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 697 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php'); |
|
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | |
| 701 | 701 | public function message_templates_help_tab() |
| 702 | 702 | { |
| 703 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 703 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php'); |
|
| 704 | 704 | } |
| 705 | 705 | |
| 706 | 706 | |
| 707 | 707 | public function edit_message_template_help_tab() |
| 708 | 708 | { |
| 709 | - $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title', |
|
| 710 | - 'event_espresso') . '" />'; |
|
| 711 | - $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview', |
|
| 712 | - 'event_espresso') . '" />'; |
|
| 713 | - $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields', |
|
| 714 | - 'event_espresso') . '" />'; |
|
| 715 | - $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox', |
|
| 716 | - 'event_espresso') . '" />'; |
|
| 717 | - $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox', |
|
| 718 | - 'event_espresso') . '" />'; |
|
| 719 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 709 | + $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="'.esc_attr__('Editor Title', |
|
| 710 | + 'event_espresso').'" />'; |
|
| 711 | + $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="'.esc_attr__('Context Switcher and Preview', |
|
| 712 | + 'event_espresso').'" />'; |
|
| 713 | + $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="'.esc_attr__('Message Template Form Fields', |
|
| 714 | + 'event_espresso').'" />'; |
|
| 715 | + $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="'.esc_attr__('Shortcodes Metabox', |
|
| 716 | + 'event_espresso').'" />'; |
|
| 717 | + $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="'.esc_attr__('Publish Metabox', |
|
| 718 | + 'event_espresso').'" />'; |
|
| 719 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 720 | 720 | $args); |
| 721 | 721 | } |
| 722 | 722 | |
@@ -725,37 +725,37 @@ discard block |
||
| 725 | 725 | { |
| 726 | 726 | $this->_set_shortcodes(); |
| 727 | 727 | $args['shortcodes'] = $this->_shortcodes; |
| 728 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 728 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 729 | 729 | $args); |
| 730 | 730 | } |
| 731 | 731 | |
| 732 | 732 | |
| 733 | 733 | public function preview_message_help_tab() |
| 734 | 734 | { |
| 735 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 735 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php'); |
|
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | |
| 739 | 739 | public function settings_help_tab() |
| 740 | 740 | { |
| 741 | - $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab', |
|
| 742 | - 'event_espresso') . '" />'; |
|
| 743 | - $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab', |
|
| 744 | - 'event_espresso') . '" />'; |
|
| 741 | + $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'.'" alt="'.esc_attr__('Active Email Tab', |
|
| 742 | + 'event_espresso').'" />'; |
|
| 743 | + $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'.'" alt="'.esc_attr__('Inactive Email Tab', |
|
| 744 | + 'event_espresso').'" />'; |
|
| 745 | 745 | $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>'; |
| 746 | 746 | $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>'; |
| 747 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 747 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 748 | 748 | } |
| 749 | 749 | |
| 750 | 750 | |
| 751 | 751 | public function load_scripts_styles() |
| 752 | 752 | { |
| 753 | - wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 753 | + wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 754 | 754 | wp_enqueue_style('espresso_ee_msg'); |
| 755 | 755 | |
| 756 | - wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 756 | + wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL.'ee-messages-settings.js', |
|
| 757 | 757 | array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); |
| 758 | - wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 758 | + wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js', |
|
| 759 | 759 | array('ee-dialog'), EVENT_ESPRESSO_VERSION); |
| 760 | 760 | } |
| 761 | 761 | |
@@ -787,7 +787,7 @@ discard block |
||
| 787 | 787 | |
| 788 | 788 | $this->_set_shortcodes(); |
| 789 | 789 | |
| 790 | - EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 790 | + EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 791 | 791 | __('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.', |
| 792 | 792 | 'event_espresso'), |
| 793 | 793 | $this->_message_template_group->messenger_obj()->label['singular'], |
@@ -796,7 +796,7 @@ discard block |
||
| 796 | 796 | 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?', |
| 797 | 797 | 'event_espresso'); |
| 798 | 798 | |
| 799 | - wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'), |
|
| 799 | + wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL.'ee_message_editor.js', array('jquery'), |
|
| 800 | 800 | EVENT_ESPRESSO_VERSION); |
| 801 | 801 | |
| 802 | 802 | wp_enqueue_script('ee_admin_js'); |
@@ -827,7 +827,7 @@ discard block |
||
| 827 | 827 | |
| 828 | 828 | public function load_scripts_styles_settings() |
| 829 | 829 | { |
| 830 | - wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(), |
|
| 830 | + wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL.'ee_message_settings.css', array(), |
|
| 831 | 831 | EVENT_ESPRESSO_VERSION); |
| 832 | 832 | wp_enqueue_style('ee-text-links'); |
| 833 | 833 | wp_enqueue_style('ee-message-settings'); |
@@ -893,7 +893,7 @@ discard block |
||
| 893 | 893 | } |
| 894 | 894 | $status_bulk_actions = $common_bulk_actions; |
| 895 | 895 | //unset bulk actions not applying to status |
| 896 | - if (! empty($status_bulk_actions)) { |
|
| 896 | + if ( ! empty($status_bulk_actions)) { |
|
| 897 | 897 | switch ($status) { |
| 898 | 898 | case EEM_Message::status_idle: |
| 899 | 899 | case EEM_Message::status_resend: |
@@ -918,7 +918,7 @@ discard block |
||
| 918 | 918 | } |
| 919 | 919 | |
| 920 | 920 | //skip adding messenger executing status to views because it will be included with the Failed view. |
| 921 | - if ( $status === EEM_Message::status_messenger_executing ) { |
|
| 921 | + if ($status === EEM_Message::status_messenger_executing) { |
|
| 922 | 922 | continue; |
| 923 | 923 | } |
| 924 | 924 | |
@@ -944,7 +944,7 @@ discard block |
||
| 944 | 944 | $this->_search_btn_label = __('Message Activity', 'event_espresso'); |
| 945 | 945 | $this->_template_args['per_column'] = 6; |
| 946 | 946 | $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); |
| 947 | - $this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>'; |
|
| 947 | + $this->_template_args['before_list_table'] = '<h3>'.EEM_Message::instance()->get_pretty_label_for_results().'</h3>'; |
|
| 948 | 948 | $this->display_admin_list_table_page_with_no_sidebar(); |
| 949 | 949 | } |
| 950 | 950 | |
@@ -968,37 +968,37 @@ discard block |
||
| 968 | 968 | /** @type array $status_items status legend setup */ |
| 969 | 969 | $status_items = array( |
| 970 | 970 | 'sent_status' => array( |
| 971 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 971 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_sent, |
|
| 972 | 972 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence') |
| 973 | 973 | ), |
| 974 | 974 | 'idle_status' => array( |
| 975 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 975 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_idle, |
|
| 976 | 976 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence') |
| 977 | 977 | ), |
| 978 | 978 | 'failed_status' => array( |
| 979 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 979 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_failed, |
|
| 980 | 980 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence') |
| 981 | 981 | ), |
| 982 | 982 | 'messenger_executing_status' => array( |
| 983 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, |
|
| 983 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_messenger_executing, |
|
| 984 | 984 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence') |
| 985 | 985 | ), |
| 986 | 986 | 'resend_status' => array( |
| 987 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 987 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_resend, |
|
| 988 | 988 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence') |
| 989 | 989 | ), |
| 990 | 990 | 'incomplete_status' => array( |
| 991 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 991 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_incomplete, |
|
| 992 | 992 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence') |
| 993 | 993 | ), |
| 994 | 994 | 'retry_status' => array( |
| 995 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 995 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_retry, |
|
| 996 | 996 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence') |
| 997 | 997 | ) |
| 998 | 998 | ); |
| 999 | 999 | if (EEM_Message::debug()) { |
| 1000 | 1000 | $status_items['debug_only_status'] = array( |
| 1001 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 1001 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_debug_only, |
|
| 1002 | 1002 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence') |
| 1003 | 1003 | ); |
| 1004 | 1004 | } |
@@ -1010,10 +1010,10 @@ discard block |
||
| 1010 | 1010 | protected function _custom_mtps_preview() |
| 1011 | 1011 | { |
| 1012 | 1012 | $this->_admin_page_title = __('Custom Message Templates (Preview)', 'event_espresso'); |
| 1013 | - $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot', |
|
| 1014 | - 'event_espresso') . '" />'; |
|
| 1015 | - $this->_template_args['preview_text'] = '<strong>' . __('Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', |
|
| 1016 | - 'event_espresso') . '</strong>'; |
|
| 1013 | + $this->_template_args['preview_img'] = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png" alt="'.esc_attr__('Preview Custom Message Templates screenshot', |
|
| 1014 | + 'event_espresso').'" />'; |
|
| 1015 | + $this->_template_args['preview_text'] = '<strong>'.__('Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', |
|
| 1016 | + 'event_espresso').'</strong>'; |
|
| 1017 | 1017 | $this->display_admin_caf_preview_page('custom_message_types', false); |
| 1018 | 1018 | } |
| 1019 | 1019 | |
@@ -1261,7 +1261,7 @@ discard block |
||
| 1261 | 1261 | //let's verify if we need this extra field via the shortcodes parameter. |
| 1262 | 1262 | $continue = false; |
| 1263 | 1263 | if (isset($extra_array['shortcodes_required'])) { |
| 1264 | - foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { |
|
| 1264 | + foreach ((array) $extra_array['shortcodes_required'] as $shortcode) { |
|
| 1265 | 1265 | if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
| 1266 | 1266 | $continue = true; |
| 1267 | 1267 | } |
@@ -1271,9 +1271,9 @@ discard block |
||
| 1271 | 1271 | } |
| 1272 | 1272 | } |
| 1273 | 1273 | |
| 1274 | - $field_id = $reference_field . '-' . $extra_field . '-content'; |
|
| 1274 | + $field_id = $reference_field.'-'.$extra_field.'-content'; |
|
| 1275 | 1275 | $template_form_fields[$field_id] = $extra_array; |
| 1276 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']'; |
|
| 1276 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields['.$reference_field.'][content]['.$extra_field.']'; |
|
| 1277 | 1277 | $css_class = isset($extra_array['css_class']) ? $extra_array['css_class'] : ''; |
| 1278 | 1278 | |
| 1279 | 1279 | $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
@@ -1283,7 +1283,7 @@ discard block |
||
| 1283 | 1283 | is_array($validators[$extra_field]) |
| 1284 | 1284 | && isset($validators[$extra_field]['msg']) |
| 1285 | 1285 | ) |
| 1286 | - ? 'validate-error ' . $css_class |
|
| 1286 | + ? 'validate-error '.$css_class |
|
| 1287 | 1287 | : $css_class; |
| 1288 | 1288 | |
| 1289 | 1289 | $template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field]) |
@@ -1311,11 +1311,11 @@ discard block |
||
| 1311 | 1311 | |
| 1312 | 1312 | }/**/ |
| 1313 | 1313 | } |
| 1314 | - $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1315 | - $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1314 | + $templatefield_MTP_id = $reference_field.'-MTP_ID'; |
|
| 1315 | + $templatefield_templatename_id = $reference_field.'-name'; |
|
| 1316 | 1316 | |
| 1317 | 1317 | $template_form_fields[$templatefield_MTP_id] = array( |
| 1318 | - 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1318 | + 'name' => 'MTP_template_fields['.$reference_field.'][MTP_ID]', |
|
| 1319 | 1319 | 'label' => null, |
| 1320 | 1320 | 'input' => 'hidden', |
| 1321 | 1321 | 'type' => 'int', |
@@ -1328,7 +1328,7 @@ discard block |
||
| 1328 | 1328 | ); |
| 1329 | 1329 | |
| 1330 | 1330 | $template_form_fields[$templatefield_templatename_id] = array( |
| 1331 | - 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1331 | + 'name' => 'MTP_template_fields['.$reference_field.'][name]', |
|
| 1332 | 1332 | 'label' => null, |
| 1333 | 1333 | 'input' => 'hidden', |
| 1334 | 1334 | 'type' => 'string', |
@@ -1342,9 +1342,9 @@ discard block |
||
| 1342 | 1342 | } |
| 1343 | 1343 | continue; //skip the next stuff, we got the necessary fields here for this dataset. |
| 1344 | 1344 | } else { |
| 1345 | - $field_id = $template_field . '-content'; |
|
| 1345 | + $field_id = $template_field.'-content'; |
|
| 1346 | 1346 | $template_form_fields[$field_id] = $field_setup_array; |
| 1347 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1347 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields['.$template_field.'][content]'; |
|
| 1348 | 1348 | $message_template = isset($message_templates[$context][$template_field]) |
| 1349 | 1349 | ? $message_templates[$context][$template_field] |
| 1350 | 1350 | : null; |
@@ -1365,7 +1365,7 @@ discard block |
||
| 1365 | 1365 | $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
| 1366 | 1366 | && in_array($template_field, $v_fields) |
| 1367 | 1367 | && isset($validators[$template_field]['msg']) |
| 1368 | - ? 'validate-error ' . $css_class |
|
| 1368 | + ? 'validate-error '.$css_class |
|
| 1369 | 1369 | : $css_class; |
| 1370 | 1370 | |
| 1371 | 1371 | //shortcode selector |
@@ -1376,12 +1376,12 @@ discard block |
||
| 1376 | 1376 | |
| 1377 | 1377 | //k took care of content field(s) now let's take care of others. |
| 1378 | 1378 | |
| 1379 | - $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1380 | - $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1379 | + $templatefield_MTP_id = $template_field.'-MTP_ID'; |
|
| 1380 | + $templatefield_field_templatename_id = $template_field.'-name'; |
|
| 1381 | 1381 | |
| 1382 | 1382 | //foreach template field there are actually two form fields created |
| 1383 | 1383 | $template_form_fields[$templatefield_MTP_id] = array( |
| 1384 | - 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1384 | + 'name' => 'MTP_template_fields['.$template_field.'][MTP_ID]', |
|
| 1385 | 1385 | 'label' => null, |
| 1386 | 1386 | 'input' => 'hidden', |
| 1387 | 1387 | 'type' => 'int', |
@@ -1394,7 +1394,7 @@ discard block |
||
| 1394 | 1394 | ); |
| 1395 | 1395 | |
| 1396 | 1396 | $template_form_fields[$templatefield_field_templatename_id] = array( |
| 1397 | - 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1397 | + 'name' => 'MTP_template_fields['.$template_field.'][name]', |
|
| 1398 | 1398 | 'label' => null, |
| 1399 | 1399 | 'input' => 'hidden', |
| 1400 | 1400 | 'type' => 'string', |
@@ -1512,7 +1512,7 @@ discard block |
||
| 1512 | 1512 | 'format' => '%d', |
| 1513 | 1513 | 'db-col' => 'MTP_deleted' |
| 1514 | 1514 | ); |
| 1515 | - $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1515 | + $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1516 | 1516 | 'name' => 'MTP_user_id', |
| 1517 | 1517 | 'label' => __('Author', 'event_espresso'), |
| 1518 | 1518 | 'input' => 'hidden', |
@@ -1531,17 +1531,17 @@ discard block |
||
| 1531 | 1531 | 'value' => $action |
| 1532 | 1532 | ); |
| 1533 | 1533 | |
| 1534 | - $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1534 | + $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1535 | 1535 | 'name' => 'id', |
| 1536 | 1536 | 'input' => 'hidden', |
| 1537 | 1537 | 'type' => 'int', |
| 1538 | 1538 | 'value' => $GRP_ID |
| 1539 | 1539 | ); |
| 1540 | 1540 | $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
| 1541 | - 'name' => $action . '_nonce', |
|
| 1541 | + 'name' => $action.'_nonce', |
|
| 1542 | 1542 | 'input' => 'hidden', |
| 1543 | 1543 | 'type' => 'string', |
| 1544 | - 'value' => wp_create_nonce($action . '_nonce') |
|
| 1544 | + 'value' => wp_create_nonce($action.'_nonce') |
|
| 1545 | 1545 | ); |
| 1546 | 1546 | |
| 1547 | 1547 | if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
@@ -1573,7 +1573,7 @@ discard block |
||
| 1573 | 1573 | ); |
| 1574 | 1574 | |
| 1575 | 1575 | //add preview button |
| 1576 | - $preview_url = parent::add_query_args_and_nonce( |
|
| 1576 | + $preview_url = parent::add_query_args_and_nonce( |
|
| 1577 | 1577 | array( |
| 1578 | 1578 | 'message_type' => $message_template_group->message_type(), |
| 1579 | 1579 | 'messenger' => $message_template_group->messenger(), |
@@ -1583,8 +1583,8 @@ discard block |
||
| 1583 | 1583 | ), |
| 1584 | 1584 | $this->_admin_base_url |
| 1585 | 1585 | ); |
| 1586 | - $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview', |
|
| 1587 | - 'event_espresso') . '</a>'; |
|
| 1586 | + $preview_button = '<a href="'.$preview_url.'" class="button-secondary messages-preview-button">'.__('Preview', |
|
| 1587 | + 'event_espresso').'</a>'; |
|
| 1588 | 1588 | |
| 1589 | 1589 | |
| 1590 | 1590 | //setup context switcher |
@@ -1612,8 +1612,8 @@ discard block |
||
| 1612 | 1612 | $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after(); |
| 1613 | 1613 | |
| 1614 | 1614 | $this->_template_path = $this->_template_args['GRP_ID'] |
| 1615 | - ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
|
| 1616 | - : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1615 | + ? EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_edit_meta_box.template.php' |
|
| 1616 | + : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1617 | 1617 | |
| 1618 | 1618 | //send along EE_Message_Template_Group object for further template use. |
| 1619 | 1619 | $this->_template_args['MTP'] = $message_template_group; |
@@ -1648,7 +1648,7 @@ discard block |
||
| 1648 | 1648 | |
| 1649 | 1649 | public function _add_form_element_before() |
| 1650 | 1650 | { |
| 1651 | - return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">'; |
|
| 1651 | + return '<form method="post" action="'.$this->_template_args["edit_message_template_form_url"].'" id="ee-msg-edit-frm">'; |
|
| 1652 | 1652 | } |
| 1653 | 1653 | |
| 1654 | 1654 | public function _add_form_element_after() |
@@ -1843,14 +1843,14 @@ discard block |
||
| 1843 | 1843 | } |
| 1844 | 1844 | |
| 1845 | 1845 | //let's add a button to go back to the edit view |
| 1846 | - $query_args = array( |
|
| 1846 | + $query_args = array( |
|
| 1847 | 1847 | 'id' => $this->_req_data['GRP_ID'], |
| 1848 | 1848 | 'context' => $this->_req_data['context'], |
| 1849 | 1849 | 'action' => 'edit_message_template' |
| 1850 | 1850 | ); |
| 1851 | 1851 | $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
| 1852 | - $preview_button = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit', |
|
| 1853 | - 'event_espresso') . '</a>'; |
|
| 1852 | + $preview_button = '<a href="'.$go_back_url.'" class="button-secondary messages-preview-go-back-button">'.__('Go Back to Edit', |
|
| 1853 | + 'event_espresso').'</a>'; |
|
| 1854 | 1854 | $message_types = $this->get_installed_message_types(); |
| 1855 | 1855 | $active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
| 1856 | 1856 | $active_messenger_label = $active_messenger instanceof EE_messenger |
@@ -1864,7 +1864,7 @@ discard block |
||
| 1864 | 1864 | ); |
| 1865 | 1865 | //setup display of preview. |
| 1866 | 1866 | $this->_admin_page_title = $preview_title; |
| 1867 | - $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview); |
|
| 1867 | + $this->_template_args['admin_page_content'] = $preview_button.'<br />'.stripslashes($preview); |
|
| 1868 | 1868 | $this->_template_args['data']['force_json'] = true; |
| 1869 | 1869 | |
| 1870 | 1870 | return ''; |
@@ -1946,7 +1946,7 @@ discard block |
||
| 1946 | 1946 | } |
| 1947 | 1947 | |
| 1948 | 1948 | //setup variation select values for the currently selected template. |
| 1949 | - $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 1949 | + $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 1950 | 1950 | $this->_message_template_group->messenger(), |
| 1951 | 1951 | $this->_message_template_group->message_type() |
| 1952 | 1952 | ); |
@@ -1960,12 +1960,12 @@ discard block |
||
| 1960 | 1960 | |
| 1961 | 1961 | $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
| 1962 | 1962 | |
| 1963 | - $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 1963 | + $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 1964 | 1964 | 'MTP_template_pack', |
| 1965 | 1965 | $tp_select_values, |
| 1966 | 1966 | $this->_message_template_group->get_template_pack_name() |
| 1967 | 1967 | ); |
| 1968 | - $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 1968 | + $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 1969 | 1969 | 'MTP_template_variation', |
| 1970 | 1970 | $variations_select_values, |
| 1971 | 1971 | $this->_message_template_group->get_template_pack_variation() |
@@ -1975,7 +1975,7 @@ discard block |
||
| 1975 | 1975 | $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
| 1976 | 1976 | $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
| 1977 | 1977 | |
| 1978 | - $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 1978 | + $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php'; |
|
| 1979 | 1979 | |
| 1980 | 1980 | EEH_Template::display_template($template, $template_args); |
| 1981 | 1981 | } |
@@ -2004,7 +2004,7 @@ discard block |
||
| 2004 | 2004 | if ( ! empty($fields)) { |
| 2005 | 2005 | //yup there be fields |
| 2006 | 2006 | foreach ($fields as $field => $config) { |
| 2007 | - $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 2007 | + $field_id = $this->_message_template_group->messenger().'_'.$field; |
|
| 2008 | 2008 | $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
| 2009 | 2009 | $default = isset($config['default']) ? $config['default'] : ''; |
| 2010 | 2010 | $default = isset($config['value']) ? $config['value'] : $default; |
@@ -2019,7 +2019,7 @@ discard block |
||
| 2019 | 2019 | : $fix; |
| 2020 | 2020 | |
| 2021 | 2021 | $template_form_fields[$field_id] = array( |
| 2022 | - 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2022 | + 'name' => 'test_settings_fld['.$field.']', |
|
| 2023 | 2023 | 'label' => $config['label'], |
| 2024 | 2024 | 'input' => $config['input'], |
| 2025 | 2025 | 'type' => $config['type'], |
@@ -2049,7 +2049,7 @@ discard block |
||
| 2049 | 2049 | } |
| 2050 | 2050 | |
| 2051 | 2051 | //and button |
| 2052 | - $test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>'; |
|
| 2052 | + $test_settings_html .= '<p>'.__('Need to reset this message type and start over?', 'event_espresso').'</p>'; |
|
| 2053 | 2053 | $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; |
| 2054 | 2054 | $test_settings_html .= $this->get_action_link_or_button( |
| 2055 | 2055 | 'reset_to_default', |
@@ -2080,7 +2080,7 @@ discard block |
||
| 2080 | 2080 | 'linked_input_id' => $linked_input_id |
| 2081 | 2081 | ); |
| 2082 | 2082 | |
| 2083 | - return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2083 | + return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php', |
|
| 2084 | 2084 | $template_args, true); |
| 2085 | 2085 | } |
| 2086 | 2086 | |
@@ -2098,7 +2098,7 @@ discard block |
||
| 2098 | 2098 | //$messenger = $this->_message_template_group->messenger_obj(); |
| 2099 | 2099 | //now let's set the content depending on the status of the shortcodes array |
| 2100 | 2100 | if (empty($shortcodes)) { |
| 2101 | - $content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2101 | + $content = '<p>'.__('There are no valid shortcodes available', 'event_espresso').'</p>'; |
|
| 2102 | 2102 | echo $content; |
| 2103 | 2103 | } else { |
| 2104 | 2104 | //$alt = 0; |
@@ -2215,7 +2215,7 @@ discard block |
||
| 2215 | 2215 | <?php |
| 2216 | 2216 | } |
| 2217 | 2217 | //setup nonce_url |
| 2218 | - wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2218 | + wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false); |
|
| 2219 | 2219 | ?> |
| 2220 | 2220 | <select name="context"> |
| 2221 | 2221 | <?php |
@@ -2313,7 +2313,7 @@ discard block |
||
| 2313 | 2313 | : ''; |
| 2314 | 2314 | $context = ucwords(str_replace('_', ' ', $context_slug)); |
| 2315 | 2315 | |
| 2316 | - $item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : ''; |
|
| 2316 | + $item_desc = $messenger_label && $message_type_label ? $messenger_label.' '.$message_type_label.' '.$context.' ' : ''; |
|
| 2317 | 2317 | $item_desc .= 'Message Template'; |
| 2318 | 2318 | $query_args = array(); |
| 2319 | 2319 | $edit_array = array(); |
@@ -2682,8 +2682,8 @@ discard block |
||
| 2682 | 2682 | */ |
| 2683 | 2683 | protected function _learn_more_about_message_templates_link() |
| 2684 | 2684 | { |
| 2685 | - return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works', |
|
| 2686 | - 'event_espresso') . '</a>'; |
|
| 2685 | + return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'.__('learn more about how message templates works', |
|
| 2686 | + 'event_espresso').'</a>'; |
|
| 2687 | 2687 | } |
| 2688 | 2688 | |
| 2689 | 2689 | |
@@ -2759,10 +2759,10 @@ discard block |
||
| 2759 | 2759 | |
| 2760 | 2760 | $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
| 2761 | 2761 | 'label' => ucwords($message_type->label['singular']), |
| 2762 | - 'class' => 'message-type-' . $a_or_i, |
|
| 2763 | - 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 2764 | - 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 2765 | - 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 2762 | + 'class' => 'message-type-'.$a_or_i, |
|
| 2763 | + 'slug_id' => $message_type->name.'-messagetype-'.$messenger->name, |
|
| 2764 | + 'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'), |
|
| 2765 | + 'href' => 'espresso_'.$message_type->name.'_message_type_settings', |
|
| 2766 | 2766 | 'title' => $a_or_i == 'active' |
| 2767 | 2767 | ? __('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
| 2768 | 2768 | : __('Drag this message type to the messenger to activate', 'event_espresso'), |
@@ -2798,9 +2798,9 @@ discard block |
||
| 2798 | 2798 | $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
| 2799 | 2799 | |
| 2800 | 2800 | foreach ($fields as $fldname => $fldprops) { |
| 2801 | - $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 2801 | + $field_id = $messenger->name.'-'.$message_type->name.'-'.$fldname; |
|
| 2802 | 2802 | $template_form_field[$field_id] = array( |
| 2803 | - 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 2803 | + 'name' => 'message_type_settings['.$fldname.']', |
|
| 2804 | 2804 | 'label' => $fldprops['label'], |
| 2805 | 2805 | 'input' => $fldprops['field_type'], |
| 2806 | 2806 | 'type' => $fldprops['value_type'], |
@@ -2841,7 +2841,7 @@ discard block |
||
| 2841 | 2841 | $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) ? ' hidden' : ''; |
| 2842 | 2842 | |
| 2843 | 2843 | |
| 2844 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 2844 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php'; |
|
| 2845 | 2845 | $content = EEH_Template::display_template($template, $settings_template_args, true); |
| 2846 | 2846 | |
| 2847 | 2847 | return $content; |
@@ -2871,11 +2871,11 @@ discard block |
||
| 2871 | 2871 | $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active']) |
| 2872 | 2872 | ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
| 2873 | 2873 | : ''; |
| 2874 | - $m_boxes[$messenger . '_a_box'] = sprintf( |
|
| 2874 | + $m_boxes[$messenger.'_a_box'] = sprintf( |
|
| 2875 | 2875 | __('%s Settings', 'event_espresso'), |
| 2876 | 2876 | $tab_array['label'] |
| 2877 | 2877 | ); |
| 2878 | - $m_template_args[$messenger . '_a_box'] = array( |
|
| 2878 | + $m_template_args[$messenger.'_a_box'] = array( |
|
| 2879 | 2879 | 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
| 2880 | 2880 | 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
| 2881 | 2881 | ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
@@ -2889,8 +2889,8 @@ discard block |
||
| 2889 | 2889 | // message type meta boxes |
| 2890 | 2890 | // (which is really just the inactive container for each messenger |
| 2891 | 2891 | // showing inactive message types for that messenger) |
| 2892 | - $mt_boxes[$messenger . '_i_box'] = __('Inactive Message Types', 'event_espresso'); |
|
| 2893 | - $mt_template_args[$messenger . '_i_box'] = array( |
|
| 2892 | + $mt_boxes[$messenger.'_i_box'] = __('Inactive Message Types', 'event_espresso'); |
|
| 2893 | + $mt_template_args[$messenger.'_i_box'] = array( |
|
| 2894 | 2894 | 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
| 2895 | 2895 | 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
| 2896 | 2896 | ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
@@ -2906,14 +2906,14 @@ discard block |
||
| 2906 | 2906 | |
| 2907 | 2907 | |
| 2908 | 2908 | //register messenger metaboxes |
| 2909 | - $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 2909 | + $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 2910 | 2910 | foreach ($m_boxes as $box => $label) { |
| 2911 | 2911 | $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
| 2912 | 2912 | $msgr = str_replace('_a_box', '', $box); |
| 2913 | 2913 | add_meta_box( |
| 2914 | - 'espresso_' . $msgr . '_settings', |
|
| 2914 | + 'espresso_'.$msgr.'_settings', |
|
| 2915 | 2915 | $label, |
| 2916 | - function ($post, $metabox) { |
|
| 2916 | + function($post, $metabox) { |
|
| 2917 | 2917 | echo EEH_Template::display_template($metabox["args"]["template_path"], |
| 2918 | 2918 | $metabox["args"]["template_args"], true); |
| 2919 | 2919 | }, |
@@ -2925,17 +2925,17 @@ discard block |
||
| 2925 | 2925 | } |
| 2926 | 2926 | |
| 2927 | 2927 | //register message type metaboxes |
| 2928 | - $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 2928 | + $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php'; |
|
| 2929 | 2929 | foreach ($mt_boxes as $box => $label) { |
| 2930 | 2930 | $callback_args = array( |
| 2931 | 2931 | 'template_path' => $mt_template_path, |
| 2932 | 2932 | 'template_args' => $mt_template_args[$box] |
| 2933 | 2933 | ); |
| 2934 | - $mt = str_replace('_i_box', '', $box); |
|
| 2934 | + $mt = str_replace('_i_box', '', $box); |
|
| 2935 | 2935 | add_meta_box( |
| 2936 | - 'espresso_' . $mt . '_inactive_mts', |
|
| 2936 | + 'espresso_'.$mt.'_inactive_mts', |
|
| 2937 | 2937 | $label, |
| 2938 | - function ($post, $metabox) { |
|
| 2938 | + function($post, $metabox) { |
|
| 2939 | 2939 | echo EEH_Template::display_template($metabox["args"]["template_path"], |
| 2940 | 2940 | $metabox["args"]["template_args"], true); |
| 2941 | 2941 | }, |
@@ -3037,7 +3037,7 @@ discard block |
||
| 3037 | 3037 | if ($form->is_valid()) { |
| 3038 | 3038 | $valid_data = $form->valid_data(); |
| 3039 | 3039 | foreach ($valid_data as $property => $value) { |
| 3040 | - $setter = 'set_' . $property; |
|
| 3040 | + $setter = 'set_'.$property; |
|
| 3041 | 3041 | if (method_exists($network_config, $setter)) { |
| 3042 | 3042 | $network_config->{$setter}($value); |
| 3043 | 3043 | } else if ( |
@@ -3066,8 +3066,8 @@ discard block |
||
| 3066 | 3066 | */ |
| 3067 | 3067 | protected function _get_mt_tabs($tab_array) |
| 3068 | 3068 | { |
| 3069 | - $tab_array = (array)$tab_array; |
|
| 3070 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3069 | + $tab_array = (array) $tab_array; |
|
| 3070 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3071 | 3071 | $tabs = ''; |
| 3072 | 3072 | |
| 3073 | 3073 | foreach ($tab_array as $tab) { |
@@ -3100,9 +3100,9 @@ discard block |
||
| 3100 | 3100 | $existing_settings = $messenger->get_existing_admin_settings(); |
| 3101 | 3101 | |
| 3102 | 3102 | foreach ($fields as $fldname => $fldprops) { |
| 3103 | - $field_id = $messenger->name . '-' . $fldname; |
|
| 3103 | + $field_id = $messenger->name.'-'.$fldname; |
|
| 3104 | 3104 | $template_form_field[$field_id] = array( |
| 3105 | - 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3105 | + 'name' => 'messenger_settings['.$field_id.']', |
|
| 3106 | 3106 | 'label' => $fldprops['label'], |
| 3107 | 3107 | 'input' => $fldprops['field_type'], |
| 3108 | 3108 | 'type' => $fldprops['value_type'], |
@@ -3137,7 +3137,7 @@ discard block |
||
| 3137 | 3137 | //make sure any active message types that are existing are included in the hidden fields |
| 3138 | 3138 | if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
| 3139 | 3139 | foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
| 3140 | - $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array( |
|
| 3140 | + $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = array( |
|
| 3141 | 3141 | 'type' => 'hidden', |
| 3142 | 3142 | 'value' => $mt |
| 3143 | 3143 | ); |
@@ -3147,7 +3147,7 @@ discard block |
||
| 3147 | 3147 | $settings_template_args['hidden_fields'], |
| 3148 | 3148 | 'array' |
| 3149 | 3149 | ); |
| 3150 | - $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3150 | + $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3151 | 3151 | |
| 3152 | 3152 | $settings_template_args['messenger'] = $messenger->name; |
| 3153 | 3153 | $settings_template_args['description'] = $messenger->description; |
@@ -3164,9 +3164,9 @@ discard block |
||
| 3164 | 3164 | |
| 3165 | 3165 | |
| 3166 | 3166 | $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
| 3167 | - $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3167 | + $settings_template_args['nonce'] = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce'); |
|
| 3168 | 3168 | $settings_template_args['on_off_status'] = $active ? true : false; |
| 3169 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3169 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php'; |
|
| 3170 | 3170 | $content = EEH_Template::display_template($template, $settings_template_args, |
| 3171 | 3171 | true); |
| 3172 | 3172 | |
@@ -3194,7 +3194,7 @@ discard block |
||
| 3194 | 3194 | |
| 3195 | 3195 | //do a nonce check here since we're not arriving via a normal route |
| 3196 | 3196 | $nonce = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : ''; |
| 3197 | - $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3197 | + $nonce_ref = 'activate_'.$this->_req_data['messenger'].'_toggle_nonce'; |
|
| 3198 | 3198 | |
| 3199 | 3199 | $this->_verify_nonce($nonce, $nonce_ref); |
| 3200 | 3200 | |
@@ -3296,7 +3296,7 @@ discard block |
||
| 3296 | 3296 | |
| 3297 | 3297 | //do a nonce check here since we're not arriving via a normal route |
| 3298 | 3298 | $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
| 3299 | - $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3299 | + $nonce_ref = $this->_req_data['message_type'].'_nonce'; |
|
| 3300 | 3300 | |
| 3301 | 3301 | $this->_verify_nonce($nonce, $nonce_ref); |
| 3302 | 3302 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('NO direct script access allowed'); |
|
| 2 | + exit('NO direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | /** |
@@ -17,2213 +17,2213 @@ discard block |
||
| 17 | 17 | class Messages_Admin_Page extends EE_Admin_Page |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 22 | - */ |
|
| 23 | - protected $_message_resource_manager; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @type string $_active_message_type_name |
|
| 27 | - */ |
|
| 28 | - protected $_active_message_type_name = ''; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @type EE_messenger $_active_messenger |
|
| 32 | - */ |
|
| 33 | - protected $_active_messenger; |
|
| 34 | - protected $_activate_state; |
|
| 35 | - protected $_activate_meta_box_type; |
|
| 36 | - protected $_current_message_meta_box; |
|
| 37 | - protected $_current_message_meta_box_object; |
|
| 38 | - protected $_context_switcher; |
|
| 39 | - protected $_shortcodes = array(); |
|
| 40 | - protected $_active_messengers = array(); |
|
| 41 | - protected $_active_message_types = array(); |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @var EE_Message_Template_Group $_message_template_group |
|
| 45 | - */ |
|
| 46 | - protected $_message_template_group; |
|
| 47 | - protected $_m_mt_settings = array(); |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * This is set via the _set_message_template_group method and holds whatever the template pack for the group is. |
|
| 52 | - * IF there is no group then it gets automatically set to the Default template pack. |
|
| 53 | - * |
|
| 54 | - * @since 4.5.0 |
|
| 55 | - * |
|
| 56 | - * @var EE_Messages_Template_Pack |
|
| 57 | - */ |
|
| 58 | - protected $_template_pack; |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * This is set via the _set_message_template_group method and holds whatever the template pack variation for the |
|
| 63 | - * group is. If there is no group then it automatically gets set to default. |
|
| 64 | - * |
|
| 65 | - * @since 4.5.0 |
|
| 66 | - * |
|
| 67 | - * @var string |
|
| 68 | - */ |
|
| 69 | - protected $_variation; |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @param bool $routing |
|
| 74 | - */ |
|
| 75 | - public function __construct($routing = true) |
|
| 76 | - { |
|
| 77 | - //make sure messages autoloader is running |
|
| 78 | - EED_Messages::set_autoloaders(); |
|
| 79 | - parent::__construct($routing); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - protected function _init_page_props() |
|
| 84 | - { |
|
| 85 | - $this->page_slug = EE_MSG_PG_SLUG; |
|
| 86 | - $this->page_label = __('Messages Settings', 'event_espresso'); |
|
| 87 | - $this->_admin_base_url = EE_MSG_ADMIN_URL; |
|
| 88 | - $this->_admin_base_path = EE_MSG_ADMIN; |
|
| 89 | - |
|
| 90 | - $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array(); |
|
| 91 | - |
|
| 92 | - $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
|
| 93 | - $this->_load_message_resource_manager(); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * loads messenger objects into the $_active_messengers property (so we can access the needed methods) |
|
| 99 | - * |
|
| 100 | - * |
|
| 101 | - * @throws EE_Error |
|
| 102 | - */ |
|
| 103 | - protected function _load_message_resource_manager() |
|
| 104 | - { |
|
| 105 | - $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @deprecated 4.9.9.rc.014 |
|
| 111 | - * @return array |
|
| 112 | - */ |
|
| 113 | - public function get_messengers_for_list_table() |
|
| 114 | - { |
|
| 115 | - EE_Error::doing_it_wrong( |
|
| 116 | - __METHOD__, |
|
| 117 | - __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 20 | + /** |
|
| 21 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 22 | + */ |
|
| 23 | + protected $_message_resource_manager; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @type string $_active_message_type_name |
|
| 27 | + */ |
|
| 28 | + protected $_active_message_type_name = ''; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @type EE_messenger $_active_messenger |
|
| 32 | + */ |
|
| 33 | + protected $_active_messenger; |
|
| 34 | + protected $_activate_state; |
|
| 35 | + protected $_activate_meta_box_type; |
|
| 36 | + protected $_current_message_meta_box; |
|
| 37 | + protected $_current_message_meta_box_object; |
|
| 38 | + protected $_context_switcher; |
|
| 39 | + protected $_shortcodes = array(); |
|
| 40 | + protected $_active_messengers = array(); |
|
| 41 | + protected $_active_message_types = array(); |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @var EE_Message_Template_Group $_message_template_group |
|
| 45 | + */ |
|
| 46 | + protected $_message_template_group; |
|
| 47 | + protected $_m_mt_settings = array(); |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * This is set via the _set_message_template_group method and holds whatever the template pack for the group is. |
|
| 52 | + * IF there is no group then it gets automatically set to the Default template pack. |
|
| 53 | + * |
|
| 54 | + * @since 4.5.0 |
|
| 55 | + * |
|
| 56 | + * @var EE_Messages_Template_Pack |
|
| 57 | + */ |
|
| 58 | + protected $_template_pack; |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * This is set via the _set_message_template_group method and holds whatever the template pack variation for the |
|
| 63 | + * group is. If there is no group then it automatically gets set to default. |
|
| 64 | + * |
|
| 65 | + * @since 4.5.0 |
|
| 66 | + * |
|
| 67 | + * @var string |
|
| 68 | + */ |
|
| 69 | + protected $_variation; |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @param bool $routing |
|
| 74 | + */ |
|
| 75 | + public function __construct($routing = true) |
|
| 76 | + { |
|
| 77 | + //make sure messages autoloader is running |
|
| 78 | + EED_Messages::set_autoloaders(); |
|
| 79 | + parent::__construct($routing); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + protected function _init_page_props() |
|
| 84 | + { |
|
| 85 | + $this->page_slug = EE_MSG_PG_SLUG; |
|
| 86 | + $this->page_label = __('Messages Settings', 'event_espresso'); |
|
| 87 | + $this->_admin_base_url = EE_MSG_ADMIN_URL; |
|
| 88 | + $this->_admin_base_path = EE_MSG_ADMIN; |
|
| 89 | + |
|
| 90 | + $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array(); |
|
| 91 | + |
|
| 92 | + $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
|
| 93 | + $this->_load_message_resource_manager(); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * loads messenger objects into the $_active_messengers property (so we can access the needed methods) |
|
| 99 | + * |
|
| 100 | + * |
|
| 101 | + * @throws EE_Error |
|
| 102 | + */ |
|
| 103 | + protected function _load_message_resource_manager() |
|
| 104 | + { |
|
| 105 | + $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @deprecated 4.9.9.rc.014 |
|
| 111 | + * @return array |
|
| 112 | + */ |
|
| 113 | + public function get_messengers_for_list_table() |
|
| 114 | + { |
|
| 115 | + EE_Error::doing_it_wrong( |
|
| 116 | + __METHOD__, |
|
| 117 | + __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 118 | 118 | values for use in creating a messenger filter dropdown which is now generated differently via |
| 119 | 119 | Messages_Admin_Page::get_messengers_select_input', 'event_espresso'), |
| 120 | - '4.9.9.rc.014' |
|
| 121 | - ); |
|
| 122 | - |
|
| 123 | - $m_values = array(); |
|
| 124 | - $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); |
|
| 125 | - //setup messengers for selects |
|
| 126 | - $i = 1; |
|
| 127 | - foreach ($active_messengers as $active_messenger) { |
|
| 128 | - if ($active_messenger instanceof EE_Message) { |
|
| 129 | - $m_values[$i]['id'] = $active_messenger->messenger(); |
|
| 130 | - $m_values[$i]['text'] = ucwords($active_messenger->messenger_label()); |
|
| 131 | - $i++; |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - return $m_values; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @deprecated 4.9.9.rc.014 |
|
| 141 | - * @return array |
|
| 142 | - */ |
|
| 143 | - public function get_message_types_for_list_table() |
|
| 144 | - { |
|
| 145 | - EE_Error::doing_it_wrong( |
|
| 146 | - __METHOD__, |
|
| 147 | - __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 120 | + '4.9.9.rc.014' |
|
| 121 | + ); |
|
| 122 | + |
|
| 123 | + $m_values = array(); |
|
| 124 | + $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); |
|
| 125 | + //setup messengers for selects |
|
| 126 | + $i = 1; |
|
| 127 | + foreach ($active_messengers as $active_messenger) { |
|
| 128 | + if ($active_messenger instanceof EE_Message) { |
|
| 129 | + $m_values[$i]['id'] = $active_messenger->messenger(); |
|
| 130 | + $m_values[$i]['text'] = ucwords($active_messenger->messenger_label()); |
|
| 131 | + $i++; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + return $m_values; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @deprecated 4.9.9.rc.014 |
|
| 141 | + * @return array |
|
| 142 | + */ |
|
| 143 | + public function get_message_types_for_list_table() |
|
| 144 | + { |
|
| 145 | + EE_Error::doing_it_wrong( |
|
| 146 | + __METHOD__, |
|
| 147 | + __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 148 | 148 | values for use in creating a message type filter dropdown which is now generated differently via |
| 149 | 149 | Messages_Admin_Page::get_message_types_select_input', 'event_espresso'), |
| 150 | - '4.9.9.rc.014' |
|
| 151 | - ); |
|
| 152 | - |
|
| 153 | - $mt_values = array(); |
|
| 154 | - $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type')); |
|
| 155 | - $i = 1; |
|
| 156 | - foreach ($active_messages as $active_message) { |
|
| 157 | - if ($active_message instanceof EE_Message) { |
|
| 158 | - $mt_values[$i]['id'] = $active_message->message_type(); |
|
| 159 | - $mt_values[$i]['text'] = ucwords($active_message->message_type_label()); |
|
| 160 | - $i++; |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - return $mt_values; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @deprecated 4.9.9.rc.014 |
|
| 170 | - * @return array |
|
| 171 | - */ |
|
| 172 | - public function get_contexts_for_message_types_for_list_table() |
|
| 173 | - { |
|
| 174 | - EE_Error::doing_it_wrong( |
|
| 175 | - __METHOD__, |
|
| 176 | - __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 150 | + '4.9.9.rc.014' |
|
| 151 | + ); |
|
| 152 | + |
|
| 153 | + $mt_values = array(); |
|
| 154 | + $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type')); |
|
| 155 | + $i = 1; |
|
| 156 | + foreach ($active_messages as $active_message) { |
|
| 157 | + if ($active_message instanceof EE_Message) { |
|
| 158 | + $mt_values[$i]['id'] = $active_message->message_type(); |
|
| 159 | + $mt_values[$i]['text'] = ucwords($active_message->message_type_label()); |
|
| 160 | + $i++; |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + return $mt_values; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @deprecated 4.9.9.rc.014 |
|
| 170 | + * @return array |
|
| 171 | + */ |
|
| 172 | + public function get_contexts_for_message_types_for_list_table() |
|
| 173 | + { |
|
| 174 | + EE_Error::doing_it_wrong( |
|
| 175 | + __METHOD__, |
|
| 176 | + __('This method is no longer in use. There is no replacement for it. The method was used to generate a set of |
|
| 177 | 177 | values for use in creating a message type context filter dropdown which is now generated differently via |
| 178 | 178 | Messages_Admin_Page::get_contexts_for_message_types_select_input', 'event_espresso'), |
| 179 | - '4.9.9.rc.014' |
|
| 180 | - ); |
|
| 181 | - |
|
| 182 | - $contexts = array(); |
|
| 183 | - $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); |
|
| 184 | - foreach ($active_message_contexts as $active_message) { |
|
| 185 | - if ($active_message instanceof EE_Message) { |
|
| 186 | - $message_type = $active_message->message_type_object(); |
|
| 187 | - if ($message_type instanceof EE_message_type) { |
|
| 188 | - $message_type_contexts = $message_type->get_contexts(); |
|
| 189 | - foreach ($message_type_contexts as $context => $context_details) { |
|
| 190 | - $contexts[$context] = $context_details['label']; |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - return $contexts; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * Generate select input with provided messenger options array. |
|
| 202 | - * |
|
| 203 | - * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger |
|
| 204 | - * labels. |
|
| 205 | - * |
|
| 206 | - * @return string |
|
| 207 | - */ |
|
| 208 | - public function get_messengers_select_input($messenger_options) |
|
| 209 | - { |
|
| 210 | - //if empty or just one value then just return an empty string |
|
| 211 | - if (empty($messenger_options) |
|
| 212 | - || ! is_array($messenger_options) |
|
| 213 | - || count($messenger_options) === 1 |
|
| 214 | - ) { |
|
| 215 | - return ''; |
|
| 216 | - } |
|
| 217 | - //merge in default |
|
| 218 | - $messenger_options = array_merge( |
|
| 219 | - array('none_selected' => __('Show All Messengers', 'event_espresso')), |
|
| 220 | - $messenger_options |
|
| 221 | - ); |
|
| 222 | - $input = new EE_Select_Input( |
|
| 223 | - $messenger_options, |
|
| 224 | - array( |
|
| 225 | - 'html_name' => 'ee_messenger_filter_by', |
|
| 226 | - 'html_id' => 'ee_messenger_filter_by', |
|
| 227 | - 'html_class' => 'wide', |
|
| 228 | - 'default' => isset($this->_req_data['ee_messenger_filter_by']) |
|
| 229 | - ? sanitize_title($this->_req_data['ee_messenger_filter_by']) |
|
| 230 | - : 'none_selected' |
|
| 231 | - ) |
|
| 232 | - ); |
|
| 233 | - |
|
| 234 | - return $input->get_html_for_input(); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * Generate select input with provided message type options array. |
|
| 240 | - * |
|
| 241 | - * @param array $message_type_options Array of message types indexed by message type slug, and values are the |
|
| 242 | - * message type labels |
|
| 243 | - * |
|
| 244 | - * @return string |
|
| 245 | - */ |
|
| 246 | - public function get_message_types_select_input($message_type_options) |
|
| 247 | - { |
|
| 248 | - //if empty or count of options is 1 then just return an empty string |
|
| 249 | - if (empty($message_type_options) |
|
| 250 | - || ! is_array($message_type_options) |
|
| 251 | - || count($message_type_options) === 1 |
|
| 252 | - ) { |
|
| 253 | - return ''; |
|
| 254 | - } |
|
| 255 | - //merge in default |
|
| 256 | - $message_type_options = array_merge( |
|
| 257 | - array('none_selected' => __('Show All Message Types', 'event_espresso')), |
|
| 258 | - $message_type_options |
|
| 259 | - ); |
|
| 260 | - $input = new EE_Select_Input( |
|
| 261 | - $message_type_options, |
|
| 262 | - array( |
|
| 263 | - 'html_name' => 'ee_message_type_filter_by', |
|
| 264 | - 'html_id' => 'ee_message_type_filter_by', |
|
| 265 | - 'html_class' => 'wide', |
|
| 266 | - 'default' => isset($this->_req_data['ee_message_type_filter_by']) |
|
| 267 | - ? sanitize_title($this->_req_data['ee_message_type_filter_by']) |
|
| 268 | - : 'none_selected', |
|
| 269 | - ) |
|
| 270 | - ); |
|
| 271 | - |
|
| 272 | - return $input->get_html_for_input(); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * Generate select input with provide message type contexts array. |
|
| 278 | - * |
|
| 279 | - * @param array $context_options Array of message type contexts indexed by context slug, and values are the |
|
| 280 | - * context label. |
|
| 281 | - * |
|
| 282 | - * @return string |
|
| 283 | - */ |
|
| 284 | - public function get_contexts_for_message_types_select_input($context_options) |
|
| 285 | - { |
|
| 286 | - //if empty or count of options is one then just return empty string |
|
| 287 | - if (empty($context_options) |
|
| 288 | - || ! is_array($context_options) |
|
| 289 | - || count($context_options) === 1 |
|
| 290 | - ) { |
|
| 291 | - return ''; |
|
| 292 | - } |
|
| 293 | - //merge in default |
|
| 294 | - $context_options = array_merge( |
|
| 295 | - array('none_selected' => __('Show all Contexts', 'event_espresso')), |
|
| 296 | - $context_options |
|
| 297 | - ); |
|
| 298 | - $input = new EE_Select_Input( |
|
| 299 | - $context_options, |
|
| 300 | - array( |
|
| 301 | - 'html_name' => 'ee_context_filter_by', |
|
| 302 | - 'html_id' => 'ee_context_filter_by', |
|
| 303 | - 'html_class' => 'wide', |
|
| 304 | - 'default' => isset($this->_req_data['ee_context_filter_by']) |
|
| 305 | - ? sanitize_title($this->_req_data['ee_context_filter_by']) |
|
| 306 | - : 'none_selected', |
|
| 307 | - ) |
|
| 308 | - ); |
|
| 309 | - |
|
| 310 | - return $input->get_html_for_input(); |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - |
|
| 314 | - protected function _ajax_hooks() |
|
| 315 | - { |
|
| 316 | - add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle')); |
|
| 317 | - add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle')); |
|
| 318 | - add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings')); |
|
| 319 | - add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form')); |
|
| 320 | - add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack')); |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - protected function _define_page_props() |
|
| 325 | - { |
|
| 326 | - $this->_admin_page_title = $this->page_label; |
|
| 327 | - $this->_labels = array( |
|
| 328 | - 'buttons' => array( |
|
| 329 | - 'add' => __('Add New Message Template', 'event_espresso'), |
|
| 330 | - 'edit' => __('Edit Message Template', 'event_espresso'), |
|
| 331 | - 'delete' => __('Delete Message Template', 'event_espresso') |
|
| 332 | - ), |
|
| 333 | - 'publishbox' => __('Update Actions', 'event_espresso') |
|
| 334 | - ); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * an array for storing key => value pairs of request actions and their corresponding methods |
|
| 340 | - * @access protected |
|
| 341 | - * @return void |
|
| 342 | - */ |
|
| 343 | - protected function _set_page_routes() |
|
| 344 | - { |
|
| 345 | - $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID']) |
|
| 346 | - ? $this->_req_data['GRP_ID'] |
|
| 347 | - : 0; |
|
| 348 | - $grp_id = empty($grp_id) && ! empty($this->_req_data['id']) |
|
| 349 | - ? $this->_req_data['id'] |
|
| 350 | - : $grp_id; |
|
| 351 | - $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID']) |
|
| 352 | - ? $this->_req_data['MSG_ID'] |
|
| 353 | - : 0; |
|
| 354 | - |
|
| 355 | - $this->_page_routes = array( |
|
| 356 | - 'default' => array( |
|
| 357 | - 'func' => '_message_queue_list_table', |
|
| 358 | - 'capability' => 'ee_read_global_messages' |
|
| 359 | - ), |
|
| 360 | - 'global_mtps' => array( |
|
| 361 | - 'func' => '_ee_default_messages_overview_list_table', |
|
| 362 | - 'capability' => 'ee_read_global_messages' |
|
| 363 | - ), |
|
| 364 | - 'custom_mtps' => array( |
|
| 365 | - 'func' => '_custom_mtps_preview', |
|
| 366 | - 'capability' => 'ee_read_messages' |
|
| 367 | - ), |
|
| 368 | - 'add_new_message_template' => array( |
|
| 369 | - 'func' => '_add_message_template', |
|
| 370 | - 'capability' => 'ee_edit_messages', |
|
| 371 | - 'noheader' => true |
|
| 372 | - ), |
|
| 373 | - 'edit_message_template' => array( |
|
| 374 | - 'func' => '_edit_message_template', |
|
| 375 | - 'capability' => 'ee_edit_message', |
|
| 376 | - 'obj_id' => $grp_id |
|
| 377 | - ), |
|
| 378 | - 'preview_message' => array( |
|
| 379 | - 'func' => '_preview_message', |
|
| 380 | - 'capability' => 'ee_read_message', |
|
| 381 | - 'obj_id' => $grp_id, |
|
| 382 | - 'noheader' => true, |
|
| 383 | - 'headers_sent_route' => 'display_preview_message' |
|
| 384 | - ), |
|
| 385 | - 'display_preview_message' => array( |
|
| 386 | - 'func' => '_display_preview_message', |
|
| 387 | - 'capability' => 'ee_read_message', |
|
| 388 | - 'obj_id' => $grp_id |
|
| 389 | - ), |
|
| 390 | - 'insert_message_template' => array( |
|
| 391 | - 'func' => '_insert_or_update_message_template', |
|
| 392 | - 'capability' => 'ee_edit_messages', |
|
| 393 | - 'args' => array('new_template' => true), |
|
| 394 | - 'noheader' => true |
|
| 395 | - ), |
|
| 396 | - 'update_message_template' => array( |
|
| 397 | - 'func' => '_insert_or_update_message_template', |
|
| 398 | - 'capability' => 'ee_edit_message', |
|
| 399 | - 'obj_id' => $grp_id, |
|
| 400 | - 'args' => array('new_template' => false), |
|
| 401 | - 'noheader' => true |
|
| 402 | - ), |
|
| 403 | - 'trash_message_template' => array( |
|
| 404 | - 'func' => '_trash_or_restore_message_template', |
|
| 405 | - 'capability' => 'ee_delete_message', |
|
| 406 | - 'obj_id' => $grp_id, |
|
| 407 | - 'args' => array('trash' => true, 'all' => true), |
|
| 408 | - 'noheader' => true |
|
| 409 | - ), |
|
| 410 | - 'trash_message_template_context' => array( |
|
| 411 | - 'func' => '_trash_or_restore_message_template', |
|
| 412 | - 'capability' => 'ee_delete_message', |
|
| 413 | - 'obj_id' => $grp_id, |
|
| 414 | - 'args' => array('trash' => true), |
|
| 415 | - 'noheader' => true |
|
| 416 | - ), |
|
| 417 | - 'restore_message_template' => array( |
|
| 418 | - 'func' => '_trash_or_restore_message_template', |
|
| 419 | - 'capability' => 'ee_delete_message', |
|
| 420 | - 'obj_id' => $grp_id, |
|
| 421 | - 'args' => array('trash' => false, 'all' => true), |
|
| 422 | - 'noheader' => true |
|
| 423 | - ), |
|
| 424 | - 'restore_message_template_context' => array( |
|
| 425 | - 'func' => '_trash_or_restore_message_template', |
|
| 426 | - 'capability' => 'ee_delete_message', |
|
| 427 | - 'obj_id' => $grp_id, |
|
| 428 | - 'args' => array('trash' => false), |
|
| 429 | - 'noheader' => true |
|
| 430 | - ), |
|
| 431 | - 'delete_message_template' => array( |
|
| 432 | - 'func' => '_delete_message_template', |
|
| 433 | - 'capability' => 'ee_delete_message', |
|
| 434 | - 'obj_id' => $grp_id, |
|
| 435 | - 'noheader' => true |
|
| 436 | - ), |
|
| 437 | - 'reset_to_default' => array( |
|
| 438 | - 'func' => '_reset_to_default_template', |
|
| 439 | - 'capability' => 'ee_edit_message', |
|
| 440 | - 'obj_id' => $grp_id, |
|
| 441 | - 'noheader' => true |
|
| 442 | - ), |
|
| 443 | - 'settings' => array( |
|
| 444 | - 'func' => '_settings', |
|
| 445 | - 'capability' => 'manage_options' |
|
| 446 | - ), |
|
| 447 | - 'update_global_settings' => array( |
|
| 448 | - 'func' => '_update_global_settings', |
|
| 449 | - 'capability' => 'manage_options', |
|
| 450 | - 'noheader' => true |
|
| 451 | - ), |
|
| 452 | - 'generate_now' => array( |
|
| 453 | - 'func' => '_generate_now', |
|
| 454 | - 'capability' => 'ee_send_message', |
|
| 455 | - 'noheader' => true |
|
| 456 | - ), |
|
| 457 | - 'generate_and_send_now' => array( |
|
| 458 | - 'func' => '_generate_and_send_now', |
|
| 459 | - 'capability' => 'ee_send_message', |
|
| 460 | - 'noheader' => true |
|
| 461 | - ), |
|
| 462 | - 'queue_for_resending' => array( |
|
| 463 | - 'func' => '_queue_for_resending', |
|
| 464 | - 'capability' => 'ee_send_message', |
|
| 465 | - 'noheader' => true |
|
| 466 | - ), |
|
| 467 | - 'send_now' => array( |
|
| 468 | - 'func' => '_send_now', |
|
| 469 | - 'capability' => 'ee_send_message', |
|
| 470 | - 'noheader' => true |
|
| 471 | - ), |
|
| 472 | - 'delete_ee_message' => array( |
|
| 473 | - 'func' => '_delete_ee_messages', |
|
| 474 | - 'capability' => 'ee_delete_message', |
|
| 475 | - 'noheader' => true |
|
| 476 | - ), |
|
| 477 | - 'delete_ee_messages' => array( |
|
| 478 | - 'func' => '_delete_ee_messages', |
|
| 479 | - 'capability' => 'ee_delete_messages', |
|
| 480 | - 'noheader' => true, |
|
| 481 | - 'obj_id' => $msg_id |
|
| 482 | - ) |
|
| 483 | - ); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - protected function _set_page_config() |
|
| 488 | - { |
|
| 489 | - $this->_page_config = array( |
|
| 490 | - 'default' => array( |
|
| 491 | - 'nav' => array( |
|
| 492 | - 'label' => __('Message Activity', 'event_espresso'), |
|
| 493 | - 'order' => 10 |
|
| 494 | - ), |
|
| 495 | - 'list_table' => 'EE_Message_List_Table', |
|
| 496 | - // 'qtips' => array( 'EE_Message_List_Table_Tips' ), |
|
| 497 | - 'require_nonce' => false |
|
| 498 | - ), |
|
| 499 | - 'global_mtps' => array( |
|
| 500 | - 'nav' => array( |
|
| 501 | - 'label' => __('Default Message Templates', 'event_espresso'), |
|
| 502 | - 'order' => 20 |
|
| 503 | - ), |
|
| 504 | - 'list_table' => 'Messages_Template_List_Table', |
|
| 505 | - 'help_tabs' => array( |
|
| 506 | - 'messages_overview_help_tab' => array( |
|
| 507 | - 'title' => __('Messages Overview', 'event_espresso'), |
|
| 508 | - 'filename' => 'messages_overview' |
|
| 509 | - ), |
|
| 510 | - 'messages_overview_messages_table_column_headings_help_tab' => array( |
|
| 511 | - 'title' => __('Messages Table Column Headings', 'event_espresso'), |
|
| 512 | - 'filename' => 'messages_overview_table_column_headings' |
|
| 513 | - ), |
|
| 514 | - 'messages_overview_messages_filters_help_tab' => array( |
|
| 515 | - 'title' => __('Message Filters', 'event_espresso'), |
|
| 516 | - 'filename' => 'messages_overview_filters' |
|
| 517 | - ), |
|
| 518 | - 'messages_overview_messages_views_help_tab' => array( |
|
| 519 | - 'title' => __('Message Views', 'event_espresso'), |
|
| 520 | - 'filename' => 'messages_overview_views' |
|
| 521 | - ), |
|
| 522 | - 'message_overview_message_types_help_tab' => array( |
|
| 523 | - 'title' => __('Message Types', 'event_espresso'), |
|
| 524 | - 'filename' => 'messages_overview_types' |
|
| 525 | - ), |
|
| 526 | - 'messages_overview_messengers_help_tab' => array( |
|
| 527 | - 'title' => __('Messengers', 'event_espresso'), |
|
| 528 | - 'filename' => 'messages_overview_messengers', |
|
| 529 | - ), |
|
| 530 | - 'messages_overview_other_help_tab' => array( |
|
| 531 | - 'title' => __('Messages Other', 'event_espresso'), |
|
| 532 | - 'filename' => 'messages_overview_other', |
|
| 533 | - ), |
|
| 534 | - ), |
|
| 535 | - 'help_tour' => array('Messages_Overview_Help_Tour'), |
|
| 536 | - 'require_nonce' => false |
|
| 537 | - ), |
|
| 538 | - 'custom_mtps' => array( |
|
| 539 | - 'nav' => array( |
|
| 540 | - 'label' => __('Custom Message Templates', 'event_espresso'), |
|
| 541 | - 'order' => 30 |
|
| 542 | - ), |
|
| 543 | - 'help_tabs' => array(), |
|
| 544 | - 'help_tour' => array(), |
|
| 545 | - 'require_nonce' => false |
|
| 546 | - ), |
|
| 547 | - 'add_new_message_template' => array( |
|
| 548 | - 'nav' => array( |
|
| 549 | - 'label' => __('Add New Message Templates', 'event_espresso'), |
|
| 550 | - 'order' => 5, |
|
| 551 | - 'persistent' => false |
|
| 552 | - ), |
|
| 553 | - 'require_nonce' => false |
|
| 554 | - ), |
|
| 555 | - 'edit_message_template' => array( |
|
| 556 | - 'labels' => array( |
|
| 557 | - 'buttons' => array( |
|
| 558 | - 'reset' => __('Reset Templates'), |
|
| 559 | - ), |
|
| 560 | - 'publishbox' => __('Update Actions', 'event_espresso') |
|
| 561 | - ), |
|
| 562 | - 'nav' => array( |
|
| 563 | - 'label' => __('Edit Message Templates', 'event_espresso'), |
|
| 564 | - 'order' => 5, |
|
| 565 | - 'persistent' => false, |
|
| 566 | - 'url' => '' |
|
| 567 | - ), |
|
| 568 | - 'metaboxes' => array('_publish_post_box', '_register_edit_meta_boxes'), |
|
| 569 | - 'has_metaboxes' => true, |
|
| 570 | - 'help_tour' => array('Message_Templates_Edit_Help_Tour'), |
|
| 571 | - 'help_tabs' => array( |
|
| 572 | - 'edit_message_template' => array( |
|
| 573 | - 'title' => __('Message Template Editor', 'event_espresso'), |
|
| 574 | - 'callback' => 'edit_message_template_help_tab' |
|
| 575 | - ), |
|
| 576 | - 'message_templates_help_tab' => array( |
|
| 577 | - 'title' => __('Message Templates', 'event_espresso'), |
|
| 578 | - 'filename' => 'messages_templates' |
|
| 579 | - ), |
|
| 580 | - 'message_template_shortcodes' => array( |
|
| 581 | - 'title' => __('Message Shortcodes', 'event_espresso'), |
|
| 582 | - 'callback' => 'message_template_shortcodes_help_tab' |
|
| 583 | - ), |
|
| 584 | - 'message_preview_help_tab' => array( |
|
| 585 | - 'title' => __('Message Preview', 'event_espresso'), |
|
| 586 | - 'filename' => 'messages_preview' |
|
| 587 | - ), |
|
| 588 | - ), |
|
| 589 | - 'require_nonce' => false |
|
| 590 | - ), |
|
| 591 | - 'display_preview_message' => array( |
|
| 592 | - 'nav' => array( |
|
| 593 | - 'label' => __('Message Preview', 'event_espresso'), |
|
| 594 | - 'order' => 5, |
|
| 595 | - 'url' => '', |
|
| 596 | - 'persistent' => false |
|
| 597 | - ), |
|
| 598 | - 'help_tabs' => array( |
|
| 599 | - 'preview_message' => array( |
|
| 600 | - 'title' => __('About Previews', 'event_espresso'), |
|
| 601 | - 'callback' => 'preview_message_help_tab' |
|
| 602 | - ) |
|
| 603 | - ), |
|
| 604 | - 'require_nonce' => false |
|
| 605 | - ), |
|
| 606 | - 'settings' => array( |
|
| 607 | - 'nav' => array( |
|
| 608 | - 'label' => __('Settings', 'event_espresso'), |
|
| 609 | - 'order' => 40 |
|
| 610 | - ), |
|
| 611 | - 'metaboxes' => array('_messages_settings_metaboxes'), |
|
| 612 | - 'help_tabs' => array( |
|
| 613 | - 'messages_settings_help_tab' => array( |
|
| 614 | - 'title' => __('Messages Settings', 'event_espresso'), |
|
| 615 | - 'filename' => 'messages_settings' |
|
| 616 | - ), |
|
| 617 | - 'messages_settings_message_types_help_tab' => array( |
|
| 618 | - 'title' => __('Activating / Deactivating Message Types', 'event_espresso'), |
|
| 619 | - 'filename' => 'messages_settings_message_types' |
|
| 620 | - ), |
|
| 621 | - 'messages_settings_messengers_help_tab' => array( |
|
| 622 | - 'title' => __('Activating / Deactivating Messengers', 'event_espresso'), |
|
| 623 | - 'filename' => 'messages_settings_messengers' |
|
| 624 | - ), |
|
| 625 | - ), |
|
| 626 | - 'help_tour' => array('Messages_Settings_Help_Tour'), |
|
| 627 | - 'require_nonce' => false |
|
| 628 | - ) |
|
| 629 | - ); |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - |
|
| 633 | - protected function _add_screen_options() |
|
| 634 | - { |
|
| 635 | - //todo |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - |
|
| 639 | - protected function _add_screen_options_global_mtps() |
|
| 640 | - { |
|
| 641 | - /** |
|
| 642 | - * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options |
|
| 643 | - * uses the $_admin_page_title property and we want different outputs in the different spots. |
|
| 644 | - */ |
|
| 645 | - $page_title = $this->_admin_page_title; |
|
| 646 | - $this->_admin_page_title = __('Global Message Templates', 'event_espresso'); |
|
| 647 | - $this->_per_page_screen_option(); |
|
| 648 | - $this->_admin_page_title = $page_title; |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - |
|
| 652 | - protected function _add_screen_options_default() |
|
| 653 | - { |
|
| 654 | - $this->_admin_page_title = __('Message Activity', 'event_espresso'); |
|
| 655 | - $this->_per_page_screen_option(); |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - |
|
| 659 | - //none of the below group are currently used for Messages |
|
| 660 | - protected function _add_feature_pointers() |
|
| 661 | - { |
|
| 662 | - } |
|
| 663 | - |
|
| 664 | - public function admin_init() |
|
| 665 | - { |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - public function admin_notices() |
|
| 669 | - { |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - public function admin_footer_scripts() |
|
| 673 | - { |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - |
|
| 677 | - public function messages_help_tab() |
|
| 678 | - { |
|
| 679 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - |
|
| 683 | - public function messengers_help_tab() |
|
| 684 | - { |
|
| 685 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - |
|
| 689 | - public function message_types_help_tab() |
|
| 690 | - { |
|
| 691 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - |
|
| 695 | - public function messages_overview_help_tab() |
|
| 696 | - { |
|
| 697 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - |
|
| 701 | - public function message_templates_help_tab() |
|
| 702 | - { |
|
| 703 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - |
|
| 707 | - public function edit_message_template_help_tab() |
|
| 708 | - { |
|
| 709 | - $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title', |
|
| 710 | - 'event_espresso') . '" />'; |
|
| 711 | - $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview', |
|
| 712 | - 'event_espresso') . '" />'; |
|
| 713 | - $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields', |
|
| 714 | - 'event_espresso') . '" />'; |
|
| 715 | - $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox', |
|
| 716 | - 'event_espresso') . '" />'; |
|
| 717 | - $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox', |
|
| 718 | - 'event_espresso') . '" />'; |
|
| 719 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 720 | - $args); |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - |
|
| 724 | - public function message_template_shortcodes_help_tab() |
|
| 725 | - { |
|
| 726 | - $this->_set_shortcodes(); |
|
| 727 | - $args['shortcodes'] = $this->_shortcodes; |
|
| 728 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 729 | - $args); |
|
| 730 | - } |
|
| 179 | + '4.9.9.rc.014' |
|
| 180 | + ); |
|
| 181 | + |
|
| 182 | + $contexts = array(); |
|
| 183 | + $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); |
|
| 184 | + foreach ($active_message_contexts as $active_message) { |
|
| 185 | + if ($active_message instanceof EE_Message) { |
|
| 186 | + $message_type = $active_message->message_type_object(); |
|
| 187 | + if ($message_type instanceof EE_message_type) { |
|
| 188 | + $message_type_contexts = $message_type->get_contexts(); |
|
| 189 | + foreach ($message_type_contexts as $context => $context_details) { |
|
| 190 | + $contexts[$context] = $context_details['label']; |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + return $contexts; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * Generate select input with provided messenger options array. |
|
| 202 | + * |
|
| 203 | + * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger |
|
| 204 | + * labels. |
|
| 205 | + * |
|
| 206 | + * @return string |
|
| 207 | + */ |
|
| 208 | + public function get_messengers_select_input($messenger_options) |
|
| 209 | + { |
|
| 210 | + //if empty or just one value then just return an empty string |
|
| 211 | + if (empty($messenger_options) |
|
| 212 | + || ! is_array($messenger_options) |
|
| 213 | + || count($messenger_options) === 1 |
|
| 214 | + ) { |
|
| 215 | + return ''; |
|
| 216 | + } |
|
| 217 | + //merge in default |
|
| 218 | + $messenger_options = array_merge( |
|
| 219 | + array('none_selected' => __('Show All Messengers', 'event_espresso')), |
|
| 220 | + $messenger_options |
|
| 221 | + ); |
|
| 222 | + $input = new EE_Select_Input( |
|
| 223 | + $messenger_options, |
|
| 224 | + array( |
|
| 225 | + 'html_name' => 'ee_messenger_filter_by', |
|
| 226 | + 'html_id' => 'ee_messenger_filter_by', |
|
| 227 | + 'html_class' => 'wide', |
|
| 228 | + 'default' => isset($this->_req_data['ee_messenger_filter_by']) |
|
| 229 | + ? sanitize_title($this->_req_data['ee_messenger_filter_by']) |
|
| 230 | + : 'none_selected' |
|
| 231 | + ) |
|
| 232 | + ); |
|
| 233 | + |
|
| 234 | + return $input->get_html_for_input(); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * Generate select input with provided message type options array. |
|
| 240 | + * |
|
| 241 | + * @param array $message_type_options Array of message types indexed by message type slug, and values are the |
|
| 242 | + * message type labels |
|
| 243 | + * |
|
| 244 | + * @return string |
|
| 245 | + */ |
|
| 246 | + public function get_message_types_select_input($message_type_options) |
|
| 247 | + { |
|
| 248 | + //if empty or count of options is 1 then just return an empty string |
|
| 249 | + if (empty($message_type_options) |
|
| 250 | + || ! is_array($message_type_options) |
|
| 251 | + || count($message_type_options) === 1 |
|
| 252 | + ) { |
|
| 253 | + return ''; |
|
| 254 | + } |
|
| 255 | + //merge in default |
|
| 256 | + $message_type_options = array_merge( |
|
| 257 | + array('none_selected' => __('Show All Message Types', 'event_espresso')), |
|
| 258 | + $message_type_options |
|
| 259 | + ); |
|
| 260 | + $input = new EE_Select_Input( |
|
| 261 | + $message_type_options, |
|
| 262 | + array( |
|
| 263 | + 'html_name' => 'ee_message_type_filter_by', |
|
| 264 | + 'html_id' => 'ee_message_type_filter_by', |
|
| 265 | + 'html_class' => 'wide', |
|
| 266 | + 'default' => isset($this->_req_data['ee_message_type_filter_by']) |
|
| 267 | + ? sanitize_title($this->_req_data['ee_message_type_filter_by']) |
|
| 268 | + : 'none_selected', |
|
| 269 | + ) |
|
| 270 | + ); |
|
| 271 | + |
|
| 272 | + return $input->get_html_for_input(); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * Generate select input with provide message type contexts array. |
|
| 278 | + * |
|
| 279 | + * @param array $context_options Array of message type contexts indexed by context slug, and values are the |
|
| 280 | + * context label. |
|
| 281 | + * |
|
| 282 | + * @return string |
|
| 283 | + */ |
|
| 284 | + public function get_contexts_for_message_types_select_input($context_options) |
|
| 285 | + { |
|
| 286 | + //if empty or count of options is one then just return empty string |
|
| 287 | + if (empty($context_options) |
|
| 288 | + || ! is_array($context_options) |
|
| 289 | + || count($context_options) === 1 |
|
| 290 | + ) { |
|
| 291 | + return ''; |
|
| 292 | + } |
|
| 293 | + //merge in default |
|
| 294 | + $context_options = array_merge( |
|
| 295 | + array('none_selected' => __('Show all Contexts', 'event_espresso')), |
|
| 296 | + $context_options |
|
| 297 | + ); |
|
| 298 | + $input = new EE_Select_Input( |
|
| 299 | + $context_options, |
|
| 300 | + array( |
|
| 301 | + 'html_name' => 'ee_context_filter_by', |
|
| 302 | + 'html_id' => 'ee_context_filter_by', |
|
| 303 | + 'html_class' => 'wide', |
|
| 304 | + 'default' => isset($this->_req_data['ee_context_filter_by']) |
|
| 305 | + ? sanitize_title($this->_req_data['ee_context_filter_by']) |
|
| 306 | + : 'none_selected', |
|
| 307 | + ) |
|
| 308 | + ); |
|
| 309 | + |
|
| 310 | + return $input->get_html_for_input(); |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + |
|
| 314 | + protected function _ajax_hooks() |
|
| 315 | + { |
|
| 316 | + add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle')); |
|
| 317 | + add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle')); |
|
| 318 | + add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings')); |
|
| 319 | + add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form')); |
|
| 320 | + add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack')); |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + protected function _define_page_props() |
|
| 325 | + { |
|
| 326 | + $this->_admin_page_title = $this->page_label; |
|
| 327 | + $this->_labels = array( |
|
| 328 | + 'buttons' => array( |
|
| 329 | + 'add' => __('Add New Message Template', 'event_espresso'), |
|
| 330 | + 'edit' => __('Edit Message Template', 'event_espresso'), |
|
| 331 | + 'delete' => __('Delete Message Template', 'event_espresso') |
|
| 332 | + ), |
|
| 333 | + 'publishbox' => __('Update Actions', 'event_espresso') |
|
| 334 | + ); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * an array for storing key => value pairs of request actions and their corresponding methods |
|
| 340 | + * @access protected |
|
| 341 | + * @return void |
|
| 342 | + */ |
|
| 343 | + protected function _set_page_routes() |
|
| 344 | + { |
|
| 345 | + $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID']) |
|
| 346 | + ? $this->_req_data['GRP_ID'] |
|
| 347 | + : 0; |
|
| 348 | + $grp_id = empty($grp_id) && ! empty($this->_req_data['id']) |
|
| 349 | + ? $this->_req_data['id'] |
|
| 350 | + : $grp_id; |
|
| 351 | + $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID']) |
|
| 352 | + ? $this->_req_data['MSG_ID'] |
|
| 353 | + : 0; |
|
| 354 | + |
|
| 355 | + $this->_page_routes = array( |
|
| 356 | + 'default' => array( |
|
| 357 | + 'func' => '_message_queue_list_table', |
|
| 358 | + 'capability' => 'ee_read_global_messages' |
|
| 359 | + ), |
|
| 360 | + 'global_mtps' => array( |
|
| 361 | + 'func' => '_ee_default_messages_overview_list_table', |
|
| 362 | + 'capability' => 'ee_read_global_messages' |
|
| 363 | + ), |
|
| 364 | + 'custom_mtps' => array( |
|
| 365 | + 'func' => '_custom_mtps_preview', |
|
| 366 | + 'capability' => 'ee_read_messages' |
|
| 367 | + ), |
|
| 368 | + 'add_new_message_template' => array( |
|
| 369 | + 'func' => '_add_message_template', |
|
| 370 | + 'capability' => 'ee_edit_messages', |
|
| 371 | + 'noheader' => true |
|
| 372 | + ), |
|
| 373 | + 'edit_message_template' => array( |
|
| 374 | + 'func' => '_edit_message_template', |
|
| 375 | + 'capability' => 'ee_edit_message', |
|
| 376 | + 'obj_id' => $grp_id |
|
| 377 | + ), |
|
| 378 | + 'preview_message' => array( |
|
| 379 | + 'func' => '_preview_message', |
|
| 380 | + 'capability' => 'ee_read_message', |
|
| 381 | + 'obj_id' => $grp_id, |
|
| 382 | + 'noheader' => true, |
|
| 383 | + 'headers_sent_route' => 'display_preview_message' |
|
| 384 | + ), |
|
| 385 | + 'display_preview_message' => array( |
|
| 386 | + 'func' => '_display_preview_message', |
|
| 387 | + 'capability' => 'ee_read_message', |
|
| 388 | + 'obj_id' => $grp_id |
|
| 389 | + ), |
|
| 390 | + 'insert_message_template' => array( |
|
| 391 | + 'func' => '_insert_or_update_message_template', |
|
| 392 | + 'capability' => 'ee_edit_messages', |
|
| 393 | + 'args' => array('new_template' => true), |
|
| 394 | + 'noheader' => true |
|
| 395 | + ), |
|
| 396 | + 'update_message_template' => array( |
|
| 397 | + 'func' => '_insert_or_update_message_template', |
|
| 398 | + 'capability' => 'ee_edit_message', |
|
| 399 | + 'obj_id' => $grp_id, |
|
| 400 | + 'args' => array('new_template' => false), |
|
| 401 | + 'noheader' => true |
|
| 402 | + ), |
|
| 403 | + 'trash_message_template' => array( |
|
| 404 | + 'func' => '_trash_or_restore_message_template', |
|
| 405 | + 'capability' => 'ee_delete_message', |
|
| 406 | + 'obj_id' => $grp_id, |
|
| 407 | + 'args' => array('trash' => true, 'all' => true), |
|
| 408 | + 'noheader' => true |
|
| 409 | + ), |
|
| 410 | + 'trash_message_template_context' => array( |
|
| 411 | + 'func' => '_trash_or_restore_message_template', |
|
| 412 | + 'capability' => 'ee_delete_message', |
|
| 413 | + 'obj_id' => $grp_id, |
|
| 414 | + 'args' => array('trash' => true), |
|
| 415 | + 'noheader' => true |
|
| 416 | + ), |
|
| 417 | + 'restore_message_template' => array( |
|
| 418 | + 'func' => '_trash_or_restore_message_template', |
|
| 419 | + 'capability' => 'ee_delete_message', |
|
| 420 | + 'obj_id' => $grp_id, |
|
| 421 | + 'args' => array('trash' => false, 'all' => true), |
|
| 422 | + 'noheader' => true |
|
| 423 | + ), |
|
| 424 | + 'restore_message_template_context' => array( |
|
| 425 | + 'func' => '_trash_or_restore_message_template', |
|
| 426 | + 'capability' => 'ee_delete_message', |
|
| 427 | + 'obj_id' => $grp_id, |
|
| 428 | + 'args' => array('trash' => false), |
|
| 429 | + 'noheader' => true |
|
| 430 | + ), |
|
| 431 | + 'delete_message_template' => array( |
|
| 432 | + 'func' => '_delete_message_template', |
|
| 433 | + 'capability' => 'ee_delete_message', |
|
| 434 | + 'obj_id' => $grp_id, |
|
| 435 | + 'noheader' => true |
|
| 436 | + ), |
|
| 437 | + 'reset_to_default' => array( |
|
| 438 | + 'func' => '_reset_to_default_template', |
|
| 439 | + 'capability' => 'ee_edit_message', |
|
| 440 | + 'obj_id' => $grp_id, |
|
| 441 | + 'noheader' => true |
|
| 442 | + ), |
|
| 443 | + 'settings' => array( |
|
| 444 | + 'func' => '_settings', |
|
| 445 | + 'capability' => 'manage_options' |
|
| 446 | + ), |
|
| 447 | + 'update_global_settings' => array( |
|
| 448 | + 'func' => '_update_global_settings', |
|
| 449 | + 'capability' => 'manage_options', |
|
| 450 | + 'noheader' => true |
|
| 451 | + ), |
|
| 452 | + 'generate_now' => array( |
|
| 453 | + 'func' => '_generate_now', |
|
| 454 | + 'capability' => 'ee_send_message', |
|
| 455 | + 'noheader' => true |
|
| 456 | + ), |
|
| 457 | + 'generate_and_send_now' => array( |
|
| 458 | + 'func' => '_generate_and_send_now', |
|
| 459 | + 'capability' => 'ee_send_message', |
|
| 460 | + 'noheader' => true |
|
| 461 | + ), |
|
| 462 | + 'queue_for_resending' => array( |
|
| 463 | + 'func' => '_queue_for_resending', |
|
| 464 | + 'capability' => 'ee_send_message', |
|
| 465 | + 'noheader' => true |
|
| 466 | + ), |
|
| 467 | + 'send_now' => array( |
|
| 468 | + 'func' => '_send_now', |
|
| 469 | + 'capability' => 'ee_send_message', |
|
| 470 | + 'noheader' => true |
|
| 471 | + ), |
|
| 472 | + 'delete_ee_message' => array( |
|
| 473 | + 'func' => '_delete_ee_messages', |
|
| 474 | + 'capability' => 'ee_delete_message', |
|
| 475 | + 'noheader' => true |
|
| 476 | + ), |
|
| 477 | + 'delete_ee_messages' => array( |
|
| 478 | + 'func' => '_delete_ee_messages', |
|
| 479 | + 'capability' => 'ee_delete_messages', |
|
| 480 | + 'noheader' => true, |
|
| 481 | + 'obj_id' => $msg_id |
|
| 482 | + ) |
|
| 483 | + ); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + protected function _set_page_config() |
|
| 488 | + { |
|
| 489 | + $this->_page_config = array( |
|
| 490 | + 'default' => array( |
|
| 491 | + 'nav' => array( |
|
| 492 | + 'label' => __('Message Activity', 'event_espresso'), |
|
| 493 | + 'order' => 10 |
|
| 494 | + ), |
|
| 495 | + 'list_table' => 'EE_Message_List_Table', |
|
| 496 | + // 'qtips' => array( 'EE_Message_List_Table_Tips' ), |
|
| 497 | + 'require_nonce' => false |
|
| 498 | + ), |
|
| 499 | + 'global_mtps' => array( |
|
| 500 | + 'nav' => array( |
|
| 501 | + 'label' => __('Default Message Templates', 'event_espresso'), |
|
| 502 | + 'order' => 20 |
|
| 503 | + ), |
|
| 504 | + 'list_table' => 'Messages_Template_List_Table', |
|
| 505 | + 'help_tabs' => array( |
|
| 506 | + 'messages_overview_help_tab' => array( |
|
| 507 | + 'title' => __('Messages Overview', 'event_espresso'), |
|
| 508 | + 'filename' => 'messages_overview' |
|
| 509 | + ), |
|
| 510 | + 'messages_overview_messages_table_column_headings_help_tab' => array( |
|
| 511 | + 'title' => __('Messages Table Column Headings', 'event_espresso'), |
|
| 512 | + 'filename' => 'messages_overview_table_column_headings' |
|
| 513 | + ), |
|
| 514 | + 'messages_overview_messages_filters_help_tab' => array( |
|
| 515 | + 'title' => __('Message Filters', 'event_espresso'), |
|
| 516 | + 'filename' => 'messages_overview_filters' |
|
| 517 | + ), |
|
| 518 | + 'messages_overview_messages_views_help_tab' => array( |
|
| 519 | + 'title' => __('Message Views', 'event_espresso'), |
|
| 520 | + 'filename' => 'messages_overview_views' |
|
| 521 | + ), |
|
| 522 | + 'message_overview_message_types_help_tab' => array( |
|
| 523 | + 'title' => __('Message Types', 'event_espresso'), |
|
| 524 | + 'filename' => 'messages_overview_types' |
|
| 525 | + ), |
|
| 526 | + 'messages_overview_messengers_help_tab' => array( |
|
| 527 | + 'title' => __('Messengers', 'event_espresso'), |
|
| 528 | + 'filename' => 'messages_overview_messengers', |
|
| 529 | + ), |
|
| 530 | + 'messages_overview_other_help_tab' => array( |
|
| 531 | + 'title' => __('Messages Other', 'event_espresso'), |
|
| 532 | + 'filename' => 'messages_overview_other', |
|
| 533 | + ), |
|
| 534 | + ), |
|
| 535 | + 'help_tour' => array('Messages_Overview_Help_Tour'), |
|
| 536 | + 'require_nonce' => false |
|
| 537 | + ), |
|
| 538 | + 'custom_mtps' => array( |
|
| 539 | + 'nav' => array( |
|
| 540 | + 'label' => __('Custom Message Templates', 'event_espresso'), |
|
| 541 | + 'order' => 30 |
|
| 542 | + ), |
|
| 543 | + 'help_tabs' => array(), |
|
| 544 | + 'help_tour' => array(), |
|
| 545 | + 'require_nonce' => false |
|
| 546 | + ), |
|
| 547 | + 'add_new_message_template' => array( |
|
| 548 | + 'nav' => array( |
|
| 549 | + 'label' => __('Add New Message Templates', 'event_espresso'), |
|
| 550 | + 'order' => 5, |
|
| 551 | + 'persistent' => false |
|
| 552 | + ), |
|
| 553 | + 'require_nonce' => false |
|
| 554 | + ), |
|
| 555 | + 'edit_message_template' => array( |
|
| 556 | + 'labels' => array( |
|
| 557 | + 'buttons' => array( |
|
| 558 | + 'reset' => __('Reset Templates'), |
|
| 559 | + ), |
|
| 560 | + 'publishbox' => __('Update Actions', 'event_espresso') |
|
| 561 | + ), |
|
| 562 | + 'nav' => array( |
|
| 563 | + 'label' => __('Edit Message Templates', 'event_espresso'), |
|
| 564 | + 'order' => 5, |
|
| 565 | + 'persistent' => false, |
|
| 566 | + 'url' => '' |
|
| 567 | + ), |
|
| 568 | + 'metaboxes' => array('_publish_post_box', '_register_edit_meta_boxes'), |
|
| 569 | + 'has_metaboxes' => true, |
|
| 570 | + 'help_tour' => array('Message_Templates_Edit_Help_Tour'), |
|
| 571 | + 'help_tabs' => array( |
|
| 572 | + 'edit_message_template' => array( |
|
| 573 | + 'title' => __('Message Template Editor', 'event_espresso'), |
|
| 574 | + 'callback' => 'edit_message_template_help_tab' |
|
| 575 | + ), |
|
| 576 | + 'message_templates_help_tab' => array( |
|
| 577 | + 'title' => __('Message Templates', 'event_espresso'), |
|
| 578 | + 'filename' => 'messages_templates' |
|
| 579 | + ), |
|
| 580 | + 'message_template_shortcodes' => array( |
|
| 581 | + 'title' => __('Message Shortcodes', 'event_espresso'), |
|
| 582 | + 'callback' => 'message_template_shortcodes_help_tab' |
|
| 583 | + ), |
|
| 584 | + 'message_preview_help_tab' => array( |
|
| 585 | + 'title' => __('Message Preview', 'event_espresso'), |
|
| 586 | + 'filename' => 'messages_preview' |
|
| 587 | + ), |
|
| 588 | + ), |
|
| 589 | + 'require_nonce' => false |
|
| 590 | + ), |
|
| 591 | + 'display_preview_message' => array( |
|
| 592 | + 'nav' => array( |
|
| 593 | + 'label' => __('Message Preview', 'event_espresso'), |
|
| 594 | + 'order' => 5, |
|
| 595 | + 'url' => '', |
|
| 596 | + 'persistent' => false |
|
| 597 | + ), |
|
| 598 | + 'help_tabs' => array( |
|
| 599 | + 'preview_message' => array( |
|
| 600 | + 'title' => __('About Previews', 'event_espresso'), |
|
| 601 | + 'callback' => 'preview_message_help_tab' |
|
| 602 | + ) |
|
| 603 | + ), |
|
| 604 | + 'require_nonce' => false |
|
| 605 | + ), |
|
| 606 | + 'settings' => array( |
|
| 607 | + 'nav' => array( |
|
| 608 | + 'label' => __('Settings', 'event_espresso'), |
|
| 609 | + 'order' => 40 |
|
| 610 | + ), |
|
| 611 | + 'metaboxes' => array('_messages_settings_metaboxes'), |
|
| 612 | + 'help_tabs' => array( |
|
| 613 | + 'messages_settings_help_tab' => array( |
|
| 614 | + 'title' => __('Messages Settings', 'event_espresso'), |
|
| 615 | + 'filename' => 'messages_settings' |
|
| 616 | + ), |
|
| 617 | + 'messages_settings_message_types_help_tab' => array( |
|
| 618 | + 'title' => __('Activating / Deactivating Message Types', 'event_espresso'), |
|
| 619 | + 'filename' => 'messages_settings_message_types' |
|
| 620 | + ), |
|
| 621 | + 'messages_settings_messengers_help_tab' => array( |
|
| 622 | + 'title' => __('Activating / Deactivating Messengers', 'event_espresso'), |
|
| 623 | + 'filename' => 'messages_settings_messengers' |
|
| 624 | + ), |
|
| 625 | + ), |
|
| 626 | + 'help_tour' => array('Messages_Settings_Help_Tour'), |
|
| 627 | + 'require_nonce' => false |
|
| 628 | + ) |
|
| 629 | + ); |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + |
|
| 633 | + protected function _add_screen_options() |
|
| 634 | + { |
|
| 635 | + //todo |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + |
|
| 639 | + protected function _add_screen_options_global_mtps() |
|
| 640 | + { |
|
| 641 | + /** |
|
| 642 | + * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options |
|
| 643 | + * uses the $_admin_page_title property and we want different outputs in the different spots. |
|
| 644 | + */ |
|
| 645 | + $page_title = $this->_admin_page_title; |
|
| 646 | + $this->_admin_page_title = __('Global Message Templates', 'event_espresso'); |
|
| 647 | + $this->_per_page_screen_option(); |
|
| 648 | + $this->_admin_page_title = $page_title; |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + |
|
| 652 | + protected function _add_screen_options_default() |
|
| 653 | + { |
|
| 654 | + $this->_admin_page_title = __('Message Activity', 'event_espresso'); |
|
| 655 | + $this->_per_page_screen_option(); |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + |
|
| 659 | + //none of the below group are currently used for Messages |
|
| 660 | + protected function _add_feature_pointers() |
|
| 661 | + { |
|
| 662 | + } |
|
| 663 | + |
|
| 664 | + public function admin_init() |
|
| 665 | + { |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + public function admin_notices() |
|
| 669 | + { |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + public function admin_footer_scripts() |
|
| 673 | + { |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + |
|
| 677 | + public function messages_help_tab() |
|
| 678 | + { |
|
| 679 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + |
|
| 683 | + public function messengers_help_tab() |
|
| 684 | + { |
|
| 685 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + |
|
| 689 | + public function message_types_help_tab() |
|
| 690 | + { |
|
| 691 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + |
|
| 695 | + public function messages_overview_help_tab() |
|
| 696 | + { |
|
| 697 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 698 | + } |
|
| 699 | + |
|
| 700 | + |
|
| 701 | + public function message_templates_help_tab() |
|
| 702 | + { |
|
| 703 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + |
|
| 707 | + public function edit_message_template_help_tab() |
|
| 708 | + { |
|
| 709 | + $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title', |
|
| 710 | + 'event_espresso') . '" />'; |
|
| 711 | + $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview', |
|
| 712 | + 'event_espresso') . '" />'; |
|
| 713 | + $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields', |
|
| 714 | + 'event_espresso') . '" />'; |
|
| 715 | + $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox', |
|
| 716 | + 'event_espresso') . '" />'; |
|
| 717 | + $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox', |
|
| 718 | + 'event_espresso') . '" />'; |
|
| 719 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 720 | + $args); |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + |
|
| 724 | + public function message_template_shortcodes_help_tab() |
|
| 725 | + { |
|
| 726 | + $this->_set_shortcodes(); |
|
| 727 | + $args['shortcodes'] = $this->_shortcodes; |
|
| 728 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 729 | + $args); |
|
| 730 | + } |
|
| 731 | 731 | |
| 732 | 732 | |
| 733 | - public function preview_message_help_tab() |
|
| 734 | - { |
|
| 735 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 736 | - } |
|
| 733 | + public function preview_message_help_tab() |
|
| 734 | + { |
|
| 735 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 736 | + } |
|
| 737 | 737 | |
| 738 | - |
|
| 739 | - public function settings_help_tab() |
|
| 740 | - { |
|
| 741 | - $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab', |
|
| 742 | - 'event_espresso') . '" />'; |
|
| 743 | - $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab', |
|
| 744 | - 'event_espresso') . '" />'; |
|
| 745 | - $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>'; |
|
| 746 | - $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>'; |
|
| 747 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 748 | - } |
|
| 738 | + |
|
| 739 | + public function settings_help_tab() |
|
| 740 | + { |
|
| 741 | + $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab', |
|
| 742 | + 'event_espresso') . '" />'; |
|
| 743 | + $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab', |
|
| 744 | + 'event_espresso') . '" />'; |
|
| 745 | + $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>'; |
|
| 746 | + $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>'; |
|
| 747 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 748 | + } |
|
| 749 | 749 | |
| 750 | 750 | |
| 751 | - public function load_scripts_styles() |
|
| 752 | - { |
|
| 753 | - wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 754 | - wp_enqueue_style('espresso_ee_msg'); |
|
| 751 | + public function load_scripts_styles() |
|
| 752 | + { |
|
| 753 | + wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 754 | + wp_enqueue_style('espresso_ee_msg'); |
|
| 755 | 755 | |
| 756 | - wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 757 | - array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); |
|
| 758 | - wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 759 | - array('ee-dialog'), EVENT_ESPRESSO_VERSION); |
|
| 760 | - } |
|
| 756 | + wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 757 | + array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); |
|
| 758 | + wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 759 | + array('ee-dialog'), EVENT_ESPRESSO_VERSION); |
|
| 760 | + } |
|
| 761 | 761 | |
| 762 | 762 | |
| 763 | - public function load_scripts_styles_default() |
|
| 764 | - { |
|
| 765 | - wp_enqueue_script('ee-msg-list-table-js'); |
|
| 766 | - } |
|
| 763 | + public function load_scripts_styles_default() |
|
| 764 | + { |
|
| 765 | + wp_enqueue_script('ee-msg-list-table-js'); |
|
| 766 | + } |
|
| 767 | 767 | |
| 768 | 768 | |
| 769 | - public function wp_editor_css($mce_css) |
|
| 770 | - { |
|
| 771 | - //if we're on the edit_message_template route |
|
| 772 | - if ($this->_req_action == 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { |
|
| 773 | - $message_type_name = $this->_active_message_type_name; |
|
| 769 | + public function wp_editor_css($mce_css) |
|
| 770 | + { |
|
| 771 | + //if we're on the edit_message_template route |
|
| 772 | + if ($this->_req_action == 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { |
|
| 773 | + $message_type_name = $this->_active_message_type_name; |
|
| 774 | 774 | |
| 775 | - //we're going to REPLACE the existing mce css |
|
| 776 | - //we need to get the css file location from the active messenger |
|
| 777 | - $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, |
|
| 778 | - 'wpeditor', $this->_variation); |
|
| 779 | - } |
|
| 775 | + //we're going to REPLACE the existing mce css |
|
| 776 | + //we need to get the css file location from the active messenger |
|
| 777 | + $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, |
|
| 778 | + 'wpeditor', $this->_variation); |
|
| 779 | + } |
|
| 780 | 780 | |
| 781 | - return $mce_css; |
|
| 782 | - } |
|
| 783 | - |
|
| 784 | - |
|
| 785 | - public function load_scripts_styles_edit_message_template() |
|
| 786 | - { |
|
| 787 | - |
|
| 788 | - $this->_set_shortcodes(); |
|
| 781 | + return $mce_css; |
|
| 782 | + } |
|
| 783 | + |
|
| 784 | + |
|
| 785 | + public function load_scripts_styles_edit_message_template() |
|
| 786 | + { |
|
| 787 | + |
|
| 788 | + $this->_set_shortcodes(); |
|
| 789 | 789 | |
| 790 | - EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 791 | - __('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.', |
|
| 792 | - 'event_espresso'), |
|
| 793 | - $this->_message_template_group->messenger_obj()->label['singular'], |
|
| 794 | - $this->_message_template_group->message_type_obj()->label['singular'] |
|
| 795 | - ); |
|
| 796 | - 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?', |
|
| 797 | - 'event_espresso'); |
|
| 798 | - |
|
| 799 | - wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'), |
|
| 800 | - EVENT_ESPRESSO_VERSION); |
|
| 801 | - |
|
| 802 | - wp_enqueue_script('ee_admin_js'); |
|
| 803 | - wp_enqueue_script('ee_msgs_edit_js'); |
|
| 804 | - |
|
| 805 | - //add in special css for tiny_mce |
|
| 806 | - add_filter('mce_css', array($this, 'wp_editor_css')); |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - |
|
| 810 | - public function load_scripts_styles_display_preview_message() |
|
| 811 | - { |
|
| 812 | - |
|
| 813 | - $this->_set_message_template_group(); |
|
| 814 | - |
|
| 815 | - if (isset($this->_req_data['messenger'])) { |
|
| 816 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : ''; |
|
| 820 | - |
|
| 821 | - |
|
| 822 | - wp_enqueue_style('espresso_preview_css', |
|
| 823 | - $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, 'preview', |
|
| 824 | - $this->_variation)); |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - |
|
| 828 | - public function load_scripts_styles_settings() |
|
| 829 | - { |
|
| 830 | - wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(), |
|
| 831 | - EVENT_ESPRESSO_VERSION); |
|
| 832 | - wp_enqueue_style('ee-text-links'); |
|
| 833 | - wp_enqueue_style('ee-message-settings'); |
|
| 834 | - |
|
| 835 | - wp_enqueue_script('ee-messages-settings'); |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - |
|
| 839 | - /** |
|
| 840 | - * set views array for List Table |
|
| 841 | - */ |
|
| 842 | - public function _set_list_table_views_global_mtps() |
|
| 843 | - { |
|
| 844 | - $this->_views = array( |
|
| 845 | - 'in_use' => array( |
|
| 846 | - 'slug' => 'in_use', |
|
| 847 | - 'label' => __('In Use', 'event_espresso'), |
|
| 848 | - 'count' => 0, |
|
| 849 | - 'bulk_action' => array( |
|
| 850 | - 'trash_message_template' => __('Move to Trash', 'event_espresso') |
|
| 851 | - ) |
|
| 852 | - ) |
|
| 853 | - ); |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - |
|
| 857 | - /** |
|
| 858 | - * set views array for message queue list table |
|
| 859 | - */ |
|
| 860 | - public function _set_list_table_views_default() |
|
| 861 | - { |
|
| 862 | - EE_Registry::instance()->load_helper('Template'); |
|
| 863 | - |
|
| 864 | - $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 865 | - 'message_list_table_bulk_actions') |
|
| 866 | - ? array( |
|
| 867 | - 'generate_now' => __('Generate Now', 'event_espresso'), |
|
| 868 | - 'generate_and_send_now' => __('Generate and Send Now', 'event_espresso'), |
|
| 869 | - 'queue_for_resending' => __('Queue for Resending', 'event_espresso'), |
|
| 870 | - 'send_now' => __('Send Now', 'event_espresso') |
|
| 871 | - ) |
|
| 872 | - : array(); |
|
| 873 | - |
|
| 874 | - $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can('ee_delete_messages', |
|
| 875 | - 'message_list_table_bulk_actions') |
|
| 876 | - ? array('delete_ee_messages' => __('Delete Messages', 'event_espresso')) |
|
| 877 | - : array(); |
|
| 878 | - |
|
| 879 | - |
|
| 880 | - $this->_views = array( |
|
| 881 | - 'all' => array( |
|
| 882 | - 'slug' => 'all', |
|
| 883 | - 'label' => __('All', 'event_espresso'), |
|
| 884 | - 'count' => 0, |
|
| 885 | - 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action) |
|
| 886 | - ) |
|
| 887 | - ); |
|
| 888 | - |
|
| 889 | - |
|
| 890 | - foreach (EEM_Message::instance()->all_statuses() as $status) { |
|
| 891 | - if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { |
|
| 892 | - continue; |
|
| 893 | - } |
|
| 894 | - $status_bulk_actions = $common_bulk_actions; |
|
| 895 | - //unset bulk actions not applying to status |
|
| 896 | - if (! empty($status_bulk_actions)) { |
|
| 897 | - switch ($status) { |
|
| 898 | - case EEM_Message::status_idle: |
|
| 899 | - case EEM_Message::status_resend: |
|
| 900 | - $status_bulk_actions['send_now'] = $common_bulk_actions['send_now']; |
|
| 901 | - break; |
|
| 790 | + EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 791 | + __('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.', |
|
| 792 | + 'event_espresso'), |
|
| 793 | + $this->_message_template_group->messenger_obj()->label['singular'], |
|
| 794 | + $this->_message_template_group->message_type_obj()->label['singular'] |
|
| 795 | + ); |
|
| 796 | + 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?', |
|
| 797 | + 'event_espresso'); |
|
| 798 | + |
|
| 799 | + wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'), |
|
| 800 | + EVENT_ESPRESSO_VERSION); |
|
| 801 | + |
|
| 802 | + wp_enqueue_script('ee_admin_js'); |
|
| 803 | + wp_enqueue_script('ee_msgs_edit_js'); |
|
| 804 | + |
|
| 805 | + //add in special css for tiny_mce |
|
| 806 | + add_filter('mce_css', array($this, 'wp_editor_css')); |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + |
|
| 810 | + public function load_scripts_styles_display_preview_message() |
|
| 811 | + { |
|
| 812 | + |
|
| 813 | + $this->_set_message_template_group(); |
|
| 814 | + |
|
| 815 | + if (isset($this->_req_data['messenger'])) { |
|
| 816 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : ''; |
|
| 820 | + |
|
| 821 | + |
|
| 822 | + wp_enqueue_style('espresso_preview_css', |
|
| 823 | + $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, 'preview', |
|
| 824 | + $this->_variation)); |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + |
|
| 828 | + public function load_scripts_styles_settings() |
|
| 829 | + { |
|
| 830 | + wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(), |
|
| 831 | + EVENT_ESPRESSO_VERSION); |
|
| 832 | + wp_enqueue_style('ee-text-links'); |
|
| 833 | + wp_enqueue_style('ee-message-settings'); |
|
| 834 | + |
|
| 835 | + wp_enqueue_script('ee-messages-settings'); |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + |
|
| 839 | + /** |
|
| 840 | + * set views array for List Table |
|
| 841 | + */ |
|
| 842 | + public function _set_list_table_views_global_mtps() |
|
| 843 | + { |
|
| 844 | + $this->_views = array( |
|
| 845 | + 'in_use' => array( |
|
| 846 | + 'slug' => 'in_use', |
|
| 847 | + 'label' => __('In Use', 'event_espresso'), |
|
| 848 | + 'count' => 0, |
|
| 849 | + 'bulk_action' => array( |
|
| 850 | + 'trash_message_template' => __('Move to Trash', 'event_espresso') |
|
| 851 | + ) |
|
| 852 | + ) |
|
| 853 | + ); |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + |
|
| 857 | + /** |
|
| 858 | + * set views array for message queue list table |
|
| 859 | + */ |
|
| 860 | + public function _set_list_table_views_default() |
|
| 861 | + { |
|
| 862 | + EE_Registry::instance()->load_helper('Template'); |
|
| 863 | + |
|
| 864 | + $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 865 | + 'message_list_table_bulk_actions') |
|
| 866 | + ? array( |
|
| 867 | + 'generate_now' => __('Generate Now', 'event_espresso'), |
|
| 868 | + 'generate_and_send_now' => __('Generate and Send Now', 'event_espresso'), |
|
| 869 | + 'queue_for_resending' => __('Queue for Resending', 'event_espresso'), |
|
| 870 | + 'send_now' => __('Send Now', 'event_espresso') |
|
| 871 | + ) |
|
| 872 | + : array(); |
|
| 873 | + |
|
| 874 | + $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can('ee_delete_messages', |
|
| 875 | + 'message_list_table_bulk_actions') |
|
| 876 | + ? array('delete_ee_messages' => __('Delete Messages', 'event_espresso')) |
|
| 877 | + : array(); |
|
| 878 | + |
|
| 879 | + |
|
| 880 | + $this->_views = array( |
|
| 881 | + 'all' => array( |
|
| 882 | + 'slug' => 'all', |
|
| 883 | + 'label' => __('All', 'event_espresso'), |
|
| 884 | + 'count' => 0, |
|
| 885 | + 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action) |
|
| 886 | + ) |
|
| 887 | + ); |
|
| 888 | + |
|
| 889 | + |
|
| 890 | + foreach (EEM_Message::instance()->all_statuses() as $status) { |
|
| 891 | + if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { |
|
| 892 | + continue; |
|
| 893 | + } |
|
| 894 | + $status_bulk_actions = $common_bulk_actions; |
|
| 895 | + //unset bulk actions not applying to status |
|
| 896 | + if (! empty($status_bulk_actions)) { |
|
| 897 | + switch ($status) { |
|
| 898 | + case EEM_Message::status_idle: |
|
| 899 | + case EEM_Message::status_resend: |
|
| 900 | + $status_bulk_actions['send_now'] = $common_bulk_actions['send_now']; |
|
| 901 | + break; |
|
| 902 | 902 | |
| 903 | - case EEM_Message::status_failed: |
|
| 904 | - case EEM_Message::status_debug_only: |
|
| 905 | - case EEM_Message::status_messenger_executing: |
|
| 906 | - $status_bulk_actions = array(); |
|
| 907 | - break; |
|
| 903 | + case EEM_Message::status_failed: |
|
| 904 | + case EEM_Message::status_debug_only: |
|
| 905 | + case EEM_Message::status_messenger_executing: |
|
| 906 | + $status_bulk_actions = array(); |
|
| 907 | + break; |
|
| 908 | 908 | |
| 909 | - case EEM_Message::status_incomplete: |
|
| 910 | - unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']); |
|
| 911 | - break; |
|
| 909 | + case EEM_Message::status_incomplete: |
|
| 910 | + unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']); |
|
| 911 | + break; |
|
| 912 | 912 | |
| 913 | - case EEM_Message::status_retry: |
|
| 914 | - case EEM_Message::status_sent: |
|
| 915 | - unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']); |
|
| 916 | - break; |
|
| 917 | - } |
|
| 918 | - } |
|
| 913 | + case EEM_Message::status_retry: |
|
| 914 | + case EEM_Message::status_sent: |
|
| 915 | + unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']); |
|
| 916 | + break; |
|
| 917 | + } |
|
| 918 | + } |
|
| 919 | 919 | |
| 920 | - //skip adding messenger executing status to views because it will be included with the Failed view. |
|
| 921 | - if ( $status === EEM_Message::status_messenger_executing ) { |
|
| 922 | - continue; |
|
| 923 | - } |
|
| 920 | + //skip adding messenger executing status to views because it will be included with the Failed view. |
|
| 921 | + if ( $status === EEM_Message::status_messenger_executing ) { |
|
| 922 | + continue; |
|
| 923 | + } |
|
| 924 | 924 | |
| 925 | - $this->_views[strtolower($status)] = array( |
|
| 926 | - 'slug' => strtolower($status), |
|
| 927 | - 'label' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
| 928 | - 'count' => 0, |
|
| 929 | - 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action) |
|
| 930 | - ); |
|
| 931 | - } |
|
| 932 | - } |
|
| 933 | - |
|
| 934 | - |
|
| 935 | - protected function _ee_default_messages_overview_list_table() |
|
| 936 | - { |
|
| 937 | - $this->_admin_page_title = __('Default Message Templates', 'event_espresso'); |
|
| 938 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 939 | - } |
|
| 940 | - |
|
| 941 | - |
|
| 942 | - protected function _message_queue_list_table() |
|
| 943 | - { |
|
| 944 | - $this->_search_btn_label = __('Message Activity', 'event_espresso'); |
|
| 945 | - $this->_template_args['per_column'] = 6; |
|
| 946 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); |
|
| 947 | - $this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>'; |
|
| 948 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - |
|
| 952 | - protected function _message_legend_items() |
|
| 953 | - { |
|
| 954 | - |
|
| 955 | - $action_css_classes = EEH_MSG_Template::get_message_action_icons(); |
|
| 956 | - $action_items = array(); |
|
| 957 | - |
|
| 958 | - foreach ($action_css_classes as $action_item => $action_details) { |
|
| 959 | - if ($action_item === 'see_notifications_for') { |
|
| 960 | - continue; |
|
| 961 | - } |
|
| 962 | - $action_items[$action_item] = array( |
|
| 963 | - 'class' => $action_details['css_class'], |
|
| 964 | - 'desc' => $action_details['label'] |
|
| 965 | - ); |
|
| 966 | - } |
|
| 967 | - |
|
| 968 | - /** @type array $status_items status legend setup */ |
|
| 969 | - $status_items = array( |
|
| 970 | - 'sent_status' => array( |
|
| 971 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 972 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence') |
|
| 973 | - ), |
|
| 974 | - 'idle_status' => array( |
|
| 975 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 976 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence') |
|
| 977 | - ), |
|
| 978 | - 'failed_status' => array( |
|
| 979 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 980 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence') |
|
| 981 | - ), |
|
| 982 | - 'messenger_executing_status' => array( |
|
| 983 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, |
|
| 984 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence') |
|
| 985 | - ), |
|
| 986 | - 'resend_status' => array( |
|
| 987 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 988 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence') |
|
| 989 | - ), |
|
| 990 | - 'incomplete_status' => array( |
|
| 991 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 992 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence') |
|
| 993 | - ), |
|
| 994 | - 'retry_status' => array( |
|
| 995 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 996 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence') |
|
| 997 | - ) |
|
| 998 | - ); |
|
| 999 | - if (EEM_Message::debug()) { |
|
| 1000 | - $status_items['debug_only_status'] = array( |
|
| 1001 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 1002 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence') |
|
| 1003 | - ); |
|
| 1004 | - } |
|
| 1005 | - |
|
| 1006 | - return array_merge($action_items, $status_items); |
|
| 1007 | - } |
|
| 1008 | - |
|
| 1009 | - |
|
| 1010 | - protected function _custom_mtps_preview() |
|
| 1011 | - { |
|
| 1012 | - $this->_admin_page_title = __('Custom Message Templates (Preview)', 'event_espresso'); |
|
| 1013 | - $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot', |
|
| 1014 | - 'event_espresso') . '" />'; |
|
| 1015 | - $this->_template_args['preview_text'] = '<strong>' . __('Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', |
|
| 1016 | - 'event_espresso') . '</strong>'; |
|
| 1017 | - $this->display_admin_caf_preview_page('custom_message_types', false); |
|
| 1018 | - } |
|
| 1019 | - |
|
| 1020 | - |
|
| 1021 | - /** |
|
| 1022 | - * get_message_templates |
|
| 1023 | - * This gets all the message templates for listing on the overview list. |
|
| 1024 | - * |
|
| 1025 | - * @access public |
|
| 1026 | - * |
|
| 1027 | - * @param int $perpage the amount of templates groups to show per page |
|
| 1028 | - * @param string $type the current _view we're getting templates for |
|
| 1029 | - * @param bool $count return count? |
|
| 1030 | - * @param bool $all disregard any paging info (get all data); |
|
| 1031 | - * @param bool $global whether to return just global (true) or custom templates (false) |
|
| 1032 | - * |
|
| 1033 | - * @return array |
|
| 1034 | - */ |
|
| 1035 | - public function get_message_templates($perpage = 10, $type = 'in_use', $count = false, $all = false, $global = true) |
|
| 1036 | - { |
|
| 1037 | - |
|
| 1038 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 1039 | - |
|
| 1040 | - $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby']; |
|
| 1041 | - $orderby = $this->_req_data['orderby']; |
|
| 1042 | - |
|
| 1043 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC'; |
|
| 1044 | - |
|
| 1045 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 1046 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $perpage; |
|
| 1047 | - |
|
| 1048 | - $offset = ($current_page - 1) * $per_page; |
|
| 1049 | - $limit = $all ? null : array($offset, $per_page); |
|
| 1050 | - |
|
| 1051 | - |
|
| 1052 | - //options will match what is in the _views array property |
|
| 1053 | - switch ($type) { |
|
| 925 | + $this->_views[strtolower($status)] = array( |
|
| 926 | + 'slug' => strtolower($status), |
|
| 927 | + 'label' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
| 928 | + 'count' => 0, |
|
| 929 | + 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action) |
|
| 930 | + ); |
|
| 931 | + } |
|
| 932 | + } |
|
| 933 | + |
|
| 934 | + |
|
| 935 | + protected function _ee_default_messages_overview_list_table() |
|
| 936 | + { |
|
| 937 | + $this->_admin_page_title = __('Default Message Templates', 'event_espresso'); |
|
| 938 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 939 | + } |
|
| 940 | + |
|
| 941 | + |
|
| 942 | + protected function _message_queue_list_table() |
|
| 943 | + { |
|
| 944 | + $this->_search_btn_label = __('Message Activity', 'event_espresso'); |
|
| 945 | + $this->_template_args['per_column'] = 6; |
|
| 946 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); |
|
| 947 | + $this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>'; |
|
| 948 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + |
|
| 952 | + protected function _message_legend_items() |
|
| 953 | + { |
|
| 954 | + |
|
| 955 | + $action_css_classes = EEH_MSG_Template::get_message_action_icons(); |
|
| 956 | + $action_items = array(); |
|
| 957 | + |
|
| 958 | + foreach ($action_css_classes as $action_item => $action_details) { |
|
| 959 | + if ($action_item === 'see_notifications_for') { |
|
| 960 | + continue; |
|
| 961 | + } |
|
| 962 | + $action_items[$action_item] = array( |
|
| 963 | + 'class' => $action_details['css_class'], |
|
| 964 | + 'desc' => $action_details['label'] |
|
| 965 | + ); |
|
| 966 | + } |
|
| 967 | + |
|
| 968 | + /** @type array $status_items status legend setup */ |
|
| 969 | + $status_items = array( |
|
| 970 | + 'sent_status' => array( |
|
| 971 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 972 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence') |
|
| 973 | + ), |
|
| 974 | + 'idle_status' => array( |
|
| 975 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 976 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence') |
|
| 977 | + ), |
|
| 978 | + 'failed_status' => array( |
|
| 979 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 980 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence') |
|
| 981 | + ), |
|
| 982 | + 'messenger_executing_status' => array( |
|
| 983 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, |
|
| 984 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence') |
|
| 985 | + ), |
|
| 986 | + 'resend_status' => array( |
|
| 987 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 988 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence') |
|
| 989 | + ), |
|
| 990 | + 'incomplete_status' => array( |
|
| 991 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 992 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence') |
|
| 993 | + ), |
|
| 994 | + 'retry_status' => array( |
|
| 995 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 996 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence') |
|
| 997 | + ) |
|
| 998 | + ); |
|
| 999 | + if (EEM_Message::debug()) { |
|
| 1000 | + $status_items['debug_only_status'] = array( |
|
| 1001 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 1002 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence') |
|
| 1003 | + ); |
|
| 1004 | + } |
|
| 1005 | + |
|
| 1006 | + return array_merge($action_items, $status_items); |
|
| 1007 | + } |
|
| 1008 | + |
|
| 1009 | + |
|
| 1010 | + protected function _custom_mtps_preview() |
|
| 1011 | + { |
|
| 1012 | + $this->_admin_page_title = __('Custom Message Templates (Preview)', 'event_espresso'); |
|
| 1013 | + $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot', |
|
| 1014 | + 'event_espresso') . '" />'; |
|
| 1015 | + $this->_template_args['preview_text'] = '<strong>' . __('Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', |
|
| 1016 | + 'event_espresso') . '</strong>'; |
|
| 1017 | + $this->display_admin_caf_preview_page('custom_message_types', false); |
|
| 1018 | + } |
|
| 1019 | + |
|
| 1020 | + |
|
| 1021 | + /** |
|
| 1022 | + * get_message_templates |
|
| 1023 | + * This gets all the message templates for listing on the overview list. |
|
| 1024 | + * |
|
| 1025 | + * @access public |
|
| 1026 | + * |
|
| 1027 | + * @param int $perpage the amount of templates groups to show per page |
|
| 1028 | + * @param string $type the current _view we're getting templates for |
|
| 1029 | + * @param bool $count return count? |
|
| 1030 | + * @param bool $all disregard any paging info (get all data); |
|
| 1031 | + * @param bool $global whether to return just global (true) or custom templates (false) |
|
| 1032 | + * |
|
| 1033 | + * @return array |
|
| 1034 | + */ |
|
| 1035 | + public function get_message_templates($perpage = 10, $type = 'in_use', $count = false, $all = false, $global = true) |
|
| 1036 | + { |
|
| 1037 | + |
|
| 1038 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 1039 | + |
|
| 1040 | + $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby']; |
|
| 1041 | + $orderby = $this->_req_data['orderby']; |
|
| 1042 | + |
|
| 1043 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC'; |
|
| 1044 | + |
|
| 1045 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 1046 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $perpage; |
|
| 1047 | + |
|
| 1048 | + $offset = ($current_page - 1) * $per_page; |
|
| 1049 | + $limit = $all ? null : array($offset, $per_page); |
|
| 1050 | + |
|
| 1051 | + |
|
| 1052 | + //options will match what is in the _views array property |
|
| 1053 | + switch ($type) { |
|
| 1054 | 1054 | |
| 1055 | - case 'in_use': |
|
| 1056 | - $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true); |
|
| 1057 | - break; |
|
| 1055 | + case 'in_use': |
|
| 1056 | + $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true); |
|
| 1057 | + break; |
|
| 1058 | 1058 | |
| 1059 | - default: |
|
| 1060 | - $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global); |
|
| 1059 | + default: |
|
| 1060 | + $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global); |
|
| 1061 | 1061 | |
| 1062 | - } |
|
| 1063 | - |
|
| 1064 | - return $templates; |
|
| 1065 | - } |
|
| 1066 | - |
|
| 1067 | - |
|
| 1068 | - /** |
|
| 1069 | - * filters etc might need a list of installed message_types |
|
| 1070 | - * @return array an array of message type objects |
|
| 1071 | - */ |
|
| 1072 | - public function get_installed_message_types() |
|
| 1073 | - { |
|
| 1074 | - $installed_message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 1075 | - $installed = array(); |
|
| 1076 | - |
|
| 1077 | - foreach ($installed_message_types as $message_type) { |
|
| 1078 | - $installed[$message_type->name] = $message_type; |
|
| 1079 | - } |
|
| 1080 | - |
|
| 1081 | - return $installed; |
|
| 1082 | - } |
|
| 1083 | - |
|
| 1084 | - |
|
| 1085 | - /** |
|
| 1086 | - * _add_message_template |
|
| 1087 | - * |
|
| 1088 | - * This is used when creating a custom template. All Custom Templates start based off another template. |
|
| 1089 | - * |
|
| 1090 | - * @param string $message_type |
|
| 1091 | - * @param string $messenger |
|
| 1092 | - * @param string $GRP_ID |
|
| 1093 | - * |
|
| 1094 | - * @throws EE_error |
|
| 1095 | - */ |
|
| 1096 | - protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '') |
|
| 1097 | - { |
|
| 1098 | - //set values override any request data |
|
| 1099 | - $message_type = ! empty($message_type) ? $message_type : ''; |
|
| 1100 | - $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) ? $this->_req_data['message_type'] : $message_type; |
|
| 1101 | - |
|
| 1102 | - $messenger = ! empty($messenger) ? $messenger : ''; |
|
| 1103 | - $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) ? $this->_req_data['messenger'] : $messenger; |
|
| 1104 | - |
|
| 1105 | - $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : ''; |
|
| 1106 | - $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID; |
|
| 1107 | - |
|
| 1108 | - //we need messenger and message type. They should be coming from the event editor. If not here then return error |
|
| 1109 | - if (empty($message_type) || empty($messenger)) { |
|
| 1110 | - throw new EE_error(__('Sorry, but we can\'t create new templates because we\'re missing the messenger or message type', |
|
| 1111 | - 'event_espresso')); |
|
| 1112 | - } |
|
| 1113 | - |
|
| 1114 | - //we need the GRP_ID for the template being used as the base for the new template |
|
| 1115 | - if (empty($GRP_ID)) { |
|
| 1116 | - 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', |
|
| 1117 | - 'event_espresso')); |
|
| 1118 | - } |
|
| 1119 | - |
|
| 1120 | - //let's just make sure the template gets generated! |
|
| 1121 | - |
|
| 1122 | - //we need to reassign some variables for what the insert is expecting |
|
| 1123 | - $this->_req_data['MTP_messenger'] = $messenger; |
|
| 1124 | - $this->_req_data['MTP_message_type'] = $message_type; |
|
| 1125 | - $this->_req_data['GRP_ID'] = $GRP_ID; |
|
| 1126 | - $this->_insert_or_update_message_template(true); |
|
| 1127 | - } |
|
| 1128 | - |
|
| 1129 | - |
|
| 1130 | - /** |
|
| 1131 | - * public wrapper for the _add_message_template method |
|
| 1132 | - * |
|
| 1133 | - * @param string $message_type message type slug |
|
| 1134 | - * @param string $messenger messenger slug |
|
| 1135 | - * @param int $GRP_ID GRP_ID for the related message template group this new template will be based |
|
| 1136 | - * off of. |
|
| 1137 | - */ |
|
| 1138 | - public function add_message_template($message_type, $messenger, $GRP_ID) |
|
| 1139 | - { |
|
| 1140 | - $this->_add_message_template($message_type, $messenger, $GRP_ID); |
|
| 1141 | - } |
|
| 1142 | - |
|
| 1143 | - |
|
| 1144 | - /** |
|
| 1145 | - * _edit_message_template |
|
| 1146 | - * |
|
| 1147 | - * @access protected |
|
| 1148 | - * @return void |
|
| 1149 | - */ |
|
| 1150 | - protected function _edit_message_template() |
|
| 1151 | - { |
|
| 1152 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1153 | - $template_fields = ''; |
|
| 1154 | - $sidebar_fields = ''; |
|
| 1155 | - //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have valid html in the templates. |
|
| 1156 | - add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2); |
|
| 1157 | - |
|
| 1158 | - $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 1159 | - ? absint($this->_req_data['id']) |
|
| 1160 | - : false; |
|
| 1161 | - |
|
| 1162 | - $this->_set_shortcodes(); //this also sets the _message_template property. |
|
| 1163 | - $message_template_group = $this->_message_template_group; |
|
| 1164 | - $c_label = $message_template_group->context_label(); |
|
| 1165 | - $c_config = $message_template_group->contexts_config(); |
|
| 1166 | - |
|
| 1167 | - reset($c_config); |
|
| 1168 | - $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context']) |
|
| 1169 | - ? strtolower($this->_req_data['context']) |
|
| 1170 | - : key($c_config); |
|
| 1171 | - |
|
| 1172 | - |
|
| 1173 | - if (empty($GRP_ID)) { |
|
| 1174 | - $action = 'insert_message_template'; |
|
| 1175 | - //$button_both = false; |
|
| 1176 | - //$button_text = array( __( 'Save','event_espresso') ); |
|
| 1177 | - //$button_actions = array('something_different'); |
|
| 1178 | - //$referrer = false; |
|
| 1179 | - $edit_message_template_form_url = add_query_arg( |
|
| 1180 | - array('action' => $action, 'noheader' => true), |
|
| 1181 | - EE_MSG_ADMIN_URL |
|
| 1182 | - ); |
|
| 1183 | - } else { |
|
| 1184 | - $action = 'update_message_template'; |
|
| 1185 | - //$button_both = true; |
|
| 1186 | - //$button_text = array(); |
|
| 1187 | - //$button_actions = array(); |
|
| 1188 | - //$referrer = $this->_admin_base_url; |
|
| 1189 | - $edit_message_template_form_url = add_query_arg( |
|
| 1190 | - array('action' => $action, 'noheader' => true), |
|
| 1191 | - EE_MSG_ADMIN_URL |
|
| 1192 | - ); |
|
| 1193 | - } |
|
| 1194 | - |
|
| 1195 | - //set active messenger for this view |
|
| 1196 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 1197 | - $message_template_group->messenger() |
|
| 1198 | - ); |
|
| 1199 | - $this->_active_message_type_name = $message_template_group->message_type(); |
|
| 1200 | - |
|
| 1201 | - |
|
| 1202 | - //Do we have any validation errors? |
|
| 1203 | - $validators = $this->_get_transient(); |
|
| 1204 | - $v_fields = ! empty($validators) ? array_keys($validators) : array(); |
|
| 1205 | - |
|
| 1206 | - |
|
| 1207 | - //we need to assemble the title from Various details |
|
| 1208 | - $context_label = sprintf( |
|
| 1209 | - __('(%s %s)', 'event_espresso'), |
|
| 1210 | - $c_config[$context]['label'], |
|
| 1211 | - ucwords($c_label['label']) |
|
| 1212 | - ); |
|
| 1213 | - |
|
| 1214 | - $title = sprintf( |
|
| 1215 | - __(' %s %s Template %s', 'event_espresso'), |
|
| 1216 | - ucwords($message_template_group->messenger_obj()->label['singular']), |
|
| 1217 | - ucwords($message_template_group->message_type_obj()->label['singular']), |
|
| 1218 | - $context_label |
|
| 1219 | - ); |
|
| 1220 | - |
|
| 1221 | - $this->_template_args['GRP_ID'] = $GRP_ID; |
|
| 1222 | - $this->_template_args['message_template'] = $message_template_group; |
|
| 1223 | - $this->_template_args['is_extra_fields'] = false; |
|
| 1224 | - |
|
| 1225 | - |
|
| 1226 | - //let's get EEH_MSG_Template so we can get template form fields |
|
| 1227 | - $template_field_structure = EEH_MSG_Template::get_fields( |
|
| 1228 | - $message_template_group->messenger(), |
|
| 1229 | - $message_template_group->message_type() |
|
| 1230 | - ); |
|
| 1231 | - |
|
| 1232 | - if ( ! $template_field_structure) { |
|
| 1233 | - $template_field_structure = false; |
|
| 1234 | - $template_fields = __('There was an error in assembling the fields for this display (you should see an error message)', |
|
| 1235 | - 'event_espresso'); |
|
| 1236 | - } |
|
| 1237 | - |
|
| 1238 | - |
|
| 1239 | - $message_templates = $message_template_group->context_templates(); |
|
| 1240 | - |
|
| 1241 | - |
|
| 1242 | - //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. |
|
| 1243 | - if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) { |
|
| 1244 | - foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) { |
|
| 1245 | - unset($template_field_structure[$context][$reference_field]); |
|
| 1246 | - } |
|
| 1247 | - } |
|
| 1248 | - |
|
| 1249 | - //let's loop through the template_field_structure and actually assemble the input fields! |
|
| 1250 | - if ( ! empty($template_field_structure)) { |
|
| 1251 | - foreach ($template_field_structure[$context] as $template_field => $field_setup_array) { |
|
| 1252 | - //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. |
|
| 1253 | - if ($template_field == 'extra') { |
|
| 1254 | - $this->_template_args['is_extra_fields'] = true; |
|
| 1255 | - foreach ($field_setup_array as $reference_field => $new_fields_array) { |
|
| 1256 | - $message_template = $message_templates[$context][$reference_field]; |
|
| 1257 | - $content = $message_template instanceof EE_Message_Template |
|
| 1258 | - ? $message_template->get('MTP_content') |
|
| 1259 | - : ''; |
|
| 1260 | - foreach ($new_fields_array as $extra_field => $extra_array) { |
|
| 1261 | - //let's verify if we need this extra field via the shortcodes parameter. |
|
| 1262 | - $continue = false; |
|
| 1263 | - if (isset($extra_array['shortcodes_required'])) { |
|
| 1264 | - foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { |
|
| 1265 | - if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
|
| 1266 | - $continue = true; |
|
| 1267 | - } |
|
| 1268 | - } |
|
| 1269 | - if ($continue) { |
|
| 1270 | - continue; |
|
| 1271 | - } |
|
| 1272 | - } |
|
| 1062 | + } |
|
| 1063 | + |
|
| 1064 | + return $templates; |
|
| 1065 | + } |
|
| 1066 | + |
|
| 1067 | + |
|
| 1068 | + /** |
|
| 1069 | + * filters etc might need a list of installed message_types |
|
| 1070 | + * @return array an array of message type objects |
|
| 1071 | + */ |
|
| 1072 | + public function get_installed_message_types() |
|
| 1073 | + { |
|
| 1074 | + $installed_message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 1075 | + $installed = array(); |
|
| 1076 | + |
|
| 1077 | + foreach ($installed_message_types as $message_type) { |
|
| 1078 | + $installed[$message_type->name] = $message_type; |
|
| 1079 | + } |
|
| 1080 | + |
|
| 1081 | + return $installed; |
|
| 1082 | + } |
|
| 1083 | + |
|
| 1084 | + |
|
| 1085 | + /** |
|
| 1086 | + * _add_message_template |
|
| 1087 | + * |
|
| 1088 | + * This is used when creating a custom template. All Custom Templates start based off another template. |
|
| 1089 | + * |
|
| 1090 | + * @param string $message_type |
|
| 1091 | + * @param string $messenger |
|
| 1092 | + * @param string $GRP_ID |
|
| 1093 | + * |
|
| 1094 | + * @throws EE_error |
|
| 1095 | + */ |
|
| 1096 | + protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '') |
|
| 1097 | + { |
|
| 1098 | + //set values override any request data |
|
| 1099 | + $message_type = ! empty($message_type) ? $message_type : ''; |
|
| 1100 | + $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) ? $this->_req_data['message_type'] : $message_type; |
|
| 1101 | + |
|
| 1102 | + $messenger = ! empty($messenger) ? $messenger : ''; |
|
| 1103 | + $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) ? $this->_req_data['messenger'] : $messenger; |
|
| 1104 | + |
|
| 1105 | + $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : ''; |
|
| 1106 | + $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID; |
|
| 1107 | + |
|
| 1108 | + //we need messenger and message type. They should be coming from the event editor. If not here then return error |
|
| 1109 | + if (empty($message_type) || empty($messenger)) { |
|
| 1110 | + throw new EE_error(__('Sorry, but we can\'t create new templates because we\'re missing the messenger or message type', |
|
| 1111 | + 'event_espresso')); |
|
| 1112 | + } |
|
| 1113 | + |
|
| 1114 | + //we need the GRP_ID for the template being used as the base for the new template |
|
| 1115 | + if (empty($GRP_ID)) { |
|
| 1116 | + 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', |
|
| 1117 | + 'event_espresso')); |
|
| 1118 | + } |
|
| 1119 | + |
|
| 1120 | + //let's just make sure the template gets generated! |
|
| 1121 | + |
|
| 1122 | + //we need to reassign some variables for what the insert is expecting |
|
| 1123 | + $this->_req_data['MTP_messenger'] = $messenger; |
|
| 1124 | + $this->_req_data['MTP_message_type'] = $message_type; |
|
| 1125 | + $this->_req_data['GRP_ID'] = $GRP_ID; |
|
| 1126 | + $this->_insert_or_update_message_template(true); |
|
| 1127 | + } |
|
| 1128 | + |
|
| 1129 | + |
|
| 1130 | + /** |
|
| 1131 | + * public wrapper for the _add_message_template method |
|
| 1132 | + * |
|
| 1133 | + * @param string $message_type message type slug |
|
| 1134 | + * @param string $messenger messenger slug |
|
| 1135 | + * @param int $GRP_ID GRP_ID for the related message template group this new template will be based |
|
| 1136 | + * off of. |
|
| 1137 | + */ |
|
| 1138 | + public function add_message_template($message_type, $messenger, $GRP_ID) |
|
| 1139 | + { |
|
| 1140 | + $this->_add_message_template($message_type, $messenger, $GRP_ID); |
|
| 1141 | + } |
|
| 1142 | + |
|
| 1143 | + |
|
| 1144 | + /** |
|
| 1145 | + * _edit_message_template |
|
| 1146 | + * |
|
| 1147 | + * @access protected |
|
| 1148 | + * @return void |
|
| 1149 | + */ |
|
| 1150 | + protected function _edit_message_template() |
|
| 1151 | + { |
|
| 1152 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1153 | + $template_fields = ''; |
|
| 1154 | + $sidebar_fields = ''; |
|
| 1155 | + //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have valid html in the templates. |
|
| 1156 | + add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2); |
|
| 1157 | + |
|
| 1158 | + $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 1159 | + ? absint($this->_req_data['id']) |
|
| 1160 | + : false; |
|
| 1161 | + |
|
| 1162 | + $this->_set_shortcodes(); //this also sets the _message_template property. |
|
| 1163 | + $message_template_group = $this->_message_template_group; |
|
| 1164 | + $c_label = $message_template_group->context_label(); |
|
| 1165 | + $c_config = $message_template_group->contexts_config(); |
|
| 1166 | + |
|
| 1167 | + reset($c_config); |
|
| 1168 | + $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context']) |
|
| 1169 | + ? strtolower($this->_req_data['context']) |
|
| 1170 | + : key($c_config); |
|
| 1171 | + |
|
| 1172 | + |
|
| 1173 | + if (empty($GRP_ID)) { |
|
| 1174 | + $action = 'insert_message_template'; |
|
| 1175 | + //$button_both = false; |
|
| 1176 | + //$button_text = array( __( 'Save','event_espresso') ); |
|
| 1177 | + //$button_actions = array('something_different'); |
|
| 1178 | + //$referrer = false; |
|
| 1179 | + $edit_message_template_form_url = add_query_arg( |
|
| 1180 | + array('action' => $action, 'noheader' => true), |
|
| 1181 | + EE_MSG_ADMIN_URL |
|
| 1182 | + ); |
|
| 1183 | + } else { |
|
| 1184 | + $action = 'update_message_template'; |
|
| 1185 | + //$button_both = true; |
|
| 1186 | + //$button_text = array(); |
|
| 1187 | + //$button_actions = array(); |
|
| 1188 | + //$referrer = $this->_admin_base_url; |
|
| 1189 | + $edit_message_template_form_url = add_query_arg( |
|
| 1190 | + array('action' => $action, 'noheader' => true), |
|
| 1191 | + EE_MSG_ADMIN_URL |
|
| 1192 | + ); |
|
| 1193 | + } |
|
| 1194 | + |
|
| 1195 | + //set active messenger for this view |
|
| 1196 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 1197 | + $message_template_group->messenger() |
|
| 1198 | + ); |
|
| 1199 | + $this->_active_message_type_name = $message_template_group->message_type(); |
|
| 1200 | + |
|
| 1201 | + |
|
| 1202 | + //Do we have any validation errors? |
|
| 1203 | + $validators = $this->_get_transient(); |
|
| 1204 | + $v_fields = ! empty($validators) ? array_keys($validators) : array(); |
|
| 1205 | + |
|
| 1206 | + |
|
| 1207 | + //we need to assemble the title from Various details |
|
| 1208 | + $context_label = sprintf( |
|
| 1209 | + __('(%s %s)', 'event_espresso'), |
|
| 1210 | + $c_config[$context]['label'], |
|
| 1211 | + ucwords($c_label['label']) |
|
| 1212 | + ); |
|
| 1213 | + |
|
| 1214 | + $title = sprintf( |
|
| 1215 | + __(' %s %s Template %s', 'event_espresso'), |
|
| 1216 | + ucwords($message_template_group->messenger_obj()->label['singular']), |
|
| 1217 | + ucwords($message_template_group->message_type_obj()->label['singular']), |
|
| 1218 | + $context_label |
|
| 1219 | + ); |
|
| 1220 | + |
|
| 1221 | + $this->_template_args['GRP_ID'] = $GRP_ID; |
|
| 1222 | + $this->_template_args['message_template'] = $message_template_group; |
|
| 1223 | + $this->_template_args['is_extra_fields'] = false; |
|
| 1224 | + |
|
| 1225 | + |
|
| 1226 | + //let's get EEH_MSG_Template so we can get template form fields |
|
| 1227 | + $template_field_structure = EEH_MSG_Template::get_fields( |
|
| 1228 | + $message_template_group->messenger(), |
|
| 1229 | + $message_template_group->message_type() |
|
| 1230 | + ); |
|
| 1231 | + |
|
| 1232 | + if ( ! $template_field_structure) { |
|
| 1233 | + $template_field_structure = false; |
|
| 1234 | + $template_fields = __('There was an error in assembling the fields for this display (you should see an error message)', |
|
| 1235 | + 'event_espresso'); |
|
| 1236 | + } |
|
| 1237 | + |
|
| 1238 | + |
|
| 1239 | + $message_templates = $message_template_group->context_templates(); |
|
| 1240 | + |
|
| 1241 | + |
|
| 1242 | + //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. |
|
| 1243 | + if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) { |
|
| 1244 | + foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) { |
|
| 1245 | + unset($template_field_structure[$context][$reference_field]); |
|
| 1246 | + } |
|
| 1247 | + } |
|
| 1248 | + |
|
| 1249 | + //let's loop through the template_field_structure and actually assemble the input fields! |
|
| 1250 | + if ( ! empty($template_field_structure)) { |
|
| 1251 | + foreach ($template_field_structure[$context] as $template_field => $field_setup_array) { |
|
| 1252 | + //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. |
|
| 1253 | + if ($template_field == 'extra') { |
|
| 1254 | + $this->_template_args['is_extra_fields'] = true; |
|
| 1255 | + foreach ($field_setup_array as $reference_field => $new_fields_array) { |
|
| 1256 | + $message_template = $message_templates[$context][$reference_field]; |
|
| 1257 | + $content = $message_template instanceof EE_Message_Template |
|
| 1258 | + ? $message_template->get('MTP_content') |
|
| 1259 | + : ''; |
|
| 1260 | + foreach ($new_fields_array as $extra_field => $extra_array) { |
|
| 1261 | + //let's verify if we need this extra field via the shortcodes parameter. |
|
| 1262 | + $continue = false; |
|
| 1263 | + if (isset($extra_array['shortcodes_required'])) { |
|
| 1264 | + foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { |
|
| 1265 | + if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
|
| 1266 | + $continue = true; |
|
| 1267 | + } |
|
| 1268 | + } |
|
| 1269 | + if ($continue) { |
|
| 1270 | + continue; |
|
| 1271 | + } |
|
| 1272 | + } |
|
| 1273 | 1273 | |
| 1274 | - $field_id = $reference_field . '-' . $extra_field . '-content'; |
|
| 1275 | - $template_form_fields[$field_id] = $extra_array; |
|
| 1276 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']'; |
|
| 1277 | - $css_class = isset($extra_array['css_class']) ? $extra_array['css_class'] : ''; |
|
| 1274 | + $field_id = $reference_field . '-' . $extra_field . '-content'; |
|
| 1275 | + $template_form_fields[$field_id] = $extra_array; |
|
| 1276 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']'; |
|
| 1277 | + $css_class = isset($extra_array['css_class']) ? $extra_array['css_class'] : ''; |
|
| 1278 | 1278 | |
| 1279 | - $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1280 | - && in_array($extra_field, $v_fields) |
|
| 1281 | - && |
|
| 1282 | - ( |
|
| 1283 | - is_array($validators[$extra_field]) |
|
| 1284 | - && isset($validators[$extra_field]['msg']) |
|
| 1285 | - ) |
|
| 1286 | - ? 'validate-error ' . $css_class |
|
| 1287 | - : $css_class; |
|
| 1279 | + $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1280 | + && in_array($extra_field, $v_fields) |
|
| 1281 | + && |
|
| 1282 | + ( |
|
| 1283 | + is_array($validators[$extra_field]) |
|
| 1284 | + && isset($validators[$extra_field]['msg']) |
|
| 1285 | + ) |
|
| 1286 | + ? 'validate-error ' . $css_class |
|
| 1287 | + : $css_class; |
|
| 1288 | 1288 | |
| 1289 | - $template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field]) |
|
| 1290 | - ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8")) |
|
| 1291 | - : ''; |
|
| 1289 | + $template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field]) |
|
| 1290 | + ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8")) |
|
| 1291 | + : ''; |
|
| 1292 | 1292 | |
| 1293 | - //do we have a validation error? if we do then let's use that value instead |
|
| 1294 | - $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) ? $validators[$extra_field]['value'] : $template_form_fields[$field_id]['value']; |
|
| 1293 | + //do we have a validation error? if we do then let's use that value instead |
|
| 1294 | + $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) ? $validators[$extra_field]['value'] : $template_form_fields[$field_id]['value']; |
|
| 1295 | 1295 | |
| 1296 | 1296 | |
| 1297 | - $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1297 | + $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1298 | 1298 | |
| 1299 | - //shortcode selector |
|
| 1300 | - $field_name_to_use = $extra_field == 'main' ? 'content' : $extra_field; |
|
| 1301 | - $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1302 | - $field_name_to_use, |
|
| 1303 | - $field_id |
|
| 1304 | - ); |
|
| 1299 | + //shortcode selector |
|
| 1300 | + $field_name_to_use = $extra_field == 'main' ? 'content' : $extra_field; |
|
| 1301 | + $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1302 | + $field_name_to_use, |
|
| 1303 | + $field_id |
|
| 1304 | + ); |
|
| 1305 | 1305 | |
| 1306 | - if (isset($extra_array['input']) && $extra_array['input'] == 'wp_editor') { |
|
| 1307 | - //we want to decode the entities |
|
| 1308 | - $template_form_fields[$field_id]['value'] = stripslashes( |
|
| 1309 | - html_entity_decode($template_form_fields[$field_id]['value'], ENT_QUOTES, "UTF-8") |
|
| 1310 | - ); |
|
| 1306 | + if (isset($extra_array['input']) && $extra_array['input'] == 'wp_editor') { |
|
| 1307 | + //we want to decode the entities |
|
| 1308 | + $template_form_fields[$field_id]['value'] = stripslashes( |
|
| 1309 | + html_entity_decode($template_form_fields[$field_id]['value'], ENT_QUOTES, "UTF-8") |
|
| 1310 | + ); |
|
| 1311 | 1311 | |
| 1312 | - }/**/ |
|
| 1313 | - } |
|
| 1314 | - $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1315 | - $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1312 | + }/**/ |
|
| 1313 | + } |
|
| 1314 | + $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1315 | + $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1316 | 1316 | |
| 1317 | - $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1318 | - 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1319 | - 'label' => null, |
|
| 1320 | - 'input' => 'hidden', |
|
| 1321 | - 'type' => 'int', |
|
| 1322 | - 'required' => false, |
|
| 1323 | - 'validation' => false, |
|
| 1324 | - 'value' => ! empty($message_templates) ? $message_template->ID() : '', |
|
| 1325 | - 'css_class' => '', |
|
| 1326 | - 'format' => '%d', |
|
| 1327 | - 'db-col' => 'MTP_ID' |
|
| 1328 | - ); |
|
| 1317 | + $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1318 | + 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1319 | + 'label' => null, |
|
| 1320 | + 'input' => 'hidden', |
|
| 1321 | + 'type' => 'int', |
|
| 1322 | + 'required' => false, |
|
| 1323 | + 'validation' => false, |
|
| 1324 | + 'value' => ! empty($message_templates) ? $message_template->ID() : '', |
|
| 1325 | + 'css_class' => '', |
|
| 1326 | + 'format' => '%d', |
|
| 1327 | + 'db-col' => 'MTP_ID' |
|
| 1328 | + ); |
|
| 1329 | 1329 | |
| 1330 | - $template_form_fields[$templatefield_templatename_id] = array( |
|
| 1331 | - 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1332 | - 'label' => null, |
|
| 1333 | - 'input' => 'hidden', |
|
| 1334 | - 'type' => 'string', |
|
| 1335 | - 'required' => false, |
|
| 1336 | - 'validation' => true, |
|
| 1337 | - 'value' => $reference_field, |
|
| 1338 | - 'css_class' => '', |
|
| 1339 | - 'format' => '%s', |
|
| 1340 | - 'db-col' => 'MTP_template_field' |
|
| 1341 | - ); |
|
| 1342 | - } |
|
| 1343 | - continue; //skip the next stuff, we got the necessary fields here for this dataset. |
|
| 1344 | - } else { |
|
| 1345 | - $field_id = $template_field . '-content'; |
|
| 1346 | - $template_form_fields[$field_id] = $field_setup_array; |
|
| 1347 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1348 | - $message_template = isset($message_templates[$context][$template_field]) |
|
| 1349 | - ? $message_templates[$context][$template_field] |
|
| 1350 | - : null; |
|
| 1351 | - $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1352 | - && is_array($message_templates[$context]) |
|
| 1353 | - && $message_template instanceof EE_Message_Template |
|
| 1354 | - ? $message_template->get('MTP_content') |
|
| 1355 | - : ''; |
|
| 1330 | + $template_form_fields[$templatefield_templatename_id] = array( |
|
| 1331 | + 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1332 | + 'label' => null, |
|
| 1333 | + 'input' => 'hidden', |
|
| 1334 | + 'type' => 'string', |
|
| 1335 | + 'required' => false, |
|
| 1336 | + 'validation' => true, |
|
| 1337 | + 'value' => $reference_field, |
|
| 1338 | + 'css_class' => '', |
|
| 1339 | + 'format' => '%s', |
|
| 1340 | + 'db-col' => 'MTP_template_field' |
|
| 1341 | + ); |
|
| 1342 | + } |
|
| 1343 | + continue; //skip the next stuff, we got the necessary fields here for this dataset. |
|
| 1344 | + } else { |
|
| 1345 | + $field_id = $template_field . '-content'; |
|
| 1346 | + $template_form_fields[$field_id] = $field_setup_array; |
|
| 1347 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1348 | + $message_template = isset($message_templates[$context][$template_field]) |
|
| 1349 | + ? $message_templates[$context][$template_field] |
|
| 1350 | + : null; |
|
| 1351 | + $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1352 | + && is_array($message_templates[$context]) |
|
| 1353 | + && $message_template instanceof EE_Message_Template |
|
| 1354 | + ? $message_template->get('MTP_content') |
|
| 1355 | + : ''; |
|
| 1356 | 1356 | |
| 1357 | - //do we have a validator error for this field? if we do then we'll use that value instead |
|
| 1358 | - $template_form_fields[$field_id]['value'] = isset($validators[$template_field]) |
|
| 1359 | - ? $validators[$template_field]['value'] |
|
| 1360 | - : $template_form_fields[$field_id]['value']; |
|
| 1357 | + //do we have a validator error for this field? if we do then we'll use that value instead |
|
| 1358 | + $template_form_fields[$field_id]['value'] = isset($validators[$template_field]) |
|
| 1359 | + ? $validators[$template_field]['value'] |
|
| 1360 | + : $template_form_fields[$field_id]['value']; |
|
| 1361 | 1361 | |
| 1362 | 1362 | |
| 1363 | - $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1364 | - $css_class = isset($field_setup_array['css_class']) ? $field_setup_array['css_class'] : ''; |
|
| 1365 | - $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1366 | - && in_array($template_field, $v_fields) |
|
| 1367 | - && isset($validators[$template_field]['msg']) |
|
| 1368 | - ? 'validate-error ' . $css_class |
|
| 1369 | - : $css_class; |
|
| 1363 | + $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1364 | + $css_class = isset($field_setup_array['css_class']) ? $field_setup_array['css_class'] : ''; |
|
| 1365 | + $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1366 | + && in_array($template_field, $v_fields) |
|
| 1367 | + && isset($validators[$template_field]['msg']) |
|
| 1368 | + ? 'validate-error ' . $css_class |
|
| 1369 | + : $css_class; |
|
| 1370 | 1370 | |
| 1371 | - //shortcode selector |
|
| 1372 | - $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1373 | - $template_field, $field_id |
|
| 1374 | - ); |
|
| 1375 | - } |
|
| 1371 | + //shortcode selector |
|
| 1372 | + $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1373 | + $template_field, $field_id |
|
| 1374 | + ); |
|
| 1375 | + } |
|
| 1376 | 1376 | |
| 1377 | - //k took care of content field(s) now let's take care of others. |
|
| 1377 | + //k took care of content field(s) now let's take care of others. |
|
| 1378 | 1378 | |
| 1379 | - $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1380 | - $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1379 | + $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1380 | + $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1381 | 1381 | |
| 1382 | - //foreach template field there are actually two form fields created |
|
| 1383 | - $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1384 | - 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1385 | - 'label' => null, |
|
| 1386 | - 'input' => 'hidden', |
|
| 1387 | - 'type' => 'int', |
|
| 1388 | - 'required' => false, |
|
| 1389 | - 'validation' => true, |
|
| 1390 | - 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '', |
|
| 1391 | - 'css_class' => '', |
|
| 1392 | - 'format' => '%d', |
|
| 1393 | - 'db-col' => 'MTP_ID' |
|
| 1394 | - ); |
|
| 1382 | + //foreach template field there are actually two form fields created |
|
| 1383 | + $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1384 | + 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1385 | + 'label' => null, |
|
| 1386 | + 'input' => 'hidden', |
|
| 1387 | + 'type' => 'int', |
|
| 1388 | + 'required' => false, |
|
| 1389 | + 'validation' => true, |
|
| 1390 | + 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '', |
|
| 1391 | + 'css_class' => '', |
|
| 1392 | + 'format' => '%d', |
|
| 1393 | + 'db-col' => 'MTP_ID' |
|
| 1394 | + ); |
|
| 1395 | 1395 | |
| 1396 | - $template_form_fields[$templatefield_field_templatename_id] = array( |
|
| 1397 | - 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1398 | - 'label' => null, |
|
| 1399 | - 'input' => 'hidden', |
|
| 1400 | - 'type' => 'string', |
|
| 1401 | - 'required' => false, |
|
| 1402 | - 'validation' => true, |
|
| 1403 | - 'value' => $template_field, |
|
| 1404 | - 'css_class' => '', |
|
| 1405 | - 'format' => '%s', |
|
| 1406 | - 'db-col' => 'MTP_template_field' |
|
| 1407 | - ); |
|
| 1396 | + $template_form_fields[$templatefield_field_templatename_id] = array( |
|
| 1397 | + 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1398 | + 'label' => null, |
|
| 1399 | + 'input' => 'hidden', |
|
| 1400 | + 'type' => 'string', |
|
| 1401 | + 'required' => false, |
|
| 1402 | + 'validation' => true, |
|
| 1403 | + 'value' => $template_field, |
|
| 1404 | + 'css_class' => '', |
|
| 1405 | + 'format' => '%s', |
|
| 1406 | + 'db-col' => 'MTP_template_field' |
|
| 1407 | + ); |
|
| 1408 | 1408 | |
| 1409 | - } |
|
| 1409 | + } |
|
| 1410 | 1410 | |
| 1411 | - //add other fields |
|
| 1412 | - $template_form_fields['ee-msg-current-context'] = array( |
|
| 1413 | - 'name' => 'MTP_context', |
|
| 1414 | - 'label' => null, |
|
| 1415 | - 'input' => 'hidden', |
|
| 1416 | - 'type' => 'string', |
|
| 1417 | - 'required' => false, |
|
| 1418 | - 'validation' => true, |
|
| 1419 | - 'value' => $context, |
|
| 1420 | - 'css_class' => '', |
|
| 1421 | - 'format' => '%s', |
|
| 1422 | - 'db-col' => 'MTP_context' |
|
| 1423 | - ); |
|
| 1411 | + //add other fields |
|
| 1412 | + $template_form_fields['ee-msg-current-context'] = array( |
|
| 1413 | + 'name' => 'MTP_context', |
|
| 1414 | + 'label' => null, |
|
| 1415 | + 'input' => 'hidden', |
|
| 1416 | + 'type' => 'string', |
|
| 1417 | + 'required' => false, |
|
| 1418 | + 'validation' => true, |
|
| 1419 | + 'value' => $context, |
|
| 1420 | + 'css_class' => '', |
|
| 1421 | + 'format' => '%s', |
|
| 1422 | + 'db-col' => 'MTP_context' |
|
| 1423 | + ); |
|
| 1424 | 1424 | |
| 1425 | - $template_form_fields['ee-msg-grp-id'] = array( |
|
| 1426 | - 'name' => 'GRP_ID', |
|
| 1427 | - 'label' => null, |
|
| 1428 | - 'input' => 'hidden', |
|
| 1429 | - 'type' => 'int', |
|
| 1430 | - 'required' => false, |
|
| 1431 | - 'validation' => true, |
|
| 1432 | - 'value' => $GRP_ID, |
|
| 1433 | - 'css_class' => '', |
|
| 1434 | - 'format' => '%d', |
|
| 1435 | - 'db-col' => 'GRP_ID' |
|
| 1436 | - ); |
|
| 1425 | + $template_form_fields['ee-msg-grp-id'] = array( |
|
| 1426 | + 'name' => 'GRP_ID', |
|
| 1427 | + 'label' => null, |
|
| 1428 | + 'input' => 'hidden', |
|
| 1429 | + 'type' => 'int', |
|
| 1430 | + 'required' => false, |
|
| 1431 | + 'validation' => true, |
|
| 1432 | + 'value' => $GRP_ID, |
|
| 1433 | + 'css_class' => '', |
|
| 1434 | + 'format' => '%d', |
|
| 1435 | + 'db-col' => 'GRP_ID' |
|
| 1436 | + ); |
|
| 1437 | 1437 | |
| 1438 | - $template_form_fields['ee-msg-messenger'] = array( |
|
| 1439 | - 'name' => 'MTP_messenger', |
|
| 1440 | - 'label' => null, |
|
| 1441 | - 'input' => 'hidden', |
|
| 1442 | - 'type' => 'string', |
|
| 1443 | - 'required' => false, |
|
| 1444 | - 'validation' => true, |
|
| 1445 | - 'value' => $message_template_group->messenger(), |
|
| 1446 | - 'css_class' => '', |
|
| 1447 | - 'format' => '%s', |
|
| 1448 | - 'db-col' => 'MTP_messenger' |
|
| 1449 | - ); |
|
| 1438 | + $template_form_fields['ee-msg-messenger'] = array( |
|
| 1439 | + 'name' => 'MTP_messenger', |
|
| 1440 | + 'label' => null, |
|
| 1441 | + 'input' => 'hidden', |
|
| 1442 | + 'type' => 'string', |
|
| 1443 | + 'required' => false, |
|
| 1444 | + 'validation' => true, |
|
| 1445 | + 'value' => $message_template_group->messenger(), |
|
| 1446 | + 'css_class' => '', |
|
| 1447 | + 'format' => '%s', |
|
| 1448 | + 'db-col' => 'MTP_messenger' |
|
| 1449 | + ); |
|
| 1450 | 1450 | |
| 1451 | - $template_form_fields['ee-msg-message-type'] = array( |
|
| 1452 | - 'name' => 'MTP_message_type', |
|
| 1453 | - 'label' => null, |
|
| 1454 | - 'input' => 'hidden', |
|
| 1455 | - 'type' => 'string', |
|
| 1456 | - 'required' => false, |
|
| 1457 | - 'validation' => true, |
|
| 1458 | - 'value' => $message_template_group->message_type(), |
|
| 1459 | - 'css_class' => '', |
|
| 1460 | - 'format' => '%s', |
|
| 1461 | - 'db-col' => 'MTP_message_type' |
|
| 1462 | - ); |
|
| 1451 | + $template_form_fields['ee-msg-message-type'] = array( |
|
| 1452 | + 'name' => 'MTP_message_type', |
|
| 1453 | + 'label' => null, |
|
| 1454 | + 'input' => 'hidden', |
|
| 1455 | + 'type' => 'string', |
|
| 1456 | + 'required' => false, |
|
| 1457 | + 'validation' => true, |
|
| 1458 | + 'value' => $message_template_group->message_type(), |
|
| 1459 | + 'css_class' => '', |
|
| 1460 | + 'format' => '%s', |
|
| 1461 | + 'db-col' => 'MTP_message_type' |
|
| 1462 | + ); |
|
| 1463 | 1463 | |
| 1464 | - $sidebar_form_fields['ee-msg-is-global'] = array( |
|
| 1465 | - 'name' => 'MTP_is_global', |
|
| 1466 | - 'label' => __('Global Template', 'event_espresso'), |
|
| 1467 | - 'input' => 'hidden', |
|
| 1468 | - 'type' => 'int', |
|
| 1469 | - 'required' => false, |
|
| 1470 | - 'validation' => true, |
|
| 1471 | - 'value' => $message_template_group->get('MTP_is_global'), |
|
| 1472 | - 'css_class' => '', |
|
| 1473 | - 'format' => '%d', |
|
| 1474 | - 'db-col' => 'MTP_is_global' |
|
| 1475 | - ); |
|
| 1464 | + $sidebar_form_fields['ee-msg-is-global'] = array( |
|
| 1465 | + 'name' => 'MTP_is_global', |
|
| 1466 | + 'label' => __('Global Template', 'event_espresso'), |
|
| 1467 | + 'input' => 'hidden', |
|
| 1468 | + 'type' => 'int', |
|
| 1469 | + 'required' => false, |
|
| 1470 | + 'validation' => true, |
|
| 1471 | + 'value' => $message_template_group->get('MTP_is_global'), |
|
| 1472 | + 'css_class' => '', |
|
| 1473 | + 'format' => '%d', |
|
| 1474 | + 'db-col' => 'MTP_is_global' |
|
| 1475 | + ); |
|
| 1476 | 1476 | |
| 1477 | - $sidebar_form_fields['ee-msg-is-override'] = array( |
|
| 1478 | - 'name' => 'MTP_is_override', |
|
| 1479 | - 'label' => __('Override all custom', 'event_espresso'), |
|
| 1480 | - 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden', |
|
| 1481 | - 'type' => 'int', |
|
| 1482 | - 'required' => false, |
|
| 1483 | - 'validation' => true, |
|
| 1484 | - 'value' => $message_template_group->get('MTP_is_override'), |
|
| 1485 | - 'css_class' => '', |
|
| 1486 | - 'format' => '%d', |
|
| 1487 | - 'db-col' => 'MTP_is_override' |
|
| 1488 | - ); |
|
| 1477 | + $sidebar_form_fields['ee-msg-is-override'] = array( |
|
| 1478 | + 'name' => 'MTP_is_override', |
|
| 1479 | + 'label' => __('Override all custom', 'event_espresso'), |
|
| 1480 | + 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden', |
|
| 1481 | + 'type' => 'int', |
|
| 1482 | + 'required' => false, |
|
| 1483 | + 'validation' => true, |
|
| 1484 | + 'value' => $message_template_group->get('MTP_is_override'), |
|
| 1485 | + 'css_class' => '', |
|
| 1486 | + 'format' => '%d', |
|
| 1487 | + 'db-col' => 'MTP_is_override' |
|
| 1488 | + ); |
|
| 1489 | 1489 | |
| 1490 | - $sidebar_form_fields['ee-msg-is-active'] = array( |
|
| 1491 | - 'name' => 'MTP_is_active', |
|
| 1492 | - 'label' => __('Active Template', 'event_espresso'), |
|
| 1493 | - 'input' => 'hidden', |
|
| 1494 | - 'type' => 'int', |
|
| 1495 | - 'required' => false, |
|
| 1496 | - 'validation' => true, |
|
| 1497 | - 'value' => $message_template_group->is_active(), |
|
| 1498 | - 'css_class' => '', |
|
| 1499 | - 'format' => '%d', |
|
| 1500 | - 'db-col' => 'MTP_is_active' |
|
| 1501 | - ); |
|
| 1490 | + $sidebar_form_fields['ee-msg-is-active'] = array( |
|
| 1491 | + 'name' => 'MTP_is_active', |
|
| 1492 | + 'label' => __('Active Template', 'event_espresso'), |
|
| 1493 | + 'input' => 'hidden', |
|
| 1494 | + 'type' => 'int', |
|
| 1495 | + 'required' => false, |
|
| 1496 | + 'validation' => true, |
|
| 1497 | + 'value' => $message_template_group->is_active(), |
|
| 1498 | + 'css_class' => '', |
|
| 1499 | + 'format' => '%d', |
|
| 1500 | + 'db-col' => 'MTP_is_active' |
|
| 1501 | + ); |
|
| 1502 | 1502 | |
| 1503 | - $sidebar_form_fields['ee-msg-deleted'] = array( |
|
| 1504 | - 'name' => 'MTP_deleted', |
|
| 1505 | - 'label' => null, |
|
| 1506 | - 'input' => 'hidden', |
|
| 1507 | - 'type' => 'int', |
|
| 1508 | - 'required' => false, |
|
| 1509 | - 'validation' => true, |
|
| 1510 | - 'value' => $message_template_group->get('MTP_deleted'), |
|
| 1511 | - 'css_class' => '', |
|
| 1512 | - 'format' => '%d', |
|
| 1513 | - 'db-col' => 'MTP_deleted' |
|
| 1514 | - ); |
|
| 1515 | - $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1516 | - 'name' => 'MTP_user_id', |
|
| 1517 | - 'label' => __('Author', 'event_espresso'), |
|
| 1518 | - 'input' => 'hidden', |
|
| 1519 | - 'type' => 'int', |
|
| 1520 | - 'required' => false, |
|
| 1521 | - 'validation' => false, |
|
| 1522 | - 'value' => $message_template_group->user(), |
|
| 1523 | - 'format' => '%d', |
|
| 1524 | - 'db-col' => 'MTP_user_id' |
|
| 1525 | - ); |
|
| 1503 | + $sidebar_form_fields['ee-msg-deleted'] = array( |
|
| 1504 | + 'name' => 'MTP_deleted', |
|
| 1505 | + 'label' => null, |
|
| 1506 | + 'input' => 'hidden', |
|
| 1507 | + 'type' => 'int', |
|
| 1508 | + 'required' => false, |
|
| 1509 | + 'validation' => true, |
|
| 1510 | + 'value' => $message_template_group->get('MTP_deleted'), |
|
| 1511 | + 'css_class' => '', |
|
| 1512 | + 'format' => '%d', |
|
| 1513 | + 'db-col' => 'MTP_deleted' |
|
| 1514 | + ); |
|
| 1515 | + $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1516 | + 'name' => 'MTP_user_id', |
|
| 1517 | + 'label' => __('Author', 'event_espresso'), |
|
| 1518 | + 'input' => 'hidden', |
|
| 1519 | + 'type' => 'int', |
|
| 1520 | + 'required' => false, |
|
| 1521 | + 'validation' => false, |
|
| 1522 | + 'value' => $message_template_group->user(), |
|
| 1523 | + 'format' => '%d', |
|
| 1524 | + 'db-col' => 'MTP_user_id' |
|
| 1525 | + ); |
|
| 1526 | 1526 | |
| 1527 | - $sidebar_form_fields['ee-msg-route'] = array( |
|
| 1528 | - 'name' => 'action', |
|
| 1529 | - 'input' => 'hidden', |
|
| 1530 | - 'type' => 'string', |
|
| 1531 | - 'value' => $action |
|
| 1532 | - ); |
|
| 1527 | + $sidebar_form_fields['ee-msg-route'] = array( |
|
| 1528 | + 'name' => 'action', |
|
| 1529 | + 'input' => 'hidden', |
|
| 1530 | + 'type' => 'string', |
|
| 1531 | + 'value' => $action |
|
| 1532 | + ); |
|
| 1533 | 1533 | |
| 1534 | - $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1535 | - 'name' => 'id', |
|
| 1536 | - 'input' => 'hidden', |
|
| 1537 | - 'type' => 'int', |
|
| 1538 | - 'value' => $GRP_ID |
|
| 1539 | - ); |
|
| 1540 | - $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
|
| 1541 | - 'name' => $action . '_nonce', |
|
| 1542 | - 'input' => 'hidden', |
|
| 1543 | - 'type' => 'string', |
|
| 1544 | - 'value' => wp_create_nonce($action . '_nonce') |
|
| 1545 | - ); |
|
| 1534 | + $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1535 | + 'name' => 'id', |
|
| 1536 | + 'input' => 'hidden', |
|
| 1537 | + 'type' => 'int', |
|
| 1538 | + 'value' => $GRP_ID |
|
| 1539 | + ); |
|
| 1540 | + $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
|
| 1541 | + 'name' => $action . '_nonce', |
|
| 1542 | + 'input' => 'hidden', |
|
| 1543 | + 'type' => 'string', |
|
| 1544 | + 'value' => wp_create_nonce($action . '_nonce') |
|
| 1545 | + ); |
|
| 1546 | 1546 | |
| 1547 | - if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
|
| 1548 | - $sidebar_form_fields['ee-msg-template-switch'] = array( |
|
| 1549 | - 'name' => 'template_switch', |
|
| 1550 | - 'input' => 'hidden', |
|
| 1551 | - 'type' => 'int', |
|
| 1552 | - 'value' => 1 |
|
| 1553 | - ); |
|
| 1554 | - } |
|
| 1547 | + if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
|
| 1548 | + $sidebar_form_fields['ee-msg-template-switch'] = array( |
|
| 1549 | + 'name' => 'template_switch', |
|
| 1550 | + 'input' => 'hidden', |
|
| 1551 | + 'type' => 'int', |
|
| 1552 | + 'value' => 1 |
|
| 1553 | + ); |
|
| 1554 | + } |
|
| 1555 | 1555 | |
| 1556 | 1556 | |
| 1557 | - $template_fields = $this->_generate_admin_form_fields($template_form_fields); |
|
| 1558 | - $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields); |
|
| 1557 | + $template_fields = $this->_generate_admin_form_fields($template_form_fields); |
|
| 1558 | + $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields); |
|
| 1559 | 1559 | |
| 1560 | 1560 | |
| 1561 | - } //end if ( !empty($template_field_structure) ) |
|
| 1561 | + } //end if ( !empty($template_field_structure) ) |
|
| 1562 | 1562 | |
| 1563 | - //set extra content for publish box |
|
| 1564 | - $this->_template_args['publish_box_extra_content'] = $sidebar_fields; |
|
| 1565 | - $this->_set_publish_post_box_vars( |
|
| 1566 | - 'id', |
|
| 1567 | - $GRP_ID, |
|
| 1568 | - false, |
|
| 1569 | - add_query_arg( |
|
| 1570 | - array('action' => 'global_mtps'), |
|
| 1571 | - $this->_admin_base_url |
|
| 1572 | - ) |
|
| 1573 | - ); |
|
| 1574 | - |
|
| 1575 | - //add preview button |
|
| 1576 | - $preview_url = parent::add_query_args_and_nonce( |
|
| 1577 | - array( |
|
| 1578 | - 'message_type' => $message_template_group->message_type(), |
|
| 1579 | - 'messenger' => $message_template_group->messenger(), |
|
| 1580 | - 'context' => $context, |
|
| 1581 | - 'GRP_ID' => $GRP_ID, |
|
| 1582 | - 'action' => 'preview_message' |
|
| 1583 | - ), |
|
| 1584 | - $this->_admin_base_url |
|
| 1585 | - ); |
|
| 1586 | - $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview', |
|
| 1587 | - 'event_espresso') . '</a>'; |
|
| 1588 | - |
|
| 1589 | - |
|
| 1590 | - //setup context switcher |
|
| 1591 | - $context_switcher_args = array( |
|
| 1592 | - 'page' => 'espresso_messages', |
|
| 1593 | - 'action' => 'edit_message_template', |
|
| 1594 | - 'id' => $GRP_ID, |
|
| 1595 | - 'context' => $context, |
|
| 1596 | - 'extra' => $preview_button |
|
| 1597 | - ); |
|
| 1598 | - $this->_set_context_switcher($message_template_group, $context_switcher_args); |
|
| 1599 | - |
|
| 1600 | - |
|
| 1601 | - //main box |
|
| 1602 | - $this->_template_args['template_fields'] = $template_fields; |
|
| 1603 | - $this->_template_args['sidebar_box_id'] = 'details'; |
|
| 1604 | - $this->_template_args['action'] = $action; |
|
| 1605 | - $this->_template_args['context'] = $context; |
|
| 1606 | - $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url; |
|
| 1607 | - $this->_template_args['learn_more_about_message_templates_link'] = $this->_learn_more_about_message_templates_link(); |
|
| 1608 | - |
|
| 1609 | - |
|
| 1610 | - $this->_template_args['before_admin_page_content'] = $this->add_context_switcher(); |
|
| 1611 | - $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before(); |
|
| 1612 | - $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after(); |
|
| 1613 | - |
|
| 1614 | - $this->_template_path = $this->_template_args['GRP_ID'] |
|
| 1615 | - ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
|
| 1616 | - : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1617 | - |
|
| 1618 | - //send along EE_Message_Template_Group object for further template use. |
|
| 1619 | - $this->_template_args['MTP'] = $message_template_group; |
|
| 1620 | - |
|
| 1621 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
| 1622 | - $this->_template_args, true); |
|
| 1623 | - |
|
| 1624 | - |
|
| 1625 | - //finally, let's set the admin_page title |
|
| 1626 | - $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title); |
|
| 1627 | - |
|
| 1628 | - |
|
| 1629 | - //we need to take care of setting the shortcodes property for use elsewhere. |
|
| 1630 | - $this->_set_shortcodes(); |
|
| 1631 | - |
|
| 1632 | - |
|
| 1633 | - //final template wrapper |
|
| 1634 | - $this->display_admin_page_with_sidebar(); |
|
| 1635 | - } |
|
| 1636 | - |
|
| 1637 | - |
|
| 1638 | - public function filter_tinymce_init($mceInit, $editor_id) |
|
| 1639 | - { |
|
| 1640 | - return $mceInit; |
|
| 1641 | - } |
|
| 1642 | - |
|
| 1643 | - |
|
| 1644 | - public function add_context_switcher() |
|
| 1645 | - { |
|
| 1646 | - return $this->_context_switcher; |
|
| 1647 | - } |
|
| 1648 | - |
|
| 1649 | - public function _add_form_element_before() |
|
| 1650 | - { |
|
| 1651 | - return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">'; |
|
| 1652 | - } |
|
| 1653 | - |
|
| 1654 | - public function _add_form_element_after() |
|
| 1655 | - { |
|
| 1656 | - return '</form>'; |
|
| 1657 | - } |
|
| 1658 | - |
|
| 1659 | - |
|
| 1660 | - /** |
|
| 1661 | - * This executes switching the template pack for a message template. |
|
| 1662 | - * |
|
| 1663 | - * @since 4.5.0 |
|
| 1664 | - * |
|
| 1665 | - */ |
|
| 1666 | - public function switch_template_pack() |
|
| 1667 | - { |
|
| 1668 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1669 | - $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : ''; |
|
| 1670 | - |
|
| 1671 | - //verify we have needed values. |
|
| 1672 | - if (empty($GRP_ID) || empty($template_pack)) { |
|
| 1673 | - $this->_template_args['error'] = true; |
|
| 1674 | - EE_Error::add_error(__('The required date for switching templates is not available.', 'event_espresso'), |
|
| 1675 | - __FILE__, __FUNCTION__, __LINE__); |
|
| 1676 | - } else { |
|
| 1677 | - //get template, set the new template_pack and then reset to default |
|
| 1678 | - /** @type EE_Message_Template_Group $message_template_group */ |
|
| 1679 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1563 | + //set extra content for publish box |
|
| 1564 | + $this->_template_args['publish_box_extra_content'] = $sidebar_fields; |
|
| 1565 | + $this->_set_publish_post_box_vars( |
|
| 1566 | + 'id', |
|
| 1567 | + $GRP_ID, |
|
| 1568 | + false, |
|
| 1569 | + add_query_arg( |
|
| 1570 | + array('action' => 'global_mtps'), |
|
| 1571 | + $this->_admin_base_url |
|
| 1572 | + ) |
|
| 1573 | + ); |
|
| 1574 | + |
|
| 1575 | + //add preview button |
|
| 1576 | + $preview_url = parent::add_query_args_and_nonce( |
|
| 1577 | + array( |
|
| 1578 | + 'message_type' => $message_template_group->message_type(), |
|
| 1579 | + 'messenger' => $message_template_group->messenger(), |
|
| 1580 | + 'context' => $context, |
|
| 1581 | + 'GRP_ID' => $GRP_ID, |
|
| 1582 | + 'action' => 'preview_message' |
|
| 1583 | + ), |
|
| 1584 | + $this->_admin_base_url |
|
| 1585 | + ); |
|
| 1586 | + $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview', |
|
| 1587 | + 'event_espresso') . '</a>'; |
|
| 1588 | + |
|
| 1589 | + |
|
| 1590 | + //setup context switcher |
|
| 1591 | + $context_switcher_args = array( |
|
| 1592 | + 'page' => 'espresso_messages', |
|
| 1593 | + 'action' => 'edit_message_template', |
|
| 1594 | + 'id' => $GRP_ID, |
|
| 1595 | + 'context' => $context, |
|
| 1596 | + 'extra' => $preview_button |
|
| 1597 | + ); |
|
| 1598 | + $this->_set_context_switcher($message_template_group, $context_switcher_args); |
|
| 1599 | + |
|
| 1600 | + |
|
| 1601 | + //main box |
|
| 1602 | + $this->_template_args['template_fields'] = $template_fields; |
|
| 1603 | + $this->_template_args['sidebar_box_id'] = 'details'; |
|
| 1604 | + $this->_template_args['action'] = $action; |
|
| 1605 | + $this->_template_args['context'] = $context; |
|
| 1606 | + $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url; |
|
| 1607 | + $this->_template_args['learn_more_about_message_templates_link'] = $this->_learn_more_about_message_templates_link(); |
|
| 1608 | + |
|
| 1609 | + |
|
| 1610 | + $this->_template_args['before_admin_page_content'] = $this->add_context_switcher(); |
|
| 1611 | + $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before(); |
|
| 1612 | + $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after(); |
|
| 1613 | + |
|
| 1614 | + $this->_template_path = $this->_template_args['GRP_ID'] |
|
| 1615 | + ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
|
| 1616 | + : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1617 | + |
|
| 1618 | + //send along EE_Message_Template_Group object for further template use. |
|
| 1619 | + $this->_template_args['MTP'] = $message_template_group; |
|
| 1620 | + |
|
| 1621 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
| 1622 | + $this->_template_args, true); |
|
| 1623 | + |
|
| 1624 | + |
|
| 1625 | + //finally, let's set the admin_page title |
|
| 1626 | + $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title); |
|
| 1627 | + |
|
| 1628 | + |
|
| 1629 | + //we need to take care of setting the shortcodes property for use elsewhere. |
|
| 1630 | + $this->_set_shortcodes(); |
|
| 1631 | + |
|
| 1632 | + |
|
| 1633 | + //final template wrapper |
|
| 1634 | + $this->display_admin_page_with_sidebar(); |
|
| 1635 | + } |
|
| 1636 | + |
|
| 1637 | + |
|
| 1638 | + public function filter_tinymce_init($mceInit, $editor_id) |
|
| 1639 | + { |
|
| 1640 | + return $mceInit; |
|
| 1641 | + } |
|
| 1642 | + |
|
| 1643 | + |
|
| 1644 | + public function add_context_switcher() |
|
| 1645 | + { |
|
| 1646 | + return $this->_context_switcher; |
|
| 1647 | + } |
|
| 1648 | + |
|
| 1649 | + public function _add_form_element_before() |
|
| 1650 | + { |
|
| 1651 | + return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">'; |
|
| 1652 | + } |
|
| 1653 | + |
|
| 1654 | + public function _add_form_element_after() |
|
| 1655 | + { |
|
| 1656 | + return '</form>'; |
|
| 1657 | + } |
|
| 1658 | + |
|
| 1659 | + |
|
| 1660 | + /** |
|
| 1661 | + * This executes switching the template pack for a message template. |
|
| 1662 | + * |
|
| 1663 | + * @since 4.5.0 |
|
| 1664 | + * |
|
| 1665 | + */ |
|
| 1666 | + public function switch_template_pack() |
|
| 1667 | + { |
|
| 1668 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1669 | + $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : ''; |
|
| 1670 | + |
|
| 1671 | + //verify we have needed values. |
|
| 1672 | + if (empty($GRP_ID) || empty($template_pack)) { |
|
| 1673 | + $this->_template_args['error'] = true; |
|
| 1674 | + EE_Error::add_error(__('The required date for switching templates is not available.', 'event_espresso'), |
|
| 1675 | + __FILE__, __FUNCTION__, __LINE__); |
|
| 1676 | + } else { |
|
| 1677 | + //get template, set the new template_pack and then reset to default |
|
| 1678 | + /** @type EE_Message_Template_Group $message_template_group */ |
|
| 1679 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1680 | 1680 | |
| 1681 | - $message_template_group->set_template_pack_name($template_pack); |
|
| 1682 | - $this->_req_data['msgr'] = $message_template_group->messenger(); |
|
| 1683 | - $this->_req_data['mt'] = $message_template_group->message_type(); |
|
| 1681 | + $message_template_group->set_template_pack_name($template_pack); |
|
| 1682 | + $this->_req_data['msgr'] = $message_template_group->messenger(); |
|
| 1683 | + $this->_req_data['mt'] = $message_template_group->message_type(); |
|
| 1684 | 1684 | |
| 1685 | - $query_args = $this->_reset_to_default_template(); |
|
| 1685 | + $query_args = $this->_reset_to_default_template(); |
|
| 1686 | 1686 | |
| 1687 | - if (empty($query_args['id'])) { |
|
| 1688 | - EE_Error::add_error( |
|
| 1689 | - __( |
|
| 1690 | - 'Something went wrong with switching the template pack. Please try again or contact EE support', |
|
| 1691 | - 'event_espresso' |
|
| 1692 | - ), |
|
| 1693 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1694 | - ); |
|
| 1695 | - $this->_template_args['error'] = true; |
|
| 1696 | - } else { |
|
| 1697 | - $template_label = $message_template_group->get_template_pack()->label; |
|
| 1698 | - $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1699 | - EE_Error::add_success( |
|
| 1700 | - sprintf( |
|
| 1701 | - __( |
|
| 1702 | - 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.', |
|
| 1703 | - 'event_espresso' |
|
| 1704 | - ), |
|
| 1705 | - $template_label, |
|
| 1706 | - $template_pack_labels->template_pack |
|
| 1707 | - ) |
|
| 1708 | - ); |
|
| 1709 | - //generate the redirect url for js. |
|
| 1710 | - $url = self::add_query_args_and_nonce($query_args, |
|
| 1711 | - $this->_admin_base_url); |
|
| 1712 | - $this->_template_args['data']['redirect_url'] = $url; |
|
| 1713 | - $this->_template_args['success'] = true; |
|
| 1714 | - } |
|
| 1687 | + if (empty($query_args['id'])) { |
|
| 1688 | + EE_Error::add_error( |
|
| 1689 | + __( |
|
| 1690 | + 'Something went wrong with switching the template pack. Please try again or contact EE support', |
|
| 1691 | + 'event_espresso' |
|
| 1692 | + ), |
|
| 1693 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1694 | + ); |
|
| 1695 | + $this->_template_args['error'] = true; |
|
| 1696 | + } else { |
|
| 1697 | + $template_label = $message_template_group->get_template_pack()->label; |
|
| 1698 | + $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1699 | + EE_Error::add_success( |
|
| 1700 | + sprintf( |
|
| 1701 | + __( |
|
| 1702 | + 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.', |
|
| 1703 | + 'event_espresso' |
|
| 1704 | + ), |
|
| 1705 | + $template_label, |
|
| 1706 | + $template_pack_labels->template_pack |
|
| 1707 | + ) |
|
| 1708 | + ); |
|
| 1709 | + //generate the redirect url for js. |
|
| 1710 | + $url = self::add_query_args_and_nonce($query_args, |
|
| 1711 | + $this->_admin_base_url); |
|
| 1712 | + $this->_template_args['data']['redirect_url'] = $url; |
|
| 1713 | + $this->_template_args['success'] = true; |
|
| 1714 | + } |
|
| 1715 | 1715 | |
| 1716 | - $this->_return_json(); |
|
| 1716 | + $this->_return_json(); |
|
| 1717 | 1717 | |
| 1718 | - } |
|
| 1719 | - } |
|
| 1720 | - |
|
| 1721 | - |
|
| 1722 | - /** |
|
| 1723 | - * This handles resetting the template for the given messenger/message_type so that users can start from scratch if |
|
| 1724 | - * they want. |
|
| 1725 | - * |
|
| 1726 | - * @access protected |
|
| 1727 | - * @return array|null |
|
| 1728 | - */ |
|
| 1729 | - protected function _reset_to_default_template() |
|
| 1730 | - { |
|
| 1731 | - |
|
| 1732 | - $templates = array(); |
|
| 1733 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1734 | - //we need to make sure we've got the info we need. |
|
| 1735 | - if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { |
|
| 1736 | - EE_Error::add_error( |
|
| 1737 | - __( |
|
| 1738 | - '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.', |
|
| 1739 | - 'event_espresso' |
|
| 1740 | - ), |
|
| 1741 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1742 | - ); |
|
| 1743 | - } |
|
| 1744 | - |
|
| 1745 | - // all templates will be reset to whatever the defaults are |
|
| 1746 | - // for the global template matching the messenger and message type. |
|
| 1747 | - $success = ! empty($GRP_ID) ? true : false; |
|
| 1748 | - |
|
| 1749 | - if ($success) { |
|
| 1718 | + } |
|
| 1719 | + } |
|
| 1720 | + |
|
| 1721 | + |
|
| 1722 | + /** |
|
| 1723 | + * This handles resetting the template for the given messenger/message_type so that users can start from scratch if |
|
| 1724 | + * they want. |
|
| 1725 | + * |
|
| 1726 | + * @access protected |
|
| 1727 | + * @return array|null |
|
| 1728 | + */ |
|
| 1729 | + protected function _reset_to_default_template() |
|
| 1730 | + { |
|
| 1731 | + |
|
| 1732 | + $templates = array(); |
|
| 1733 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1734 | + //we need to make sure we've got the info we need. |
|
| 1735 | + if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { |
|
| 1736 | + EE_Error::add_error( |
|
| 1737 | + __( |
|
| 1738 | + '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.', |
|
| 1739 | + 'event_espresso' |
|
| 1740 | + ), |
|
| 1741 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1742 | + ); |
|
| 1743 | + } |
|
| 1744 | + |
|
| 1745 | + // all templates will be reset to whatever the defaults are |
|
| 1746 | + // for the global template matching the messenger and message type. |
|
| 1747 | + $success = ! empty($GRP_ID) ? true : false; |
|
| 1748 | + |
|
| 1749 | + if ($success) { |
|
| 1750 | 1750 | |
| 1751 | - //let's first determine if the incoming template is a global template, |
|
| 1752 | - // if it isn't then we need to get the global template matching messenger and message type. |
|
| 1753 | - //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
|
| 1751 | + //let's first determine if the incoming template is a global template, |
|
| 1752 | + // if it isn't then we need to get the global template matching messenger and message type. |
|
| 1753 | + //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
|
| 1754 | 1754 | |
| 1755 | 1755 | |
| 1756 | - //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group. |
|
| 1757 | - $success = $this->_delete_mtp_permanently($GRP_ID, false); |
|
| 1756 | + //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group. |
|
| 1757 | + $success = $this->_delete_mtp_permanently($GRP_ID, false); |
|
| 1758 | 1758 | |
| 1759 | - if ($success) { |
|
| 1760 | - // if successfully deleted, lets generate the new ones. |
|
| 1761 | - // Note. We set GLOBAL to true, because resets on ANY template |
|
| 1762 | - // will use the related global template defaults for regeneration. |
|
| 1763 | - // This means that if a custom template is reset it resets to whatever the related global template is. |
|
| 1764 | - // HOWEVER, we DO keep the template pack and template variation set |
|
| 1765 | - // for the current custom template when resetting. |
|
| 1766 | - $templates = $this->_generate_new_templates( |
|
| 1767 | - $this->_req_data['msgr'], |
|
| 1768 | - $this->_req_data['mt'], |
|
| 1769 | - $GRP_ID, |
|
| 1770 | - true |
|
| 1771 | - ); |
|
| 1772 | - } |
|
| 1759 | + if ($success) { |
|
| 1760 | + // if successfully deleted, lets generate the new ones. |
|
| 1761 | + // Note. We set GLOBAL to true, because resets on ANY template |
|
| 1762 | + // will use the related global template defaults for regeneration. |
|
| 1763 | + // This means that if a custom template is reset it resets to whatever the related global template is. |
|
| 1764 | + // HOWEVER, we DO keep the template pack and template variation set |
|
| 1765 | + // for the current custom template when resetting. |
|
| 1766 | + $templates = $this->_generate_new_templates( |
|
| 1767 | + $this->_req_data['msgr'], |
|
| 1768 | + $this->_req_data['mt'], |
|
| 1769 | + $GRP_ID, |
|
| 1770 | + true |
|
| 1771 | + ); |
|
| 1772 | + } |
|
| 1773 | 1773 | |
| 1774 | - } |
|
| 1775 | - |
|
| 1776 | - //any error messages? |
|
| 1777 | - if ( ! $success) { |
|
| 1778 | - EE_Error::add_error( |
|
| 1779 | - __('Something went wrong with deleting existing templates. Unable to reset to default', |
|
| 1780 | - 'event_espresso'), |
|
| 1781 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1782 | - ); |
|
| 1783 | - } |
|
| 1784 | - |
|
| 1785 | - //all good, let's add a success message! |
|
| 1786 | - if ($success && ! empty($templates)) { |
|
| 1787 | - $templates = $templates[0]; //the info for the template we generated is the first element in the returned array. |
|
| 1788 | - EE_Error::overwrite_success(); |
|
| 1789 | - EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso')); |
|
| 1790 | - } |
|
| 1791 | - |
|
| 1792 | - |
|
| 1793 | - $query_args = array( |
|
| 1794 | - 'id' => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null, |
|
| 1795 | - 'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null, |
|
| 1796 | - 'action' => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps' |
|
| 1797 | - ); |
|
| 1798 | - |
|
| 1799 | - //if called via ajax then we return query args otherwise redirect |
|
| 1800 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 1801 | - return $query_args; |
|
| 1802 | - } else { |
|
| 1803 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1774 | + } |
|
| 1775 | + |
|
| 1776 | + //any error messages? |
|
| 1777 | + if ( ! $success) { |
|
| 1778 | + EE_Error::add_error( |
|
| 1779 | + __('Something went wrong with deleting existing templates. Unable to reset to default', |
|
| 1780 | + 'event_espresso'), |
|
| 1781 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1782 | + ); |
|
| 1783 | + } |
|
| 1784 | + |
|
| 1785 | + //all good, let's add a success message! |
|
| 1786 | + if ($success && ! empty($templates)) { |
|
| 1787 | + $templates = $templates[0]; //the info for the template we generated is the first element in the returned array. |
|
| 1788 | + EE_Error::overwrite_success(); |
|
| 1789 | + EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso')); |
|
| 1790 | + } |
|
| 1791 | + |
|
| 1792 | + |
|
| 1793 | + $query_args = array( |
|
| 1794 | + 'id' => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null, |
|
| 1795 | + 'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null, |
|
| 1796 | + 'action' => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps' |
|
| 1797 | + ); |
|
| 1798 | + |
|
| 1799 | + //if called via ajax then we return query args otherwise redirect |
|
| 1800 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 1801 | + return $query_args; |
|
| 1802 | + } else { |
|
| 1803 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1804 | 1804 | |
| 1805 | - return null; |
|
| 1806 | - } |
|
| 1807 | - } |
|
| 1808 | - |
|
| 1809 | - |
|
| 1810 | - /** |
|
| 1811 | - * Retrieve and set the message preview for display. |
|
| 1812 | - * |
|
| 1813 | - * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview. |
|
| 1814 | - * |
|
| 1815 | - * @return string |
|
| 1816 | - */ |
|
| 1817 | - public function _preview_message($send = false) |
|
| 1818 | - { |
|
| 1819 | - //first make sure we've got the necessary parameters |
|
| 1820 | - if ( |
|
| 1821 | - ! isset( |
|
| 1822 | - $this->_req_data['message_type'], |
|
| 1823 | - $this->_req_data['messenger'], |
|
| 1824 | - $this->_req_data['messenger'], |
|
| 1825 | - $this->_req_data['GRP_ID'] |
|
| 1826 | - ) |
|
| 1827 | - ) { |
|
| 1828 | - EE_Error::add_error( |
|
| 1829 | - __('Missing necessary parameters for displaying preview', 'event_espresso'), |
|
| 1830 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1831 | - ); |
|
| 1832 | - } |
|
| 1833 | - |
|
| 1834 | - EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']); |
|
| 1835 | - |
|
| 1836 | - |
|
| 1837 | - //get the preview! |
|
| 1838 | - $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'], |
|
| 1839 | - $this->_req_data['messenger'], $send); |
|
| 1840 | - |
|
| 1841 | - if ($send) { |
|
| 1842 | - return $preview; |
|
| 1843 | - } |
|
| 1844 | - |
|
| 1845 | - //let's add a button to go back to the edit view |
|
| 1846 | - $query_args = array( |
|
| 1847 | - 'id' => $this->_req_data['GRP_ID'], |
|
| 1848 | - 'context' => $this->_req_data['context'], |
|
| 1849 | - 'action' => 'edit_message_template' |
|
| 1850 | - ); |
|
| 1851 | - $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 1852 | - $preview_button = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit', |
|
| 1853 | - 'event_espresso') . '</a>'; |
|
| 1854 | - $message_types = $this->get_installed_message_types(); |
|
| 1855 | - $active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 1856 | - $active_messenger_label = $active_messenger instanceof EE_messenger |
|
| 1857 | - ? ucwords($active_messenger->label['singular']) |
|
| 1858 | - : esc_html__('Unknown Messenger', 'event_espresso'); |
|
| 1859 | - //let's provide a helpful title for context |
|
| 1860 | - $preview_title = sprintf( |
|
| 1861 | - __('Viewing Preview for %s %s Message Template', 'event_espresso'), |
|
| 1862 | - $active_messenger_label, |
|
| 1863 | - ucwords($message_types[$this->_req_data['message_type']]->label['singular']) |
|
| 1864 | - ); |
|
| 1865 | - //setup display of preview. |
|
| 1866 | - $this->_admin_page_title = $preview_title; |
|
| 1867 | - $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview); |
|
| 1868 | - $this->_template_args['data']['force_json'] = true; |
|
| 1869 | - |
|
| 1870 | - return ''; |
|
| 1871 | - } |
|
| 1872 | - |
|
| 1873 | - |
|
| 1874 | - /** |
|
| 1875 | - * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it |
|
| 1876 | - * gets called automatically. |
|
| 1877 | - * |
|
| 1878 | - * @since 4.5.0 |
|
| 1879 | - * |
|
| 1880 | - * @return string |
|
| 1881 | - */ |
|
| 1882 | - protected function _display_preview_message() |
|
| 1883 | - { |
|
| 1884 | - $this->display_admin_page_with_no_sidebar(); |
|
| 1885 | - } |
|
| 1886 | - |
|
| 1887 | - |
|
| 1888 | - /** |
|
| 1889 | - * registers metaboxes that should show up on the "edit_message_template" page |
|
| 1890 | - * |
|
| 1891 | - * @access protected |
|
| 1892 | - * @return void |
|
| 1893 | - */ |
|
| 1894 | - protected function _register_edit_meta_boxes() |
|
| 1895 | - { |
|
| 1896 | - add_meta_box('mtp_valid_shortcodes', __('Valid Shortcodes', 'event_espresso'), |
|
| 1897 | - array($this, 'shortcode_meta_box'), $this->_current_screen->id, 'side', 'default'); |
|
| 1898 | - add_meta_box('mtp_extra_actions', __('Extra Actions', 'event_espresso'), array($this, 'extra_actions_meta_box'), |
|
| 1899 | - $this->_current_screen->id, 'side', 'high'); |
|
| 1900 | - add_meta_box('mtp_templates', __('Template Styles', 'event_espresso'), array($this, 'template_pack_meta_box'), |
|
| 1901 | - $this->_current_screen->id, 'side', 'high'); |
|
| 1902 | - } |
|
| 1903 | - |
|
| 1904 | - |
|
| 1905 | - /** |
|
| 1906 | - * metabox content for all template pack and variation selection. |
|
| 1907 | - * |
|
| 1908 | - * @since 4.5.0 |
|
| 1909 | - * |
|
| 1910 | - * @return string |
|
| 1911 | - */ |
|
| 1912 | - public function template_pack_meta_box() |
|
| 1913 | - { |
|
| 1914 | - $this->_set_message_template_group(); |
|
| 1915 | - |
|
| 1916 | - $tp_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 1917 | - |
|
| 1918 | - $tp_select_values = array(); |
|
| 1919 | - |
|
| 1920 | - foreach ($tp_collection as $tp) { |
|
| 1921 | - //only include template packs that support this messenger and message type! |
|
| 1922 | - $supports = $tp->get_supports(); |
|
| 1923 | - if ( |
|
| 1924 | - ! isset($supports[$this->_message_template_group->messenger()]) |
|
| 1925 | - || ! in_array( |
|
| 1926 | - $this->_message_template_group->message_type(), |
|
| 1927 | - $supports[$this->_message_template_group->messenger()] |
|
| 1928 | - ) |
|
| 1929 | - ) { |
|
| 1930 | - //not supported |
|
| 1931 | - continue; |
|
| 1932 | - } |
|
| 1805 | + return null; |
|
| 1806 | + } |
|
| 1807 | + } |
|
| 1808 | + |
|
| 1809 | + |
|
| 1810 | + /** |
|
| 1811 | + * Retrieve and set the message preview for display. |
|
| 1812 | + * |
|
| 1813 | + * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview. |
|
| 1814 | + * |
|
| 1815 | + * @return string |
|
| 1816 | + */ |
|
| 1817 | + public function _preview_message($send = false) |
|
| 1818 | + { |
|
| 1819 | + //first make sure we've got the necessary parameters |
|
| 1820 | + if ( |
|
| 1821 | + ! isset( |
|
| 1822 | + $this->_req_data['message_type'], |
|
| 1823 | + $this->_req_data['messenger'], |
|
| 1824 | + $this->_req_data['messenger'], |
|
| 1825 | + $this->_req_data['GRP_ID'] |
|
| 1826 | + ) |
|
| 1827 | + ) { |
|
| 1828 | + EE_Error::add_error( |
|
| 1829 | + __('Missing necessary parameters for displaying preview', 'event_espresso'), |
|
| 1830 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1831 | + ); |
|
| 1832 | + } |
|
| 1833 | + |
|
| 1834 | + EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']); |
|
| 1835 | + |
|
| 1836 | + |
|
| 1837 | + //get the preview! |
|
| 1838 | + $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'], |
|
| 1839 | + $this->_req_data['messenger'], $send); |
|
| 1840 | + |
|
| 1841 | + if ($send) { |
|
| 1842 | + return $preview; |
|
| 1843 | + } |
|
| 1844 | + |
|
| 1845 | + //let's add a button to go back to the edit view |
|
| 1846 | + $query_args = array( |
|
| 1847 | + 'id' => $this->_req_data['GRP_ID'], |
|
| 1848 | + 'context' => $this->_req_data['context'], |
|
| 1849 | + 'action' => 'edit_message_template' |
|
| 1850 | + ); |
|
| 1851 | + $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 1852 | + $preview_button = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit', |
|
| 1853 | + 'event_espresso') . '</a>'; |
|
| 1854 | + $message_types = $this->get_installed_message_types(); |
|
| 1855 | + $active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 1856 | + $active_messenger_label = $active_messenger instanceof EE_messenger |
|
| 1857 | + ? ucwords($active_messenger->label['singular']) |
|
| 1858 | + : esc_html__('Unknown Messenger', 'event_espresso'); |
|
| 1859 | + //let's provide a helpful title for context |
|
| 1860 | + $preview_title = sprintf( |
|
| 1861 | + __('Viewing Preview for %s %s Message Template', 'event_espresso'), |
|
| 1862 | + $active_messenger_label, |
|
| 1863 | + ucwords($message_types[$this->_req_data['message_type']]->label['singular']) |
|
| 1864 | + ); |
|
| 1865 | + //setup display of preview. |
|
| 1866 | + $this->_admin_page_title = $preview_title; |
|
| 1867 | + $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview); |
|
| 1868 | + $this->_template_args['data']['force_json'] = true; |
|
| 1869 | + |
|
| 1870 | + return ''; |
|
| 1871 | + } |
|
| 1872 | + |
|
| 1873 | + |
|
| 1874 | + /** |
|
| 1875 | + * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it |
|
| 1876 | + * gets called automatically. |
|
| 1877 | + * |
|
| 1878 | + * @since 4.5.0 |
|
| 1879 | + * |
|
| 1880 | + * @return string |
|
| 1881 | + */ |
|
| 1882 | + protected function _display_preview_message() |
|
| 1883 | + { |
|
| 1884 | + $this->display_admin_page_with_no_sidebar(); |
|
| 1885 | + } |
|
| 1886 | + |
|
| 1887 | + |
|
| 1888 | + /** |
|
| 1889 | + * registers metaboxes that should show up on the "edit_message_template" page |
|
| 1890 | + * |
|
| 1891 | + * @access protected |
|
| 1892 | + * @return void |
|
| 1893 | + */ |
|
| 1894 | + protected function _register_edit_meta_boxes() |
|
| 1895 | + { |
|
| 1896 | + add_meta_box('mtp_valid_shortcodes', __('Valid Shortcodes', 'event_espresso'), |
|
| 1897 | + array($this, 'shortcode_meta_box'), $this->_current_screen->id, 'side', 'default'); |
|
| 1898 | + add_meta_box('mtp_extra_actions', __('Extra Actions', 'event_espresso'), array($this, 'extra_actions_meta_box'), |
|
| 1899 | + $this->_current_screen->id, 'side', 'high'); |
|
| 1900 | + add_meta_box('mtp_templates', __('Template Styles', 'event_espresso'), array($this, 'template_pack_meta_box'), |
|
| 1901 | + $this->_current_screen->id, 'side', 'high'); |
|
| 1902 | + } |
|
| 1903 | + |
|
| 1904 | + |
|
| 1905 | + /** |
|
| 1906 | + * metabox content for all template pack and variation selection. |
|
| 1907 | + * |
|
| 1908 | + * @since 4.5.0 |
|
| 1909 | + * |
|
| 1910 | + * @return string |
|
| 1911 | + */ |
|
| 1912 | + public function template_pack_meta_box() |
|
| 1913 | + { |
|
| 1914 | + $this->_set_message_template_group(); |
|
| 1915 | + |
|
| 1916 | + $tp_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 1917 | + |
|
| 1918 | + $tp_select_values = array(); |
|
| 1919 | + |
|
| 1920 | + foreach ($tp_collection as $tp) { |
|
| 1921 | + //only include template packs that support this messenger and message type! |
|
| 1922 | + $supports = $tp->get_supports(); |
|
| 1923 | + if ( |
|
| 1924 | + ! isset($supports[$this->_message_template_group->messenger()]) |
|
| 1925 | + || ! in_array( |
|
| 1926 | + $this->_message_template_group->message_type(), |
|
| 1927 | + $supports[$this->_message_template_group->messenger()] |
|
| 1928 | + ) |
|
| 1929 | + ) { |
|
| 1930 | + //not supported |
|
| 1931 | + continue; |
|
| 1932 | + } |
|
| 1933 | 1933 | |
| 1934 | - $tp_select_values[] = array( |
|
| 1935 | - 'text' => $tp->label, |
|
| 1936 | - 'id' => $tp->dbref |
|
| 1937 | - ); |
|
| 1938 | - } |
|
| 1939 | - |
|
| 1940 | - //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. |
|
| 1941 | - if (empty($tp_select_values)) { |
|
| 1942 | - $tp_select_values[] = array( |
|
| 1943 | - 'text' => __('Default', 'event_espresso'), |
|
| 1944 | - 'id' => 'default' |
|
| 1945 | - ); |
|
| 1946 | - } |
|
| 1947 | - |
|
| 1948 | - //setup variation select values for the currently selected template. |
|
| 1949 | - $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 1950 | - $this->_message_template_group->messenger(), |
|
| 1951 | - $this->_message_template_group->message_type() |
|
| 1952 | - ); |
|
| 1953 | - $variations_select_values = array(); |
|
| 1954 | - foreach ($variations as $variation => $label) { |
|
| 1955 | - $variations_select_values[] = array( |
|
| 1956 | - 'text' => $label, |
|
| 1957 | - 'id' => $variation |
|
| 1958 | - ); |
|
| 1959 | - } |
|
| 1960 | - |
|
| 1961 | - $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1962 | - |
|
| 1963 | - $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 1964 | - 'MTP_template_pack', |
|
| 1965 | - $tp_select_values, |
|
| 1966 | - $this->_message_template_group->get_template_pack_name() |
|
| 1967 | - ); |
|
| 1968 | - $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 1969 | - 'MTP_template_variation', |
|
| 1970 | - $variations_select_values, |
|
| 1971 | - $this->_message_template_group->get_template_pack_variation() |
|
| 1972 | - ); |
|
| 1973 | - $template_args['template_pack_label'] = $template_pack_labels->template_pack; |
|
| 1974 | - $template_args['template_variation_label'] = $template_pack_labels->template_variation; |
|
| 1975 | - $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
|
| 1976 | - $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
|
| 1977 | - |
|
| 1978 | - $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 1979 | - |
|
| 1980 | - EEH_Template::display_template($template, $template_args); |
|
| 1981 | - } |
|
| 1982 | - |
|
| 1983 | - |
|
| 1984 | - /** |
|
| 1985 | - * This meta box holds any extra actions related to Message Templates |
|
| 1986 | - * For now, this includes Resetting templates to defaults and sending a test email. |
|
| 1987 | - * |
|
| 1988 | - * @access public |
|
| 1989 | - * @return void |
|
| 1990 | - * @throws \EE_Error |
|
| 1991 | - */ |
|
| 1992 | - public function extra_actions_meta_box() |
|
| 1993 | - { |
|
| 1994 | - $template_form_fields = array(); |
|
| 1995 | - |
|
| 1996 | - $extra_args = array( |
|
| 1997 | - 'msgr' => $this->_message_template_group->messenger(), |
|
| 1998 | - 'mt' => $this->_message_template_group->message_type(), |
|
| 1999 | - 'GRP_ID' => $this->_message_template_group->GRP_ID() |
|
| 2000 | - ); |
|
| 2001 | - //first we need to see if there are any fields |
|
| 2002 | - $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields(); |
|
| 2003 | - |
|
| 2004 | - if ( ! empty($fields)) { |
|
| 2005 | - //yup there be fields |
|
| 2006 | - foreach ($fields as $field => $config) { |
|
| 2007 | - $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 2008 | - $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
|
| 2009 | - $default = isset($config['default']) ? $config['default'] : ''; |
|
| 2010 | - $default = isset($config['value']) ? $config['value'] : $default; |
|
| 1934 | + $tp_select_values[] = array( |
|
| 1935 | + 'text' => $tp->label, |
|
| 1936 | + 'id' => $tp->dbref |
|
| 1937 | + ); |
|
| 1938 | + } |
|
| 1939 | + |
|
| 1940 | + //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. |
|
| 1941 | + if (empty($tp_select_values)) { |
|
| 1942 | + $tp_select_values[] = array( |
|
| 1943 | + 'text' => __('Default', 'event_espresso'), |
|
| 1944 | + 'id' => 'default' |
|
| 1945 | + ); |
|
| 1946 | + } |
|
| 1947 | + |
|
| 1948 | + //setup variation select values for the currently selected template. |
|
| 1949 | + $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 1950 | + $this->_message_template_group->messenger(), |
|
| 1951 | + $this->_message_template_group->message_type() |
|
| 1952 | + ); |
|
| 1953 | + $variations_select_values = array(); |
|
| 1954 | + foreach ($variations as $variation => $label) { |
|
| 1955 | + $variations_select_values[] = array( |
|
| 1956 | + 'text' => $label, |
|
| 1957 | + 'id' => $variation |
|
| 1958 | + ); |
|
| 1959 | + } |
|
| 1960 | + |
|
| 1961 | + $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1962 | + |
|
| 1963 | + $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 1964 | + 'MTP_template_pack', |
|
| 1965 | + $tp_select_values, |
|
| 1966 | + $this->_message_template_group->get_template_pack_name() |
|
| 1967 | + ); |
|
| 1968 | + $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 1969 | + 'MTP_template_variation', |
|
| 1970 | + $variations_select_values, |
|
| 1971 | + $this->_message_template_group->get_template_pack_variation() |
|
| 1972 | + ); |
|
| 1973 | + $template_args['template_pack_label'] = $template_pack_labels->template_pack; |
|
| 1974 | + $template_args['template_variation_label'] = $template_pack_labels->template_variation; |
|
| 1975 | + $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
|
| 1976 | + $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
|
| 1977 | + |
|
| 1978 | + $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 1979 | + |
|
| 1980 | + EEH_Template::display_template($template, $template_args); |
|
| 1981 | + } |
|
| 1982 | + |
|
| 1983 | + |
|
| 1984 | + /** |
|
| 1985 | + * This meta box holds any extra actions related to Message Templates |
|
| 1986 | + * For now, this includes Resetting templates to defaults and sending a test email. |
|
| 1987 | + * |
|
| 1988 | + * @access public |
|
| 1989 | + * @return void |
|
| 1990 | + * @throws \EE_Error |
|
| 1991 | + */ |
|
| 1992 | + public function extra_actions_meta_box() |
|
| 1993 | + { |
|
| 1994 | + $template_form_fields = array(); |
|
| 1995 | + |
|
| 1996 | + $extra_args = array( |
|
| 1997 | + 'msgr' => $this->_message_template_group->messenger(), |
|
| 1998 | + 'mt' => $this->_message_template_group->message_type(), |
|
| 1999 | + 'GRP_ID' => $this->_message_template_group->GRP_ID() |
|
| 2000 | + ); |
|
| 2001 | + //first we need to see if there are any fields |
|
| 2002 | + $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields(); |
|
| 2003 | + |
|
| 2004 | + if ( ! empty($fields)) { |
|
| 2005 | + //yup there be fields |
|
| 2006 | + foreach ($fields as $field => $config) { |
|
| 2007 | + $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 2008 | + $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
|
| 2009 | + $default = isset($config['default']) ? $config['default'] : ''; |
|
| 2010 | + $default = isset($config['value']) ? $config['value'] : $default; |
|
| 2011 | 2011 | |
| 2012 | - // if type is hidden and the value is empty |
|
| 2013 | - // something may have gone wrong so let's correct with the defaults |
|
| 2014 | - $fix = $config['input'] === 'hidden' && isset($existing[$field]) && empty($existing[$field]) |
|
| 2015 | - ? $default |
|
| 2016 | - : ''; |
|
| 2017 | - $existing[$field] = isset($existing[$field]) && empty($fix) |
|
| 2018 | - ? $existing[$field] |
|
| 2019 | - : $fix; |
|
| 2012 | + // if type is hidden and the value is empty |
|
| 2013 | + // something may have gone wrong so let's correct with the defaults |
|
| 2014 | + $fix = $config['input'] === 'hidden' && isset($existing[$field]) && empty($existing[$field]) |
|
| 2015 | + ? $default |
|
| 2016 | + : ''; |
|
| 2017 | + $existing[$field] = isset($existing[$field]) && empty($fix) |
|
| 2018 | + ? $existing[$field] |
|
| 2019 | + : $fix; |
|
| 2020 | 2020 | |
| 2021 | - $template_form_fields[$field_id] = array( |
|
| 2022 | - 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2023 | - 'label' => $config['label'], |
|
| 2024 | - 'input' => $config['input'], |
|
| 2025 | - 'type' => $config['type'], |
|
| 2026 | - 'required' => $config['required'], |
|
| 2027 | - 'validation' => $config['validation'], |
|
| 2028 | - 'value' => isset($existing[$field]) ? $existing[$field] : $default, |
|
| 2029 | - 'css_class' => $config['css_class'], |
|
| 2030 | - 'options' => isset($config['options']) ? $config['options'] : array(), |
|
| 2031 | - 'default' => $default, |
|
| 2032 | - 'format' => $config['format'] |
|
| 2033 | - ); |
|
| 2034 | - } |
|
| 2035 | - } |
|
| 2036 | - |
|
| 2037 | - $test_settings_fields = ! empty($template_form_fields) |
|
| 2038 | - ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds') |
|
| 2039 | - : ''; |
|
| 2040 | - |
|
| 2041 | - $test_settings_html = ''; |
|
| 2042 | - //print out $test_settings_fields |
|
| 2043 | - if ( ! empty($test_settings_fields)) { |
|
| 2044 | - echo $test_settings_fields; |
|
| 2045 | - $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" '; |
|
| 2046 | - $test_settings_html .= 'name="test_button" value="'; |
|
| 2047 | - $test_settings_html .= __('Test Send', 'event_espresso'); |
|
| 2048 | - $test_settings_html .= '" /><div style="clear:both"></div>'; |
|
| 2049 | - } |
|
| 2050 | - |
|
| 2051 | - //and button |
|
| 2052 | - $test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>'; |
|
| 2053 | - $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; |
|
| 2054 | - $test_settings_html .= $this->get_action_link_or_button( |
|
| 2055 | - 'reset_to_default', |
|
| 2056 | - 'reset', |
|
| 2057 | - $extra_args, |
|
| 2058 | - 'button-primary reset-default-button' |
|
| 2059 | - ); |
|
| 2060 | - $test_settings_html .= '</div><div style="clear:both"></div>'; |
|
| 2061 | - echo $test_settings_html; |
|
| 2062 | - } |
|
| 2063 | - |
|
| 2064 | - |
|
| 2065 | - /** |
|
| 2066 | - * This returns the shortcode selector skeleton for a given context and field. |
|
| 2067 | - * |
|
| 2068 | - * @since 4.9.rc.000 |
|
| 2069 | - * |
|
| 2070 | - * @param string $field The name of the field retrieving shortcodes for. |
|
| 2071 | - * @param string $linked_input_id The css id of the input that the shortcodes get added to. |
|
| 2072 | - * |
|
| 2073 | - * @return string |
|
| 2074 | - */ |
|
| 2075 | - protected function _get_shortcode_selector($field, $linked_input_id) |
|
| 2076 | - { |
|
| 2077 | - $template_args = array( |
|
| 2078 | - 'shortcodes' => $this->_get_shortcodes(array($field), true), |
|
| 2079 | - 'fieldname' => $field, |
|
| 2080 | - 'linked_input_id' => $linked_input_id |
|
| 2081 | - ); |
|
| 2082 | - |
|
| 2083 | - return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2084 | - $template_args, true); |
|
| 2085 | - } |
|
| 2086 | - |
|
| 2087 | - |
|
| 2088 | - /** |
|
| 2089 | - * This just takes care of returning the meta box content for shortcodes (only used on the edit message template |
|
| 2090 | - * page) |
|
| 2091 | - * |
|
| 2092 | - * @access public |
|
| 2093 | - * @return void |
|
| 2094 | - */ |
|
| 2095 | - public function shortcode_meta_box() |
|
| 2096 | - { |
|
| 2097 | - $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set |
|
| 2098 | - //$messenger = $this->_message_template_group->messenger_obj(); |
|
| 2099 | - //now let's set the content depending on the status of the shortcodes array |
|
| 2100 | - if (empty($shortcodes)) { |
|
| 2101 | - $content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2102 | - echo $content; |
|
| 2103 | - } else { |
|
| 2104 | - //$alt = 0; |
|
| 2105 | - ?> |
|
| 2021 | + $template_form_fields[$field_id] = array( |
|
| 2022 | + 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2023 | + 'label' => $config['label'], |
|
| 2024 | + 'input' => $config['input'], |
|
| 2025 | + 'type' => $config['type'], |
|
| 2026 | + 'required' => $config['required'], |
|
| 2027 | + 'validation' => $config['validation'], |
|
| 2028 | + 'value' => isset($existing[$field]) ? $existing[$field] : $default, |
|
| 2029 | + 'css_class' => $config['css_class'], |
|
| 2030 | + 'options' => isset($config['options']) ? $config['options'] : array(), |
|
| 2031 | + 'default' => $default, |
|
| 2032 | + 'format' => $config['format'] |
|
| 2033 | + ); |
|
| 2034 | + } |
|
| 2035 | + } |
|
| 2036 | + |
|
| 2037 | + $test_settings_fields = ! empty($template_form_fields) |
|
| 2038 | + ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds') |
|
| 2039 | + : ''; |
|
| 2040 | + |
|
| 2041 | + $test_settings_html = ''; |
|
| 2042 | + //print out $test_settings_fields |
|
| 2043 | + if ( ! empty($test_settings_fields)) { |
|
| 2044 | + echo $test_settings_fields; |
|
| 2045 | + $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" '; |
|
| 2046 | + $test_settings_html .= 'name="test_button" value="'; |
|
| 2047 | + $test_settings_html .= __('Test Send', 'event_espresso'); |
|
| 2048 | + $test_settings_html .= '" /><div style="clear:both"></div>'; |
|
| 2049 | + } |
|
| 2050 | + |
|
| 2051 | + //and button |
|
| 2052 | + $test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>'; |
|
| 2053 | + $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; |
|
| 2054 | + $test_settings_html .= $this->get_action_link_or_button( |
|
| 2055 | + 'reset_to_default', |
|
| 2056 | + 'reset', |
|
| 2057 | + $extra_args, |
|
| 2058 | + 'button-primary reset-default-button' |
|
| 2059 | + ); |
|
| 2060 | + $test_settings_html .= '</div><div style="clear:both"></div>'; |
|
| 2061 | + echo $test_settings_html; |
|
| 2062 | + } |
|
| 2063 | + |
|
| 2064 | + |
|
| 2065 | + /** |
|
| 2066 | + * This returns the shortcode selector skeleton for a given context and field. |
|
| 2067 | + * |
|
| 2068 | + * @since 4.9.rc.000 |
|
| 2069 | + * |
|
| 2070 | + * @param string $field The name of the field retrieving shortcodes for. |
|
| 2071 | + * @param string $linked_input_id The css id of the input that the shortcodes get added to. |
|
| 2072 | + * |
|
| 2073 | + * @return string |
|
| 2074 | + */ |
|
| 2075 | + protected function _get_shortcode_selector($field, $linked_input_id) |
|
| 2076 | + { |
|
| 2077 | + $template_args = array( |
|
| 2078 | + 'shortcodes' => $this->_get_shortcodes(array($field), true), |
|
| 2079 | + 'fieldname' => $field, |
|
| 2080 | + 'linked_input_id' => $linked_input_id |
|
| 2081 | + ); |
|
| 2082 | + |
|
| 2083 | + return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2084 | + $template_args, true); |
|
| 2085 | + } |
|
| 2086 | + |
|
| 2087 | + |
|
| 2088 | + /** |
|
| 2089 | + * This just takes care of returning the meta box content for shortcodes (only used on the edit message template |
|
| 2090 | + * page) |
|
| 2091 | + * |
|
| 2092 | + * @access public |
|
| 2093 | + * @return void |
|
| 2094 | + */ |
|
| 2095 | + public function shortcode_meta_box() |
|
| 2096 | + { |
|
| 2097 | + $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set |
|
| 2098 | + //$messenger = $this->_message_template_group->messenger_obj(); |
|
| 2099 | + //now let's set the content depending on the status of the shortcodes array |
|
| 2100 | + if (empty($shortcodes)) { |
|
| 2101 | + $content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2102 | + echo $content; |
|
| 2103 | + } else { |
|
| 2104 | + //$alt = 0; |
|
| 2105 | + ?> |
|
| 2106 | 2106 | <div |
| 2107 | 2107 | style="float:right; margin-top:10px"><?php echo $this->_get_help_tab_link('message_template_shortcodes'); ?></div> |
| 2108 | 2108 | <p class="small-text"><?php printf(__('You can view the shortcodes usable in your template by clicking the %s icon next to each field.', |
| 2109 | - 'event_espresso'), '<span class="dashicons dashicons-menu"></span>'); ?></p> |
|
| 2109 | + 'event_espresso'), '<span class="dashicons dashicons-menu"></span>'); ?></p> |
|
| 2110 | 2110 | <?php |
| 2111 | - } |
|
| 2112 | - |
|
| 2113 | - |
|
| 2114 | - } |
|
| 2115 | - |
|
| 2116 | - |
|
| 2117 | - /** |
|
| 2118 | - * used to set the $_shortcodes property for when its needed elsewhere. |
|
| 2119 | - * |
|
| 2120 | - * @access protected |
|
| 2121 | - * @return void |
|
| 2122 | - */ |
|
| 2123 | - protected function _set_shortcodes() |
|
| 2124 | - { |
|
| 2125 | - |
|
| 2126 | - //no need to run this if the property is already set |
|
| 2127 | - if ( ! empty($this->_shortcodes)) { |
|
| 2128 | - return; |
|
| 2129 | - } |
|
| 2130 | - |
|
| 2131 | - $this->_shortcodes = $this->_get_shortcodes(); |
|
| 2132 | - } |
|
| 2133 | - |
|
| 2134 | - |
|
| 2135 | - /** |
|
| 2136 | - * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes |
|
| 2137 | - * property) |
|
| 2138 | - * |
|
| 2139 | - * @access protected |
|
| 2140 | - * |
|
| 2141 | - * @param array $fields include an array of specific field names that you want to be used to get the shortcodes |
|
| 2142 | - * for. Defaults to all (for the given context) |
|
| 2143 | - * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes |
|
| 2144 | - * |
|
| 2145 | - * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is |
|
| 2146 | - * true just an array of shortcode/label pairs. |
|
| 2147 | - */ |
|
| 2148 | - protected function _get_shortcodes($fields = array(), $merged = true) |
|
| 2149 | - { |
|
| 2150 | - $this->_set_message_template_group(); |
|
| 2151 | - |
|
| 2152 | - //we need the messenger and message template to retrieve the valid shortcodes array. |
|
| 2153 | - $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) : false; |
|
| 2154 | - $context = isset($this->_req_data['context']) ? $this->_req_data['context'] : key($this->_message_template_group->contexts_config()); |
|
| 2155 | - |
|
| 2156 | - return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array(); |
|
| 2157 | - } |
|
| 2158 | - |
|
| 2159 | - |
|
| 2160 | - /** |
|
| 2161 | - * This sets the _message_template property (containing the called message_template object) |
|
| 2162 | - * |
|
| 2163 | - * @access protected |
|
| 2164 | - * @return void |
|
| 2165 | - */ |
|
| 2166 | - protected function _set_message_template_group() |
|
| 2167 | - { |
|
| 2168 | - |
|
| 2169 | - if ( ! empty($this->_message_template_group)) { |
|
| 2170 | - return; |
|
| 2171 | - } //get out if this is already set. |
|
| 2172 | - |
|
| 2173 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false; |
|
| 2174 | - $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID; |
|
| 2175 | - |
|
| 2176 | - //let's get the message templates |
|
| 2177 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 2178 | - |
|
| 2179 | - if (empty($GRP_ID)) { |
|
| 2180 | - $this->_message_template_group = $MTP->create_default_object(); |
|
| 2181 | - } else { |
|
| 2182 | - $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID); |
|
| 2183 | - } |
|
| 2184 | - |
|
| 2185 | - $this->_template_pack = $this->_message_template_group->get_template_pack(); |
|
| 2186 | - $this->_variation = $this->_message_template_group->get_template_pack_variation(); |
|
| 2187 | - |
|
| 2188 | - } |
|
| 2189 | - |
|
| 2190 | - |
|
| 2191 | - /** |
|
| 2192 | - * sets up a context switcher for edit forms |
|
| 2193 | - * |
|
| 2194 | - * @access protected |
|
| 2195 | - * |
|
| 2196 | - * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form |
|
| 2197 | - * @param array $args various things the context switcher needs. |
|
| 2198 | - * |
|
| 2199 | - */ |
|
| 2200 | - protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args) |
|
| 2201 | - { |
|
| 2202 | - $context_details = $template_group_object->contexts_config(); |
|
| 2203 | - $context_label = $template_group_object->context_label(); |
|
| 2204 | - ob_start(); |
|
| 2205 | - ?> |
|
| 2111 | + } |
|
| 2112 | + |
|
| 2113 | + |
|
| 2114 | + } |
|
| 2115 | + |
|
| 2116 | + |
|
| 2117 | + /** |
|
| 2118 | + * used to set the $_shortcodes property for when its needed elsewhere. |
|
| 2119 | + * |
|
| 2120 | + * @access protected |
|
| 2121 | + * @return void |
|
| 2122 | + */ |
|
| 2123 | + protected function _set_shortcodes() |
|
| 2124 | + { |
|
| 2125 | + |
|
| 2126 | + //no need to run this if the property is already set |
|
| 2127 | + if ( ! empty($this->_shortcodes)) { |
|
| 2128 | + return; |
|
| 2129 | + } |
|
| 2130 | + |
|
| 2131 | + $this->_shortcodes = $this->_get_shortcodes(); |
|
| 2132 | + } |
|
| 2133 | + |
|
| 2134 | + |
|
| 2135 | + /** |
|
| 2136 | + * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes |
|
| 2137 | + * property) |
|
| 2138 | + * |
|
| 2139 | + * @access protected |
|
| 2140 | + * |
|
| 2141 | + * @param array $fields include an array of specific field names that you want to be used to get the shortcodes |
|
| 2142 | + * for. Defaults to all (for the given context) |
|
| 2143 | + * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes |
|
| 2144 | + * |
|
| 2145 | + * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is |
|
| 2146 | + * true just an array of shortcode/label pairs. |
|
| 2147 | + */ |
|
| 2148 | + protected function _get_shortcodes($fields = array(), $merged = true) |
|
| 2149 | + { |
|
| 2150 | + $this->_set_message_template_group(); |
|
| 2151 | + |
|
| 2152 | + //we need the messenger and message template to retrieve the valid shortcodes array. |
|
| 2153 | + $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) : false; |
|
| 2154 | + $context = isset($this->_req_data['context']) ? $this->_req_data['context'] : key($this->_message_template_group->contexts_config()); |
|
| 2155 | + |
|
| 2156 | + return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array(); |
|
| 2157 | + } |
|
| 2158 | + |
|
| 2159 | + |
|
| 2160 | + /** |
|
| 2161 | + * This sets the _message_template property (containing the called message_template object) |
|
| 2162 | + * |
|
| 2163 | + * @access protected |
|
| 2164 | + * @return void |
|
| 2165 | + */ |
|
| 2166 | + protected function _set_message_template_group() |
|
| 2167 | + { |
|
| 2168 | + |
|
| 2169 | + if ( ! empty($this->_message_template_group)) { |
|
| 2170 | + return; |
|
| 2171 | + } //get out if this is already set. |
|
| 2172 | + |
|
| 2173 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false; |
|
| 2174 | + $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID; |
|
| 2175 | + |
|
| 2176 | + //let's get the message templates |
|
| 2177 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 2178 | + |
|
| 2179 | + if (empty($GRP_ID)) { |
|
| 2180 | + $this->_message_template_group = $MTP->create_default_object(); |
|
| 2181 | + } else { |
|
| 2182 | + $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID); |
|
| 2183 | + } |
|
| 2184 | + |
|
| 2185 | + $this->_template_pack = $this->_message_template_group->get_template_pack(); |
|
| 2186 | + $this->_variation = $this->_message_template_group->get_template_pack_variation(); |
|
| 2187 | + |
|
| 2188 | + } |
|
| 2189 | + |
|
| 2190 | + |
|
| 2191 | + /** |
|
| 2192 | + * sets up a context switcher for edit forms |
|
| 2193 | + * |
|
| 2194 | + * @access protected |
|
| 2195 | + * |
|
| 2196 | + * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form |
|
| 2197 | + * @param array $args various things the context switcher needs. |
|
| 2198 | + * |
|
| 2199 | + */ |
|
| 2200 | + protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args) |
|
| 2201 | + { |
|
| 2202 | + $context_details = $template_group_object->contexts_config(); |
|
| 2203 | + $context_label = $template_group_object->context_label(); |
|
| 2204 | + ob_start(); |
|
| 2205 | + ?> |
|
| 2206 | 2206 | <div class="ee-msg-switcher-container"> |
| 2207 | 2207 | <form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm"> |
| 2208 | 2208 | <?php |
| 2209 | - foreach ($args as $name => $value) { |
|
| 2210 | - if ($name == 'context' || empty($value) || $name == 'extra') { |
|
| 2211 | - continue; |
|
| 2212 | - } |
|
| 2213 | - ?> |
|
| 2209 | + foreach ($args as $name => $value) { |
|
| 2210 | + if ($name == 'context' || empty($value) || $name == 'extra') { |
|
| 2211 | + continue; |
|
| 2212 | + } |
|
| 2213 | + ?> |
|
| 2214 | 2214 | <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/> |
| 2215 | 2215 | <?php |
| 2216 | - } |
|
| 2217 | - //setup nonce_url |
|
| 2218 | - wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2219 | - ?> |
|
| 2216 | + } |
|
| 2217 | + //setup nonce_url |
|
| 2218 | + wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2219 | + ?> |
|
| 2220 | 2220 | <select name="context"> |
| 2221 | 2221 | <?php |
| 2222 | - $context_templates = $template_group_object->context_templates(); |
|
| 2223 | - if (is_array($context_templates)) : |
|
| 2224 | - foreach ($context_templates as $context => $template_fields) : |
|
| 2225 | - $checked = ($context == $args['context']) ? 'selected="selected"' : ''; |
|
| 2226 | - ?> |
|
| 2222 | + $context_templates = $template_group_object->context_templates(); |
|
| 2223 | + if (is_array($context_templates)) : |
|
| 2224 | + foreach ($context_templates as $context => $template_fields) : |
|
| 2225 | + $checked = ($context == $args['context']) ? 'selected="selected"' : ''; |
|
| 2226 | + ?> |
|
| 2227 | 2227 | <option value="<?php echo $context; ?>" <?php echo $checked; ?>> |
| 2228 | 2228 | <?php echo $context_details[$context]['label']; ?> |
| 2229 | 2229 | </option> |
@@ -2236,1560 +2236,1560 @@ discard block |
||
| 2236 | 2236 | <?php echo $args['extra']; ?> |
| 2237 | 2237 | </div> <!-- end .ee-msg-switcher-container --> |
| 2238 | 2238 | <?php |
| 2239 | - $output = ob_get_contents(); |
|
| 2240 | - ob_clean(); |
|
| 2241 | - $this->_context_switcher = $output; |
|
| 2242 | - } |
|
| 2243 | - |
|
| 2244 | - |
|
| 2245 | - /** |
|
| 2246 | - * utility for sanitizing new values coming in. |
|
| 2247 | - * Note: this is only used when updating a context. |
|
| 2248 | - * |
|
| 2249 | - * @access protected |
|
| 2250 | - * |
|
| 2251 | - * @param int $index This helps us know which template field to select from the request array. |
|
| 2252 | - * |
|
| 2253 | - * @return array |
|
| 2254 | - */ |
|
| 2255 | - protected function _set_message_template_column_values($index) |
|
| 2256 | - { |
|
| 2257 | - if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) { |
|
| 2258 | - foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) { |
|
| 2259 | - $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value; |
|
| 2260 | - } |
|
| 2261 | - } /*else { |
|
| 2239 | + $output = ob_get_contents(); |
|
| 2240 | + ob_clean(); |
|
| 2241 | + $this->_context_switcher = $output; |
|
| 2242 | + } |
|
| 2243 | + |
|
| 2244 | + |
|
| 2245 | + /** |
|
| 2246 | + * utility for sanitizing new values coming in. |
|
| 2247 | + * Note: this is only used when updating a context. |
|
| 2248 | + * |
|
| 2249 | + * @access protected |
|
| 2250 | + * |
|
| 2251 | + * @param int $index This helps us know which template field to select from the request array. |
|
| 2252 | + * |
|
| 2253 | + * @return array |
|
| 2254 | + */ |
|
| 2255 | + protected function _set_message_template_column_values($index) |
|
| 2256 | + { |
|
| 2257 | + if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) { |
|
| 2258 | + foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) { |
|
| 2259 | + $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value; |
|
| 2260 | + } |
|
| 2261 | + } /*else { |
|
| 2262 | 2262 | $this->_req_data['MTP_template_fields'][$index]['content'] = $this->_req_data['MTP_template_fields'][$index]['content']; |
| 2263 | 2263 | }*/ |
| 2264 | 2264 | |
| 2265 | 2265 | |
| 2266 | - $set_column_values = array( |
|
| 2267 | - 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']), |
|
| 2268 | - 'GRP_ID' => absint($this->_req_data['GRP_ID']), |
|
| 2269 | - 'MTP_user_id' => absint($this->_req_data['MTP_user_id']), |
|
| 2270 | - 'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']), |
|
| 2271 | - 'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']), |
|
| 2272 | - 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']), |
|
| 2273 | - 'MTP_context' => strtolower($this->_req_data['MTP_context']), |
|
| 2274 | - 'MTP_content' => $this->_req_data['MTP_template_fields'][$index]['content'], |
|
| 2275 | - 'MTP_is_global' => isset($this->_req_data['MTP_is_global']) |
|
| 2276 | - ? absint($this->_req_data['MTP_is_global']) |
|
| 2277 | - : 0, |
|
| 2278 | - 'MTP_is_override' => isset($this->_req_data['MTP_is_override']) |
|
| 2279 | - ? absint($this->_req_data['MTP_is_override']) |
|
| 2280 | - : 0, |
|
| 2281 | - 'MTP_deleted' => absint($this->_req_data['MTP_deleted']), |
|
| 2282 | - 'MTP_is_active' => absint($this->_req_data['MTP_is_active']) |
|
| 2283 | - ); |
|
| 2284 | - |
|
| 2285 | - |
|
| 2286 | - return $set_column_values; |
|
| 2287 | - } |
|
| 2288 | - |
|
| 2289 | - |
|
| 2290 | - protected function _insert_or_update_message_template($new = false) |
|
| 2291 | - { |
|
| 2292 | - |
|
| 2293 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2294 | - $success = 0; |
|
| 2295 | - $override = false; |
|
| 2296 | - |
|
| 2297 | - //setup notices description |
|
| 2298 | - $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : ''; |
|
| 2299 | - |
|
| 2300 | - //need the message type and messenger objects to be able to use the labels for the notices |
|
| 2301 | - $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug); |
|
| 2302 | - $messenger_label = $messenger_object instanceof EE_messenger ? ucwords($messenger_object->label['singular']) : ''; |
|
| 2303 | - |
|
| 2304 | - $message_type_slug = ! empty($this->_req_data['MTP_message_type']) ? $this->_req_data['MTP_message_type'] : ''; |
|
| 2305 | - $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug); |
|
| 2306 | - |
|
| 2307 | - $message_type_label = $message_type_object instanceof EE_message_type |
|
| 2308 | - ? ucwords($message_type_object->label['singular']) |
|
| 2309 | - : ''; |
|
| 2310 | - |
|
| 2311 | - $context_slug = ! empty($this->_req_data['MTP_context']) |
|
| 2312 | - ? $this->_req_data['MTP_context'] |
|
| 2313 | - : ''; |
|
| 2314 | - $context = ucwords(str_replace('_', ' ', $context_slug)); |
|
| 2315 | - |
|
| 2316 | - $item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : ''; |
|
| 2317 | - $item_desc .= 'Message Template'; |
|
| 2318 | - $query_args = array(); |
|
| 2319 | - $edit_array = array(); |
|
| 2320 | - $action_desc = ''; |
|
| 2321 | - |
|
| 2322 | - //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for user to edit. |
|
| 2323 | - if ($new) { |
|
| 2324 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2325 | - if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) { |
|
| 2326 | - if (empty($edit_array)) { |
|
| 2327 | - $success = 0; |
|
| 2328 | - } else { |
|
| 2329 | - $success = 1; |
|
| 2330 | - $edit_array = $edit_array[0]; |
|
| 2331 | - $query_args = array( |
|
| 2332 | - 'id' => $edit_array['GRP_ID'], |
|
| 2333 | - 'context' => $edit_array['MTP_context'], |
|
| 2334 | - 'action' => 'edit_message_template' |
|
| 2335 | - ); |
|
| 2336 | - } |
|
| 2337 | - } |
|
| 2338 | - $action_desc = 'created'; |
|
| 2339 | - } else { |
|
| 2340 | - $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2341 | - $MTP = EEM_Message_Template::instance(); |
|
| 2266 | + $set_column_values = array( |
|
| 2267 | + 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']), |
|
| 2268 | + 'GRP_ID' => absint($this->_req_data['GRP_ID']), |
|
| 2269 | + 'MTP_user_id' => absint($this->_req_data['MTP_user_id']), |
|
| 2270 | + 'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']), |
|
| 2271 | + 'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']), |
|
| 2272 | + 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']), |
|
| 2273 | + 'MTP_context' => strtolower($this->_req_data['MTP_context']), |
|
| 2274 | + 'MTP_content' => $this->_req_data['MTP_template_fields'][$index]['content'], |
|
| 2275 | + 'MTP_is_global' => isset($this->_req_data['MTP_is_global']) |
|
| 2276 | + ? absint($this->_req_data['MTP_is_global']) |
|
| 2277 | + : 0, |
|
| 2278 | + 'MTP_is_override' => isset($this->_req_data['MTP_is_override']) |
|
| 2279 | + ? absint($this->_req_data['MTP_is_override']) |
|
| 2280 | + : 0, |
|
| 2281 | + 'MTP_deleted' => absint($this->_req_data['MTP_deleted']), |
|
| 2282 | + 'MTP_is_active' => absint($this->_req_data['MTP_is_active']) |
|
| 2283 | + ); |
|
| 2284 | + |
|
| 2285 | + |
|
| 2286 | + return $set_column_values; |
|
| 2287 | + } |
|
| 2288 | + |
|
| 2289 | + |
|
| 2290 | + protected function _insert_or_update_message_template($new = false) |
|
| 2291 | + { |
|
| 2292 | + |
|
| 2293 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2294 | + $success = 0; |
|
| 2295 | + $override = false; |
|
| 2296 | + |
|
| 2297 | + //setup notices description |
|
| 2298 | + $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : ''; |
|
| 2299 | + |
|
| 2300 | + //need the message type and messenger objects to be able to use the labels for the notices |
|
| 2301 | + $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug); |
|
| 2302 | + $messenger_label = $messenger_object instanceof EE_messenger ? ucwords($messenger_object->label['singular']) : ''; |
|
| 2303 | + |
|
| 2304 | + $message_type_slug = ! empty($this->_req_data['MTP_message_type']) ? $this->_req_data['MTP_message_type'] : ''; |
|
| 2305 | + $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug); |
|
| 2306 | + |
|
| 2307 | + $message_type_label = $message_type_object instanceof EE_message_type |
|
| 2308 | + ? ucwords($message_type_object->label['singular']) |
|
| 2309 | + : ''; |
|
| 2310 | + |
|
| 2311 | + $context_slug = ! empty($this->_req_data['MTP_context']) |
|
| 2312 | + ? $this->_req_data['MTP_context'] |
|
| 2313 | + : ''; |
|
| 2314 | + $context = ucwords(str_replace('_', ' ', $context_slug)); |
|
| 2315 | + |
|
| 2316 | + $item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : ''; |
|
| 2317 | + $item_desc .= 'Message Template'; |
|
| 2318 | + $query_args = array(); |
|
| 2319 | + $edit_array = array(); |
|
| 2320 | + $action_desc = ''; |
|
| 2321 | + |
|
| 2322 | + //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for user to edit. |
|
| 2323 | + if ($new) { |
|
| 2324 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2325 | + if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) { |
|
| 2326 | + if (empty($edit_array)) { |
|
| 2327 | + $success = 0; |
|
| 2328 | + } else { |
|
| 2329 | + $success = 1; |
|
| 2330 | + $edit_array = $edit_array[0]; |
|
| 2331 | + $query_args = array( |
|
| 2332 | + 'id' => $edit_array['GRP_ID'], |
|
| 2333 | + 'context' => $edit_array['MTP_context'], |
|
| 2334 | + 'action' => 'edit_message_template' |
|
| 2335 | + ); |
|
| 2336 | + } |
|
| 2337 | + } |
|
| 2338 | + $action_desc = 'created'; |
|
| 2339 | + } else { |
|
| 2340 | + $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2341 | + $MTP = EEM_Message_Template::instance(); |
|
| 2342 | 2342 | |
| 2343 | 2343 | |
| 2344 | - //run update for each template field in displayed context |
|
| 2345 | - if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { |
|
| 2346 | - EE_Error::add_error( |
|
| 2347 | - __('There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', |
|
| 2348 | - 'event_espresso'), |
|
| 2349 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2350 | - ); |
|
| 2351 | - $success = 0; |
|
| 2344 | + //run update for each template field in displayed context |
|
| 2345 | + if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { |
|
| 2346 | + EE_Error::add_error( |
|
| 2347 | + __('There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', |
|
| 2348 | + 'event_espresso'), |
|
| 2349 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2350 | + ); |
|
| 2351 | + $success = 0; |
|
| 2352 | 2352 | |
| 2353 | - } else { |
|
| 2354 | - //first validate all fields! |
|
| 2355 | - $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug, |
|
| 2356 | - $message_type_slug); |
|
| 2353 | + } else { |
|
| 2354 | + //first validate all fields! |
|
| 2355 | + $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug, |
|
| 2356 | + $message_type_slug); |
|
| 2357 | 2357 | |
| 2358 | - //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. |
|
| 2359 | - if (is_array($validates) && ! empty($validates)) { |
|
| 2360 | - //add the transient so when the form loads we know which fields to highlight |
|
| 2361 | - $this->_add_transient('edit_message_template', $validates); |
|
| 2358 | + //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. |
|
| 2359 | + if (is_array($validates) && ! empty($validates)) { |
|
| 2360 | + //add the transient so when the form loads we know which fields to highlight |
|
| 2361 | + $this->_add_transient('edit_message_template', $validates); |
|
| 2362 | 2362 | |
| 2363 | - $success = 0; |
|
| 2363 | + $success = 0; |
|
| 2364 | 2364 | |
| 2365 | - //setup notices |
|
| 2366 | - foreach ($validates as $field => $error) { |
|
| 2367 | - if (isset($error['msg'])) { |
|
| 2368 | - EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__); |
|
| 2369 | - } |
|
| 2370 | - } |
|
| 2365 | + //setup notices |
|
| 2366 | + foreach ($validates as $field => $error) { |
|
| 2367 | + if (isset($error['msg'])) { |
|
| 2368 | + EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__); |
|
| 2369 | + } |
|
| 2370 | + } |
|
| 2371 | 2371 | |
| 2372 | - } else { |
|
| 2373 | - $set_column_values = array(); |
|
| 2374 | - foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) { |
|
| 2375 | - $set_column_values = $this->_set_message_template_column_values($template_field); |
|
| 2372 | + } else { |
|
| 2373 | + $set_column_values = array(); |
|
| 2374 | + foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) { |
|
| 2375 | + $set_column_values = $this->_set_message_template_column_values($template_field); |
|
| 2376 | 2376 | |
| 2377 | - $where_cols_n_values = array( |
|
| 2378 | - 'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'] |
|
| 2379 | - ); |
|
| 2377 | + $where_cols_n_values = array( |
|
| 2378 | + 'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'] |
|
| 2379 | + ); |
|
| 2380 | 2380 | |
| 2381 | - $message_template_fields = array( |
|
| 2382 | - 'GRP_ID' => $set_column_values['GRP_ID'], |
|
| 2383 | - 'MTP_template_field' => $set_column_values['MTP_template_field'], |
|
| 2384 | - 'MTP_context' => $set_column_values['MTP_context'], |
|
| 2385 | - 'MTP_content' => $set_column_values['MTP_content'] |
|
| 2386 | - ); |
|
| 2387 | - if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) { |
|
| 2388 | - if ($updated === false) { |
|
| 2389 | - EE_Error::add_error( |
|
| 2390 | - sprintf( |
|
| 2391 | - __('%s field was NOT updated for some reason', 'event_espresso'), |
|
| 2392 | - $template_field |
|
| 2393 | - ), |
|
| 2394 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2395 | - ); |
|
| 2396 | - } else { |
|
| 2397 | - $success = 1; |
|
| 2398 | - } |
|
| 2399 | - } |
|
| 2400 | - $action_desc = 'updated'; |
|
| 2401 | - } |
|
| 2381 | + $message_template_fields = array( |
|
| 2382 | + 'GRP_ID' => $set_column_values['GRP_ID'], |
|
| 2383 | + 'MTP_template_field' => $set_column_values['MTP_template_field'], |
|
| 2384 | + 'MTP_context' => $set_column_values['MTP_context'], |
|
| 2385 | + 'MTP_content' => $set_column_values['MTP_content'] |
|
| 2386 | + ); |
|
| 2387 | + if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) { |
|
| 2388 | + if ($updated === false) { |
|
| 2389 | + EE_Error::add_error( |
|
| 2390 | + sprintf( |
|
| 2391 | + __('%s field was NOT updated for some reason', 'event_espresso'), |
|
| 2392 | + $template_field |
|
| 2393 | + ), |
|
| 2394 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2395 | + ); |
|
| 2396 | + } else { |
|
| 2397 | + $success = 1; |
|
| 2398 | + } |
|
| 2399 | + } |
|
| 2400 | + $action_desc = 'updated'; |
|
| 2401 | + } |
|
| 2402 | 2402 | |
| 2403 | - //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs) |
|
| 2404 | - $mtpg_fields = array( |
|
| 2405 | - 'MTP_user_id' => $set_column_values['MTP_user_id'], |
|
| 2406 | - 'MTP_messenger' => $set_column_values['MTP_messenger'], |
|
| 2407 | - 'MTP_message_type' => $set_column_values['MTP_message_type'], |
|
| 2408 | - 'MTP_is_global' => $set_column_values['MTP_is_global'], |
|
| 2409 | - 'MTP_is_override' => $set_column_values['MTP_is_override'], |
|
| 2410 | - 'MTP_deleted' => $set_column_values['MTP_deleted'], |
|
| 2411 | - 'MTP_is_active' => $set_column_values['MTP_is_active'], |
|
| 2412 | - 'MTP_name' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name']) |
|
| 2413 | - ? $this->_req_data['ee_msg_non_global_fields']['MTP_name'] |
|
| 2414 | - : '', |
|
| 2415 | - 'MTP_description' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description']) |
|
| 2416 | - ? $this->_req_data['ee_msg_non_global_fields']['MTP_description'] |
|
| 2417 | - : '' |
|
| 2418 | - ); |
|
| 2403 | + //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs) |
|
| 2404 | + $mtpg_fields = array( |
|
| 2405 | + 'MTP_user_id' => $set_column_values['MTP_user_id'], |
|
| 2406 | + 'MTP_messenger' => $set_column_values['MTP_messenger'], |
|
| 2407 | + 'MTP_message_type' => $set_column_values['MTP_message_type'], |
|
| 2408 | + 'MTP_is_global' => $set_column_values['MTP_is_global'], |
|
| 2409 | + 'MTP_is_override' => $set_column_values['MTP_is_override'], |
|
| 2410 | + 'MTP_deleted' => $set_column_values['MTP_deleted'], |
|
| 2411 | + 'MTP_is_active' => $set_column_values['MTP_is_active'], |
|
| 2412 | + 'MTP_name' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name']) |
|
| 2413 | + ? $this->_req_data['ee_msg_non_global_fields']['MTP_name'] |
|
| 2414 | + : '', |
|
| 2415 | + 'MTP_description' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description']) |
|
| 2416 | + ? $this->_req_data['ee_msg_non_global_fields']['MTP_description'] |
|
| 2417 | + : '' |
|
| 2418 | + ); |
|
| 2419 | 2419 | |
| 2420 | - $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']); |
|
| 2421 | - $updated = $MTPG->update($mtpg_fields, array($mtpg_where)); |
|
| 2420 | + $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']); |
|
| 2421 | + $updated = $MTPG->update($mtpg_fields, array($mtpg_where)); |
|
| 2422 | 2422 | |
| 2423 | - if ($updated === false) { |
|
| 2424 | - EE_Error::add_error( |
|
| 2425 | - sprintf( |
|
| 2426 | - __('The Message Template Group (%d) was NOT updated for some reason', 'event_espresso'), |
|
| 2427 | - $set_column_values['GRP_ID'] |
|
| 2428 | - ), |
|
| 2429 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2430 | - ); |
|
| 2431 | - } else { |
|
| 2432 | - //k now we need to ensure the template_pack and template_variation fields are set. |
|
| 2433 | - $template_pack = ! empty($this->_req_data['MTP_template_pack']) |
|
| 2434 | - ? $this->_req_data['MTP_template_pack'] |
|
| 2435 | - : 'default'; |
|
| 2423 | + if ($updated === false) { |
|
| 2424 | + EE_Error::add_error( |
|
| 2425 | + sprintf( |
|
| 2426 | + __('The Message Template Group (%d) was NOT updated for some reason', 'event_espresso'), |
|
| 2427 | + $set_column_values['GRP_ID'] |
|
| 2428 | + ), |
|
| 2429 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2430 | + ); |
|
| 2431 | + } else { |
|
| 2432 | + //k now we need to ensure the template_pack and template_variation fields are set. |
|
| 2433 | + $template_pack = ! empty($this->_req_data['MTP_template_pack']) |
|
| 2434 | + ? $this->_req_data['MTP_template_pack'] |
|
| 2435 | + : 'default'; |
|
| 2436 | 2436 | |
| 2437 | - $template_variation = ! empty($this->_req_data['MTP_template_variation']) |
|
| 2438 | - ? $this->_req_data['MTP_template_variation'] |
|
| 2439 | - : 'default'; |
|
| 2437 | + $template_variation = ! empty($this->_req_data['MTP_template_variation']) |
|
| 2438 | + ? $this->_req_data['MTP_template_variation'] |
|
| 2439 | + : 'default'; |
|
| 2440 | 2440 | |
| 2441 | - $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']); |
|
| 2442 | - if ($mtpg_obj instanceof EE_Message_Template_Group) { |
|
| 2443 | - $mtpg_obj->set_template_pack_name($template_pack); |
|
| 2444 | - $mtpg_obj->set_template_pack_variation($template_variation); |
|
| 2445 | - } |
|
| 2446 | - $success = 1; |
|
| 2447 | - } |
|
| 2448 | - } |
|
| 2449 | - } |
|
| 2441 | + $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']); |
|
| 2442 | + if ($mtpg_obj instanceof EE_Message_Template_Group) { |
|
| 2443 | + $mtpg_obj->set_template_pack_name($template_pack); |
|
| 2444 | + $mtpg_obj->set_template_pack_variation($template_variation); |
|
| 2445 | + } |
|
| 2446 | + $success = 1; |
|
| 2447 | + } |
|
| 2448 | + } |
|
| 2449 | + } |
|
| 2450 | 2450 | |
| 2451 | - } |
|
| 2452 | - |
|
| 2453 | - //we return things differently if doing ajax |
|
| 2454 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2455 | - $this->_template_args['success'] = $success; |
|
| 2456 | - $this->_template_args['error'] = ! $success ? true : false; |
|
| 2457 | - $this->_template_args['content'] = ''; |
|
| 2458 | - $this->_template_args['data'] = array( |
|
| 2459 | - 'grpID' => $edit_array['GRP_ID'], |
|
| 2460 | - 'templateName' => $edit_array['template_name'] |
|
| 2461 | - ); |
|
| 2462 | - if ($success) { |
|
| 2463 | - EE_Error::overwrite_success(); |
|
| 2464 | - 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.', |
|
| 2465 | - 'event_espresso')); |
|
| 2466 | - } |
|
| 2451 | + } |
|
| 2452 | + |
|
| 2453 | + //we return things differently if doing ajax |
|
| 2454 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2455 | + $this->_template_args['success'] = $success; |
|
| 2456 | + $this->_template_args['error'] = ! $success ? true : false; |
|
| 2457 | + $this->_template_args['content'] = ''; |
|
| 2458 | + $this->_template_args['data'] = array( |
|
| 2459 | + 'grpID' => $edit_array['GRP_ID'], |
|
| 2460 | + 'templateName' => $edit_array['template_name'] |
|
| 2461 | + ); |
|
| 2462 | + if ($success) { |
|
| 2463 | + EE_Error::overwrite_success(); |
|
| 2464 | + 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.', |
|
| 2465 | + 'event_espresso')); |
|
| 2466 | + } |
|
| 2467 | 2467 | |
| 2468 | - $this->_return_json(); |
|
| 2469 | - } |
|
| 2470 | - |
|
| 2471 | - |
|
| 2472 | - //was a test send triggered? |
|
| 2473 | - if (isset($this->_req_data['test_button'])) { |
|
| 2474 | - EE_Error::overwrite_success(); |
|
| 2475 | - $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug); |
|
| 2476 | - $override = true; |
|
| 2477 | - } |
|
| 2478 | - |
|
| 2479 | - if (empty($query_args)) { |
|
| 2480 | - $query_args = array( |
|
| 2481 | - 'id' => $this->_req_data['GRP_ID'], |
|
| 2482 | - 'context' => $context_slug, |
|
| 2483 | - 'action' => 'edit_message_template' |
|
| 2484 | - ); |
|
| 2485 | - } |
|
| 2486 | - |
|
| 2487 | - $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override); |
|
| 2488 | - } |
|
| 2489 | - |
|
| 2490 | - |
|
| 2491 | - /** |
|
| 2492 | - * processes a test send request to do an actual messenger delivery test for the given message template being tested |
|
| 2493 | - * |
|
| 2494 | - * @param string $context what context being tested |
|
| 2495 | - * @param string $messenger messenger being tested |
|
| 2496 | - * @param string $message_type message type being tested |
|
| 2497 | - * |
|
| 2498 | - */ |
|
| 2499 | - protected function _do_test_send($context, $messenger, $message_type) |
|
| 2500 | - { |
|
| 2501 | - //set things up for preview |
|
| 2502 | - $this->_req_data['messenger'] = $messenger; |
|
| 2503 | - $this->_req_data['message_type'] = $message_type; |
|
| 2504 | - $this->_req_data['context'] = $context; |
|
| 2505 | - $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : ''; |
|
| 2506 | - $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger); |
|
| 2507 | - |
|
| 2508 | - //let's save any existing fields that might be required by the messenger |
|
| 2509 | - if ( |
|
| 2510 | - isset($this->_req_data['test_settings_fld']) |
|
| 2511 | - && $active_messenger instanceof EE_messenger |
|
| 2512 | - && apply_filters( |
|
| 2513 | - 'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings', |
|
| 2514 | - true, |
|
| 2515 | - $this->_req_data['test_settings_fld'], |
|
| 2516 | - $active_messenger |
|
| 2517 | - ) |
|
| 2518 | - ) { |
|
| 2519 | - $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']); |
|
| 2520 | - } |
|
| 2521 | - |
|
| 2522 | - $success = $this->_preview_message(true); |
|
| 2523 | - |
|
| 2524 | - if ($success) { |
|
| 2525 | - EE_Error::add_success(__('Test message sent', 'event_espresso')); |
|
| 2526 | - } else { |
|
| 2527 | - EE_Error::add_error(__('The test message was not sent', 'event_espresso'), __FILE__, __FUNCTION__, |
|
| 2528 | - __LINE__); |
|
| 2529 | - } |
|
| 2530 | - } |
|
| 2531 | - |
|
| 2532 | - |
|
| 2533 | - /** |
|
| 2534 | - * _generate_new_templates |
|
| 2535 | - * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will |
|
| 2536 | - * automatically create the defaults for the event. The user would then be redirected to edit the default context |
|
| 2537 | - * for the event. |
|
| 2538 | - * |
|
| 2539 | - * |
|
| 2540 | - * @param string $messenger the messenger we are generating templates for |
|
| 2541 | - * @param array $message_types array of message types that the templates are generated for. |
|
| 2542 | - * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to |
|
| 2543 | - * indicate the message_template_group being used as the base. |
|
| 2544 | - * |
|
| 2545 | - * @param bool $global |
|
| 2546 | - * |
|
| 2547 | - * @return array|bool array of data required for the redirect to the correct edit page or bool if |
|
| 2548 | - * encountering problems. |
|
| 2549 | - * @throws \EE_Error |
|
| 2550 | - */ |
|
| 2551 | - protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 2552 | - { |
|
| 2553 | - |
|
| 2554 | - //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. |
|
| 2555 | - if (empty($message_types)) { |
|
| 2556 | - return true; |
|
| 2557 | - } |
|
| 2558 | - |
|
| 2559 | - return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global); |
|
| 2560 | - } |
|
| 2561 | - |
|
| 2562 | - |
|
| 2563 | - /** |
|
| 2564 | - * [_trash_or_restore_message_template] |
|
| 2565 | - * |
|
| 2566 | - * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE) |
|
| 2567 | - * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just |
|
| 2568 | - * an individual context (FALSE). |
|
| 2569 | - * |
|
| 2570 | - * @return void |
|
| 2571 | - */ |
|
| 2572 | - protected function _trash_or_restore_message_template($trash = true, $all = false) |
|
| 2573 | - { |
|
| 2574 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2575 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 2576 | - |
|
| 2577 | - $success = 1; |
|
| 2578 | - |
|
| 2579 | - //incoming GRP_IDs |
|
| 2580 | - if ($all) { |
|
| 2581 | - //Checkboxes |
|
| 2582 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2583 | - //if array has more than one element then success message should be plural. |
|
| 2584 | - //todo: what about nonce? |
|
| 2585 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2468 | + $this->_return_json(); |
|
| 2469 | + } |
|
| 2470 | + |
|
| 2471 | + |
|
| 2472 | + //was a test send triggered? |
|
| 2473 | + if (isset($this->_req_data['test_button'])) { |
|
| 2474 | + EE_Error::overwrite_success(); |
|
| 2475 | + $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug); |
|
| 2476 | + $override = true; |
|
| 2477 | + } |
|
| 2478 | + |
|
| 2479 | + if (empty($query_args)) { |
|
| 2480 | + $query_args = array( |
|
| 2481 | + 'id' => $this->_req_data['GRP_ID'], |
|
| 2482 | + 'context' => $context_slug, |
|
| 2483 | + 'action' => 'edit_message_template' |
|
| 2484 | + ); |
|
| 2485 | + } |
|
| 2486 | + |
|
| 2487 | + $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override); |
|
| 2488 | + } |
|
| 2489 | + |
|
| 2490 | + |
|
| 2491 | + /** |
|
| 2492 | + * processes a test send request to do an actual messenger delivery test for the given message template being tested |
|
| 2493 | + * |
|
| 2494 | + * @param string $context what context being tested |
|
| 2495 | + * @param string $messenger messenger being tested |
|
| 2496 | + * @param string $message_type message type being tested |
|
| 2497 | + * |
|
| 2498 | + */ |
|
| 2499 | + protected function _do_test_send($context, $messenger, $message_type) |
|
| 2500 | + { |
|
| 2501 | + //set things up for preview |
|
| 2502 | + $this->_req_data['messenger'] = $messenger; |
|
| 2503 | + $this->_req_data['message_type'] = $message_type; |
|
| 2504 | + $this->_req_data['context'] = $context; |
|
| 2505 | + $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : ''; |
|
| 2506 | + $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger); |
|
| 2507 | + |
|
| 2508 | + //let's save any existing fields that might be required by the messenger |
|
| 2509 | + if ( |
|
| 2510 | + isset($this->_req_data['test_settings_fld']) |
|
| 2511 | + && $active_messenger instanceof EE_messenger |
|
| 2512 | + && apply_filters( |
|
| 2513 | + 'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings', |
|
| 2514 | + true, |
|
| 2515 | + $this->_req_data['test_settings_fld'], |
|
| 2516 | + $active_messenger |
|
| 2517 | + ) |
|
| 2518 | + ) { |
|
| 2519 | + $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']); |
|
| 2520 | + } |
|
| 2521 | + |
|
| 2522 | + $success = $this->_preview_message(true); |
|
| 2523 | + |
|
| 2524 | + if ($success) { |
|
| 2525 | + EE_Error::add_success(__('Test message sent', 'event_espresso')); |
|
| 2526 | + } else { |
|
| 2527 | + EE_Error::add_error(__('The test message was not sent', 'event_espresso'), __FILE__, __FUNCTION__, |
|
| 2528 | + __LINE__); |
|
| 2529 | + } |
|
| 2530 | + } |
|
| 2531 | + |
|
| 2532 | + |
|
| 2533 | + /** |
|
| 2534 | + * _generate_new_templates |
|
| 2535 | + * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will |
|
| 2536 | + * automatically create the defaults for the event. The user would then be redirected to edit the default context |
|
| 2537 | + * for the event. |
|
| 2538 | + * |
|
| 2539 | + * |
|
| 2540 | + * @param string $messenger the messenger we are generating templates for |
|
| 2541 | + * @param array $message_types array of message types that the templates are generated for. |
|
| 2542 | + * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to |
|
| 2543 | + * indicate the message_template_group being used as the base. |
|
| 2544 | + * |
|
| 2545 | + * @param bool $global |
|
| 2546 | + * |
|
| 2547 | + * @return array|bool array of data required for the redirect to the correct edit page or bool if |
|
| 2548 | + * encountering problems. |
|
| 2549 | + * @throws \EE_Error |
|
| 2550 | + */ |
|
| 2551 | + protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 2552 | + { |
|
| 2553 | + |
|
| 2554 | + //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. |
|
| 2555 | + if (empty($message_types)) { |
|
| 2556 | + return true; |
|
| 2557 | + } |
|
| 2558 | + |
|
| 2559 | + return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global); |
|
| 2560 | + } |
|
| 2561 | + |
|
| 2562 | + |
|
| 2563 | + /** |
|
| 2564 | + * [_trash_or_restore_message_template] |
|
| 2565 | + * |
|
| 2566 | + * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE) |
|
| 2567 | + * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just |
|
| 2568 | + * an individual context (FALSE). |
|
| 2569 | + * |
|
| 2570 | + * @return void |
|
| 2571 | + */ |
|
| 2572 | + protected function _trash_or_restore_message_template($trash = true, $all = false) |
|
| 2573 | + { |
|
| 2574 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2575 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 2576 | + |
|
| 2577 | + $success = 1; |
|
| 2578 | + |
|
| 2579 | + //incoming GRP_IDs |
|
| 2580 | + if ($all) { |
|
| 2581 | + //Checkboxes |
|
| 2582 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2583 | + //if array has more than one element then success message should be plural. |
|
| 2584 | + //todo: what about nonce? |
|
| 2585 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2586 | 2586 | |
| 2587 | - //cycle through checkboxes |
|
| 2588 | - while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2589 | - $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 2590 | - if ( ! $trashed_or_restored) { |
|
| 2591 | - $success = 0; |
|
| 2592 | - } |
|
| 2593 | - } |
|
| 2594 | - } else { |
|
| 2595 | - //grab single GRP_ID and handle |
|
| 2596 | - $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 2597 | - if ( ! empty($GRP_ID)) { |
|
| 2598 | - $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 2599 | - if ( ! $trashed_or_restored) { |
|
| 2600 | - $success = 0; |
|
| 2601 | - } |
|
| 2602 | - } else { |
|
| 2603 | - $success = 0; |
|
| 2604 | - } |
|
| 2605 | - } |
|
| 2587 | + //cycle through checkboxes |
|
| 2588 | + while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2589 | + $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 2590 | + if ( ! $trashed_or_restored) { |
|
| 2591 | + $success = 0; |
|
| 2592 | + } |
|
| 2593 | + } |
|
| 2594 | + } else { |
|
| 2595 | + //grab single GRP_ID and handle |
|
| 2596 | + $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 2597 | + if ( ! empty($GRP_ID)) { |
|
| 2598 | + $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 2599 | + if ( ! $trashed_or_restored) { |
|
| 2600 | + $success = 0; |
|
| 2601 | + } |
|
| 2602 | + } else { |
|
| 2603 | + $success = 0; |
|
| 2604 | + } |
|
| 2605 | + } |
|
| 2606 | 2606 | |
| 2607 | - } |
|
| 2607 | + } |
|
| 2608 | 2608 | |
| 2609 | - $action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso'); |
|
| 2609 | + $action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso'); |
|
| 2610 | 2610 | |
| 2611 | - $action_desc = ! empty($this->_req_data['template_switch']) ? __('switched') : $action_desc; |
|
| 2611 | + $action_desc = ! empty($this->_req_data['template_switch']) ? __('switched') : $action_desc; |
|
| 2612 | 2612 | |
| 2613 | - $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success, |
|
| 2614 | - 'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); |
|
| 2613 | + $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success, |
|
| 2614 | + 'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); |
|
| 2615 | 2615 | |
| 2616 | - $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success, |
|
| 2617 | - 'event_espresso') : $item_desc; |
|
| 2616 | + $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success, |
|
| 2617 | + 'event_espresso') : $item_desc; |
|
| 2618 | 2618 | |
| 2619 | - $this->_redirect_after_action($success, $item_desc, $action_desc, array()); |
|
| 2619 | + $this->_redirect_after_action($success, $item_desc, $action_desc, array()); |
|
| 2620 | 2620 | |
| 2621 | - } |
|
| 2621 | + } |
|
| 2622 | 2622 | |
| 2623 | 2623 | |
| 2624 | - /** |
|
| 2625 | - * [_delete_message_template] |
|
| 2626 | - * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group. |
|
| 2627 | - * @return void |
|
| 2628 | - */ |
|
| 2629 | - protected function _delete_message_template() |
|
| 2630 | - { |
|
| 2631 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2624 | + /** |
|
| 2625 | + * [_delete_message_template] |
|
| 2626 | + * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group. |
|
| 2627 | + * @return void |
|
| 2628 | + */ |
|
| 2629 | + protected function _delete_message_template() |
|
| 2630 | + { |
|
| 2631 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2632 | 2632 | |
| 2633 | - //checkboxes |
|
| 2634 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2635 | - //if array has more than one element then success message should be plural |
|
| 2636 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2633 | + //checkboxes |
|
| 2634 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2635 | + //if array has more than one element then success message should be plural |
|
| 2636 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2637 | 2637 | |
| 2638 | - //cycle through bulk action checkboxes |
|
| 2639 | - while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2640 | - $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 2641 | - } |
|
| 2642 | - } else { |
|
| 2643 | - //grab single grp_id and delete |
|
| 2644 | - $GRP_ID = absint($this->_req_data['id']); |
|
| 2645 | - $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 2646 | - } |
|
| 2647 | - |
|
| 2648 | - $this->_redirect_after_action($success, 'Message Templates', 'deleted', array()); |
|
| 2649 | - |
|
| 2650 | - } |
|
| 2651 | - |
|
| 2652 | - |
|
| 2653 | - /** |
|
| 2654 | - * helper for permanently deleting a mtP group and all related message_templates |
|
| 2655 | - * |
|
| 2656 | - * @param int $GRP_ID The group being deleted |
|
| 2657 | - * @param bool $include_group whether to delete the Message Template Group as well. |
|
| 2658 | - * |
|
| 2659 | - * @return bool boolean to indicate the success of the deletes or not. |
|
| 2660 | - */ |
|
| 2661 | - private function _delete_mtp_permanently($GRP_ID, $include_group = true) |
|
| 2662 | - { |
|
| 2663 | - $success = 1; |
|
| 2664 | - $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2665 | - //first let's GET this group |
|
| 2666 | - $MTG = $MTPG->get_one_by_ID($GRP_ID); |
|
| 2667 | - //then delete permanently all the related Message Templates |
|
| 2668 | - $deleted = $MTG->delete_related_permanently('Message_Template'); |
|
| 2669 | - |
|
| 2670 | - if ($deleted === 0) { |
|
| 2671 | - $success = 0; |
|
| 2672 | - } |
|
| 2673 | - |
|
| 2674 | - //now delete permanently this particular group |
|
| 2675 | - |
|
| 2676 | - if ($include_group && ! $MTG->delete_permanently()) { |
|
| 2677 | - $success = 0; |
|
| 2678 | - } |
|
| 2679 | - |
|
| 2680 | - return $success; |
|
| 2681 | - } |
|
| 2682 | - |
|
| 2683 | - |
|
| 2684 | - /** |
|
| 2685 | - * _learn_more_about_message_templates_link |
|
| 2686 | - * @access protected |
|
| 2687 | - * @return string |
|
| 2688 | - */ |
|
| 2689 | - protected function _learn_more_about_message_templates_link() |
|
| 2690 | - { |
|
| 2691 | - return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works', |
|
| 2692 | - 'event_espresso') . '</a>'; |
|
| 2693 | - } |
|
| 2694 | - |
|
| 2695 | - |
|
| 2696 | - /** |
|
| 2697 | - * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by |
|
| 2698 | - * ajax and other routes. |
|
| 2699 | - * @return void |
|
| 2700 | - */ |
|
| 2701 | - protected function _settings() |
|
| 2702 | - { |
|
| 2703 | - |
|
| 2704 | - |
|
| 2705 | - $this->_set_m_mt_settings(); |
|
| 2706 | - |
|
| 2707 | - $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2708 | - |
|
| 2709 | - //let's setup the messenger tabs |
|
| 2710 | - $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links($this->_m_mt_settings['messenger_tabs'], |
|
| 2711 | - 'messenger_links', '|', $selected_messenger); |
|
| 2712 | - $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">'; |
|
| 2713 | - $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->'; |
|
| 2714 | - |
|
| 2715 | - $this->display_admin_page_with_sidebar(); |
|
| 2716 | - |
|
| 2717 | - } |
|
| 2718 | - |
|
| 2719 | - |
|
| 2720 | - /** |
|
| 2721 | - * This sets the $_m_mt_settings property for when needed (used on the Messages settings page) |
|
| 2722 | - * |
|
| 2723 | - * @access protected |
|
| 2724 | - * @return void |
|
| 2725 | - */ |
|
| 2726 | - protected function _set_m_mt_settings() |
|
| 2727 | - { |
|
| 2728 | - //first if this is already set then lets get out no need to regenerate data. |
|
| 2729 | - if ( ! empty($this->_m_mt_settings)) { |
|
| 2730 | - return; |
|
| 2731 | - } |
|
| 2732 | - |
|
| 2733 | - //$selected_messenger = isset( $this->_req_data['selected_messenger'] ) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2734 | - |
|
| 2735 | - //get all installed messengers and message_types |
|
| 2736 | - /** @type EE_messenger[] $messengers */ |
|
| 2737 | - $messengers = $this->_message_resource_manager->installed_messengers(); |
|
| 2738 | - /** @type EE_message_type[] $message_types */ |
|
| 2739 | - $message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 2740 | - |
|
| 2741 | - |
|
| 2742 | - //assemble the array for the _tab_text_links helper |
|
| 2743 | - |
|
| 2744 | - foreach ($messengers as $messenger) { |
|
| 2745 | - $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array( |
|
| 2746 | - 'label' => ucwords($messenger->label['singular']), |
|
| 2747 | - 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) ? 'messenger-active' : '', |
|
| 2748 | - 'href' => $messenger->name, |
|
| 2749 | - 'title' => __('Modify this Messenger', 'event_espresso'), |
|
| 2750 | - 'slug' => $messenger->name, |
|
| 2751 | - 'obj' => $messenger |
|
| 2752 | - ); |
|
| 2638 | + //cycle through bulk action checkboxes |
|
| 2639 | + while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2640 | + $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 2641 | + } |
|
| 2642 | + } else { |
|
| 2643 | + //grab single grp_id and delete |
|
| 2644 | + $GRP_ID = absint($this->_req_data['id']); |
|
| 2645 | + $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 2646 | + } |
|
| 2647 | + |
|
| 2648 | + $this->_redirect_after_action($success, 'Message Templates', 'deleted', array()); |
|
| 2649 | + |
|
| 2650 | + } |
|
| 2651 | + |
|
| 2652 | + |
|
| 2653 | + /** |
|
| 2654 | + * helper for permanently deleting a mtP group and all related message_templates |
|
| 2655 | + * |
|
| 2656 | + * @param int $GRP_ID The group being deleted |
|
| 2657 | + * @param bool $include_group whether to delete the Message Template Group as well. |
|
| 2658 | + * |
|
| 2659 | + * @return bool boolean to indicate the success of the deletes or not. |
|
| 2660 | + */ |
|
| 2661 | + private function _delete_mtp_permanently($GRP_ID, $include_group = true) |
|
| 2662 | + { |
|
| 2663 | + $success = 1; |
|
| 2664 | + $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2665 | + //first let's GET this group |
|
| 2666 | + $MTG = $MTPG->get_one_by_ID($GRP_ID); |
|
| 2667 | + //then delete permanently all the related Message Templates |
|
| 2668 | + $deleted = $MTG->delete_related_permanently('Message_Template'); |
|
| 2669 | + |
|
| 2670 | + if ($deleted === 0) { |
|
| 2671 | + $success = 0; |
|
| 2672 | + } |
|
| 2673 | + |
|
| 2674 | + //now delete permanently this particular group |
|
| 2675 | + |
|
| 2676 | + if ($include_group && ! $MTG->delete_permanently()) { |
|
| 2677 | + $success = 0; |
|
| 2678 | + } |
|
| 2679 | + |
|
| 2680 | + return $success; |
|
| 2681 | + } |
|
| 2682 | + |
|
| 2683 | + |
|
| 2684 | + /** |
|
| 2685 | + * _learn_more_about_message_templates_link |
|
| 2686 | + * @access protected |
|
| 2687 | + * @return string |
|
| 2688 | + */ |
|
| 2689 | + protected function _learn_more_about_message_templates_link() |
|
| 2690 | + { |
|
| 2691 | + return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works', |
|
| 2692 | + 'event_espresso') . '</a>'; |
|
| 2693 | + } |
|
| 2694 | + |
|
| 2695 | + |
|
| 2696 | + /** |
|
| 2697 | + * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by |
|
| 2698 | + * ajax and other routes. |
|
| 2699 | + * @return void |
|
| 2700 | + */ |
|
| 2701 | + protected function _settings() |
|
| 2702 | + { |
|
| 2703 | + |
|
| 2704 | + |
|
| 2705 | + $this->_set_m_mt_settings(); |
|
| 2706 | + |
|
| 2707 | + $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2708 | + |
|
| 2709 | + //let's setup the messenger tabs |
|
| 2710 | + $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links($this->_m_mt_settings['messenger_tabs'], |
|
| 2711 | + 'messenger_links', '|', $selected_messenger); |
|
| 2712 | + $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">'; |
|
| 2713 | + $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->'; |
|
| 2714 | + |
|
| 2715 | + $this->display_admin_page_with_sidebar(); |
|
| 2716 | + |
|
| 2717 | + } |
|
| 2718 | + |
|
| 2719 | + |
|
| 2720 | + /** |
|
| 2721 | + * This sets the $_m_mt_settings property for when needed (used on the Messages settings page) |
|
| 2722 | + * |
|
| 2723 | + * @access protected |
|
| 2724 | + * @return void |
|
| 2725 | + */ |
|
| 2726 | + protected function _set_m_mt_settings() |
|
| 2727 | + { |
|
| 2728 | + //first if this is already set then lets get out no need to regenerate data. |
|
| 2729 | + if ( ! empty($this->_m_mt_settings)) { |
|
| 2730 | + return; |
|
| 2731 | + } |
|
| 2732 | + |
|
| 2733 | + //$selected_messenger = isset( $this->_req_data['selected_messenger'] ) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2734 | + |
|
| 2735 | + //get all installed messengers and message_types |
|
| 2736 | + /** @type EE_messenger[] $messengers */ |
|
| 2737 | + $messengers = $this->_message_resource_manager->installed_messengers(); |
|
| 2738 | + /** @type EE_message_type[] $message_types */ |
|
| 2739 | + $message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 2740 | + |
|
| 2741 | + |
|
| 2742 | + //assemble the array for the _tab_text_links helper |
|
| 2743 | + |
|
| 2744 | + foreach ($messengers as $messenger) { |
|
| 2745 | + $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array( |
|
| 2746 | + 'label' => ucwords($messenger->label['singular']), |
|
| 2747 | + 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) ? 'messenger-active' : '', |
|
| 2748 | + 'href' => $messenger->name, |
|
| 2749 | + 'title' => __('Modify this Messenger', 'event_espresso'), |
|
| 2750 | + 'slug' => $messenger->name, |
|
| 2751 | + 'obj' => $messenger |
|
| 2752 | + ); |
|
| 2753 | 2753 | |
| 2754 | 2754 | |
| 2755 | - $message_types_for_messenger = $messenger->get_valid_message_types(); |
|
| 2755 | + $message_types_for_messenger = $messenger->get_valid_message_types(); |
|
| 2756 | 2756 | |
| 2757 | - foreach ($message_types as $message_type) { |
|
| 2758 | - //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. |
|
| 2759 | - if ( ! in_array($message_type->name, $message_types_for_messenger)) { |
|
| 2760 | - continue; |
|
| 2761 | - } |
|
| 2757 | + foreach ($message_types as $message_type) { |
|
| 2758 | + //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. |
|
| 2759 | + if ( ! in_array($message_type->name, $message_types_for_messenger)) { |
|
| 2760 | + continue; |
|
| 2761 | + } |
|
| 2762 | 2762 | |
| 2763 | - $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger($messenger->name, |
|
| 2764 | - $message_type->name) ? 'active' : 'inactive'; |
|
| 2763 | + $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger($messenger->name, |
|
| 2764 | + $message_type->name) ? 'active' : 'inactive'; |
|
| 2765 | 2765 | |
| 2766 | - $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
|
| 2767 | - 'label' => ucwords($message_type->label['singular']), |
|
| 2768 | - 'class' => 'message-type-' . $a_or_i, |
|
| 2769 | - 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 2770 | - 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 2771 | - 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 2772 | - 'title' => $a_or_i == 'active' |
|
| 2773 | - ? __('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
|
| 2774 | - : __('Drag this message type to the messenger to activate', 'event_espresso'), |
|
| 2775 | - 'content' => $a_or_i == 'active' |
|
| 2776 | - ? $this->_message_type_settings_content($message_type, $messenger, true) |
|
| 2777 | - : $this->_message_type_settings_content($message_type, $messenger), |
|
| 2778 | - 'slug' => $message_type->name, |
|
| 2779 | - 'active' => $a_or_i == 'active' ? true : false, |
|
| 2780 | - 'obj' => $message_type |
|
| 2781 | - ); |
|
| 2782 | - } |
|
| 2783 | - } |
|
| 2784 | - } |
|
| 2785 | - |
|
| 2786 | - |
|
| 2787 | - /** |
|
| 2788 | - * This just prepares the content for the message type settings |
|
| 2789 | - * |
|
| 2790 | - * @param object $message_type The message type object |
|
| 2791 | - * @param object $messenger The messenger object |
|
| 2792 | - * @param boolean $active Whether the message type is active or not |
|
| 2793 | - * |
|
| 2794 | - * @return string html output for the content |
|
| 2795 | - */ |
|
| 2796 | - protected function _message_type_settings_content($message_type, $messenger, $active = false) |
|
| 2797 | - { |
|
| 2798 | - //get message type fields |
|
| 2799 | - $fields = $message_type->get_admin_settings_fields(); |
|
| 2800 | - $settings_template_args['template_form_fields'] = ''; |
|
| 2801 | - |
|
| 2802 | - if ( ! empty($fields) && $active) { |
|
| 2766 | + $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
|
| 2767 | + 'label' => ucwords($message_type->label['singular']), |
|
| 2768 | + 'class' => 'message-type-' . $a_or_i, |
|
| 2769 | + 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 2770 | + 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 2771 | + 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 2772 | + 'title' => $a_or_i == 'active' |
|
| 2773 | + ? __('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
|
| 2774 | + : __('Drag this message type to the messenger to activate', 'event_espresso'), |
|
| 2775 | + 'content' => $a_or_i == 'active' |
|
| 2776 | + ? $this->_message_type_settings_content($message_type, $messenger, true) |
|
| 2777 | + : $this->_message_type_settings_content($message_type, $messenger), |
|
| 2778 | + 'slug' => $message_type->name, |
|
| 2779 | + 'active' => $a_or_i == 'active' ? true : false, |
|
| 2780 | + 'obj' => $message_type |
|
| 2781 | + ); |
|
| 2782 | + } |
|
| 2783 | + } |
|
| 2784 | + } |
|
| 2785 | + |
|
| 2786 | + |
|
| 2787 | + /** |
|
| 2788 | + * This just prepares the content for the message type settings |
|
| 2789 | + * |
|
| 2790 | + * @param object $message_type The message type object |
|
| 2791 | + * @param object $messenger The messenger object |
|
| 2792 | + * @param boolean $active Whether the message type is active or not |
|
| 2793 | + * |
|
| 2794 | + * @return string html output for the content |
|
| 2795 | + */ |
|
| 2796 | + protected function _message_type_settings_content($message_type, $messenger, $active = false) |
|
| 2797 | + { |
|
| 2798 | + //get message type fields |
|
| 2799 | + $fields = $message_type->get_admin_settings_fields(); |
|
| 2800 | + $settings_template_args['template_form_fields'] = ''; |
|
| 2801 | + |
|
| 2802 | + if ( ! empty($fields) && $active) { |
|
| 2803 | 2803 | |
| 2804 | - $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
|
| 2804 | + $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
|
| 2805 | 2805 | |
| 2806 | - foreach ($fields as $fldname => $fldprops) { |
|
| 2807 | - $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 2808 | - $template_form_field[$field_id] = array( |
|
| 2809 | - 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 2810 | - 'label' => $fldprops['label'], |
|
| 2811 | - 'input' => $fldprops['field_type'], |
|
| 2812 | - 'type' => $fldprops['value_type'], |
|
| 2813 | - 'required' => $fldprops['required'], |
|
| 2814 | - 'validation' => $fldprops['validation'], |
|
| 2815 | - 'value' => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'], |
|
| 2816 | - 'options' => isset($fldprops['options']) ? $fldprops['options'] : array(), |
|
| 2817 | - 'default' => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'], |
|
| 2818 | - 'css_class' => 'no-drag', |
|
| 2819 | - 'format' => $fldprops['format'] |
|
| 2820 | - ); |
|
| 2821 | - } |
|
| 2806 | + foreach ($fields as $fldname => $fldprops) { |
|
| 2807 | + $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 2808 | + $template_form_field[$field_id] = array( |
|
| 2809 | + 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 2810 | + 'label' => $fldprops['label'], |
|
| 2811 | + 'input' => $fldprops['field_type'], |
|
| 2812 | + 'type' => $fldprops['value_type'], |
|
| 2813 | + 'required' => $fldprops['required'], |
|
| 2814 | + 'validation' => $fldprops['validation'], |
|
| 2815 | + 'value' => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'], |
|
| 2816 | + 'options' => isset($fldprops['options']) ? $fldprops['options'] : array(), |
|
| 2817 | + 'default' => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'], |
|
| 2818 | + 'css_class' => 'no-drag', |
|
| 2819 | + 'format' => $fldprops['format'] |
|
| 2820 | + ); |
|
| 2821 | + } |
|
| 2822 | 2822 | |
| 2823 | 2823 | |
| 2824 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field) ? $this->_generate_admin_form_fields($template_form_field, |
|
| 2825 | - 'string', 'ee_mt_activate_form') : ''; |
|
| 2826 | - } |
|
| 2827 | - |
|
| 2828 | - $settings_template_args['description'] = $message_type->description; |
|
| 2829 | - //we also need some hidden fields |
|
| 2830 | - $settings_template_args['hidden_fields'] = array( |
|
| 2831 | - 'message_type_settings[messenger]' => array( |
|
| 2832 | - 'type' => 'hidden', |
|
| 2833 | - 'value' => $messenger->name |
|
| 2834 | - ), |
|
| 2835 | - 'message_type_settings[message_type]' => array( |
|
| 2836 | - 'type' => 'hidden', |
|
| 2837 | - 'value' => $message_type->name |
|
| 2838 | - ), |
|
| 2839 | - 'type' => array( |
|
| 2840 | - 'type' => 'hidden', |
|
| 2841 | - 'value' => 'message_type' |
|
| 2842 | - ) |
|
| 2843 | - ); |
|
| 2844 | - |
|
| 2845 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields($settings_template_args['hidden_fields'], |
|
| 2846 | - 'array'); |
|
| 2847 | - $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) ? ' hidden' : ''; |
|
| 2848 | - |
|
| 2849 | - |
|
| 2850 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 2851 | - $content = EEH_Template::display_template($template, $settings_template_args, true); |
|
| 2852 | - |
|
| 2853 | - return $content; |
|
| 2854 | - } |
|
| 2855 | - |
|
| 2856 | - |
|
| 2857 | - /** |
|
| 2858 | - * Generate all the metaboxes for the message types and register them for the messages settings page. |
|
| 2859 | - * |
|
| 2860 | - * @access protected |
|
| 2861 | - * @return void |
|
| 2862 | - */ |
|
| 2863 | - protected function _messages_settings_metaboxes() |
|
| 2864 | - { |
|
| 2865 | - $this->_set_m_mt_settings(); |
|
| 2866 | - $m_boxes = $mt_boxes = array(); |
|
| 2867 | - $m_template_args = $mt_template_args = array(); |
|
| 2868 | - |
|
| 2869 | - $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2870 | - |
|
| 2871 | - if (isset($this->_m_mt_settings['messenger_tabs'])) { |
|
| 2872 | - foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { |
|
| 2873 | - $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden'; |
|
| 2874 | - $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : ''; |
|
| 2875 | - //messenger meta boxes |
|
| 2876 | - $active = $selected_messenger == $messenger ? true : false; |
|
| 2877 | - $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active']) |
|
| 2878 | - ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 2879 | - : ''; |
|
| 2880 | - $m_boxes[$messenger . '_a_box'] = sprintf( |
|
| 2881 | - __('%s Settings', 'event_espresso'), |
|
| 2882 | - $tab_array['label'] |
|
| 2883 | - ); |
|
| 2884 | - $m_template_args[$messenger . '_a_box'] = array( |
|
| 2885 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 2886 | - 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2887 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2888 | - : '', |
|
| 2889 | - 'content' => $this->_get_messenger_box_content($tab_array['obj']), |
|
| 2890 | - 'hidden' => $active ? '' : ' hidden', |
|
| 2891 | - 'hide_on_message' => $hide_on_message, |
|
| 2892 | - 'messenger' => $messenger, |
|
| 2893 | - 'active' => $active |
|
| 2894 | - ); |
|
| 2895 | - // message type meta boxes |
|
| 2896 | - // (which is really just the inactive container for each messenger |
|
| 2897 | - // showing inactive message types for that messenger) |
|
| 2898 | - $mt_boxes[$messenger . '_i_box'] = __('Inactive Message Types', 'event_espresso'); |
|
| 2899 | - $mt_template_args[$messenger . '_i_box'] = array( |
|
| 2900 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 2901 | - 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2902 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2903 | - : '', |
|
| 2904 | - 'hidden' => $active ? '' : ' hidden', |
|
| 2905 | - 'hide_on_message' => $hide_on_message, |
|
| 2906 | - 'hide_off_message' => $hide_off_message, |
|
| 2907 | - 'messenger' => $messenger, |
|
| 2908 | - 'active' => $active |
|
| 2909 | - ); |
|
| 2910 | - } |
|
| 2911 | - } |
|
| 2912 | - |
|
| 2913 | - |
|
| 2914 | - //register messenger metaboxes |
|
| 2915 | - $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 2916 | - foreach ($m_boxes as $box => $label) { |
|
| 2917 | - $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
|
| 2918 | - $msgr = str_replace('_a_box', '', $box); |
|
| 2919 | - add_meta_box( |
|
| 2920 | - 'espresso_' . $msgr . '_settings', |
|
| 2921 | - $label, |
|
| 2922 | - function ($post, $metabox) { |
|
| 2923 | - echo EEH_Template::display_template($metabox["args"]["template_path"], |
|
| 2924 | - $metabox["args"]["template_args"], true); |
|
| 2925 | - }, |
|
| 2926 | - $this->_current_screen->id, |
|
| 2927 | - 'normal', |
|
| 2928 | - 'high', |
|
| 2929 | - $callback_args |
|
| 2930 | - ); |
|
| 2931 | - } |
|
| 2932 | - |
|
| 2933 | - //register message type metaboxes |
|
| 2934 | - $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 2935 | - foreach ($mt_boxes as $box => $label) { |
|
| 2936 | - $callback_args = array( |
|
| 2937 | - 'template_path' => $mt_template_path, |
|
| 2938 | - 'template_args' => $mt_template_args[$box] |
|
| 2939 | - ); |
|
| 2940 | - $mt = str_replace('_i_box', '', $box); |
|
| 2941 | - add_meta_box( |
|
| 2942 | - 'espresso_' . $mt . '_inactive_mts', |
|
| 2943 | - $label, |
|
| 2944 | - function ($post, $metabox) { |
|
| 2945 | - echo EEH_Template::display_template($metabox["args"]["template_path"], |
|
| 2946 | - $metabox["args"]["template_args"], true); |
|
| 2947 | - }, |
|
| 2948 | - $this->_current_screen->id, |
|
| 2949 | - 'side', |
|
| 2950 | - 'high', |
|
| 2951 | - $callback_args |
|
| 2952 | - ); |
|
| 2953 | - } |
|
| 2954 | - |
|
| 2955 | - //register metabox for global messages settings but only when on the main site. On single site installs this will |
|
| 2956 | - //always result in the metabox showing, on multisite installs the metabox will only show on the main site. |
|
| 2957 | - if (is_main_site()) { |
|
| 2958 | - add_meta_box( |
|
| 2959 | - 'espresso_global_message_settings', |
|
| 2960 | - __('Global Message Settings', 'event_espresso'), |
|
| 2961 | - array($this, 'global_messages_settings_metabox_content'), |
|
| 2962 | - $this->_current_screen->id, |
|
| 2963 | - 'normal', |
|
| 2964 | - 'low', |
|
| 2965 | - array() |
|
| 2966 | - ); |
|
| 2967 | - } |
|
| 2968 | - |
|
| 2969 | - } |
|
| 2970 | - |
|
| 2971 | - |
|
| 2972 | - /** |
|
| 2973 | - * This generates the content for the global messages settings metabox. |
|
| 2974 | - * @return string |
|
| 2975 | - */ |
|
| 2976 | - public function global_messages_settings_metabox_content() |
|
| 2977 | - { |
|
| 2978 | - $form = $this->_generate_global_settings_form(); |
|
| 2979 | - echo $form->form_open( |
|
| 2980 | - $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL), |
|
| 2981 | - 'POST' |
|
| 2982 | - ) |
|
| 2983 | - . $form->get_html() |
|
| 2984 | - . $form->form_close(); |
|
| 2985 | - } |
|
| 2986 | - |
|
| 2987 | - |
|
| 2988 | - /** |
|
| 2989 | - * This generates and returns the form object for the global messages settings. |
|
| 2990 | - * @return EE_Form_Section_Proper |
|
| 2991 | - */ |
|
| 2992 | - protected function _generate_global_settings_form() |
|
| 2993 | - { |
|
| 2994 | - EE_Registry::instance()->load_helper('HTML'); |
|
| 2995 | - /** @var EE_Network_Core_Config $network_config */ |
|
| 2996 | - $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 2997 | - |
|
| 2998 | - return new EE_Form_Section_Proper( |
|
| 2999 | - array( |
|
| 3000 | - 'name' => 'global_messages_settings', |
|
| 3001 | - 'html_id' => 'global_messages_settings', |
|
| 3002 | - 'html_class' => 'form-table', |
|
| 3003 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 3004 | - 'subsections' => apply_filters( |
|
| 3005 | - 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections', |
|
| 3006 | - array( |
|
| 3007 | - 'do_messages_on_same_request' => new EE_Select_Input( |
|
| 3008 | - array( |
|
| 3009 | - true => __("On the same request", "event_espresso"), |
|
| 3010 | - false => __("On a separate request", "event_espresso") |
|
| 3011 | - ), |
|
| 3012 | - array( |
|
| 3013 | - 'default' => $network_config->do_messages_on_same_request, |
|
| 3014 | - 'html_label_text' => __('Generate and send all messages:', 'event_espresso'), |
|
| 3015 | - 'html_help_text' => __('By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system. This makes things execute faster for people registering for your events. However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.', |
|
| 3016 | - 'event_espresso'), |
|
| 3017 | - ) |
|
| 3018 | - ), |
|
| 3019 | - 'update_settings' => new EE_Submit_Input( |
|
| 3020 | - array( |
|
| 3021 | - 'default' => __('Update', 'event_espresso'), |
|
| 3022 | - 'html_label_text' => ' ' |
|
| 3023 | - ) |
|
| 3024 | - ) |
|
| 3025 | - ) |
|
| 3026 | - ) |
|
| 3027 | - ) |
|
| 3028 | - ); |
|
| 3029 | - } |
|
| 3030 | - |
|
| 3031 | - |
|
| 3032 | - /** |
|
| 3033 | - * This handles updating the global settings set on the admin page. |
|
| 3034 | - * @throws \EE_Error |
|
| 3035 | - */ |
|
| 3036 | - protected function _update_global_settings() |
|
| 3037 | - { |
|
| 3038 | - /** @var EE_Network_Core_Config $network_config */ |
|
| 3039 | - $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3040 | - $form = $this->_generate_global_settings_form(); |
|
| 3041 | - if ($form->was_submitted()) { |
|
| 3042 | - $form->receive_form_submission(); |
|
| 3043 | - if ($form->is_valid()) { |
|
| 3044 | - $valid_data = $form->valid_data(); |
|
| 3045 | - foreach ($valid_data as $property => $value) { |
|
| 3046 | - $setter = 'set_' . $property; |
|
| 3047 | - if (method_exists($network_config, $setter)) { |
|
| 3048 | - $network_config->{$setter}($value); |
|
| 3049 | - } else if ( |
|
| 3050 | - property_exists($network_config, $property) |
|
| 3051 | - && $network_config->{$property} !== $value |
|
| 3052 | - ) { |
|
| 3053 | - $network_config->{$property} = $value; |
|
| 3054 | - } |
|
| 3055 | - } |
|
| 3056 | - //only update if the form submission was valid! |
|
| 3057 | - EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 3058 | - EE_Error::overwrite_success(); |
|
| 3059 | - EE_Error::add_success(__('Global message settings were updated', 'event_espresso')); |
|
| 3060 | - } |
|
| 3061 | - } |
|
| 3062 | - $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true); |
|
| 3063 | - } |
|
| 3064 | - |
|
| 3065 | - |
|
| 3066 | - /** |
|
| 3067 | - * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate |
|
| 3068 | - * |
|
| 3069 | - * @param array $tab_array This is an array of message type tab details used to generate the tabs |
|
| 3070 | - * |
|
| 3071 | - * @return string html formatted tabs |
|
| 3072 | - */ |
|
| 3073 | - protected function _get_mt_tabs($tab_array) |
|
| 3074 | - { |
|
| 3075 | - $tab_array = (array)$tab_array; |
|
| 3076 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3077 | - $tabs = ''; |
|
| 3078 | - |
|
| 3079 | - foreach ($tab_array as $tab) { |
|
| 3080 | - $tabs .= EEH_Template::display_template($template, $tab, true); |
|
| 3081 | - } |
|
| 3082 | - |
|
| 3083 | - return $tabs; |
|
| 3084 | - } |
|
| 3085 | - |
|
| 3086 | - |
|
| 3087 | - /** |
|
| 3088 | - * This prepares the content of the messenger meta box admin settings |
|
| 3089 | - * |
|
| 3090 | - * @param EE_messenger $messenger The messenger we're setting up content for |
|
| 3091 | - * |
|
| 3092 | - * @return string html formatted content |
|
| 3093 | - */ |
|
| 3094 | - protected function _get_messenger_box_content(EE_messenger $messenger) |
|
| 3095 | - { |
|
| 3096 | - |
|
| 3097 | - $fields = $messenger->get_admin_settings_fields(); |
|
| 3098 | - $settings_template_args['template_form_fields'] = ''; |
|
| 3099 | - |
|
| 3100 | - //is $messenger active? |
|
| 3101 | - $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3102 | - |
|
| 3103 | - |
|
| 3104 | - if ( ! empty($fields)) { |
|
| 2824 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field) ? $this->_generate_admin_form_fields($template_form_field, |
|
| 2825 | + 'string', 'ee_mt_activate_form') : ''; |
|
| 2826 | + } |
|
| 2827 | + |
|
| 2828 | + $settings_template_args['description'] = $message_type->description; |
|
| 2829 | + //we also need some hidden fields |
|
| 2830 | + $settings_template_args['hidden_fields'] = array( |
|
| 2831 | + 'message_type_settings[messenger]' => array( |
|
| 2832 | + 'type' => 'hidden', |
|
| 2833 | + 'value' => $messenger->name |
|
| 2834 | + ), |
|
| 2835 | + 'message_type_settings[message_type]' => array( |
|
| 2836 | + 'type' => 'hidden', |
|
| 2837 | + 'value' => $message_type->name |
|
| 2838 | + ), |
|
| 2839 | + 'type' => array( |
|
| 2840 | + 'type' => 'hidden', |
|
| 2841 | + 'value' => 'message_type' |
|
| 2842 | + ) |
|
| 2843 | + ); |
|
| 2844 | + |
|
| 2845 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields($settings_template_args['hidden_fields'], |
|
| 2846 | + 'array'); |
|
| 2847 | + $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) ? ' hidden' : ''; |
|
| 2848 | + |
|
| 2849 | + |
|
| 2850 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 2851 | + $content = EEH_Template::display_template($template, $settings_template_args, true); |
|
| 2852 | + |
|
| 2853 | + return $content; |
|
| 2854 | + } |
|
| 2855 | + |
|
| 2856 | + |
|
| 2857 | + /** |
|
| 2858 | + * Generate all the metaboxes for the message types and register them for the messages settings page. |
|
| 2859 | + * |
|
| 2860 | + * @access protected |
|
| 2861 | + * @return void |
|
| 2862 | + */ |
|
| 2863 | + protected function _messages_settings_metaboxes() |
|
| 2864 | + { |
|
| 2865 | + $this->_set_m_mt_settings(); |
|
| 2866 | + $m_boxes = $mt_boxes = array(); |
|
| 2867 | + $m_template_args = $mt_template_args = array(); |
|
| 2868 | + |
|
| 2869 | + $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email'; |
|
| 2870 | + |
|
| 2871 | + if (isset($this->_m_mt_settings['messenger_tabs'])) { |
|
| 2872 | + foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { |
|
| 2873 | + $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden'; |
|
| 2874 | + $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : ''; |
|
| 2875 | + //messenger meta boxes |
|
| 2876 | + $active = $selected_messenger == $messenger ? true : false; |
|
| 2877 | + $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active']) |
|
| 2878 | + ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 2879 | + : ''; |
|
| 2880 | + $m_boxes[$messenger . '_a_box'] = sprintf( |
|
| 2881 | + __('%s Settings', 'event_espresso'), |
|
| 2882 | + $tab_array['label'] |
|
| 2883 | + ); |
|
| 2884 | + $m_template_args[$messenger . '_a_box'] = array( |
|
| 2885 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 2886 | + 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2887 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2888 | + : '', |
|
| 2889 | + 'content' => $this->_get_messenger_box_content($tab_array['obj']), |
|
| 2890 | + 'hidden' => $active ? '' : ' hidden', |
|
| 2891 | + 'hide_on_message' => $hide_on_message, |
|
| 2892 | + 'messenger' => $messenger, |
|
| 2893 | + 'active' => $active |
|
| 2894 | + ); |
|
| 2895 | + // message type meta boxes |
|
| 2896 | + // (which is really just the inactive container for each messenger |
|
| 2897 | + // showing inactive message types for that messenger) |
|
| 2898 | + $mt_boxes[$messenger . '_i_box'] = __('Inactive Message Types', 'event_espresso'); |
|
| 2899 | + $mt_template_args[$messenger . '_i_box'] = array( |
|
| 2900 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 2901 | + 'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2902 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 2903 | + : '', |
|
| 2904 | + 'hidden' => $active ? '' : ' hidden', |
|
| 2905 | + 'hide_on_message' => $hide_on_message, |
|
| 2906 | + 'hide_off_message' => $hide_off_message, |
|
| 2907 | + 'messenger' => $messenger, |
|
| 2908 | + 'active' => $active |
|
| 2909 | + ); |
|
| 2910 | + } |
|
| 2911 | + } |
|
| 2912 | + |
|
| 2913 | + |
|
| 2914 | + //register messenger metaboxes |
|
| 2915 | + $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 2916 | + foreach ($m_boxes as $box => $label) { |
|
| 2917 | + $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
|
| 2918 | + $msgr = str_replace('_a_box', '', $box); |
|
| 2919 | + add_meta_box( |
|
| 2920 | + 'espresso_' . $msgr . '_settings', |
|
| 2921 | + $label, |
|
| 2922 | + function ($post, $metabox) { |
|
| 2923 | + echo EEH_Template::display_template($metabox["args"]["template_path"], |
|
| 2924 | + $metabox["args"]["template_args"], true); |
|
| 2925 | + }, |
|
| 2926 | + $this->_current_screen->id, |
|
| 2927 | + 'normal', |
|
| 2928 | + 'high', |
|
| 2929 | + $callback_args |
|
| 2930 | + ); |
|
| 2931 | + } |
|
| 2932 | + |
|
| 2933 | + //register message type metaboxes |
|
| 2934 | + $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 2935 | + foreach ($mt_boxes as $box => $label) { |
|
| 2936 | + $callback_args = array( |
|
| 2937 | + 'template_path' => $mt_template_path, |
|
| 2938 | + 'template_args' => $mt_template_args[$box] |
|
| 2939 | + ); |
|
| 2940 | + $mt = str_replace('_i_box', '', $box); |
|
| 2941 | + add_meta_box( |
|
| 2942 | + 'espresso_' . $mt . '_inactive_mts', |
|
| 2943 | + $label, |
|
| 2944 | + function ($post, $metabox) { |
|
| 2945 | + echo EEH_Template::display_template($metabox["args"]["template_path"], |
|
| 2946 | + $metabox["args"]["template_args"], true); |
|
| 2947 | + }, |
|
| 2948 | + $this->_current_screen->id, |
|
| 2949 | + 'side', |
|
| 2950 | + 'high', |
|
| 2951 | + $callback_args |
|
| 2952 | + ); |
|
| 2953 | + } |
|
| 2954 | + |
|
| 2955 | + //register metabox for global messages settings but only when on the main site. On single site installs this will |
|
| 2956 | + //always result in the metabox showing, on multisite installs the metabox will only show on the main site. |
|
| 2957 | + if (is_main_site()) { |
|
| 2958 | + add_meta_box( |
|
| 2959 | + 'espresso_global_message_settings', |
|
| 2960 | + __('Global Message Settings', 'event_espresso'), |
|
| 2961 | + array($this, 'global_messages_settings_metabox_content'), |
|
| 2962 | + $this->_current_screen->id, |
|
| 2963 | + 'normal', |
|
| 2964 | + 'low', |
|
| 2965 | + array() |
|
| 2966 | + ); |
|
| 2967 | + } |
|
| 2968 | + |
|
| 2969 | + } |
|
| 2970 | + |
|
| 2971 | + |
|
| 2972 | + /** |
|
| 2973 | + * This generates the content for the global messages settings metabox. |
|
| 2974 | + * @return string |
|
| 2975 | + */ |
|
| 2976 | + public function global_messages_settings_metabox_content() |
|
| 2977 | + { |
|
| 2978 | + $form = $this->_generate_global_settings_form(); |
|
| 2979 | + echo $form->form_open( |
|
| 2980 | + $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL), |
|
| 2981 | + 'POST' |
|
| 2982 | + ) |
|
| 2983 | + . $form->get_html() |
|
| 2984 | + . $form->form_close(); |
|
| 2985 | + } |
|
| 2986 | + |
|
| 2987 | + |
|
| 2988 | + /** |
|
| 2989 | + * This generates and returns the form object for the global messages settings. |
|
| 2990 | + * @return EE_Form_Section_Proper |
|
| 2991 | + */ |
|
| 2992 | + protected function _generate_global_settings_form() |
|
| 2993 | + { |
|
| 2994 | + EE_Registry::instance()->load_helper('HTML'); |
|
| 2995 | + /** @var EE_Network_Core_Config $network_config */ |
|
| 2996 | + $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 2997 | + |
|
| 2998 | + return new EE_Form_Section_Proper( |
|
| 2999 | + array( |
|
| 3000 | + 'name' => 'global_messages_settings', |
|
| 3001 | + 'html_id' => 'global_messages_settings', |
|
| 3002 | + 'html_class' => 'form-table', |
|
| 3003 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 3004 | + 'subsections' => apply_filters( |
|
| 3005 | + 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections', |
|
| 3006 | + array( |
|
| 3007 | + 'do_messages_on_same_request' => new EE_Select_Input( |
|
| 3008 | + array( |
|
| 3009 | + true => __("On the same request", "event_espresso"), |
|
| 3010 | + false => __("On a separate request", "event_espresso") |
|
| 3011 | + ), |
|
| 3012 | + array( |
|
| 3013 | + 'default' => $network_config->do_messages_on_same_request, |
|
| 3014 | + 'html_label_text' => __('Generate and send all messages:', 'event_espresso'), |
|
| 3015 | + 'html_help_text' => __('By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system. This makes things execute faster for people registering for your events. However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.', |
|
| 3016 | + 'event_espresso'), |
|
| 3017 | + ) |
|
| 3018 | + ), |
|
| 3019 | + 'update_settings' => new EE_Submit_Input( |
|
| 3020 | + array( |
|
| 3021 | + 'default' => __('Update', 'event_espresso'), |
|
| 3022 | + 'html_label_text' => ' ' |
|
| 3023 | + ) |
|
| 3024 | + ) |
|
| 3025 | + ) |
|
| 3026 | + ) |
|
| 3027 | + ) |
|
| 3028 | + ); |
|
| 3029 | + } |
|
| 3030 | + |
|
| 3031 | + |
|
| 3032 | + /** |
|
| 3033 | + * This handles updating the global settings set on the admin page. |
|
| 3034 | + * @throws \EE_Error |
|
| 3035 | + */ |
|
| 3036 | + protected function _update_global_settings() |
|
| 3037 | + { |
|
| 3038 | + /** @var EE_Network_Core_Config $network_config */ |
|
| 3039 | + $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3040 | + $form = $this->_generate_global_settings_form(); |
|
| 3041 | + if ($form->was_submitted()) { |
|
| 3042 | + $form->receive_form_submission(); |
|
| 3043 | + if ($form->is_valid()) { |
|
| 3044 | + $valid_data = $form->valid_data(); |
|
| 3045 | + foreach ($valid_data as $property => $value) { |
|
| 3046 | + $setter = 'set_' . $property; |
|
| 3047 | + if (method_exists($network_config, $setter)) { |
|
| 3048 | + $network_config->{$setter}($value); |
|
| 3049 | + } else if ( |
|
| 3050 | + property_exists($network_config, $property) |
|
| 3051 | + && $network_config->{$property} !== $value |
|
| 3052 | + ) { |
|
| 3053 | + $network_config->{$property} = $value; |
|
| 3054 | + } |
|
| 3055 | + } |
|
| 3056 | + //only update if the form submission was valid! |
|
| 3057 | + EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 3058 | + EE_Error::overwrite_success(); |
|
| 3059 | + EE_Error::add_success(__('Global message settings were updated', 'event_espresso')); |
|
| 3060 | + } |
|
| 3061 | + } |
|
| 3062 | + $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true); |
|
| 3063 | + } |
|
| 3064 | + |
|
| 3065 | + |
|
| 3066 | + /** |
|
| 3067 | + * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate |
|
| 3068 | + * |
|
| 3069 | + * @param array $tab_array This is an array of message type tab details used to generate the tabs |
|
| 3070 | + * |
|
| 3071 | + * @return string html formatted tabs |
|
| 3072 | + */ |
|
| 3073 | + protected function _get_mt_tabs($tab_array) |
|
| 3074 | + { |
|
| 3075 | + $tab_array = (array)$tab_array; |
|
| 3076 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3077 | + $tabs = ''; |
|
| 3078 | + |
|
| 3079 | + foreach ($tab_array as $tab) { |
|
| 3080 | + $tabs .= EEH_Template::display_template($template, $tab, true); |
|
| 3081 | + } |
|
| 3082 | + |
|
| 3083 | + return $tabs; |
|
| 3084 | + } |
|
| 3085 | + |
|
| 3086 | + |
|
| 3087 | + /** |
|
| 3088 | + * This prepares the content of the messenger meta box admin settings |
|
| 3089 | + * |
|
| 3090 | + * @param EE_messenger $messenger The messenger we're setting up content for |
|
| 3091 | + * |
|
| 3092 | + * @return string html formatted content |
|
| 3093 | + */ |
|
| 3094 | + protected function _get_messenger_box_content(EE_messenger $messenger) |
|
| 3095 | + { |
|
| 3096 | + |
|
| 3097 | + $fields = $messenger->get_admin_settings_fields(); |
|
| 3098 | + $settings_template_args['template_form_fields'] = ''; |
|
| 3099 | + |
|
| 3100 | + //is $messenger active? |
|
| 3101 | + $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3102 | + |
|
| 3103 | + |
|
| 3104 | + if ( ! empty($fields)) { |
|
| 3105 | 3105 | |
| 3106 | - $existing_settings = $messenger->get_existing_admin_settings(); |
|
| 3106 | + $existing_settings = $messenger->get_existing_admin_settings(); |
|
| 3107 | 3107 | |
| 3108 | - foreach ($fields as $fldname => $fldprops) { |
|
| 3109 | - $field_id = $messenger->name . '-' . $fldname; |
|
| 3110 | - $template_form_field[$field_id] = array( |
|
| 3111 | - 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3112 | - 'label' => $fldprops['label'], |
|
| 3113 | - 'input' => $fldprops['field_type'], |
|
| 3114 | - 'type' => $fldprops['value_type'], |
|
| 3115 | - 'required' => $fldprops['required'], |
|
| 3116 | - 'validation' => $fldprops['validation'], |
|
| 3117 | - 'value' => isset($existing_settings[$field_id]) |
|
| 3118 | - ? $existing_settings[$field_id] |
|
| 3119 | - : $fldprops['default'], |
|
| 3120 | - 'css_class' => '', |
|
| 3121 | - 'format' => $fldprops['format'] |
|
| 3122 | - ); |
|
| 3123 | - } |
|
| 3108 | + foreach ($fields as $fldname => $fldprops) { |
|
| 3109 | + $field_id = $messenger->name . '-' . $fldname; |
|
| 3110 | + $template_form_field[$field_id] = array( |
|
| 3111 | + 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3112 | + 'label' => $fldprops['label'], |
|
| 3113 | + 'input' => $fldprops['field_type'], |
|
| 3114 | + 'type' => $fldprops['value_type'], |
|
| 3115 | + 'required' => $fldprops['required'], |
|
| 3116 | + 'validation' => $fldprops['validation'], |
|
| 3117 | + 'value' => isset($existing_settings[$field_id]) |
|
| 3118 | + ? $existing_settings[$field_id] |
|
| 3119 | + : $fldprops['default'], |
|
| 3120 | + 'css_class' => '', |
|
| 3121 | + 'format' => $fldprops['format'] |
|
| 3122 | + ); |
|
| 3123 | + } |
|
| 3124 | 3124 | |
| 3125 | 3125 | |
| 3126 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3127 | - ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form') |
|
| 3128 | - : ''; |
|
| 3129 | - } |
|
| 3130 | - |
|
| 3131 | - //we also need some hidden fields |
|
| 3132 | - $settings_template_args['hidden_fields'] = array( |
|
| 3133 | - 'messenger_settings[messenger]' => array( |
|
| 3134 | - 'type' => 'hidden', |
|
| 3135 | - 'value' => $messenger->name |
|
| 3136 | - ), |
|
| 3137 | - 'type' => array( |
|
| 3138 | - 'type' => 'hidden', |
|
| 3139 | - 'value' => 'messenger' |
|
| 3140 | - ) |
|
| 3141 | - ); |
|
| 3142 | - |
|
| 3143 | - //make sure any active message types that are existing are included in the hidden fields |
|
| 3144 | - if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
|
| 3145 | - foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
|
| 3146 | - $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array( |
|
| 3147 | - 'type' => 'hidden', |
|
| 3148 | - 'value' => $mt |
|
| 3149 | - ); |
|
| 3150 | - } |
|
| 3151 | - } |
|
| 3152 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3153 | - $settings_template_args['hidden_fields'], |
|
| 3154 | - 'array' |
|
| 3155 | - ); |
|
| 3156 | - $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3157 | - |
|
| 3158 | - $settings_template_args['messenger'] = $messenger->name; |
|
| 3159 | - $settings_template_args['description'] = $messenger->description; |
|
| 3160 | - $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden'; |
|
| 3161 | - |
|
| 3162 | - |
|
| 3163 | - $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active($messenger->name) |
|
| 3164 | - ? $settings_template_args['show_hide_edit_form'] |
|
| 3165 | - : ' hidden'; |
|
| 3166 | - |
|
| 3167 | - $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3168 | - ? ' hidden' |
|
| 3169 | - : $settings_template_args['show_hide_edit_form']; |
|
| 3170 | - |
|
| 3171 | - |
|
| 3172 | - $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
|
| 3173 | - $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3174 | - $settings_template_args['on_off_status'] = $active ? true : false; |
|
| 3175 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3176 | - $content = EEH_Template::display_template($template, $settings_template_args, |
|
| 3177 | - true); |
|
| 3178 | - |
|
| 3179 | - return $content; |
|
| 3180 | - } |
|
| 3181 | - |
|
| 3182 | - |
|
| 3183 | - /** |
|
| 3184 | - * used by ajax on the messages settings page to activate|deactivate the messenger |
|
| 3185 | - */ |
|
| 3186 | - public function activate_messenger_toggle() |
|
| 3187 | - { |
|
| 3188 | - $success = true; |
|
| 3189 | - $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3190 | - //let's check that we have required data |
|
| 3191 | - if ( ! isset($this->_req_data['messenger'])) { |
|
| 3192 | - EE_Error::add_error( |
|
| 3193 | - __('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3194 | - __FILE__, |
|
| 3195 | - __FUNCTION__, |
|
| 3196 | - __LINE__ |
|
| 3197 | - ); |
|
| 3198 | - $success = false; |
|
| 3199 | - } |
|
| 3200 | - |
|
| 3201 | - //do a nonce check here since we're not arriving via a normal route |
|
| 3202 | - $nonce = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : ''; |
|
| 3203 | - $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3204 | - |
|
| 3205 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3206 | - |
|
| 3207 | - |
|
| 3208 | - if ( ! isset($this->_req_data['status'])) { |
|
| 3209 | - EE_Error::add_error( |
|
| 3210 | - __( |
|
| 3211 | - 'Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3212 | - 'event_espresso' |
|
| 3213 | - ), |
|
| 3214 | - __FILE__, |
|
| 3215 | - __FUNCTION__, |
|
| 3216 | - __LINE__ |
|
| 3217 | - ); |
|
| 3218 | - $success = false; |
|
| 3219 | - } |
|
| 3220 | - |
|
| 3221 | - //do check to verify we have a valid status. |
|
| 3222 | - $status = $this->_req_data['status']; |
|
| 3223 | - |
|
| 3224 | - if ($status != 'off' && $status != 'on') { |
|
| 3225 | - EE_Error::add_error( |
|
| 3226 | - sprintf( |
|
| 3227 | - __('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 3228 | - $this->_req_data['status'] |
|
| 3229 | - ), |
|
| 3230 | - __FILE__, |
|
| 3231 | - __FUNCTION__, |
|
| 3232 | - __LINE__ |
|
| 3233 | - ); |
|
| 3234 | - $success = false; |
|
| 3235 | - } |
|
| 3236 | - |
|
| 3237 | - if ($success) { |
|
| 3238 | - //made it here? Stop dawdling then!! |
|
| 3239 | - $success = $status == 'off' |
|
| 3240 | - ? $this->_deactivate_messenger($this->_req_data['messenger']) |
|
| 3241 | - : $this->_activate_messenger($this->_req_data['messenger']); |
|
| 3242 | - } |
|
| 3243 | - |
|
| 3244 | - $this->_template_args['success'] = $success; |
|
| 3245 | - |
|
| 3246 | - //no special instructions so let's just do the json return (which should automatically do all the special stuff). |
|
| 3247 | - $this->_return_json(); |
|
| 3248 | - |
|
| 3249 | - } |
|
| 3250 | - |
|
| 3251 | - |
|
| 3252 | - /** |
|
| 3253 | - * used by ajax from the messages settings page to activate|deactivate a message type |
|
| 3254 | - * |
|
| 3255 | - */ |
|
| 3256 | - public function activate_mt_toggle() |
|
| 3257 | - { |
|
| 3258 | - $success = true; |
|
| 3259 | - $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3260 | - |
|
| 3261 | - //let's make sure we have the necessary data |
|
| 3262 | - if ( ! isset($this->_req_data['message_type'])) { |
|
| 3263 | - EE_Error::add_error( |
|
| 3264 | - __('Message Type name needed to toggle activation. None given', 'event_espresso'), |
|
| 3265 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 3266 | - ); |
|
| 3267 | - $success = false; |
|
| 3268 | - } |
|
| 3269 | - |
|
| 3270 | - if ( ! isset($this->_req_data['messenger'])) { |
|
| 3271 | - EE_Error::add_error( |
|
| 3272 | - __('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3273 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 3274 | - ); |
|
| 3275 | - $success = false; |
|
| 3276 | - } |
|
| 3277 | - |
|
| 3278 | - if ( ! isset($this->_req_data['status'])) { |
|
| 3279 | - EE_Error::add_error( |
|
| 3280 | - __('Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3281 | - 'event_espresso'), |
|
| 3282 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 3283 | - ); |
|
| 3284 | - $success = false; |
|
| 3285 | - } |
|
| 3286 | - |
|
| 3287 | - |
|
| 3288 | - //do check to verify we have a valid status. |
|
| 3289 | - $status = $this->_req_data['status']; |
|
| 3290 | - |
|
| 3291 | - if ($status != 'activate' && $status != 'deactivate') { |
|
| 3292 | - EE_Error::add_error( |
|
| 3293 | - sprintf( |
|
| 3294 | - __('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), |
|
| 3295 | - $this->_req_data['status'] |
|
| 3296 | - ), |
|
| 3297 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 3298 | - ); |
|
| 3299 | - $success = false; |
|
| 3300 | - } |
|
| 3301 | - |
|
| 3302 | - |
|
| 3303 | - //do a nonce check here since we're not arriving via a normal route |
|
| 3304 | - $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
|
| 3305 | - $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3306 | - |
|
| 3307 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3308 | - |
|
| 3309 | - if ($success) { |
|
| 3310 | - //made it here? um, what are you waiting for then? |
|
| 3311 | - $success = $status == 'deactivate' |
|
| 3312 | - ? $this->_deactivate_message_type_for_messenger($this->_req_data['messenger'], |
|
| 3313 | - $this->_req_data['message_type']) |
|
| 3314 | - : $this->_activate_message_type_for_messenger($this->_req_data['messenger'], |
|
| 3315 | - $this->_req_data['message_type']); |
|
| 3316 | - } |
|
| 3317 | - |
|
| 3318 | - $this->_template_args['success'] = $success; |
|
| 3319 | - $this->_return_json(); |
|
| 3320 | - } |
|
| 3321 | - |
|
| 3322 | - |
|
| 3323 | - /** |
|
| 3324 | - * Takes care of processing activating a messenger and preparing the appropriate response. |
|
| 3325 | - * |
|
| 3326 | - * @param string $messenger_name The name of the messenger being activated |
|
| 3327 | - * |
|
| 3328 | - * @return bool |
|
| 3329 | - */ |
|
| 3330 | - protected function _activate_messenger($messenger_name) |
|
| 3331 | - { |
|
| 3332 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3333 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3334 | - $message_types_to_activate = $active_messenger instanceof EE_Messenger ? $active_messenger->get_default_message_types() : array(); |
|
| 3335 | - |
|
| 3336 | - //ensure is active |
|
| 3337 | - $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate); |
|
| 3338 | - |
|
| 3339 | - //set response_data for reload |
|
| 3340 | - foreach ($message_types_to_activate as $message_type_name) { |
|
| 3341 | - /** @var EE_message_type $message_type */ |
|
| 3342 | - $message_type = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3343 | - if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3344 | - $message_type_name) |
|
| 3345 | - && $message_type instanceof EE_message_type |
|
| 3346 | - ) { |
|
| 3347 | - $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3348 | - if ($message_type->get_admin_settings_fields()) { |
|
| 3349 | - $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3350 | - } |
|
| 3351 | - } |
|
| 3352 | - } |
|
| 3353 | - |
|
| 3354 | - //add success message for activating messenger |
|
| 3355 | - return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger); |
|
| 3356 | - |
|
| 3357 | - } |
|
| 3358 | - |
|
| 3359 | - |
|
| 3360 | - /** |
|
| 3361 | - * Takes care of processing deactivating a messenger and preparing the appropriate response. |
|
| 3362 | - * |
|
| 3363 | - * @param string $messenger_name The name of the messenger being activated |
|
| 3364 | - * |
|
| 3365 | - * @return bool |
|
| 3366 | - */ |
|
| 3367 | - protected function _deactivate_messenger($messenger_name) |
|
| 3368 | - { |
|
| 3369 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3370 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3371 | - $this->_message_resource_manager->deactivate_messenger($messenger_name); |
|
| 3372 | - |
|
| 3373 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger); |
|
| 3374 | - } |
|
| 3375 | - |
|
| 3376 | - |
|
| 3377 | - /** |
|
| 3378 | - * Takes care of processing activating a message type for a messenger and preparing the appropriate response. |
|
| 3379 | - * |
|
| 3380 | - * @param string $messenger_name The name of the messenger the message type is being activated for. |
|
| 3381 | - * @param string $message_type_name The name of the message type being activated for the messenger |
|
| 3382 | - * |
|
| 3383 | - * @return bool |
|
| 3384 | - */ |
|
| 3385 | - protected function _activate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3386 | - { |
|
| 3387 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3388 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3389 | - /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3390 | - $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3391 | - |
|
| 3392 | - //ensure is active |
|
| 3393 | - $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name); |
|
| 3394 | - |
|
| 3395 | - //set response for load |
|
| 3396 | - if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3397 | - $message_type_name) |
|
| 3398 | - ) { |
|
| 3399 | - $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3400 | - if ($message_type_to_activate->get_admin_settings_fields()) { |
|
| 3401 | - $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3402 | - } |
|
| 3403 | - } |
|
| 3404 | - |
|
| 3405 | - return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger, |
|
| 3406 | - $message_type_to_activate); |
|
| 3407 | - } |
|
| 3408 | - |
|
| 3409 | - |
|
| 3410 | - /** |
|
| 3411 | - * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response. |
|
| 3412 | - * |
|
| 3413 | - * @param string $messenger_name The name of the messenger the message type is being deactivated for. |
|
| 3414 | - * @param string $message_type_name The name of the message type being deactivated for the messenger |
|
| 3415 | - * |
|
| 3416 | - * @return bool |
|
| 3417 | - */ |
|
| 3418 | - protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3419 | - { |
|
| 3420 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3421 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3422 | - /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3423 | - $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3424 | - $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name); |
|
| 3425 | - |
|
| 3426 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger, |
|
| 3427 | - $message_type_to_deactivate); |
|
| 3428 | - } |
|
| 3429 | - |
|
| 3430 | - |
|
| 3431 | - /** |
|
| 3432 | - * This just initializes the defaults for activating messenger and message type responses. |
|
| 3433 | - */ |
|
| 3434 | - protected function _prep_default_response_for_messenger_or_message_type_toggle() |
|
| 3435 | - { |
|
| 3436 | - $this->_template_args['data']['active_mts'] = array(); |
|
| 3437 | - $this->_template_args['data']['mt_reload'] = array(); |
|
| 3438 | - } |
|
| 3439 | - |
|
| 3440 | - |
|
| 3441 | - /** |
|
| 3442 | - * Setup appropriate response for activating a messenger and/or message types |
|
| 3443 | - * |
|
| 3444 | - * @param EE_messenger $messenger |
|
| 3445 | - * @param EE_message_type|null $message_type |
|
| 3446 | - * |
|
| 3447 | - * @return bool |
|
| 3448 | - * @throws EE_Error |
|
| 3449 | - */ |
|
| 3450 | - protected function _setup_response_message_for_activating_messenger_with_message_types( |
|
| 3451 | - $messenger, |
|
| 3452 | - EE_Message_Type $message_type = null |
|
| 3453 | - ) { |
|
| 3454 | - //if $messenger isn't a valid messenger object then get out. |
|
| 3455 | - if ( ! $messenger instanceof EE_Messenger) { |
|
| 3456 | - EE_Error::add_error( |
|
| 3457 | - __('The messenger being activated is not a valid messenger', 'event_espresso'), |
|
| 3458 | - __FILE__, |
|
| 3459 | - __FUNCTION__, |
|
| 3460 | - __LINE__ |
|
| 3461 | - ); |
|
| 3126 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3127 | + ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form') |
|
| 3128 | + : ''; |
|
| 3129 | + } |
|
| 3130 | + |
|
| 3131 | + //we also need some hidden fields |
|
| 3132 | + $settings_template_args['hidden_fields'] = array( |
|
| 3133 | + 'messenger_settings[messenger]' => array( |
|
| 3134 | + 'type' => 'hidden', |
|
| 3135 | + 'value' => $messenger->name |
|
| 3136 | + ), |
|
| 3137 | + 'type' => array( |
|
| 3138 | + 'type' => 'hidden', |
|
| 3139 | + 'value' => 'messenger' |
|
| 3140 | + ) |
|
| 3141 | + ); |
|
| 3142 | + |
|
| 3143 | + //make sure any active message types that are existing are included in the hidden fields |
|
| 3144 | + if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
|
| 3145 | + foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
|
| 3146 | + $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array( |
|
| 3147 | + 'type' => 'hidden', |
|
| 3148 | + 'value' => $mt |
|
| 3149 | + ); |
|
| 3150 | + } |
|
| 3151 | + } |
|
| 3152 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3153 | + $settings_template_args['hidden_fields'], |
|
| 3154 | + 'array' |
|
| 3155 | + ); |
|
| 3156 | + $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3157 | + |
|
| 3158 | + $settings_template_args['messenger'] = $messenger->name; |
|
| 3159 | + $settings_template_args['description'] = $messenger->description; |
|
| 3160 | + $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden'; |
|
| 3161 | + |
|
| 3162 | + |
|
| 3163 | + $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active($messenger->name) |
|
| 3164 | + ? $settings_template_args['show_hide_edit_form'] |
|
| 3165 | + : ' hidden'; |
|
| 3166 | + |
|
| 3167 | + $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3168 | + ? ' hidden' |
|
| 3169 | + : $settings_template_args['show_hide_edit_form']; |
|
| 3170 | + |
|
| 3171 | + |
|
| 3172 | + $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
|
| 3173 | + $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3174 | + $settings_template_args['on_off_status'] = $active ? true : false; |
|
| 3175 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3176 | + $content = EEH_Template::display_template($template, $settings_template_args, |
|
| 3177 | + true); |
|
| 3178 | + |
|
| 3179 | + return $content; |
|
| 3180 | + } |
|
| 3181 | + |
|
| 3182 | + |
|
| 3183 | + /** |
|
| 3184 | + * used by ajax on the messages settings page to activate|deactivate the messenger |
|
| 3185 | + */ |
|
| 3186 | + public function activate_messenger_toggle() |
|
| 3187 | + { |
|
| 3188 | + $success = true; |
|
| 3189 | + $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3190 | + //let's check that we have required data |
|
| 3191 | + if ( ! isset($this->_req_data['messenger'])) { |
|
| 3192 | + EE_Error::add_error( |
|
| 3193 | + __('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3194 | + __FILE__, |
|
| 3195 | + __FUNCTION__, |
|
| 3196 | + __LINE__ |
|
| 3197 | + ); |
|
| 3198 | + $success = false; |
|
| 3199 | + } |
|
| 3200 | + |
|
| 3201 | + //do a nonce check here since we're not arriving via a normal route |
|
| 3202 | + $nonce = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : ''; |
|
| 3203 | + $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3204 | + |
|
| 3205 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3206 | + |
|
| 3207 | + |
|
| 3208 | + if ( ! isset($this->_req_data['status'])) { |
|
| 3209 | + EE_Error::add_error( |
|
| 3210 | + __( |
|
| 3211 | + 'Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3212 | + 'event_espresso' |
|
| 3213 | + ), |
|
| 3214 | + __FILE__, |
|
| 3215 | + __FUNCTION__, |
|
| 3216 | + __LINE__ |
|
| 3217 | + ); |
|
| 3218 | + $success = false; |
|
| 3219 | + } |
|
| 3220 | + |
|
| 3221 | + //do check to verify we have a valid status. |
|
| 3222 | + $status = $this->_req_data['status']; |
|
| 3223 | + |
|
| 3224 | + if ($status != 'off' && $status != 'on') { |
|
| 3225 | + EE_Error::add_error( |
|
| 3226 | + sprintf( |
|
| 3227 | + __('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 3228 | + $this->_req_data['status'] |
|
| 3229 | + ), |
|
| 3230 | + __FILE__, |
|
| 3231 | + __FUNCTION__, |
|
| 3232 | + __LINE__ |
|
| 3233 | + ); |
|
| 3234 | + $success = false; |
|
| 3235 | + } |
|
| 3236 | + |
|
| 3237 | + if ($success) { |
|
| 3238 | + //made it here? Stop dawdling then!! |
|
| 3239 | + $success = $status == 'off' |
|
| 3240 | + ? $this->_deactivate_messenger($this->_req_data['messenger']) |
|
| 3241 | + : $this->_activate_messenger($this->_req_data['messenger']); |
|
| 3242 | + } |
|
| 3243 | + |
|
| 3244 | + $this->_template_args['success'] = $success; |
|
| 3245 | + |
|
| 3246 | + //no special instructions so let's just do the json return (which should automatically do all the special stuff). |
|
| 3247 | + $this->_return_json(); |
|
| 3248 | + |
|
| 3249 | + } |
|
| 3250 | + |
|
| 3251 | + |
|
| 3252 | + /** |
|
| 3253 | + * used by ajax from the messages settings page to activate|deactivate a message type |
|
| 3254 | + * |
|
| 3255 | + */ |
|
| 3256 | + public function activate_mt_toggle() |
|
| 3257 | + { |
|
| 3258 | + $success = true; |
|
| 3259 | + $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3260 | + |
|
| 3261 | + //let's make sure we have the necessary data |
|
| 3262 | + if ( ! isset($this->_req_data['message_type'])) { |
|
| 3263 | + EE_Error::add_error( |
|
| 3264 | + __('Message Type name needed to toggle activation. None given', 'event_espresso'), |
|
| 3265 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 3266 | + ); |
|
| 3267 | + $success = false; |
|
| 3268 | + } |
|
| 3269 | + |
|
| 3270 | + if ( ! isset($this->_req_data['messenger'])) { |
|
| 3271 | + EE_Error::add_error( |
|
| 3272 | + __('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3273 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 3274 | + ); |
|
| 3275 | + $success = false; |
|
| 3276 | + } |
|
| 3277 | + |
|
| 3278 | + if ( ! isset($this->_req_data['status'])) { |
|
| 3279 | + EE_Error::add_error( |
|
| 3280 | + __('Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3281 | + 'event_espresso'), |
|
| 3282 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 3283 | + ); |
|
| 3284 | + $success = false; |
|
| 3285 | + } |
|
| 3286 | + |
|
| 3287 | + |
|
| 3288 | + //do check to verify we have a valid status. |
|
| 3289 | + $status = $this->_req_data['status']; |
|
| 3290 | + |
|
| 3291 | + if ($status != 'activate' && $status != 'deactivate') { |
|
| 3292 | + EE_Error::add_error( |
|
| 3293 | + sprintf( |
|
| 3294 | + __('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), |
|
| 3295 | + $this->_req_data['status'] |
|
| 3296 | + ), |
|
| 3297 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 3298 | + ); |
|
| 3299 | + $success = false; |
|
| 3300 | + } |
|
| 3301 | + |
|
| 3302 | + |
|
| 3303 | + //do a nonce check here since we're not arriving via a normal route |
|
| 3304 | + $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
|
| 3305 | + $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3306 | + |
|
| 3307 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3308 | + |
|
| 3309 | + if ($success) { |
|
| 3310 | + //made it here? um, what are you waiting for then? |
|
| 3311 | + $success = $status == 'deactivate' |
|
| 3312 | + ? $this->_deactivate_message_type_for_messenger($this->_req_data['messenger'], |
|
| 3313 | + $this->_req_data['message_type']) |
|
| 3314 | + : $this->_activate_message_type_for_messenger($this->_req_data['messenger'], |
|
| 3315 | + $this->_req_data['message_type']); |
|
| 3316 | + } |
|
| 3317 | + |
|
| 3318 | + $this->_template_args['success'] = $success; |
|
| 3319 | + $this->_return_json(); |
|
| 3320 | + } |
|
| 3321 | + |
|
| 3322 | + |
|
| 3323 | + /** |
|
| 3324 | + * Takes care of processing activating a messenger and preparing the appropriate response. |
|
| 3325 | + * |
|
| 3326 | + * @param string $messenger_name The name of the messenger being activated |
|
| 3327 | + * |
|
| 3328 | + * @return bool |
|
| 3329 | + */ |
|
| 3330 | + protected function _activate_messenger($messenger_name) |
|
| 3331 | + { |
|
| 3332 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3333 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3334 | + $message_types_to_activate = $active_messenger instanceof EE_Messenger ? $active_messenger->get_default_message_types() : array(); |
|
| 3335 | + |
|
| 3336 | + //ensure is active |
|
| 3337 | + $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate); |
|
| 3338 | + |
|
| 3339 | + //set response_data for reload |
|
| 3340 | + foreach ($message_types_to_activate as $message_type_name) { |
|
| 3341 | + /** @var EE_message_type $message_type */ |
|
| 3342 | + $message_type = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3343 | + if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3344 | + $message_type_name) |
|
| 3345 | + && $message_type instanceof EE_message_type |
|
| 3346 | + ) { |
|
| 3347 | + $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3348 | + if ($message_type->get_admin_settings_fields()) { |
|
| 3349 | + $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3350 | + } |
|
| 3351 | + } |
|
| 3352 | + } |
|
| 3353 | + |
|
| 3354 | + //add success message for activating messenger |
|
| 3355 | + return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger); |
|
| 3356 | + |
|
| 3357 | + } |
|
| 3358 | + |
|
| 3359 | + |
|
| 3360 | + /** |
|
| 3361 | + * Takes care of processing deactivating a messenger and preparing the appropriate response. |
|
| 3362 | + * |
|
| 3363 | + * @param string $messenger_name The name of the messenger being activated |
|
| 3364 | + * |
|
| 3365 | + * @return bool |
|
| 3366 | + */ |
|
| 3367 | + protected function _deactivate_messenger($messenger_name) |
|
| 3368 | + { |
|
| 3369 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3370 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3371 | + $this->_message_resource_manager->deactivate_messenger($messenger_name); |
|
| 3372 | + |
|
| 3373 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger); |
|
| 3374 | + } |
|
| 3375 | + |
|
| 3376 | + |
|
| 3377 | + /** |
|
| 3378 | + * Takes care of processing activating a message type for a messenger and preparing the appropriate response. |
|
| 3379 | + * |
|
| 3380 | + * @param string $messenger_name The name of the messenger the message type is being activated for. |
|
| 3381 | + * @param string $message_type_name The name of the message type being activated for the messenger |
|
| 3382 | + * |
|
| 3383 | + * @return bool |
|
| 3384 | + */ |
|
| 3385 | + protected function _activate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3386 | + { |
|
| 3387 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3388 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3389 | + /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3390 | + $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3391 | + |
|
| 3392 | + //ensure is active |
|
| 3393 | + $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name); |
|
| 3394 | + |
|
| 3395 | + //set response for load |
|
| 3396 | + if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3397 | + $message_type_name) |
|
| 3398 | + ) { |
|
| 3399 | + $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3400 | + if ($message_type_to_activate->get_admin_settings_fields()) { |
|
| 3401 | + $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3402 | + } |
|
| 3403 | + } |
|
| 3404 | + |
|
| 3405 | + return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger, |
|
| 3406 | + $message_type_to_activate); |
|
| 3407 | + } |
|
| 3408 | + |
|
| 3409 | + |
|
| 3410 | + /** |
|
| 3411 | + * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response. |
|
| 3412 | + * |
|
| 3413 | + * @param string $messenger_name The name of the messenger the message type is being deactivated for. |
|
| 3414 | + * @param string $message_type_name The name of the message type being deactivated for the messenger |
|
| 3415 | + * |
|
| 3416 | + * @return bool |
|
| 3417 | + */ |
|
| 3418 | + protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3419 | + { |
|
| 3420 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3421 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3422 | + /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3423 | + $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3424 | + $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name); |
|
| 3425 | + |
|
| 3426 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger, |
|
| 3427 | + $message_type_to_deactivate); |
|
| 3428 | + } |
|
| 3429 | + |
|
| 3430 | + |
|
| 3431 | + /** |
|
| 3432 | + * This just initializes the defaults for activating messenger and message type responses. |
|
| 3433 | + */ |
|
| 3434 | + protected function _prep_default_response_for_messenger_or_message_type_toggle() |
|
| 3435 | + { |
|
| 3436 | + $this->_template_args['data']['active_mts'] = array(); |
|
| 3437 | + $this->_template_args['data']['mt_reload'] = array(); |
|
| 3438 | + } |
|
| 3439 | + |
|
| 3440 | + |
|
| 3441 | + /** |
|
| 3442 | + * Setup appropriate response for activating a messenger and/or message types |
|
| 3443 | + * |
|
| 3444 | + * @param EE_messenger $messenger |
|
| 3445 | + * @param EE_message_type|null $message_type |
|
| 3446 | + * |
|
| 3447 | + * @return bool |
|
| 3448 | + * @throws EE_Error |
|
| 3449 | + */ |
|
| 3450 | + protected function _setup_response_message_for_activating_messenger_with_message_types( |
|
| 3451 | + $messenger, |
|
| 3452 | + EE_Message_Type $message_type = null |
|
| 3453 | + ) { |
|
| 3454 | + //if $messenger isn't a valid messenger object then get out. |
|
| 3455 | + if ( ! $messenger instanceof EE_Messenger) { |
|
| 3456 | + EE_Error::add_error( |
|
| 3457 | + __('The messenger being activated is not a valid messenger', 'event_espresso'), |
|
| 3458 | + __FILE__, |
|
| 3459 | + __FUNCTION__, |
|
| 3460 | + __LINE__ |
|
| 3461 | + ); |
|
| 3462 | 3462 | |
| 3463 | - return false; |
|
| 3464 | - } |
|
| 3465 | - //activated |
|
| 3466 | - if ($this->_template_args['data']['active_mts']) { |
|
| 3467 | - EE_Error::overwrite_success(); |
|
| 3468 | - //activated a message type with the messenger |
|
| 3469 | - if ($message_type instanceof EE_message_type) { |
|
| 3470 | - EE_Error::add_success( |
|
| 3471 | - sprintf( |
|
| 3472 | - __('%s message type has been successfully activated with the %s messenger', 'event_espresso'), |
|
| 3473 | - ucwords($message_type->label['singular']), |
|
| 3474 | - ucwords($messenger->label['singular']) |
|
| 3475 | - ) |
|
| 3476 | - ); |
|
| 3463 | + return false; |
|
| 3464 | + } |
|
| 3465 | + //activated |
|
| 3466 | + if ($this->_template_args['data']['active_mts']) { |
|
| 3467 | + EE_Error::overwrite_success(); |
|
| 3468 | + //activated a message type with the messenger |
|
| 3469 | + if ($message_type instanceof EE_message_type) { |
|
| 3470 | + EE_Error::add_success( |
|
| 3471 | + sprintf( |
|
| 3472 | + __('%s message type has been successfully activated with the %s messenger', 'event_espresso'), |
|
| 3473 | + ucwords($message_type->label['singular']), |
|
| 3474 | + ucwords($messenger->label['singular']) |
|
| 3475 | + ) |
|
| 3476 | + ); |
|
| 3477 | 3477 | |
| 3478 | - //if message type was invoice then let's make sure we activate the invoice payment method. |
|
| 3479 | - if ($message_type->name == 'invoice') { |
|
| 3480 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 3481 | - $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 3482 | - if ($pm instanceof EE_Payment_Method) { |
|
| 3483 | - 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.', |
|
| 3484 | - 'event_espresso')); |
|
| 3485 | - } |
|
| 3486 | - } |
|
| 3487 | - //just toggles the entire messenger |
|
| 3488 | - } else { |
|
| 3489 | - EE_Error::add_success( |
|
| 3490 | - sprintf( |
|
| 3491 | - __('%s messenger has been successfully activated', 'event_espresso'), |
|
| 3492 | - ucwords($messenger->label['singular']) |
|
| 3493 | - ) |
|
| 3494 | - ); |
|
| 3495 | - } |
|
| 3478 | + //if message type was invoice then let's make sure we activate the invoice payment method. |
|
| 3479 | + if ($message_type->name == 'invoice') { |
|
| 3480 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 3481 | + $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 3482 | + if ($pm instanceof EE_Payment_Method) { |
|
| 3483 | + 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.', |
|
| 3484 | + 'event_espresso')); |
|
| 3485 | + } |
|
| 3486 | + } |
|
| 3487 | + //just toggles the entire messenger |
|
| 3488 | + } else { |
|
| 3489 | + EE_Error::add_success( |
|
| 3490 | + sprintf( |
|
| 3491 | + __('%s messenger has been successfully activated', 'event_espresso'), |
|
| 3492 | + ucwords($messenger->label['singular']) |
|
| 3493 | + ) |
|
| 3494 | + ); |
|
| 3495 | + } |
|
| 3496 | 3496 | |
| 3497 | - return true; |
|
| 3497 | + return true; |
|
| 3498 | 3498 | |
| 3499 | - //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active |
|
| 3500 | - //message types after the activation process. However its possible some messengers don't HAVE any default_message_types |
|
| 3501 | - //in which case we just give a success message for the messenger being successfully activated. |
|
| 3502 | - } else { |
|
| 3503 | - if ( ! $messenger->get_default_message_types()) { |
|
| 3504 | - //messenger doesn't have any default message types so still a success. |
|
| 3505 | - EE_Error::add_success( |
|
| 3506 | - sprintf( |
|
| 3507 | - __('%s messenger was successfully activated.', 'event_espresso'), |
|
| 3508 | - ucwords($messenger->label['singular']) |
|
| 3509 | - ) |
|
| 3510 | - ); |
|
| 3499 | + //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active |
|
| 3500 | + //message types after the activation process. However its possible some messengers don't HAVE any default_message_types |
|
| 3501 | + //in which case we just give a success message for the messenger being successfully activated. |
|
| 3502 | + } else { |
|
| 3503 | + if ( ! $messenger->get_default_message_types()) { |
|
| 3504 | + //messenger doesn't have any default message types so still a success. |
|
| 3505 | + EE_Error::add_success( |
|
| 3506 | + sprintf( |
|
| 3507 | + __('%s messenger was successfully activated.', 'event_espresso'), |
|
| 3508 | + ucwords($messenger->label['singular']) |
|
| 3509 | + ) |
|
| 3510 | + ); |
|
| 3511 | 3511 | |
| 3512 | - return true; |
|
| 3513 | - } else { |
|
| 3514 | - EE_Error::add_error( |
|
| 3515 | - $message_type instanceof EE_message_type |
|
| 3516 | - ? sprintf( |
|
| 3517 | - __('%s message type was not successfully activated with the %s messenger', 'event_espresso'), |
|
| 3518 | - ucwords($message_type->label['singular']), |
|
| 3519 | - ucwords($messenger->label['singular']) |
|
| 3520 | - ) |
|
| 3521 | - : sprintf( |
|
| 3522 | - __('%s messenger was not successfully activated', 'event_espresso'), |
|
| 3523 | - ucwords($messenger->label['singular']) |
|
| 3524 | - ), |
|
| 3525 | - __FILE__, |
|
| 3526 | - __FUNCTION__, |
|
| 3527 | - __LINE__ |
|
| 3528 | - ); |
|
| 3512 | + return true; |
|
| 3513 | + } else { |
|
| 3514 | + EE_Error::add_error( |
|
| 3515 | + $message_type instanceof EE_message_type |
|
| 3516 | + ? sprintf( |
|
| 3517 | + __('%s message type was not successfully activated with the %s messenger', 'event_espresso'), |
|
| 3518 | + ucwords($message_type->label['singular']), |
|
| 3519 | + ucwords($messenger->label['singular']) |
|
| 3520 | + ) |
|
| 3521 | + : sprintf( |
|
| 3522 | + __('%s messenger was not successfully activated', 'event_espresso'), |
|
| 3523 | + ucwords($messenger->label['singular']) |
|
| 3524 | + ), |
|
| 3525 | + __FILE__, |
|
| 3526 | + __FUNCTION__, |
|
| 3527 | + __LINE__ |
|
| 3528 | + ); |
|
| 3529 | 3529 | |
| 3530 | - return false; |
|
| 3531 | - } |
|
| 3532 | - } |
|
| 3533 | - } |
|
| 3534 | - |
|
| 3535 | - |
|
| 3536 | - /** |
|
| 3537 | - * This sets up the appropriate response for deactivating a messenger and/or message type. |
|
| 3538 | - * |
|
| 3539 | - * @param EE_messenger $messenger |
|
| 3540 | - * @param EE_message_type|null $message_type |
|
| 3541 | - * |
|
| 3542 | - * @return bool |
|
| 3543 | - */ |
|
| 3544 | - protected function _setup_response_message_for_deactivating_messenger_with_message_types( |
|
| 3545 | - $messenger, |
|
| 3546 | - EE_message_type $message_type = null |
|
| 3547 | - ) { |
|
| 3548 | - EE_Error::overwrite_success(); |
|
| 3549 | - |
|
| 3550 | - //if $messenger isn't a valid messenger object then get out. |
|
| 3551 | - if ( ! $messenger instanceof EE_Messenger) { |
|
| 3552 | - EE_Error::add_error( |
|
| 3553 | - __('The messenger being deactivated is not a valid messenger', 'event_espresso'), |
|
| 3554 | - __FILE__, |
|
| 3555 | - __FUNCTION__, |
|
| 3556 | - __LINE__ |
|
| 3557 | - ); |
|
| 3530 | + return false; |
|
| 3531 | + } |
|
| 3532 | + } |
|
| 3533 | + } |
|
| 3534 | + |
|
| 3535 | + |
|
| 3536 | + /** |
|
| 3537 | + * This sets up the appropriate response for deactivating a messenger and/or message type. |
|
| 3538 | + * |
|
| 3539 | + * @param EE_messenger $messenger |
|
| 3540 | + * @param EE_message_type|null $message_type |
|
| 3541 | + * |
|
| 3542 | + * @return bool |
|
| 3543 | + */ |
|
| 3544 | + protected function _setup_response_message_for_deactivating_messenger_with_message_types( |
|
| 3545 | + $messenger, |
|
| 3546 | + EE_message_type $message_type = null |
|
| 3547 | + ) { |
|
| 3548 | + EE_Error::overwrite_success(); |
|
| 3549 | + |
|
| 3550 | + //if $messenger isn't a valid messenger object then get out. |
|
| 3551 | + if ( ! $messenger instanceof EE_Messenger) { |
|
| 3552 | + EE_Error::add_error( |
|
| 3553 | + __('The messenger being deactivated is not a valid messenger', 'event_espresso'), |
|
| 3554 | + __FILE__, |
|
| 3555 | + __FUNCTION__, |
|
| 3556 | + __LINE__ |
|
| 3557 | + ); |
|
| 3558 | 3558 | |
| 3559 | - return false; |
|
| 3560 | - } |
|
| 3561 | - |
|
| 3562 | - if ($message_type instanceof EE_message_type) { |
|
| 3563 | - $message_type_name = $message_type->name; |
|
| 3564 | - EE_Error::add_success( |
|
| 3565 | - sprintf( |
|
| 3566 | - __('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'), |
|
| 3567 | - ucwords($message_type->label['singular']), |
|
| 3568 | - ucwords($messenger->label['singular']) |
|
| 3569 | - ) |
|
| 3570 | - ); |
|
| 3571 | - } else { |
|
| 3572 | - $message_type_name = ''; |
|
| 3573 | - EE_Error::add_success( |
|
| 3574 | - sprintf( |
|
| 3575 | - __('%s messenger has been successfully deactivated.', 'event_espresso'), |
|
| 3576 | - ucwords($messenger->label['singular']) |
|
| 3577 | - ) |
|
| 3578 | - ); |
|
| 3579 | - } |
|
| 3580 | - |
|
| 3581 | - //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method. |
|
| 3582 | - if ($messenger->name == 'html' || $message_type_name == 'invoice') { |
|
| 3583 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 3584 | - $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); |
|
| 3585 | - if ($count_updated > 0) { |
|
| 3586 | - $msg = $message_type_name == 'invoice' |
|
| 3587 | - ? __('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 visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 3588 | - 'event_espresso') |
|
| 3589 | - : __('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.', |
|
| 3590 | - 'event_espresso'); |
|
| 3591 | - EE_Error::add_attention($msg); |
|
| 3592 | - } |
|
| 3593 | - } |
|
| 3594 | - |
|
| 3595 | - return true; |
|
| 3596 | - } |
|
| 3597 | - |
|
| 3598 | - |
|
| 3599 | - /** |
|
| 3600 | - * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax) |
|
| 3601 | - */ |
|
| 3602 | - public function update_mt_form() |
|
| 3603 | - { |
|
| 3604 | - if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { |
|
| 3605 | - EE_Error::add_error(__('Require message type or messenger to send an updated form'), __FILE__, __FUNCTION__, |
|
| 3606 | - __LINE__); |
|
| 3607 | - $this->_return_json(); |
|
| 3608 | - } |
|
| 3609 | - |
|
| 3610 | - $message_types = $this->get_installed_message_types(); |
|
| 3611 | - |
|
| 3612 | - $message_type = $message_types[$this->_req_data['message_type']]; |
|
| 3613 | - $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 3614 | - |
|
| 3615 | - $content = $this->_message_type_settings_content($message_type, $messenger, true); |
|
| 3616 | - $this->_template_args['success'] = true; |
|
| 3617 | - $this->_template_args['content'] = $content; |
|
| 3618 | - $this->_return_json(); |
|
| 3619 | - } |
|
| 3620 | - |
|
| 3621 | - |
|
| 3622 | - /** |
|
| 3623 | - * this handles saving the settings for a messenger or message type |
|
| 3624 | - * |
|
| 3625 | - */ |
|
| 3626 | - public function save_settings() |
|
| 3627 | - { |
|
| 3628 | - if ( ! isset($this->_req_data['type'])) { |
|
| 3629 | - EE_Error::add_error(__('Cannot save settings because type is unknown (messenger settings or messsage type settings?)', |
|
| 3630 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 3631 | - $this->_template_args['error'] = true; |
|
| 3632 | - $this->_return_json(); |
|
| 3633 | - } |
|
| 3634 | - |
|
| 3635 | - |
|
| 3636 | - if ($this->_req_data['type'] == 'messenger') { |
|
| 3637 | - $settings = $this->_req_data['messenger_settings']; //this should be an array. |
|
| 3638 | - $messenger = $settings['messenger']; |
|
| 3639 | - //let's setup the settings data |
|
| 3640 | - foreach ($settings as $key => $value) { |
|
| 3641 | - switch ($key) { |
|
| 3642 | - case 'messenger' : |
|
| 3643 | - unset($settings['messenger']); |
|
| 3644 | - break; |
|
| 3645 | - case 'message_types' : |
|
| 3646 | - unset($settings['message_types']); |
|
| 3647 | - break; |
|
| 3648 | - default : |
|
| 3649 | - $settings[$key] = $value; |
|
| 3650 | - break; |
|
| 3651 | - } |
|
| 3652 | - } |
|
| 3653 | - $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings); |
|
| 3654 | - } else if ($this->_req_data['type'] == 'message_type') { |
|
| 3655 | - $settings = $this->_req_data['message_type_settings']; |
|
| 3656 | - $messenger = $settings['messenger']; |
|
| 3657 | - $message_type = $settings['message_type']; |
|
| 3559 | + return false; |
|
| 3560 | + } |
|
| 3561 | + |
|
| 3562 | + if ($message_type instanceof EE_message_type) { |
|
| 3563 | + $message_type_name = $message_type->name; |
|
| 3564 | + EE_Error::add_success( |
|
| 3565 | + sprintf( |
|
| 3566 | + __('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'), |
|
| 3567 | + ucwords($message_type->label['singular']), |
|
| 3568 | + ucwords($messenger->label['singular']) |
|
| 3569 | + ) |
|
| 3570 | + ); |
|
| 3571 | + } else { |
|
| 3572 | + $message_type_name = ''; |
|
| 3573 | + EE_Error::add_success( |
|
| 3574 | + sprintf( |
|
| 3575 | + __('%s messenger has been successfully deactivated.', 'event_espresso'), |
|
| 3576 | + ucwords($messenger->label['singular']) |
|
| 3577 | + ) |
|
| 3578 | + ); |
|
| 3579 | + } |
|
| 3580 | + |
|
| 3581 | + //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method. |
|
| 3582 | + if ($messenger->name == 'html' || $message_type_name == 'invoice') { |
|
| 3583 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 3584 | + $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); |
|
| 3585 | + if ($count_updated > 0) { |
|
| 3586 | + $msg = $message_type_name == 'invoice' |
|
| 3587 | + ? __('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 visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 3588 | + 'event_espresso') |
|
| 3589 | + : __('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.', |
|
| 3590 | + 'event_espresso'); |
|
| 3591 | + EE_Error::add_attention($msg); |
|
| 3592 | + } |
|
| 3593 | + } |
|
| 3594 | + |
|
| 3595 | + return true; |
|
| 3596 | + } |
|
| 3597 | + |
|
| 3598 | + |
|
| 3599 | + /** |
|
| 3600 | + * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax) |
|
| 3601 | + */ |
|
| 3602 | + public function update_mt_form() |
|
| 3603 | + { |
|
| 3604 | + if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { |
|
| 3605 | + EE_Error::add_error(__('Require message type or messenger to send an updated form'), __FILE__, __FUNCTION__, |
|
| 3606 | + __LINE__); |
|
| 3607 | + $this->_return_json(); |
|
| 3608 | + } |
|
| 3609 | + |
|
| 3610 | + $message_types = $this->get_installed_message_types(); |
|
| 3611 | + |
|
| 3612 | + $message_type = $message_types[$this->_req_data['message_type']]; |
|
| 3613 | + $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 3614 | + |
|
| 3615 | + $content = $this->_message_type_settings_content($message_type, $messenger, true); |
|
| 3616 | + $this->_template_args['success'] = true; |
|
| 3617 | + $this->_template_args['content'] = $content; |
|
| 3618 | + $this->_return_json(); |
|
| 3619 | + } |
|
| 3620 | + |
|
| 3621 | + |
|
| 3622 | + /** |
|
| 3623 | + * this handles saving the settings for a messenger or message type |
|
| 3624 | + * |
|
| 3625 | + */ |
|
| 3626 | + public function save_settings() |
|
| 3627 | + { |
|
| 3628 | + if ( ! isset($this->_req_data['type'])) { |
|
| 3629 | + EE_Error::add_error(__('Cannot save settings because type is unknown (messenger settings or messsage type settings?)', |
|
| 3630 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 3631 | + $this->_template_args['error'] = true; |
|
| 3632 | + $this->_return_json(); |
|
| 3633 | + } |
|
| 3634 | + |
|
| 3635 | + |
|
| 3636 | + if ($this->_req_data['type'] == 'messenger') { |
|
| 3637 | + $settings = $this->_req_data['messenger_settings']; //this should be an array. |
|
| 3638 | + $messenger = $settings['messenger']; |
|
| 3639 | + //let's setup the settings data |
|
| 3640 | + foreach ($settings as $key => $value) { |
|
| 3641 | + switch ($key) { |
|
| 3642 | + case 'messenger' : |
|
| 3643 | + unset($settings['messenger']); |
|
| 3644 | + break; |
|
| 3645 | + case 'message_types' : |
|
| 3646 | + unset($settings['message_types']); |
|
| 3647 | + break; |
|
| 3648 | + default : |
|
| 3649 | + $settings[$key] = $value; |
|
| 3650 | + break; |
|
| 3651 | + } |
|
| 3652 | + } |
|
| 3653 | + $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings); |
|
| 3654 | + } else if ($this->_req_data['type'] == 'message_type') { |
|
| 3655 | + $settings = $this->_req_data['message_type_settings']; |
|
| 3656 | + $messenger = $settings['messenger']; |
|
| 3657 | + $message_type = $settings['message_type']; |
|
| 3658 | 3658 | |
| 3659 | - foreach ($settings as $key => $value) { |
|
| 3660 | - switch ($key) { |
|
| 3661 | - case 'messenger' : |
|
| 3662 | - unset($settings['messenger']); |
|
| 3663 | - break; |
|
| 3664 | - case 'message_type' : |
|
| 3665 | - unset($settings['message_type']); |
|
| 3666 | - break; |
|
| 3667 | - default : |
|
| 3668 | - $settings[$key] = $value; |
|
| 3669 | - break; |
|
| 3670 | - } |
|
| 3671 | - } |
|
| 3659 | + foreach ($settings as $key => $value) { |
|
| 3660 | + switch ($key) { |
|
| 3661 | + case 'messenger' : |
|
| 3662 | + unset($settings['messenger']); |
|
| 3663 | + break; |
|
| 3664 | + case 'message_type' : |
|
| 3665 | + unset($settings['message_type']); |
|
| 3666 | + break; |
|
| 3667 | + default : |
|
| 3668 | + $settings[$key] = $value; |
|
| 3669 | + break; |
|
| 3670 | + } |
|
| 3671 | + } |
|
| 3672 | 3672 | |
| 3673 | - $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings); |
|
| 3674 | - } |
|
| 3675 | - |
|
| 3676 | - //okay we should have the data all setup. Now we just update! |
|
| 3677 | - $success = $this->_message_resource_manager->update_active_messengers_option(); |
|
| 3678 | - |
|
| 3679 | - if ($success) { |
|
| 3680 | - EE_Error::add_success(__('Settings updated', 'event_espresso')); |
|
| 3681 | - } else { |
|
| 3682 | - EE_Error::add_error(__('Settings did not get updated', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 3683 | - } |
|
| 3684 | - |
|
| 3685 | - $this->_template_args['success'] = $success; |
|
| 3686 | - $this->_return_json(); |
|
| 3687 | - } |
|
| 3688 | - |
|
| 3689 | - |
|
| 3690 | - |
|
| 3691 | - |
|
| 3692 | - /** EE MESSAGE PROCESSING ACTIONS **/ |
|
| 3693 | - |
|
| 3694 | - |
|
| 3695 | - /** |
|
| 3696 | - * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete |
|
| 3697 | - * However, this does not send immediately, it just queues for sending. |
|
| 3698 | - * |
|
| 3699 | - * @since 4.9.0 |
|
| 3700 | - */ |
|
| 3701 | - protected function _generate_now() |
|
| 3702 | - { |
|
| 3703 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3704 | - EED_Messages::generate_now($msg_ids); |
|
| 3705 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3706 | - } |
|
| 3707 | - |
|
| 3708 | - |
|
| 3709 | - /** |
|
| 3710 | - * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that |
|
| 3711 | - * are EEM_Message::status_resend or EEM_Message::status_idle |
|
| 3712 | - * |
|
| 3713 | - * @since 4.9.0 |
|
| 3714 | - * |
|
| 3715 | - */ |
|
| 3716 | - protected function _generate_and_send_now() |
|
| 3717 | - { |
|
| 3718 | - $this->_generate_now(); |
|
| 3719 | - $this->_send_now(); |
|
| 3720 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3721 | - } |
|
| 3722 | - |
|
| 3723 | - |
|
| 3724 | - /** |
|
| 3725 | - * This queues any EEM_Message::status_sent EE_Message ids in the request for resending. |
|
| 3726 | - * |
|
| 3727 | - * @since 4.9.0 |
|
| 3728 | - */ |
|
| 3729 | - protected function _queue_for_resending() |
|
| 3730 | - { |
|
| 3731 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3732 | - EED_Messages::queue_for_resending($msg_ids); |
|
| 3733 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3734 | - } |
|
| 3735 | - |
|
| 3736 | - |
|
| 3737 | - /** |
|
| 3738 | - * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue |
|
| 3739 | - * |
|
| 3740 | - * @since 4.9.0 |
|
| 3741 | - */ |
|
| 3742 | - protected function _send_now() |
|
| 3743 | - { |
|
| 3744 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3745 | - EED_Messages::send_now($msg_ids); |
|
| 3746 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3747 | - } |
|
| 3748 | - |
|
| 3749 | - |
|
| 3750 | - /** |
|
| 3751 | - * Deletes EE_messages for IDs in the request. |
|
| 3752 | - * |
|
| 3753 | - * @since 4.9.0 |
|
| 3754 | - */ |
|
| 3755 | - protected function _delete_ee_messages() |
|
| 3756 | - { |
|
| 3757 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3758 | - $deleted_count = 0; |
|
| 3759 | - foreach ($msg_ids as $msg_id) { |
|
| 3760 | - if (EEM_Message::instance()->delete_by_ID($msg_id)) { |
|
| 3761 | - $deleted_count++; |
|
| 3762 | - } |
|
| 3763 | - } |
|
| 3764 | - if ($deleted_count) { |
|
| 3765 | - $this->_redirect_after_action( |
|
| 3766 | - true, |
|
| 3767 | - _n('message', 'messages', $deleted_count, 'event_espresso'), |
|
| 3768 | - __('deleted', 'event_espresso') |
|
| 3769 | - ); |
|
| 3770 | - } else { |
|
| 3771 | - EE_Error::add_error( |
|
| 3772 | - _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'), |
|
| 3773 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 3774 | - ); |
|
| 3775 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3776 | - } |
|
| 3777 | - } |
|
| 3778 | - |
|
| 3779 | - |
|
| 3780 | - /** |
|
| 3781 | - * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present. |
|
| 3782 | - * @since 4.9.0 |
|
| 3783 | - * @return array |
|
| 3784 | - */ |
|
| 3785 | - protected function _get_msg_ids_from_request() |
|
| 3786 | - { |
|
| 3787 | - if ( ! isset($this->_req_data['MSG_ID'])) { |
|
| 3788 | - return array(); |
|
| 3789 | - } |
|
| 3790 | - |
|
| 3791 | - return is_array($this->_req_data['MSG_ID']) ? array_keys($this->_req_data['MSG_ID']) : array($this->_req_data['MSG_ID']); |
|
| 3792 | - } |
|
| 3673 | + $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings); |
|
| 3674 | + } |
|
| 3675 | + |
|
| 3676 | + //okay we should have the data all setup. Now we just update! |
|
| 3677 | + $success = $this->_message_resource_manager->update_active_messengers_option(); |
|
| 3678 | + |
|
| 3679 | + if ($success) { |
|
| 3680 | + EE_Error::add_success(__('Settings updated', 'event_espresso')); |
|
| 3681 | + } else { |
|
| 3682 | + EE_Error::add_error(__('Settings did not get updated', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 3683 | + } |
|
| 3684 | + |
|
| 3685 | + $this->_template_args['success'] = $success; |
|
| 3686 | + $this->_return_json(); |
|
| 3687 | + } |
|
| 3688 | + |
|
| 3689 | + |
|
| 3690 | + |
|
| 3691 | + |
|
| 3692 | + /** EE MESSAGE PROCESSING ACTIONS **/ |
|
| 3693 | + |
|
| 3694 | + |
|
| 3695 | + /** |
|
| 3696 | + * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete |
|
| 3697 | + * However, this does not send immediately, it just queues for sending. |
|
| 3698 | + * |
|
| 3699 | + * @since 4.9.0 |
|
| 3700 | + */ |
|
| 3701 | + protected function _generate_now() |
|
| 3702 | + { |
|
| 3703 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3704 | + EED_Messages::generate_now($msg_ids); |
|
| 3705 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3706 | + } |
|
| 3707 | + |
|
| 3708 | + |
|
| 3709 | + /** |
|
| 3710 | + * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that |
|
| 3711 | + * are EEM_Message::status_resend or EEM_Message::status_idle |
|
| 3712 | + * |
|
| 3713 | + * @since 4.9.0 |
|
| 3714 | + * |
|
| 3715 | + */ |
|
| 3716 | + protected function _generate_and_send_now() |
|
| 3717 | + { |
|
| 3718 | + $this->_generate_now(); |
|
| 3719 | + $this->_send_now(); |
|
| 3720 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3721 | + } |
|
| 3722 | + |
|
| 3723 | + |
|
| 3724 | + /** |
|
| 3725 | + * This queues any EEM_Message::status_sent EE_Message ids in the request for resending. |
|
| 3726 | + * |
|
| 3727 | + * @since 4.9.0 |
|
| 3728 | + */ |
|
| 3729 | + protected function _queue_for_resending() |
|
| 3730 | + { |
|
| 3731 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3732 | + EED_Messages::queue_for_resending($msg_ids); |
|
| 3733 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3734 | + } |
|
| 3735 | + |
|
| 3736 | + |
|
| 3737 | + /** |
|
| 3738 | + * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue |
|
| 3739 | + * |
|
| 3740 | + * @since 4.9.0 |
|
| 3741 | + */ |
|
| 3742 | + protected function _send_now() |
|
| 3743 | + { |
|
| 3744 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3745 | + EED_Messages::send_now($msg_ids); |
|
| 3746 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3747 | + } |
|
| 3748 | + |
|
| 3749 | + |
|
| 3750 | + /** |
|
| 3751 | + * Deletes EE_messages for IDs in the request. |
|
| 3752 | + * |
|
| 3753 | + * @since 4.9.0 |
|
| 3754 | + */ |
|
| 3755 | + protected function _delete_ee_messages() |
|
| 3756 | + { |
|
| 3757 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 3758 | + $deleted_count = 0; |
|
| 3759 | + foreach ($msg_ids as $msg_id) { |
|
| 3760 | + if (EEM_Message::instance()->delete_by_ID($msg_id)) { |
|
| 3761 | + $deleted_count++; |
|
| 3762 | + } |
|
| 3763 | + } |
|
| 3764 | + if ($deleted_count) { |
|
| 3765 | + $this->_redirect_after_action( |
|
| 3766 | + true, |
|
| 3767 | + _n('message', 'messages', $deleted_count, 'event_espresso'), |
|
| 3768 | + __('deleted', 'event_espresso') |
|
| 3769 | + ); |
|
| 3770 | + } else { |
|
| 3771 | + EE_Error::add_error( |
|
| 3772 | + _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'), |
|
| 3773 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 3774 | + ); |
|
| 3775 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 3776 | + } |
|
| 3777 | + } |
|
| 3778 | + |
|
| 3779 | + |
|
| 3780 | + /** |
|
| 3781 | + * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present. |
|
| 3782 | + * @since 4.9.0 |
|
| 3783 | + * @return array |
|
| 3784 | + */ |
|
| 3785 | + protected function _get_msg_ids_from_request() |
|
| 3786 | + { |
|
| 3787 | + if ( ! isset($this->_req_data['MSG_ID'])) { |
|
| 3788 | + return array(); |
|
| 3789 | + } |
|
| 3790 | + |
|
| 3791 | + return is_array($this->_req_data['MSG_ID']) ? array_keys($this->_req_data['MSG_ID']) : array($this->_req_data['MSG_ID']); |
|
| 3792 | + } |
|
| 3793 | 3793 | |
| 3794 | 3794 | |
| 3795 | 3795 | } |